Merge branch 'fix_compile_warnings'

This commit is contained in:
2026-02-20 15:34:50 -06:00
40 changed files with 282 additions and 312 deletions

View File

@@ -10,7 +10,7 @@ var os = use('internal/os')
var fd = use('fd') var fd = use('fd')
if (length(args) < 1) { if (length(args) < 1) {
print('usage: cell --dev bench_native.ce <module.cm> [iterations]') log.bench('usage: cell --dev bench_native.ce <module.cm> [iterations]')
return return
} }
@@ -117,12 +117,12 @@ var run_bench = function(fn, label) {
// --- Load VM module --- // --- Load VM module ---
print('loading VM module: ' + file) log.bench('loading VM module: ' + file)
var vm_mod = use(name) var vm_mod = use(name)
var vm_benches = collect_benches(vm_mod) var vm_benches = collect_benches(vm_mod)
if (length(vm_benches) == 0) { if (length(vm_benches) == 0) {
print('no benchmarkable functions found in ' + file) log.bench('no benchmarkable functions found in ' + file)
return return
} }
@@ -134,20 +134,20 @@ var has_native = fd.is_file(dylib_path)
var lib = null var lib = null
if (has_native) { if (has_native) {
print('loading native module: ' + dylib_path) log.bench('loading native module: ' + dylib_path)
lib = os.dylib_open(dylib_path) lib = os.dylib_open(dylib_path)
native_mod = os.dylib_symbol(lib, symbol) native_mod = os.dylib_symbol(lib, symbol)
native_benches = collect_benches(native_mod) native_benches = collect_benches(native_mod)
} else { } else {
print('no ' + dylib_path + ' found -- VM-only benchmarking') log.bench('no ' + dylib_path + ' found -- VM-only benchmarking')
print(' hint: cell --dev compile.ce ' + file) log.bench(' hint: cell --dev compile.ce ' + file)
} }
// --- Run benchmarks --- // --- Run benchmarks ---
print('') log.bench('')
print('samples: ' + text(iterations) + ' (warmup: ' + text(WARMUP) + ')') log.bench('samples: ' + text(iterations) + ' (warmup: ' + text(WARMUP) + ')')
print('') log.bench('')
var pad = function(s, n) { var pad = function(s, n) {
var result = s var result = s
@@ -166,7 +166,7 @@ while (i < length(vm_benches)) {
b = vm_benches[i] b = vm_benches[i]
vm_result = run_bench(b.fn, 'vm') 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)') log.bench(pad(b.name, 20) + ' VM: ' + pad(format_ns(vm_result.median), 12) + ' (median) ' + format_ns(vm_result.mean) + ' (mean)')
// find matching native bench // find matching native bench
j = 0 j = 0
@@ -174,11 +174,11 @@ while (i < length(vm_benches)) {
while (j < length(native_benches)) { while (j < length(native_benches)) {
if (native_benches[j].name == b.name) { if (native_benches[j].name == b.name) {
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)') log.bench(pad('', 20) + ' NT: ' + pad(format_ns(nat_result.median), 12) + ' (median) ' + format_ns(nat_result.mean) + ' (mean)')
if (nat_result.median > 0) { if (nat_result.median > 0) {
speedup = vm_result.median / nat_result.median speedup = vm_result.median / nat_result.median
print(pad('', 20) + ' speedup: ' + text(round(speedup * 100) / 100) + 'x') log.bench(pad('', 20) + ' speedup: ' + text(round(speedup * 100) / 100) + 'x')
} }
found = true found = true
} }
@@ -186,9 +186,9 @@ while (i < length(vm_benches)) {
} }
if (has_native && !found) { if (has_native && !found) {
print(pad('', 20) + ' NT: (no matching function)') log.bench(pad('', 20) + ' NT: (no matching function)')
} }
print('') log.bench('')
i = i + 1 i = i + 1
} }

View File

@@ -180,7 +180,7 @@ Build.compile_file = function(pkg, file, target, opts) {
var core_dir = null var core_dir = null
if (!fd.is_file(src_path)) { if (!fd.is_file(src_path)) {
print('Source file not found: ' + src_path) log.error('Source file not found: ' + src_path)
return null return null
} }
@@ -244,8 +244,8 @@ Build.compile_file = function(pkg, file, target, opts) {
var cmd_str = text(cmd_parts, ' ') var cmd_str = text(cmd_parts, ' ')
if (_opts.verbose) { if (_opts.verbose) {
print('[verbose] CFLAGS: ' + text(cflags, ' ')) log.build('[verbose] CFLAGS: ' + text(cflags, ' '))
print('[verbose] compile: ' + cmd_str) log.build('[verbose] compile: ' + cmd_str)
} }
// Two-level cache: quick hash for deps file, full hash for object // Two-level cache: quick hash for deps file, full hash for object
@@ -259,7 +259,7 @@ Build.compile_file = function(pkg, file, target, opts) {
// Check for cached failure (skip files that previously failed to compile) // Check for cached failure (skip files that previously failed to compile)
if (fd.is_file(fail_path)) { if (fd.is_file(fail_path)) {
if (_opts.verbose) print('[verbose] skipping ' + file + ' (cached failure)') if (_opts.verbose) log.build('[verbose] skipping ' + file + ' (cached failure)')
log.shop('skip ' + file + ' (cached failure)') log.shop('skip ' + file + ' (cached failure)')
return null return null
} }
@@ -276,7 +276,7 @@ Build.compile_file = function(pkg, file, target, opts) {
full_content = hash_all_deps(cmd_str, deps) full_content = hash_all_deps(cmd_str, deps)
obj_path = cache_path(full_content, SALT_OBJ) obj_path = cache_path(full_content, SALT_OBJ)
if (fd.is_file(obj_path)) { if (fd.is_file(obj_path)) {
if (_opts.verbose) print('[verbose] cache hit: ' + file) if (_opts.verbose) log.build('[verbose] cache hit: ' + file)
log.shop('cache hit ' + file) log.shop('cache hit ' + file)
return obj_path return obj_path
} }
@@ -292,7 +292,7 @@ Build.compile_file = function(pkg, file, target, opts) {
// Check if object exists (might exist from previous build with same deps) // Check if object exists (might exist from previous build with same deps)
if (fd.is_file(obj_path)) { if (fd.is_file(obj_path)) {
fd.slurpwrite(deps_path, stone(blob(text(deps, '\n')))) fd.slurpwrite(deps_path, stone(blob(text(deps, '\n'))))
if (_opts.verbose) print('[verbose] cache hit: ' + file + ' (after dep scan)') if (_opts.verbose) log.build('[verbose] cache hit: ' + file + ' (after dep scan)')
log.shop('cache hit ' + file + ' (after dep scan)') log.shop('cache hit ' + file + ' (after dep scan)')
return obj_path return obj_path
} }
@@ -318,11 +318,11 @@ Build.compile_file = function(pkg, file, target, opts) {
if (missing != null) { if (missing != null) {
err_lines = array(err_text, "\n") err_lines = array(err_text, "\n")
first_err = length(err_lines) > 0 ? err_lines[0] : err_text first_err = length(err_lines) > 0 ? err_lines[0] : err_text
print(file + ': ' + first_err + ' (SDK not installed?)') log.error(file + ': ' + first_err + ' (SDK not installed?)')
} else { } else {
print('Compilation failed: ' + file) log.error('Compilation failed: ' + file)
if (err_text) print(err_text) if (err_text) log.error(err_text)
else print('Command: ' + full_cmd) else log.error('Command: ' + full_cmd)
} }
// Cache the failure so we don't retry on every build // Cache the failure so we don't retry on every build
fd.slurpwrite(fail_path, stone(blob(err_text || 'compilation failed'))) fd.slurpwrite(fail_path, stone(blob(err_text || 'compilation failed')))
@@ -424,7 +424,7 @@ Build.build_module_dylib = function(pkg, file, target, opts) {
var ret = null var ret = null
if (_opts.verbose) { if (_opts.verbose) {
print('[verbose] LDFLAGS: ' + text(resolved_ldflags, ' ')) log.build('[verbose] LDFLAGS: ' + text(resolved_ldflags, ' '))
} }
if (!fd.is_file(dylib_path)) { if (!fd.is_file(dylib_path)) {
@@ -459,12 +459,12 @@ Build.build_module_dylib = function(pkg, file, target, opts) {
push(cmd_parts, '"' + dylib_path + '"') push(cmd_parts, '"' + dylib_path + '"')
cmd_str = text(cmd_parts, ' ') cmd_str = text(cmd_parts, ' ')
if (_opts.verbose) print('[verbose] link: ' + cmd_str) if (_opts.verbose) log.build('[verbose] link: ' + cmd_str)
log.shop('linking ' + file) log.shop('linking ' + file)
log.console('Linking module ' + file + ' -> ' + fd.basename(dylib_path)) log.console('Linking module ' + file + ' -> ' + fd.basename(dylib_path))
ret = os.system(cmd_str) ret = os.system(cmd_str)
if (ret != 0) { if (ret != 0) {
print('Linking failed: ' + file) log.error('Linking failed: ' + file)
return null return null
} }
} else { } else {
@@ -562,7 +562,7 @@ Build.build_static = function(packages, target, output, buildtype) {
}) })
if (length(all_objects) == 0) { if (length(all_objects) == 0) {
print('No object files to link'); disrupt log.error('No object files to link'); disrupt
} }
// Link // Link
@@ -596,7 +596,7 @@ Build.build_static = function(packages, target, output, buildtype) {
log.console('Linking ' + out_path) log.console('Linking ' + out_path)
var ret = os.system(cmd_str) var ret = os.system(cmd_str)
if (ret != 0) { if (ret != 0) {
print('Linking failed: ' + cmd_str); disrupt log.error('Linking failed: ' + cmd_str); disrupt
} }
log.console('Built ' + out_path) log.console('Built ' + out_path)
@@ -625,7 +625,7 @@ function compile_native_single(il_parts, cc, tmp_prefix, extra_flags) {
fd.slurpwrite(s_path, stone(blob(asm_text))) fd.slurpwrite(s_path, stone(blob(asm_text)))
rc = os.system(cc + _extra + ' -c ' + s_path + ' -o ' + o_path) rc = os.system(cc + _extra + ' -c ' + s_path + ' -o ' + o_path)
if (rc != 0) { if (rc != 0) {
print('Assembly failed'); disrupt log.error('Assembly failed'); disrupt
} }
return [o_path] return [o_path]
} }
@@ -667,7 +667,7 @@ Build.compile_native = function(src_path, target, buildtype, pkg) {
var qbe_rt_path = null var qbe_rt_path = null
if (!fd.is_file(src_path)) { if (!fd.is_file(src_path)) {
print('Source file not found: ' + src_path); disrupt log.error('Source file not found: ' + src_path); disrupt
} }
var tc = toolchains[_target] var tc = toolchains[_target]
@@ -709,7 +709,7 @@ Build.compile_native = function(src_path, target, buildtype, pkg) {
qbe_rt_path = shop.get_package_dir('core') + '/src/qbe_rt.c' qbe_rt_path = shop.get_package_dir('core') + '/src/qbe_rt.c'
rc = os.system(cc + san_flags + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC') rc = os.system(cc + san_flags + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC')
if (rc != 0) { if (rc != 0) {
print('QBE runtime stubs compilation failed'); disrupt log.error('QBE runtime stubs compilation failed'); disrupt
} }
} }
@@ -729,7 +729,7 @@ Build.compile_native = function(src_path, target, buildtype, pkg) {
rc = os.system(link_cmd) rc = os.system(link_cmd)
if (rc != 0) { if (rc != 0) {
print('Linking native dylib failed for: ' + src_path); disrupt log.error('Linking native dylib failed for: ' + src_path); disrupt
} }
log.console('Built native: ' + fd.basename(dylib_path)) log.console('Built native: ' + fd.basename(dylib_path))
@@ -781,7 +781,7 @@ Build.compile_native_ir = function(optimized, src_path, opts) {
qbe_rt_path = shop.get_package_dir('core') + '/src/qbe_rt.c' qbe_rt_path = shop.get_package_dir('core') + '/src/qbe_rt.c'
rc = os.system(cc + san_flags + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC') rc = os.system(cc + san_flags + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC')
if (rc != 0) { if (rc != 0) {
print('QBE runtime stubs compilation failed'); disrupt log.error('QBE runtime stubs compilation failed'); disrupt
} }
} }
@@ -801,7 +801,7 @@ Build.compile_native_ir = function(optimized, src_path, opts) {
rc = os.system(link_cmd) rc = os.system(link_cmd)
if (rc != 0) { if (rc != 0) {
print('Linking native dylib failed for: ' + src_path); disrupt log.error('Linking native dylib failed for: ' + src_path); disrupt
} }
log.console('Built native: ' + fd.basename(dylib_path)) log.console('Built native: ' + fd.basename(dylib_path))
@@ -817,7 +817,7 @@ Build.compile_native_ir = function(optimized, src_path, opts) {
// Returns the raw mach bytes as a blob // Returns the raw mach bytes as a blob
Build.compile_cm_to_mach = function(src_path) { Build.compile_cm_to_mach = function(src_path) {
if (!fd.is_file(src_path)) { if (!fd.is_file(src_path)) {
print('Source file not found: ' + src_path); disrupt log.error('Source file not found: ' + src_path); disrupt
} }
var json = use('json') var json = use('json')
var optimized = shop.compile_file(src_path) var optimized = shop.compile_file(src_path)
@@ -907,7 +907,7 @@ Build.build_all_dynamic = function(target, buildtype, opts) {
}) })
// Print build report // Print build report
print('\n--- Build Report ---') log.build('--- Build Report ---')
arrfor(results, function(r) { arrfor(results, function(r) {
var pkg_dir = shop.get_package_dir(r.package) var pkg_dir = shop.get_package_dir(r.package)
var c_files = pkg_tools.get_c_files(r.package, _target, true) var c_files = pkg_tools.get_c_files(r.package, _target, true)
@@ -919,10 +919,10 @@ Build.build_all_dynamic = function(target, buildtype, opts) {
total_fail = total_fail + fail_count total_fail = total_fail + fail_count
if (file_count == 0) return if (file_count == 0) return
var status = fail_count == 0 ? 'OK' : `${ok_count}/${file_count}` var status = fail_count == 0 ? 'OK' : `${ok_count}/${file_count}`
print(` ${r.package}: ${status}`) log.build(` ${r.package}: ${status}`)
}) })
print(`Total: ${total_ok}/${total_files} compiled, ${total_fail} failed`) log.build(`Total: ${total_ok}/${total_files} compiled, ${total_fail} failed`)
print('--------------------\n') log.build('--------------------')
return results return results
} }

View File

@@ -96,7 +96,7 @@ function resolve(path, must_exist) {
}, false, true) }, false, true)
if (!mount) { if (!mount) {
print("Unknown mount point: @" + mount_name); disrupt log.error("Unknown mount point: @" + mount_name); disrupt
} }
return { mount: mount, path: rel_path } return { mount: mount, path: rel_path }
@@ -114,7 +114,7 @@ function resolve(path, must_exist) {
} }
if (must_exist) { if (must_exist) {
print("File not found in any mount: " + npath); disrupt log.error("File not found in any mount: " + npath); disrupt
} }
} }
@@ -152,7 +152,7 @@ function mount(source, name) {
} else { } else {
zip = miniz.read(blob) zip = miniz.read(blob)
if (!is_object(zip) || !is_function(zip.count)) { if (!is_object(zip) || !is_function(zip.count)) {
print("Invalid archive file (not zip or qop): " + source); disrupt log.error("Invalid archive file (not zip or qop): " + source); disrupt
} }
mount_info.type = 'zip' mount_info.type = 'zip'
@@ -160,7 +160,7 @@ function mount(source, name) {
mount_info.zip_blob = blob mount_info.zip_blob = blob
} }
} else { } else {
print("Unsupported mount source type: " + source); disrupt log.error("Unsupported mount source type: " + source); disrupt
} }
push(mounts, mount_info) push(mounts, mount_info)
@@ -176,13 +176,13 @@ function slurp(path) {
var res = resolve(path, true) var res = resolve(path, true)
var data = null var data = null
var full_path = null var full_path = null
if (!res) { print("File not found: " + path); disrupt } if (!res) { log.error("File not found: " + path); disrupt }
if (res.mount.type == 'zip') { if (res.mount.type == 'zip') {
return res.mount.handle.slurp(res.path) return res.mount.handle.slurp(res.path)
} else if (res.mount.type == 'qop') { } else if (res.mount.type == 'qop') {
data = res.mount.handle.read(res.path) data = res.mount.handle.read(res.path)
if (!data) { print("File not found in qop: " + path); disrupt } if (!data) { log.error("File not found in qop: " + path); disrupt }
return data return data
} else { } else {
full_path = fd.join_paths(res.mount.source, res.path) full_path = fd.join_paths(res.mount.source, res.path)
@@ -211,7 +211,7 @@ function stat(path) {
var mod = null var mod = null
var s = null var s = null
var full_path = null var full_path = null
if (!res) { print("File not found: " + path); disrupt } if (!res) { log.error("File not found: " + path); disrupt }
if (res.mount.type == 'zip') { if (res.mount.type == 'zip') {
mod = res.mount.handle.mod(res.path) mod = res.mount.handle.mod(res.path)
@@ -222,7 +222,7 @@ function stat(path) {
} }
} else if (res.mount.type == 'qop') { } else if (res.mount.type == 'qop') {
s = res.mount.handle.stat(res.path) s = res.mount.handle.stat(res.path)
if (!s) { print("File not found in qop: " + path); disrupt } if (!s) { log.error("File not found in qop: " + path); disrupt }
return { return {
filesize: s.size, filesize: s.size,
modtime: s.modtime, modtime: s.modtime,
@@ -253,7 +253,7 @@ function mount_package(name) {
var dir = shop.get_package_dir(name) var dir = shop.get_package_dir(name)
if (!dir) { if (!dir) {
print("Package not found: " + name); disrupt log.error("Package not found: " + name); disrupt
} }
mount(dir, name) mount(dir, name)
@@ -267,7 +267,7 @@ function rm(path) {
var res = resolve(path, true) var res = resolve(path, true)
var full_path = null var full_path = null
var st = null var st = null
if (res.mount.type != 'fs') { print("Cannot delete from non-fs mount"); disrupt } if (res.mount.type != 'fs') { log.error("Cannot delete from non-fs mount"); disrupt }
full_path = fd.join_paths(res.mount.source, res.path) full_path = fd.join_paths(res.mount.source, res.path)
st = fd.stat(full_path) st = fd.stat(full_path)

View File

@@ -15,7 +15,7 @@ var show = function(v) {
} }
if (length(args) < 1) { if (length(args) < 1) {
print('usage: cell --dev compare_aot.ce <file>') log.compile('usage: cell --dev compare_aot.ce <file>')
return return
} }
@@ -26,7 +26,7 @@ if (!fd_mod.is_file(file)) {
else if (!ends_with(file, '.cm') && fd_mod.is_file(file + '.cm')) else if (!ends_with(file, '.cm') && fd_mod.is_file(file + '.cm'))
file = file + '.cm' file = file + '.cm'
else { else {
print('file not found: ' + file) log.error('file not found: ' + file)
return return
} }
} }
@@ -54,14 +54,14 @@ var t5 = time.number()
var optimized = streamline_mod(compiled) var optimized = streamline_mod(compiled)
var t6 = time.number() var t6 = time.number()
print('--- front-end timing ---') log.compile('--- front-end timing ---')
print(' read: ' + text(t1 - t0) + 's') log.compile(' read: ' + text(t1 - t0) + 's')
print(' tokenize: ' + text(t2 - t1) + 's') log.compile(' tokenize: ' + text(t2 - t1) + 's')
print(' parse: ' + text(t3 - t2) + 's') log.compile(' parse: ' + text(t3 - t2) + 's')
print(' fold: ' + text(t4 - t3) + 's') log.compile(' fold: ' + text(t4 - t3) + 's')
print(' mcode: ' + text(t5 - t4) + 's') log.compile(' mcode: ' + text(t5 - t4) + 's')
print(' streamline: ' + text(t6 - t5) + 's') log.compile(' streamline: ' + text(t6 - t5) + 's')
print(' total: ' + text(t6 - t0) + 's') log.compile(' total: ' + text(t6 - t0) + 's')
// Shared env for both paths — only non-intrinsic runtime functions. // Shared env for both paths — only non-intrinsic runtime functions.
// Intrinsics (starts_with, ends_with, logical, some, every, etc.) live on // Intrinsics (starts_with, ends_with, logical, some, every, etc.) live on
@@ -79,15 +79,15 @@ var env = stone({
var result_interp = null var result_interp = null
var interp_ok = false var interp_ok = false
var run_interp = function() { var run_interp = function() {
print('--- interpreted ---') log.compile('--- interpreted ---')
var mcode_json = json.encode(optimized) var mcode_json = json.encode(optimized)
var mach_blob = mach_compile_mcode_bin(abs, mcode_json) var mach_blob = mach_compile_mcode_bin(abs, mcode_json)
result_interp = mach_load(mach_blob, env) result_interp = mach_load(mach_blob, env)
interp_ok = true interp_ok = true
print('result: ' + show(result_interp)) log.compile('result: ' + show(result_interp))
} disruption { } disruption {
interp_ok = true interp_ok = true
print('(disruption escaped from interpreted run)') log.compile('(disruption escaped from interpreted run)')
} }
run_interp() run_interp()
@@ -95,36 +95,36 @@ run_interp()
var result_native = null var result_native = null
var native_ok = false var native_ok = false
var run_native = function() { var run_native = function() {
print('\n--- native ---') log.compile('\n--- native ---')
var dylib_path = build.compile_native_ir(optimized, abs, null) var dylib_path = build.compile_native_ir(optimized, abs, null)
print('dylib: ' + dylib_path) log.compile('dylib: ' + dylib_path)
var handle = os.dylib_open(dylib_path) var handle = os.dylib_open(dylib_path)
if (!handle) { if (!handle) {
print('failed to open dylib') log.error('failed to open dylib')
return return
} }
result_native = os.native_module_load(handle, env) result_native = os.native_module_load(handle, env)
native_ok = true native_ok = true
print('result: ' + show(result_native)) log.compile('result: ' + show(result_native))
} disruption { } disruption {
native_ok = true native_ok = true
print('(disruption escaped from native run)') log.compile('(disruption escaped from native run)')
} }
run_native() run_native()
// --- Comparison --- // --- Comparison ---
print('\n--- comparison ---') log.compile('\n--- comparison ---')
var s_interp = show(result_interp) var s_interp = show(result_interp)
var s_native = show(result_native) var s_native = show(result_native)
if (interp_ok && native_ok) { if (interp_ok && native_ok) {
if (s_interp == s_native) { if (s_interp == s_native) {
print('MATCH') log.compile('MATCH')
} else { } else {
print('MISMATCH') log.error('MISMATCH')
print(' interp: ' + s_interp) log.error(' interp: ' + s_interp)
print(' native: ' + s_native) log.error(' native: ' + s_native)
} }
} else { } else {
if (!interp_ok) print('interpreted run failed') if (!interp_ok) log.error('interpreted run failed')
if (!native_ok) print('native run failed') if (!native_ok) log.error('native run failed')
} }

View File

@@ -10,13 +10,13 @@ var build = use('build')
var fd = use('fd') var fd = use('fd')
if (length(args) < 1) { if (length(args) < 1) {
print('usage: cell compile <file.cm|file.ce>') log.compile('usage: cell compile <file.cm|file.ce>')
return return
} }
var file = args[0] var file = args[0]
if (!fd.is_file(file)) { if (!fd.is_file(file)) {
print('file not found: ' + file) log.error('file not found: ' + file)
return return
} }

View File

@@ -395,16 +395,6 @@ Returns the opposite logical. Returns null for non-logicals.
Returns a requestor that starts all requestors in the array. Results are collected into an array matching the input order. Optional throttle limits concurrent requestors. Optional need specifies the minimum number of successes required. See [Requestors](/docs/requestors/) for usage. Returns a requestor that starts all requestors in the array. Results are collected into an array matching the input order. Optional throttle limits concurrent requestors. Optional need specifies the minimum number of successes required. See [Requestors](/docs/requestors/) for usage.
### print(value)
Print a value to standard output.
```javascript
print("hello")
print(42)
print(`result: ${x}`)
```
### race(requestor_array, throttle, need) ### race(requestor_array, throttle, need)
Like parallel, but returns as soon as the needed number of results are obtained. Default need is 1. Unfinished requestors are cancelled. See [Requestors](/docs/requestors/) for usage. Like parallel, but returns as soon as the needed number of results are obtained. Default need is 1. Unfinished requestors are cancelled. See [Requestors](/docs/requestors/) for usage.

View File

@@ -595,7 +595,7 @@ var safe_divide = function(a, b) {
if (b == 0) disrupt if (b == 0) disrupt
return a / b return a / b
} disruption { } disruption {
print("something went wrong") log.error("something went wrong")
} }
``` ```

View File

@@ -8,6 +8,6 @@ var optimized = shop.compile_file(args[0])
var instrs = optimized.main.instructions var instrs = optimized.main.instructions
var i = 0 var i = 0
while (i < length(instrs)) { while (i < length(instrs)) {
print(text(i) + ': ' + json.encode(instrs[i])) log.compile(text(i) + ': ' + json.encode(instrs[i]))
i = i + 1 i = i + 1
} }

View File

@@ -86,8 +86,7 @@ if (mode == "span") {
if (result == null) { if (result == null) {
log.console("Nothing found at " + filename + ":" + text(line) + ":" + text(col)) log.console("Nothing found at " + filename + ":" + text(line) + ":" + text(col))
} else { } else {
print(json.encode(result, true)) log.compile(json.encode(result, true))
print("\n")
} }
} }
@@ -116,8 +115,7 @@ if (mode == "symbol") {
if (result == null || length(result.symbols) == 0) { if (result == null || length(result.symbols) == 0) {
log.console("Symbol '" + symbol_name + "' not found in " + filename) log.console("Symbol '" + symbol_name + "' not found in " + filename)
} else { } else {
print(json.encode(result, true)) log.compile(json.encode(result, true))
print("\n")
} }
} else if (length(files) > 1) { } else if (length(files) > 1) {
indexes = [] indexes = []
@@ -132,8 +130,7 @@ if (mode == "symbol") {
if (result == null || length(result.symbols) == 0) { if (result == null || length(result.symbols) == 0) {
log.console("Symbol '" + symbol_name + "' not found in " + text(length(files)) + " files") log.console("Symbol '" + symbol_name + "' not found in " + text(length(files)) + " files")
} else { } else {
print(json.encode(result, true)) log.compile(json.encode(result, true))
print("\n")
} }
} }
} }

View File

@@ -4,4 +4,4 @@ var json = use("json")
var shop = use("internal/shop") var shop = use("internal/shop")
var filename = args[0] var filename = args[0]
var folded = shop.analyze_file(filename) var folded = shop.analyze_file(filename)
print(json.encode(folded)) log.compile(json.encode(folded))

View File

@@ -52,8 +52,7 @@ if (output_path != null) {
fd.slurpwrite(output_path, out) fd.slurpwrite(output_path, out)
log.console('Wrote index to ' + output_path) log.console('Wrote index to ' + output_path)
} else { } else {
print(out) log.compile(out)
print("\n")
} }
$stop() $stop()

View File

@@ -34,7 +34,7 @@ function boot_load(name) {
var mcode_blob = null var mcode_blob = null
var mach_blob = null var mach_blob = null
if (!fd.is_file(mcode_path)) { if (!fd.is_file(mcode_path)) {
print("error: missing seed: " + name + "\n") os.print("error: missing seed: " + name + "\n")
disrupt disrupt
} }
mcode_blob = fd.slurp(mcode_path) mcode_blob = fd.slurp(mcode_path)
@@ -60,9 +60,9 @@ function analyze(src, filename) {
e = ast.errors[_i] e = ast.errors[_i]
msg = e.message msg = e.message
if (e.line != null && e.column != null) if (e.line != null && e.column != null)
print(`${filename}:${text(e.line)}:${text(e.column)}: error: ${msg}`) os.print(`${filename}:${text(e.line)}:${text(e.column)}: error: ${msg}\n`)
else else
print(`${filename}: error: ${msg}`) os.print(`${filename}: error: ${msg}\n`)
_i = _i + 1 _i = _i + 1
} }
disrupt disrupt
@@ -105,4 +105,4 @@ while (_i < length(seed_files)) {
compile_and_cache(entry.name, core_path + '/' + entry.path) compile_and_cache(entry.name, core_path + '/' + entry.path)
_i = _i + 1 _i = _i + 1
} }
print("bootstrap: cache seeded\n") os.print("bootstrap: cache seeded\n")

View File

@@ -58,7 +58,7 @@ function boot_load(name) {
var mcode_blob = null var mcode_blob = null
var mach_blob = null var mach_blob = null
if (!fd.is_file(mcode_path)) { if (!fd.is_file(mcode_path)) {
print("error: missing boot seed: " + name + "\n") os.print("error: missing boot seed: " + name + "\n")
disrupt disrupt
} }
mcode_blob = fd.slurp(mcode_path) mcode_blob = fd.slurp(mcode_path)
@@ -103,7 +103,7 @@ function load_pipeline_module(name, env) {
tok_result = boot_tok(src, source_path) tok_result = boot_tok(src, source_path)
ast = boot_par(tok_result.tokens, src, source_path, boot_tok) ast = boot_par(tok_result.tokens, src, source_path, boot_tok)
if (ast.errors != null && length(ast.errors) > 0) { if (ast.errors != null && length(ast.errors) > 0) {
print("error: failed to compile pipeline module: " + name + "\n") os.print("error: failed to compile pipeline module: " + name + "\n")
disrupt disrupt
} }
ast = boot_fld(ast) ast = boot_fld(ast)
@@ -126,7 +126,7 @@ function load_pipeline_module(name, env) {
mach_blob = mach_compile_mcode_bin(name, text(mcode_blob)) mach_blob = mach_compile_mcode_bin(name, text(mcode_blob))
return mach_load(mach_blob, env) return mach_load(mach_blob, env)
} }
print("error: cannot load pipeline module: " + name + "\n") os.print("error: cannot load pipeline module: " + name + "\n")
disrupt disrupt
} }
@@ -166,9 +166,9 @@ function analyze(src, filename) {
col = e.column col = e.column
if (msg != prev_msg || line != prev_line) { if (msg != prev_msg || line != prev_line) {
if (line != null && col != null) if (line != null && col != null)
print(`${filename}:${text(line)}:${text(col)}: error: ${msg}`) os.print(`${filename}:${text(line)}:${text(col)}: error: ${msg}\n`)
else else
print(`${filename}: error: ${msg}`) os.print(`${filename}: error: ${msg}\n`)
} }
prev_line = line prev_line = line
prev_msg = msg prev_msg = msg
@@ -473,7 +473,7 @@ function use_core(path) {
result = mach_load(mach_blob, env) result = mach_load(mach_blob, env)
} }
} disruption { } disruption {
print("use('" + path + "'): failed to compile or load " + file_path + "\n") os.print("use('" + path + "'): failed to compile or load " + file_path + "\n")
disrupt disrupt
} }
_load_mod() _load_mod()
@@ -701,7 +701,7 @@ function load_log_config() {
terminal: { terminal: {
type: "console", type: "console",
format: "pretty", format: "pretty",
channels: ["console", "error", "system"], channels: ["*"],
stack: ["error"] stack: ["error"]
} }
} }

