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
throw.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
35
36
case
OP_THROW
: {
37
Value
err = pop_value(vm);
38
/* if there is a handler in this frame, jump to it and push err for catch */
39
if
(
f
->try_sp >= 0) {
40
int
try_idx =
f
->try_stack[
f
->try_sp--];
41
int
target
=
f
->fn->instructions[try_idx].operand;
42
/* push error for catch block */
43
push_value(vm, err);
/* transfer ownership to stack */
44
f
->ip =
target
;
45
break
;
46
}
47
/* Unhandled: print error and terminate */
48
char
*
s
=
value_to_string_alloc
(&err);
49
if
(
s
) {
50
fprintf
(stdout,
"%s\n"
,
s
);
51
free
(
s
);
52
}
else
{
53
fprintf
(stdout,
"<error>\n"
);
54
}
55
free_value
(err);
56
/* clear frames to stop execution */
57
vm->fp = -1;
58
break
;
59
}
OP_THROW
@ OP_THROW
Definition
bytecode.h:250
target
char target[32]
Definition
cast.c:28
free
free(vals)
f
FILE * f
Definition
read_file.c:38
s
uint32_t s
Definition
rol.c:31
Value
Tagged union representing a Fun value.
Definition
value.h:68
free_value
free_value(err)
value_to_string_alloc
char * value_to_string_alloc(const Value *v)
Allocate a printable C string for a Value.
Definition
value.c:641
fprintf
#define fprintf
Definition
vm.c:200
Generated on
for Fun by
1.16.1