diff options
| author | Johnny Richard <johnny@johnnyrichard.com> | 2025-04-11 01:15:01 +0200 |
|---|---|---|
| committer | Johnny Richard <johnny@johnnyrichard.com> | 2025-04-14 23:11:22 +0200 |
| commit | e7f69c8fbbbcbddde84933b2becd91e787d1ac63 (patch) | |
| tree | 16cd17da17133494dd06aab614724e76b059d4ad /src/vm.h | |
Intial commit
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/vm.h')
| -rw-r--r-- | src/vm.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/vm.h b/src/vm.h new file mode 100644 index 0000000..2e9e487 --- /dev/null +++ b/src/vm.h @@ -0,0 +1,64 @@ +#ifndef VM_H +#define VM_H +#include "stack.h" + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(program[0])) +#define STACK_CAPACITY 1024 +#define HEAP_CAPACITY 1024 + +typedef enum inst_type { + // stack + INST_PUSH, + INST_DUP, + INST_COPY, + INST_SWAP, + INST_DROP, + INST_SLIDE, + // arithmetics + INST_ADD, + INST_SUB, + INST_MUL, + INST_DIV, + INST_MOD, + // heap access + INST_STORE, + INST_LOAD, + // Flow control + INST_CALL, + INST_RET, + INST_LABEL, + INST_JMP, + INST_JMPZ, + INST_JMPN, + // I/O + INST_PRINTI, + INST_PRINTC, + INST_READI, + INST_READC, + INST_END, +} inst_type_t; + +typedef struct instr { + inst_type_t type; + int operand; +} inst_t; + +typedef struct label { + int name; + int index; +} label_t; + +typedef struct vm { + stack_t stack; + stack_t call_stack; + int *heap; + label_t *labels; +} vm_t; + +void +vm_init(vm_t *vm); + +void +vm_run(vm_t *vm, inst_t *insts); + +#endif /* VM_H */ |
