Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
exit.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
19
20case OP_EXIT: {
21 int code = 0;
22 if (vm->sp >= 0) {
23 Value v = pop_value(vm);
24 if (v.type == VAL_INT) {
25 code = (int)v.i;
26 } else if (v.type == VAL_STRING) {
27 /* best-effort parse number from string */
28 code = (int)strtoll(v.s, NULL, 10);
29 } else if (v.type == VAL_NIL) {
30 code = 0;
31 } else {
32 /* unsupported type for exit; default to 0 */
33 code = 0;
34 }
36 }
37 vm->exit_code = code;
38 return;
39}
@ OP_EXIT
Definition bytecode.h:235
Value v
Definition cast.c:22
int code
Definition proc_system.c:31
Tagged union representing a Fun value.
Definition value.h:68
void free_value(Value v)
Free dynamic storage owned by a Value.
Definition value.c:517
@ VAL_STRING
Definition value.h:53
@ VAL_NIL
Definition value.h:57
@ VAL_INT
Definition value.h:51