Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
get_sp.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 get_sp.c
12 * @brief Implements the OP_RUST_GET_SP opcode (conditional build).
13 *
14 * Delegates to a Rust helper to read the VM's current stack pointer (sp).
15 * When Rust support is disabled, this raises a runtime error and pushes -1 to
16 * signal unavailability.
17 *
18 * OP_RUST_GET_SP: () -> int | Nil
19 *
20 * Behavior (FUN_WITH_RUST=ON):
21 * - Does not pop any values.
22 * - Invokes fun_op_rget_sp(vm). The Rust helper may push the result or
23 * otherwise communicate it. The C side does not directly push here.
24 *
25 * Behavior (FUN_WITH_RUST=OFF):
26 * - Raises a runtime error indicating missing Rust support.
27 * - Pushes integer -1 as a sentinel value.
28 */
29
31#ifdef FUN_WITH_RUST
32 extern int fun_op_rget_sp(VM * vm);
33 int rc = fun_op_rget_sp(vm);
34 (void)rc; /* rc currently unused; 0 means OK */
35#else
36 vm_raise_error(vm, "RUST_GET_SP requires FUN_WITH_RUST=ON at build time");
37 push_value(vm, make_int(-1));
38#endif
39 break;
40}
@ OP_RUST_GET_SP
Definition bytecode.h:281
CURLcode rc
Definition download.c:71
The Fun virtual machine state.
Definition vm.h:110
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
void vm_raise_error(VM *vm, const char *msg)
Raise a runtime error inside the VM, honoring try/catch/finally.
Definition vm.c:248
static void push_value(VM *vm, Value v)
Push a Value onto the VM operand stack.
Definition vm.c:564
int fun_op_rget_sp(VM *vm)