#ifndef VM_H #define VM_H #include #include #include typedef enum { OpType_Nop, OpType_PushNull, OpType_PushInt, OpType_PushBool, OpType_PushPtr, OpType_Pop, OpType_LoadLocal, OpType_StoreLocal, OpType_Jump, OpType_JumpIf, OpType_Load, OpType_Store, OpType_Call, OpType_Return, OpType_And, OpType_Or, OpType_EE, OpType_NE, OpType_LT, OpType_GT, OpType_LTE, OpType_GTE, OpType_Add, OpType_Subtract, OpType_Multiply, OpType_Not, OpType_Negate, } OpType; typedef uint32_t Op; typedef enum { ValueType_Null, ValueType_Int, ValueType_Bool, ValueType_Ptr, } ValueType; typedef struct Value Value; struct Value { ValueType type; union { int int_value; bool bool_value; void* ptr_value; }; }; typedef struct { const Op* program; size_t program_size; size_t pc; Value* stack; size_t stack_size; size_t sp; size_t bp; } VM; void vm_construct( VM* vm, const Op* program, size_t program_size, size_t stack_size); #endif