From 4eee6e1a0a17465756f1b4156727c55bc17214f1 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 2 Nov 2023 23:25:33 +0000 Subject: Implemented subroutine instructions in runtime Very easy overall, printing the call stack not so much. --- vm/runtime.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'vm/runtime.h') diff --git a/vm/runtime.h b/vm/runtime.h index ce3cb42..c98dfcf 100644 --- a/vm/runtime.h +++ b/vm/runtime.h @@ -24,6 +24,8 @@ typedef enum ERR_OK = 0, ERR_STACK_UNDERFLOW, ERR_STACK_OVERFLOW, + ERR_CALL_STACK_UNDERFLOW, + ERR_CALL_STACK_OVERFLOW, ERR_INVALID_OPCODE, ERR_INVALID_REGISTER_BYTE, ERR_INVALID_REGISTER_HWORD, @@ -46,14 +48,19 @@ typedef struct struct Stack { byte *data; - word ptr, max; + size_t ptr, max; } stack; heap_t heap; struct Program { inst_t *instructions; - word ptr, max; + size_t ptr, max; } program; + struct CallStack + { + word *address_pointers; + size_t ptr, max; + } call_stack; } vm_t; err_t vm_execute(vm_t *); @@ -63,6 +70,7 @@ void vm_load_stack(vm_t *, byte *, size_t); void vm_load_registers(vm_t *, registers_t); void vm_load_heap(vm_t *, heap_t); void vm_load_program(vm_t *, inst_t *, size_t); +void vm_load_call_stack(vm_t *, word *, size_t); void vm_stop(vm_t *); // Print routines @@ -71,6 +79,7 @@ void vm_print_registers(vm_t *, FILE *); void vm_print_stack(vm_t *, FILE *); void vm_print_program(vm_t *, FILE *); void vm_print_heap(vm_t *, FILE *); +void vm_print_call_stack(vm_t *, FILE *); void vm_print_all(vm_t *, FILE *); // Execution routines -- cgit v1.2.3-13-gbd6f