This commit is contained in:
2026-01-19 01:06:45 -06:00
parent 5271688dd4
commit cbf99295da
16 changed files with 69 additions and 121 deletions

12
add.ce
View File

@@ -14,8 +14,8 @@ var fd = use('fd')
var locator = null var locator = null
var alias = null var alias = null
for (var i = 0; i < length(args); i++) { array(args, function(arg) {
if (args[i] == '--help' || args[i] == '-h') { if (arg == '--help' || arg == '-h') {
log.console("Usage: cell add <locator> [alias]") log.console("Usage: cell add <locator> [alias]")
log.console("") log.console("")
log.console("Add a dependency to the current package.") log.console("Add a dependency to the current package.")
@@ -25,14 +25,14 @@ for (var i = 0; i < length(args); i++) {
log.console(" cell add gitea.pockle.world/john/cell-image image") log.console(" cell add gitea.pockle.world/john/cell-image image")
log.console(" cell add ../local-package") log.console(" cell add ../local-package")
$stop() $stop()
} else if (!starts_with(args[i], '-')) { } else if (!starts_with(arg, '-')) {
if (!locator) { if (!locator) {
locator = args[i] locator = arg
} else if (!alias) { } else if (!alias) {
alias = args[i] alias = arg
} }
} }
} })
if (!locator) { if (!locator) {
log.console("Usage: cell add <locator> [alias]") log.console("Usage: cell add <locator> [alias]")

View File

@@ -43,10 +43,11 @@ for (var i = 0; i < 100; i++) {
// Calculate statistics // Calculate statistics
function getStats(arr) { function getStats(arr) {
def avg = reduce(arr, (a,b) => a+b, 0) / length(arr) return {
def min = min(...arr); avg: reduce(arr, (a,b) => a+b, 0) / length(arr),
def max = max(...arr); min: reduce(arr, min),
return { avg, min, max }; max: reduce(arr, max)
};
} }
// Pretty print results // Pretty print results

View File

@@ -79,18 +79,13 @@ log.console("Wota Encode/Decode Benchmark");
log.console("===================\n"); log.console("===================\n");
// We'll run each benchmark scenario in turn. // We'll run each benchmark scenario in turn.
for (var bench of benchmarks) { arrfor(benchmarks, function(bench) {
// We'll measure how long it takes to do 'iterations' *for each test value* var totalIterations = bench.iterations * length(bench.data);
// in bench.data. The total loop count is `bench.iterations * bench.data)`.
// Then we compute an overall encode+decode throughput (ops/s).
var totalIterations = bench.iterations * bench.data);
// We'll define a function that does a roundTrip for *each* data item in bench.data // We'll define a function that does a roundTrip for *each* data item in bench.data
// to measure in one loop iteration. Then we multiply by bench.iterations. // to measure in one loop iteration. Then we multiply by bench.iterations.
function runAllData() { function runAllData() {
for (var val of bench.data) { arrfor(bench.data, roundTripWota)
roundTripWota(val);
}
} }
var elapsedSec = measureTime(runAllData, bench.iterations); var elapsedSec = measureTime(runAllData, bench.iterations);
@@ -100,7 +95,7 @@ for (var bench of benchmarks) {
log.console(` Iterations: ${bench.iterations} × ${length(bench.data)} data items = ${totalIterations}`); log.console(` Iterations: ${bench.iterations} × ${length(bench.data)} data items = ${totalIterations}`);
log.console(` Elapsed: ${elapsedSec.toFixed(3)} s`); log.console(` Elapsed: ${elapsedSec.toFixed(3)} s`);
log.console(` Throughput: ${opsPerSec} encode+decode ops/sec\n`); log.console(` Throughput: ${opsPerSec} encode+decode ops/sec\n`);
} })
// All done // All done
log.console("Benchmark completed.\n"); log.console("Benchmark completed.\n");

View File

@@ -149,11 +149,7 @@ function runBenchmarkForLibrary(lib, bench) {
// 2) Measure DECODING // 2) Measure DECODING
var decodeTime = measureTime(() => { var decodeTime = measureTime(() => {
for (var i = 0; i < bench.iterations; i++) { for (var i = 0; i < bench.iterations; i++) {
// decode everything we stored during the first iteration arrfor(encodedList, lib.decode)
for (var e of encodedList) {
var decoded = lib.decode(e);
// not verifying correctness here, just measuring speed
}
} }
}); });

View File

@@ -88,9 +88,7 @@ function ensure_dir(path) {
for (var i = 0; i < length(parts); i++) { for (var i = 0; i < length(parts); i++) {
if (parts[i] == '') continue if (parts[i] == '') continue
current += parts[i] + '/' current += parts[i] + '/'
if (!fd.stat(current).isDirectory) { if (!fd.stat(current).isDirectory) fd.mkdir(current)
fd.mkdir(current)
}
} }
} }

View File

@@ -177,10 +177,10 @@ function disrupt(err)
if (underlings) { if (underlings) {
var unders = array(underlings) var unders = array(underlings)
for (var id of unders) { arrfor(unders, function(id) {
log.console(`calling on ${id} to disrupt too`) log.console(`calling on ${id} to disrupt too`)
$_.stop(create_actor({id})) $_.stop(create_actor({id}))
} })
} }
if (err) { if (err) {
@@ -449,16 +449,14 @@ $_.receiver = function receiver(fn) {
receive_fn = fn receive_fn = fn
} }
$_.start = function start(cb, program, ...args) { $_.start = function start(cb, program) {
if (!program) return if (!program) return
var id = guid() var id = guid()
if (length(args) == 1 && is_array(args[0])) args = args[0]
var startup = { var startup = {
id, id,
overling: $_.self, overling: $_.self,
root, root,
arg: args,
program, program,
} }
greeters[id] = cb greeters[id] = cb
@@ -582,14 +580,14 @@ var need_stop = false
return return
} }
for (var msg of message_queue) { arrfor(message_queue, function(msg) {
if (msg.startup) { if (msg.startup) {
// now is the time to actually spin up the actor // now is the time to actually spin up the actor
actor_mod.createactor(msg.startup) actor_mod.createactor(msg.startup)
} else { } else {
actor_send(msg.actor, msg.send) actor_send(msg.actor, msg.send)
} }
} })
message_queue = [] message_queue = []
} }
@@ -803,7 +801,7 @@ $_.clock(_ => {
var pkg = file_info ? file_info.package : null var pkg = file_info ? file_info.package : null
var use_fn = function(path) { return shop.use(path, pkg) } var use_fn = function(path) { return shop.use(path, pkg) }
// Call with signature: setup_module(args, use, ...capabilities) // Call with signature: setup_module(args, use, ..capabilities)
// The script wrapper builds $_ from the injected capabilities for backward compatibility // The script wrapper builds $_ from the injected capabilities for backward compatibility
var val = call(locator.symbol, null, _cell.args.arg, use_fn, ...vals) var val = call(locator.symbol, null, _cell.args.arg, use_fn, ...vals)

View File

@@ -360,11 +360,6 @@ var open_dls = {}
// These map to $_ properties in engine.cm // These map to $_ properties in engine.cm
var SHOP_DEFAULT_INJECT = ['$self', '$overling', '$clock', '$delay', '$start', '$receiver', '$contact', '$portal', '$time_limit', '$couple', '$stop', '$unneeded', '$connection', '$fd'] var SHOP_DEFAULT_INJECT = ['$self', '$overling', '$clock', '$delay', '$start', '$receiver', '$contact', '$portal', '$time_limit', '$couple', '$stop', '$unneeded', '$connection', '$fd']
function strip_dollar(name) {
if (name && name[0] == '$') return text(name, 1)
return name
}
// Decide what a given module is allowed to see. // Decide what a given module is allowed to see.
// This is the capability gate - tweak as needed. // This is the capability gate - tweak as needed.
Shop.script_inject_for = function(file_info) { Shop.script_inject_for = function(file_info) {
@@ -387,13 +382,11 @@ function inject_params(inject) {
} }
function inject_values(inject) { function inject_values(inject) {
var vals = [] return array(inject, function(inj) {
for (var i = 0; i < length(inject); i++) { var key = trim(inj, '$')
var key = strip_dollar(inject[i]) if (key == 'fd') return fd
if (key == 'fd') vals.push(fd) return my$_[key]
else vals.push(my$_[key]) })
}
return vals
} }
// Build the use function for a specific package context // Build the use function for a specific package context
@@ -802,7 +795,7 @@ function execute_module(info)
var pkg = file_info.package var pkg = file_info.package
var use_fn = make_use_fn(pkg) var use_fn = make_use_fn(pkg)
// Call with signature: setup_module(args, use, ...capabilities) // Call with signature: setup_module(args, use, ..capabilities)
// args is null for module loading // args is null for module loading
used = call(mod_resolve.symbol, context, null, use_fn, ...vals) used = call(mod_resolve.symbol, context, null, use_fn, ...vals)
} else if (c_resolve.scope < 900) { } else if (c_resolve.scope < 900) {
@@ -1217,8 +1210,9 @@ Shop.build_package_scripts = function(package)
var scripts = get_package_scripts(package) var scripts = get_package_scripts(package)
var pkg_dir = get_package_abs_dir(package) var pkg_dir = get_package_abs_dir(package)
for (var script of scripts) arrfor(scripts, function(script) {
resolve_mod_fn(pkg_dir + '/' + script, package) resolve_mod_fn(pkg_dir + '/' + script, package)
})
} }
Shop.list_packages = function() Shop.list_packages = function()
@@ -1274,12 +1268,12 @@ Shop.audit_packages = function() {
var bad = [] var bad = []
for (var package of packages) { arrfor(packages, function(package) {
if (package == 'core') continue if (package == 'core') return
if (fd.is_dir(package)) continue if (fd.is_dir(package)) return
if (fetch_remote_hash(package)) continue if (fetch_remote_hash(package)) return
bad.push(package) bad.push(package)
} })
return bad return bad
} }

View File

@@ -319,45 +319,12 @@ function requestorize(unary) {
} }
} }
// objectify(factory_fn)
// Converts a factory that takes arrays to one that takes objects.
function objectify(factory_fn) {
def factory = 'objectify'
if (!is_function(factory_fn))
throw make_reason(factory, 'Not a factory.', factory_fn)
return function objectified_factory(object_of_requestors, ...rest) {
if (!is_object(object_of_requestors))
throw make_reason(factory, 'Expected an object.', object_of_requestors)
def keys = array(object_of_requestors)
def requestor_array = array(keys, k => object_of_requestors[k])
def inner_requestor = factory_fn(requestor_array, ...rest)
return function(callback, value) {
return inner_requestor(function(results, reason) {
if (results == null) {
callback(null, reason)
} else if (is_array(results)) {
def obj = {}
arrfor(keys, (k, i) => { obj[k] = results[i] })
callback(obj, reason)
} else {
callback(results, reason)
}
}, value)
}
}
}
return { return {
fallback, fallback,
parallel, parallel,
race, race,
sequence, sequence,
requestorize, requestorize,
objectify,
is_requestor, is_requestor,
check_callback check_callback
} }

