From d229784d8d3358b0f0a7acc837f3fecb889a5178 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Thu, 4 Dec 2025 21:54:38 -0600 Subject: [PATCH] fix cached modules --- examples/http_download_actor.ce | 2 -- scripts/cellfs.cm | 2 -- scripts/engine.cm | 19 ++++++++-------- scripts/shop.cm | 40 +++++++++++++++++++++++---------- source/cell.h | 1 - source/quickjs.c | 2 +- 6 files changed, 39 insertions(+), 27 deletions(-) diff --git a/examples/http_download_actor.ce b/examples/http_download_actor.ce index 3951e09d..9bbce384 100644 --- a/examples/http_download_actor.ce +++ b/examples/http_download_actor.ce @@ -3,8 +3,6 @@ var http = use('http'); var os = use('os'); -log.console("HERE") - // Actor state var state = { downloading: false, diff --git a/scripts/cellfs.cm b/scripts/cellfs.cm index 6bc1aa79..ab125f6d 100644 --- a/scripts/cellfs.cm +++ b/scripts/cellfs.cm @@ -479,6 +479,4 @@ cellfs.slurp = slurp cellfs.mount('.') -log.console(`about to return...`) - return cellfs diff --git a/scripts/engine.cm b/scripts/engine.cm index 11b4e31d..3064cfee 100644 --- a/scripts/engine.cm +++ b/scripts/engine.cm @@ -173,10 +173,18 @@ cell.args = cell.hidden.init cell.args ??= {} cell.id ??= "newguy" +function create_actor(desc = {id:guid()}) { + var actor = {} + actor[ACTORDATA] = desc + return actor +} + +var $_ = create_actor() + var shop = use('shop') os.core_qop = core_qop os.use_cache = use_cache -shop.set_os(os) +shop.set_os(os, $_) globalThis.use = shop.use @@ -249,14 +257,6 @@ function guid(bits = 256) var HEADER = Symbol() -function create_actor(desc = {id:guid()}) { - var actor = {} - actor[ACTORDATA] = desc - return actor -} - -var $_ = create_actor() - // returns a number between 0 and 1. There is a 50% chance that the result is less than 0.5. $_.random = function() { var n = os.random() @@ -585,6 +585,7 @@ function turn(msg) } log.console(`FIXME: need to get main from config, not just set to true`) +log.console(`FIXME: actors need the truncated use function as well`) actor_mod.register_actor(cell.id, turn, true, config.system.ar_timer) if (config.system.actor_memory) diff --git a/scripts/shop.cm b/scripts/shop.cm index 4edd1252..fc47bb55 100644 --- a/scripts/shop.cm +++ b/scripts/shop.cm @@ -29,9 +29,11 @@ var dylib_ext = '.so' // Default extension var os var use_cache var platform -Shop.set_os = function(o) +var $_ +Shop.set_os = function(o, $guy) { os = o + $_ = $guy qop = os.load_internal('js_qop_use') core_qop = os.core_qop use_cache = os.use_cache @@ -139,12 +141,10 @@ function ensure_dir(path) { } Shop.load_config = function(module) { - log.console(`checking for config ${module}`) var content if (!module) { if (!fd.is_file(shop_path)) return null - log.console(`found config ${shop_path}`) content = fd.slurp(shop_path) } else { var module_path = `.cell/modules/${module}/.cell/cell.toml` @@ -631,7 +631,8 @@ function resolve_c_symbol(path, package_context) if (os.dylib_has_symbol(open_dls[local_dl_name], candidate)) return { symbol: function() { return os.dylib_symbol(open_dls[local_dl_name], candidate); }, - scope: SCOPE_LOCAL + scope: SCOPE_LOCAL, + path: candidate }; } } @@ -644,7 +645,8 @@ function resolve_c_symbol(path, package_context) if (os.internal_exists(lc)) return { symbol: function() { return os.load_internal(lc); }, - scope: SCOPE_LOCAL + scope: SCOPE_LOCAL, + path: lc }; } @@ -668,7 +670,8 @@ function resolve_c_symbol(path, package_context) return { symbol: function() { return os.dylib_symbol(open_dls[dl_path], sym_name) }, scope: SCOPE_PACKAGE, - package: canon_pkg + package: canon_pkg, + path: sym_name } } } @@ -680,7 +683,8 @@ function resolve_c_symbol(path, package_context) return { symbol: function() { return os.load_internal(sym_name) }, scope: SCOPE_PACKAGE, - package: canon_pkg + package: canon_pkg, + path: sym_name }; } } @@ -690,7 +694,8 @@ function resolve_c_symbol(path, package_context) if (os.internal_exists(core_sym)) return { symbol: function() { return os.load_internal(core_sym); }, - scope: SCOPE_CORE + scope: SCOPE_CORE, + path: core_sym }; return null @@ -709,7 +714,18 @@ Shop.use = function(path, package_context) { if (min_scope == 999) throw new Error(`Module ${path} could not be found in ${package_context}`) - var cache_key = `${text(min_scope)}::${path}` + var resolved_path + if (mod_resolve.scope != 999) resolved_path = mod_resolve.path + else resolved_path = c_resolve.path + + var cache_scope = min_scope == SCOPE_CORE ? 2 : 0 + var cache_key + if (min_scope == SCOPE_CORE) + cache_key = `2::${path}` + else + cache_key = `${text(cache_scope)}::${resolved_path}` + + cache_key = cache_key.replace('//', '/') if (use_cache[cache_key]) return use_cache[cache_key] @@ -717,11 +733,11 @@ Shop.use = function(path, package_context) { var used if (c_resolve.scope < mod_resolve.scope) - used = c_resolve.symbol() + used = c_resolve.symbol(null, $_) else if (mod_resolve.scope < c_resolve.scope) - used = mod_resolve.symbol.call() + used = mod_resolve.symbol.call(null, $_) else - used = mod_resolve.symbol.call(c_resolve.symbol()) + used = mod_resolve.symbol.call(c_resolve.symbol(), $_) if (!used) throw new Error(`Module ${path} via package ${package_context} returned null`) diff --git a/source/cell.h b/source/cell.h index 028ee349..12a10861 100644 --- a/source/cell.h +++ b/source/cell.h @@ -168,7 +168,6 @@ JS_SetPropertyFunctionList(js, TYPE##_proto, js_##TYPE##_funcs, countof(js_##TYP #define QJSCLASSPREP_NO_FUNCS(TYPE) \ JS_NewClassID(&js_##TYPE##_id);\ -printf(" class %s got new id %d\n", #TYPE, js_##TYPE##_id);\ JS_NewClass(JS_GetRuntime(js), js_##TYPE##_id, &js_##TYPE##_class);\ JSValue TYPE##_proto = JS_NewObject(js); \ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \ diff --git a/source/quickjs.c b/source/quickjs.c index f061afdf..869885e1 100644 --- a/source/quickjs.c +++ b/source/quickjs.c @@ -96,7 +96,7 @@ /* dump objects freed by the garbage collector */ //#define DUMP_GC_FREE /* dump objects leaking when freeing the runtime */ -#define DUMP_LEAKS 1 +//#define DUMP_LEAKS 1 /* dump memory usage before running the garbage collector */ //#define DUMP_MEM //#define DUMP_OBJECTS /* dump objects in JS_FreeContext */