#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" typedef struct { int id; param_t addr; } local_t; typedef struct stack_frame{ struct frame* prev; param_t stack[RZ_STACK_LIMIT]; size_t pc; size_t bp; size_t sp; struct { size_t size; size_t cap; local_t** data; } locals; } frame_t; typedef struct { sym_t* sym; tysy_t* tysy; err_t* err; frame_t* top_frame; } 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); int vm_frame_pop(vm_t* vm); local_t* vm_try_local_load(vm_t* vm, int id); void vm_local_store(vm_t* vm, int id, param_t addr); void vm_push_new_value(vm_t* vm, mod_t* mod, value_t* value); void vm_push(vm_t* vm, param_t param); param_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, mod_t* mod, Opcode op, param_t param); void vm_ensure_type(vm_t* vm, value_t* value, TypeKind want); #endif