From 5af76bce9b62215a5eeb0f21d49d3dd08973d32a Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Fri, 20 Feb 2026 15:33:46 -0600 Subject: [PATCH] rm print --- bench_native.ce | 28 ++++++++--------- build.cm | 52 +++++++++++++++---------------- cellfs.cm | 20 ++++++------ compare_aot.ce | 50 +++++++++++++++--------------- compile.ce | 4 +-- docs/functions.md | 10 ------ docs/language.md | 2 +- dump_ir.ce | 2 +- explain.ce | 9 ++---- fold.ce | 2 +- index.ce | 3 +- internal/bootstrap.cm | 8 ++--- internal/engine.cm | 14 ++++----- internal/shop.cm | 38 +++++++++++------------ ir_report.ce | 23 +++++++------- link.cm | 20 ++++++------ mcode.ce | 10 +++--- package.cm | 4 +-- parse.ce | 2 +- pronto.cm | 22 ++++++------- qbe.ce | 2 +- run_aot.ce | 4 +-- run_native.ce | 28 ++++++++--------- run_native_seed.ce | 32 +++++++++---------- seed.ce | 28 ++++++++--------- source/quickjs-internal.h | 1 - source/runtime.c | 14 --------- streamline.ce | 36 +++++++++++----------- streamline.cm | 4 +-- syntax_suite.ce | 6 ++-- test_backward.cm | 8 ++--- test_intrinsics.cm | 58 +++++++++++++++++------------------ test_parse_boot.cm | 18 +++++------ tests/actor_memory_abuse.ce | 2 +- tests/actor_slow_killed.ce | 2 +- tests/actor_suspend_resume.ce | 6 ++-- tests/decl_restrictions.ce | 6 ++-- tests/demo.ce | 12 ++++---- tokenize.ce | 2 +- vm_suite.ce | 6 ++-- 40 files changed, 284 insertions(+), 314 deletions(-) diff --git a/bench_native.ce b/bench_native.ce index de5c8b5c..9c29d4fd 100644 --- a/bench_native.ce +++ b/bench_native.ce @@ -10,7 +10,7 @@ var os = use('os') var fd = use('fd') if (length(args) < 1) { - print('usage: cell --dev bench_native.ce [iterations]') + log.bench('usage: cell --dev bench_native.ce [iterations]') return } @@ -117,12 +117,12 @@ var run_bench = function(fn, label) { // --- Load VM module --- -print('loading VM module: ' + file) +log.bench('loading VM module: ' + file) var vm_mod = use(name) var vm_benches = collect_benches(vm_mod) if (length(vm_benches) == 0) { - print('no benchmarkable functions found in ' + file) + log.bench('no benchmarkable functions found in ' + file) return } @@ -134,20 +134,20 @@ var has_native = fd.is_file(dylib_path) var lib = null if (has_native) { - print('loading native module: ' + dylib_path) + log.bench('loading native module: ' + dylib_path) lib = os.dylib_open(dylib_path) native_mod = os.dylib_symbol(lib, symbol) native_benches = collect_benches(native_mod) } else { - print('no ' + dylib_path + ' found -- VM-only benchmarking') - print(' hint: cell --dev compile.ce ' + file) + log.bench('no ' + dylib_path + ' found -- VM-only benchmarking') + log.bench(' hint: cell --dev compile.ce ' + file) } // --- Run benchmarks --- -print('') -print('samples: ' + text(iterations) + ' (warmup: ' + text(WARMUP) + ')') -print('') +log.bench('') +log.bench('samples: ' + text(iterations) + ' (warmup: ' + text(WARMUP) + ')') +log.bench('') var pad = function(s, n) { var result = s @@ -166,7 +166,7 @@ while (i < length(vm_benches)) { 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)') + 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 j = 0 @@ -174,11 +174,11 @@ while (i < length(vm_benches)) { while (j < length(native_benches)) { if (native_benches[j].name == b.name) { 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) { 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 } @@ -186,9 +186,9 @@ while (i < length(vm_benches)) { } 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 } diff --git a/build.cm b/build.cm index 5767fa53..167d742b 100644 --- a/build.cm +++ b/build.cm @@ -192,7 +192,7 @@ Build.compile_file = function(pkg, file, target, opts) { var core_dir = null if (!fd.is_file(src_path)) { - print('Source file not found: ' + src_path) + log.error('Source file not found: ' + src_path) return null } @@ -256,8 +256,8 @@ Build.compile_file = function(pkg, file, target, opts) { var cmd_str = text(cmd_parts, ' ') if (_opts.verbose) { - print('[verbose] CFLAGS: ' + text(cflags, ' ')) - print('[verbose] compile: ' + cmd_str) + log.build('[verbose] CFLAGS: ' + text(cflags, ' ')) + log.build('[verbose] compile: ' + cmd_str) } // Two-level cache: quick hash for deps file, full hash for object @@ -271,7 +271,7 @@ Build.compile_file = function(pkg, file, target, opts) { // Check for cached failure (skip files that previously failed to compile) 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)') return null } @@ -288,7 +288,7 @@ Build.compile_file = function(pkg, file, target, opts) { full_content = hash_all_deps(cmd_str, deps) obj_path = cache_path(full_content, SALT_OBJ) 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) return obj_path } @@ -304,7 +304,7 @@ Build.compile_file = function(pkg, file, target, opts) { // Check if object exists (might exist from previous build with same deps) if (fd.is_file(obj_path)) { 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)') return obj_path } @@ -330,11 +330,11 @@ Build.compile_file = function(pkg, file, target, opts) { if (missing != null) { err_lines = array(err_text, "\n") 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 { - print('Compilation failed: ' + file) - if (err_text) print(err_text) - else print('Command: ' + full_cmd) + log.error('Compilation failed: ' + file) + if (err_text) log.error(err_text) + else log.error('Command: ' + full_cmd) } // Cache the failure so we don't retry on every build fd.slurpwrite(fail_path, stone(blob(err_text || 'compilation failed'))) @@ -436,7 +436,7 @@ Build.build_module_dylib = function(pkg, file, target, opts) { var ret = null if (_opts.verbose) { - print('[verbose] LDFLAGS: ' + text(resolved_ldflags, ' ')) + log.build('[verbose] LDFLAGS: ' + text(resolved_ldflags, ' ')) } if (!fd.is_file(dylib_path)) { @@ -471,12 +471,12 @@ Build.build_module_dylib = function(pkg, file, target, opts) { push(cmd_parts, '"' + dylib_path + '"') 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.console('Linking module ' + file + ' -> ' + fd.basename(dylib_path)) ret = os.system(cmd_str) if (ret != 0) { - print('Linking failed: ' + file) + log.error('Linking failed: ' + file) return null } } else { @@ -574,7 +574,7 @@ Build.build_static = function(packages, target, output, buildtype) { }) if (length(all_objects) == 0) { - print('No object files to link'); disrupt + log.error('No object files to link'); disrupt } // Link @@ -608,7 +608,7 @@ Build.build_static = function(packages, target, output, buildtype) { log.console('Linking ' + out_path) var ret = os.system(cmd_str) if (ret != 0) { - print('Linking failed: ' + cmd_str); disrupt + log.error('Linking failed: ' + cmd_str); disrupt } log.console('Built ' + out_path) @@ -637,7 +637,7 @@ function compile_native_single(il_parts, cc, tmp_prefix, extra_flags) { fd.slurpwrite(s_path, stone(blob(asm_text))) rc = os.system(cc + _extra + ' -c ' + s_path + ' -o ' + o_path) if (rc != 0) { - print('Assembly failed'); disrupt + log.error('Assembly failed'); disrupt } return [o_path] } @@ -679,7 +679,7 @@ Build.compile_native = function(src_path, target, buildtype, pkg) { var qbe_rt_path = null 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] @@ -721,7 +721,7 @@ Build.compile_native = function(src_path, target, buildtype, pkg) { qbe_rt_path = shop.get_package_dir('core') + '/qbe_rt.c' rc = os.system(cc + san_flags + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC') if (rc != 0) { - print('QBE runtime stubs compilation failed'); disrupt + log.error('QBE runtime stubs compilation failed'); disrupt } } @@ -741,7 +741,7 @@ Build.compile_native = function(src_path, target, buildtype, pkg) { rc = os.system(link_cmd) 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)) @@ -793,7 +793,7 @@ Build.compile_native_ir = function(optimized, src_path, opts) { qbe_rt_path = shop.get_package_dir('core') + '/qbe_rt.c' rc = os.system(cc + san_flags + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC') if (rc != 0) { - print('QBE runtime stubs compilation failed'); disrupt + log.error('QBE runtime stubs compilation failed'); disrupt } } @@ -813,7 +813,7 @@ Build.compile_native_ir = function(optimized, src_path, opts) { rc = os.system(link_cmd) 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)) @@ -829,7 +829,7 @@ Build.compile_native_ir = function(optimized, src_path, opts) { // Returns the raw mach bytes as a blob Build.compile_cm_to_mach = function(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 optimized = shop.compile_file(src_path) @@ -919,7 +919,7 @@ Build.build_all_dynamic = function(target, buildtype, opts) { }) // Print build report - print('\n--- Build Report ---') + log.build('--- Build Report ---') arrfor(results, function(r) { var pkg_dir = shop.get_package_dir(r.package) var c_files = pkg_tools.get_c_files(r.package, _target, true) @@ -931,10 +931,10 @@ Build.build_all_dynamic = function(target, buildtype, opts) { total_fail = total_fail + fail_count if (file_count == 0) return 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`) - print('--------------------\n') + log.build(`Total: ${total_ok}/${total_files} compiled, ${total_fail} failed`) + log.build('--------------------') return results } diff --git a/cellfs.cm b/cellfs.cm index d6a009bc..109f2d23 100644 --- a/cellfs.cm +++ b/cellfs.cm @@ -96,7 +96,7 @@ function resolve(path, must_exist) { }, false, true) if (!mount) { - print("Unknown mount point: @" + mount_name); disrupt + log.error("Unknown mount point: @" + mount_name); disrupt } return { mount: mount, path: rel_path } @@ -114,7 +114,7 @@ function resolve(path, 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 { zip = miniz.read(blob) 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' @@ -160,7 +160,7 @@ function mount(source, name) { mount_info.zip_blob = blob } } else { - print("Unsupported mount source type: " + source); disrupt + log.error("Unsupported mount source type: " + source); disrupt } push(mounts, mount_info) @@ -176,13 +176,13 @@ function slurp(path) { var res = resolve(path, true) var data = 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') { return res.mount.handle.slurp(res.path) } else if (res.mount.type == 'qop') { 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 } else { full_path = fd.join_paths(res.mount.source, res.path) @@ -211,7 +211,7 @@ function stat(path) { var mod = null var s = 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') { mod = res.mount.handle.mod(res.path) @@ -222,7 +222,7 @@ function stat(path) { } } else if (res.mount.type == 'qop') { 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 { filesize: s.size, modtime: s.modtime, @@ -253,7 +253,7 @@ function mount_package(name) { var dir = shop.get_package_dir(name) if (!dir) { - print("Package not found: " + name); disrupt + log.error("Package not found: " + name); disrupt } mount(dir, name) @@ -267,7 +267,7 @@ function rm(path) { var res = resolve(path, true) var full_path = 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) st = fd.stat(full_path) diff --git a/compare_aot.ce b/compare_aot.ce index 12a83b99..d0d2a99b 100644 --- a/compare_aot.ce +++ b/compare_aot.ce @@ -15,7 +15,7 @@ var show = function(v) { } if (length(args) < 1) { - print('usage: cell --dev compare_aot.ce ') + log.compile('usage: cell --dev compare_aot.ce ') return } @@ -26,7 +26,7 @@ if (!fd_mod.is_file(file)) { else if (!ends_with(file, '.cm') && fd_mod.is_file(file + '.cm')) file = file + '.cm' else { - print('file not found: ' + file) + log.error('file not found: ' + file) return } } @@ -54,14 +54,14 @@ var t5 = time.number() var optimized = streamline_mod(compiled) var t6 = time.number() -print('--- front-end timing ---') -print(' read: ' + text(t1 - t0) + 's') -print(' tokenize: ' + text(t2 - t1) + 's') -print(' parse: ' + text(t3 - t2) + 's') -print(' fold: ' + text(t4 - t3) + 's') -print(' mcode: ' + text(t5 - t4) + 's') -print(' streamline: ' + text(t6 - t5) + 's') -print(' total: ' + text(t6 - t0) + 's') +log.compile('--- front-end timing ---') +log.compile(' read: ' + text(t1 - t0) + 's') +log.compile(' tokenize: ' + text(t2 - t1) + 's') +log.compile(' parse: ' + text(t3 - t2) + 's') +log.compile(' fold: ' + text(t4 - t3) + 's') +log.compile(' mcode: ' + text(t5 - t4) + 's') +log.compile(' streamline: ' + text(t6 - t5) + 's') +log.compile(' total: ' + text(t6 - t0) + 's') // Shared env for both paths — only non-intrinsic runtime functions. // Intrinsics (starts_with, ends_with, logical, some, every, etc.) live on @@ -79,15 +79,15 @@ var env = stone({ var result_interp = null var interp_ok = false var run_interp = function() { - print('--- interpreted ---') + log.compile('--- interpreted ---') var mcode_json = json.encode(optimized) var mach_blob = mach_compile_mcode_bin(abs, mcode_json) result_interp = mach_load(mach_blob, env) interp_ok = true - print('result: ' + show(result_interp)) + log.compile('result: ' + show(result_interp)) } disruption { interp_ok = true - print('(disruption escaped from interpreted run)') + log.compile('(disruption escaped from interpreted run)') } run_interp() @@ -95,36 +95,36 @@ run_interp() var result_native = null var native_ok = false var run_native = function() { - print('\n--- native ---') + log.compile('\n--- native ---') 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) if (!handle) { - print('failed to open dylib') + log.error('failed to open dylib') return } result_native = os.native_module_load(handle, env) native_ok = true - print('result: ' + show(result_native)) + log.compile('result: ' + show(result_native)) } disruption { native_ok = true - print('(disruption escaped from native run)') + log.compile('(disruption escaped from native run)') } run_native() // --- Comparison --- -print('\n--- comparison ---') +log.compile('\n--- comparison ---') var s_interp = show(result_interp) var s_native = show(result_native) if (interp_ok && native_ok) { if (s_interp == s_native) { - print('MATCH') + log.compile('MATCH') } else { - print('MISMATCH') - print(' interp: ' + s_interp) - print(' native: ' + s_native) + log.error('MISMATCH') + log.error(' interp: ' + s_interp) + log.error(' native: ' + s_native) } } else { - if (!interp_ok) print('interpreted run failed') - if (!native_ok) print('native run failed') + if (!interp_ok) log.error('interpreted run failed') + if (!native_ok) log.error('native run failed') } diff --git a/compile.ce b/compile.ce index e2aad0ac..ac391724 100644 --- a/compile.ce +++ b/compile.ce @@ -10,13 +10,13 @@ var build = use('build') var fd = use('fd') if (length(args) < 1) { - print('usage: cell compile ') + log.compile('usage: cell compile ') return } var file = args[0] if (!fd.is_file(file)) { - print('file not found: ' + file) + log.error('file not found: ' + file) return } diff --git a/docs/functions.md b/docs/functions.md index f7e92830..d612de0c 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -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. -### print(value) - -Print a value to standard output. - -```javascript -print("hello") -print(42) -print(`result: ${x}`) -``` - ### 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. diff --git a/docs/language.md b/docs/language.md index c51d0c03..20adc66e 100644 --- a/docs/language.md +++ b/docs/language.md @@ -595,7 +595,7 @@ var safe_divide = function(a, b) { if (b == 0) disrupt return a / b } disruption { - print("something went wrong") + log.error("something went wrong") } ``` diff --git a/dump_ir.ce b/dump_ir.ce index de7a537d..d050ae57 100644 --- a/dump_ir.ce +++ b/dump_ir.ce @@ -8,6 +8,6 @@ var optimized = shop.compile_file(args[0]) var instrs = optimized.main.instructions var i = 0 while (i < length(instrs)) { - print(text(i) + ': ' + json.encode(instrs[i])) + log.compile(text(i) + ': ' + json.encode(instrs[i])) i = i + 1 } diff --git a/explain.ce b/explain.ce index b794b71f..b6075304 100644 --- a/explain.ce +++ b/explain.ce @@ -86,8 +86,7 @@ if (mode == "span") { if (result == null) { log.console("Nothing found at " + filename + ":" + text(line) + ":" + text(col)) } else { - print(json.encode(result, true)) - print("\n") + log.compile(json.encode(result, true)) } } @@ -116,8 +115,7 @@ if (mode == "symbol") { if (result == null || length(result.symbols) == 0) { log.console("Symbol '" + symbol_name + "' not found in " + filename) } else { - print(json.encode(result, true)) - print("\n") + log.compile(json.encode(result, true)) } } else if (length(files) > 1) { indexes = [] @@ -132,8 +130,7 @@ if (mode == "symbol") { if (result == null || length(result.symbols) == 0) { log.console("Symbol '" + symbol_name + "' not found in " + text(length(files)) + " files") } else { - print(json.encode(result, true)) - print("\n") + log.compile(json.encode(result, true)) } } } diff --git a/fold.ce b/fold.ce index d1bd5cf5..068aa412 100644 --- a/fold.ce +++ b/fold.ce @@ -4,4 +4,4 @@ var json = use("json") var shop = use("internal/shop") var filename = args[0] var folded = shop.analyze_file(filename) -print(json.encode(folded)) +log.compile(json.encode(folded)) diff --git a/index.ce b/index.ce index 4b3a8fb9..6e5d776e 100644 --- a/index.ce +++ b/index.ce @@ -52,8 +52,7 @@ if (output_path != null) { fd.slurpwrite(output_path, out) log.console('Wrote index to ' + output_path) } else { - print(out) - print("\n") + log.compile(out) } $stop() diff --git a/internal/bootstrap.cm b/internal/bootstrap.cm index d2fb6590..49577c4d 100644 --- a/internal/bootstrap.cm +++ b/internal/bootstrap.cm @@ -34,7 +34,7 @@ function boot_load(name) { var mcode_blob = null var mach_blob = null if (!fd.is_file(mcode_path)) { - print("error: missing seed: " + name + "\n") + os.print("error: missing seed: " + name + "\n") disrupt } mcode_blob = fd.slurp(mcode_path) @@ -60,9 +60,9 @@ function analyze(src, filename) { e = ast.errors[_i] msg = e.message 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 - print(`${filename}: error: ${msg}`) + os.print(`${filename}: error: ${msg}\n`) _i = _i + 1 } disrupt @@ -105,4 +105,4 @@ while (_i < length(seed_files)) { compile_and_cache(entry.name, core_path + '/' + entry.path) _i = _i + 1 } -print("bootstrap: cache seeded\n") +os.print("bootstrap: cache seeded\n") diff --git a/internal/engine.cm b/internal/engine.cm index 81815b53..a679cd4a 100644 --- a/internal/engine.cm +++ b/internal/engine.cm @@ -58,7 +58,7 @@ function boot_load(name) { var mcode_blob = null var mach_blob = null if (!fd.is_file(mcode_path)) { - print("error: missing boot seed: " + name + "\n") + os.print("error: missing boot seed: " + name + "\n") disrupt } mcode_blob = fd.slurp(mcode_path) @@ -103,7 +103,7 @@ function load_pipeline_module(name, env) { tok_result = boot_tok(src, source_path) ast = boot_par(tok_result.tokens, src, source_path, boot_tok) 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 } ast = boot_fld(ast) @@ -126,7 +126,7 @@ function load_pipeline_module(name, env) { mach_blob = mach_compile_mcode_bin(name, text(mcode_blob)) return mach_load(mach_blob, env) } - print("error: cannot load pipeline module: " + name + "\n") + os.print("error: cannot load pipeline module: " + name + "\n") disrupt } @@ -166,9 +166,9 @@ function analyze(src, filename) { col = e.column if (msg != prev_msg || line != prev_line) { if (line != null && col != null) - print(`${filename}:${text(line)}:${text(col)}: error: ${msg}`) + os.print(`${filename}:${text(line)}:${text(col)}: error: ${msg}\n`) else - print(`${filename}: error: ${msg}`) + os.print(`${filename}: error: ${msg}\n`) } prev_line = line prev_msg = msg @@ -291,7 +291,7 @@ function use_core(path) { result = mach_load(mach_blob, env) } } 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 } _load_mod() @@ -485,7 +485,7 @@ function load_log_config() { terminal: { type: "console", format: "pretty", - channels: ["console", "error", "system"], + channels: ["*"], stack: ["error"] } } diff --git a/internal/shop.cm b/internal/shop.cm index 2d549f85..40e3668d 100644 --- a/internal/shop.cm +++ b/internal/shop.cm @@ -153,7 +153,7 @@ function package_in_shop(package) { function abs_path_to_package(package_dir) { 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 } @@ -352,12 +352,12 @@ Shop.resolve_package_info = function(pkg) { // Verify if a package name is valid and return status Shop.verify_package_name = function(pkg) { - if (!pkg) { print("Empty package name"); disrupt } - if (pkg == 'local') { print("local is not a valid package name"); disrupt } - if (pkg == 'core') { print("core is not a valid package name"); disrupt } + if (!pkg) { log.error("Empty package name"); disrupt } + if (pkg == 'local') { log.error("local is not a valid package name"); disrupt } + if (pkg == 'core') { log.error("core is not a valid package name"); disrupt } 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 } } @@ -661,10 +661,10 @@ var _streamline_mod = null // Compile a module and return its bytecode blob. // The bytecode is cached on disk by content hash. 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)) - 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 native_result = null var cached = null @@ -739,7 +739,7 @@ function resolve_mod_fn(path, pkg) { 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 (!_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 } ast = analyze(content, path) @@ -758,7 +758,7 @@ function resolve_mod_fn(path, pkg) { 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 } @@ -1223,7 +1223,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 } - if (!used) { print(`Module ${info} returned null`); disrupt } + if (!used) { log.error(`Module ${info} returned null`); disrupt } return used } @@ -1481,7 +1481,7 @@ Shop.extract = function(pkg) { var zip_blob = get_package_zip(pkg) if (!zip_blob) { - print("No zip blob available for " + pkg) + log.error("No zip blob available for " + pkg) disrupt } @@ -1569,7 +1569,7 @@ Shop.update = function(pkg) { function install_zip(zip_blob, target_dir) { 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_dir(target_dir)) fd.rmdir(target_dir, 1) @@ -1641,14 +1641,14 @@ Shop.get = function(pkg) { if (!lock[pkg]) { info = Shop.resolve_package_info(pkg) if (!info) { - print("Invalid package: " + pkg); disrupt + log.error("Invalid package: " + pkg); disrupt } commit = null if (info != 'local') { commit = fetch_remote_hash(pkg) if (!commit) { - print("Could not resolve commit for " + pkg); disrupt + log.error("Could not resolve commit for " + pkg); disrupt } } @@ -1813,7 +1813,7 @@ Shop.load_as_mach = function(path, pkg) { var inject = 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 content = text(fd.slurp(file_path)) @@ -1838,7 +1838,7 @@ Shop.load_as_mach = function(path, pkg) { 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 (!_mcode_mod || !_streamline_mod) { - print('error: compiler modules not loaded') + log.error('error: compiler modules not loaded') disrupt } ast = analyze(content, file_path) @@ -1874,7 +1874,7 @@ Shop.load_as_dylib = function(path, pkg) { var inject = 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 if (!real_pkg) { @@ -1942,7 +1942,7 @@ Shop.use_native = function(path, package_context) { var src_path = path if (!starts_with(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 pkg = file_info.package || package_context @@ -1955,7 +1955,7 @@ Shop.use_native = function(path, package_context) { var dylib_path = build.compile_native(src_path, null, null, pkg) 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 var inject = Shop.script_inject_for(file_info) diff --git a/ir_report.ce b/ir_report.ce index 70845cb0..43a47730 100644 --- a/ir_report.ce +++ b/ir_report.ce @@ -55,22 +55,22 @@ while (i < length(args)) { } else if (!starts_with(arg, "--")) { filename = arg } else { - print(`unknown option: ${arg}\n`) - print("usage: cell --core . ir_report.ce [options] \n") + log.error(`unknown option: ${arg}`) + log.error("usage: cell --core . ir_report.ce [options] ") $stop() } i = i + 1 } if (filename == null) { - print("usage: cell --core . ir_report.ce [options] \n") - print(" --summary per-pass JSON summaries (default)\n") - print(" --events include rewrite events\n") - print(" --types include type deltas\n") - print(" --ir-before=PASS print canonical IR before PASS\n") - print(" --ir-after=PASS print canonical IR after PASS\n") - print(" --ir-all print canonical IR before/after every pass\n") - print(" --full everything\n") + log.compile("usage: cell --core . ir_report.ce [options] ") + log.compile(" --summary per-pass JSON summaries (default)") + log.compile(" --events include rewrite events") + log.compile(" --types include type deltas") + log.compile(" --ir-before=PASS print canonical IR before PASS") + log.compile(" --ir-after=PASS print canonical IR after PASS") + log.compile(" --ir-all print canonical IR before/after every pass") + log.compile(" --full everything") $stop() } @@ -114,8 +114,7 @@ var optimized = streamline(compiled, log) // --- Output --- var emit = function(obj) { - print(json.encode(obj)) - print("\n") + log.compile(json.encode(obj)) } // Pass summaries (always) diff --git a/link.cm b/link.cm index b3fba589..90fc5389 100644 --- a/link.cm +++ b/link.cm @@ -75,7 +75,7 @@ Link.load = function() { if (cfg && cfg.links) link_cache = cfg.links else link_cache = {} } disruption { - print("Warning: Failed to load link.toml\n") + log.build("Warning: Failed to load link.toml") link_cache = {} } _load() @@ -95,7 +95,7 @@ Link.add = function(canonical, target, shop) { // Validate canonical package exists in shop var lock = shop.load_lock() 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 } @@ -103,7 +103,7 @@ Link.add = function(canonical, target, shop) { if (starts_with(target, '/')) { // Local path - must have 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 } } else { @@ -132,7 +132,7 @@ Link.add = function(canonical, target, shop) { var dep_locator = cfg.dependencies[alias] // Skip local dependencies that don't exist 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 } // Install the dependency if not already in shop @@ -140,18 +140,18 @@ Link.add = function(canonical, target, shop) { shop.get(dep_locator) shop.extract(dep_locator) } disruption { - print(` Warning: Could not install dependency ${dep_locator}\n`) + log.build(` Warning: Could not install dependency ${dep_locator}`) } _get_dep() }) } } disruption { - print(` Warning: Could not read dependencies from ${toml_path}\n`) + log.build(` Warning: Could not read dependencies from ${toml_path}`) } _install_deps() } - print("Linked " + canonical + " -> " + target + "\n") + log.build("Linked " + canonical + " -> " + target) return true } @@ -163,12 +163,12 @@ Link.remove = function(canonical) { var target_dir = get_package_abs_dir(canonical) if (fd.is_link(target_dir)) { fd.unlink(target_dir) - print("Removed symlink at " + target_dir + "\n") + log.build("Removed symlink at " + target_dir) } delete links[canonical] Link.save(links) - print("Unlinked " + canonical + "\n") + log.build("Unlinked " + canonical) return true } @@ -183,7 +183,7 @@ Link.clear = function() { }) Link.save({}) - print("Cleared all links\n") + log.build("Cleared all links") return true } diff --git a/mcode.ce b/mcode.ce index ca2e0fbd..1fef5b3b 100644 --- a/mcode.ce +++ b/mcode.ce @@ -31,7 +31,7 @@ if (!filename) { var compiled = shop.mcode_file(filename) if (!show_pretty) { - print(json.encode(compiled)) + log.compile(json.encode(compiled)) $stop() } @@ -68,16 +68,16 @@ var dump_function = function(func, name) { var operands = null var pc_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) { - print(" (empty)") + log.compile(" (empty)") return null } while (i < length(instrs)) { instr = instrs[i] if (is_text(instr)) { if (!starts_with(instr, "_nop_")) { - print(`${instr}:`) + log.compile(`${instr}:`) } } else if (is_array(instr)) { op = instr[0] @@ -91,7 +91,7 @@ var dump_function = function(func, name) { operands = text(parts, ", ") pc_str = pad_right(text(pc), 5) op_str = pad_right(op, 14) - print(` ${pc_str} ${op_str} ${operands}`) + log.compile(` ${pc_str} ${op_str} ${operands}`) pc = pc + 1 } i = i + 1 diff --git a/package.cm b/package.cm index 506006c4..46c8f0b6 100644 --- a/package.cm +++ b/package.cm @@ -50,7 +50,7 @@ package.load_config = function(name) var config_path = get_path(name) + '/cell.toml' 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)) @@ -59,7 +59,7 @@ package.load_config = function(name) var result = toml.decode(content) if (!result) { - print(`TOML decode returned null for ${config_path}`) + log.error(`TOML decode returned null for ${config_path}`) return {} } diff --git a/parse.ce b/parse.ce index cb29c4d2..cb200532 100644 --- a/parse.ce +++ b/parse.ce @@ -4,4 +4,4 @@ var json = use("json") var shop = use("internal/shop") var filename = args[0] var ast = shop.parse_file(filename) -print(json.encode(ast, true)) +log.compile(json.encode(ast, true)) diff --git a/pronto.cm b/pronto.cm index e860d550..446c7a9e 100644 --- a/pronto.cm +++ b/pronto.cm @@ -15,14 +15,14 @@ function is_requestor(fn) { function check_requestors(list, factory) { 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 } } function check_callback(cb, factory) { 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 } } @@ -32,7 +32,7 @@ function check_callback(cb, factory) { function fallback(requestor_array) { def factory = 'fallback' 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 } check_requestors(requestor_array, factory) @@ -89,7 +89,7 @@ function fallback(requestor_array) { function parallel(requestor_array, throttle, need) { def factory = 'parallel' 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 } check_requestors(requestor_array, factory) @@ -101,12 +101,12 @@ function parallel(requestor_array, throttle, need) { var _need = need if (_need == null) _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 } 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 } @@ -184,7 +184,7 @@ function parallel(requestor_array, throttle, need) { function race(requestor_array, throttle, need) { def factory = 'race' 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 } check_requestors(requestor_array, factory) @@ -193,12 +193,12 @@ function race(requestor_array, throttle, need) { var _need = need if (_need == null) _need = 1 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 } 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 } @@ -279,7 +279,7 @@ function race(requestor_array, throttle, need) { function sequence(requestor_array) { def factory = 'sequence' 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 } check_requestors(requestor_array, factory) @@ -339,7 +339,7 @@ function sequence(requestor_array) { function requestorize(unary) { def factory = 'requestorize' 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 } diff --git a/qbe.ce b/qbe.ce index 5521a1b6..d120ffa4 100644 --- a/qbe.ce +++ b/qbe.ce @@ -17,4 +17,4 @@ var folded = fold(ast) var compiled = mcode(folded) var optimized = streamline(compiled) var il = qbe_emit(optimized, qbe_macros) -print(il) +log.compile(il) diff --git a/run_aot.ce b/run_aot.ce index 1e3588ff..fc4a01bd 100644 --- a/run_aot.ce +++ b/run_aot.ce @@ -7,7 +7,7 @@ var shop = use('internal/shop') var fd = use('fd') if (length(args) < 1) { - print('usage: cell run_aot ') + log.compile('usage: cell run_aot ') return } @@ -16,7 +16,7 @@ if (!fd.is_file(file)) { if (!ends_with(file, '.ce') && fd.is_file(file + '.ce')) file = file + '.ce' else { - print('file not found: ' + file) + log.error('file not found: ' + file) return } } diff --git a/run_native.ce b/run_native.ce index 0d803521..b34ea1d3 100644 --- a/run_native.ce +++ b/run_native.ce @@ -11,8 +11,8 @@ var fd = use('fd') var shop = use('internal/shop') if (length(args) < 1) { - print('usage: cell --dev run_native ') - print(' e.g. cell --dev run_native num_torture') + log.compile('usage: cell --dev run_native ') + log.compile(' e.g. cell --dev run_native num_torture') return } @@ -28,52 +28,52 @@ if (length(args) > 1) { } // --- Interpreted run --- -print('--- interpreted ---') +log.compile('--- interpreted ---') var t1 = os.now() var mod_interp = use(name) var t2 = os.now() var result_interp = null 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() result_interp = mod_interp(test_arg) t2 = os.now() } result_interp = result_interp != null ? result_interp : mod_interp var ms_interp = (t2 - t1) / 1000000 -print('result: ' + text(result_interp)) -print('time: ' + text(ms_interp) + ' ms') +log.compile('result: ' + text(result_interp)) +log.compile('time: ' + text(ms_interp) + ' ms') // --- Native run --- // Resolve to .cm path for shop.use_native() var mod_path = name + '.cm' if (!fd.is_file(mod_path)) { - print('\nno ' + mod_path + ' found') + log.error('\nno ' + mod_path + ' found') return } -print('\n--- native ---') +log.compile('\n--- native ---') var t3 = os.now() var mod_native = shop.use_native(mod_path) var t4 = os.now() var result_native = null 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() result_native = mod_native(test_arg) t4 = os.now() } result_native = result_native != null ? result_native : mod_native var ms_native = (t4 - t3) / 1000000 -print('result: ' + text(result_native)) -print('time: ' + text(ms_native) + ' ms') +log.compile('result: ' + text(result_native)) +log.compile('time: ' + text(ms_native) + ' ms') // --- Comparison --- -print('\n--- comparison ---') +log.compile('\n--- comparison ---') var match = result_interp == result_native var speedup = 0 -print('match: ' + text(match)) +log.compile('match: ' + text(match)) if (ms_native > 0) { speedup = ms_interp / ms_native - print('speedup: ' + text(speedup) + 'x') + log.compile('speedup: ' + text(speedup) + 'x') } diff --git a/run_native_seed.ce b/run_native_seed.ce index ae837557..dbc5f46c 100644 --- a/run_native_seed.ce +++ b/run_native_seed.ce @@ -5,7 +5,7 @@ var fd = use("fd") var os = use("os") if (length(args) < 1) { - print("usage: cell --dev --seed run_native_seed ") + log.compile("usage: cell --dev --seed run_native_seed ") disrupt } @@ -24,29 +24,29 @@ if (length(args) > 1) { } // --- Interpreted run --- -print("--- interpreted ---") +log.compile("--- interpreted ---") var t1 = os.now() var mod_interp = use(name) var t2 = os.now() var result_interp = null 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() result_interp = mod_interp(test_arg) t2 = os.now() } result_interp = result_interp != null ? result_interp : mod_interp var ms_interp = (t2 - t1) / 1000000 -print("result: " + text(result_interp)) -print("time: " + text(ms_interp) + " ms") +log.compile("result: " + text(result_interp)) +log.compile("time: " + text(ms_interp) + " ms") // --- Native run --- if (!fd.is_file(dylib_path)) { - print("\nno " + dylib_path + " found") + log.error("\nno " + dylib_path + " found") disrupt } -print("\n--- native ---") +log.compile("\n--- native ---") var t3 = os.now() var lib = os.dylib_open(dylib_path) var t4 = os.now() @@ -54,7 +54,7 @@ var mod_native = os.dylib_symbol(lib, symbol) var t5 = os.now() var result_native = null 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() result_native = mod_native(test_arg) t5 = os.now() @@ -62,17 +62,17 @@ if (is_function(mod_native)) { result_native = result_native != null ? result_native : mod_native var ms_native = (t5 - t3) / 1000000 var ms_exec = (t5 - t4) / 1000000 -print("result: " + text(result_native)) -print("load: " + text((t4 - t3) / 1000000) + " ms") -print("exec: " + text(ms_exec) + " ms") -print("total: " + text(ms_native) + " ms") +log.compile("result: " + text(result_native)) +log.compile("load: " + text((t4 - t3) / 1000000) + " ms") +log.compile("exec: " + text(ms_exec) + " ms") +log.compile("total: " + text(ms_native) + " ms") // --- Comparison --- -print("\n--- comparison ---") -print("match: " + text(result_interp == result_native)) +log.compile("\n--- comparison ---") +log.compile("match: " + text(result_interp == result_native)) 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) { - print("speedup: " + text(ms_interp / ms_exec) + "x (exec only)") + log.compile("speedup: " + text(ms_interp / ms_exec) + "x (exec only)") } diff --git a/seed.ce b/seed.ce index d9aa2cd1..89b9cd4c 100644 --- a/seed.ce +++ b/seed.ce @@ -32,10 +32,10 @@ for (i = 0; i < length(args); i++) { if (args[i] == '--clean') { clean = true } else if (args[i] == '--help' || args[i] == '-h') { - print("usage: pit seed [--clean]") - print("") - print(" Regenerate boot seed files in boot/") - print(" --clean Also clear the build cache after") + log.compile("usage: pit seed [--clean]") + log.compile("") + log.compile(" Regenerate boot seed files in boot/") + log.compile(" --clean Also clear the build cache after") $stop() } } @@ -62,11 +62,11 @@ for (i = 0; i < length(pipeline_modules); i++) { src_path = core_dir + '/' + name + '.cm' if (!fd.is_file(src_path)) { - print('WARNING: source not found: ' + src_path) + log.error('WARNING: source not found: ' + src_path) continue } - print('Seeding ' + name + '.cm ...') + log.compile('Seeding ' + name + '.cm ...') src = text(fd.slurp(src_path)) tok = tokenize(src, src_path) 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' 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 } // Regenerate bootstrap.cm seed var bootstrap_path = core_dir + '/internal/bootstrap.cm' if (fd.is_file(bootstrap_path)) { - print('Seeding bootstrap.cm ...') + log.compile('Seeding bootstrap.cm ...') src = text(fd.slurp(bootstrap_path)) tok = tokenize(src, bootstrap_path) 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' 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 } 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) { build_dir = shop.get_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 + '"') - print('Build cache cleared. Next run will recompile from new seeds.') + log.compile('Build cache cleared. Next run will recompile from new seeds.') } else { - print('No build cache to clear.') + log.compile('No build cache to clear.') } } diff --git a/source/quickjs-internal.h b/source/quickjs-internal.h index dfcce6e2..afd37004 100644 --- a/source/quickjs-internal.h +++ b/source/quickjs-internal.h @@ -1057,7 +1057,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_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_print (JSContext *ctx, JSValue this_val, int argc, JSValue *argv); JSValue JS_GetStack(JSContext *ctx); JSValue JS_RaiseOOM (JSContext *ctx); diff --git a/source/runtime.c b/source/runtime.c index 95c9922a..6815d75e 100644 --- a/source/runtime.c +++ b/source/runtime.c @@ -8132,19 +8132,6 @@ static JSValue js_cell_text_format (JSContext *ctx, JSValue this_val, int argc, 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) { (void)this_val; (void)argc; (void)argv; @@ -11551,7 +11538,6 @@ static void JS_AddIntrinsicBaseObjects (JSContext *ctx) { } /* 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, "caller_info", js_caller_info, 1); } diff --git a/streamline.ce b/streamline.ce index 1d82f97a..6e2688df 100644 --- a/streamline.ce +++ b/streamline.ce @@ -36,7 +36,7 @@ for (i = 0; i < length(args); i++) { } if (!filename) { - print("usage: cell streamline [--stats] [--ir] [--check] [--types] ") + log.compile("usage: cell streamline [--stats] [--ir] [--check] [--types] ") $stop() } @@ -50,7 +50,7 @@ var optimized = shop.compile_file(filename) // If no flags, default to full JSON output if (!show_stats && !show_ir && !show_check && !show_types) { - print(json.encode(optimized, true)) + log.compile(json.encode(optimized, true)) $stop() } @@ -103,29 +103,29 @@ var print_func_stats = function(func, before_func, name) { var before_stats = before_func ? ir_stats.detailed_stats(before_func) : null var before_total = before_stats ? before_stats.instr : stats.instr - print(` ${name}`) - print(` 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(` ${name}`) + log.compile(` args=${text(nr_args)} slots=${text(nr_slots)} close_slots=${text(nr_close)}`) + log.compile(` instructions: ${text(stats.instr)} total, ${text(nops)} nops eliminated`) 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)}`) - print(` guard=${text(stats.guard)} arith=${text(stats.arith)} move=${text(stats.move)} const=${text(stats.const)}`) + log.compile(` load=${text(stats.load)} store=${text(stats.store)} branch=${text(stats.branch)} call=${text(stats.call)}`) + log.compile(` guard=${text(stats.guard)} arith=${text(stats.arith)} move=${text(stats.move)} const=${text(stats.const)}`) 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 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 nr_slots = func.nr_slots != null ? func.nr_slots : 0 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)`) } } @@ -246,9 +246,9 @@ var dump_function_typed = function(func, name) { var pc_str = null var op_str = 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) { - print(" (empty)") + log.compile(" (empty)") return null } while (i < length(instrs)) { @@ -259,7 +259,7 @@ var dump_function_typed = function(func, name) { continue } slot_types = {} - print(`${instr}:`) + log.compile(`${instr}:`) } else if (is_array(instr)) { op = instr[0] n = length(instr) @@ -275,9 +275,9 @@ var dump_function_typed = function(func, name) { op_str = pad_right(op, 14) line = pad_right(` ${pc_str} ${op_str} ${operands}`, 50) if (length(annotation) > 0) { - print(`${line} ; ${annotation}`) + log.compile(`${line} ; ${annotation}`) } else { - print(line) + log.compile(line) } track_types(slot_types, instr) pc = pc + 1 @@ -296,7 +296,7 @@ var bfunc = null var fname = null if (show_stats) { - print(`\n--- Stats for ${filename} ---`) + log.compile(`\n--- Stats for ${filename} ---`) } // Main function @@ -340,7 +340,7 @@ if (optimized.functions != null) { } if (show_stats) { - print('---') + log.compile('---') } $stop() diff --git a/streamline.cm b/streamline.cm index 9fe9adb5..a06f8e15 100644 --- a/streamline.cm +++ b/streamline.cm @@ -13,11 +13,11 @@ var streamline = function(ir, log) { var errs = verifier.verify_all(func, pass_name) var i = 0 while (i < length(errs)) { - print(`[verify_ir] ${errs[i]}\n`) + log.error(`[verify_ir] ${errs[i]}`) i = i + 1 } 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}`) } } } diff --git a/syntax_suite.ce b/syntax_suite.ce index 17dd396b..2c4a3126 100644 --- a/syntax_suite.ce +++ b/syntax_suite.ce @@ -632,11 +632,11 @@ run("inequality not confused with bang ident", function() { // === 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 if (failed > 0) { - print("") + log.test("") for (_j = 0; _j < failed; _j++) { - print(" FAIL " + error_names[_j] + ": " + error_reasons[_j]) + log.error(" FAIL " + error_names[_j] + ": " + error_reasons[_j]) } } diff --git a/test_backward.cm b/test_backward.cm index 9465c976..3d7f4915 100644 --- a/test_backward.cm +++ b/test_backward.cm @@ -20,8 +20,8 @@ var concat_all = function(a, b, c) { return a + b + c } -if (sum_ints(1, 2, 3) != 6) { print("FAIL sum_ints") } -if (count_down(5) != 15) { print("FAIL count_down") } -if (concat_all("a", "b", "c") != "abc") { print("FAIL concat_all") } +if (sum_ints(1, 2, 3) != 6) { log.error("FAIL sum_ints") } +if (count_down(5) != 15) { log.error("FAIL count_down") } +if (concat_all("a", "b", "c") != "abc") { log.error("FAIL concat_all") } -print("backward type tests passed") +log.test("backward type tests passed") diff --git a/test_intrinsics.cm b/test_intrinsics.cm index a649aeae..9cbcce5b 100644 --- a/test_intrinsics.cm +++ b/test_intrinsics.cm @@ -7,57 +7,57 @@ var num = 42 var boo = true // is_array -if (!is_array(arr)) { print("FAIL is_array(arr)") } -if (is_array(rec)) { print("FAIL is_array(rec)") } -if (is_array(42)) { print("FAIL is_array(42)") } +if (!is_array(arr)) { log.error("FAIL is_array(arr)") } +if (is_array(rec)) { log.error("FAIL is_array(rec)") } +if (is_array(42)) { log.error("FAIL is_array(42)") } // is_object -if (!is_object(rec)) { print("FAIL is_object(rec)") } -if (is_object(arr)) { print("FAIL is_object(arr)") } -if (is_object(42)) { print("FAIL is_object(42)") } +if (!is_object(rec)) { log.error("FAIL is_object(rec)") } +if (is_object(arr)) { log.error("FAIL is_object(arr)") } +if (is_object(42)) { log.error("FAIL is_object(42)") } // is_function -if (!is_function(fn)) { print("FAIL is_function(fn)") } -if (is_function(rec)) { print("FAIL is_function(rec)") } +if (!is_function(fn)) { log.error("FAIL is_function(fn)") } +if (is_function(rec)) { log.error("FAIL is_function(rec)") } // is_stone var frozen = stone([1, 2]) -if (!is_stone(frozen)) { print("FAIL is_stone(frozen)") } -if (is_stone(arr)) { print("FAIL is_stone(arr)") } -if (!is_stone(42)) { print("FAIL is_stone(42)") } -if (!is_stone("hi")) { print("FAIL is_stone(str)") } +if (!is_stone(frozen)) { log.error("FAIL is_stone(frozen)") } +if (is_stone(arr)) { log.error("FAIL is_stone(arr)") } +if (!is_stone(42)) { log.error("FAIL is_stone(42)") } +if (!is_stone("hi")) { log.error("FAIL is_stone(str)") } // length -if (length(arr) != 3) { print("FAIL length(arr)") } -if (length(txt) != 5) { print("FAIL length(txt)") } -if (length([]) != 0) { print("FAIL length([])") } +if (length(arr) != 3) { log.error("FAIL length(arr)") } +if (length(txt) != 5) { log.error("FAIL length(txt)") } +if (length([]) != 0) { log.error("FAIL length([])") } // is_integer (already existed but now inlined) -if (!is_integer(42)) { print("FAIL is_integer(42)") } -if (is_integer(3.14)) { print("FAIL is_integer(3.14)") } +if (!is_integer(42)) { log.error("FAIL is_integer(42)") } +if (is_integer(3.14)) { log.error("FAIL is_integer(3.14)") } // is_text -if (!is_text("hi")) { print("FAIL is_text(hi)") } -if (is_text(42)) { print("FAIL is_text(42)") } +if (!is_text("hi")) { log.error("FAIL is_text(hi)") } +if (is_text(42)) { log.error("FAIL is_text(42)") } // is_number -if (!is_number(42)) { print("FAIL is_number(42)") } -if (!is_number(3.14)) { print("FAIL is_number(3.14)") } -if (is_number("hi")) { print("FAIL is_number(hi)") } +if (!is_number(42)) { log.error("FAIL is_number(42)") } +if (!is_number(3.14)) { log.error("FAIL is_number(3.14)") } +if (is_number("hi")) { log.error("FAIL is_number(hi)") } // is_logical -if (!is_logical(true)) { print("FAIL is_logical(true)") } -if (is_logical(42)) { print("FAIL is_logical(42)") } +if (!is_logical(true)) { log.error("FAIL is_logical(true)") } +if (is_logical(42)) { log.error("FAIL is_logical(42)") } // is_null -if (!is_null(null)) { print("FAIL is_null(null)") } -if (is_null(42)) { print("FAIL is_null(42)") } +if (!is_null(null)) { log.error("FAIL is_null(null)") } +if (is_null(42)) { log.error("FAIL is_null(42)") } // push (inlined) var a = [1] push(a, 2) push(a, 3) -if (length(a) != 3) { print("FAIL push length") } -if (a[2] != 3) { print("FAIL push value") } +if (length(a) != 3) { log.error("FAIL push length") } +if (a[2] != 3) { log.error("FAIL push value") } -print("all intrinsic tests passed") +log.test("all intrinsic tests passed") diff --git a/test_parse_boot.cm b/test_parse_boot.cm index 05dd3cdf..eb07a048 100644 --- a/test_parse_boot.cm +++ b/test_parse_boot.cm @@ -14,29 +14,29 @@ var f = null var bytecode = null var has_errors = ast.errors != null && length(ast.errors) > 0 if (has_errors) { - print("PARSE ERRORS:") + log.error("PARSE 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 } } else { - print("Parse OK") - print(" statements: " + text(length(ast.statements))) + log.test("Parse OK") + log.test(" statements: " + text(length(ast.statements))) if (ast.functions != null) { - print(" functions: " + text(length(ast.functions))) + log.test(" functions: " + text(length(ast.functions))) } else { - print(" functions: null") + log.test(" functions: null") } folded = fold(ast) ast_json = json.encode(folded) f = fd.open("/tmp/bootstrap_ast.json", "w") fd.write(f, ast_json) 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) - print("Bytecode size: " + text(length(bytecode))) + log.test("Bytecode size: " + text(length(bytecode))) f = fd.open("/tmp/bootstrap_test.mach", "w") fd.write(f, bytecode) fd.close(f) - print("Wrote bytecode to /tmp/bootstrap_test.mach") + log.test("Wrote bytecode to /tmp/bootstrap_test.mach") } diff --git a/tests/actor_memory_abuse.ce b/tests/actor_memory_abuse.ce index 3f403ca9..bb9d039d 100644 --- a/tests/actor_memory_abuse.ce +++ b/tests/actor_memory_abuse.ce @@ -6,7 +6,7 @@ $start(function(event) { // child started, wait for it to die from memory abuse } if (event.type == 'disrupt') { - print("PASS: memory abusing actor killed") + log.test("PASS: memory abusing actor killed") $stop() } }, 'tests/hang_actor_memory') diff --git a/tests/actor_slow_killed.ce b/tests/actor_slow_killed.ce index cd58acf0..4008accc 100644 --- a/tests/actor_slow_killed.ce +++ b/tests/actor_slow_killed.ce @@ -7,7 +7,7 @@ $start(function(event) { } if (event.type == 'disrupt') { // child was killed by the timer — success - print("PASS: slow actor killed by timer") + log.test("PASS: slow actor killed by timer") $stop() } }, 'tests/hang_actor') diff --git a/tests/actor_suspend_resume.ce b/tests/actor_suspend_resume.ce index 387ad1e6..ff977a94 100644 --- a/tests/actor_suspend_resume.ce +++ b/tests/actor_suspend_resume.ce @@ -2,9 +2,9 @@ // completing the computation correctly. $receiver(function(msg) { if (msg.sum == 12499997500000) { - print("PASS: actor suspended and resumed correctly") + log.test("PASS: actor suspended and resumed correctly") } else { - print(`FAIL: expected 12499997500000, got ${msg.sum}`) + log.error(`FAIL: expected 12499997500000, got ${msg.sum}`) } $stop() }) @@ -14,7 +14,7 @@ $start(function(event) { send(event.actor, {count: 5000000, reply: $self}) } if (event.type == 'disrupt') { - print("FAIL: actor was killed instead of completing") + log.error("FAIL: actor was killed instead of completing") $stop() } }, 'tests/slow_compute_actor') diff --git a/tests/decl_restrictions.ce b/tests/decl_restrictions.ce index 413c56fc..9271b725 100644 --- a/tests/decl_restrictions.ce +++ b/tests/decl_restrictions.ce @@ -155,12 +155,12 @@ run("valid var in function body", function() { // === 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 if (failed > 0) { - print("") + log.test("") for (_j = 0; _j < failed; _j++) { - print(" FAIL " + error_names[_j] + ": " + error_reasons[_j]) + log.error(" FAIL " + error_names[_j] + ": " + error_reasons[_j]) } } $stop() diff --git a/tests/demo.ce b/tests/demo.ce index dc9c5872..3da56bb5 100644 --- a/tests/demo.ce +++ b/tests/demo.ce @@ -1,7 +1,7 @@ function safe_add(a, b) { return a + b } disruption { - print("disruption caught in safe_add") + log.test("disruption caught in safe_add") } function inner() { @@ -11,19 +11,19 @@ function inner() { function outer() { inner() } disruption { - print("disruption caught in outer — from inner()") + log.test("disruption caught in outer — from inner()") } // Test 1: explicit disrupt with handler function test_explicit() { disrupt } disruption { - print("test 1: explicit disrupt handled") + log.test("test 1: explicit disrupt handled") } test_explicit() // Test 2: type error disrupt (number + function) -safe_add(1, print) +safe_add(1, is_number) // Test 3: unwinding — inner disrupts, outer catches outer() @@ -32,9 +32,9 @@ outer() function test_nested() { disrupt } disruption { - print("test 4: first disruption") + log.test("test 4: first disruption") } test_nested() -print("done") +log.test("done") $stop() diff --git a/tokenize.ce b/tokenize.ce index 875e5e5b..12a32371 100644 --- a/tokenize.ce +++ b/tokenize.ce @@ -4,4 +4,4 @@ var json = use("json") var shop = use("internal/shop") var filename = args[0] 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})) diff --git a/vm_suite.ce b/vm_suite.ce index 553456b4..0c6f84d9 100644 --- a/vm_suite.ce +++ b/vm_suite.ce @@ -5541,11 +5541,11 @@ run("gc blob forward pointer chase", function() { // 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 if (failed > 0) { - print("") + log.test("") for (_j = 0; _j < failed; _j++) { - print(" FAIL " + error_names[_j] + ": " + error_reasons[_j]) + log.error(" FAIL " + error_names[_j] + ": " + error_reasons[_j]) } }