This commit is contained in:
2026-01-13 22:16:28 -06:00
parent ac4b47f075
commit 66a9ca27e2
21 changed files with 122 additions and 578 deletions

View File

@@ -43,14 +43,14 @@ var fd = use_embed('fd')
// Get the shop path from HOME environment
var home = os.getenv('HOME') || os.getenv('USERPROFILE')
if (!home) {
throw new Error('Could not determine home directory')
throw Error('Could not determine home directory')
}
var shop_path = home + '/.cell'
var packages_path = shop_path + '/packages'
var core_path = packages_path + '/core'
if (!fd.is_dir(core_path)) {
throw new Error('Cell shop not found at ' + shop_path + '. Run "cell install" to set up.')
throw Error('Cell shop not found at ' + shop_path + '. Run "cell install" to set up.')
}
var use_cache = {}
@@ -104,7 +104,7 @@ function caller_data(depth = 0)
var file = "nofile"
var line = 0
var caller = new Error().stack.split("\n")[1+depth]
var caller = Error().stack.split("\n")[1+depth]
if (caller) {
var md = caller.match(/\((.*)\:/)
var m = md ? md[1] : "SCRIPT"
@@ -131,7 +131,7 @@ globalThis.log = function(name, args) {
os.print(console_rec(caller.line, caller.file, msg))
break
case 'error':
msg = msg ?? new Error()
msg = msg ?? Error()
if (is_proto(msg, Error))
msg = msg.name + ": " + msg.message + "\n" + msg.stack
os.print(console_rec(caller.line, caller.file, msg))
@@ -206,9 +206,9 @@ globalThis.sequence = pronto.sequence
$_.time_limit = function(requestor, seconds)
{
if (!pronto.is_requestor(requestor))
throw new Error('time_limit: first argument must be a requestor');
throw Error('time_limit: first argument must be a requestor');
if (!is_number(seconds) || seconds <= 0)
throw new Error('time_limit: seconds must be a positive number');
throw Error('time_limit: seconds must be a positive number');
return function time_limit_requestor(callback, value) {
pronto.check_callback(callback, 'time_limit')
@@ -304,7 +304,7 @@ REPLYTIMEOUT = config.reply_timeout
function guid(bits = 256)
{
var guid = new blob(bits, os.random)
var guid = blob(bits, os.random)
stone(guid)
return text(guid,'h')
}
@@ -372,8 +372,8 @@ var portal_fn = null
// takes a function input value that will eventually be called with the current time in number form.
$_.portal = function(fn, port) {
if (portal) throw new Error(`Already started a portal listening on ${portal.port}`)
if (!port) throw new Error("Requires a valid port.")
if (portal) throw Error(`Already started a portal listening on ${portal.port}`)
if (!port) throw Error("Requires a valid port.")
log.system(`starting a portal on port ${port}`)
portal = enet.create_host({address: "any", port})
portal_fn = fn
@@ -453,9 +453,9 @@ $_.stop = function stop(actor) {
return
}
if (!is_actor(actor))
throw new Error('Can only call stop on an actor.')
throw Error('Can only call stop on an actor.')
if (!underlings.has(actor[ACTORDATA].id))
throw new Error('Can only call stop on an underling or self.')
throw Error('Can only call stop on an underling or self.')
sys_msg(actor, {kind:"stop"})
}
@@ -508,9 +508,9 @@ function actor_send(actor, message) {
if (actor[HEADER] && !actor[HEADER].replycc) // attempting to respond to a message but sender is not expecting; silently drop
return
if (!is_actor(actor) && !is_actor(actor.replycc)) throw new Error(`Must send to an actor object. Attempted send to ${actor}`)
if (!is_actor(actor) && !is_actor(actor.replycc)) throw Error(`Must send to an actor object. Attempted send to ${actor}`)
if (!is_object(message)) throw new Error('Must send an object record.')
if (!is_object(message)) throw Error('Must send an object record.')
// message to self
if (actor[ACTORDATA].id == _cell.id) {
@@ -579,16 +579,16 @@ var replies = {}
globalThis.send = function send(actor, message, reply) {
if (!is_object(actor))
throw new Error(`Must send to an actor object. Provided: ${actor}`);
throw Error(`Must send to an actor object. Provided: ${actor}`);
if (!is_object(message))
throw new Error('Message must be an object')
throw Error('Message must be an object')
var send = {type:"user", data: message}
if (actor[HEADER] && actor[HEADER].replycc) {
var header = actor[HEADER]
if (!header.replycc || !is_actor(header.replycc))
throw new Error(`Supplied actor had a return, but it's not a valid actor! ${actor[HEADER]}`)
throw Error(`Supplied actor had a return, but it's not a valid actor! ${actor[HEADER]}`)
actor = header.replycc
send.return = header.reply
@@ -699,7 +699,7 @@ function handle_sysym(msg)
letter2[HEADER] = msg
delete msg.data
portal_fn(letter2)
} else throw new Error('Got a contact message, but no portal is established.')
} else throw Error('Got a contact message, but no portal is established.')
break
case 'couple': // from must be notified when we die
from = msg.from
@@ -764,7 +764,7 @@ if (!locator) {
}
if (!locator)
throw new Error(`Main program ${_cell.args.program} could not be found`)
throw Error(`Main program ${_cell.args.program} could not be found`)
stone(globalThis)
@@ -791,7 +791,7 @@ $_.clock(_ => {
var val = call(locator.symbol, null, _cell.args.arg, use_fn, ...vals)
if (val)
throw new Error('Program must not return anything');
throw Error('Program must not return anything');
})
})()