48 printf(
"=== Bytecode dump ===\n");
51 printf(
"instr %3d: opcode=%2d operand=%d\n", i, instr.
op, instr.
operand);
53 printf(
"=====================\n");
55 printf(
"=====================\n");
61 printf(
"Output[%d] = ", i);
73 printf(
"=== Rust FFI demo ===\n");
76 printf(
"Rust says: %s\n", rs);
83 printf(
"fun_op_radd rc=%d\n",
rc);
85 printf(
"Rust op result: %lld\n", sum);
87 printf(
"=== Rust FFI demo (disabled; build with -DFUN_WITH_RUST=ON) ===\n");
Bytecode * bytecode_new(void)
Allocate and initialize an empty Bytecode object.
int bytecode_add_instruction(Bytecode *bc, OpCode op, int32_t operand)
Append a single instruction to the instruction stream.
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.
int bytecode_add_constant(Bytecode *bc, Value v)
Append a constant to a Bytecode's constant table.
Definitions for the Fun VM bytecode: opcodes, instruction format, and bytecode container API.
Instruction * instructions
The Fun virtual machine state.
Value output[OUTPUT_SIZE]
int main()
Minimal executable to exercise a subset of VM opcodes.
void print_value(const Value *v)
Print a human-readable representation of a Value to stdout.
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Defines the Value type and associated functions for the Fun VM.
void vm_push_i64(VM *vm, int64_t v)
Push a 64-bit integer as a VM int Value (C ABI helper).
void vm_init(VM *vm)
Initialize a VM instance to its default state.
void vm_free(VM *vm)
Free resources owned directly by the VM structure.
void vm_clear_output(VM *vm)
Clear the VM's buffered output values and partial flags.
int64_t vm_pop_i64(VM *vm)
Pop a numeric Value and convert it to a 64-bit integer (C ABI helper).
Core virtual machine data structures and public VM API.
const char * fun_rust_get_string(void)
void vm_run(VM *vm, Bytecode *entry)
Execute the provided entry bytecode in the VM. Pushes an initial frame and runs until HALT or an unre...