From a8b7de0d64d0d1f0b92d025455debed9932cdc4c Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 19 Mar 2016 15:06:07 -0400 Subject: [PATCH] Support gaining access to the ground object --- js/compiler/compiler.js | 9 +++++++-- js/compiler/syndicate.ohm | 4 ++-- js/src/ground.js | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/js/compiler/compiler.js b/js/compiler/compiler.js index 66616a1..cd65c43 100644 --- a/js/compiler/compiler.js +++ b/js/compiler/compiler.js @@ -86,8 +86,13 @@ var modifiedSourceActions = { return buildActor(ctorExp.asES5, block); }, - NetworkStatement_ground: function(_ground, _network, block) { - return 'new Syndicate.Ground(function () ' + block.asES5 + ').startStepping();'; + NetworkStatement_ground: function(_ground, _network, maybeId, block) { + var code = 'new Syndicate.Ground(function () ' + block.asES5 + ').startStepping();'; + if (maybeId.numChildren === 1) { + return 'var ' + maybeId.children[0].interval.contents + ' = ' + code; + } else { + return code; + } }, NetworkStatement_normal: function(_network, block) { return 'Syndicate.Network.spawn(new Network(function () ' + block.asES5 + '));'; diff --git a/js/compiler/syndicate.ohm b/js/compiler/syndicate.ohm index 56a3ecb..f6e1106 100644 --- a/js/compiler/syndicate.ohm +++ b/js/compiler/syndicate.ohm @@ -18,8 +18,8 @@ Syndicate <: ES5 { | actor Block -- noConstructor NetworkStatement - = ground network Block -- ground - | network Block -- normal + = ground network identifier? Block -- ground + | network Block -- normal ActorFacetStatement = state FacetBlock until FacetStateTransitionBlock -- state diff --git a/js/src/ground.js b/js/src/ground.js index 9fc0cd6..a6ea0a9 100644 --- a/js/src/ground.js +++ b/js/src/ground.js @@ -37,6 +37,7 @@ Ground.prototype.startStepping = function () { self.startStepping(); }, 0); } + return this; // because the syndicatec compiler chains startStepping after the ctor }; Ground.prototype.stopStepping = function () {