View File

@@ -131,7 +131,7 @@ function package_in_shop(package) {
function abs_path_to_package(package_dir) function abs_path_to_package(package_dir)
{ {
if (!fd.is_file(package_dir + '/cell.toml')) { if (!fd.is_file(package_dir + '/cell.toml')) {
print('Not a valid package directory (no cell.toml): ' + package_dir) log.error('Not a valid package directory (no cell.toml): ' + package_dir)
disrupt disrupt
} }
@@ -339,12 +339,12 @@ Shop.resolve_package_info = function(pkg) {
// Verify if a package name is valid and return status // Verify if a package name is valid and return status
Shop.verify_package_name = function(pkg) { Shop.verify_package_name = function(pkg) {
if (!pkg) { print("Empty package name"); disrupt } if (!pkg) { log.error("Empty package name"); disrupt }
if (pkg == 'local') { print("local is not a valid package name"); disrupt } if (pkg == 'local') { log.error("local is not a valid package name"); disrupt }
if (pkg == 'core') { print("core is not a valid package name"); disrupt } if (pkg == 'core') { log.error("core is not a valid package name"); disrupt }
if (search(pkg, '://') != null) { if (search(pkg, '://') != null) {
print(`Invalid package name: ${pkg}; did you mean ${array(pkg, '://')[1]}?`) log.error(`Invalid package name: ${pkg}; did you mean ${array(pkg, '://')[1]}?`)
disrupt disrupt
} }
} }
@@ -667,10 +667,10 @@ var _streamline_mod = null
// Compile a module and return its bytecode blob. // Compile a module and return its bytecode blob.
// The bytecode is cached on disk by content hash. // The bytecode is cached on disk by content hash.
function resolve_mod_fn(path, pkg) { function resolve_mod_fn(path, pkg) {
if (!fd.is_file(path)) { print(`path ${path} is not a file`); disrupt } if (!fd.is_file(path)) { log.error(`path ${path} is not a file`); disrupt }
var content = text(fd.slurp(path)) var content = text(fd.slurp(path))
if (length(content) == 0) { print(`${path}: empty file`); disrupt } if (length(content) == 0) { log.error(`${path}: empty file`); disrupt }
var content_key = stone(blob(content)) var content_key = stone(blob(content))
var native_result = null var native_result = null
var cached = null var cached = null
@@ -745,7 +745,7 @@ function resolve_mod_fn(path, pkg) {
if (!_mcode_mod) _mcode_mod = use_cache['core/mcode'] || use_cache['mcode'] if (!_mcode_mod) _mcode_mod = use_cache['core/mcode'] || use_cache['mcode']
if (!_streamline_mod) _streamline_mod = use_cache['core/streamline'] || use_cache['streamline'] if (!_streamline_mod) _streamline_mod = use_cache['core/streamline'] || use_cache['streamline']
if (!_mcode_mod || !_streamline_mod) { if (!_mcode_mod || !_streamline_mod) {
print(`error: compiler modules not loaded (mcode=${_mcode_mod != null}, streamline=${_streamline_mod != null})`) log.error(`error: compiler modules not loaded (mcode=${_mcode_mod != null}, streamline=${_streamline_mod != null})`)
disrupt disrupt
} }
ast = analyze(content, path) ast = analyze(content, path)
@@ -764,7 +764,7 @@ function resolve_mod_fn(path, pkg) {
return compiled return compiled
} }
print(`Module ${path} could not be loaded: no artifact found or all methods blocked by policy`) log.error(`Module ${path} could not be loaded: no artifact found or all methods blocked by policy`)
disrupt disrupt
} }
@@ -1253,7 +1253,7 @@ function execute_module(info)
log.shop(`Module could not be found (c_resolve scope=${info.c_resolve.scope}, mod_resolve scope=${info.mod_resolve.scope}, cache_key=${info.cache_key})`); disrupt log.shop(`Module could not be found (c_resolve scope=${info.c_resolve.scope}, mod_resolve scope=${info.mod_resolve.scope}, cache_key=${info.cache_key})`); disrupt
} }
if (!used) { print(`Module ${info} returned null`); disrupt } if (!used) { log.error(`Module ${info} returned null`); disrupt }
return used return used
} }
@@ -1559,7 +1559,7 @@ Shop.extract = function(pkg) {
var zip_blob = get_package_zip(pkg) var zip_blob = get_package_zip(pkg)
if (!zip_blob) { if (!zip_blob) {
print("No zip blob available for " + pkg) log.error("No zip blob available for " + pkg)
disrupt disrupt
} }
@@ -1729,7 +1729,7 @@ Shop.sync_with_deps = function(pkg, opts) {
function install_zip(zip_blob, target_dir) { function install_zip(zip_blob, target_dir) {
var zip = miniz.read(zip_blob) var zip = miniz.read(zip_blob)
if (!zip) { print("Failed to read zip archive"); disrupt } if (!zip) { log.error("Failed to read zip archive"); disrupt }
if (fd.is_link(target_dir)) fd.unlink(target_dir) if (fd.is_link(target_dir)) fd.unlink(target_dir)
if (fd.is_dir(target_dir)) fd.rmdir(target_dir, 1) if (fd.is_dir(target_dir)) fd.rmdir(target_dir, 1)
@@ -1947,7 +1947,7 @@ Shop.load_as_mach = function(path, pkg) {
var inject = null var inject = null
var env = null var env = null
if (!locator) { print('Module ' + path + ' not found'); disrupt } if (!locator) { log.error('Module ' + path + ' not found'); disrupt }
file_path = locator.path file_path = locator.path
content = text(fd.slurp(file_path)) content = text(fd.slurp(file_path))
@@ -1972,7 +1972,7 @@ Shop.load_as_mach = function(path, pkg) {
if (!_mcode_mod) _mcode_mod = use_cache['core/mcode'] || use_cache['mcode'] if (!_mcode_mod) _mcode_mod = use_cache['core/mcode'] || use_cache['mcode']
if (!_streamline_mod) _streamline_mod = use_cache['core/streamline'] || use_cache['streamline'] if (!_streamline_mod) _streamline_mod = use_cache['core/streamline'] || use_cache['streamline']
if (!_mcode_mod || !_streamline_mod) { if (!_mcode_mod || !_streamline_mod) {
print('error: compiler modules not loaded') log.error('error: compiler modules not loaded')
disrupt disrupt
} }
ast = analyze(content, file_path) ast = analyze(content, file_path)
@@ -2008,7 +2008,7 @@ Shop.load_as_dylib = function(path, pkg) {
var inject = null var inject = null
var env = null var env = null
if (!locator) { print('Module ' + path + ' not found'); disrupt } if (!locator) { log.error('Module ' + path + ' not found'); disrupt }
file_path = locator.path file_path = locator.path
if (!real_pkg) { if (!real_pkg) {
@@ -2076,7 +2076,7 @@ Shop.use_native = function(path, package_context) {
var src_path = path var src_path = path
if (!starts_with(path, '/')) if (!starts_with(path, '/'))
src_path = fd.realpath(path) src_path = fd.realpath(path)
if (!fd.is_file(src_path)) { print('File not found: ' + path); disrupt } if (!fd.is_file(src_path)) { log.error('File not found: ' + path); disrupt }
var file_info = Shop.file_info(src_path) var file_info = Shop.file_info(src_path)
var pkg = file_info.package || package_context var pkg = file_info.package || package_context
@@ -2089,7 +2089,7 @@ Shop.use_native = function(path, package_context) {
var dylib_path = build.compile_native(src_path, null, null, pkg) var dylib_path = build.compile_native(src_path, null, null, pkg)
var handle = os.dylib_open(dylib_path) var handle = os.dylib_open(dylib_path)
if (!handle) { print('Failed to open native dylib: ' + dylib_path); disrupt } if (!handle) { log.error('Failed to open native dylib: ' + dylib_path); disrupt }
// Build env with runtime functions and capabilities // Build env with runtime functions and capabilities
var inject = Shop.script_inject_for(file_info) var inject = Shop.script_inject_for(file_info)

View File

@@ -55,22 +55,22 @@ while (i < length(args)) {
} else if (!starts_with(arg, "--")) { } else if (!starts_with(arg, "--")) {
filename = arg filename = arg
} else { } else {
print(`unknown option: ${arg}\n`) log.error(`unknown option: ${arg}`)
print("usage: cell --core . ir_report.ce [options] <file>\n") log.error("usage: cell --core . ir_report.ce [options] <file>")
$stop() $stop()
} }
i = i + 1 i = i + 1
} }
if (filename == null) { if (filename == null) {
print("usage: cell --core . ir_report.ce [options] <file.cm|file.ce>\n") log.compile("usage: cell --core . ir_report.ce [options] <file.cm|file.ce>")
print(" --summary per-pass JSON summaries (default)\n") log.compile(" --summary per-pass JSON summaries (default)")
print(" --events include rewrite events\n") log.compile(" --events include rewrite events")
print(" --types include type deltas\n") log.compile(" --types include type deltas")
print(" --ir-before=PASS print canonical IR before PASS\n") log.compile(" --ir-before=PASS print canonical IR before PASS")
print(" --ir-after=PASS print canonical IR after PASS\n") log.compile(" --ir-after=PASS print canonical IR after PASS")
print(" --ir-all print canonical IR before/after every pass\n") log.compile(" --ir-all print canonical IR before/after every pass")
print(" --full everything\n") log.compile(" --full everything")
$stop() $stop()
} }
@@ -114,8 +114,7 @@ var optimized = streamline(compiled, log)
// --- Output --- // --- Output ---
var emit = function(obj) { var emit = function(obj) {
print(json.encode(obj)) log.compile(json.encode(obj))
print("\n")
} }
// Pass summaries (always) // Pass summaries (always)

20
link.cm
View File

@@ -53,7 +53,7 @@ Link.load = function() {
if (cfg && cfg.links) link_cache = cfg.links if (cfg && cfg.links) link_cache = cfg.links
else link_cache = {} else link_cache = {}
} disruption { } disruption {
print("Warning: Failed to load link.toml\n") log.build("Warning: Failed to load link.toml")
link_cache = {} link_cache = {}
} }
_load() _load()
@@ -73,7 +73,7 @@ Link.add = function(canonical, target, shop) {
// Validate canonical package exists in shop // Validate canonical package exists in shop
var lock = shop.load_lock() var lock = shop.load_lock()
if (!lock[canonical]) { if (!lock[canonical]) {
print('Package ' + canonical + ' is not installed. Install it first with: cell get ' + canonical + '\n') log.error('Package ' + canonical + ' is not installed. Install it first with: cell get ' + canonical)
disrupt disrupt
} }
@@ -81,7 +81,7 @@ Link.add = function(canonical, target, shop) {
if (starts_with(target, '/')) { if (starts_with(target, '/')) {
// Local path - must have cell.toml // Local path - must have cell.toml
if (!fd.is_file(target + '/cell.toml')) { if (!fd.is_file(target + '/cell.toml')) {
print('Target ' + target + ' is not a valid package (no cell.toml)\n') log.error('Target ' + target + ' is not a valid package (no cell.toml)')
disrupt disrupt
} }
} else { } else {
@@ -110,7 +110,7 @@ Link.add = function(canonical, target, shop) {
var dep_locator = cfg.dependencies[alias] var dep_locator = cfg.dependencies[alias]
// Skip local dependencies that don't exist // Skip local dependencies that don't exist
if (starts_with(dep_locator, '/') && !fd.is_dir(dep_locator)) { if (starts_with(dep_locator, '/') && !fd.is_dir(dep_locator)) {
print(" Skipping missing local dependency: " + dep_locator + "\n") log.build(" Skipping missing local dependency: " + dep_locator)
return return
} }
// Install the dependency if not already in shop // Install the dependency if not already in shop
@@ -118,18 +118,18 @@ Link.add = function(canonical, target, shop) {
shop.get(dep_locator) shop.get(dep_locator)
shop.extract(dep_locator) shop.extract(dep_locator)
} disruption { } disruption {
print(` Warning: Could not install dependency ${dep_locator}\n`) log.build(` Warning: Could not install dependency ${dep_locator}`)
} }
_get_dep() _get_dep()
}) })
} }
} disruption { } disruption {
print(` Warning: Could not read dependencies from ${toml_path}\n`) log.build(` Warning: Could not read dependencies from ${toml_path}`)
} }
_install_deps() _install_deps()
} }
print("Linked " + canonical + " -> " + target + "\n") log.build("Linked " + canonical + " -> " + target)
return true return true
} }
@@ -141,12 +141,12 @@ Link.remove = function(canonical) {
var target_dir = get_package_abs_dir(canonical) var target_dir = get_package_abs_dir(canonical)
if (fd.is_link(target_dir)) { if (fd.is_link(target_dir)) {
fd.unlink(target_dir) fd.unlink(target_dir)
print("Removed symlink at " + target_dir + "\n") log.build("Removed symlink at " + target_dir)
} }
delete links[canonical] delete links[canonical]
Link.save(links) Link.save(links)
print("Unlinked " + canonical + "\n") log.build("Unlinked " + canonical)
return true return true
} }
@@ -161,7 +161,7 @@ Link.clear = function() {
}) })
Link.save({}) Link.save({})
print("Cleared all links\n") log.build("Cleared all links")
return true return true
} }

