further loading

This commit is contained in:
2026-02-08 22:26:13 -06:00
parent 6799d90a7d
commit a74231563a
3 changed files with 36 additions and 8 deletions

View File

@@ -49,9 +49,13 @@ function ends_with(str, suffix) {
return search(str, suffix, -length(suffix)) != null
}
print("engine: loading js")
var js = use_embed('js')
print("engine: loading fd")
var fd = use_embed('fd')
print("engine: loaded fd")
print("engine: getting home")
// Get the shop path from HOME environment
var home = os.getenv('HOME') || os.getenv('USERPROFILE')
if (!home) {
@@ -76,34 +80,49 @@ function use_core(path) {
if (use_cache[cache_key])
return use_cache[cache_key];
print(`engine: use_core('${path}') - embed`)
var sym = use_embed(replace(path, '/', '_'))
// Core scripts are in packages/core/
var file_path = core_path + '/' + path + MOD_EXT
if (fd.is_file(file_path)) {
print(`engine: use_core('${path}') - loading script`)
var script_blob = fd.slurp(file_path)
var script = text(script_blob)
var mod = `(function setup_module(use){${script}})`
var fn = mach_eval('core:' + path, mod)
if (fn == null) {
print(`engine: use_core('${path}') - mach_eval returned null!`)
return null
}
print(`engine: use_core('${path}') - calling (fn type: ${typeof(fn)})`)
var result = call(fn,sym, [use_core])
print(`engine: use_core('${path}') - done`)
use_cache[cache_key] = result;
return result;
}
print(`engine: use_core('${path}') - using embed directly`)
use_cache[cache_key] = sym;
return sym;
}
print("engine: loading blob")
var blob = use_core('blob')
print("engine: loaded blob")
function actor() {
}
print("engine: loading actor")
var actor_mod = use_core('actor')
print("engine: loading wota")
var wota = use_core('wota')
print("engine: loading nota")
var nota = use_core('nota')
print("engine: loaded nota")
function is_actor(value) {
return is_object(value) && value[ACTORDATA]
@@ -191,10 +210,15 @@ function actor_die(err)
print("engine: setting up actor_die")
actor_mod.on_exception(actor_die)
print("engine: setting cell args")
print(`engine: init is ${init}`)
_cell.args = init != null ? init : {}
print("engine: args set")
_cell.id = "newguy"
print("engine: id set")
function create_actor(desc = {id:guid()}) {
var actor = {}
@@ -202,19 +226,25 @@ function create_actor(desc = {id:guid()}) {
return actor
}
print("engine: creating $_")
var $_ = {}
print("engine: creating self actor")
$_.self = create_actor()
print("engine: setting os props")
os.use_cache = use_cache
os.global_shop_path = shop_path
os.$_ = $_
print("engine: os props set")
print("engine: loading shop")
var shop = use_core('internal/shop')
print("engine: loaded shop, loading json")
var json = use_core('json')
var time = use_core('time')
print("engine: loading pronto")
var pronto = use_core('pronto')
print("engine: loaded pronto")
var fallback = pronto.fallback
var parallel = pronto.parallel
var race = pronto.race

View File

@@ -1,5 +1,6 @@
print("shop: starting")
var toml = use('toml')
print("shop: loaded toml")
var json = use('json')
var fd = use('fd')
var http = use('http')

View File

@@ -215,22 +215,19 @@ void script_startup(cell_rt *prt)
JS_PushGCRef(js, &env_ref);
env_ref.val = JS_NewObject(js);
// Create modules with GC rooting
JSGCRef os_ref, json_ref, nota_ref, wota_ref;
JS_PushGCRef(js, &os_ref);
JS_PushGCRef(js, &json_ref);
JS_PushGCRef(js, &nota_ref);
JS_PushGCRef(js, &wota_ref);
// Create and stone each module to make them GC-immovable
os_ref.val = js_os_use(js);
os_ref.val = JS_Stone(js, os_ref.val);
json_ref.val = js_json_use(js);
json_ref.val = JS_Stone(js, json_ref.val);
nota_ref.val = js_nota_use(js);
nota_ref.val = JS_Stone(js, nota_ref.val);
wota_ref.val = js_wota_use(js);
wota_ref.val = JS_Stone(js, wota_ref.val);
// Set properties on env (SetPropertyStr internally roots its args)
JS_SetPropertyStr(js, env_ref.val, "os", os_ref.val);
JS_SetPropertyStr(js, env_ref.val, "json", json_ref.val);
JS_SetPropertyStr(js, env_ref.val, "nota", nota_ref.val);