From efc444ac37643b774e918cd1ba483a5c13761f46 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 10 May 2016 18:49:12 -0400 Subject: [PATCH] forever => react, state => react, init => do, done => finally, until => react until --- js/compiler/compiler.js | 2 +- js/compiler/demo-bankaccount.js | 10 +++++----- js/compiler/demo-filesystem.js | 12 +++++------ js/compiler/syndicate.ohm | 15 ++++++-------- js/examples/button/index.js | 2 +- js/examples/chat/index.js | 6 +++--- js/examples/iot/index.js | 32 +++++++++++++++--------------- js/examples/smoketest-dsl/index.js | 8 ++++---- js/examples/svg/index.js | 2 +- js/examples/textfield-dsl/index.js | 6 +++--- 10 files changed, 46 insertions(+), 49 deletions(-) diff --git a/js/compiler/compiler.js b/js/compiler/compiler.js index 0ce2aae..1e81092 100644 --- a/js/compiler/compiler.js +++ b/js/compiler/compiler.js @@ -101,7 +101,7 @@ var modifiedSourceActions = { ActorFacetStatement_state: function(_state, facetBlock, _until, transitionBlock) { return buildFacet(facetBlock, transitionBlock); }, - ActorFacetStatement_until: function(_until, transitionBlock) { + ActorFacetStatement_until: function(_react, _until, transitionBlock) { return buildFacet(null, transitionBlock); }, ActorFacetStatement_forever: function(_forever, facetBlock) { diff --git a/js/compiler/demo-bankaccount.js b/js/compiler/demo-bankaccount.js index 83c3cc2..621b3e1 100644 --- a/js/compiler/demo-bankaccount.js +++ b/js/compiler/demo-bankaccount.js @@ -9,7 +9,7 @@ ground dataspace { actor { this.balance = 0; - forever { + react { assert account(this.balance); on message deposit($amount) { this.balance += amount; @@ -18,7 +18,7 @@ ground dataspace { } actor { - forever { + react { on asserted account($balance) { console.log("Balance is now", balance); } @@ -26,11 +26,11 @@ ground dataspace { } actor { - state { - init { + react { + do { console.log("Waiting for account."); } - done { + finally { console.log("Account became ready."); } } until { diff --git a/js/compiler/demo-filesystem.js b/js/compiler/demo-filesystem.js index 4cd54ab..6e6840f 100644 --- a/js/compiler/demo-filesystem.js +++ b/js/compiler/demo-filesystem.js @@ -12,13 +12,13 @@ ground dataspace { actor { this.files = {}; - forever { + react { during Syndicate.observe(file($name, _)) { - init { + do { console.log("At least one reader exists for:", name); } assert file(name, this.files[name]); - done { + finally { console.log("No remaining readers exist for:", name); } } @@ -35,7 +35,7 @@ ground dataspace { // A simple demo client of the file system actor { - state { + react { on asserted file("hello.txt", $content) { console.log("hello.txt has content", JSON.stringify(content)); } @@ -45,7 +45,7 @@ ground dataspace { } } - until { + react until { case asserted Syndicate.observe(saveFile(_, _)) { :: saveFile("hello.txt", "a"); :: deleteFile("hello.txt"); @@ -53,7 +53,7 @@ ground dataspace { :: saveFile("hello.txt", "quit demo"); :: saveFile("hello.txt", "final contents"); actor { - until { + react until { case asserted file("hello.txt", $content) { console.log("second observer sees that hello.txt content is", JSON.stringify(content)); diff --git a/js/compiler/syndicate.ohm b/js/compiler/syndicate.ohm index d52f5e0..1bc0a01 100644 --- a/js/compiler/syndicate.ohm +++ b/js/compiler/syndicate.ohm @@ -22,9 +22,9 @@ Syndicate <: ES5 { | dataspace Block -- normal ActorFacetStatement - = state FacetBlock until FacetStateTransitionBlock -- state - | until FacetStateTransitionBlock -- until - | forever FacetBlock -- forever + = react FacetBlock until FacetStateTransitionBlock -- state + | react until FacetStateTransitionBlock -- until + | react FacetBlock -- forever AssertionTypeDeclarationStatement = assertion type identifier "(" FormalParameterList ")" ("=" stringLiteral)? #(sc) @@ -37,8 +37,8 @@ Syndicate <: ES5 { FacetBlock = "{" FacetInitBlock? FacetSituation* FacetDoneBlock? "}" FacetStateTransitionBlock = "{" FacetStateTransition* "}" - FacetInitBlock = init Block - FacetDoneBlock = done Block + FacetInitBlock = do Block + FacetDoneBlock = finally Block FacetSituation = assert FacetPattern AssertWhenClause? #(sc) -- assert @@ -74,16 +74,13 @@ Syndicate <: ES5 { asserted = "asserted" ~identifierPart assertion = "assertion" ~identifierPart dataspace = "dataspace" ~identifierPart - done = "done" ~identifierPart during = "during" ~identifierPart - forever = "forever" ~identifierPart ground = "ground" ~identifierPart - init = "init" ~identifierPart message = "message" ~identifierPart metalevel = "metalevel" ~identifierPart on = "on" ~identifierPart + react = "react" ~identifierPart retracted = "retracted" ~identifierPart - state = "state" ~identifierPart type = "type" ~identifierPart until = "until" ~identifierPart when = "when" ~identifierPart diff --git a/js/examples/button/index.js b/js/examples/button/index.js index 7b6bfee..f9ad9bd 100644 --- a/js/examples/button/index.js +++ b/js/examples/button/index.js @@ -8,7 +8,7 @@ $(document).ready(function() { actor { this.counter = 0; - forever { + react { assert DOM('#button-label', '', Syndicate.seal(this.counter)); on message jQueryEvent('#counter', 'click', _) { this.counter++; diff --git a/js/examples/chat/index.js b/js/examples/chat/index.js index 2c03433..617a269 100644 --- a/js/examples/chat/index.js +++ b/js/examples/chat/index.js @@ -19,7 +19,7 @@ function spawnChatApp() { if (!($("#nym").val())) { $("#nym").val("nym" + Math.floor(Math.random() * 65536)); } actor { - forever { + react { on asserted jQueryInput('#nym', $v) { this.nym = v; } on asserted jQueryInput('#status', $v) { this.status = v; } @@ -85,11 +85,11 @@ assertion type jQueryInput(selector, value); function spawnInputChangeMonitor() { actor { - forever { + react { on asserted Syndicate.observe(jQueryInput($selector, _)) { actor { this.value = $(selector).val(); - state { + react { assert jQueryInput(selector, this.value); on message jQueryEvent(selector, 'change', $e) { this.value = e.target.value; diff --git a/js/examples/iot/index.js b/js/examples/iot/index.js index e46dd7d..3293a56 100644 --- a/js/examples/iot/index.js +++ b/js/examples/iot/index.js @@ -13,7 +13,7 @@ var jQueryEvent = Syndicate.JQuery.jQueryEvent; function spawnTV() { actor { - forever { + react { during tvAlert($text) { assert DOM('#tv', 'alert', Syndicate.seal(["li", text])); } @@ -26,7 +26,7 @@ function spawnTV() { function spawnRemoteControl() { actor { - forever { + react { assert componentPresent('remote control'); on message jQueryEvent('#remote-control', 'click', _) { :: remoteClick(); @@ -43,7 +43,7 @@ function spawnRemoteListener() { // state, if we've been clicked, turn it off. We don't do this // here, for simplicity. - forever { + react { on asserted powerDraw($watts) { this.stoveIsOn = watts > 0; } @@ -63,7 +63,7 @@ function spawnRemoteListener() { function spawnStoveSwitch() { actor { this.powerOn = false; - state { + react { assert componentPresent('stove switch'); assert switchState(this.powerOn); @@ -87,7 +87,7 @@ function spawnStoveSwitch() { function spawnPowerDrawMonitor() { actor { this.watts = 0; - state { + react { assert componentPresent('power draw monitor'); assert powerDraw(this.watts); @@ -110,14 +110,14 @@ function spawnPowerDrawMonitor() { function spawnTimeoutListener() { actor { - forever { + react { during powerDraw($watts) { - init { + do { if (watts > 0) { var powerOnTime = Date.now(); - forever { + react { on asserted Syndicate.Timer.timeLaterThan(powerOnTime + 3000) { - forever { assert tvAlert('Stove on too long?'); } + react { assert tvAlert('Stove on too long?'); } } } } @@ -129,13 +129,13 @@ function spawnTimeoutListener() { // function spawnTimeoutListener() { // actor { -// forever { +// react { // on asserted powerDraw($watts) { // if (watts > 0) { // var powerOnTime = Date.now(); -// state { +// react { // on asserted Syndicate.Timer.timeLaterThan(powerOnTime + 3000) { -// forever { assert tvAlert('Stove on too long?'); } +// react { assert tvAlert('Stove on too long?'); } // } // } until { // case asserted powerDraw(0); // alt: on retracted powerDraw(watts); @@ -150,7 +150,7 @@ function spawnTimeoutListener() { // actor { // this.mostRecentTime = 0; // this.powerOnTime = null; -// forever { +// react { // on asserted powerDraw($watts) { // this.powerOnTime = (watts > 0) ? this.mostRecentTime : null; // } @@ -168,9 +168,9 @@ function spawnTimeoutListener() { function spawnFailureMonitor() { actor { - forever { + react { on retracted componentPresent($who) { - state { + react { assert tvAlert('FAILURE: ' + who); } until { case asserted componentPresent(who); @@ -185,7 +185,7 @@ function spawnFailureMonitor() { function spawnChaosMonkey() { actor { - forever { + react { on message jQueryEvent('#spawn-power-draw-monitor', 'click', _) { spawnPowerDrawMonitor(); } diff --git a/js/examples/smoketest-dsl/index.js b/js/examples/smoketest-dsl/index.js index 24d279a..23cfb88 100644 --- a/js/examples/smoketest-dsl/index.js +++ b/js/examples/smoketest-dsl/index.js @@ -4,11 +4,11 @@ ground dataspace { console.log('starting ground boot'); actor { - until { + react until { case asserted Syndicate.observe(beep(_)) { var counter = 0; - state { - init { + react { + do { :: beep(counter++); } on message beep(_) { @@ -22,7 +22,7 @@ ground dataspace { } actor { - forever { + react { on message beep($counter) { console.log("beep!", counter); } diff --git a/js/examples/svg/index.js b/js/examples/svg/index.js index c3761df..485db4d 100644 --- a/js/examples/svg/index.js +++ b/js/examples/svg/index.js @@ -13,7 +13,7 @@ $(document).ready(function () { :: time(+(new Date())); }), 1000); - forever { + react { on message time($now) { this.angle = (((now / 1000) % 60) / 60) * 2 * Math.PI; this.handX = 50 + 40 * Math.cos(this.angle); diff --git a/js/examples/textfield-dsl/index.js b/js/examples/textfield-dsl/index.js index 3f7ad36..747f709 100644 --- a/js/examples/textfield-dsl/index.js +++ b/js/examples/textfield-dsl/index.js @@ -43,7 +43,7 @@ function spawnGui() { : piece(text, pos, 0, text.length + 1, "normal"); }; - forever { + react { on message jQueryEvent("#inputRow", "+keypress", $event) { var keycode = event.keyCode; var character = String.fromCharCode(event.charCode); @@ -82,7 +82,7 @@ function spawnModel() { this.fieldValue = "initial"; this.cursorPos = this.fieldValue.length; /* positions address gaps between characters */ - forever { + react { assert fieldContents(this.fieldValue, this.cursorPos); on message fieldCommand("cursorLeft") { @@ -135,7 +135,7 @@ function spawnSearch() { } }; - forever { + react { assert highlight(this.highlight); on message jQueryEvent("#searchBox", "input", $event) {