View File

@@ -31,7 +31,7 @@ if (!filename) {
var compiled = shop.mcode_file(filename) var compiled = shop.mcode_file(filename)
if (!show_pretty) { if (!show_pretty) {
print(json.encode(compiled)) log.compile(json.encode(compiled))
$stop() $stop()
} }
@@ -68,16 +68,16 @@ var dump_function = function(func, name) {
var operands = null var operands = null
var pc_str = null var pc_str = null
var op_str = null var op_str = null
print(`\n=== ${name} (args=${text(nr_args)}, slots=${text(nr_slots)}, closures=${text(nr_close)}) ===`) log.compile(`\n=== ${name} (args=${text(nr_args)}, slots=${text(nr_slots)}, closures=${text(nr_close)}) ===`)
if (instrs == null || length(instrs) == 0) { if (instrs == null || length(instrs) == 0) {
print(" (empty)") log.compile(" (empty)")
return null return null
} }
while (i < length(instrs)) { while (i < length(instrs)) {
instr = instrs[i] instr = instrs[i]
if (is_text(instr)) { if (is_text(instr)) {
if (!starts_with(instr, "_nop_")) { if (!starts_with(instr, "_nop_")) {
print(`${instr}:`) log.compile(`${instr}:`)
} }
} else if (is_array(instr)) { } else if (is_array(instr)) {
op = instr[0] op = instr[0]
@@ -91,7 +91,7 @@ var dump_function = function(func, name) {
operands = text(parts, ", ") operands = text(parts, ", ")
pc_str = pad_right(text(pc), 5) pc_str = pad_right(text(pc), 5)
op_str = pad_right(op, 14) op_str = pad_right(op, 14)
print(` ${pc_str} ${op_str} ${operands}`) log.compile(` ${pc_str} ${op_str} ${operands}`)
pc = pc + 1 pc = pc + 1
} }
i = i + 1 i = i + 1

View File

@@ -40,7 +40,7 @@ package.load_config = function(name)
var config_path = get_path(name) + '/cell.toml' var config_path = get_path(name) + '/cell.toml'
if (!fd.is_file(config_path)) { if (!fd.is_file(config_path)) {
print(`${config_path} does not exist`); disrupt log.error(`${config_path} does not exist`); disrupt
} }
var content = text(fd.slurp(config_path)) var content = text(fd.slurp(config_path))
@@ -49,7 +49,7 @@ package.load_config = function(name)
var result = toml.decode(content) var result = toml.decode(content)
if (!result) { if (!result) {
print(`TOML decode returned null for ${config_path}`) log.error(`TOML decode returned null for ${config_path}`)
return {} return {}
} }

View File

@@ -4,4 +4,4 @@ var json = use("json")
var shop = use("internal/shop") var shop = use("internal/shop")
var filename = args[0] var filename = args[0]
var ast = shop.parse_file(filename) var ast = shop.parse_file(filename)
print(json.encode(ast, true)) log.compile(json.encode(ast, true))

View File

@@ -15,14 +15,14 @@ function is_requestor(fn) {
function check_requestors(list, factory) { function check_requestors(list, factory) {
if (!is_array(list) || some(list, r => !is_requestor(r))) { if (!is_array(list) || some(list, r => !is_requestor(r))) {
print(make_reason(factory, 'Bad requestor array.', list).message + '\n') log.error(make_reason(factory, 'Bad requestor array.', list).message)
disrupt disrupt
} }
} }
function check_callback(cb, factory) { function check_callback(cb, factory) {
if (!is_function(cb) || length(cb) != 2) { if (!is_function(cb) || length(cb) != 2) {
print(make_reason(factory, 'Not a callback.', cb).message + '\n') log.error(make_reason(factory, 'Not a callback.', cb).message)
disrupt disrupt
} }
} }
@@ -32,7 +32,7 @@ function check_callback(cb, factory) {
function fallback(requestor_array) { function fallback(requestor_array) {
def factory = 'fallback' def factory = 'fallback'
if (!is_array(requestor_array) || length(requestor_array) == 0) { if (!is_array(requestor_array) || length(requestor_array) == 0) {
print(make_reason(factory, 'Empty requestor array.').message + '\n') log.error(make_reason(factory, 'Empty requestor array.').message)
disrupt disrupt
} }
check_requestors(requestor_array, factory) check_requestors(requestor_array, factory)
@@ -89,7 +89,7 @@ function fallback(requestor_array) {
function parallel(requestor_array, throttle, need) { function parallel(requestor_array, throttle, need) {
def factory = 'parallel' def factory = 'parallel'
if (!is_array(requestor_array)) { if (!is_array(requestor_array)) {
print(make_reason(factory, 'Not an array.', requestor_array).message + '\n') log.error(make_reason(factory, 'Not an array.', requestor_array).message)
disrupt disrupt
} }
check_requestors(requestor_array, factory) check_requestors(requestor_array, factory)
@@ -101,12 +101,12 @@ function parallel(requestor_array, throttle, need) {
var _need = need var _need = need
if (_need == null) _need = len if (_need == null) _need = len
if (!is_number(_need) || _need < 0 || _need > len) { if (!is_number(_need) || _need < 0 || _need > len) {
print(make_reason(factory, 'Bad need.', _need).message + '\n') log.error(make_reason(factory, 'Bad need.', _need).message)
disrupt disrupt
} }
if (throttle != null && (!is_number(throttle) || throttle < 1)) { if (throttle != null && (!is_number(throttle) || throttle < 1)) {
print(make_reason(factory, 'Bad throttle.', throttle).message + '\n') log.error(make_reason(factory, 'Bad throttle.', throttle).message)
disrupt disrupt
} }
@@ -184,7 +184,7 @@ function parallel(requestor_array, throttle, need) {
function race(requestor_array, throttle, need) { function race(requestor_array, throttle, need) {
def factory = 'race' def factory = 'race'
if (!is_array(requestor_array) || length(requestor_array) == 0) { if (!is_array(requestor_array) || length(requestor_array) == 0) {
print(make_reason(factory, 'Empty requestor array.').message + '\n') log.error(make_reason(factory, 'Empty requestor array.').message)
disrupt disrupt
} }
check_requestors(requestor_array, factory) check_requestors(requestor_array, factory)
@@ -193,12 +193,12 @@ function race(requestor_array, throttle, need) {
var _need = need var _need = need
if (_need == null) _need = 1 if (_need == null) _need = 1
if (!is_number(_need) || _need < 1 || _need > len) { if (!is_number(_need) || _need < 1 || _need > len) {
print(make_reason(factory, 'Bad need.', _need).message + '\n') log.error(make_reason(factory, 'Bad need.', _need).message)
disrupt disrupt
} }
if (throttle != null && (!is_number(throttle) || throttle < 1)) { if (throttle != null && (!is_number(throttle) || throttle < 1)) {
print(make_reason(factory, 'Bad throttle.', throttle).message + '\n') log.error(make_reason(factory, 'Bad throttle.', throttle).message)
disrupt disrupt
} }
@@ -279,7 +279,7 @@ function race(requestor_array, throttle, need) {
function sequence(requestor_array) { function sequence(requestor_array) {
def factory = 'sequence' def factory = 'sequence'
if (!is_array(requestor_array)) { if (!is_array(requestor_array)) {
print(make_reason(factory, 'Not an array.', requestor_array).message + '\n') log.error(make_reason(factory, 'Not an array.', requestor_array).message)
disrupt disrupt
} }
check_requestors(requestor_array, factory) check_requestors(requestor_array, factory)
@@ -339,7 +339,7 @@ function sequence(requestor_array) {
function requestorize(unary) { function requestorize(unary) {
def factory = 'requestorize' def factory = 'requestorize'
if (!is_function(unary)) { if (!is_function(unary)) {
print(make_reason(factory, 'Not a function.', unary).message + '\n') log.error(make_reason(factory, 'Not a function.', unary).message)
disrupt disrupt
} }

2
qbe.ce
View File

@@ -17,4 +17,4 @@ var folded = fold(ast)
var compiled = mcode(folded) var compiled = mcode(folded)
var optimized = streamline(compiled) var optimized = streamline(compiled)
var il = qbe_emit(optimized, qbe_macros) var il = qbe_emit(optimized, qbe_macros)
print(il) log.compile(il)

View File

@@ -7,7 +7,7 @@ var shop = use('internal/shop')
var fd = use('fd') var fd = use('fd')
if (length(args) < 1) { if (length(args) < 1) {
print('usage: cell run_aot <program.ce>') log.compile('usage: cell run_aot <program.ce>')
return return
} }
@@ -16,7 +16,7 @@ if (!fd.is_file(file)) {
if (!ends_with(file, '.ce') && fd.is_file(file + '.ce')) if (!ends_with(file, '.ce') && fd.is_file(file + '.ce'))
file = file + '.ce' file = file + '.ce'
else { else {
print('file not found: ' + file) log.error('file not found: ' + file)
return return
} }
} }

View File

@@ -11,8 +11,8 @@ var fd = use('fd')
var shop = use('internal/shop') var shop = use('internal/shop')
if (length(args) < 1) { if (length(args) < 1) {
print('usage: cell --dev run_native <module>') log.compile('usage: cell --dev run_native <module>')
print(' e.g. cell --dev run_native num_torture') log.compile(' e.g. cell --dev run_native num_torture')
return return
} }
@@ -28,52 +28,52 @@ if (length(args) > 1) {
} }
// --- Interpreted run --- // --- Interpreted run ---
print('--- interpreted ---') log.compile('--- interpreted ---')
var t1 = os.now() var t1 = os.now()
var mod_interp = use(name) var mod_interp = use(name)
var t2 = os.now() var t2 = os.now()
var result_interp = null var result_interp = null
if (is_function(mod_interp)) { if (is_function(mod_interp)) {
print('module returns a function, calling with ' + text(test_arg)) log.compile('module returns a function, calling with ' + text(test_arg))
t1 = os.now() t1 = os.now()
result_interp = mod_interp(test_arg) result_interp = mod_interp(test_arg)
t2 = os.now() t2 = os.now()
} }
result_interp = result_interp != null ? result_interp : mod_interp result_interp = result_interp != null ? result_interp : mod_interp
var ms_interp = (t2 - t1) / 1000000 var ms_interp = (t2 - t1) / 1000000
print('result: ' + text(result_interp)) log.compile('result: ' + text(result_interp))
print('time: ' + text(ms_interp) + ' ms') log.compile('time: ' + text(ms_interp) + ' ms')
// --- Native run --- // --- Native run ---
// Resolve to .cm path for shop.use_native() // Resolve to .cm path for shop.use_native()
var mod_path = name + '.cm' var mod_path = name + '.cm'
if (!fd.is_file(mod_path)) { if (!fd.is_file(mod_path)) {
print('\nno ' + mod_path + ' found') log.error('\nno ' + mod_path + ' found')
return return
} }
print('\n--- native ---') log.compile('\n--- native ---')
var t3 = os.now() var t3 = os.now()
var mod_native = shop.use_native(mod_path) var mod_native = shop.use_native(mod_path)
var t4 = os.now() var t4 = os.now()
var result_native = null var result_native = null
if (is_function(mod_native)) { if (is_function(mod_native)) {
print('module returns a function, calling with ' + text(test_arg)) log.compile('module returns a function, calling with ' + text(test_arg))
t3 = os.now() t3 = os.now()
result_native = mod_native(test_arg) result_native = mod_native(test_arg)
t4 = os.now() t4 = os.now()
} }
result_native = result_native != null ? result_native : mod_native result_native = result_native != null ? result_native : mod_native
var ms_native = (t4 - t3) / 1000000 var ms_native = (t4 - t3) / 1000000
print('result: ' + text(result_native)) log.compile('result: ' + text(result_native))
print('time: ' + text(ms_native) + ' ms') log.compile('time: ' + text(ms_native) + ' ms')
// --- Comparison --- // --- Comparison ---
print('\n--- comparison ---') log.compile('\n--- comparison ---')
var match = result_interp == result_native var match = result_interp == result_native
var speedup = 0 var speedup = 0
print('match: ' + text(match)) log.compile('match: ' + text(match))
if (ms_native > 0) { if (ms_native > 0) {
speedup = ms_interp / ms_native speedup = ms_interp / ms_native
print('speedup: ' + text(speedup) + 'x') log.compile('speedup: ' + text(speedup) + 'x')
} }

View File

@@ -5,7 +5,7 @@ var fd = use("fd")
var os = use("internal/os") var os = use("internal/os")
if (length(args) < 1) { if (length(args) < 1) {
print("usage: cell --dev --seed run_native_seed <module>") log.compile("usage: cell --dev --seed run_native_seed <module>")
disrupt disrupt
} }
@@ -24,29 +24,29 @@ if (length(args) > 1) {
} }
// --- Interpreted run --- // --- Interpreted run ---
print("--- interpreted ---") log.compile("--- interpreted ---")
var t1 = os.now() var t1 = os.now()
var mod_interp = use(name) var mod_interp = use(name)
var t2 = os.now() var t2 = os.now()
var result_interp = null var result_interp = null
if (is_function(mod_interp)) { if (is_function(mod_interp)) {
print("module returns a function, calling with " + text(test_arg)) log.compile("module returns a function, calling with " + text(test_arg))
t1 = os.now() t1 = os.now()
result_interp = mod_interp(test_arg) result_interp = mod_interp(test_arg)
t2 = os.now() t2 = os.now()
} }
result_interp = result_interp != null ? result_interp : mod_interp result_interp = result_interp != null ? result_interp : mod_interp
var ms_interp = (t2 - t1) / 1000000 var ms_interp = (t2 - t1) / 1000000
print("result: " + text(result_interp)) log.compile("result: " + text(result_interp))
print("time: " + text(ms_interp) + " ms") log.compile("time: " + text(ms_interp) + " ms")
// --- Native run --- // --- Native run ---
if (!fd.is_file(dylib_path)) { if (!fd.is_file(dylib_path)) {
print("\nno " + dylib_path + " found") log.error("\nno " + dylib_path + " found")
disrupt disrupt
} }
print("\n--- native ---") log.compile("\n--- native ---")
var t3 = os.now() var t3 = os.now()
var lib = os.dylib_open(dylib_path) var lib = os.dylib_open(dylib_path)
var t4 = os.now() var t4 = os.now()
@@ -54,7 +54,7 @@ var mod_native = os.dylib_symbol(lib, symbol)
var t5 = os.now() var t5 = os.now()
var result_native = null var result_native = null
if (is_function(mod_native)) { if (is_function(mod_native)) {
print("module returns a function, calling with " + text(test_arg)) log.compile("module returns a function, calling with " + text(test_arg))
t4 = os.now() t4 = os.now()
result_native = mod_native(test_arg) result_native = mod_native(test_arg)
t5 = os.now() t5 = os.now()
@@ -62,17 +62,17 @@ if (is_function(mod_native)) {
result_native = result_native != null ? result_native : mod_native result_native = result_native != null ? result_native : mod_native
var ms_native = (t5 - t3) / 1000000 var ms_native = (t5 - t3) / 1000000
var ms_exec = (t5 - t4) / 1000000 var ms_exec = (t5 - t4) / 1000000
print("result: " + text(result_native)) log.compile("result: " + text(result_native))
print("load: " + text((t4 - t3) / 1000000) + " ms") log.compile("load: " + text((t4 - t3) / 1000000) + " ms")
print("exec: " + text(ms_exec) + " ms") log.compile("exec: " + text(ms_exec) + " ms")
print("total: " + text(ms_native) + " ms") log.compile("total: " + text(ms_native) + " ms")
// --- Comparison --- // --- Comparison ---
print("\n--- comparison ---") log.compile("\n--- comparison ---")
print("match: " + text(result_interp == result_native)) log.compile("match: " + text(result_interp == result_native))
if (ms_native > 0) { if (ms_native > 0) {
print("speedup: " + text(ms_interp / ms_native) + "x (total)") log.compile("speedup: " + text(ms_interp / ms_native) + "x (total)")
} }
if (ms_exec > 0) { if (ms_exec > 0) {
print("speedup: " + text(ms_interp / ms_exec) + "x (exec only)") log.compile("speedup: " + text(ms_interp / ms_exec) + "x (exec only)")
} }

28
seed.ce
View File

@@ -32,10 +32,10 @@ for (i = 0; i < length(args); i++) {
if (args[i] == '--clean') { if (args[i] == '--clean') {
clean = true clean = true
} else if (args[i] == '--help' || args[i] == '-h') { } else if (args[i] == '--help' || args[i] == '-h') {
print("usage: pit seed [--clean]") log.compile("usage: pit seed [--clean]")
print("") log.compile("")
print(" Regenerate boot seed files in boot/") log.compile(" Regenerate boot seed files in boot/")
print(" --clean Also clear the build cache after") log.compile(" --clean Also clear the build cache after")
$stop() $stop()
} }
} }
@@ -62,11 +62,11 @@ for (i = 0; i < length(pipeline_modules); i++) {
src_path = core_dir + '/' + name + '.cm' src_path = core_dir + '/' + name + '.cm'
if (!fd.is_file(src_path)) { if (!fd.is_file(src_path)) {
print('WARNING: source not found: ' + src_path) log.error('WARNING: source not found: ' + src_path)
continue continue
} }
print('Seeding ' + name + '.cm ...') log.compile('Seeding ' + name + '.cm ...')
src = text(fd.slurp(src_path)) src = text(fd.slurp(src_path))
tok = tokenize(src, src_path) tok = tokenize(src, src_path)
ast = parse(tok.tokens, src, src_path, tokenize) ast = parse(tok.tokens, src, src_path, tokenize)
@@ -77,14 +77,14 @@ for (i = 0; i < length(pipeline_modules); i++) {
out_path = boot_dir + '/' + name + '.cm.mcode' out_path = boot_dir + '/' + name + '.cm.mcode'
fd.slurpwrite(out_path, stone(blob(mcode_json))) fd.slurpwrite(out_path, stone(blob(mcode_json)))
print(' -> ' + out_path + ' (' + text(length(mcode_json)) + ' bytes)') log.compile(' -> ' + out_path + ' (' + text(length(mcode_json)) + ' bytes)')
generated = generated + 1 generated = generated + 1
} }
// Regenerate bootstrap.cm seed // Regenerate bootstrap.cm seed
var bootstrap_path = core_dir + '/internal/bootstrap.cm' var bootstrap_path = core_dir + '/internal/bootstrap.cm'
if (fd.is_file(bootstrap_path)) { if (fd.is_file(bootstrap_path)) {
print('Seeding bootstrap.cm ...') log.compile('Seeding bootstrap.cm ...')
src = text(fd.slurp(bootstrap_path)) src = text(fd.slurp(bootstrap_path))
tok = tokenize(src, bootstrap_path) tok = tokenize(src, bootstrap_path)
ast = parse(tok.tokens, src, bootstrap_path, tokenize) ast = parse(tok.tokens, src, bootstrap_path, tokenize)
@@ -95,22 +95,22 @@ if (fd.is_file(bootstrap_path)) {
out_path = boot_dir + '/bootstrap.cm.mcode' out_path = boot_dir + '/bootstrap.cm.mcode'
fd.slurpwrite(out_path, stone(blob(mcode_json))) fd.slurpwrite(out_path, stone(blob(mcode_json)))
print(' -> ' + out_path + ' (' + text(length(mcode_json)) + ' bytes)') log.compile(' -> ' + out_path + ' (' + text(length(mcode_json)) + ' bytes)')
generated = generated + 1 generated = generated + 1
} else { } else {
print('WARNING: bootstrap source not found: ' + bootstrap_path) log.error('WARNING: bootstrap source not found: ' + bootstrap_path)
} }
print('\nRegenerated ' + text(generated) + ' seed(s)') log.compile('\nRegenerated ' + text(generated) + ' seed(s)')
if (clean) { if (clean) {
build_dir = shop.get_build_dir() build_dir = shop.get_build_dir()
if (fd.is_dir(build_dir)) { if (fd.is_dir(build_dir)) {
print('Clearing build cache: ' + build_dir) log.compile('Clearing build cache: ' + build_dir)
os.system('rm -rf "' + build_dir + '"') os.system('rm -rf "' + build_dir + '"')
print('Build cache cleared. Next run will recompile from new seeds.') log.compile('Build cache cleared. Next run will recompile from new seeds.')
} else { } else {
print('No build cache to clear.') log.compile('No build cache to clear.')
} }
} }

View File

@@ -1060,7 +1060,6 @@ JSValue js_cell_character (JSContext *ctx, JSValue this_val, int argc, JSValue *
static JSValue js_cell_number (JSContext *ctx, JSValue this_val, int argc, JSValue *argv); static JSValue js_cell_number (JSContext *ctx, JSValue this_val, int argc, JSValue *argv);
static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSValue *argv); static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSValue *argv);
static JSValue js_cell_text_format (JSContext *ctx, JSValue this_val, int argc, JSValue *argv); static JSValue js_cell_text_format (JSContext *ctx, JSValue this_val, int argc, JSValue *argv);
static JSValue js_print (JSContext *ctx, JSValue this_val, int argc, JSValue *argv);
JSValue JS_GetStack(JSContext *ctx); JSValue JS_GetStack(JSContext *ctx);
JSValue JS_RaiseOOM (JSContext *ctx); JSValue JS_RaiseOOM (JSContext *ctx);

View File

@@ -8135,19 +8135,6 @@ static JSValue js_cell_text_format (JSContext *ctx, JSValue this_val, int argc,
return pretext_end (ctx, result); return pretext_end (ctx, result);
} }
/* print(args...) - print arguments to stdout */
static JSValue js_print (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
for (int i = 0; i < argc; i++) {
const char *str = JS_ToCString (ctx, argv[i]);
if (str) {
fputs (str, stdout);
JS_FreeCString (ctx, str);
}
if (i < argc - 1) fputc (' ', stdout);
}
fputc ('\n', stdout);
return JS_NULL;
}
static JSValue js_stacktrace (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { static JSValue js_stacktrace (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
(void)this_val; (void)argc; (void)argv; (void)this_val; (void)argc; (void)argv;
@@ -11554,7 +11541,6 @@ static void JS_AddIntrinsicBaseObjects (JSContext *ctx) {
} }
/* I/O functions */ /* I/O functions */
js_set_global_cfunc(ctx, "print", js_print, -1); /* variadic: length < 0 means no arg limit */
js_set_global_cfunc(ctx, "stacktrace", js_stacktrace, 0); js_set_global_cfunc(ctx, "stacktrace", js_stacktrace, 0);
js_set_global_cfunc(ctx, "caller_info", js_caller_info, 1); js_set_global_cfunc(ctx, "caller_info", js_caller_info, 1);
} }

View File

@@ -42,7 +42,7 @@ for (i = 0; i < length(args); i++) {
} }
if (!filename) { if (!filename) {
print("usage: cell streamline [--stats] [--ir] [--check] [--types] [--diagnose] <file>") log.compile("usage: cell streamline [--stats] [--ir] [--check] [--types] <file>")
$stop() $stop()
} }
@@ -65,7 +65,7 @@ if (show_diagnose) {
// If no flags, default to full JSON output // If no flags, default to full JSON output
if (!show_stats && !show_ir && !show_check && !show_types && !show_diagnose) { if (!show_stats && !show_ir && !show_check && !show_types && !show_diagnose) {
print(json.encode(optimized, true)) log.compile(json.encode(optimized, true))
$stop() $stop()
} }
@@ -118,29 +118,29 @@ var print_func_stats = function(func, before_func, name) {
var before_stats = before_func ? ir_stats.detailed_stats(before_func) : null var before_stats = before_func ? ir_stats.detailed_stats(before_func) : null
var before_total = before_stats ? before_stats.instr : stats.instr var before_total = before_stats ? before_stats.instr : stats.instr
print(` ${name}`) log.compile(` ${name}`)
print(` args=${text(nr_args)} slots=${text(nr_slots)} close_slots=${text(nr_close)}`) log.compile(` args=${text(nr_args)} slots=${text(nr_slots)} close_slots=${text(nr_close)}`)
print(` instructions: ${text(stats.instr)} total, ${text(nops)} nops eliminated`) log.compile(` instructions: ${text(stats.instr)} total, ${text(nops)} nops eliminated`)
if (before_stats) { if (before_stats) {
print(` before: ${text(before_total)} after: ${text(stats.instr - nops)}`) log.compile(` before: ${text(before_total)} after: ${text(stats.instr - nops)}`)
} }
print(` load=${text(stats.load)} store=${text(stats.store)} branch=${text(stats.branch)} call=${text(stats.call)}`) log.compile(` load=${text(stats.load)} store=${text(stats.store)} branch=${text(stats.branch)} call=${text(stats.call)}`)
print(` guard=${text(stats.guard)} arith=${text(stats.arith)} move=${text(stats.move)} const=${text(stats.const)}`) log.compile(` guard=${text(stats.guard)} arith=${text(stats.arith)} move=${text(stats.move)} const=${text(stats.const)}`)
if (nr_slots > 200) { if (nr_slots > 200) {
print(` WARNING: nr_slots=${text(nr_slots)} approaching 255 limit`) log.compile(` WARNING: nr_slots=${text(nr_slots)} approaching 255 limit`)
} }
} }
var print_func_ir = function(func, name) { var print_func_ir = function(func, name) {
var ir_text = ir_stats.canonical_ir(func, name, {show_nops: true}) var ir_text = ir_stats.canonical_ir(func, name, {show_nops: true})
print(ir_text) log.compile(ir_text)
} }
var check_func = function(func, name) { var check_func = function(func, name) {
var nr_slots = func.nr_slots != null ? func.nr_slots : 0 var nr_slots = func.nr_slots != null ? func.nr_slots : 0
if (nr_slots > 200) { if (nr_slots > 200) {
print(`WARNING: ${name} has ${text(nr_slots)} slots (approaching 255 limit)`) log.compile(`WARNING: ${name} has ${text(nr_slots)} slots (approaching 255 limit)`)
} }
} }
@@ -261,9 +261,9 @@ var dump_function_typed = function(func, name) {
var pc_str = null var pc_str = null
var op_str = null var op_str = null
var line = null var line = null
print(`\n=== ${name} (args=${text(nr_args)}, slots=${text(nr_slots)}) ===`) log.compile(`\n=== ${name} (args=${text(nr_args)}, slots=${text(nr_slots)}) ===`)
if (instrs == null || length(instrs) == 0) { if (instrs == null || length(instrs) == 0) {
print(" (empty)") log.compile(" (empty)")
return null return null
} }
while (i < length(instrs)) { while (i < length(instrs)) {
@@ -274,7 +274,7 @@ var dump_function_typed = function(func, name) {
continue continue
} }
slot_types = {} slot_types = {}
print(`${instr}:`) log.compile(`${instr}:`)
} else if (is_array(instr)) { } else if (is_array(instr)) {
op = instr[0] op = instr[0]
n = length(instr) n = length(instr)
@@ -290,9 +290,9 @@ var dump_function_typed = function(func, name) {
op_str = pad_right(op, 14) op_str = pad_right(op, 14)
line = pad_right(` ${pc_str} ${op_str} ${operands}`, 50) line = pad_right(` ${pc_str} ${op_str} ${operands}`, 50)
if (length(annotation) > 0) { if (length(annotation) > 0) {
print(`${line} ; ${annotation}`) log.compile(`${line} ; ${annotation}`)
} else { } else {
print(line) log.compile(line)
} }
track_types(slot_types, instr) track_types(slot_types, instr)
pc = pc + 1 pc = pc + 1
@@ -311,7 +311,7 @@ var bfunc = null
var fname = null var fname = null
if (show_stats) { if (show_stats) {
print(`\n--- Stats for ${filename} ---`) log.compile(`\n--- Stats for ${filename} ---`)
} }
// Main function // Main function
@@ -355,7 +355,7 @@ if (optimized.functions != null) {
} }
if (show_stats) { if (show_stats) {
print('---') log.compile('---')
} }
if (show_diagnose) { if (show_diagnose) {

View File

@@ -13,11 +13,11 @@ var streamline = function(ir, log) {
var errs = verifier.verify_all(func, pass_name) var errs = verifier.verify_all(func, pass_name)
var i = 0 var i = 0
while (i < length(errs)) { while (i < length(errs)) {
print(`[verify_ir] ${errs[i]}\n`) log.error(`[verify_ir] ${errs[i]}`)
i = i + 1 i = i + 1
} }
if (length(errs) > 0) { if (length(errs) > 0) {
print(`[verify_ir] ${text(length(errs))} errors after ${pass_name}\n`) log.error(`[verify_ir] ${text(length(errs))} errors after ${pass_name}`)
} }
} }
} }

View File

@@ -632,11 +632,11 @@ run("inequality not confused with bang ident", function() {
// === SUMMARY === // === SUMMARY ===
print(text(passed) + " passed, " + text(failed) + " failed out of " + text(passed + failed)) log.test(text(passed) + " passed, " + text(failed) + " failed out of " + text(passed + failed))
var _j = 0 var _j = 0
if (failed > 0) { if (failed > 0) {
print("") log.test("")
for (_j = 0; _j < failed; _j++) { for (_j = 0; _j < failed; _j++) {
print(" FAIL " + error_names[_j] + ": " + error_reasons[_j]) log.error(" FAIL " + error_names[_j] + ": " + error_reasons[_j])
} }
} }

View File

@@ -20,8 +20,8 @@ var concat_all = function(a, b, c) {
return a + b + c return a + b + c
} }
if (sum_ints(1, 2, 3) != 6) { print("FAIL sum_ints") } if (sum_ints(1, 2, 3) != 6) { log.error("FAIL sum_ints") }
if (count_down(5) != 15) { print("FAIL count_down") } if (count_down(5) != 15) { log.error("FAIL count_down") }
if (concat_all("a", "b", "c") != "abc") { print("FAIL concat_all") } if (concat_all("a", "b", "c") != "abc") { log.error("FAIL concat_all") }
print("backward type tests passed") log.test("backward type tests passed")

View File

@@ -7,57 +7,57 @@ var num = 42
var boo = true var boo = true
// is_array // is_array
if (!is_array(arr)) { print("FAIL is_array(arr)") } if (!is_array(arr)) { log.error("FAIL is_array(arr)") }
if (is_array(rec)) { print("FAIL is_array(rec)") } if (is_array(rec)) { log.error("FAIL is_array(rec)") }
if (is_array(42)) { print("FAIL is_array(42)") } if (is_array(42)) { log.error("FAIL is_array(42)") }
// is_object // is_object
if (!is_object(rec)) { print("FAIL is_object(rec)") } if (!is_object(rec)) { log.error("FAIL is_object(rec)") }
if (is_object(arr)) { print("FAIL is_object(arr)") } if (is_object(arr)) { log.error("FAIL is_object(arr)") }
if (is_object(42)) { print("FAIL is_object(42)") } if (is_object(42)) { log.error("FAIL is_object(42)") }
// is_function // is_function
if (!is_function(fn)) { print("FAIL is_function(fn)") } if (!is_function(fn)) { log.error("FAIL is_function(fn)") }
if (is_function(rec)) { print("FAIL is_function(rec)") } if (is_function(rec)) { log.error("FAIL is_function(rec)") }
// is_stone // is_stone
var frozen = stone([1, 2]) var frozen = stone([1, 2])
if (!is_stone(frozen)) { print("FAIL is_stone(frozen)") } if (!is_stone(frozen)) { log.error("FAIL is_stone(frozen)") }
if (is_stone(arr)) { print("FAIL is_stone(arr)") } if (is_stone(arr)) { log.error("FAIL is_stone(arr)") }
if (!is_stone(42)) { print("FAIL is_stone(42)") } if (!is_stone(42)) { log.error("FAIL is_stone(42)") }
if (!is_stone("hi")) { print("FAIL is_stone(str)") } if (!is_stone("hi")) { log.error("FAIL is_stone(str)") }
// length // length
if (length(arr) != 3) { print("FAIL length(arr)") } if (length(arr) != 3) { log.error("FAIL length(arr)") }
if (length(txt) != 5) { print("FAIL length(txt)") } if (length(txt) != 5) { log.error("FAIL length(txt)") }
if (length([]) != 0) { print("FAIL length([])") } if (length([]) != 0) { log.error("FAIL length([])") }
// is_integer (already existed but now inlined) // is_integer (already existed but now inlined)
if (!is_integer(42)) { print("FAIL is_integer(42)") } if (!is_integer(42)) { log.error("FAIL is_integer(42)") }
if (is_integer(3.14)) { print("FAIL is_integer(3.14)") } if (is_integer(3.14)) { log.error("FAIL is_integer(3.14)") }
// is_text // is_text
if (!is_text("hi")) { print("FAIL is_text(hi)") } if (!is_text("hi")) { log.error("FAIL is_text(hi)") }
if (is_text(42)) { print("FAIL is_text(42)") } if (is_text(42)) { log.error("FAIL is_text(42)") }
// is_number // is_number
if (!is_number(42)) { print("FAIL is_number(42)") } if (!is_number(42)) { log.error("FAIL is_number(42)") }
if (!is_number(3.14)) { print("FAIL is_number(3.14)") } if (!is_number(3.14)) { log.error("FAIL is_number(3.14)") }
if (is_number("hi")) { print("FAIL is_number(hi)") } if (is_number("hi")) { log.error("FAIL is_number(hi)") }
// is_logical // is_logical
if (!is_logical(true)) { print("FAIL is_logical(true)") } if (!is_logical(true)) { log.error("FAIL is_logical(true)") }
if (is_logical(42)) { print("FAIL is_logical(42)") } if (is_logical(42)) { log.error("FAIL is_logical(42)") }
// is_null // is_null
if (!is_null(null)) { print("FAIL is_null(null)") } if (!is_null(null)) { log.error("FAIL is_null(null)") }
if (is_null(42)) { print("FAIL is_null(42)") } if (is_null(42)) { log.error("FAIL is_null(42)") }
// push (inlined) // push (inlined)
var a = [1] var a = [1]
push(a, 2) push(a, 2)
push(a, 3) push(a, 3)
if (length(a) != 3) { print("FAIL push length") } if (length(a) != 3) { log.error("FAIL push length") }
if (a[2] != 3) { print("FAIL push value") } if (a[2] != 3) { log.error("FAIL push value") }
print("all intrinsic tests passed") log.test("all intrinsic tests passed")

View File

@@ -14,29 +14,29 @@ var f = null
var bytecode = null var bytecode = null
var has_errors = ast.errors != null && length(ast.errors) > 0 var has_errors = ast.errors != null && length(ast.errors) > 0
if (has_errors) { if (has_errors) {
print("PARSE ERRORS:") log.error("PARSE ERRORS:")
while (i < length(ast.errors)) { while (i < length(ast.errors)) {
print(text(ast.errors[i].line) + ":" + text(ast.errors[i].column) + " " + ast.errors[i].message) log.error(text(ast.errors[i].line) + ":" + text(ast.errors[i].column) + " " + ast.errors[i].message)
i = i + 1 i = i + 1
} }
} else { } else {
print("Parse OK") log.test("Parse OK")
print(" statements: " + text(length(ast.statements))) log.test(" statements: " + text(length(ast.statements)))
if (ast.functions != null) { if (ast.functions != null) {
print(" functions: " + text(length(ast.functions))) log.test(" functions: " + text(length(ast.functions)))
} else { } else {
print(" functions: null") log.test(" functions: null")
} }
folded = fold(ast) folded = fold(ast)
ast_json = json.encode(folded) ast_json = json.encode(folded)
f = fd.open("/tmp/bootstrap_ast.json", "w") f = fd.open("/tmp/bootstrap_ast.json", "w")
fd.write(f, ast_json) fd.write(f, ast_json)
fd.close(f) fd.close(f)
print("Wrote AST to /tmp/bootstrap_ast.json") log.test("Wrote AST to /tmp/bootstrap_ast.json")
bytecode = mach_compile_ast("bootstrap", ast_json) bytecode = mach_compile_ast("bootstrap", ast_json)
print("Bytecode size: " + text(length(bytecode))) log.test("Bytecode size: " + text(length(bytecode)))
f = fd.open("/tmp/bootstrap_test.mach", "w") f = fd.open("/tmp/bootstrap_test.mach", "w")
fd.write(f, bytecode) fd.write(f, bytecode)
fd.close(f) fd.close(f)
print("Wrote bytecode to /tmp/bootstrap_test.mach") log.test("Wrote bytecode to /tmp/bootstrap_test.mach")
} }

View File

@@ -6,7 +6,7 @@ $start(function(event) {
// child started, wait for it to die from memory abuse // child started, wait for it to die from memory abuse
} }
if (event.type == 'disrupt') { if (event.type == 'disrupt') {
print("PASS: memory abusing actor killed") log.test("PASS: memory abusing actor killed")
$stop() $stop()
} }
}, 'tests/hang_actor_memory') }, 'tests/hang_actor_memory')

View File

@@ -7,7 +7,7 @@ $start(function(event) {
} }
if (event.type == 'disrupt') { if (event.type == 'disrupt') {
// child was killed by the timer — success // child was killed by the timer — success
print("PASS: slow actor killed by timer") log.test("PASS: slow actor killed by timer")
$stop() $stop()
} }
}, 'tests/hang_actor') }, 'tests/hang_actor')

View File

@@ -2,9 +2,9 @@
// completing the computation correctly. // completing the computation correctly.
$receiver(function(msg) { $receiver(function(msg) {
if (msg.sum == 12499997500000) { if (msg.sum == 12499997500000) {
print("PASS: actor suspended and resumed correctly") log.test("PASS: actor suspended and resumed correctly")
} else { } else {
print(`FAIL: expected 12499997500000, got ${msg.sum}`) log.error(`FAIL: expected 12499997500000, got ${msg.sum}`)
} }
$stop() $stop()
}) })
@@ -14,7 +14,7 @@ $start(function(event) {
send(event.actor, {count: 5000000, reply: $self}) send(event.actor, {count: 5000000, reply: $self})
} }
if (event.type == 'disrupt') { if (event.type == 'disrupt') {
print("FAIL: actor was killed instead of completing") log.error("FAIL: actor was killed instead of completing")
$stop() $stop()
} }
}, 'tests/slow_compute_actor') }, 'tests/slow_compute_actor')

View File

@@ -155,12 +155,12 @@ run("valid var in function body", function() {
// === SUMMARY === // === SUMMARY ===
print(text(passed) + " passed, " + text(failed) + " failed out of " + text(passed + failed)) log.test(text(passed) + " passed, " + text(failed) + " failed out of " + text(passed + failed))
var _j = 0 var _j = 0
if (failed > 0) { if (failed > 0) {
print("") log.test("")
for (_j = 0; _j < failed; _j++) { for (_j = 0; _j < failed; _j++) {
print(" FAIL " + error_names[_j] + ": " + error_reasons[_j]) log.error(" FAIL " + error_names[_j] + ": " + error_reasons[_j])
} }
} }
$stop() $stop()

View File

@@ -1,7 +1,7 @@
function safe_add(a, b) { function safe_add(a, b) {
return a + b return a + b
} disruption { } disruption {
print("disruption caught in safe_add") log.test("disruption caught in safe_add")
} }
function inner() { function inner() {
@@ -11,19 +11,19 @@ function inner() {
function outer() { function outer() {
inner() inner()
} disruption { } disruption {
print("disruption caught in outer — from inner()") log.test("disruption caught in outer — from inner()")
} }
// Test 1: explicit disrupt with handler // Test 1: explicit disrupt with handler
function test_explicit() { function test_explicit() {
disrupt disrupt
} disruption { } disruption {
print("test 1: explicit disrupt handled") log.test("test 1: explicit disrupt handled")
} }
test_explicit() test_explicit()
// Test 2: type error disrupt (number + function) // Test 2: type error disrupt (number + function)
safe_add(1, print) safe_add(1, is_number)
// Test 3: unwinding — inner disrupts, outer catches // Test 3: unwinding — inner disrupts, outer catches
outer() outer()
@@ -32,9 +32,9 @@ outer()
function test_nested() { function test_nested() {
disrupt disrupt
} disruption { } disruption {
print("test 4: first disruption") log.test("test 4: first disruption")
} }
test_nested() test_nested()
print("done") log.test("done")
$stop() $stop()

View File

@@ -4,4 +4,4 @@ var json = use("json")
var shop = use("internal/shop") var shop = use("internal/shop")
var filename = args[0] var filename = args[0]
var result = shop.tokenize_file(filename) var result = shop.tokenize_file(filename)
print(json.encode({filename: result.filename, tokens: result.tokens})) log.compile(json.encode({filename: result.filename, tokens: result.tokens}))

View File

@@ -5543,11 +5543,11 @@ run("gc blob forward pointer chase", function() {
// SUMMARY // SUMMARY
// ============================================================================ // ============================================================================
print(text(passed) + " passed, " + text(failed) + " failed out of " + text(passed + failed)) log.test(text(passed) + " passed, " + text(failed) + " failed out of " + text(passed + failed))
var _j = 0 var _j = 0
if (failed > 0) { if (failed > 0) {
print("") log.test("")
for (_j = 0; _j < failed; _j++) { for (_j = 0; _j < failed; _j++) {
print(" FAIL " + error_names[_j] + ": " + error_reasons[_j]) log.error(" FAIL " + error_names[_j] + ": " + error_reasons[_j])
} }
} }