remove json as a global
This commit is contained in:
@@ -182,7 +182,7 @@ if (fn_info.locals && fn_info.locals.length > 0) {
|
||||
log.console(` stack_size: ${fn_info.stack_size}`)
|
||||
|
||||
// Display disassembly
|
||||
log.console(json.encode(js.disassemble(advance)))
|
||||
log.console(js.disassemble(advance))
|
||||
log.console(js.disassemble(advance).length)
|
||||
|
||||
$_.stop()
|
||||
@@ -1,6 +1,7 @@
|
||||
var nota = use('nota')
|
||||
var os = use('os')
|
||||
var io = use('fd')
|
||||
var json = use('json')
|
||||
|
||||
var ll = io.slurp('benchmarks/nota.json')
|
||||
|
||||
|
||||
@@ -199,6 +199,6 @@ var result = {
|
||||
decodeNsPerOp: (decodeTime / totalOps) * 1e9
|
||||
};
|
||||
|
||||
log.console(json.encode(result));
|
||||
log.console(result);
|
||||
|
||||
$_.stop()
|
||||
|
||||
@@ -101,7 +101,7 @@ $_.receiver(function(msg) {
|
||||
break;
|
||||
|
||||
case 'status':
|
||||
log.console(`got status request. current is ${json.encode(get_status())}`)
|
||||
log.console(`got status request. current is ${get_status()}`)
|
||||
send(msg, {
|
||||
type: 'status_response',
|
||||
...get_status()
|
||||
|
||||
@@ -10,11 +10,11 @@ var match_id = 0;
|
||||
$_.portal(e => {
|
||||
log.console("NAT server: received connection request");
|
||||
|
||||
if (!is_actor(e.actor))
|
||||
if (!isa(e.actor, actor))
|
||||
send(e, {reason: "Must provide the actor you want to connect."});
|
||||
|
||||
if (waiting_client) {
|
||||
log.console(`sending out messages! to ${json.encode(e.actor)} and ${json.encode(waiting_client.actor)}`)
|
||||
log.console(`sending out messages! to ${e.actor} and ${waiting_client.actor}`)
|
||||
send(waiting_client, e.actor)
|
||||
send(e, waiting_client.actor)
|
||||
|
||||
@@ -25,5 +25,5 @@ $_.portal(e => {
|
||||
|
||||
waiting_client = e
|
||||
|
||||
log.console(`actor ${json.encode(e.actor)} is waiting ...`)
|
||||
log.console(`actor ${e.actor} is waiting ...`)
|
||||
}, 4000);
|
||||
|
||||
@@ -2,10 +2,10 @@ log.console(`nat client starting`)
|
||||
|
||||
$_.contact((actor, reason) => {
|
||||
if (actor) {
|
||||
log.console(`trying to message ${json.encode(actor)}`)
|
||||
log.console(`trying to message ${actor}`)
|
||||
send(actor, {type:"greet"})
|
||||
} else {
|
||||
log.console(json.encode(reason))
|
||||
log.console(reason)
|
||||
}
|
||||
}, {
|
||||
address: "108.210.60.32", // NAT server's public IP
|
||||
|
||||
@@ -106,6 +106,10 @@ var _ObjectGetPrototypeOf = Object.getPrototypeOf
|
||||
var _ObjectCreate = meme
|
||||
var _ArrayIsArray = Array.isArray
|
||||
|
||||
Object.prototype.toString = function()
|
||||
{
|
||||
return json.encode(this)
|
||||
}
|
||||
|
||||
function deepFreeze(object) {
|
||||
if (object instanceof blob)
|
||||
@@ -123,6 +127,11 @@ function deepFreeze(object) {
|
||||
return _ObjectFreeze(object);
|
||||
}
|
||||
|
||||
globalThis.actor = function()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
globalThis.stone = deepFreeze
|
||||
stone.p = function(object)
|
||||
{
|
||||
@@ -194,11 +203,6 @@ globalThis.reverse = function(value) {
|
||||
return null
|
||||
}
|
||||
|
||||
var keyCounter = 0
|
||||
globalThis.key = function() {
|
||||
return _Symbol('key_' + (keyCounter++))
|
||||
}
|
||||
|
||||
globalThis.isa = function(value, master) {
|
||||
if (master == null) return false
|
||||
|
||||
@@ -221,6 +225,7 @@ globalThis.isa = function(value, master) {
|
||||
if (master == array) return _isArray(value)
|
||||
if (master == object) return typeof value == 'object' && value != null && !_isArray(value)
|
||||
if (master == fn) return typeof value == 'function'
|
||||
if (master == actor) return isa(value, object) && value[ACTORDATA]
|
||||
|
||||
// Check prototype chain
|
||||
if (master.prototype) {
|
||||
@@ -388,7 +393,7 @@ os.$_ = $_
|
||||
var shop = use('shop')
|
||||
|
||||
globalThis.use = shop.use
|
||||
globalThis.json = use('json')
|
||||
var json = use('json')
|
||||
var time = use('time')
|
||||
|
||||
var pronto = use('pronto')
|
||||
@@ -396,9 +401,6 @@ globalThis.fallback = pronto.fallback
|
||||
globalThis.parallel = pronto.parallel
|
||||
globalThis.race = pronto.race
|
||||
globalThis.sequence = pronto.sequence
|
||||
globalThis.time_limit = pronto.time_limit
|
||||
globalThis.requestorize = pronto.requestorize
|
||||
globalThis.objectify = pronto.objectify
|
||||
|
||||
var config = {
|
||||
ar_timer: 60,
|
||||
@@ -443,14 +445,9 @@ function guid(bits = 256)
|
||||
return text(guid,'h')
|
||||
}
|
||||
|
||||
var HEADER = key()
|
||||
var _Symbol = Symbol
|
||||
|
||||
// returns a number between 0 and 1. There is a 50% chance that the result is less than 0.5.
|
||||
$_.random = function() {
|
||||
return (os.random() / 9007199254740992)
|
||||
}
|
||||
|
||||
$_.random_fit = os.random
|
||||
var HEADER = _Symbol()
|
||||
|
||||
// takes a function input value that will eventually be called with the current time in number form.
|
||||
$_.clock = function(fn) {
|
||||
@@ -467,10 +464,6 @@ var root = null
|
||||
var receive_fn = null
|
||||
var greeters = {} // Router functions for when messages are received for a specific actor
|
||||
|
||||
globalThis.is_actor = function is_actor(actor) {
|
||||
return actor[ACTORDATA]
|
||||
}
|
||||
|
||||
function peer_connection(peer) {
|
||||
return {
|
||||
latency: peer.rtt,
|
||||
@@ -532,7 +525,7 @@ function handle_host(e) {
|
||||
var queue = peer_queue.get(e.peer)
|
||||
if (queue) {
|
||||
for (var msg of queue) e.peer.send(nota.encode(msg))
|
||||
log.system(`sent ${json.encode(msg)} out of queue`)
|
||||
log.system(`sent ${msg} out of queue`)
|
||||
peer_queue.delete(e.peer)
|
||||
}
|
||||
break
|
||||
@@ -597,7 +590,7 @@ $_.stop = function stop(actor) {
|
||||
need_stop = true
|
||||
return
|
||||
}
|
||||
if (!is_actor(actor))
|
||||
if (!isa(actor, actor))
|
||||
throw new 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.')
|
||||
@@ -653,7 +646,7 @@ 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 ${json.encode(actor)}`)
|
||||
if (!isa(actor, actor) && !isa(actor.replycc, actor)) throw new Error(`Must send to an actor object. Attempted send to ${actor}`)
|
||||
|
||||
if (typeof message != 'object') throw new Error('Must send an object record.')
|
||||
|
||||
@@ -692,7 +685,7 @@ function actor_send(actor, message) {
|
||||
}
|
||||
return
|
||||
}
|
||||
log.system(`Unable to send message to actor ${json.encode(actor[ACTORDATA])}`)
|
||||
log.system(`Unable to send message to actor ${actor[ACTORDATA]}`)
|
||||
}
|
||||
|
||||
// Holds all messages queued during the current turn.
|
||||
@@ -724,7 +717,7 @@ var replies = {}
|
||||
|
||||
globalThis.send = function send(actor, message, reply) {
|
||||
if (typeof actor != 'object')
|
||||
throw new Error(`Must send to an actor object. Provided: ${json.encode(actor)}`);
|
||||
throw new Error(`Must send to an actor object. Provided: ${actor}`);
|
||||
|
||||
if (typeof message != 'object')
|
||||
throw new Error('Message must be an object')
|
||||
@@ -732,8 +725,8 @@ globalThis.send = function send(actor, message, reply) {
|
||||
|
||||
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! ${json.encode(actor[HEADER])}`)
|
||||
if (!header.replycc || !isa(header.replycc, actor))
|
||||
throw new Error(`Supplied actor had a return, but it's not a valid actor! ${actor[HEADER]}`)
|
||||
|
||||
actor = header.replycc
|
||||
send.return = header.reply
|
||||
@@ -978,11 +971,7 @@ delete globalThis.unescape
|
||||
delete globalThis.Intl
|
||||
delete globalThis.RegExp
|
||||
|
||||
// TODO: delete globalThis
|
||||
|
||||
var mem = js.calc_mem()
|
||||
log.console(json.encode(mem))
|
||||
log.console("total memory usage: " + text(mem.memory_used_size/1024) + " KB");
|
||||
_ObjectFreeze(globalThis)
|
||||
|
||||
$_.clock(_ => {
|
||||
var val = locator.symbol.call(null, $_, cell.args.arg);
|
||||
|
||||
3
shop.cm
3
shop.cm
@@ -647,8 +647,9 @@ function execute_module(info)
|
||||
} else {
|
||||
throw new Error(`Module ${info.path} could not be found`)
|
||||
} if (!used)
|
||||
throw new Error(`Module ${json.encode(info)} returned null`)
|
||||
throw new Error(`Module ${info} returned null`)
|
||||
|
||||
stone(used)
|
||||
return used
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ return {
|
||||
test_contact: function() {
|
||||
function contact_fn(actor,reason) {
|
||||
if (actor) {
|
||||
log.console(`Got an actor: ${json.encode(actor)}`)
|
||||
log.console(`Got an actor: ${actor}`)
|
||||
|
||||
send(actor, {greet: "Hello!"}, e => {
|
||||
log.console(`Got the response ${json.encode(e)}. Goodbye!`);
|
||||
log.console(`Got the response ${e}. Goodbye!`);
|
||||
})
|
||||
}
|
||||
else
|
||||
log.console(`Did not get an actor: ${json.encode(reason)}`)
|
||||
log.console(`Did not get an actor: ${reason}`)
|
||||
}
|
||||
|
||||
$_.contact(contact_fn,
|
||||
|
||||
@@ -9,7 +9,7 @@ return {
|
||||
|
||||
$_.start(e => {
|
||||
send(e.actor, { op: 'get', domain: host, port: 80}, addrs => {
|
||||
log.console(json.encode(addrs[0]))
|
||||
log.console(addrs[0])
|
||||
})
|
||||
}, 'dig')
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ return {
|
||||
if (reason)
|
||||
log.console(reason)
|
||||
else
|
||||
log.console(json.encode(result))
|
||||
log.console(result)
|
||||
|
||||
log.console(`took ${time.number()-st} secs`)
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ $_.portal(e => {
|
||||
}, 5678);
|
||||
|
||||
$_.receiver(e => {
|
||||
log.console(`Got message: ${json.encode(e)}`)
|
||||
log.console(`Got message: ${e}`)
|
||||
send(e, {greet: "Hello back!"})
|
||||
$_.delay(_ => $_.stop(), 0.2)
|
||||
})
|
||||
|
||||
@@ -128,7 +128,7 @@ return {
|
||||
|
||||
req(function(result, reason) {
|
||||
if (result != null) {
|
||||
log.console(`Objectify result: ${json.encode(result)}`)
|
||||
log.console(`Objectify result: ${result}`)
|
||||
} else {
|
||||
log.console(`Objectify failed: ${reason}`)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$_.receiver(e => {
|
||||
log.console(`Got a message: ${json.encode(e)}`)
|
||||
log.console(`Got a message: ${e}`)
|
||||
|
||||
send(e, {
|
||||
message: "Good to go."
|
||||
|
||||
@@ -2,7 +2,7 @@ return {
|
||||
test_send: function() {
|
||||
$_.start(e => {
|
||||
send(e.actor, { message: "Hello! Good to go?" }, msg => {
|
||||
log.console(`Original sender got message back: ${json.encode(msg)}. Stopping!`)
|
||||
log.console(`Original sender got message back: ${msg}. Stopping!`)
|
||||
// $_.stop() // Removed
|
||||
})
|
||||
}, "tests/reply_actor")
|
||||
|
||||
@@ -23,8 +23,8 @@ function test_roundtrip(obj, name) {
|
||||
var encoded = toml.encode(obj)
|
||||
var decoded = toml.decode(encoded)
|
||||
if (!deep_equal(obj, decoded)) {
|
||||
log.console(name + " - Original:", json.encode(obj))
|
||||
log.console(name + " - Round-trip:", json.encode(decoded))
|
||||
log.console(name + " - Original:", obj)
|
||||
log.console(name + " - Round-trip:", decoded)
|
||||
throw name + " round-trip failed"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user