Fun
0.41.5
The programming language that makes you have fun!
Main Page
Data Structures
Files
File List
Globals
Loading...
Searching...
No Matches
src
vm
core
try_push.c
Go to the documentation of this file.
1
/*
2
* This file is part of the Fun programming language.
3
* https://fun-lang.xyz/
4
*
5
* Copyright 2025 Johannes Findeisen <you@hanez.org>
6
* Licensed under the terms of the Apache-2.0 license.
7
* https://opensource.org/license/apache-2-0
8
*/
9
10
/**
11
* @file try_push.c
12
* @brief Implements the OP_TRY_PUSH opcode to begin a try/catch region.
13
*
14
* This file handles the OP_TRY_PUSH instruction, which marks the start of a
15
* try/catch region in the current frame by pushing the index of the TRY
16
* instruction onto a small per-frame stack. The actual catch target IP is
17
* stored in the TRY instruction's operand and may be patched later by the
18
* compiler/linker.
19
*
20
* Behavior:
21
* - Pushes the index of this TRY instruction (f->ip - 1) onto f->try_stack.
22
* - Does not modify the value stack.
23
*
24
* Errors:
25
* - If the try depth exceeds the size of f->try_stack, prints a runtime error
26
* and terminates the process.
27
*/
28
29
case
OP_TRY_PUSH
: {
30
/* push index of this TRY instruction; handler ip is in its operand (may be patched later) */
31
if
(
f
->try_sp >= (
int
)(
sizeof
(
f
->try_stack) /
sizeof
(
f
->try_stack[0])) - 1) {
32
fprintf
(stderr,
"Runtime error: try depth exceeded\n"
);
33
exit
(1);
34
}
35
f
->try_stack[++
f
->try_sp] =
f
->ip - 1;
/* index of TRY_PUSH instruction */
36
break
;
37
}
OP_TRY_PUSH
@ OP_TRY_PUSH
Definition
bytecode.h:248
f
FILE * f
Definition
read_file.c:38
fprintf
#define fprintf
Definition
vm.c:200
exit
#define exit(code)
Definition
vm.c:230
Generated on
for Fun by
1.16.1