/** * vm.h * Copyright (C) 2017 Alexander Koch * Golem stack-based virtual machine (GVM) * * The virtual machine runs the generated bytecode. * Instructions are defined in bytecode.h and Bytecode.md. */ #ifndef vm_h #define vm_h #include #include #include #include "../adt/vector.h" #include "../adt/hashmap.h" #include "../vm/val.h" #include "../vm/bytecode.h" #include "../lib/libdef.h" #include "../lib/native.h" #define STACK_SIZE 512 /** * vm_t - VM definition * * @stack General purpose Stack / RAM * @pc Program counter * @fp Frame pointer * @sp Stack pointer * @firstVal Current reference for GC * @numObject Counted objects by GC * @maxObjects Count of objects when GC is triggered * @errjmp Jump position when failure occurs. * @argc Argument count * @argc Arguments */ typedef struct { // Stack val_t stack[STACK_SIZE]; int pc; int fp; int sp; // Gargabe collection obj_t* firstVal; int numObjects; int maxObjects; int errjmp; int argc; char** argv; } vm_t; // Internal function typedef void (*gvm_c_function)(vm_t*); // Methods void vm_run(vm_t* vm, vector_t* buffer); void vm_run_args(vm_t* vm, vector_t* buffer, int argc, char** argv); void vm_register(vm_t* vm, val_t val); void vm_push(vm_t* vm, val_t val); val_t vm_pop(vm_t* vm); void vm_gc(vm_t* vm); #endif