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
return.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 return.c
12
* @brief Implements the OP_RETURN opcode for returning from a function in the VM.
13
*
14
* This file handles the OP_RETURN instruction, which returns from the current function
15
* and optionally pushes a return value onto the stack.
16
*
17
* Behavior:
18
* - Pops the optional return value from the stack.
19
* - Returns to the caller frame.
20
* - Pushes the return value onto the stack (if any).
21
*
22
* Error Handling:
23
* - Exits with an error if the frame stack is empty.
24
*
25
* Example:
26
* - Bytecode: OP_RETURN
27
* - Stack before: [42]
28
* - Stack after: [42]
29
*/
30
31
case
OP_RETURN
: {
32
Value
retv
;
33
if
(vm->sp >= 0)
34
retv
=
pop_value
(vm);
35
else
36
retv
=
make_nil
();
37
vm_pop_frame
(vm);
38
push_value
(vm,
retv
);
39
break
;
40
}
OP_RETURN
@ OP_RETURN
Definition
bytecode.h:61
retv
else retv
Definition
return.c:36
push_value
push_value(vm, retv)
vm_pop_frame
vm_pop_frame(vm)
Value
Tagged union representing a Fun value.
Definition
value.h:68
make_nil
Value make_nil(void)
Construct a nil Value.
Definition
value.c:126
pop_value
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition
vm.c:580
Generated on
for Fun by
1.16.1