From 35af4ba4fc21a4b2357c50e6b02a2e3e4b236e88 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 21 Apr 2021 15:07:16 +0200 Subject: 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 --- module.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'module.h') diff --git a/module.h b/module.h index 9885270..aa72074 100644 --- a/module.h +++ b/module.h @@ -18,7 +18,6 @@ #define __MODULE_H_ #include "lib.h" -#include "object.h" #include "vm.h" #define register_functions(scope, functions) \ @@ -34,23 +33,19 @@ }) #define declare_type(name, proto, freefn) \ - ops->ressource.define(name, proto, freefn) + ucv_ressource_type_add(name, proto, freefn) #define alloc_ressource(data, type) \ - ops->ressource.create(xjs_new_object(), type, data) + ucv_ressource_new(ucv_object_new(NULL), type, data) #define register_ressource(scope, key, res) \ json_object_object_add((scope)->header.jso, key, (res)->header.jso) -static const uc_ops *ops; +void uc_module_init(uc_value_t *scope) __attribute__((weak)); -void uc_module_init(uc_prototype *scope) __attribute__((weak)); - -void uc_module_entry(const uc_ops *_ops, uc_prototype *scope); -void uc_module_entry(const uc_ops *_ops, uc_prototype *scope) +void uc_module_entry(uc_value_t *scope); +void uc_module_entry(uc_value_t *scope) { - ops = _ops; - if (uc_module_init) uc_module_init(scope); } -- cgit v1.2.3