View File

@@ -3,10 +3,10 @@ var qop = use('qop')
function print_usage() { function print_usage() {
log.console("Usage: qopconv [OPTION...] FILE...") log.console("Usage: qopconv [OPTION...] FILE...")
log.console(" -u <archive> ... unpack archive") log.console(" -u <archive> .. unpack archive")
log.console(" -l <archive> ... list contents of archive") log.console(" -l <archive> .. list contents of archive")
log.console(" -d <dir> ....... change read dir when creating archives") log.console(" -d <dir> ....... change read dir when creating archives")
log.console(" <sources...> <archive> ... create archive from sources") log.console(" <sources...> <archive> .. create archive from sources")
} }
function list(archive_path) { function list(archive_path) {

View File

@@ -149,9 +149,8 @@ function ensure_dir(path) {
for (var i = 0; i < length(parts); i++) { for (var i = 0; i < length(parts); i++) {
if (parts[i] == '') continue if (parts[i] == '') continue
current += parts[i] + '/' current += parts[i] + '/'
if (!fd.is_dir(current)) { if (!fd.is_dir(current))
fd.mkdir(current) fd.mkdir(current)
}
} }
return true return true
} }

View File

@@ -30,7 +30,10 @@ return {
send(tree, reason) send(tree, reason)
} }
send(tree, { ...result.comment, children: result.children, time: time.text() }) var obj = object(result.comment)
obj.children = result.children
obj.time = time.text()
send(tree, obj)
}) })
}) })
} }

