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 alias = null
for (var i = 0; i < length(args); i++) {
if (args[i] == '--help' || args[i] == '-h') {
array(args, function(arg) {
if (arg == '--help' || arg == '-h') {
log.console("Usage: cell add <locator> [alias]")
log.console("")
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 ../local-package")
$stop()
} else if (!starts_with(args[i], '-')) {
} else if (!starts_with(arg, '-')) {
if (!locator) {
locator = args[i]
locator = arg
} else if (!alias) {
alias = args[i]
alias = arg
}
}
}
})
if (!locator) {
log.console("Usage: cell add <locator> [alias]")

View File

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

View File

@@ -79,18 +79,13 @@ log.console("Wota Encode/Decode Benchmark");
log.console("===================\n");
// We'll run each benchmark scenario in turn.
for (var bench of benchmarks) {
// We'll measure how long it takes to do 'iterations' *for each test value*
// 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);
arrfor(benchmarks, function(bench) {
var totalIterations = bench.iterations * length(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.
function runAllData() {
for (var val of bench.data) {
roundTripWota(val);
}
arrfor(bench.data, roundTripWota)
}
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(` Elapsed: ${elapsedSec.toFixed(3)} s`);
log.console(` Throughput: ${opsPerSec} encode+decode ops/sec\n`);
}
})
// All done
log.console("Benchmark completed.\n");

View File

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

View File

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

View File

@@ -177,10 +177,10 @@ function disrupt(err)
if (underlings) {
var unders = array(underlings)
for (var id of unders) {
arrfor(unders, function(id) {
log.console(`calling on ${id} to disrupt too`)
$_.stop(create_actor({id}))
}
})
}
if (err) {
@@ -449,16 +449,14 @@ $_.receiver = function receiver(fn) {
receive_fn = fn
}
$_.start = function start(cb, program, ...args) {
$_.start = function start(cb, program) {
if (!program) return
var id = guid()
if (length(args) == 1 && is_array(args[0])) args = args[0]
var startup = {
id,
overling: $_.self,
root,
arg: args,
program,
}
greeters[id] = cb
@@ -582,14 +580,14 @@ var need_stop = false
return
}
for (var msg of message_queue) {
arrfor(message_queue, function(msg) {
if (msg.startup) {
// now is the time to actually spin up the actor
actor_mod.createactor(msg.startup)
} else {
actor_send(msg.actor, msg.send)
}
}
})
message_queue = []
}
@@ -803,7 +801,7 @@ $_.clock(_ => {
var pkg = file_info ? file_info.package : null
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
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
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.
// This is the capability gate - tweak as needed.
Shop.script_inject_for = function(file_info) {
@@ -387,13 +382,11 @@ function inject_params(inject) {
}
function inject_values(inject) {
var vals = []
for (var i = 0; i < length(inject); i++) {
var key = strip_dollar(inject[i])
if (key == 'fd') vals.push(fd)
else vals.push(my$_[key])
}
return vals
return array(inject, function(inj) {
var key = trim(inj, '$')
if (key == 'fd') return fd
return my$_[key]
})
}
// Build the use function for a specific package context
@@ -802,7 +795,7 @@ function execute_module(info)
var pkg = file_info.package
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
used = call(mod_resolve.symbol, context, null, use_fn, ...vals)
} else if (c_resolve.scope < 900) {
@@ -1217,8 +1210,9 @@ Shop.build_package_scripts = function(package)
var scripts = get_package_scripts(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)
})
}
Shop.list_packages = function()
@@ -1274,12 +1268,12 @@ Shop.audit_packages = function() {
var bad = []
for (var package of packages) {
if (package == 'core') continue
if (fd.is_dir(package)) continue
if (fetch_remote_hash(package)) continue
arrfor(packages, function(package) {
if (package == 'core') return
if (fd.is_dir(package)) return
if (fetch_remote_hash(package)) return
bad.push(package)
}
})
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 {
fallback,
parallel,
race,
sequence,
requestorize,
objectify,
is_requestor,
check_callback
}

View File

@@ -3,10 +3,10 @@ var qop = use('qop')
function print_usage() {
log.console("Usage: qopconv [OPTION...] FILE...")
log.console(" -u <archive> ... unpack archive")
log.console(" -l <archive> ... list contents of archive")
log.console(" -u <archive> .. unpack archive")
log.console(" -l <archive> .. list contents of archive")
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) {

View File

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

View File

@@ -30,7 +30,10 @@ return {
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, { ...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 {
test_hang: function() {
log.console(`Going to start hanging ... (disabled)`)
log.console(`Going to start hanging .. (disabled)`)
// while(1) {
// // hang!

View File

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

View File

@@ -226,7 +226,7 @@ function encode_toml(obj) {
// Direct properties
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 sv = value[sk]
if (!is_object(sv)) result.push(quote_key(sk) + ' = ' + encode_value(sv))