diff --git a/Makefile b/Makefile index d9a9593e..d870f506 100755 --- a/Makefile +++ b/Makefile @@ -48,12 +48,12 @@ cell_main: source/main.c libcell_runtime.dylib # Regenerate .mach bytecode when any .cm source changes .mach.stamp: $(MACH_SOURCES) - ./cell --core . regen.cm + ./cell --core . regen @touch $@ # Force-regenerate all .mach bytecode files regen: - ./cell --core . regen.cm + ./cell --core . regen @touch .mach.stamp # Create the cell shop directories diff --git a/internal/bootstrap.cm b/internal/bootstrap.cm index d2c422dd..027de66c 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, emit_qbe, dump_mach +// CLI mode (cell_init): os, args, core_path, shop_path // 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 @@ -48,7 +48,6 @@ use_cache['fold'] = fold_mod var mcode_mod = boot_load("mcode", boot_env) use_cache['mcode'] = mcode_mod var streamline_mod = null -var qbe_emit_mod = null // Warn if any .cm source is newer than its .mach bytecode function check_mach_stale() { @@ -83,7 +82,7 @@ function check_mach_stale() { } if (length(stale) > 0) { print("warning: bytecode is stale for: " + text(stale, ", ") + "\n") - print("run 'make regen' or './cell --core . regen.cm' to update\n") + print("run 'make regen' to update\n") } } check_mach_stale() @@ -145,30 +144,13 @@ function load_module(name, env) { } // Load optimization pipeline modules (needs analyze to be defined) -var qbe_macros = null 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 mcode pipeline → register VM function run_ast(name, ast, env) { var compiled = mcode_mod(ast) var optimized = streamline_mod(compiled) - var qbe_il = null - if (emit_qbe) { - qbe_il = qbe_emit_mod(optimized, qbe_macros) - print(qbe_il) - return null - } - if (dump_mach) { - mach_dump_mcode(name, json.encode(optimized), env) - return null - } return mach_eval_mcode(name, json.encode(optimized), env) } @@ -234,45 +216,26 @@ function load_engine(env) { var program = null var user_args = [] var _j = 0 -var script_file = null -var script = null -var ast = null if (args != null) { - // CLI mode — parse args + // CLI mode — always run as actor program (.ce) program = args[0] + if (!program) { + print("error: no program specified\n") + disrupt + } _j = 1 while (_j < length(args)) { push(user_args, args[_j]) _j = _j + 1 } - // Resolve script file: try .cm then .ce in CWD then core_path - script_file = program - if (!ends_with(script_file, '.ce') && !ends_with(script_file, '.cm')) - script_file = program + '.cm' - - if (!fd.is_file(script_file)) - script_file = core_path + '/' + program + '.cm' - if (!fd.is_file(script_file)) - script_file = program + '.ce' - if (!fd.is_file(script_file)) - script_file = core_path + '/' + program + '.ce' - - if (ends_with(script_file, '.ce')) { - // Actor script — delegate to engine - load_engine({ - os: os, actorsym: actorsym, - init: {program: program, arg: user_args}, - core_path: core_path, shop_path: shop_path, json: json, - analyze: analyze, run_ast_fn: run_ast - }) - } else { - // Module script — run directly - script = text(fd.slurp(script_file)) - ast = analyze(script, script_file) - run_ast(program, ast, {use: use_fn, args: user_args, json: json}) - } + load_engine({ + os: os, actorsym: actorsym, + init: {program: program, arg: user_args}, + core_path: core_path, shop_path: shop_path, json: json, + analyze: analyze, run_ast_fn: run_ast + }) } else { // Actor spawn mode — load engine.cm with full actor env load_engine({ diff --git a/internal/engine.cm b/internal/engine.cm index 86f6f255..94300b57 100644 --- a/internal/engine.cm +++ b/internal/engine.cm @@ -728,7 +728,7 @@ function report_to_overling(msg) var program = _cell.args.program if (!program) { - log.error('No program specified. Usage: cell [args...]') + log.error('No program specified. Usage: cell [args...]') os.exit(1) } @@ -819,7 +819,7 @@ actor_mod.setname(_cell.args.program) var prog = _cell.args.program if (ends_with(prog, '.cm')) { - os.print(`error: ${prog} is a module (.cm), not an actor (.ce). Run it with: cell --core ${prog}\n`) + os.print(`error: ${prog} is a module (.cm), not a program (.ce)\n`) os.exit(1) } if (ends_with(prog, '.ce')) prog = text(prog, 0, -3) @@ -868,6 +868,8 @@ $_.clock(_ => { env.use = function(path) { var ck = 'core/' + path if (use_cache[ck]) return use_cache[ck] + var core_mod = use_core(path) + if (core_mod) return core_mod return shop.use(path, pkg) } env.args = _cell.args.arg diff --git a/regen.cm b/regen.ce similarity index 95% rename from regen.cm rename to regen.ce index 2abaeee2..9b81516c 100644 --- a/regen.cm +++ b/regen.ce @@ -1,5 +1,5 @@ -// regen.cm — regenerate .mach bytecode files -// Run with: ./cell --core . regen.cm +// regen.ce — regenerate .mach bytecode files +// Run with: ./cell --core . regen var fd = use("fd") var json = use("json") diff --git a/source/cell.c b/source/cell.c index bbabfdaf..0d7b38a0 100644 --- a/source/cell.c +++ b/source/cell.c @@ -269,13 +269,11 @@ static int run_test_suite(size_t heap_size) static void print_usage(const char *prog) { - printf("Usage: %s [options]