Support debug names for actors (any JSON term)
This commit is contained in:
parent
6160012576
commit
fba4aaa6b4
|
@ -42,9 +42,15 @@ var forEachChild = (function () {
|
||||||
return forEachChild;
|
return forEachChild;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
function buildActor(constructorES5, block) {
|
function buildActor(constructorES5, nameExpOpt, block) {
|
||||||
|
var nameExpStr;
|
||||||
|
if (nameExpOpt.numChildren === 1) {
|
||||||
|
nameExpStr = ', ' + nameExpOpt.asES5;
|
||||||
|
} else {
|
||||||
|
nameExpStr = '';
|
||||||
|
}
|
||||||
return 'Syndicate.Actor.spawnActor(new '+constructorES5+', '+
|
return 'Syndicate.Actor.spawnActor(new '+constructorES5+', '+
|
||||||
'function() ' + block.asES5 + ');';
|
'function() ' + block.asES5 + nameExpStr + ');';
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildFacet(facetBlock, transitionBlock) {
|
function buildFacet(facetBlock, transitionBlock) {
|
||||||
|
@ -79,11 +85,11 @@ function buildCaseEvent(eventPattern, body) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var modifiedSourceActions = {
|
var modifiedSourceActions = {
|
||||||
ActorStatement_noConstructor: function(_actor, block) {
|
ActorStatement_noConstructor: function(_actor, _namedOpt, nameExpOpt, block) {
|
||||||
return buildActor('Object()', block);
|
return buildActor('Object()', nameExpOpt, block);
|
||||||
},
|
},
|
||||||
ActorStatement_withConstructor: function(_actor, ctorExp, block) {
|
ActorStatement_withConstructor: function(_actor, ctorExp, _namedOpt, nameExpOpt, block) {
|
||||||
return buildActor(ctorExp.asES5, block);
|
return buildActor(ctorExp.asES5, nameExpOpt, block);
|
||||||
},
|
},
|
||||||
|
|
||||||
DataspaceStatement_ground: function(_ground, _dataspace, maybeId, block) {
|
DataspaceStatement_ground: function(_ground, _dataspace, maybeId, block) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ assertion type ready(what);
|
||||||
assertion type entry(key, val);
|
assertion type entry(key, val);
|
||||||
|
|
||||||
ground dataspace {
|
ground dataspace {
|
||||||
actor {
|
actor named 'listener' {
|
||||||
react {
|
react {
|
||||||
assert ready("listener");
|
assert ready("listener");
|
||||||
on asserted entry($key, _) {
|
on asserted entry($key, _) {
|
||||||
|
@ -31,7 +31,7 @@ ground dataspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actor {
|
actor named 'other-listener' {
|
||||||
react {
|
react {
|
||||||
assert ready('other-listener');
|
assert ready('other-listener');
|
||||||
during entry($key, _) {
|
during entry($key, _) {
|
||||||
|
@ -56,7 +56,7 @@ ground dataspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actor {
|
actor named 'driver' {
|
||||||
react until {
|
react until {
|
||||||
case asserted ready("listener") {
|
case asserted ready("listener") {
|
||||||
react until {
|
react until {
|
||||||
|
|
|
@ -16,8 +16,8 @@ Syndicate <: ES5 {
|
||||||
FunctionBodyBlock = "{" FunctionBody "}" // odd that this isn't in es5.ohm somewhere
|
FunctionBodyBlock = "{" FunctionBody "}" // odd that this isn't in es5.ohm somewhere
|
||||||
|
|
||||||
ActorStatement
|
ActorStatement
|
||||||
= actor CallExpression FunctionBodyBlock -- withConstructor
|
= actor CallExpression (named Expression<withIn>)? FunctionBodyBlock -- withConstructor
|
||||||
| actor FunctionBodyBlock -- noConstructor
|
| actor (named Expression<withIn>)? FunctionBodyBlock -- noConstructor
|
||||||
|
|
||||||
DataspaceStatement
|
DataspaceStatement
|
||||||
= ground dataspace identifier? FunctionBodyBlock -- ground
|
= ground dataspace identifier? FunctionBodyBlock -- ground
|
||||||
|
@ -82,6 +82,7 @@ Syndicate <: ES5 {
|
||||||
ground = "ground" ~identifierPart
|
ground = "ground" ~identifierPart
|
||||||
message = "message" ~identifierPart
|
message = "message" ~identifierPart
|
||||||
metalevel = "metalevel" ~identifierPart
|
metalevel = "metalevel" ~identifierPart
|
||||||
|
named = "named" ~identifierPart
|
||||||
on = "on" ~identifierPart
|
on = "on" ~identifierPart
|
||||||
react = "react" ~identifierPart
|
react = "react" ~identifierPart
|
||||||
retracted = "retracted" ~identifierPart
|
retracted = "retracted" ~identifierPart
|
||||||
|
|
|
@ -10,11 +10,11 @@ var Util = require('./util.js');
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
function spawnActor(state, bootFn) {
|
function spawnActor(state, bootFn, optName) {
|
||||||
Dataspace.spawn(new Actor(state, bootFn));
|
Dataspace.spawn(new Actor(state, bootFn, optName));
|
||||||
}
|
}
|
||||||
|
|
||||||
function Actor(state, bootFn) {
|
function Actor(state, bootFn, optName) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.facets = Immutable.Set();
|
this.facets = Immutable.Set();
|
||||||
this.mux = new Mux.Mux();
|
this.mux = new Mux.Mux();
|
||||||
|
@ -22,6 +22,10 @@ function Actor(state, bootFn) {
|
||||||
this.knowledge = Trie.emptyTrie;
|
this.knowledge = Trie.emptyTrie;
|
||||||
this.pendingActions = [];
|
this.pendingActions = [];
|
||||||
|
|
||||||
|
if (typeof optName !== 'undefined') {
|
||||||
|
this.name = optName;
|
||||||
|
}
|
||||||
|
|
||||||
this.boot = function() {
|
this.boot = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
withCurrentFacet(null, function () {
|
withCurrentFacet(null, function () {
|
||||||
|
|
|
@ -113,17 +113,32 @@ Dataspace.exitDataspace = function () {
|
||||||
Dataspace.enqueueAction(terminateDataspace());
|
Dataspace.enqueueAction(terminateDataspace());
|
||||||
};
|
};
|
||||||
|
|
||||||
Dataspace.inertBehavior = {
|
Dataspace.inertBehavior = function (oldBehavior) {
|
||||||
handleEvent: function (e) {}
|
var b = { handleEvent: function (e) {} };
|
||||||
|
if ('name' in oldBehavior) {
|
||||||
|
b.name = oldBehavior.name;
|
||||||
|
}
|
||||||
|
return b;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Instance methods
|
// Instance methods
|
||||||
|
|
||||||
|
Dataspace.prototype.debugName = function (pid) {
|
||||||
|
var p = this.processTable.get(pid, null);
|
||||||
|
if (p === null) {
|
||||||
|
return '(dead)[' + pid + ']';
|
||||||
|
}
|
||||||
|
if ('name' in p.behavior) {
|
||||||
|
return JSON.stringify(p.behavior.name) + '[' + pid + ']';
|
||||||
|
}
|
||||||
|
return '(anon)[' + pid + ']';
|
||||||
|
};
|
||||||
|
|
||||||
Dataspace.prototype.asChild = function (pid, f, omitLivenessCheck) {
|
Dataspace.prototype.asChild = function (pid, f, omitLivenessCheck) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var p = this.processTable.get(pid, null);
|
var p = this.processTable.get(pid, null);
|
||||||
if (!omitLivenessCheck && (p === null)) {
|
if (!omitLivenessCheck && (p === null)) {
|
||||||
console.warn("Dataspace.asChild eliding invocation of dead process", pid);
|
console.warn("Dataspace.asChild eliding invocation of dead process", this.debugName(pid));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,15 +156,17 @@ Dataspace.prototype.asChild = function (pid, f, omitLivenessCheck) {
|
||||||
Dataspace.prototype.kill = function (pid, exn) {
|
Dataspace.prototype.kill = function (pid, exn) {
|
||||||
if (exn) {
|
if (exn) {
|
||||||
if (exn.stack) {
|
if (exn.stack) {
|
||||||
console.error("Process crashed", pid, exn, exn.stack);
|
console.error("Process crashed", this.debugName(pid), exn, exn.stack);
|
||||||
} else {
|
} else {
|
||||||
console.error("Process crashed", pid, exn);
|
console.error("Process crashed", this.debugName(pid), exn);
|
||||||
}
|
}
|
||||||
} else if (Dataspace.noisy) {
|
} else if (Dataspace.noisy) {
|
||||||
console.log("Process exiting", pid);
|
console.log("Process exiting", this.debugName(pid));
|
||||||
}
|
}
|
||||||
var p = this.processTable.get(pid);
|
var p = this.processTable.get(pid);
|
||||||
this.processTable = this.processTable.set(pid, { behavior: Dataspace.inertBehavior });
|
this.processTable = this.processTable.set(pid, {
|
||||||
|
behavior: Dataspace.inertBehavior(p.behavior)
|
||||||
|
});
|
||||||
if (p) {
|
if (p) {
|
||||||
if (p.behavior.trapexit) {
|
if (p.behavior.trapexit) {
|
||||||
this.asChild(pid, function () { return p.behavior.trapexit(exn); }, true);
|
this.asChild(pid, function () { return p.behavior.trapexit(exn); }, true);
|
||||||
|
@ -234,7 +251,8 @@ Dataspace.prototype.interpretAction = function (pid, action) {
|
||||||
|
|
||||||
case 'message':
|
case 'message':
|
||||||
if (Patch.observe.isClassOf(action.message)) {
|
if (Patch.observe.isClassOf(action.message)) {
|
||||||
console.warn('Process ' + pid + ' send message containing query', action.message);
|
console.warn('Process ' + this.debugName(pid) + ' sent message containing query',
|
||||||
|
action.message);
|
||||||
}
|
}
|
||||||
if (pid !== 'meta' && Patch.atMeta.isClassOf(action.message)) {
|
if (pid !== 'meta' && Patch.atMeta.isClassOf(action.message)) {
|
||||||
Dataspace.send(action.message[0]);
|
Dataspace.send(action.message[0]);
|
||||||
|
@ -262,7 +280,7 @@ Dataspace.prototype.interpretAction = function (pid, action) {
|
||||||
case 'terminate':
|
case 'terminate':
|
||||||
var oldMux = this.mux.shallowCopy();
|
var oldMux = this.mux.shallowCopy();
|
||||||
this.deliverPatches(oldMux, this.mux.removeStream(pid));
|
this.deliverPatches(oldMux, this.mux.removeStream(pid));
|
||||||
if (Dataspace.noisy) console.log("Process exit complete", pid);
|
if (Dataspace.noisy) console.log("Process exit complete", this.debugName(pid));
|
||||||
this.processTable = this.processTable.remove(pid);
|
this.processTable = this.processTable.remove(pid);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue