intrinsics rewritten without ++, --, etc
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// Hidden vars (os, args, core_path, use_mcode) come from env
|
||||
// args[0] = script name, args[1..] = user args
|
||||
// Hidden vars come from env:
|
||||
// CLI mode (cell_init): os, args, core_path, use_mcode
|
||||
// Actor spawn (script_startup): os, json, nota, wota, actorsym, init, core_path
|
||||
var load_internal = os.load_internal
|
||||
function use_embed(name) {
|
||||
return load_internal("js_" + name + "_use")
|
||||
@@ -24,13 +25,14 @@ function use_basic(path) {
|
||||
|
||||
// Load a module from .mach bytecode, falling back to .ast.json
|
||||
function boot_load(name, env) {
|
||||
var mach_path = name + ".mach"
|
||||
var mach_path = core_path + '/' + name + ".mach"
|
||||
var data = null
|
||||
if (fd.is_file(mach_path)) {
|
||||
data = fd.slurp(mach_path)
|
||||
return mach_load(data, env)
|
||||
}
|
||||
data = text(fd.slurp(name + ".ast.json"))
|
||||
var ast_path = core_path + '/' + name + ".ast.json"
|
||||
data = text(fd.slurp(ast_path))
|
||||
return mach_eval_ast(name, data, env)
|
||||
}
|
||||
|
||||
@@ -91,7 +93,7 @@ function run_ast(name, ast, env) {
|
||||
}
|
||||
|
||||
// use() with ƿit pipeline for .cm modules
|
||||
function use(path) {
|
||||
function use_fn(path) {
|
||||
var file_path = path + '.cm'
|
||||
var script = null
|
||||
var ast = null
|
||||
@@ -106,7 +108,7 @@ function use(path) {
|
||||
if (fd.is_file(file_path)) {
|
||||
script = text(fd.slurp(file_path))
|
||||
ast = analyze(script, file_path)
|
||||
result = run_ast(path, ast, {use: use})
|
||||
result = run_ast(path, ast, {use: use_fn})
|
||||
use_cache[path] = result
|
||||
return result
|
||||
}
|
||||
@@ -117,21 +119,46 @@ function use(path) {
|
||||
return result
|
||||
}
|
||||
|
||||
// Load and run the user's program
|
||||
var program = args[0]
|
||||
var script_file = program
|
||||
|
||||
// Add .ce extension if not already present
|
||||
if (!ends_with(script_file, '.ce') && !ends_with(script_file, '.cm'))
|
||||
script_file = program + '.ce'
|
||||
|
||||
var user_args = []
|
||||
var _j = 1
|
||||
while (_j < length(args)) {
|
||||
push(user_args, args[_j])
|
||||
_j = _j + 1
|
||||
// Helper to load engine.cm and run it with given env
|
||||
function load_engine(env) {
|
||||
var engine_path = core_path + '/internal/engine.mach'
|
||||
if (fd.is_file(engine_path)) {
|
||||
var data = fd.slurp(engine_path)
|
||||
return mach_load(data, env)
|
||||
}
|
||||
engine_path = core_path + '/internal/engine.cm'
|
||||
var engine_src = text(fd.slurp(engine_path))
|
||||
var engine_ast = analyze(engine_src, engine_path)
|
||||
return run_ast('engine', engine_ast, env)
|
||||
}
|
||||
|
||||
var script = text(fd.slurp(script_file))
|
||||
var ast = analyze(script, script_file)
|
||||
run_ast(program, ast, {use: use, args: user_args, json: json})
|
||||
// Detect mode and route
|
||||
// CLI mode has 'args'; actor spawn mode has 'init'
|
||||
if (args != null) {
|
||||
// CLI mode — run script directly
|
||||
var program = args[0]
|
||||
var user_args = []
|
||||
var _j = 1
|
||||
while (_j < length(args)) {
|
||||
push(user_args, args[_j])
|
||||
_j = _j + 1
|
||||
}
|
||||
|
||||
var 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'
|
||||
|
||||
var script = text(fd.slurp(script_file))
|
||||
var ast = analyze(script, script_file)
|
||||
run_ast(program, ast, {use: use_fn, args: user_args, json: json})
|
||||
} else {
|
||||
// Actor spawn mode — load engine.cm with full actor env
|
||||
load_engine({
|
||||
os: os, actorsym: actorsym, init: init,
|
||||
core_path: core_path, json: json, nota: nota, wota: wota,
|
||||
analyze: analyze, run_ast_fn: run_ast
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user