Merge branch 'gen_dylib'

This commit is contained in:
2026-02-17 08:59:05 -06:00
23 changed files with 96093 additions and 87168 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,30 +22,6 @@ function use_embed(name) {
return load_internal("js_core_" + name + "_use")
}
function logical(val1) {
if (val1 == 0 || val1 == false || val1 == "false" || val1 == null)
return false;
if (val1 == 1 || val1 == true || val1 == "true")
return true;
return null;
}
function some(arr, pred) {
return find(arr, pred) != null
}
function every(arr, pred) {
return find(arr, x => not(pred(x))) == null
}
function starts_with(str, prefix) {
return search(str, prefix) == 0
}
function ends_with(str, suffix) {
return search(str, suffix, -length(suffix)) != null
}
var fd = use_embed('internal_fd')
var js = use_embed('js')
var crypto = use_embed('crypto')
@@ -84,7 +60,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}))
}
// Load a pipeline module from cache; on miss compile from source via boot chain
@@ -149,7 +125,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)
@@ -270,6 +246,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
@@ -447,12 +424,6 @@ var parallel = pronto.parallel
var race = pronto.race
var sequence = pronto.sequence
// Fill runtime_env (same object reference shop holds)
runtime_env.logical = logical
runtime_env.some = some
runtime_env.every = every
runtime_env.starts_with = starts_with
runtime_env.ends_with = ends_with
runtime_env.actor = actor
runtime_env.is_actor = is_actor
runtime_env.log = log
@@ -1109,6 +1080,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

@@ -959,6 +959,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)
@@ -994,6 +995,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]
}
@@ -1587,6 +1589,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)
}
@@ -1676,9 +1679,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