![]() | Fun 0.41.5 The programming language that makes You have fun |
Definitions for the Fun VM bytecode: opcodes, instruction format, and bytecode container API. More...


Go to the source code of this file.
Data Structures | |
| struct | Instruction |
| struct | Bytecode |
Typedefs | |
| typedef struct Bytecode | Bytecode |
Functions | |
| Bytecode * | bytecode_new (void) |
| Allocate and initialize an empty Bytecode object. | |
| int | bytecode_add_constant (Bytecode *bc, Value v) |
| Append a constant to a Bytecode's constant table. | |
| int | bytecode_add_instruction (Bytecode *bc, OpCode op, int32_t operand) |
| Append a single instruction to the instruction stream. | |
| void | bytecode_set_operand (Bytecode *bc, int idx, int32_t operand) |
| Patch the operand of a previously emitted instruction. | |
| void | bytecode_free (Bytecode *bc) |
| Free a Bytecode and all memory it owns. | |
| void | bytecode_dump (const Bytecode *bc) |
| Print a human-readable dump of constants and instructions to stdout. | |
Definitions for the Fun VM bytecode: opcodes, instruction format, and bytecode container API.
This header declares the VM's operation codes (OpCode), the compact instruction representation (Instruction), and the owning bytecode container (Bytecode) together with minimal constructor/manipulation helpers. The concrete execution semantics for each opcode are implemented in the VM (see vm.c and vm/* handlers).
Definition in file bytecode.h.
| typedef struct Bytecode Bytecode |
| enum OpCode |
VM operation codes executed by the Fun virtual machine.
Unless stated otherwise, opcodes operate on the VM stack. Comments on each opcode describe stack effects using a left-to-right pop order and the value pushed as a result. For example, "pops b, a; pushes a+b" means the instruction will pop first b then a from the stack and finally push the result of a+b.
Definition at line 35 of file bytecode.h.
Append a constant to a Bytecode's constant table.
The value is deep-copied into the table; the caller retains ownership of v and may free it independently.
Definition at line 48 of file bytecode.c.


Append a single instruction to the instruction stream.
| bc | Target bytecode (must not be NULL). |
| op | Opcode to emit. |
| operand | Operand value (semantics depend on opcode). |
Definition at line 62 of file bytecode.c.

| void bytecode_dump | ( | const Bytecode * | bc | ) |
Print a human-readable dump of constants and instructions to stdout.
Intended for debugging and tests. Formats constants with print_value() and shows each instruction index, mnemonic and operand.
| bc | Bytecode to dump (prints "<null bytecode>" if NULL). |
Definition at line 423 of file bytecode.c.


| void bytecode_free | ( | Bytecode * | bc | ) |
Free a Bytecode and all memory it owns.
Frees constants (deep), instruction array, and metadata strings. Accepts NULL and is then a no-op.
| bc | Bytecode to free (may be NULL). |
Definition at line 92 of file bytecode.c.


| Bytecode * bytecode_new | ( | void | ) |
Allocate and initialize an empty Bytecode object.
Initializes instruction and constant arrays to empty and clears metadata. Caller owns the returned pointer and must free it with bytecode_free().
Definition at line 27 of file bytecode.c.

| void bytecode_set_operand | ( | Bytecode * | bc, |
| int | idx, | ||
| int32_t | operand ) |
Patch the operand of a previously emitted instruction.
Silently ignores out-of-bounds indices.
| bc | Target bytecode. |
| idx | Instruction index to patch. |
| operand | New operand value. |
Definition at line 78 of file bytecode.c.