View File

@@ -25,6 +25,9 @@ $receiver(tree => {
send(tree, reason) send(tree, reason)
} }
send(tree, { ...result.comment, children: result.children, time: time.text() }) var obj = object(result.comment)
obj.children = result.children
obj.time = time.text()
send(tree, obj)
}) })
}) })

View File

@@ -1,6 +1,6 @@
return { return {
test_hang: function() { test_hang: function() {
log.console(`Going to start hanging ... (disabled)`) log.console(`Going to start hanging .. (disabled)`)
// while(1) { // while(1) {
// // hang! // // hang!

View File

@@ -41,7 +41,7 @@ function deepCompare(expected, actual, path) {
stone_if_needed(expected); stone_if_needed(actual) stone_if_needed(expected); stone_if_needed(actual)
if (expected.length != actual.length) if (expected.length != actual.length)
return { passed: false, messages: [`blob length mismatch at ${path}: ${length(expected)} vs ${length(actual)}`] } return { passed: false, messages: [`blob length mismatch at ${path}: ${length(expected)} vs ${length(actual)}`] }
for (var i = 0; i < expected.length; i++) { for (var i = 0; i < length(expected); i++) {
if (expected.read_logical(i) != actual.read_logical(i)) if (expected.read_logical(i) != actual.read_logical(i))
return { passed: false, messages: [`blob bit mismatch at ${path}[${i}]`] } return { passed: false, messages: [`blob bit mismatch at ${path}[${i}]`] }
} }
@@ -55,12 +55,11 @@ function deepCompare(expected, actual, path) {
messages: [`Array length mismatch at ${path}: expected ${length(expected)}, got ${length(actual)}`] messages: [`Array length mismatch at ${path}: expected ${length(expected)}, got ${length(actual)}`]
}; };
var messages = []; var messages = [];
for (var i = 0; i < expected.length; i++) { arrfor(expected, function(val, i) {
var result = deepCompare(expected[i], actual[i], `${path}[${i}]`); var result = deepCompare(val, actual[i], `${path}[${i}]`);
if (!result.passed) { if (!result.passed)
for(var m of result.messages) messages.push(m); messages = array(messages, result.messages)
} })
}
return { passed: messages.length == 0, messages: messages }; return { passed: messages.length == 0, messages: messages };
} }
@@ -73,12 +72,11 @@ function deepCompare(expected, actual, path) {
messages: [`Object keys mismatch at ${path}: expected ${expKeys}, got ${actKeys}`] messages: [`Object keys mismatch at ${path}: expected ${expKeys}, got ${actKeys}`]
}; };
var messages = []; var messages = [];
for (var key of expKeys) { arrfor(expKeys, function(key) {
var result = deepCompare(expected[key], actual[key], `${path}.${key}`); var result = deepCompare(expected[key], actual[key], `${path}.${key}`);
if (!result.passed) { if (!result.passed)
for(var m of result.messages) messages.push(m); messages = array(messages, result.messages)
} })
}
return { passed: messages.length == 0, messages: messages }; return { passed: messages.length == 0, messages: messages };
} }

