27#define ASSERT_EQ(val, expected) \ 28 if ((val).type != VAL_INT || (val).i != (expected)) { \ 29 fprintf(stderr, "Assertion failed: expected %lld, got ", (long long)(expected)); \ 30 print_value(&(val)); \ 166 (void)start_round_demo;
316 printf(
"=== Bytecode dump ===\n");
319 printf(
"instr %3d: opcode=%2d operand=%d\n", i, instr.
op, instr.
operand);
321 printf(
"=====================\n");
326 printf(
"All tests executed. Output count: %d\n", vm.
output_count);
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.
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.
int main(void)
Build and execute a demo bytecode program and print results.
Instruction * instructions
The Fun virtual machine state.
Value make_float(double v)
Construct a Value representing a double-precision float.
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_init(VM *vm)
Initialize a VM instance to its default state.
void vm_clear_output(VM *vm)
Clear the VM's buffered output values and partial flags.
Core virtual machine data structures and public VM API.
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...