Merge branch 'master' into gen_dylib

This commit is contained in:
2026-02-16 22:07:56 -06:00
24 changed files with 2002 additions and 200 deletions

View File

@@ -76,7 +76,21 @@ function ensure_build_dir() {
return dir
}
// Load a pipeline module from cache, with boot/ seed fallback
// Load a boot seed module (for compiling pipeline modules on cache miss)
function boot_load(name) {
var mcode_path = core_path + '/boot/' + name + '.cm.mcode'
var mcode_blob = null
var mach_blob = null
if (!fd.is_file(mcode_path)) {
print("error: missing boot seed: " + name + "\n")
disrupt
}
mcode_blob = fd.slurp(mcode_path)
mach_blob = mach_compile_mcode_bin(name, text(mcode_blob))
return mach_load(mach_blob, {use: use_embed})
}
// Load a pipeline module from cache; on miss compile from source via boot chain
function load_pipeline_module(name, env) {
var source_path = core_path + '/' + name + '.cm'
var source_blob = null
@@ -85,14 +99,48 @@ function load_pipeline_module(name, env) {
var mcode_path = null
var mcode_blob = null
var mach_blob = null
var src = null
var boot_tok = null
var boot_par = null
var boot_fld = null
var boot_mc = null
var tok_result = null
var ast = null
var compiled = null
var mcode_json = null
if (fd.is_file(source_path)) {
source_blob = fd.slurp(source_path)
hash = content_hash(source_blob)
cached = cache_path(hash)
if (cached && fd.is_file(cached))
return mach_load(fd.slurp(cached), env)
// Cache miss: compile from source using boot seed pipeline
mcode_path = core_path + '/boot/' + name + '.cm.mcode'
if (fd.is_file(mcode_path)) {
boot_tok = boot_load("tokenize")
boot_par = boot_load("parse")
boot_fld = boot_load("fold")
boot_mc = boot_load("mcode")
src = text(source_blob)
tok_result = boot_tok(src, source_path)
ast = boot_par(tok_result.tokens, src, source_path, boot_tok)
if (ast.errors != null && length(ast.errors) > 0) {
print("error: failed to compile pipeline module: " + name + "\n")
disrupt
}
ast = boot_fld(ast)
compiled = boot_mc(ast)
mcode_json = json.encode(compiled)
mach_blob = mach_compile_mcode_bin(name, mcode_json)
if (cached) {
ensure_build_dir()
fd.slurpwrite(cached, mach_blob)
}
return mach_load(mach_blob, env)
}
}
// Boot seed fallback
// Last resort: boot seed as runtime (no source file found)
mcode_path = core_path + '/boot/' + name + '.cm.mcode'
if (fd.is_file(mcode_path)) {
mcode_blob = fd.slurp(mcode_path)
@@ -386,6 +434,7 @@ os.run_ast_fn = run_ast_fn
os.run_ast_noopt_fn = run_ast_noopt_fn
core_extras.core_json = json
core_extras.actor_api = $_
core_extras.log = log
core_extras.runtime_env = runtime_env
core_extras.content_hash = content_hash
core_extras.cache_path = cache_path