clean up cli
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -728,7 +728,7 @@ function report_to_overling(msg)
|
||||
var program = _cell.args.program
|
||||
|
||||
if (!program) {
|
||||
log.error('No program specified. Usage: cell <program.ce> [args...]')
|
||||
log.error('No program specified. Usage: cell <program> [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 <path> ${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
|
||||
|
||||
Reference in New Issue
Block a user