Files
cell/internal/bootstrap.cm
2026-02-09 10:56:15 -06:00

41 lines
867 B
Plaintext

// 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})