semos/vm.h

71 lines
1.1 KiB
C
Raw Permalink Normal View History

2024-04-05 03:14:35 +01:00
#ifndef VM_H
#define VM_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
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