bootstrap

This commit is contained in:
2026-02-09 10:56:15 -06:00
parent 0503acb7e6
commit e04ab4c30c
7 changed files with 131 additions and 77 deletions

40
internal/bootstrap.cm Normal file
View File

@@ -0,0 +1,40 @@
// Hidden vars (os, program) come from env
var load_internal = os.load_internal
function use_embed(name) {
return load_internal("js_" + name + "_use")
}
var fd = use_embed('fd')
var use_cache = {}
use_cache['fd'] = fd
use_cache['os'] = os
function use(path) {
if (use_cache[path])
return use_cache[path];
var file_path = path + '.cm'
var script = null
var result = null
var exports = null
if (fd.is_file(file_path)) {
script = text(fd.slurp(file_path))
exports = {}
mach_eval(path, script, {use: use, exports: exports})
use_cache[path] = exports
return exports
}
// Try embedded C module
result = use_embed(replace(path, '/', '_'))
use_cache[path] = result
return result
}
// Load and run the user's program
var blob = fd.slurp(program)
stone(blob)
var script = text(blob)
mach_eval(program, script, {use: use})

View File

@@ -578,7 +578,7 @@ static const JSCFunctionListEntry js_os_funcs[] = {
JSValue js_os_use(JSContext *js) {
JS_NewClassID(&js_dylib_class_id);
JS_NewClass(js, js_dylib_class_id, &js_dylib_class);
JSValue mod = JS_NewObject(js);
JS_SetPropertyFunctionList(js,mod,js_os_funcs,countof(js_os_funcs));
return mod;