Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
set_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 2026 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 set_exit.c
12 * @brief Implements the OP_RUST_SET_EXIT opcode (conditional build).
13 *
14 * Pops an integer exit code and delegates to a Rust helper to store it into
15 * vm.exit_code. Pushes Nil afterwards. When Rust support is disabled, the
16 * argument is still popped/freed, a runtime error is raised, and Nil is
17 * pushed to maintain stack discipline.
18 *
19 * OP_RUST_SET_EXIT: (code:int) -> Nil
20 *
21 * Behavior (FUN_WITH_RUST=ON):
22 * - Expects an integer on the stack (provided by previous opcodes).
23 * - Calls fun_op_rset_exit(vm) which pops the int and writes vm->exit_code.
24 * - Pushes Nil.
25 *
26 * Behavior (FUN_WITH_RUST=OFF):
27 * - Pops and frees one value to preserve stack discipline.
28 * - Raises a runtime error indicating missing Rust support.
29 * - Pushes Nil.
30 */
31
33#ifdef FUN_WITH_RUST
34 extern int fun_op_rset_exit(VM * vm);
35 /* Expect an integer on the stack already (produced by prior ops) */
36 /* fun_op_rset_exit will pop it and store into vm.exit_code */
38 (void)rc;
39 /* push Nil as a conventional result */
41#else
42 /* pop and ignore to keep stack sane */
43 Value v = pop_value(vm);
45 vm_raise_error(vm, "RUST_SET_EXIT requires FUN_WITH_RUST=ON at build time");
46 push_value(vm, make_nil());
47#endif
48 break;
49}
@ OP_RUST_SET_EXIT
Definition bytecode.h:282
Value v
Definition cast.c:22
CURLcode rc
Definition download.c:71
push_value(vm, make_nil())
The Fun virtual machine state.
Definition vm.h:110
Tagged union representing a Fun value.
Definition value.h:68
Value make_nil(void)
Construct a nil Value.
Definition value.c:126
void free_value(Value v)
Free dynamic storage owned by a Value.
Definition value.c:517
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition vm.c:580
void vm_raise_error(VM *vm, const char *msg)
Raise a runtime error inside the VM, honoring try/catch/finally.
Definition vm.c:248
int fun_op_rset_exit(VM *vm)