Rename "network" to "dataspace" throughout

This commit is contained in:
Tony Garnock-Jones 2016-04-07 09:42:54 +02:00
parent 71a7bacccd
commit 7fcfa9586b
58 changed files with 508 additions and 508 deletions

View File

@ -60,7 +60,7 @@
(advertisement (tcp-channel us them ?) #:meta-level 1) ;; we will write to remote client
))))
(spawn-network
(spawn-dataspace
(spawn-demand-matcher (advertise (tcp-channel (?!) (?! (tcp-listener 5999)) ?))
(observe (tcp-channel (?!) (?! (tcp-listener 5999)) ?))
#:meta-level 1
@ -105,7 +105,7 @@
(subscription (advertise (tcp-channel them us ?)) #:meta-level 1)
(advertisement (tcp-channel us them ?) #:meta-level 1)))))
(spawn-network
(spawn-dataspace
(spawn (lambda (e counter)
(match e
[(message 'bump)

View File

@ -896,18 +896,18 @@
;; LevelTerminationMonitor
;;
;; When the player vanishes from the board, or LevelCompleted is seen,
;; kills the network.
;; kills the dataspace.
(define (spawn-level-termination-monitor)
(spawn (lambda (e s)
(match e
[(? patch/removed?)
(log-info "Player died! Terminating level.")
(transition s (quit-network))]
(transition s (quit-dataspace))]
[(message (at-meta (level-completed)))
(log-info "Level completed! Terminating level.")
(transition s (list (message (at-meta (add-to-score 100)))
(quit-network)))]
(quit-dataspace)))]
[_ #f]))
(void)
(patch-seq (sub (game-piece-configuration player-id ? ? ?))
@ -946,7 +946,7 @@
#:level-size [level-size-vec (vector 4000 2000)]
#:scene [scene grassland-backdrop]
. actions)
(spawn-network
(spawn-dataspace
(and scene (spawn-background-image level-size-vec scene))
(spawn-display-controller level-size-vec)
(spawn-physics-engine)
@ -1028,10 +1028,10 @@
(define game-level 3) ;; used to specify meta-level to reach external I/O
(2d-network #:width 600 #:height 400
(spawn-keyboard-integrator)
(spawn-scene-manager)
(spawn-network (spawn-score-keeper)
(spawn-level-spawner 0)
)
)
(2d-dataspace #:width 600 #:height 400
(spawn-keyboard-integrator)
(spawn-scene-manager)
(spawn-dataspace (spawn-score-keeper)
(spawn-level-spawner 0)
)
)

View File

@ -11,8 +11,8 @@ Source files in `src/`, from most general to most specific:
- `route.js`: Implementation of dataspace trie structure.
- `patch.js`: Implementation of patches over dataspace tries.
- `mux.js`: Use of tries plus patches to build a (de)multiplexing routing structure.
- `network.js`: Implementation of core leaf actors and networks.
- `ground.js`: Pseudo-network acting as the global outermost context for Syndicate actors.
- `dataspace.js`: Implementation of core leaf actors and dataspaces.
- `ground.js`: Pseudo-dataspace acting as the global outermost context for Syndicate actors.
- `ack.js`: Utility for detecting when a previous state change has taken effect.
- `seal.js`: Immutable container for data, used to hide structure from dataspace tries.

View File

@ -86,7 +86,7 @@ var modifiedSourceActions = {
return buildActor(ctorExp.asES5, block);
},
NetworkStatement_ground: function(_ground, _network, maybeId, block) {
DataspaceStatement_ground: function(_ground, _dataspace, maybeId, block) {
var code = 'new Syndicate.Ground(function () ' + block.asES5 + ').startStepping();';
if (maybeId.numChildren === 1) {
return 'var ' + maybeId.children[0].interval.contents + ' = ' + code;
@ -94,8 +94,8 @@ var modifiedSourceActions = {
return code;
}
},
NetworkStatement_normal: function(_network, block) {
return 'Syndicate.Network.spawn(new Network(function () ' + block.asES5 + '));';
DataspaceStatement_normal: function(_dataspace, block) {
return 'Syndicate.Dataspace.spawn(new Dataspace(function () ' + block.asES5 + '));';
},
ActorFacetStatement_state: function(_state, facetBlock, _until, transitionBlock) {
@ -143,7 +143,7 @@ var modifiedSourceActions = {
},
SendMessageStatement: function(_colons, expr, sc) {
return 'Syndicate.Network.send(' + expr.asES5 + ')' + sc.interval.contents;
return 'Syndicate.Dataspace.send(' + expr.asES5 + ')' + sc.interval.contents;
},
FacetBlock: function(_leftParen, init, situations, done, _rightParen) {

View File

@ -5,7 +5,7 @@ var Syndicate = require('./src/main.js');
assertion type account(balance);
assertion type deposit(amount);
ground network {
ground dataspace {
actor {
this.balance = 0;

View File

@ -6,7 +6,7 @@ assertion type file(name, content) = "file";
assertion type saveFile(name, content) = "save";
assertion type deleteFile(name) = "delete";
ground network {
ground dataspace {
///////////////////////////////////////////////////////////////////////////
// The file system actor

View File

@ -8,7 +8,7 @@ Syndicate <: ES5 {
Statement
+= ActorStatement
| NetworkStatement
| DataspaceStatement
| ActorFacetStatement
| AssertionTypeDeclarationStatement
| SendMessageStatement
@ -17,9 +17,9 @@ Syndicate <: ES5 {
= actor CallExpression Block -- withConstructor
| actor Block -- noConstructor
NetworkStatement
= ground network identifier? Block -- ground
| network Block -- normal
DataspaceStatement
= ground dataspace identifier? Block -- ground
| dataspace Block -- normal
ActorFacetStatement
= state FacetBlock until FacetStateTransitionBlock -- state
@ -71,6 +71,7 @@ Syndicate <: ES5 {
assert = "assert" ~identifierPart
asserted = "asserted" ~identifierPart
assertion = "assertion" ~identifierPart
dataspace = "dataspace" ~identifierPart
done = "done" ~identifierPart
during = "during" ~identifierPart
forever = "forever" ~identifierPart
@ -78,7 +79,6 @@ Syndicate <: ES5 {
init = "init" ~identifierPart
message = "message" ~identifierPart
metalevel = "metalevel" ~identifierPart
network = "network" ~identifierPart
on = "on" ~identifierPart
retracted = "retracted" ~identifierPart
state = "state" ~identifierPart

View File

@ -2,7 +2,7 @@ assertion type DOM(containerSelector, fragmentClass, spec);
assertion type jQuery(selector, eventType, event);
$(document).ready(function() {
ground network {
ground dataspace {
Syndicate.DOM.spawnDOMDriver();
Syndicate.JQuery.spawnJQueryDriver();

View File

@ -1,6 +1,6 @@
var G;
$(document).ready(function () {
var Network = Syndicate.Network;
var Dataspace = Syndicate.Dataspace;
var sub = Syndicate.sub;
var assert = Syndicate.assert;
var retract = Syndicate.retract;
@ -13,7 +13,7 @@ $(document).ready(function () {
Syndicate.DOM.spawnDOMDriver();
Network.spawn({
Dataspace.spawn({
boot: function () {
return assert(["DOM", "#clicker-holder", "clicker",
seal(["button", ["span", [["style", "font-style: italic"]], "Click me!"]])])
@ -21,23 +21,23 @@ $(document).ready(function () {
},
handleEvent: function (e) {
if (e.type === "message" && e.message[0] === "jQuery") {
Network.send("bump_count");
Dataspace.send("bump_count");
}
}
});
Network.spawn({
Dataspace.spawn({
counter: 0,
boot: function () {
this.updateState();
return sub("bump_count");
},
updateState: function () {
Network.stateChange(retract(["DOM", __, __, __])
.andThen(assert(["DOM", "#counter-holder", "counter",
seal(["div",
["p", "The current count is: ",
this.counter]])])));
Dataspace.stateChange(retract(["DOM", __, __, __])
.andThen(assert(["DOM", "#counter-holder", "counter",
seal(["div",
["p", "The current count is: ",
this.counter]])])));
},
handleEvent: function (e) {
if (e.type === "message" && e.message === "bump_count") {
@ -48,7 +48,7 @@ $(document).ready(function () {
});
});
G.network.onStateChange = function (mux, patch) {
G.dataspace.onStateChange = function (mux, patch) {
$("#spy-holder").text(Syndicate.prettyTrie(mux.routingTable));
};

View File

@ -2,7 +2,7 @@
var G;
$(document).ready(function () {
var Network = Syndicate.Network;
var Dataspace = Syndicate.Dataspace;
var sub = Syndicate.sub;
var __ = Syndicate.__;
var _$ = Syndicate._$;
@ -12,7 +12,7 @@ $(document).ready(function () {
Syndicate.JQuery.spawnJQueryDriver();
Network.spawn({
Dataspace.spawn({
boot: function () {
return sub(['jQuery', '#clicker', 'click', __]);
},
@ -24,7 +24,7 @@ $(document).ready(function () {
}
});
});
G.network.onStateChange = function (mux, patch) {
G.dataspace.onStateChange = function (mux, patch) {
$("#spy-holder").text(Syndicate.prettyTrie(mux.routingTable));
};
G.startStepping();

View File

@ -1,6 +1,6 @@
assertion type beep(counter);
ground network {
ground dataspace {
console.log('starting ground boot');
actor {

View File

@ -2,7 +2,7 @@
var G;
$(document).ready(function () {
var Network = Syndicate.Network;
var Dataspace = Syndicate.Dataspace;
var sub = Syndicate.sub;
var __ = Syndicate.__;
var _$ = Syndicate._$;
@ -10,17 +10,17 @@ $(document).ready(function () {
G = new Syndicate.Ground(function () {
console.log('starting ground boot');
Network.spawn({
Dataspace.spawn({
counter: 0,
boot: function () {},
handleEvent: function (e) {},
step: function () {
Network.send(["beep", this.counter++]);
Dataspace.send(["beep", this.counter++]);
return this.counter <= 10;
}
});
Network.spawn({
Dataspace.spawn({
boot: function () { return sub(["beep", __]); },
handleEvent: function (e) {
if (e.type === 'message') {

View File

@ -154,7 +154,7 @@ function spawnSearch() {
// Main
$(document).ready(function () {
ground network G {
ground dataspace G {
Syndicate.JQuery.spawnJQueryDriver();
Syndicate.DOM.spawnDOMDriver();
@ -163,7 +163,7 @@ $(document).ready(function () {
spawnSearch();
}
G.network.onStateChange = function (mux, patch) {
G.dataspace.onStateChange = function (mux, patch) {
$("#spy-holder").text(Syndicate.prettyTrie(mux.routingTable));
};
});

View File

@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////////////
// GUI
var Network = Syndicate.Network;
var Dataspace = Syndicate.Dataspace;
var Route = Syndicate.Route;
var Patch = Syndicate.Patch;
var __ = Syndicate.__;
@ -26,7 +26,7 @@ function piece(text, pos, lo, hi, cls) {
}
function spawnGui() {
Network.spawn({
Dataspace.spawn({
field: { text: '', pos: 0 },
highlight: { state: false },
@ -46,15 +46,15 @@ function spawnGui() {
var keycode = event.keyCode;
var character = String.fromCharCode(event.charCode);
if (keycode === 37 /* left */) {
Network.send(["fieldCommand", "cursorLeft"]);
Dataspace.send(["fieldCommand", "cursorLeft"]);
} else if (keycode === 39 /* right */) {
Network.send(["fieldCommand", "cursorRight"]);
Dataspace.send(["fieldCommand", "cursorRight"]);
} else if (keycode === 9 /* tab */) {
// ignore
} else if (keycode === 8 /* backspace */) {
Network.send(["fieldCommand", "backspace"]);
Dataspace.send(["fieldCommand", "backspace"]);
} else if (character) {
Network.send(["fieldCommand", ["insert", character]]);
Dataspace.send(["fieldCommand", ["insert", character]]);
}
break;
case "stateChange":
@ -89,7 +89,7 @@ function spawnGui() {
function spawnModel() {
var initialContents = "initial";
Network.spawn({
Dataspace.spawn({
fieldContents: initialContents,
cursorPos: initialContents.length, /* positions address gaps between characters */
@ -127,7 +127,7 @@ function spawnModel() {
},
publishState: function () {
Network.stateChange(
Dataspace.stateChange(
Patch.retract(["fieldContents", __, __])
.andThen(Patch.assert(["fieldContents", this.fieldContents, this.cursorPos])));
}
@ -138,7 +138,7 @@ function spawnModel() {
// Search engine
function spawnSearch() {
Network.spawn({
Dataspace.spawn({
fieldContents: "",
highlight: false,
@ -163,7 +163,7 @@ function spawnSearch() {
},
publishState: function () {
Network.stateChange(
Dataspace.stateChange(
Patch.retract(["highlight", __])
.andThen(Patch.assert(["highlight", this.highlight])));
},
@ -198,7 +198,7 @@ $(document).ready(function () {
spawnSearch();
});
G.network.onStateChange = function (mux, patch) {
G.dataspace.onStateChange = function (mux, patch) {
$("#spy-holder").text(Syndicate.prettyTrie(mux.routingTable));
};

View File

@ -1,7 +1,7 @@
// Utility protocol for measuring when a stateChange takes effect.
var RandomID = require('./randomid.js');
var Network = require('./network.js').Network;
var Dataspace = require('./dataspace.js').Dataspace;
var Route = require('./route.js');
var Patch = require('./patch.js');
@ -14,12 +14,12 @@ function Ack(metaLevel, id) {
}
Ack.prototype.arm = function () {
Network.stateChange(Patch.sub([$Ack, this.id], this.metaLevel));
Network.send([$Ack, this.id], this.metaLevel);
Dataspace.stateChange(Patch.sub([$Ack, this.id], this.metaLevel));
Dataspace.send([$Ack, this.id], this.metaLevel);
};
Ack.prototype.disarm = function () {
Network.stateChange(Patch.unsub([$Ack, this.id], this.metaLevel));
Dataspace.stateChange(Patch.unsub([$Ack, this.id], this.metaLevel));
};
Ack.prototype.check = function (e) {

View File

@ -1,7 +1,7 @@
'use strict';
var Immutable = require('immutable');
var Network = require('./network.js').Network;
var Dataspace = require('./dataspace.js').Dataspace;
var Mux = require('./mux.js');
var Patch = require('./patch.js');
var Route = require('./route.js');
@ -10,7 +10,7 @@ var Util = require('./util.js');
//---------------------------------------------------------------------------
function spawnActor(state, bootFn) {
Network.spawn(new Actor(state, bootFn));
Dataspace.spawn(new Actor(state, bootFn));
}
function Actor(state, bootFn) {
@ -41,14 +41,14 @@ Actor.prototype.removeFacet = function(facet) {
Actor.prototype.checkForTermination = function() {
if (this.facets.isEmpty()) {
Network.exit();
Dataspace.exit();
}
};
//---------------------------------------------------------------------------
function createFacet() {
return new Facet(Network.activeBehavior());
return new Facet(Dataspace.activeBehavior());
}
function Facet(actor) {
@ -129,7 +129,7 @@ Facet.prototype.addEndpoint = function(endpoint) {
var patch = endpoint.subscriptionFn.call(this.actor.state);
var r = this.actor.mux.addStream(patch);
this.endpoints = this.endpoints.set(r.pid, endpoint);
Network.stateChange(r.deltaAggregate);
Dataspace.stateChange(r.deltaAggregate);
return this; // for chaining
};
@ -152,7 +152,7 @@ Facet.prototype.refresh = function() {
var r = facet.actor.mux.updateStream(eid, patch);
aggregate = aggregate.andThen(r.deltaAggregate);
});
Network.stateChange(aggregate);
Dataspace.stateChange(aggregate);
};
Facet.prototype.completeBuild = function() {
@ -168,7 +168,7 @@ Facet.prototype.terminate = function() {
var r = facet.actor.mux.removeStream(eid);
aggregate = aggregate.andThen(r.deltaAggregate);
});
Network.stateChange(aggregate);
Dataspace.stateChange(aggregate);
this.endpoints = Immutable.Map();
this.actor.removeFacet(this);
this.doneBlocks.forEach(function(b) { b.call(facet.actor.state); });

View File

@ -24,14 +24,14 @@ function terminate() {
return { type: 'terminate' };
}
function terminateNetwork() {
return { type: 'terminateNetwork' };
function terminateDataspace() {
return { type: 'terminateDataspace' };
}
/*---------------------------------------------------------------------------*/
/* Network */
/* Dataspace */
function Network(bootFn) {
function Dataspace(bootFn) {
this.pendingActions = Immutable.List(); // of [pid, Action]
this.processTable = Immutable.Map(); // pid -> Behavior
this.runnablePids = Immutable.Set(); // of pid
@ -42,93 +42,93 @@ function Network(bootFn) {
// Class state and methods
Network.stack = Immutable.List();
Dataspace.stack = Immutable.List();
Network.current = function () {
return Network.stack.last().network;
Dataspace.current = function () {
return Dataspace.stack.last().dataspace;
};
Network.activePid = function () {
return Network.stack.last().activePid;
Dataspace.activePid = function () {
return Dataspace.stack.last().activePid;
};
Network.activeBehavior = function () {
var entry = Network.stack.last();
var p = entry.network.processTable.get(entry.activePid);
Dataspace.activeBehavior = function () {
var entry = Dataspace.stack.last();
var p = entry.dataspace.processTable.get(entry.activePid);
return p ? p.behavior : null;
};
Network.withNetworkStack = function (stack, f) {
var oldStack = Network.stack;
Network.stack = stack;
Dataspace.withDataspaceStack = function (stack, f) {
var oldStack = Dataspace.stack;
Dataspace.stack = stack;
var result;
try {
result = f();
} catch (e) {
Network.stack = oldStack;
Dataspace.stack = oldStack;
throw e;
}
Network.stack = oldStack;
Dataspace.stack = oldStack;
return result;
};
Network.wrap = function (f) {
var savedStack = Network.stack;
Dataspace.wrap = function (f) {
var savedStack = Dataspace.stack;
return function () {
var actuals = arguments;
return Network.withNetworkStack(savedStack, function () {
var result = Network.current().asChild(Network.activePid(), function () {
return Dataspace.withDataspaceStack(savedStack, function () {
var result = Dataspace.current().asChild(Dataspace.activePid(), function () {
return f.apply(null, actuals);
});
Network.stack.reverse().forEach(function (entry) {
entry.network.markRunnable(entry.activePid);
Dataspace.stack.reverse().forEach(function (entry) {
entry.dataspace.markRunnable(entry.activePid);
});
return result;
});
};
};
Network.enqueueAction = function (action) {
var entry = Network.stack.last();
entry.network.enqueueAction(entry.activePid, action);
Dataspace.enqueueAction = function (action) {
var entry = Dataspace.stack.last();
entry.dataspace.enqueueAction(entry.activePid, action);
};
Network.send = function (body, metaLevel) {
Network.enqueueAction(message(Patch.prependAtMeta(body, metaLevel || 0)));
Dataspace.send = function (body, metaLevel) {
Dataspace.enqueueAction(message(Patch.prependAtMeta(body, metaLevel || 0)));
};
Network.stateChange = function (patch) {
Network.enqueueAction(stateChange(patch));
Dataspace.stateChange = function (patch) {
Dataspace.enqueueAction(stateChange(patch));
};
Network.spawn = function (behavior) {
Network.enqueueAction(spawn(behavior));
Dataspace.spawn = function (behavior) {
Dataspace.enqueueAction(spawn(behavior));
};
Network.exit = function (exn) {
Network.current().kill(Network.activePid(), exn);
Dataspace.exit = function (exn) {
Dataspace.current().kill(Dataspace.activePid(), exn);
};
Network.exitNetwork = function () {
Network.enqueueAction(terminateNetwork());
Dataspace.exitDataspace = function () {
Dataspace.enqueueAction(terminateDataspace());
};
Network.inertBehavior = {
Dataspace.inertBehavior = {
handleEvent: function (e) {}
};
// Instance methods
Network.prototype.asChild = function (pid, f, omitLivenessCheck) {
Dataspace.prototype.asChild = function (pid, f, omitLivenessCheck) {
var self = this;
var p = this.processTable.get(pid, null);
if (!omitLivenessCheck && (p === null)) {
console.warn("Network.asChild eliding invocation of dead process", pid);
console.warn("Dataspace.asChild eliding invocation of dead process", pid);
return;
}
return Network.withNetworkStack(
Network.stack.push({ network: this, activePid: pid }),
return Dataspace.withDataspaceStack(
Dataspace.stack.push({ dataspace: this, activePid: pid }),
function () {
try {
return f(p);
@ -138,14 +138,14 @@ Network.prototype.asChild = function (pid, f, omitLivenessCheck) {
});
};
Network.prototype.kill = function (pid, exn) {
Dataspace.prototype.kill = function (pid, exn) {
if (exn && exn.stack) {
console.log("Process exiting", pid, exn, exn.stack);
} else {
console.log("Process exiting", pid, exn);
}
var p = this.processTable.get(pid);
this.processTable = this.processTable.set(pid, { behavior: Network.inertBehavior });
this.processTable = this.processTable.set(pid, { behavior: Dataspace.inertBehavior });
if (p) {
if (p.behavior.trapexit) {
this.asChild(pid, function () { return p.behavior.trapexit(exn); }, true);
@ -154,12 +154,12 @@ Network.prototype.kill = function (pid, exn) {
}
};
Network.prototype.boot = function () {
// Needed in order for a new Network to be marked as "runnable", so
Dataspace.prototype.boot = function () {
// Needed in order for a new Dataspace to be marked as "runnable", so
// its initial actions get performed.
};
Network.prototype.handleEvent = function (e) {
Dataspace.prototype.handleEvent = function (e) {
switch (e.type) {
case 'stateChange':
this.enqueueAction('meta', stateChange(e.patch.lift()));
@ -175,17 +175,17 @@ Network.prototype.handleEvent = function (e) {
return true;
};
Network.prototype.step = function () {
Dataspace.prototype.step = function () {
return this.dispatchActions()
&& this.runRunnablePids()
&& ((this.pendingActions.size > 0) || (this.runnablePids.size > 0));
};
Network.prototype.enqueueAction = function (pid, action) {
Dataspace.prototype.enqueueAction = function (pid, action) {
this.pendingActions = this.pendingActions.push([pid, action]);
};
Network.prototype.dispatchActions = function () {
Dataspace.prototype.dispatchActions = function () {
var self = this;
var actionQueue = this.pendingActions;
this.pendingActions = Immutable.List();
@ -201,11 +201,11 @@ Network.prototype.dispatchActions = function () {
return alive;
};
Network.prototype.markRunnable = function (pid) {
Dataspace.prototype.markRunnable = function (pid) {
this.runnablePids = this.runnablePids.add(pid);
};
Network.prototype.runRunnablePids = function () {
Dataspace.prototype.runRunnablePids = function () {
var self = this;
var pidSet = this.runnablePids;
this.runnablePids = Immutable.Set();
@ -219,7 +219,7 @@ Network.prototype.runRunnablePids = function () {
return true;
};
Network.prototype.interpretAction = function (pid, action) {
Dataspace.prototype.interpretAction = function (pid, action) {
var self = this;
switch (action.type) {
@ -233,7 +233,7 @@ Network.prototype.interpretAction = function (pid, action) {
console.warn('Process ' + pid + ' send message containing query', action.message);
}
if (pid !== 'meta' && Patch.isAtMeta(action.message)) {
Network.send(action.message[1]);
Dataspace.send(action.message[1]);
} else {
this.mux.routeMessage(action.message).forEach(function (pid) {
self.deliverEvent(pid, action);
@ -262,8 +262,8 @@ Network.prototype.interpretAction = function (pid, action) {
this.processTable = this.processTable.remove(pid);
return true;
case 'terminateNetwork':
Network.exit();
case 'terminateDataspace':
Dataspace.exit();
return false;
default:
@ -273,17 +273,17 @@ Network.prototype.interpretAction = function (pid, action) {
}
};
Network.prototype.deliverPatches = function (oldMux, updateStreamResult) {
Dataspace.prototype.deliverPatches = function (oldMux, updateStreamResult) {
var self = this;
var events = Mux.computeEvents(oldMux, this.mux, updateStreamResult);
events.eventMap.forEach(function (patch, pid) {
self.deliverEvent(pid, stateChange(patch));
});
events.metaEvents.forEach(Network.stateChange);
events.metaEvents.forEach(Dataspace.stateChange);
this.onStateChange(this.mux, updateStreamResult.deltaAggregate);
};
Network.prototype.deliverEvent = function (pid, event) {
Dataspace.prototype.deliverEvent = function (pid, event) {
var childBusy = this.asChild(pid, function (p) { return p.behavior.handleEvent(event); });
if (childBusy) this.markRunnable(pid);
};
@ -294,6 +294,6 @@ module.exports.stateChange = stateChange;
module.exports.message = message;
module.exports.spawn = spawn;
module.exports.terminate = terminate;
module.exports.terminateNetwork = terminateNetwork;
module.exports.terminateDataspace = terminateDataspace;
module.exports.Network = Network;
module.exports.Dataspace = Dataspace;

View File

@ -4,20 +4,20 @@ var DemandMatcher = require('./demand-matcher.js').DemandMatcher;
var Ack = require('./ack.js').Ack;
var Seal = require('./seal.js').Seal;
var Network_ = require("./network.js");
var Network = Network_.Network;
var __ = Network_.__;
var _$ = Network_._$;
var Dataspace_ = require("./dataspace.js");
var Dataspace = Dataspace_.Dataspace;
var __ = Dataspace_.__;
var _$ = Dataspace_._$;
function spawnDOMDriver(domWrapFunction, jQueryWrapFunction) {
domWrapFunction = domWrapFunction || defaultWrapFunction;
var spec = domWrapFunction(_$('selector'), _$('fragmentClass'), _$('fragmentSpec'));
Network.spawn(
Dataspace.spawn(
new DemandMatcher(spec,
Patch.advertise(spec),
{
onDemandIncrease: function (c) {
Network.spawn(new DOMFragment(c.selector,
Dataspace.spawn(new DOMFragment(c.selector,
c.fragmentClass,
c.fragmentSpec,
domWrapFunction,
@ -45,11 +45,11 @@ DOMFragment.prototype.boot = function () {
var self = this;
var specification = self.domWrapFunction(self.selector, self.fragmentClass, self.fragmentSpec);
Network.spawn(new Network(function () {
Dataspace.spawn(new Dataspace(function () {
Syndicate.JQuery.spawnJQueryDriver(self.selector+" > ."+self.fragmentClass,
1,
self.jQueryWrapFunction);
Network.spawn({
Dataspace.spawn({
demandExists: false,
subscriptionEstablished: new Ack(1),
boot: function () {
@ -63,7 +63,7 @@ DOMFragment.prototype.boot = function () {
if (e.patch.hasRemoved()) this.demandExists = false;
}
if (this.subscriptionEstablished.done && !this.demandExists) {
Network.exitNetwork();
Dataspace.exitDataspace();
}
}
});
@ -84,7 +84,7 @@ DOMFragment.prototype.handleEvent = function (e) {
var n = this.nodes[i];
n.parentNode.removeChild(n);
}
Network.exit();
Dataspace.exit();
}
};

View File

@ -1,21 +1,21 @@
"use strict";
var Immutable = require('immutable');
var Network = require('./network.js').Network;
var Dataspace = require('./dataspace.js').Dataspace;
function Ground(bootFn) {
var self = this;
this.stepperId = null;
this.baseStack = Immutable.List.of({ network: this, activePid: -1 });
Network.withNetworkStack(this.baseStack, function () {
self.network = new Network(bootFn);
this.baseStack = Immutable.List.of({ dataspace: this, activePid: -1 });
Dataspace.withDataspaceStack(this.baseStack, function () {
self.dataspace = new Dataspace(bootFn);
});
}
Ground.prototype.step = function () {
var self = this;
return Network.withNetworkStack(this.baseStack, function () {
return self.network.step();
return Dataspace.withDataspaceStack(this.baseStack, function () {
return self.dataspace.step();
});
};
@ -49,7 +49,7 @@ Ground.prototype.stopStepping = function () {
Ground.prototype.kill = function (pid, exn) {
this.checkPid(pid);
console.log("Ground network terminated");
console.log("Ground dataspace terminated");
this.stopStepping();
};

View File

@ -2,21 +2,21 @@
var Patch = require("./patch.js");
var DemandMatcher = require('./demand-matcher.js').DemandMatcher;
var Network_ = require("./network.js");
var Network = Network_.Network;
var __ = Network_.__;
var _$ = Network_._$;
var Dataspace_ = require("./dataspace.js");
var Dataspace = Dataspace_.Dataspace;
var __ = Dataspace_.__;
var _$ = Dataspace_._$;
function spawnJQueryDriver(baseSelector, metaLevel, wrapFunction) {
metaLevel = metaLevel || 0;
wrapFunction = wrapFunction || defaultWrapFunction;
Network.spawn(
Dataspace.spawn(
new DemandMatcher(Patch.observe(wrapFunction(_$('selector'), _$('eventName'), __)),
Patch.advertise(wrapFunction(_$('selector'), _$('eventName'), __)),
{
metaLevel: metaLevel,
onDemandIncrease: function (c) {
Network.spawn(new JQueryEventRouter(baseSelector,
Dataspace.spawn(new JQueryEventRouter(baseSelector,
c.selector,
c.eventName,
metaLevel,
@ -38,8 +38,8 @@ function JQueryEventRouter(baseSelector, selector, eventName, metaLevel, wrapFun
this.wrapFunction = wrapFunction || defaultWrapFunction;
this.preventDefault = (this.eventName.charAt(0) !== "+");
this.handler =
Network.wrap(function (e) {
Network.send(self.wrapFunction(self.selector, self.eventName, e), self.metaLevel);
Dataspace.wrap(function (e) {
Dataspace.send(self.wrapFunction(self.selector, self.eventName, e), self.metaLevel);
if (self.preventDefault) e.preventDefault();
return !self.preventDefault;
});
@ -56,7 +56,7 @@ JQueryEventRouter.prototype.boot = function () {
JQueryEventRouter.prototype.handleEvent = function (e) {
if (e.type === "stateChange" && e.patch.hasRemoved()) {
this.computeNodes().off(this.eventName, this.handler);
Network.exit();
Dataspace.exit();
}
};

View File

@ -6,7 +6,7 @@ function copyKeys(keys, to, from) {
}
}
module.exports = require("./network.js");
module.exports = require("./dataspace.js");
module.exports.Route = require("./route.js");
copyKeys(['__', '_$', '$Capture', '$Special',

View File

@ -4,7 +4,7 @@ var expect = require('expect.js');
var Immutable = require('immutable');
var Syndicate = require('../src/main.js');
var Network = Syndicate.Network;
var Dataspace = Syndicate.Dataspace;
var Patch = Syndicate.Patch;
var __ = Syndicate.__;
@ -53,12 +53,12 @@ describe("configurationTrace", function() {
describe("with some traced communication", function () {
it("should yield an appropriate trace", function () {
checkTrace(function (trace) {
Network.spawn({
Dataspace.spawn({
boot: function () { return Syndicate.sub(__); },
handleEvent: traceEvent(trace)
});
Network.send(123);
Network.send(234);
Dataspace.send(123);
Dataspace.send(234);
}, ['<<<<<<<< Removed:\n'+
'::: nothing\n'+
'======== Added:\n'+
@ -75,11 +75,11 @@ describe("nonempty initial routes", function () {
it("should be immediately signalled to the process", function () {
// Specifically, no Syndicate.updateRoutes([]) first.
checkTrace(function (trace) {
Network.spawn({
Dataspace.spawn({
boot: function () { return Patch.assert(["A", __]); },
handleEvent: function (e) {}
});
Network.spawn({
Dataspace.spawn({
boot: function () { return Patch.sub(["A", __]); },
handleEvent: traceEvent(trace)
});
@ -94,10 +94,10 @@ describe("nonempty initial routes", function () {
describe("nested actor with an echoey protocol", function () {
it("shouldn't see an echoed assertion", function () {
checkTrace(function (trace) {
Network.spawn(new Network(function () {
Network.spawn({
Dataspace.spawn(new Dataspace(function () {
Dataspace.spawn({
boot: function () {
Network.stateChange(Patch.retract("X", 1)); // happens after subs on next line!
Dataspace.stateChange(Patch.retract("X", 1)); // happens after subs on next line!
return Patch.sub("X", 1).andThen(Patch.assert("X", 1));
},
handleEvent: traceEvent(trace)
@ -116,10 +116,10 @@ describe("nested actor with an echoey protocol", function () {
})
it("shouldn't see an echoed message", function () {
checkTrace(function (trace) {
Network.spawn(new Network(function () {
Network.spawn({
Dataspace.spawn(new Dataspace(function () {
Dataspace.spawn({
boot: function () {
Network.send("X", 1); // happens after subs on next line!
Dataspace.send("X", 1); // happens after subs on next line!
return Patch.sub("X", 1);
},
handleEvent: traceEvent(trace)
@ -134,10 +134,10 @@ describe("nested actor with an echoey protocol", function () {
// describe("actor with nonempty initial routes", function () {
// it("shouldn't see initial empty conversational context", function () {
// checkTrace(function (trace) {
// Network.spawn({
// Dataspace.spawn({
// boot: function () { return [pub(["A", __])] },
// handleEvent: function (e) {
// Network.spawn(new Actor(function () {
// Dataspace.spawn(new Actor(function () {
// Actor.observeAdvertisers(
// function () { return ["A", __] },
// { presence: "isPresent" },

View File

@ -2,7 +2,7 @@
* How do I run a syndicate program?
- `#lang syndicate` collects actions (`spawn`s) from module toplevel and
uses them as boot actions for a ground-level network. The alternative
uses them as boot actions for a ground-level dataspace. The alternative
is to use a different #lang, and to call `run-ground` yourself; see an
example in syndicate/examples/example-plain.rkt.
@ -20,7 +20,7 @@
p - lifecycle events (spawns, crashes, and quits)
a - process actions
g - dataspace contents
Adding 'N' will show whole network-states too. Remove each individual
Adding 'N' will show whole dataspace-states too. Remove each individual
character to turn off the corresponding trace facility; the default
value of the variable is just the empty-string.
@ -67,8 +67,8 @@
;; stateless actor
(spawn/stateless (lambda (event) ... (list action ...))
initial-action ...)
;; network of actors
(spawn-network boot-action ...)
;; dataspace of actors
(spawn-dataspace boot-action ...)
```
* How do actors at different levels communicate?
@ -98,9 +98,9 @@
while the second says
> OVER THERE, I am interested in assertions 'hello
The former is necessary for the local network to route events to us, and
the latter is necessary for the remote network to route events to the
local network.
The former is necessary for the local dataspace to route events to us, and
the latter is necessary for the remote dataspace to route events to the
local dataspace.
Implicit in any `sub` call with N>0 meta-level, therefore, is the
construction of a whole *chain* of subscriptions, relaying information
@ -176,7 +176,7 @@
When a message is sent, it is delivered to everyone that is interested in it
**at that time**.
* How to inject an external event (e.g. keyboard press) into the network?
* How to inject an external event (e.g. keyboard press) into the dataspace?
- Use `send-ground-message`.
- (Note that the argument to `send-ground-message` is wrapped in a `message`,
so to send `'foo` at the ground level use `(send-ground-message 'foo)` rather than
@ -191,10 +191,10 @@
* I used `spawn` but the actor isn't being created. What happened?
- The only two ways to spawn a process are to (a) supply the spawn instruction in
that network's boot-actions, or (b) have some already-existing actor supply the
that dataspace's boot-actions, or (b) have some already-existing actor supply the
spawn instruction in response to some event it receives. Note that calling `spawn`
constructs a structure which is perhaps eventually interpreted by the containing
network of an actor; it doesn't really "do" anything directly.
dataspace of an actor; it doesn't really "do" anything directly.
* Why does `patch-seq` exist? Aren't all the actions in a transition effectively `patch-seq`d together?
- Effectively, yes, that is what happens. The difference is in the
@ -210,7 +210,7 @@
gets to observe things-as-they-were-before-the-patch, and
things-as-they-are-after-the-patch.
* How do I create a tiered network, such as
* How do I create a tiered dataspace, such as
```
ground
/ \
@ -218,15 +218,15 @@
\
net3
```
- use `spawn-network`:
- use `spawn-dataspace`:
```racket
#lang syndicate
(spawn-network <net1-spawns> ...)
(spawn-network <net2-spawns> ...
(spawn-network <net3-spawns> ...))
(spawn-dataspace <net1-spawns> ...)
(spawn-dataspace <net2-spawns> ...
(spawn-dataspace <net3-spawns> ...))
```
`spawn-network` expands into a regular `spawn` with an event-handler and
state corresponding to a whole VM. The arguments to spawn-network are
`spawn-dataspace` expands into a regular `spawn` with an event-handler and
state corresponding to a whole VM. The arguments to spawn-dataspace are
actions to take at boot time in the new VM.
* What is the outcome if I do `(assert X)` and then later `(patch-seq (retract ?) assert X)`?
@ -275,4 +275,4 @@
* Why does `#f` keep getting sent as an event?
- When a behavior returns something besides `#f` in response to an event, it is
repeatedly sent `#f` until it does return `#f`.
- Think of it as a way of the network asking "anything else?"
- Think of it as a way of the dataspace asking "anything else?"

View File

@ -37,15 +37,15 @@
(idle 0 (- mx dx) (- my dy))]))
(actor (idle 0 orig-x orig-y)))
(big-bang-network #:width 640
#:height 480
(actor (forever
(on (asserted (active-window $id) #:meta-level 1)
(update-window 'active-window-label 300 0
(text (format "~v" id) 22 "black")))))
(button #:background "red" 'stop-button 0 0 "Exit"
(lambda () (assert! 'stop #:meta-level 1)))
(draggable-shape 'c1 50 50 (circle 30 "solid" "orange"))
(draggable-shape 's1 100 100 (star 40 "solid" "firebrick")))
(big-bang-dataspace #:width 640
#:height 480
(actor (forever
(on (asserted (active-window $id) #:meta-level 1)
(update-window 'active-window-label 300 0
(text (format "~v" id) 22 "black")))))
(button #:background "red" 'stop-button 0 0 "Exit"
(lambda () (assert! 'stop #:meta-level 1)))
(draggable-shape 'c1 50 50 (circle 30 "solid" "orange"))
(draggable-shape 's1 100 100 (star 40 "solid" "firebrick")))
(exit 0)

View File

@ -19,13 +19,13 @@
(on `(,$who says ,$what) (say who "says: ~a" what))
(on (message (at-meta (tcp-channel them us $bs)))
(define input-string (string-trim (bytes->string/utf-8 bs)))
(if (equal? input-string "quit-network")
(assert! 'quit-network)
(if (equal? input-string "quit-dataspace")
(assert! 'quit-dataspace)
(send! `(,user says ,input-string)))))
(send-to-remote "Goodbye!\n")))
(spawn-tcp-driver)
(let ((us (tcp-listener 5999)))
(group (until (asserted 'quit-network)
(group (until (asserted 'quit-dataspace)
(on (asserted (advertise (tcp-channel $them us ?)) #:meta-level 1)
(spawn-session them us)))))

View File

@ -3,7 +3,7 @@
Just a sketch, at the moment.
Instantaneous actions, I := (actor I ...)
(network I ...)
(dataspace I ...)
(state [B O ...] [E I ...] ...)
(background I ...)
(assert! P)
@ -52,8 +52,8 @@ value(s) of the final `I` from the `E` exit branch that was chosen
*prepended* to the values of the calling actor's variables at the time
of `state` termination.
There are four kinds of actor-spawning `I`s: `actor`, `network`,
`state` and `background`. Neither `actor`, `network` nor `background`
There are four kinds of actor-spawning `I`s: `actor`, `dataspace`,
`state` and `background`. Neither `actor`, `dataspace` nor `background`
yield a value; only `state` does so. However, both `state` and
`background` link to their invoking contexts, because `state` may
return values or crash, and `background` may crash. Actors using
@ -66,7 +66,7 @@ Q: Should exception values be transmitted on `state` failure? I think
no, but I am not sure there's a good reason why not.
Of the events, `asserted`, `retracted` and `message` require no
private-state, since the network does the book-keeping for us.
private-state, since the dataspace does the book-keeping for us.
`rising-edge`, however, needs to track the state of its predicate. If
the predicate happens to involve an `exists`, then an assertion set
must be maintained, like for a `track`.

View File

@ -12,7 +12,7 @@
update-scene
update-sprites
spawn-keyboard-integrator
2d-network)
2d-dataspace)
(require data/order)
(require data/splay-tree)
@ -31,13 +31,13 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Shared state maintained by network. Describes current window dimensions.
;; Shared state maintained by dataspace. Describes current window dimensions.
(struct window (width height) #:transparent)
;; Message sent by network. Describes frame about to be rendered.
;; Message sent by dataspace. Describes frame about to be rendered.
(struct frame-event (counter timestamp elapsed-ms target-frame-rate) #:transparent)
;; Message sent by network. Describes a key event. Key is a sealed
;; Message sent by dataspace. Describes a key event. Key is a sealed
;; key-event%. `press?` is #t when the key is pressed (or
;; autorepeated!), and #f when it is released.
(struct key-event (code press? key) #:transparent)
@ -221,7 +221,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define network-canvas%
(define dataspace-canvas%
(class canvas%
(inherit refresh with-gl-context swap-gl-buffers)
@ -243,7 +243,7 @@
(define postlude empty-instructions)
(define fullscreen? #f)
(define network (make-network boot-actions))
(define dataspace (make-dataspace boot-actions))
(define event-queue (make-queue))
(define target-frame-rate 60)
@ -266,7 +266,7 @@
(enqueue! event-queue e))
(define (deliver-event e)
(clean-transition (network-handle-event e network)))
(clean-transition (dataspace-handle-event e dataspace)))
(define (quiesce!)
(let loop ((txn #f) (need-poll? #t))
@ -275,8 +275,8 @@
(if (queue-empty? event-queue)
(when need-poll? (loop (deliver-event #f) #f))
(loop (deliver-event (dequeue! event-queue)) #t))]
[(transition new-network actions)
(set! network new-network)
[(transition new-dataspace actions)
(set! dataspace new-dataspace)
(for-each process-action! actions)
(loop #f #t)])))
@ -387,9 +387,9 @@
(super-new (style '(gl no-autoclear)))))
(define (2d-network #:width [width #f]
#:height [height #f]
. boot-actions)
(define (2d-dataspace #:width [width #f]
#:height [height #f]
. boot-actions)
(collect-garbage 'incremental)
(collect-garbage 'major)
(define frame (new frame%
@ -397,11 +397,11 @@
[label "syndicate-gl"]
[width (or width 640)]
[height (or height 480)]))
(define c (new network-canvas%
(define c (new dataspace-canvas%
[parent frame]
[boot-actions boot-actions]))
(unless (send (send (send c get-dc) get-gl-context) ok?)
(error '2d-network "OpenGL context failed to initialize"))
(error '2d-dataspace "OpenGL context failed to initialize"))
(send c focus)
(send frame show #t)
(yield 'wait))

View File

@ -77,20 +77,20 @@
(void)
(sub (frame-event ? ? ? ?) #:meta-level 1)))
(2d-network (spawn-keyboard-integrator)
(spawn-background)
;; (spawn-frame-counter)
(spawn-player-avatar)
(spawn (lambda (e s) #f)
(void)
(update-sprites (simple-sprite 0 50 50 50 50 (circle 50 "solid" "orange"))
(simple-sprite -1 60 60 50 50 (circle 50 "solid" "green"))))
(spawn (lambda (e s)
(match e
[(message _)
(transition s (assert 'stop #:meta-level 1))]
[_ #f]))
(void)
(sub (key-event #\q #t ?) #:meta-level 1))
)
(2d-dataspace (spawn-keyboard-integrator)
(spawn-background)
;; (spawn-frame-counter)
(spawn-player-avatar)
(spawn (lambda (e s) #f)
(void)
(update-sprites (simple-sprite 0 50 50 50 50 (circle 50 "solid" "orange"))
(simple-sprite -1 60 60 50 50 (circle 50 "solid" "green"))))
(spawn (lambda (e s)
(match e
[(message _)
(transition s (assert 'stop #:meta-level 1))]
[_ #f]))
(void)
(sub (key-event #\q #t ?) #:meta-level 1))
)
(exit 0)

View File

@ -1,14 +1,14 @@
#lang racket/base
;; Core implementation of Incremental Network Calculus.
;; Core implementation of Monolithic Syndicate.
(provide (struct-out message)
(except-out (struct-out quit) quit)
(struct-out quit-network)
(struct-out quit-dataspace)
(rename-out [quit <quit>])
(except-out (struct-out spawn) spawn)
(rename-out [spawn <spawn>])
(struct-out transition)
(struct-out network)
(struct-out dataspace)
(struct-out seal)
@ -46,11 +46,11 @@
scn/union
(rename-out [make-quit quit])
make-network
spawn-network
make-dataspace
spawn-dataspace
(rename-out [spawn-process spawn])
spawn/stateless
make-spawn-network
make-spawn-dataspace
transition-bind
sequence-transitions
@ -58,10 +58,10 @@
sequence-transitions0
sequence-transitions0*
network-handle-event
dataspace-handle-event
clean-transition
pretty-print-network)
pretty-print-dataspace)
(require racket/set)
(require racket/match)
@ -79,7 +79,7 @@
;; Actions ⊃ Events
(struct spawn (boot) #:prefab)
(struct quit-network () #:prefab) ;; NB. An action. Compare (quit), a Transition.
(struct quit-dataspace () #:prefab) ;; NB. An action. Compare (quit), a Transition.
;; A Behavior is a ((Option Event) Any -> Transition): a function
;; mapping an Event (or, in the #f case, a poll signal) and a
@ -89,7 +89,7 @@
;; - #f, a signal from a Process that it is inert and need not be
;; scheduled until some Event relevant to it arrives; or,
;; - a (transition Any (Constreeof Action)), a new Process state to
;; be held by its Network and a sequence of Actions for the Network
;; be held by its Dataspace and a sequence of Actions for the Dataspace
;; to take on the transitioning Process's behalf.
;; - a (quit (Option Exn) (Constreeof Action)), signalling that the
;; Process should never again be handed an event, and that any
@ -104,16 +104,16 @@
;; A Label is a PID or 'meta.
;; VM private states
(struct network (mux ;; Multiplexer
pending-action-queue ;; (Queueof (Cons Label (U Action 'quit)))
runnable-pids ;; (Setof PID)
behaviors ;; (HashTable PID Behavior)
states ;; (HashTable PID Any)
)
(struct dataspace (mux ;; Multiplexer
pending-action-queue ;; (Queueof (Cons Label (U Action 'quit)))
runnable-pids ;; (Setof PID)
behaviors ;; (HashTable PID Behavior)
states ;; (HashTable PID Any)
)
#:transparent
#:methods gen:syndicate-pretty-printable
[(define (syndicate-pretty-print w [p (current-output-port)])
(pretty-print-network w p))])
(pretty-print-dataspace w p))])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Seals are used by protocols to prevent the routing tries from
@ -124,7 +124,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (event? x) (or (scn? x) (message? x)))
(define (action? x) (or (event? x) (spawn? x) (quit-network? x)))
(define (action? x) (or (event? x) (spawn? x) (quit-dataspace? x)))
(define (prepend-at-meta pattern level)
(if (zero? level)
@ -181,8 +181,8 @@
(filter action? (flatten actions)))
(define (send-event e pid w)
(define behavior (hash-ref (network-behaviors w) pid #f))
(define old-state (hash-ref (network-states w) pid #f))
(define behavior (hash-ref (dataspace-behaviors w) pid #f))
(define old-state (hash-ref (dataspace-states w) pid #f))
(if (not behavior)
w
(begin
@ -205,16 +205,16 @@
(enqueue-actions (disable-process pid exn w) pid (list 'quit)))))))
(define (update-state w pid s)
(struct-copy network w [states (hash-set (network-states w) pid s)]))
(struct-copy dataspace w [states (hash-set (dataspace-states w) pid s)]))
(define (disable-process pid exn w)
(when exn
(log-error "Process ~a died with exception:\n~a"
(cons pid (trace-pid-stack))
(exn->string exn)))
(struct-copy network w
[behaviors (hash-remove (network-behaviors w) pid)]
[states (hash-remove (network-states w) pid)]))
(struct-copy dataspace w
[behaviors (hash-remove (dataspace-behaviors w) pid)]
[states (hash-remove (dataspace-states w) pid)]))
(define (invoke-process pid thunk k-ok k-exn)
(define-values (ok? result)
@ -228,12 +228,12 @@
(k-exn result)))
(define (mark-pid-runnable w pid)
(struct-copy network w [runnable-pids (set-add (network-runnable-pids w) pid)]))
(struct-copy dataspace w [runnable-pids (set-add (dataspace-runnable-pids w) pid)]))
(define (enqueue-actions w label actions)
(struct-copy network w
(struct-copy dataspace w
[pending-action-queue
(queue-append-list (network-pending-action-queue w)
(queue-append-list (dataspace-pending-action-queue w)
(for/list [(a actions)] (cons label a)))]))
(define (make-quit #:exception [exn #f] . actions)
@ -263,20 +263,20 @@
[(? quit? q) q]
[actions (transition state actions)]))
(define-syntax-rule (spawn-network boot-action ...)
(make-spawn-network (lambda () (list boot-action ...))))
(define-syntax-rule (spawn-dataspace boot-action ...)
(make-spawn-dataspace (lambda () (list boot-action ...))))
(define (make-network boot-actions)
(network (mux)
(list->queue (for/list ((a (in-list (clean-actions boot-actions)))) (cons 'meta a)))
(set)
(hash)
(hash)))
(define (make-dataspace boot-actions)
(dataspace (mux)
(list->queue (for/list ((a (in-list (clean-actions boot-actions)))) (cons 'meta a)))
(set)
(hash)
(hash)))
(define (make-spawn-network boot-actions-thunk)
(define (make-spawn-dataspace boot-actions-thunk)
(spawn (lambda ()
(list network-handle-event
(transition (make-network (boot-actions-thunk)) '())))))
(list dataspace-handle-event
(transition (make-dataspace (boot-actions-thunk)) '())))))
(define (transition-bind k t0)
(match t0
@ -307,10 +307,10 @@
[(? transition? t) (sequence-transitions* t rest)])]))
(define (inert? w)
(and (queue-empty? (network-pending-action-queue w))
(set-empty? (network-runnable-pids w))))
(and (queue-empty? (dataspace-pending-action-queue w))
(set-empty? (dataspace-runnable-pids w))))
(define (network-handle-event e w)
(define (dataspace-handle-event e w)
(if (or e (not (inert? w)))
(sequence-transitions (transition w '())
(inject-event e)
@ -326,8 +326,8 @@
'()))
(define (perform-actions w)
(for/fold ([wt (transition (struct-copy network w [pending-action-queue (make-queue)]) '())])
((entry (in-list (queue->list (network-pending-action-queue w)))))
(for/fold ([wt (transition (struct-copy dataspace w [pending-action-queue (make-queue)]) '())])
((entry (in-list (queue->list (dataspace-pending-action-queue w)))))
#:break (quit? wt) ;; TODO: should a quit action be delayed until the end of the turn?
(match-define [cons label a] entry)
(trace-internal-action label a (transition-state wt))
@ -351,20 +351,20 @@
(match-define (list behavior initial-transition) results)
(create-process w behavior initial-transition))
(lambda (exn)
(log-error "Spawned process in network ~a died with exception:\n~a"
(log-error "Spawned process in dataspace ~a died with exception:\n~a"
(trace-pid-stack)
(exn->string exn))
(transition w '())))]
['quit
(define-values (new-mux _label s aggregate-assertions)
(mux-remove-stream (network-mux w) label))
(mux-remove-stream (dataspace-mux w) label))
;; behavior & state in w already removed by disable-process
(deliver-scns w new-mux label s aggregate-assertions)]
[(quit-network)
[(quit-dataspace)
(make-quit)]
[(? scn? s-orig)
(define-values (new-mux _label s aggregate-assertions)
(mux-update-stream (network-mux w) label s-orig))
(mux-update-stream (dataspace-mux w) label s-orig))
(deliver-scns w new-mux label s aggregate-assertions)]
[(and m (message body))
(when (observe? body)
@ -375,7 +375,7 @@
(at-meta? body)) ;; it relates to envt, not local
(transition w (message (at-meta-claim body)))
(transition (for/fold [(w w)]
[(pid (in-list (mux-route-message (network-mux w) body)))]
[(pid (in-list (mux-route-message (dataspace-mux w) body)))]
(send-event m pid w))
'()))]))
@ -400,20 +400,20 @@
[(cons (? scn? s) rest) (values s rest)]
[other (values (scn trie-empty) other)]))
(define-values (new-mux new-pid s aggregate-assertions)
(mux-add-stream (network-mux w) initial-scn))
(let* ((w (struct-copy network w
[behaviors (hash-set (network-behaviors w)
(mux-add-stream (dataspace-mux w) initial-scn))
(let* ((w (struct-copy dataspace w
[behaviors (hash-set (dataspace-behaviors w)
new-pid
behavior)]))
(w (enqueue-actions (postprocess w new-pid) new-pid remaining-initial-actions)))
(deliver-scns w new-mux new-pid s aggregate-assertions)))))
(define (deliver-scns w new-mux acting-label s aggregate-assertions)
(define old-mux (network-mux w))
(define old-mux (dataspace-mux w))
(define old-echo-cancelled-assertions (echo-cancelled-routing-table old-mux))
(define-values (scns meta-action)
(compute-scns old-mux new-mux acting-label s aggregate-assertions))
(transition (for/fold [(w (struct-copy network w [mux new-mux]))]
(transition (for/fold [(w (struct-copy dataspace w [mux new-mux]))]
[(entry (in-list scns))]
(match-define (cons label (and event (scn new-assertions))) entry)
(if (equal? (biased-intersection old-echo-cancelled-assertions
@ -424,17 +424,17 @@
meta-action))
(define (step-children w)
(define runnable-pids (network-runnable-pids w))
(define runnable-pids (dataspace-runnable-pids w))
(if (set-empty? runnable-pids)
#f ;; network is inert.
(transition (for/fold [(w (struct-copy network w [runnable-pids (set)]))]
#f ;; dataspace is inert.
(transition (for/fold [(w (struct-copy dataspace w [runnable-pids (set)]))]
[(pid (in-set runnable-pids))]
(send-event #f pid w))
'())))
(define (pretty-print-network w [p (current-output-port)])
(match-define (network mux qs runnable behaviors states) w)
(fprintf p "NETWORK:\n")
(define (pretty-print-dataspace w [p (current-output-port)])
(match-define (dataspace mux qs runnable behaviors states) w)
(fprintf p "DATASPACE:\n")
(fprintf p " - ~a queued actions\n" (queue-length qs))
(fprintf p " - ~a runnable pids ~a\n" (set-count runnable) (set->list runnable))
(fprintf p " - ~a live processes\n" (hash-count states))
@ -460,10 +460,10 @@
(define (step* w)
(let loop ((w w) (actions '()))
(pretty-print w)
(match (network-handle-event #f w)
(match (dataspace-handle-event #f w)
[#f (values w #f (flatten actions))]
[(quit exn new-actions) (values w exn (flatten (cons actions new-actions)))]
[(transition new-w new-actions) (loop new-w (cons actions new-actions))])))
(step* (make-network '()))
(step* (make-dataspace '()))
)

View File

@ -27,8 +27,8 @@
#f)]
[_ #f]))
(spawn-network (spawn r (void) (scn (subscription ?)))
(spawn b 0 '()))
(spawn-dataspace (spawn r (void) (scn (subscription ?)))
(spawn b 0 '()))
(define (echoer e s)
(match e

View File

@ -11,7 +11,7 @@
(subscription 'die)
(subscription (observe 'die))))
(spawn-network
(spawn-dataspace
(spawn (lambda (e s)
(match e
[(message (at-meta 'die)) (quit)]

View File

@ -15,7 +15,7 @@
(require syndicate/pretty)
(spawn-network
(spawn-dataspace
(spawn (lambda (e counter)
(and e
(let ((new-counter (+ counter 1)))

View File

@ -3,7 +3,7 @@
(require syndicate/pretty)
(spawn-network
(spawn-dataspace
(spawn (lambda (e counter)
(and e
(let ((new-counter (+ counter 1)))

View File

@ -63,8 +63,8 @@
1
(scn/union (subscription (observe (set-timer ? ? ?)))
(subscription (timer-expired 'tick ?))))
(spawn-network (spawn r (void) (scn (subscription ?)))
(spawn b 0 '()))
(spawn-dataspace (spawn r (void) (scn (subscription ?)))
(spawn b 0 '()))
(spawn echoer
(void)
(scn (subscription (external-event (read-line-evt (current-input-port) 'any) ?)

View File

@ -1,5 +1,5 @@
#lang syndicate-monolithic
;; Demonstrates quit-network.
;; Demonstrates quit-dataspace.
(require (only-in racket/port read-bytes-line-evt))
@ -9,9 +9,9 @@
[(message (at-meta (at-meta (external-event _ (list #"quit")))))
(printf "Quitting just the leaf actor.\n")
(quit)]
[(message (at-meta (at-meta (external-event _ (list #"quit-network")))))
(printf "Terminating the whole network.\n")
(transition s (quit-network))]
[(message (at-meta (at-meta (external-event _ (list #"quit-dataspace")))))
(printf "Terminating the whole dataspace.\n")
(transition s (quit-dataspace))]
[_ #f]))
(void)
(scn (subscription (external-event (read-bytes-line-evt (current-input-port) 'any) ?)
@ -30,6 +30,6 @@
(void)
(sub-to-alarm)))
(printf "Type 'quit' or 'quit-network'.\n")
(spawn-network (spawn-command-listener)
(spawn-ticker))
(printf "Type 'quit' or 'quit-dataspace'.\n")
(spawn-dataspace (spawn-command-listener)
(spawn-ticker))

View File

@ -1,5 +1,5 @@
#lang racket/base
;; Breaking the infinite tower of nested Networks, connecting to the "real world" at the fracture line.
;; Breaking the infinite tower of nested Dataspaces, connecting to the "real world" at the fracture line.
(require racket/async-channel)
(require racket/set)
@ -51,7 +51,7 @@
;; Projection
;; Used to extract event descriptors and results from subscriptions
;; from the ground VM's contained Network.
;; from the ground VM's contained Dataspace.
(define event-projection (observe (external-event (?!) ?)))
;; Interests -> (Listof RacketEvent)
@ -74,10 +74,10 @@
(handle-evt (system-idle-evt) (lambda _ #f)))
;; Action* -> Void
;; Runs a ground VM, booting the outermost Network with the given Actions.
;; Runs a ground VM, booting the outermost Dataspace with the given Actions.
(define (run-ground . boot-actions)
(let await-interrupt ((inert? #f)
(w (make-network boot-actions))
(w (make-dataspace boot-actions))
(interests trie-empty))
;; (log-info "GROUND INTERESTS:\n~a" (trie->pretty-string interests))
(if (and inert? (trie-empty? interests))
@ -87,9 +87,9 @@
(current-ground-event-async-channel)
(if inert? never-evt idle-handler)
(extract-active-events interests))))
(trace-process-step e #f network-handle-event w)
(define resulting-transition (clean-transition (network-handle-event e w)))
(trace-process-step-result e #f network-handle-event w #f resulting-transition)
(trace-process-step e #f dataspace-handle-event w)
(define resulting-transition (clean-transition (dataspace-handle-event e w)))
(trace-process-step-result e #f dataspace-handle-event w #f resulting-transition)
(match resulting-transition
[#f ;; inert
(await-interrupt #t w interests)]

View File

@ -35,7 +35,7 @@
(define show-message-actions? #f)
(define show-actions? #f)
(define show-routing-table? #f)
(define network-is-boring? #t)
(define dataspace-is-boring? #t)
(define (set-stderr-trace-flags! flags-string)
(set! flags (for/set [(c flags-string)] (string->symbol (string c))))
@ -53,7 +53,7 @@
(set-flag! M show-message-actions?)
(set-flag! a show-actions?)
(set-flag! g show-routing-table?)
(set! network-is-boring? (not (set-member? flags 'N))))
(set! dataspace-is-boring? (not (set-member? flags 'N))))
(set-stderr-trace-flags! (or (getenv "MINIMART_TRACE") ""))
@ -81,7 +81,7 @@
(apply fprintf (current-error-port) fmt args))
(define (boring-state? state)
(or (and (network? state) network-is-boring?)
(or (and (dataspace? state) dataspace-is-boring?)
(void? state)))
(define (set-color! c) (when colored-output? (output "\e[0~am" c)))
@ -162,14 +162,14 @@
(syndicate-pretty-print (transition-state t) (current-error-port)))))))]
[('internal-action (list pids a old-w))
(define pidstr (format-pids pids))
(define oldcount (hash-count (network-behaviors old-w)))
(define oldcount (hash-count (dataspace-behaviors old-w)))
(match a
[(? spawn?)
;; Handle this in internal-action-result
(void)]
['quit
(when (or show-process-lifecycle? show-actions?)
(define interests (mux-interests-of (network-mux old-w) (car pids)))
(define interests (mux-interests-of (dataspace-mux old-w) (car pids)))
(with-color BRIGHT-RED
(output "~a exiting (~a total processes remain)\n"
pidstr
@ -177,9 +177,9 @@
(unless (trie-empty? interests)
(output "~a's final interests:\n" pidstr)
(pretty-print-trie interests (current-error-port))))]
[(quit-network)
[(quit-dataspace)
(with-color BRIGHT-RED
(output "Process ~a performed a quit-network.\n" pidstr))]
(output "Process ~a performed a quit-dataspace.\n" pidstr))]
[(scn r)
(when (or show-actions? show-scn-actions?)
(output "~a performing a SCN:\n" pidstr)
@ -192,15 +192,15 @@
(when (transition? t)
(define new-w (transition-state t))
(define pidstr (format-pids pids))
(define newcount (hash-count (network-behaviors new-w)))
(define newcount (hash-count (dataspace-behaviors new-w)))
(match a
[(? spawn?)
(when (or show-process-lifecycle? show-actions?)
(define newpid (mux-next-pid (network-mux old-w)))
(define newpid (mux-next-pid (dataspace-mux old-w)))
(define newpidstr (format-pids (cons newpid (cdr pids)))) ;; replace parent pid
(define interests (mux-interests-of (network-mux new-w) newpid))
(define behavior (hash-ref (network-behaviors new-w) newpid '#:missing-behavior))
(define state (hash-ref (network-states new-w) newpid '#:missing-state))
(define interests (mux-interests-of (dataspace-mux new-w) newpid))
(define behavior (hash-ref (dataspace-behaviors new-w) newpid '#:missing-behavior))
(define state (hash-ref (dataspace-states new-w) newpid '#:missing-state))
(with-color BRIGHT-GREEN
(output "~a ~v spawned from ~a (~a total processes now)\n"
newpidstr
@ -217,8 +217,8 @@
;; other cases handled in internal-action
(void)])
(when show-routing-table?
(define old-table (mux-routing-table (network-mux old-w)))
(define new-table (mux-routing-table (network-mux new-w)))
(define old-table (mux-routing-table (dataspace-mux old-w)))
(define new-table (mux-routing-table (dataspace-mux new-w)))
(when (not (equal? old-table new-table))
(with-color BRIGHT-BLUE
(output "~a's routing table:\n" (format-pids (cdr pids)))

View File

@ -1,7 +1,7 @@
#lang racket/base
(provide actor
network
dataspace
;; background
state
@ -54,8 +54,8 @@
(require racket/set)
(require racket/match)
(require (except-in "core.rkt" assert network)
(rename-in "core.rkt" [assert core:assert] [network core:network]))
(require (except-in "core.rkt" assert dataspace)
(rename-in "core.rkt" [assert core:assert] [dataspace core:dataspace]))
(require "trie.rkt")
(require "mux.rkt")
@ -84,7 +84,7 @@
;; A LinkageKind is one of
;; - 'call, a blocking, exception-linked connection
;; - 'actor, a non-blocking, non-exception-linked connection
;; - 'network, a non-blocking, nested, non-exception-linked connection
;; - 'dataspace, a non-blocking, nested, non-exception-linked connection
;;
;; Patch Instructions are issued when the actor uses `assert!` and
;; `retract!`. Action instructions are issued when the actor uses
@ -92,7 +92,7 @@
;; called. Script-complete instructions are automatically issued when
;; a Script terminates successfully.
;;
;; Spawn instructions are issued when `actor`, `network`, and `state`
;; Spawn instructions are issued when `actor`, `dataspace`, and `state`
;; are used, directly or indirectly. (TODO: `background`?) The
;; spawn-action-producing function is given the IDs of the spawned and
;; spawning actors, and is to return an action which spawns the new
@ -256,14 +256,14 @@
[(_ I ...)
(expand-state 'actor #'(I ... (return/no-link-result!)) #'() #'() #'() #'())]))
;; Spawn whole networks
(define-syntax (network stx)
;; Spawn whole dataspaces
(define-syntax (dataspace stx)
(syntax-parse stx
[(_ I ...)
(expand-state 'network
(expand-state 'dataspace
#'(I
...
(perform-core-action! (quit-network))
(perform-core-action! (quit-dataspace))
(return/no-link-result!))
#'()
#'()
@ -393,8 +393,8 @@
(transition (if blocking?
(store-continuation s callee-id get-next-instr)
s)
(if (eq? linkage-kind 'network)
(spawn-network spawn-action)
(if (eq? linkage-kind 'dataspace)
(spawn-dataspace spawn-action)
spawn-action)))))
(if blocking?
next-t
@ -415,7 +415,7 @@
;; TODO: track
;; TODO: default to hll
;; TODO: some better means of keeping track of nested network levels
;; TODO: some better means of keeping track of nested dataspace levels
(begin-for-syntax
(define-splicing-syntax-class when-pred

View File

@ -1,7 +1,7 @@
#lang racket/base
(provide big-bang-network
big-bang-network/universe
(provide big-bang-dataspace
big-bang-dataspace/universe
(struct-out window)
(struct-out to-server)
(struct-out from-server)
@ -48,7 +48,7 @@
;;---------------------------------------------------------------------------
(struct bb (network windows inbound outbound halted? x y) #:transparent)
(struct bb (dataspace windows inbound outbound halted? x y) #:transparent)
(define window-projection (?! (window ? ? ? ? ?)))
@ -74,7 +74,7 @@
#f)]))
(define (deliver b e)
(clean-transition (network-handle-event e (bb-network b))))
(clean-transition (dataspace-handle-event e (bb-dataspace b))))
(define (interpret-actions b txn need-poll?)
(match txn
@ -90,8 +90,8 @@
[(cons e rest)
(let ((b (struct-copy bb b [inbound rest])))
(interpret-actions b (deliver b e) #t))])]
[(transition new-network actions)
(let process-actions ((b (struct-copy bb b [network new-network])) (actions actions))
[(transition new-dataspace actions)
(let process-actions ((b (struct-copy bb b [dataspace new-dataspace])) (actions actions))
(match actions
['() (interpret-actions b #f #t)]
[(cons a actions)
@ -128,8 +128,8 @@
(patch-seq (retract (active-window ?))
(assert (active-window active-id))))
(define-syntax-rule (big-bang-network* boot-actions extra-clause ...)
(big-bang (interpret-actions (bb (make-network boot-actions)
(define-syntax-rule (big-bang-dataspace* boot-actions extra-clause ...)
(big-bang (interpret-actions (bb (make-dataspace boot-actions)
'()
'()
'()
@ -155,25 +155,25 @@
(stop-when bb-halted?)
extra-clause ...))
(define-syntax-rule (big-bang-network** width height boot-actions extra-clause ...)
(define-syntax-rule (big-bang-dataspace** width height boot-actions extra-clause ...)
(if (and width height)
(big-bang-network* boot-actions (to-draw render width height) extra-clause ...)
(big-bang-network* boot-actions (to-draw render) extra-clause ...)))
(big-bang-dataspace* boot-actions (to-draw render width height) extra-clause ...)
(big-bang-dataspace* boot-actions (to-draw render) extra-clause ...)))
(define (big-bang-network #:width [width #f]
#:height [height #f]
. boot-actions)
(big-bang-network** width height boot-actions))
(define (big-bang-dataspace #:width [width #f]
#:height [height #f]
. boot-actions)
(big-bang-dataspace** width height boot-actions))
(define (big-bang-network/universe #:width [width #f]
#:height [height #f]
#:register [ip LOCALHOST]
#:port [port-number SQPORT]
#:name [world-name (gensym 'syndicate)]
. boot-actions)
(big-bang-network** width height boot-actions
(on-receive (lambda (b sexps)
(inject b (for/list ((m sexps)) (message (from-server m))))))
(register ip)
(port port-number)
(name world-name)))
(define (big-bang-dataspace/universe #:width [width #f]
#:height [height #f]
#:register [ip LOCALHOST]
#:port [port-number SQPORT]
#:name [world-name (gensym 'syndicate)]
. boot-actions)
(big-bang-dataspace** width height boot-actions
(on-receive (lambda (b sexps)
(inject b (for/list ((m sexps)) (message (from-server m))))))
(register ip)
(port port-number)
(name world-name)))

View File

@ -1,14 +1,14 @@
#lang racket/base
;; Core implementation of Incremental Network Calculus.
;; Core implementation of Incremental Syndicate.
(provide (struct-out message)
(except-out (struct-out quit) quit)
(struct-out quit-network)
(struct-out quit-dataspace)
(rename-out [quit <quit>])
(except-out (struct-out spawn) spawn)
(rename-out [spawn <spawn>])
(struct-out transition)
(struct-out network)
(struct-out dataspace)
(struct-out seal)
@ -46,11 +46,11 @@
unpub
(rename-out [make-quit quit])
make-network
spawn-network
make-dataspace
spawn-dataspace
(rename-out [spawn-process spawn])
spawn/stateless
make-spawn-network
make-spawn-dataspace
transition-bind
sequence-transitions
@ -58,10 +58,10 @@
sequence-transitions0
sequence-transitions0*
network-handle-event
dataspace-handle-event
clean-transition
pretty-print-network)
pretty-print-dataspace)
(require racket/set)
(require racket/match)
@ -79,7 +79,7 @@
;; Actions ⊃ Events
(struct spawn (boot) #:prefab)
(struct quit-network () #:prefab) ;; NB. An action. Compare (quit), a Transition.
(struct quit-dataspace () #:prefab) ;; NB. An action. Compare (quit), a Transition.
;; A Behavior is a ((Option Event) Any -> Transition): a function
;; mapping an Event (or, in the #f case, a poll signal) and a
@ -89,7 +89,7 @@
;; - #f, a signal from a Process that it is inert and need not be
;; scheduled until some Event relevant to it arrives; or,
;; - a (transition Any (Constreeof Action)), a new Process state to
;; be held by its Network and a sequence of Actions for the Network
;; be held by its Dataspace and a sequence of Actions for the Dataspace
;; to take on the transitioning Process's behalf.
;; - a (quit (Option Exn) (Constreeof Action)), signalling that the
;; Process should never again be handed an event, and that any
@ -104,16 +104,16 @@
;; A Label is a PID or 'meta.
;; VM private states
(struct network (mux ;; Multiplexer
pending-action-queue ;; (Queueof (Cons Label (U Action 'quit)))
runnable-pids ;; (Setof PID)
behaviors ;; (HashTable PID Behavior)
states ;; (HashTable PID Any)
)
(struct dataspace (mux ;; Multiplexer
pending-action-queue ;; (Queueof (Cons Label (U Action 'quit)))
runnable-pids ;; (Setof PID)
behaviors ;; (HashTable PID Behavior)
states ;; (HashTable PID Any)
)
#:transparent
#:methods gen:syndicate-pretty-printable
[(define (syndicate-pretty-print w [p (current-output-port)])
(pretty-print-network w p))])
(pretty-print-dataspace w p))])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Seals are used by protocols to prevent the routing tries from
@ -124,7 +124,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (event? x) (or (patch? x) (message? x)))
(define (action? x) (or (event? x) (spawn? x) (quit-network? x)))
(define (action? x) (or (event? x) (spawn? x) (quit-dataspace? x)))
(define-syntax-rule (match-event e clause ...)
(match e
@ -178,8 +178,8 @@
(filter (lambda (x) (and (action? x) (not (patch-empty? x)))) (flatten actions)))
(define (send-event e pid w)
(define behavior (hash-ref (network-behaviors w) pid #f))
(define old-state (hash-ref (network-states w) pid #f))
(define behavior (hash-ref (dataspace-behaviors w) pid #f))
(define old-state (hash-ref (dataspace-states w) pid #f))
(if (not behavior)
w
(begin
@ -202,7 +202,7 @@
(enqueue-actions (disable-process pid exn w) pid (list 'quit)))))))
(define (update-state w pid s)
(struct-copy network w [states (hash-set (network-states w) pid s)]))
(struct-copy dataspace w [states (hash-set (dataspace-states w) pid s)]))
(define (send-event/guard delta pid w)
(if (patch-empty? delta)
@ -214,9 +214,9 @@
(log-error "Process ~a died with exception:\n~a"
(cons pid (trace-pid-stack))
(exn->string exn)))
(struct-copy network w
[behaviors (hash-remove (network-behaviors w) pid)]
[states (hash-remove (network-states w) pid)]))
(struct-copy dataspace w
[behaviors (hash-remove (dataspace-behaviors w) pid)]
[states (hash-remove (dataspace-states w) pid)]))
(define (invoke-process pid thunk k-ok k-exn)
(define-values (ok? result)
@ -230,12 +230,12 @@
(k-exn result)))
(define (mark-pid-runnable w pid)
(struct-copy network w [runnable-pids (set-add (network-runnable-pids w) pid)]))
(struct-copy dataspace w [runnable-pids (set-add (dataspace-runnable-pids w) pid)]))
(define (enqueue-actions w label actions)
(struct-copy network w
(struct-copy dataspace w
[pending-action-queue
(queue-append-list (network-pending-action-queue w)
(queue-append-list (dataspace-pending-action-queue w)
(for/list [(a actions)] (cons label a)))]))
(define (make-quit #:exception [exn #f] . actions)
@ -265,20 +265,20 @@
[(? quit? q) q]
[actions (transition state actions)]))
(define-syntax-rule (spawn-network boot-action ...)
(make-spawn-network (lambda () (list boot-action ...))))
(define-syntax-rule (spawn-dataspace boot-action ...)
(make-spawn-dataspace (lambda () (list boot-action ...))))
(define (make-network boot-actions)
(network (mux)
(list->queue (for/list ((a (in-list (clean-actions boot-actions)))) (cons 'meta a)))
(set)
(hash)
(hash)))
(define (make-dataspace boot-actions)
(dataspace (mux)
(list->queue (for/list ((a (in-list (clean-actions boot-actions)))) (cons 'meta a)))
(set)
(hash)
(hash)))
(define (make-spawn-network boot-actions-thunk)
(define (make-spawn-dataspace boot-actions-thunk)
(spawn (lambda ()
(list network-handle-event
(transition (make-network (boot-actions-thunk)) '())))))
(list dataspace-handle-event
(transition (make-dataspace (boot-actions-thunk)) '())))))
(define (transition-bind k t0)
(match t0
@ -309,10 +309,10 @@
[(? transition? t) (sequence-transitions* t rest)])]))
(define (inert? w)
(and (queue-empty? (network-pending-action-queue w))
(set-empty? (network-runnable-pids w))))
(and (queue-empty? (dataspace-pending-action-queue w))
(set-empty? (dataspace-runnable-pids w))))
(define (network-handle-event e w)
(define (dataspace-handle-event e w)
(if (or e (not (inert? w)))
(sequence-transitions (transition w '())
(inject-event e)
@ -328,8 +328,8 @@
'()))
(define (perform-actions w)
(for/fold ([wt (transition (struct-copy network w [pending-action-queue (make-queue)]) '())])
((entry (in-list (queue->list (network-pending-action-queue w)))))
(for/fold ([wt (transition (struct-copy dataspace w [pending-action-queue (make-queue)]) '())])
((entry (in-list (queue->list (dataspace-pending-action-queue w)))))
#:break (quit? wt) ;; TODO: should a quit action be delayed until the end of the turn?
(match-define [cons label a] entry)
(trace-internal-action label a (transition-state wt))
@ -353,20 +353,20 @@
(match-define (list behavior initial-transition) results)
(create-process w behavior initial-transition))
(lambda (exn)
(log-error "Spawned process in network ~a died with exception:\n~a"
(log-error "Spawned process in dataspace ~a died with exception:\n~a"
(trace-pid-stack)
(exn->string exn))
(transition w '())))]
['quit
(define-values (new-mux _label delta delta-aggregate)
(mux-remove-stream (network-mux w) label))
(mux-remove-stream (dataspace-mux w) label))
;; behavior & state in w already removed by disable-process
(deliver-patches w new-mux label delta delta-aggregate)]
[(quit-network)
[(quit-dataspace)
(make-quit)]
[(? patch? delta-orig)
(define-values (new-mux _label delta delta-aggregate)
(mux-update-stream (network-mux w) label delta-orig))
(mux-update-stream (dataspace-mux w) label delta-orig))
(deliver-patches w new-mux label delta delta-aggregate)]
[(and m (message body))
(when (observe? body)
@ -377,7 +377,7 @@
(at-meta? body)) ;; it relates to envt, not local
(transition w (message (at-meta-claim body)))
(transition (for/fold [(w w)]
[(pid (in-list (mux-route-message (network-mux w) body)))]
[(pid (in-list (mux-route-message (dataspace-mux w) body)))]
(send-event m pid w))
'()))]))
@ -402,9 +402,9 @@
[(cons (? patch? p) rest) (values p rest)]
[other (values patch-empty other)]))
(define-values (new-mux new-pid delta delta-aggregate)
(mux-add-stream (network-mux w) initial-patch))
(let* ((w (struct-copy network w
[behaviors (hash-set (network-behaviors w)
(mux-add-stream (dataspace-mux w) initial-patch))
(let* ((w (struct-copy dataspace w
[behaviors (hash-set (dataspace-behaviors w)
new-pid
behavior)]))
(w (enqueue-actions (postprocess w new-pid) new-pid remaining-initial-actions)))
@ -412,25 +412,25 @@
(define (deliver-patches w new-mux acting-label delta delta-aggregate)
(define-values (patches meta-action)
(compute-patches (network-mux w) new-mux acting-label delta delta-aggregate))
(transition (for/fold [(w (struct-copy network w [mux new-mux]))]
(compute-patches (dataspace-mux w) new-mux acting-label delta delta-aggregate))
(transition (for/fold [(w (struct-copy dataspace w [mux new-mux]))]
[(entry (in-list patches))]
(match-define (cons label event) entry)
(send-event/guard event label w))
meta-action))
(define (step-children w)
(define runnable-pids (network-runnable-pids w))
(define runnable-pids (dataspace-runnable-pids w))
(if (set-empty? runnable-pids)
#f ;; network is inert.
(transition (for/fold [(w (struct-copy network w [runnable-pids (set)]))]
#f ;; dataspace is inert.
(transition (for/fold [(w (struct-copy dataspace w [runnable-pids (set)]))]
[(pid (in-set runnable-pids))]
(send-event #f pid w))
'())))
(define (pretty-print-network w [p (current-output-port)])
(match-define (network mux qs runnable behaviors states) w)
(fprintf p "NETWORK:\n")
(define (pretty-print-dataspace w [p (current-output-port)])
(match-define (dataspace mux qs runnable behaviors states) w)
(fprintf p "DATASPACE:\n")
(fprintf p " - ~a queued actions\n" (queue-length qs))
(fprintf p " - ~a runnable pids ~a\n" (set-count runnable) (set->list runnable))
(fprintf p " - ~a live processes\n" (hash-count states))
@ -456,10 +456,10 @@
(define (step* w)
(let loop ((w w) (actions '()))
(pretty-print w)
(match (network-handle-event #f w)
(match (dataspace-handle-event #f w)
[#f (values w #f (flatten actions))]
[(quit exn new-actions) (values w exn (flatten (cons actions new-actions)))]
[(transition new-w new-actions) (loop new-w (cons actions new-actions))])))
(step* (make-network '()))
(step* (make-dataspace '()))
)

View File

@ -37,7 +37,7 @@
;; that are coming from the background thread.
;;
;; The race cannot occur in the sequential implementation
;; because the network makes sure to enqueue the transition
;; because the dataspace makes sure to enqueue the transition
;; actions resulting from the set-timer message delivery ahead
;; of any enqueueing of the timer-expired ground message, so
;; that by the time the ground message is processed, the

View File

@ -31,7 +31,7 @@
(send! (says user (string-trim (bytes->string/utf-8 bs))))))))
(spawn-tcp-driver)
(network (define us (tcp-listener 5999))
(forever (assert (advertise (observe (tcp-channel _ us _))) #:meta-level 1)
(on (asserted (advertise (tcp-channel $them us _)) #:meta-level 1)
(spawn-session them us))))
(dataspace (define us (tcp-listener 5999))
(forever (assert (advertise (observe (tcp-channel _ us _))) #:meta-level 1)
(on (asserted (advertise (tcp-channel $them us _)) #:meta-level 1)
(spawn-session them us))))

View File

@ -30,13 +30,13 @@
(assert (advertise (tcp-channel us them _)) #:meta-level 1)
(on (message (tcp-channel them us $bs) #:meta-level 1)
(define input-string (string-trim (bytes->string/utf-8 bs)))
(if (equal? input-string "quit-network")
(if (equal? input-string "quit-dataspace")
(send! (shutdown))
(send! (says user input-string)))))))
(spawn-tcp-driver)
(network (define us (tcp-listener 5999))
(until (message (shutdown))
(assert (advertise (observe (tcp-channel _ us _))) #:meta-level 1)
(on (asserted (advertise (tcp-channel $them us _)) #:meta-level 1)
(spawn-session them us))))
(dataspace (define us (tcp-listener 5999))
(until (message (shutdown))
(assert (advertise (observe (tcp-channel _ us _))) #:meta-level 1)
(on (asserted (advertise (tcp-channel $them us _)) #:meta-level 1)
(spawn-session them us))))

View File

@ -50,21 +50,21 @@
(mouse-sub name)
(move-to orig-x orig-y))))
(big-bang-network #:width 640
#:height 480
(spawn (lambda (e s)
(match e
[(? patch? p)
(define-values (in out)
(patch-project/set/single p (at-meta (?! (active-window ?)))))
(transition s (update-window 'active-window-label 300 0
(text (format "~v" in) 22 "black")))]
[_ #f]))
(void)
(sub (active-window ?) #:meta-level 1))
(button #:background "red" 'stop-button 0 0 "Exit"
(lambda () (assert 'stop #:meta-level 1)))
(draggable-shape 'c1 50 50 (circle 30 "solid" "orange"))
(draggable-shape 's1 100 100 (star 40 "solid" "firebrick")))
(big-bang-dataspace #:width 640
#:height 480
(spawn (lambda (e s)
(match e
[(? patch? p)
(define-values (in out)
(patch-project/set/single p (at-meta (?! (active-window ?)))))
(transition s (update-window 'active-window-label 300 0
(text (format "~v" in) 22 "black")))]
[_ #f]))
(void)
(sub (active-window ?) #:meta-level 1))
(button #:background "red" 'stop-button 0 0 "Exit"
(lambda () (assert 'stop #:meta-level 1)))
(draggable-shape 'c1 50 50 (circle 30 "solid" "orange"))
(draggable-shape 's1 100 100 (star 40 "solid" "firebrick")))
(exit 0)

View File

@ -37,7 +37,7 @@
))))
(spawn-tcp-driver)
(spawn-network
(spawn-dataspace
(spawn-demand-matcher (advertise (tcp-channel (?!) (?! (tcp-listener 5999)) ?))
(observe (tcp-channel (?!) (?! (tcp-listener 5999)) ?))
#:meta-level 1

View File

@ -18,8 +18,8 @@
(match e
[(message (at-meta (tcp-channel _ _ bs)))
(define input-string (string-trim (bytes->string/utf-8 bs)))
(if (equal? input-string "quit-network")
(quit-network)
(if (equal? input-string "quit-dataspace")
(quit-dataspace)
(message `(,user says ,input-string)))]
[(message `(,who says ,what))
(say who "says: ~a" what)]
@ -40,7 +40,7 @@
))))
(spawn-tcp-driver)
(spawn-network
(spawn-dataspace
(spawn-demand-matcher (advertise (tcp-channel (?!) (?! (tcp-listener 5999)) ?))
(observe (tcp-channel (?!) (?! (tcp-listener 5999)) ?))
#:meta-level 1

View File

@ -27,8 +27,8 @@
#f)]
[_ #f]))
(spawn-network (spawn r (void) (sub ?))
(spawn b 0 '()))
(spawn-dataspace (spawn r (void) (sub ?))
(spawn b 0 '()))
(define (echoer e s)
(match e

View File

@ -10,7 +10,7 @@
(patch-seq (sub 'die)
(sub (observe 'die))))
(spawn-network
(spawn-dataspace
(spawn (lambda (e s)
(match e
[(message (at-meta 'die)) (quit)]

View File

@ -2,7 +2,7 @@
;; Analogous to nc-incremental-meta-drop.rkt in the Redex model.
;; Demonstrates (hopefully) correct processing of meta-interests when dropping a patch.
(spawn-network
(spawn-dataspace
(spawn (lambda (e u)
(match u
[0 (transition 1 '())]

View File

@ -15,7 +15,7 @@
(require syndicate/pretty)
(spawn-network
(spawn-dataspace
(spawn (lambda (e counter)
(and e
(let ((new-counter (+ counter 1)))

View File

@ -3,7 +3,7 @@
(require syndicate/pretty)
(spawn-network
(spawn-dataspace
(spawn (lambda (e counter)
(and e
(let ((new-counter (+ counter 1)))

View File

@ -63,8 +63,8 @@
1
(patch-seq (sub (observe (set-timer ? ? ?)))
(sub (timer-expired 'tick ?))))
(spawn-network (spawn r (void) (sub ?))
(spawn b 0 '()))
(spawn-dataspace (spawn r (void) (sub ?))
(spawn b 0 '()))
(spawn echoer
(void)
(sub (external-event (read-line-evt (current-input-port) 'any) ?)

View File

@ -1,5 +1,5 @@
#lang syndicate
;; Demonstrates quit-network.
;; Demonstrates quit-dataspace.
(require (only-in racket/port read-bytes-line-evt))
@ -9,9 +9,9 @@
[(message (at-meta (at-meta (external-event _ (list #"quit")))))
(printf "Quitting just the leaf actor.\n")
(quit)]
[(message (at-meta (at-meta (external-event _ (list #"quit-network")))))
(printf "Terminating the whole network.\n")
(transition s (quit-network))]
[(message (at-meta (at-meta (external-event _ (list #"quit-dataspace")))))
(printf "Terminating the whole dataspace.\n")
(transition s (quit-dataspace))]
[_ #f]))
(void)
(sub (external-event (read-bytes-line-evt (current-input-port) 'any) ?)
@ -31,6 +31,6 @@
(void)
(sub-to-alarm)))
(printf "Type 'quit' or 'quit-network'.\n")
(spawn-network (spawn-command-listener)
(spawn-ticker))
(printf "Type 'quit' or 'quit-dataspace'.\n")
(spawn-dataspace (spawn-command-listener)
(spawn-ticker))

View File

@ -2,7 +2,7 @@
;; Demonstrate almost-wildcard assertions.
;; One actor subscribes to everything - and so initially sees itself.
;; The other advertises everything except subscriptions and at-meta assertions.
;; The first actor's aggregate view of the network then includes everything
;; The first actor's aggregate view of the dataspace then includes everything
;; except at-meta assertions.
(require syndicate/pretty)

View File

@ -1,5 +1,5 @@
#lang racket/base
;; Breaking the infinite tower of nested Networks, connecting to the "real world" at the fracture line.
;; Breaking the infinite tower of nested Dataspaces, connecting to the "real world" at the fracture line.
(require racket/async-channel)
(require racket/set)
@ -51,7 +51,7 @@
;; Projection
;; Used to extract event descriptors and results from subscriptions
;; from the ground VM's contained Network.
;; from the ground VM's contained Dataspace.
(define event-projection (observe (external-event (?!) ?)))
;; Interests -> (Listof RacketEvent)
@ -74,10 +74,10 @@
(handle-evt (system-idle-evt) (lambda _ #f)))
;; Action* -> Void
;; Runs a ground VM, booting the outermost Network with the given Actions.
;; Runs a ground VM, booting the outermost Dataspace with the given Actions.
(define (run-ground . boot-actions)
(let await-interrupt ((inert? #f)
(w (make-network boot-actions))
(w (make-dataspace boot-actions))
(interests trie-empty))
;; (log-info "GROUND INTERESTS:\n~a" (trie->pretty-string interests))
(if (and inert? (trie-empty? interests))
@ -87,9 +87,9 @@
(current-ground-event-async-channel)
(if inert? never-evt idle-handler)
(extract-active-events interests))))
(trace-process-step e #f network-handle-event w)
(define resulting-transition (clean-transition (network-handle-event e w)))
(trace-process-step-result e #f network-handle-event w #f resulting-transition)
(trace-process-step e #f dataspace-handle-event w)
(define resulting-transition (clean-transition (dataspace-handle-event e w)))
(trace-process-step-result e #f dataspace-handle-event w #f resulting-transition)
(match resulting-transition
[#f ;; inert
(await-interrupt #t w interests)]

View File

@ -14,15 +14,15 @@
Spawns an actor that executes each instantaneous action @racket[I] in
sequence.}
@defform[(network I ...)]{
Spawns a network as a child of the network enclosing the executing actor. The
new network executes each instantaneous action @racket[I].}
@defform[(dataspace I ...)]{
Spawns a dataspace as a child of the dataspace enclosing the executing actor. The
new dataspace executes each instantaneous action @racket[I].}
@defproc[(send! [v any/c]
[#:meta-level level natural-number/c 0])
void?]{
Sends a message with body @racket[v]. The message is sent @racket[level]
networks removed from the network containing the actor performing the
dataspaces removed from the dataspace containing the actor performing the
@racket[send!].}
@defproc[(assert! [v any/c]
@ -30,14 +30,14 @@ networks removed from the network containing the actor performing the
void?]{
Asserts the value of @racket[v] until either explicitly retracted via
@racket[retract!] or the immediately enclosing actor exits. @racket[level]
specifies which network the assertion should be made, in terms of relative
distance from the network containing the enclosing actor.}
specifies which dataspace the assertion should be made, in terms of relative
distance from the dataspace containing the enclosing actor.}
@defproc[(retract! [v any/c]
[#:meta-level level natural-number/c 0])
void?]{
Retracts any assertions made by the immediately enclosing actor at
@racket[level] networks above the enclosing network of the form @racket[v].}
@racket[level] dataspaces above the enclosing dataspace of the form @racket[v].}
@section{Ongoing Behaviors (O)}

View File

@ -46,10 +46,10 @@
(exn->string exn)))
(record-trace-event 'process-step-result (list (cons-pid pid) e beh st exn t)))
;; (Option PID) Action Network -> Void
;; (Option PID) Action Dataspace -> Void
(define (trace-internal-action pid a w)
(record-trace-event 'internal-action (list (cons-pid pid) a w)))
;; (Option PID) Action Network Transition -> Void
;; (Option PID) Action Dataspace Transition -> Void
(define (trace-internal-action-result pid a w t)
(record-trace-event 'internal-action-result (list (cons-pid pid) a w t)))

View File

@ -36,7 +36,7 @@
(define show-message-actions? #f)
(define show-actions? #f)
(define show-routing-table? #f)
(define network-is-boring? #t)
(define dataspace-is-boring? #t)
(define (set-stderr-trace-flags! flags-string)
(set! flags (for/set [(c flags-string)] (string->symbol (string c))))
@ -54,7 +54,7 @@
(set-flag! M show-message-actions?)
(set-flag! a show-actions?)
(set-flag! g show-routing-table?)
(set! network-is-boring? (not (set-member? flags 'N))))
(set! dataspace-is-boring? (not (set-member? flags 'N))))
(set-stderr-trace-flags! (or (getenv "MINIMART_TRACE") ""))
@ -82,7 +82,7 @@
(apply fprintf (current-error-port) fmt args))
(define (boring-state? state)
(or (and (network? state) network-is-boring?)
(or (and (dataspace? state) dataspace-is-boring?)
(void? state)))
(define (set-color! c) (when colored-output? (output "\e[0~am" c)))
@ -163,14 +163,14 @@
(syndicate-pretty-print (transition-state t) (current-error-port)))))))]
[('internal-action (list pids a old-w))
(define pidstr (format-pids pids))
(define oldcount (hash-count (network-behaviors old-w)))
(define oldcount (hash-count (dataspace-behaviors old-w)))
(match a
[(? spawn?)
;; Handle this in internal-action-result
(void)]
['quit
(when (or show-process-lifecycle? show-actions?)
(define interests (mux-interests-of (network-mux old-w) (car pids)))
(define interests (mux-interests-of (dataspace-mux old-w) (car pids)))
(with-color BRIGHT-RED
(output "~a exiting (~a total processes remain)\n"
pidstr
@ -178,9 +178,9 @@
(unless (trie-empty? interests)
(output "~a's final interests:\n" pidstr)
(pretty-print-trie interests (current-error-port))))]
[(quit-network)
[(quit-dataspace)
(with-color BRIGHT-RED
(output "Process ~a performed a quit-network.\n" pidstr))]
(output "Process ~a performed a quit-dataspace.\n" pidstr))]
[(? patch? p)
(when (or show-actions? show-patch-actions?)
(output "~a performing a patch:\n" pidstr)
@ -193,15 +193,15 @@
(when (transition? t)
(define new-w (transition-state t))
(define pidstr (format-pids pids))
(define newcount (hash-count (network-behaviors new-w)))
(define newcount (hash-count (dataspace-behaviors new-w)))
(match a
[(? spawn?)
(when (or show-process-lifecycle? show-actions?)
(define newpid (mux-next-pid (network-mux old-w)))
(define newpid (mux-next-pid (dataspace-mux old-w)))
(define newpidstr (format-pids (cons newpid (cdr pids)))) ;; replace parent pid
(define interests (mux-interests-of (network-mux new-w) newpid))
(define behavior (hash-ref (network-behaviors new-w) newpid '#:missing-behavior))
(define state (hash-ref (network-states new-w) newpid '#:missing-state))
(define interests (mux-interests-of (dataspace-mux new-w) newpid))
(define behavior (hash-ref (dataspace-behaviors new-w) newpid '#:missing-behavior))
(define state (hash-ref (dataspace-states new-w) newpid '#:missing-state))
(with-color BRIGHT-GREEN
(output "~a ~v spawned from ~a (~a total processes now)\n"
newpidstr
@ -218,8 +218,8 @@
;; other cases handled in internal-action
(void)])
(when show-routing-table?
(define old-table (mux-routing-table (network-mux old-w)))
(define new-table (mux-routing-table (network-mux new-w)))
(define old-table (mux-routing-table (dataspace-mux old-w)))
(define new-table (mux-routing-table (dataspace-mux new-w)))
(when (not (equal? old-table new-table))
(with-color BRIGHT-BLUE
(output "~a's routing table:\n" (format-pids (cdr pids)))