diff --git a/dump_mcode.cm b/dump_mcode.cm new file mode 100644 index 00000000..291b6e46 --- /dev/null +++ b/dump_mcode.cm @@ -0,0 +1,20 @@ +var fd = use("fd") +var json = use("json") +var tokenize = use("tokenize") +var parse = use("parse") +var fold = use("fold") +var mcode = use("mcode") +var streamline = use("streamline") + +var name = args[0] +var src = text(fd.slurp(name)) +var tok = tokenize(src, name) +var ast = parse(tok.tokens, src, name, tokenize) +var folded = fold(ast) +var compiled = mcode(folded) +var optimized = streamline(compiled) +var out = json.encode(optimized) +var f = fd.open("/tmp/mcode_dump.json", "w") +fd.write(f, out) +fd.close(f) +print("wrote /tmp/mcode_dump.json") diff --git a/internal/bootstrap.cm b/internal/bootstrap.cm index 09fb543f..26b10d95 100644 --- a/internal/bootstrap.cm +++ b/internal/bootstrap.cm @@ -1,5 +1,5 @@ // Hidden vars come from env: -// CLI mode (cell_init): os, args, core_path, shop_path, use_mcode +// CLI mode (cell_init): os, args, core_path, shop_path, emit_qbe // Actor spawn (script_startup): os, json, nota, wota, actorsym, init, core_path, shop_path // args[0] = script name, args[1..] = user args var load_internal = os.load_internal @@ -45,14 +45,11 @@ use_cache['tokenize'] = tokenize_mod use_cache['parse'] = parse_mod use_cache['fold'] = fold_mod -// Optionally load mcode compiler module -var mcode_mod = null +// Always load mcode compiler module +var mcode_mod = boot_load("mcode", boot_env) +use_cache['mcode'] = mcode_mod var streamline_mod = null var qbe_emit_mod = null -if (use_mcode) { - mcode_mod = boot_load("mcode", boot_env) - use_cache['mcode'] = mcode_mod -} // Warn if any .cm source is newer than its .mach bytecode function check_mach_stale() { @@ -146,33 +143,26 @@ function load_module(name, env) { // Load optimization pipeline modules (needs analyze to be defined) var qbe_macros = null -if (use_mcode) { - streamline_mod = load_module("streamline", boot_env) - use_cache['streamline'] = streamline_mod - if (emit_qbe) { - qbe_macros = load_module("qbe", boot_env) - qbe_emit_mod = load_module("qbe_emit", boot_env) - use_cache['qbe'] = qbe_macros - use_cache['qbe_emit'] = qbe_emit_mod - } +streamline_mod = load_module("streamline", boot_env) +use_cache['streamline'] = streamline_mod +if (emit_qbe) { + qbe_macros = load_module("qbe", boot_env) + qbe_emit_mod = load_module("qbe_emit", boot_env) + use_cache['qbe'] = qbe_macros + use_cache['qbe_emit'] = qbe_emit_mod } -// Run AST through either mcode or mach pipeline +// Run AST through mcode pipeline → register VM function run_ast(name, ast, env) { - var compiled = null - var optimized = null + var compiled = mcode_mod(ast) + var optimized = streamline_mod(compiled) var qbe_il = null - if (use_mcode) { - compiled = mcode_mod(ast) - optimized = streamline_mod(compiled) - if (emit_qbe) { - qbe_il = qbe_emit_mod(optimized, qbe_macros) - print(qbe_il) - return null - } - return mcode_run(name, json.encode(optimized), env) + if (emit_qbe) { + qbe_il = qbe_emit_mod(optimized, qbe_macros) + print(qbe_il) + return null } - return mach_eval_ast(name, json.encode(ast), env) + return mach_eval_mcode(name, json.encode(optimized), env) } // use() with ƿit pipeline for .cm modules diff --git a/internal/bootstrap.mach b/internal/bootstrap.mach index f2696e69..2dc682f4 100644 Binary files a/internal/bootstrap.mach and b/internal/bootstrap.mach differ diff --git a/source/cell.c b/source/cell.c index e1a9e073..e28f18df 100644 --- a/source/cell.c +++ b/source/cell.c @@ -211,9 +211,9 @@ void script_startup(cell_rt *prt) JS_SetPropertyStr(js, hidden_env, "init", JS_NULL); } - // Set args and use_mcode to null/false for actor spawn (not CLI mode) + // Set args to null for actor spawn (not CLI mode) JS_SetPropertyStr(js, hidden_env, "args", JS_NULL); - JS_SetPropertyStr(js, hidden_env, "use_mcode", JS_NewBool(js, 0)); + /* use_mcode no longer needed — new bootstrap always uses mcode pipeline */ if (core_path) JS_SetPropertyStr(js, hidden_env, "core_path", JS_NewString(js, core_path)); @@ -290,7 +290,7 @@ static void print_usage(const char *prog) printf("Options:\n"); printf(" --core Set core path directly (overrides CELL_CORE)\n"); printf(" --shop Set shop path (overrides CELL_SHOP)\n"); - printf(" --mcode