View File

@@ -22,11 +22,11 @@ function deep_compare(expected, actual, path) {
if (is_blob(expected) && is_blob(actual)) { if (is_blob(expected) && is_blob(actual)) {
stone_if_needed(expected); stone_if_needed(actual) stone_if_needed(expected); stone_if_needed(actual)
if (length(expected) != length(actual)) if (length(expected) != length(actual))
return { passed: false, messages: [`blob length mismatch at ${path}: ${length(expected)} vs ${actual)}`] } return { passed: false, messages: [`blob length mismatch at ${path}: ${length(expected)} vs ${length(actual)}`] }
for (var i = 0; i < length(expected); i++) { arrfor(array(expected), function(i) {
if (expected.read_logical(i) != actual.read_logical(i)) if (expected.read_logical(i) != actual.read_logical(i))
return { passed: false, messages: [`blob bit mismatch at ${path}[${i}]`] } return { passed: false, messages: [`blob bit mismatch at ${path}[${i}]`] }
} })
return { passed: true, messages: [] } return { passed: true, messages: [] }
} }
@@ -34,12 +34,10 @@ function deep_compare(expected, actual, path) {
if (length(expected) != length(actual)) if (length(expected) != length(actual))
return { passed: false, messages: [`Array length mismatch at ${path}: ${length(expected)} vs ${length(actual)}`] } return { passed: false, messages: [`Array length mismatch at ${path}: ${length(expected)} vs ${length(actual)}`] }
var msgs = [] var msgs = []
for (var i = 0; i < length(expected); i++) { arrfor(array(expected), function(i) {
var res = deep_compare(expected[i], actual[i], `${path}[${i}]`) var res = deep_compare(expected[i], actual[i], `${path}[${i}]`)
if (!res.passed) { if (!res.passed) array(msgs, res.messages)
for(var m of res.messages) msgs.push(m) })
}
}
return { passed: length(msgs) == 0, messages: msgs } return { passed: length(msgs) == 0, messages: msgs }
} }
@@ -49,12 +47,10 @@ function deep_compare(expected, actual, path) {
if (JSON.stringify(expKeys) != JSON.stringify(actKeys)) if (JSON.stringify(expKeys) != JSON.stringify(actKeys))
return { passed: false, messages: [`Object keys mismatch at ${path}: ${expKeys} vs ${actKeys}`] } return { passed: false, messages: [`Object keys mismatch at ${path}: ${expKeys} vs ${actKeys}`] }
var msgs = [] var msgs = []
for (var k of expKeys) { arrfor(expKeys, function(k) {
var res = deep_compare(expected[k], actual[k], `${path}.${k}`) var res = deep_compare(expected[k], actual[k], `${path}.${k}`)
if (!res.passed) { if (!res.passed) array(msgs, res.messages)
for(var m of res.messages) msgs.push(m) })
}
}
return { passed: length(msgs) == 0, messages: msgs } return { passed: length(msgs) == 0, messages: msgs }
} }

View File

@@ -226,7 +226,7 @@ function encode_toml(obj) {
// Direct properties // Direct properties
var section_keys = array(value) var section_keys = array(value)
for (var j = 0; j < section_length(keys); j++) { for (var j = 0; j < length(section_keys); j++) {
var sk = section_keys[j] var sk = section_keys[j]
var sv = value[sk] var sv = value[sk]
if (!is_object(sv)) result.push(quote_key(sk) + ' = ' + encode_value(sv)) if (!is_object(sv)) result.push(quote_key(sk) + ' = ' + encode_value(sv))