diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-04-21 15:07:16 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-04-25 20:48:40 +0200 |
commit | 35af4ba4fc21a4b2357c50e6b02a2e3e4b236e88 (patch) | |
tree | 445f9fdf2e96e490cd681dca36d5cc9912474ed3 /chunk.c | |
parent | f2c4b79feaffd7b2fdb4041f47c9cd0f4cc3bc6e (diff) |
treewide: rework internal data type system
Instead of relying on json_object values internally, use custom types to
represent the different ucode value types which brings a number of
advantages compared to the previous approach:
- Due to the use of tagged pointers, small integer, string and bool
values can be stored directly in the pointer addresses, vastly
reducing required heap memory
- Ability to create circular data structures such as
`let o; o = { test: o };`
- Ability to register custom `tostring()` function through prototypes
- Initial mark/sweep GC implementation to tear down circular object
graphs on VM deinit
The change also paves the way for possible future extensions such as
constant variables and meta methods for custom ressource types.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'chunk.c')
-rw-r--r-- | chunk.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -17,6 +17,7 @@ #include <assert.h> #include "chunk.h" +#include "types.h" #include "util.h" #define OFFSETINFO_BITS (sizeof(((uc_offsetinfo *)NULL)->entries[0]) * 8) @@ -135,14 +136,14 @@ uc_chunk_pop(uc_chunk *chunk) } } -struct json_object * +uc_value_t * uc_chunk_get_constant(uc_chunk *chunk, size_t idx) { return uc_vallist_get(&chunk->constants, idx); } ssize_t -uc_chunk_add_constant(uc_chunk *chunk, struct json_object *val) +uc_chunk_add_constant(uc_chunk *chunk, uc_value_t *val) { return uc_vallist_add(&chunk->constants, val); } @@ -165,7 +166,7 @@ uc_chunk_debug_get_srcpos(uc_chunk *chunk, size_t off) } void -uc_chunk_debug_add_variable(uc_chunk *chunk, size_t from, size_t to, size_t slot, bool upval, json_object *name) +uc_chunk_debug_add_variable(uc_chunk *chunk, size_t from, size_t to, size_t slot, bool upval, uc_value_t *name) { uc_variables *variables = &chunk->debuginfo.variables; uc_value_list *varnames = &chunk->debuginfo.varnames; @@ -185,12 +186,12 @@ uc_chunk_debug_add_variable(uc_chunk *chunk, size_t from, size_t to, size_t slot variables->count++; } -json_object * +uc_value_t * uc_chunk_debug_get_variable(uc_chunk *chunk, size_t off, size_t slot, bool upval) { uc_variables *variables = &chunk->debuginfo.variables; uc_value_list *varnames = &chunk->debuginfo.varnames; - json_object *name = NULL; + uc_value_t *name = NULL; size_t i; assert(slot <= ((size_t)-1 / 2)); |