#ifndef RZ_VM_H #define RZ_VM_H #include "commons.h" #include "opcodes.h" #include "mod.h" #include "err.h" #include "tysy.h" #include "sym.h" #include "program.h" #include "heap.h" #include "locals.h" typedef struct stack_frame{ struct frame* prev; program_t* program; value_t* stack[RZ_STACK_LIMIT]; int allocated[RZ_STACK_LIMIT]; size_t pc; size_t bp; size_t sp; fun_t* fun; locals_t* locals; struct { size_t size; size_t cap; value_t** data; } alloc; } frame_t; typedef struct { sym_t* sym; tysy_t* tysy; err_t* err; frame_t* top_frame; heap_t heap; locals_t locals; } vm_t; void vm_init(vm_t* vm, sym_t* sym, tysy_t* tysy, err_t* err); void vm_free(vm_t* vm); void vm_frame_init(frame_t* frame); void vm_frame_free(frame_t* frame); void vm_frame_push(vm_t* vm, fun_t* fun); int vm_frame_pop(vm_t* vm); void vm_push_new(vm_t* vm, value_t* value); void vm_push(vm_t* vm, value_t* value); value_t* vm_pop(vm_t* vm); size_t vm_stack_str(vm_t* vm, char* buffer, size_t size); int vm_exec_mod(vm_t* vm, mod_t* mod); int vm_exec_instr(vm_t* vm, Opcode op, param_t param); void vm_ensure_type(vm_t* vm, value_t* value, TypeKind want); void vm_push_alloc(frame_t* frame, value_t* value); void vm_clear_alloc(frame_t* frame); #endif