diff --git a/bench_native.ce b/bench_native.ce index 7fef137c..de5c8b5c 100644 --- a/bench_native.ce +++ b/bench_native.ce @@ -64,13 +64,16 @@ var format_ns = function(ns) { var collect_benches = function(mod) { var benches = [] + var keys = null + var i = 0 + var k = null if (is_function(mod)) { push(benches, {name: 'main', fn: mod}) } else if (is_object(mod)) { - var keys = array(mod) - var i = 0 + keys = array(mod) + i = 0 while (i < length(keys)) { - var k = keys[i] + k = keys[i] if (is_function(mod[k])) { push(benches, {name: k, fn: mod[k]}) } @@ -128,10 +131,11 @@ if (length(vm_benches) == 0) { var native_mod = null var native_benches = [] var has_native = fd.is_file(dylib_path) +var lib = null if (has_native) { print('loading native module: ' + dylib_path) - var lib = os.dylib_open(dylib_path) + lib = os.dylib_open(dylib_path) native_mod = os.dylib_symbol(lib, symbol) native_benches = collect_benches(native_mod) } else { @@ -146,27 +150,34 @@ print('samples: ' + text(iterations) + ' (warmup: ' + text(WARMUP) + ')') print('') var pad = function(s, n) { - while (length(s) < n) s = s + ' ' - return s + var result = s + while (length(result) < n) result = result + ' ' + return result } var i = 0 +var b = null +var vm_result = null +var j = 0 +var found = false +var nat_result = null +var speedup = 0 while (i < length(vm_benches)) { - var b = vm_benches[i] - var vm_result = run_bench(b.fn, 'vm') + b = vm_benches[i] + vm_result = run_bench(b.fn, 'vm') print(pad(b.name, 20) + ' VM: ' + pad(format_ns(vm_result.median), 12) + ' (median) ' + format_ns(vm_result.mean) + ' (mean)') // find matching native bench - var j = 0 - var found = false + j = 0 + found = false while (j < length(native_benches)) { if (native_benches[j].name == b.name) { - var nat_result = run_bench(native_benches[j].fn, 'native') + nat_result = run_bench(native_benches[j].fn, 'native') print(pad('', 20) + ' NT: ' + pad(format_ns(nat_result.median), 12) + ' (median) ' + format_ns(nat_result.mean) + ' (mean)') if (nat_result.median > 0) { - var speedup = vm_result.median / nat_result.median + speedup = vm_result.median / nat_result.median print(pad('', 20) + ' speedup: ' + text(round(speedup * 100) / 100) + 'x') } found = true diff --git a/clean.ce b/clean.ce index 17dd9c29..f3ab6b10 100644 --- a/clean.ce +++ b/clean.ce @@ -89,6 +89,7 @@ var dirs_to_delete = [] // Gather packages to clean var packages_to_clean = [] +var _gather = null if (is_shop_scope) { packages_to_clean = shop.list_packages() @@ -99,7 +100,6 @@ if (is_shop_scope) { // Single package push(packages_to_clean, scope) - var _gather = null if (deep) { _gather = function() { deps = pkg.gather_dependencies(scope) diff --git a/graph.ce b/graph.ce index d899a9a8..07d24566 100644 --- a/graph.ce +++ b/graph.ce @@ -143,6 +143,9 @@ arrfor(roots, function(root) { }) // Output based on format +var children = null +var j = 0 +var output = null if (format == 'tree') { function print_tree(locator, prefix, is_last, visited) { var node = null @@ -178,8 +181,6 @@ if (format == 'tree') { } } - var children = null - var j = 0 for (i = 0; i < length(roots); i++) { log.console(roots[i]) @@ -230,7 +231,7 @@ if (format == 'tree') { log.console("}") } else if (format == 'json') { - var output = { + output = { nodes: [], edges: [] } diff --git a/internal/engine.cm b/internal/engine.cm index c78bf00e..13d62915 100644 --- a/internal/engine.cm +++ b/internal/engine.cm @@ -70,6 +70,7 @@ function use_core(path) { var ast = null var mcode_path = null var mcode_blob = null + var _load_mod = null // Build env: merge core_extras env = {use: use_core} @@ -79,45 +80,58 @@ function use_core(path) { var cached_path = null var mach_blob = null var source_blob = null + var file_path = null // Check for pre-compiled .cm.mcode JSON IR (generated by regen) mcode_path = core_path + '/boot/' + replace(path, '/', '_') + '.cm.mcode' if (fd.is_file(mcode_path)) { - mcode_blob = fd.slurp(mcode_path) - hash = content_hash(mcode_blob) - cached_path = cache_path(hash) - if (cached_path && fd.is_file(cached_path)) { - result = mach_load(fd.slurp(cached_path), env) - } else { - mach_blob = mach_compile_mcode_bin('core:' + path, text(mcode_blob)) - if (cached_path) { - ensure_build_dir() - fd.slurpwrite(cached_path, mach_blob) + _load_mod = function() { + mcode_blob = fd.slurp(mcode_path) + hash = content_hash(mcode_blob) + cached_path = cache_path(hash) + if (cached_path && fd.is_file(cached_path)) { + result = mach_load(fd.slurp(cached_path), env) + } else { + mach_blob = mach_compile_mcode_bin('core:' + path, text(mcode_blob)) + if (cached_path) { + ensure_build_dir() + fd.slurpwrite(cached_path, mach_blob) + } + result = mach_load(mach_blob, env) } - result = mach_load(mach_blob, env) + } disruption { + print("use('" + path + "'): failed to load from " + mcode_path + "\n") + disrupt } + _load_mod() use_cache[cache_key] = result return result } // Compile from source .cm file - var file_path = core_path + '/' + path + MOD_EXT + file_path = core_path + '/' + path + MOD_EXT if (fd.is_file(file_path)) { - source_blob = fd.slurp(file_path) - hash = content_hash(source_blob) - cached_path = cache_path(hash) - if (cached_path && fd.is_file(cached_path)) { - result = mach_load(fd.slurp(cached_path), env) - } else { - script = text(source_blob) - ast = analyze(script, file_path) - mach_blob = compile_to_blob_fn('core:' + path, ast) - if (cached_path) { - ensure_build_dir() - fd.slurpwrite(cached_path, mach_blob) + _load_mod = function() { + source_blob = fd.slurp(file_path) + hash = content_hash(source_blob) + cached_path = cache_path(hash) + if (cached_path && fd.is_file(cached_path)) { + result = mach_load(fd.slurp(cached_path), env) + } else { + script = text(source_blob) + ast = analyze(script, file_path) + mach_blob = compile_to_blob_fn('core:' + path, ast) + if (cached_path) { + ensure_build_dir() + fd.slurpwrite(cached_path, mach_blob) + } + result = mach_load(mach_blob, env) } - result = mach_load(mach_blob, env) + } disruption { + print("use('" + path + "'): failed to compile or load " + file_path + "\n") + disrupt } + _load_mod() use_cache[cache_key] = result return result } @@ -238,6 +252,7 @@ var runtime_env = {} // Populate core_extras with everything shop (and other core modules) need core_extras.use_cache = use_cache +core_extras.core_path = core_path core_extras.shop_path = shop_path core_extras.analyze = analyze core_extras.run_ast_fn = run_ast_fn diff --git a/link.ce b/link.ce index 83f8ff1e..2c552a5e 100644 --- a/link.ce +++ b/link.ce @@ -77,7 +77,7 @@ if (cmd == 'list') { pkg = args[1] - var _restore = null + _restore = null if (link.remove(pkg)) { // Try to restore the original package log.console("Restoring " + pkg + "...") diff --git a/link.cm b/link.cm index d02feb2d..b3fba589 100644 --- a/link.cm +++ b/link.cm @@ -4,17 +4,19 @@ var toml = use('toml') var fd = use('fd') var blob = use('blob') -var os = use('os') +var runtime = use('runtime') -var global_shop_path = os.global_shop_path +var global_shop_path = runtime.shop_path // Get the links file path (in the global shop) function get_links_path() { + if (!global_shop_path) return null return global_shop_path + '/link.toml' } // Get the packages directory (in the global shop) function get_packages_dir() { + if (!global_shop_path) return null return global_shop_path + '/packages' } @@ -62,7 +64,7 @@ var link_cache = null Link.load = function() { if (link_cache) return link_cache var path = get_links_path() - if (!fd.is_file(path)) { + if (!path || !fd.is_file(path)) { link_cache = {} return link_cache } diff --git a/list.ce b/list.ce index f0c42445..262f873a 100644 --- a/list.ce +++ b/list.ce @@ -50,9 +50,9 @@ if (args && length(args) > 0) { var links = link.load() var lock = shop.load_lock() -function print_deps(ctx, indent) { +function print_deps(ctx, raw_indent) { var aliases = null - indent = indent || "" + var indent = raw_indent || "" deps = null var _read = function() { deps = pkg.dependencies(ctx) diff --git a/package.cm b/package.cm index 8483267d..210c7abc 100644 --- a/package.cm +++ b/package.cm @@ -2,9 +2,11 @@ var package = {} var fd = use('fd') var toml = use('toml') var json = use('json') -var os = use('os') +var runtime = use('runtime') var link = use('link') +var global_shop_path = runtime.shop_path + // Cache for loaded configs to avoid toml re-parsing corruption var config_cache = {} @@ -35,11 +37,11 @@ function get_path(name) if (starts_with(link_target, '/')) return link_target // Otherwise it's another package name, resolve that - return os.global_shop_path + '/packages/' + replace(replace(link_target, '/', '_'), '@', '_') + return global_shop_path + '/packages/' + replace(replace(link_target, '/', '_'), '@', '_') } // Remote packages use nested directories, so don't transform slashes - return os.global_shop_path + '/packages/' + replace(name, '@', '_') + return global_shop_path + '/packages/' + replace(name, '@', '_') } package.load_config = function(name) diff --git a/qopconv.ce b/qopconv.ce index 65043ec4..9a3a010d 100644 --- a/qopconv.ce +++ b/qopconv.ce @@ -86,24 +86,27 @@ function pack(sources, archive_path, read_dir) { function add_recursive(path) { var full_path = base_dir + "/" + path + var st = null + var list = null + var data = null if (path == ".") full_path = base_dir if (read_dir == null && path != ".") full_path = path - var st = fd.stat(full_path) + st = fd.stat(full_path) if (!st) { log.console("Could not stat " + full_path) return } if (st.isDirectory) { - var list = fd.readdir(full_path) + list = fd.readdir(full_path) arrfor(list, function(item) { if (item == "." || item == "..") return var sub = path == "." ? item : path + "/" + item add_recursive(sub) }) } else { - var data = fd.slurp(full_path) + data = fd.slurp(full_path) if (data) { writer.add_file(path, data) log.console("Added " + path) diff --git a/resolve.ce b/resolve.ce index 11627d12..8cee4696 100644 --- a/resolve.ce +++ b/resolve.ce @@ -140,6 +140,7 @@ var commit_str = null var line = null var cflags = null var ldflags = null +var _show_flags = null for (i = 0; i < length(sorted); i++) { locator = sorted[i].locator @@ -199,7 +200,7 @@ for (i = 0; i < length(sorted); i++) { // Show compilation inputs if requested (verbose) if (depth == 0) { - var _show_flags = function() { + _show_flags = function() { cflags = pkg.get_flags(locator, 'CFLAGS', target_triple) ldflags = pkg.get_flags(locator, 'LDFLAGS', target_triple) if (length(cflags) > 0 || length(ldflags) > 0) { diff --git a/source/scheduler.c b/source/scheduler.c index 33eab216..5b7f2f7c 100644 --- a/source/scheduler.c +++ b/source/scheduler.c @@ -310,7 +310,6 @@ void actor_free(cell_rt *actor) int actor_count = lockless_shlen(actors); if (actor_count == 0) { - fprintf(stderr, "all actors are dead\n"); pthread_mutex_lock(&engine.lock); engine.shutting_down = 1; pthread_cond_broadcast(&engine.wake_cond); diff --git a/streamline.ce b/streamline.ce index 42217d7f..5fdf3c17 100644 --- a/streamline.ce +++ b/streamline.ce @@ -16,4 +16,7 @@ var ast = parse(result.tokens, src, filename, tokenize) var folded = fold(ast) var compiled = mcode(folded) var optimized = streamline(compiled) -print(json.encode(optimized)) +print(json.encode(optimized, true, function(k,v) { + if (is_array(v)) return json.encode(v) + return v +}))