fix fd.c bugs

This commit is contained in:
2026-02-10 14:21:49 -06:00
parent 54673e4a04
commit fe5dc6ecc9
10 changed files with 815 additions and 794 deletions

View File

@@ -56,9 +56,13 @@ var packages_path = shop_path ? shop_path + '/packages' : null
var use_cache = {}
use_cache['core/os'] = os
// Extra env properties added as engine initializes (log, runtime fns, etc.)
var core_extras = {}
// Load a core module from the file system
function use_core(path) {
var cache_key = 'core/' + path
var env = null
if (use_cache[cache_key])
return use_cache[cache_key]
@@ -67,10 +71,15 @@ function use_core(path) {
var script = null
var ast = null
// Build env: merge core_extras, include C embed as 'native' if available
env = {use: use_core}
arrfor(array(core_extras), function(k) { env[k] = core_extras[k] })
if (sym) env.native = sym
// Check for pre-compiled .mach file first
var mach_path = core_path + '/' + path + '.mach'
if (fd.is_file(mach_path)) {
result = mach_load(fd.slurp(mach_path), {use: use_core})
result = mach_load(fd.slurp(mach_path), env)
use_cache[cache_key] = result
return result
}
@@ -80,7 +89,7 @@ function use_core(path) {
if (fd.is_file(file_path)) {
script = text(fd.slurp(file_path))
ast = analyze(script, file_path)
result = run_ast_fn('core:' + path, ast, {use: use_core})
result = run_ast_fn('core:' + path, ast, env)
use_cache[cache_key] = result
return result
}
@@ -90,6 +99,9 @@ function use_core(path) {
return sym
}
// Load full modules via use_core (extends C embeds with .cm additions, and caches)
fd = use_core('fd')
use_core('js')
var blob = use_core('blob')
function actor() {
@@ -223,6 +235,9 @@ var runtime_env = {
sequence: sequence
}
// Make runtime functions available to modules loaded via use_core
arrfor(array(runtime_env), function(k) { core_extras[k] = runtime_env[k] })
// Pass to os for shop to access
os.runtime_env = runtime_env
@@ -845,7 +860,11 @@ $_.clock(_ => {
}
var pkg = file_info ? file_info.package : null
env.use = function(path) { return shop.use(path, pkg) }
env.use = function(path) {
var ck = 'core/' + path
if (use_cache[ck]) return use_cache[ck]
return shop.use(path, pkg)
}
env.args = _cell.args.arg
env.log = log