parse.ce and tokenize.ce

This commit is contained in:
2026-02-09 11:56:09 -06:00
parent 45556c344d
commit 368511f666
6 changed files with 3002 additions and 19 deletions

View File

@@ -1,14 +1,17 @@
// Hidden vars (os, program) come from env
// Hidden vars (os, args) come from env
// args[0] = script filename, args[1..] = user args
var load_internal = os.load_internal
function use_embed(name) {
return load_internal("js_" + name + "_use")
}
var fd = use_embed('fd')
var json = use_embed('json')
var use_cache = {}
use_cache['fd'] = fd
use_cache['os'] = os
use_cache['json'] = json
function use(path) {
if (use_cache[path])
@@ -34,7 +37,15 @@ function use(path) {
}
// Load and run the user's program
var program = args[0]
var user_args = []
var _i = 1
while (_i < length(args)) {
push(user_args, args[_i])
_i = _i + 1
}
var blob = fd.slurp(program)
stone(blob)
var script = text(blob)
mach_eval(program, script, {use: use})
mach_eval(program, script, {use: use, args: user_args, json: json})