progress on aot

This commit is contained in:
2026-02-16 21:58:45 -06:00
parent a1ee7dd458
commit 4b7cde9400
13 changed files with 789 additions and 421 deletions

View File

@@ -37,7 +37,7 @@ function boot_load(name) {
}
mcode_blob = fd.slurp(mcode_path)
mach_blob = mach_compile_mcode_bin(name, text(mcode_blob))
return mach_load(mach_blob, {use: use_embed})
return mach_load(mach_blob, stone({use: use_embed}))
}
var tokenize_mod = boot_load("tokenize")

View File

@@ -22,6 +22,9 @@ function use_embed(name) {
return load_internal("js_core_" + name + "_use")
}
// These duplicate C builtins from runtime.c, but are needed because the GC can
// lose properties on the global object after compaction. The runtime_env provides
// a stable way for modules to access them via env_record linking.
function logical(val1) {
if (val1 == 0 || val1 == false || val1 == "false" || val1 == null)
return false;
@@ -101,7 +104,7 @@ function load_pipeline_module(name, env) {
}
// Load compilation pipeline
var pipeline_env = {use: use_embed}
var pipeline_env = stone({use: use_embed})
var tokenize_mod = load_pipeline_module('tokenize', pipeline_env)
var parse_mod = load_pipeline_module('parse', pipeline_env)
var fold_mod = load_pipeline_module('fold', pipeline_env)
@@ -222,6 +225,7 @@ function use_core(path) {
// Build env: merge core_extras
env = {use: use_core}
arrfor(array(core_extras), function(k) { env[k] = core_extras[k] })
env = stone(env)
var hash = null
var cached_path = null
@@ -398,7 +402,9 @@ var parallel = pronto.parallel
var race = pronto.race
var sequence = pronto.sequence
// Fill runtime_env (same object reference shop holds)
// Fill runtime_env — includes duplicates of C builtins because the GC can
// lose global object properties after compaction. Modules resolve these via
// env_record, not the global.
runtime_env.logical = logical
runtime_env.some = some
runtime_env.every = every
@@ -1045,6 +1051,7 @@ $_.clock(_ => {
}
env.args = _cell.args.arg
env.log = log
env = stone(env)
var source_blob = fd.slurp(prog_path)
var hash = content_hash(source_blob)

View File

@@ -445,8 +445,8 @@ static JSValue js_os_dylib_close(JSContext *js, JSValue self, int argc, JSValue
/* Load a native .cm module from a dylib handle.
Uses cell_rt_native_module_load from qbe_helpers.c */
extern JSValue cell_rt_native_module_load(JSContext *ctx, void *dl_handle);
extern JSValue cell_rt_native_module_load_named(JSContext *ctx, void *dl_handle, const char *sym_name);
extern JSValue cell_rt_native_module_load(JSContext *ctx, void *dl_handle, JSValue env);
extern JSValue cell_rt_native_module_load_named(JSContext *ctx, void *dl_handle, const char *sym_name, JSValue env);
static JSValue js_os_native_module_load(JSContext *js, JSValue self, int argc, JSValue *argv)
{
@@ -457,7 +457,8 @@ static JSValue js_os_native_module_load(JSContext *js, JSValue self, int argc, J
if (!handle)
return JS_ThrowTypeError(js, "First argument must be a dylib object");
return cell_rt_native_module_load(js, handle);
JSValue env = (argc >= 2) ? argv[1] : JS_NULL;
return cell_rt_native_module_load(js, handle, env);
}
static JSValue js_os_native_module_load_named(JSContext *js, JSValue self, int argc, JSValue *argv)
@@ -473,7 +474,8 @@ static JSValue js_os_native_module_load_named(JSContext *js, JSValue self, int a
if (!sym_name)
return JS_EXCEPTION;
JSValue result = cell_rt_native_module_load_named(js, handle, sym_name);
JSValue env = (argc >= 3) ? argv[2] : JS_NULL;
JSValue result = cell_rt_native_module_load_named(js, handle, sym_name, env);
JS_FreeCString(js, sym_name);
return result;
}
@@ -653,8 +655,8 @@ static const JSCFunctionListEntry js_os_funcs[] = {
MIST_FUNC_DEF(os, dylib_close, 1),
MIST_FUNC_DEF(os, dylib_symbol, 2),
MIST_FUNC_DEF(os, dylib_has_symbol, 2),
MIST_FUNC_DEF(os, native_module_load, 1),
MIST_FUNC_DEF(os, native_module_load_named, 2),
MIST_FUNC_DEF(os, native_module_load, 2),
MIST_FUNC_DEF(os, native_module_load_named, 3),
MIST_FUNC_DEF(os, embedded_module, 1),
MIST_FUNC_DEF(os, load_internal, 1),
MIST_FUNC_DEF(os, internal_exists, 1),

View File

@@ -1009,6 +1009,7 @@ function execute_module(info)
env = inject_env(inject)
pkg = file_info.package
env.use = make_use_fn(pkg)
env = stone(env)
// Load compiled bytecode with env
used = mach_load(mod_resolve.symbol, env)
@@ -1044,6 +1045,7 @@ Shop.use = function use(path, package_context) {
if (embedded) {
embed_env = inject_env(SHOP_DEFAULT_INJECT)
embed_env.use = make_use_fn(package_context)
embed_env = stone(embed_env)
use_cache[embed_key] = mach_load(embedded, embed_env)
return use_cache[embed_key]
}
@@ -1608,6 +1610,7 @@ Shop.load_as_mach = function(path, pkg) {
inject = Shop.script_inject_for(file_info)
env = inject_env(inject)
env.use = make_use_fn(file_info.package)
env = stone(env)
return mach_load(compiled, env)
}
@@ -1697,9 +1700,15 @@ Shop.use_native = function(path, package_context) {
var handle = os.dylib_open(dylib_path)
if (!handle) { print('Failed to open native dylib: ' + dylib_path); disrupt }
// Build env with runtime functions and capabilities
var inject = Shop.script_inject_for(file_info)
var env = inject_env(inject)
env.use = make_use_fn(pkg)
env = stone(env)
if (sym_name)
return os.native_module_load_named(handle, sym_name)
return os.native_module_load(handle)
return os.native_module_load_named(handle, sym_name, env)
return os.native_module_load(handle, env)
}
return Shop