correct syntax errors in core scripts

This commit is contained in:
2026-02-15 22:23:04 -06:00
parent 913ec9afb1
commit 8f92870141
12 changed files with 93 additions and 56 deletions

View File

@@ -64,13 +64,16 @@ var format_ns = function(ns) {
var collect_benches = function(mod) {
var benches = []
var keys = null
var i = 0
var k = null
if (is_function(mod)) {
push(benches, {name: 'main', fn: mod})
} else if (is_object(mod)) {
var keys = array(mod)
var i = 0
keys = array(mod)
i = 0
while (i < length(keys)) {
var k = keys[i]
k = keys[i]
if (is_function(mod[k])) {
push(benches, {name: k, fn: mod[k]})
}
@@ -128,10 +131,11 @@ if (length(vm_benches) == 0) {
var native_mod = null
var native_benches = []
var has_native = fd.is_file(dylib_path)
var lib = null
if (has_native) {
print('loading native module: ' + dylib_path)
var lib = os.dylib_open(dylib_path)
lib = os.dylib_open(dylib_path)
native_mod = os.dylib_symbol(lib, symbol)
native_benches = collect_benches(native_mod)
} else {
@@ -146,27 +150,34 @@ print('samples: ' + text(iterations) + ' (warmup: ' + text(WARMUP) + ')')
print('')
var pad = function(s, n) {
while (length(s) < n) s = s + ' '
return s
var result = s
while (length(result) < n) result = result + ' '
return result
}
var i = 0
var b = null
var vm_result = null
var j = 0
var found = false
var nat_result = null
var speedup = 0
while (i < length(vm_benches)) {
var b = vm_benches[i]
var vm_result = run_bench(b.fn, 'vm')
b = vm_benches[i]
vm_result = run_bench(b.fn, 'vm')
print(pad(b.name, 20) + ' VM: ' + pad(format_ns(vm_result.median), 12) + ' (median) ' + format_ns(vm_result.mean) + ' (mean)')
// find matching native bench
var j = 0
var found = false
j = 0
found = false
while (j < length(native_benches)) {
if (native_benches[j].name == b.name) {
var nat_result = run_bench(native_benches[j].fn, 'native')
nat_result = run_bench(native_benches[j].fn, 'native')
print(pad('', 20) + ' NT: ' + pad(format_ns(nat_result.median), 12) + ' (median) ' + format_ns(nat_result.mean) + ' (mean)')
if (nat_result.median > 0) {
var speedup = vm_result.median / nat_result.median
speedup = vm_result.median / nat_result.median
print(pad('', 20) + ' speedup: ' + text(round(speedup * 100) / 100) + 'x')
}
found = true

View File

@@ -89,6 +89,7 @@ var dirs_to_delete = []
// Gather packages to clean
var packages_to_clean = []
var _gather = null
if (is_shop_scope) {
packages_to_clean = shop.list_packages()
@@ -99,7 +100,6 @@ if (is_shop_scope) {
// Single package
push(packages_to_clean, scope)
var _gather = null
if (deep) {
_gather = function() {
deps = pkg.gather_dependencies(scope)

View File

@@ -143,6 +143,9 @@ arrfor(roots, function(root) {
})
// Output based on format
var children = null
var j = 0
var output = null
if (format == 'tree') {
function print_tree(locator, prefix, is_last, visited) {
var node = null
@@ -178,8 +181,6 @@ if (format == 'tree') {
}
}
var children = null
var j = 0
for (i = 0; i < length(roots); i++) {
log.console(roots[i])
@@ -230,7 +231,7 @@ if (format == 'tree') {
log.console("}")
} else if (format == 'json') {
var output = {
output = {
nodes: [],
edges: []
}

View File

@@ -70,6 +70,7 @@ function use_core(path) {
var ast = null
var mcode_path = null
var mcode_blob = null
var _load_mod = null
// Build env: merge core_extras
env = {use: use_core}
@@ -79,45 +80,58 @@ function use_core(path) {
var cached_path = null
var mach_blob = null
var source_blob = null
var file_path = null
// Check for pre-compiled .cm.mcode JSON IR (generated by regen)
mcode_path = core_path + '/boot/' + replace(path, '/', '_') + '.cm.mcode'
if (fd.is_file(mcode_path)) {
mcode_blob = fd.slurp(mcode_path)
hash = content_hash(mcode_blob)
cached_path = cache_path(hash)
if (cached_path && fd.is_file(cached_path)) {
result = mach_load(fd.slurp(cached_path), env)
} else {
mach_blob = mach_compile_mcode_bin('core:' + path, text(mcode_blob))
if (cached_path) {
ensure_build_dir()
fd.slurpwrite(cached_path, mach_blob)
_load_mod = function() {
mcode_blob = fd.slurp(mcode_path)
hash = content_hash(mcode_blob)
cached_path = cache_path(hash)
if (cached_path && fd.is_file(cached_path)) {
result = mach_load(fd.slurp(cached_path), env)
} else {
mach_blob = mach_compile_mcode_bin('core:' + path, text(mcode_blob))
if (cached_path) {
ensure_build_dir()
fd.slurpwrite(cached_path, mach_blob)
}
result = mach_load(mach_blob, env)
}
result = mach_load(mach_blob, env)
} disruption {
print("use('" + path + "'): failed to load from " + mcode_path + "\n")
disrupt
}
_load_mod()
use_cache[cache_key] = result
return result
}
// Compile from source .cm file
var file_path = core_path + '/' + path + MOD_EXT
file_path = core_path + '/' + path + MOD_EXT
if (fd.is_file(file_path)) {
source_blob = fd.slurp(file_path)
hash = content_hash(source_blob)
cached_path = cache_path(hash)
if (cached_path && fd.is_file(cached_path)) {
result = mach_load(fd.slurp(cached_path), env)
} else {
script = text(source_blob)
ast = analyze(script, file_path)
mach_blob = compile_to_blob_fn('core:' + path, ast)
if (cached_path) {
ensure_build_dir()
fd.slurpwrite(cached_path, mach_blob)
_load_mod = function() {
source_blob = fd.slurp(file_path)
hash = content_hash(source_blob)
cached_path = cache_path(hash)
if (cached_path && fd.is_file(cached_path)) {
result = mach_load(fd.slurp(cached_path), env)
} else {
script = text(source_blob)
ast = analyze(script, file_path)
mach_blob = compile_to_blob_fn('core:' + path, ast)
if (cached_path) {
ensure_build_dir()
fd.slurpwrite(cached_path, mach_blob)
}
result = mach_load(mach_blob, env)
}
result = mach_load(mach_blob, env)
} disruption {
print("use('" + path + "'): failed to compile or load " + file_path + "\n")
disrupt
}
_load_mod()
use_cache[cache_key] = result
return result
}
@@ -238,6 +252,7 @@ var runtime_env = {}
// Populate core_extras with everything shop (and other core modules) need
core_extras.use_cache = use_cache
core_extras.core_path = core_path
core_extras.shop_path = shop_path
core_extras.analyze = analyze
core_extras.run_ast_fn = run_ast_fn

View File

@@ -77,7 +77,7 @@ if (cmd == 'list') {
pkg = args[1]
var _restore = null
_restore = null
if (link.remove(pkg)) {
// Try to restore the original package
log.console("Restoring " + pkg + "...")

View File

@@ -4,17 +4,19 @@
var toml = use('toml')
var fd = use('fd')
var blob = use('blob')
var os = use('os')
var runtime = use('runtime')
var global_shop_path = os.global_shop_path
var global_shop_path = runtime.shop_path
// Get the links file path (in the global shop)
function get_links_path() {
if (!global_shop_path) return null
return global_shop_path + '/link.toml'
}
// Get the packages directory (in the global shop)
function get_packages_dir() {
if (!global_shop_path) return null
return global_shop_path + '/packages'
}
@@ -62,7 +64,7 @@ var link_cache = null
Link.load = function() {
if (link_cache) return link_cache
var path = get_links_path()
if (!fd.is_file(path)) {
if (!path || !fd.is_file(path)) {
link_cache = {}
return link_cache
}

View File

@@ -50,9 +50,9 @@ if (args && length(args) > 0) {
var links = link.load()
var lock = shop.load_lock()
function print_deps(ctx, indent) {
function print_deps(ctx, raw_indent) {
var aliases = null
indent = indent || ""
var indent = raw_indent || ""
deps = null
var _read = function() {
deps = pkg.dependencies(ctx)

View File

@@ -2,9 +2,11 @@ var package = {}
var fd = use('fd')
var toml = use('toml')
var json = use('json')
var os = use('os')
var runtime = use('runtime')
var link = use('link')
var global_shop_path = runtime.shop_path
// Cache for loaded configs to avoid toml re-parsing corruption
var config_cache = {}
@@ -35,11 +37,11 @@ function get_path(name)
if (starts_with(link_target, '/'))
return link_target
// Otherwise it's another package name, resolve that
return os.global_shop_path + '/packages/' + replace(replace(link_target, '/', '_'), '@', '_')
return global_shop_path + '/packages/' + replace(replace(link_target, '/', '_'), '@', '_')
}
// Remote packages use nested directories, so don't transform slashes
return os.global_shop_path + '/packages/' + replace(name, '@', '_')
return global_shop_path + '/packages/' + replace(name, '@', '_')
}
package.load_config = function(name)

View File

@@ -86,24 +86,27 @@ function pack(sources, archive_path, read_dir) {
function add_recursive(path) {
var full_path = base_dir + "/" + path
var st = null
var list = null
var data = null
if (path == ".") full_path = base_dir
if (read_dir == null && path != ".") full_path = path
var st = fd.stat(full_path)
st = fd.stat(full_path)
if (!st) {
log.console("Could not stat " + full_path)
return
}
if (st.isDirectory) {
var list = fd.readdir(full_path)
list = fd.readdir(full_path)
arrfor(list, function(item) {
if (item == "." || item == "..") return
var sub = path == "." ? item : path + "/" + item
add_recursive(sub)
})
} else {
var data = fd.slurp(full_path)
data = fd.slurp(full_path)
if (data) {
writer.add_file(path, data)
log.console("Added " + path)

View File

@@ -140,6 +140,7 @@ var commit_str = null
var line = null
var cflags = null
var ldflags = null
var _show_flags = null
for (i = 0; i < length(sorted); i++) {
locator = sorted[i].locator
@@ -199,7 +200,7 @@ for (i = 0; i < length(sorted); i++) {
// Show compilation inputs if requested (verbose)
if (depth == 0) {
var _show_flags = function() {
_show_flags = function() {
cflags = pkg.get_flags(locator, 'CFLAGS', target_triple)
ldflags = pkg.get_flags(locator, 'LDFLAGS', target_triple)
if (length(cflags) > 0 || length(ldflags) > 0) {

View File

@@ -310,7 +310,6 @@ void actor_free(cell_rt *actor)
int actor_count = lockless_shlen(actors);
if (actor_count == 0) {
fprintf(stderr, "all actors are dead\n");
pthread_mutex_lock(&engine.lock);
engine.shutting_down = 1;
pthread_cond_broadcast(&engine.wake_cond);

View File

@@ -16,4 +16,7 @@ var ast = parse(result.tokens, src, filename, tokenize)
var folded = fold(ast)
var compiled = mcode(folded)
var optimized = streamline(compiled)
print(json.encode(optimized))
print(json.encode(optimized, true, function(k,v) {
if (is_array(v)) return json.encode(v)
return v
}))