fix cached modules

This commit is contained in:
2025-12-04 21:54:38 -06:00
parent 19e747c120
commit d229784d8d
6 changed files with 39 additions and 27 deletions

View File

@@ -3,8 +3,6 @@
var http = use('http');
var os = use('os');
log.console("HERE")
// Actor state
var state = {
downloading: false,

View File

@@ -479,6 +479,4 @@ cellfs.slurp = slurp
cellfs.mount('.')
log.console(`about to return...`)
return cellfs

View File

@@ -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)

View File

@@ -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`)

View File

@@ -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); \

View File

@@ -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 */