diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-04-27 12:43:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-27 12:43:38 +0200 |
commit | 8469c4b1be228f42c46f08852f028f7801b93cc9 (patch) | |
tree | f61121e8f89e39787a960e621fc8492e57fc4bc0 /vm.h | |
parent | f360350bd874aeec0806c8df02c7a20a54c44406 (diff) | |
parent | 64eec7f90e945696572ee076b75d1f35e8f2248a (diff) |
Merge pull request #5 from jow-/new-type-system
New type system
Diffstat (limited to 'vm.h')
-rw-r--r-- | vm.h | 58 |
1 files changed, 5 insertions, 53 deletions
@@ -21,9 +21,9 @@ #include <stdarg.h> #include "chunk.h" -#include "object.h" #include "util.h" #include "lexer.h" +#include "types.h" #define __insns \ __insn(NOOP) \ @@ -102,57 +102,9 @@ typedef struct { int8_t stack_pop; int8_t stack_push; int8_t operand_bytes; - bool operand_is_skip; } uc_insn_definition; typedef enum { - EXCEPTION_NONE, - EXCEPTION_SYNTAX, - EXCEPTION_RUNTIME, - EXCEPTION_TYPE, - EXCEPTION_REFERENCE, - EXCEPTION_USER -} uc_exception_type_t; - -typedef struct { - uc_exception_type_t type; - json_object *stacktrace; - char *message; -} uc_exception; - -typedef struct { - uint8_t *ip; - uc_closure *closure; - uc_cfunction *cfunction; - size_t stackframe; - json_object *ctx; - bool mcall; -} uc_callframe; - -uc_declare_vector(uc_callframes, uc_callframe); -uc_declare_vector(uc_stack, json_object *); - -typedef struct uc_vm { - uc_stack stack; - uc_exception exception; - uc_callframes callframes; - uc_upvalref *open_upvals; - uc_parse_config *config; - uc_prototype *globals; - uc_source *sources; - union { - uint32_t u32; - int32_t s32; - uint16_t u16; - int16_t s16; - uint8_t u8; - int8_t s8; - } arg; - size_t spread_values; - uint8_t trace; -} uc_vm; - -typedef enum { STATUS_OK, ERROR_COMPILE, ERROR_RUNTIME @@ -163,15 +115,15 @@ extern uint32_t insns[__I_MAX]; void uc_vm_init(uc_vm *vm, uc_parse_config *config); void uc_vm_free(uc_vm *vm); -void uc_vm_stack_push(uc_vm *vm, json_object *value); -json_object *uc_vm_stack_pop(uc_vm *vm); -json_object *uc_vm_stack_peek(uc_vm *vm, size_t offset); +void uc_vm_stack_push(uc_vm *vm, uc_value_t *value); +uc_value_t *uc_vm_stack_pop(uc_vm *vm); +uc_value_t *uc_vm_stack_peek(uc_vm *vm, size_t offset); uc_exception_type_t uc_vm_call(uc_vm *vm, bool mcall, size_t nargs); void __attribute__((format(printf, 3, 0))) uc_vm_raise_exception(uc_vm *vm, uc_exception_type_t type, const char *fmt, ...); -uc_vm_status_t uc_vm_execute(uc_vm *vm, uc_function *fn, uc_prototype *globals, json_object *modules); +uc_vm_status_t uc_vm_execute(uc_vm *vm, uc_function_t *fn, uc_value_t *globals, uc_value_t *modules); #endif /* __VM_H_ */ |