Browse Source

Change send syntax from `^ ...` to `send ...`.

bonjour-mdns-experiment
Tony Garnock-Jones 4 years ago
parent
commit
baa40f5699
  1. 4
      TODO.md
  2. 4
      packages/broker/src/index.js
  3. 6
      packages/driver-browser-ui/src/index.js
  4. 2
      packages/driver-http-node/src/index.js
  5. 6
      packages/driver-tcp-node/src/index.js
  6. 5
      packages/driver-timer/src/index.js
  7. 2
      packages/driver-udp-node/src/index.js
  8. 2
      packages/driver-websocket/src/index.js
  9. 12
      packages/flappy-bird-demo/src/index.js
  10. 2
      packages/syntax-playground/src/assertionspeed.js
  11. 2
      packages/syntax-playground/src/chatclient.js
  12. 8
      packages/syntax-playground/src/chatserver.js
  13. 2
      packages/syntax-playground/src/client.js
  14. 2
      packages/syntax-playground/src/index.js
  15. 2
      packages/syntax-playground/src/mc.js
  16. 7
      packages/syntax-playground/src/messagespeed.js
  17. 2
      packages/syntax-playground/src/nested2.js
  18. 2
      packages/syntax-playground/src/server.js
  19. 2
      packages/syntax/src/generators.js
  20. 23
      packages/syntax/src/parser.js

4
TODO.md

@ -10,6 +10,8 @@ @@ -10,6 +10,8 @@
- [DONE] dataspaces, dataspace relays
- [DONE? Surely there's more] pin down and fix the problems with facet field scope (!!)
- [DONE] `npm init @syndicate`
- [DONE] change send syntax from `^ ...` to `send ...` :-(
- Using `^` is too cute. Indentation doesn't work, and forgetting a semicolon causes silent xor!
- [DONE] timer driver
- [DONE] ui driver
@ -30,5 +32,3 @@ @@ -30,5 +32,3 @@
some formulations of the game-restart logic in the flappy bird
demo.
- change send syntax from `^ ...` to `send ...` :-(
- it's too cute. Indentation doesn't work, and forgetting a semicolon causes silent xor!

4
packages/broker/src/index.js

@ -35,7 +35,7 @@ spawn named 'websocketListener' { @@ -35,7 +35,7 @@ spawn named 'websocketListener' {
during Http.WebSocket($reqId, server, ['broker'], _) spawn named ['wsConnection', reqId] {
on message Http.DataIn(reqId, $message) {
console.log('got', reqId, new Decoder(message).next());
^ Http.DataOut(reqId, message);
send Http.DataOut(reqId, message);
}
stop on message Http.DataIn(reqId, Bytes.from("quit"));
@ -47,7 +47,7 @@ spawn named 'tcpListener' { @@ -47,7 +47,7 @@ spawn named 'tcpListener' {
assert Tcp.TcpAccepted(id);
on message Tcp.DataIn(id, $data) {
console.log('got', id, data);
^ Tcp.DataOut(id, data);
send Tcp.DataOut(id, data);
}
}
}

6
packages/driver-browser-ui/src/index.js

@ -40,7 +40,7 @@ export function newFragmentId() { @@ -40,7 +40,7 @@ export function newFragmentId() {
spawn named 'GlobalEventFactory' {
during Observe(P.GlobalEvent($selector, $eventType, _))
spawn named ['GlobalEvent', selector, eventType] {
let sender = Dataspace.wrapExternal((e) => { ^ P.GlobalEvent(selector, eventType, e); });
let sender = Dataspace.wrapExternal((e) => { send P.GlobalEvent(selector, eventType, e); });
function handler(event) {
sender(event);
return dealWithPreventDefault(eventType, event);
@ -66,7 +66,7 @@ spawn named 'GlobalEventFactory' { @@ -66,7 +66,7 @@ spawn named 'GlobalEventFactory' {
spawn named 'WindowEventFactory' {
during Observe(P.WindowEvent($eventType, _))
spawn named ['WindowEvent', eventType] {
let sender = Dataspace.wrapExternal((e) => { ^ P.WindowEvent(eventType, e); });
let sender = Dataspace.wrapExternal((e) => { send P.WindowEvent(eventType, e); });
let handler = function (event) {
sender(event);
return dealWithPreventDefault(eventType, event);
@ -147,7 +147,7 @@ spawn named 'UIFragmentFactory' { @@ -147,7 +147,7 @@ spawn named 'UIFragmentFactory' {
if (!(key in eventRegistrations)) {
let sender = Dataspace.wrapExternal((e) => {
^ P.UIEvent(fragmentId, c.selector, c.eventType, e);
send P.UIEvent(fragmentId, c.selector, c.eventType, e);
});
function handler(event) {
sender(event);

2
packages/driver-http-node/src/index.js

@ -218,7 +218,7 @@ function _server(host, port, httpsOptions) { @@ -218,7 +218,7 @@ function _server(host, port, httpsOptions) {
on asserted Observe(DataIn(id, _)) {
ws.on('message', Dataspace.wrapExternal((message) => {
^ DataIn(id, Bytes.fromIO(message));
send DataIn(id, Bytes.fromIO(message));
}));
}

6
packages/driver-tcp-node/src/index.js

@ -78,7 +78,7 @@ spawn named 'driver/TcpDriver' { @@ -78,7 +78,7 @@ spawn named 'driver/TcpDriver' {
if (pos !== -1) {
const line = this.buffer.slice(0, pos);
this.buffer = this.buffer.slice(pos + 1);
^ LineIn(id, line);
send LineIn(id, line);
}
}
}
@ -107,9 +107,7 @@ function _connectionCommon(rootFacet, id, socket, established) { @@ -107,9 +107,7 @@ function _connectionCommon(rootFacet, id, socket, established) {
on stop try { socket.destroy() } catch (e) { console.error(e); }
on start react stop on asserted Observe(DataIn(id, _)) {
socket.on('data', Dataspace.wrapExternal((data) => {
^ DataIn(id, Bytes.fromIO(data));
}));
socket.on('data', Dataspace.wrapExternal((data) => { send DataIn(id, Bytes.fromIO(data)); }));
}
on message DataOut(id, $data) {

5
packages/driver-timer/src/index.js

@ -36,9 +36,8 @@ spawn named 'driver-timer/PeriodicTick' { @@ -36,9 +36,8 @@ spawn named 'driver-timer/PeriodicTick' {
let handle = null;
let finish = Dataspace.backgroundTask();
on start {
handle = setInterval(Dataspace.wrapExternal(() => {
^ PeriodicTick(intervalMS);
}), Float.unwrap(intervalMS));
handle = setInterval(Dataspace.wrapExternal(() => { send PeriodicTick(intervalMS); }),
Float.unwrap(intervalMS));
}
on stop {
if (handle) {

2
packages/driver-udp-node/src/index.js

@ -70,7 +70,7 @@ function _socket(addr, port) { @@ -70,7 +70,7 @@ function _socket(addr, port) {
socket.on('listening', Dataspace.wrapExternal(() => { this.connected = true; }));
socket.on('message', Dataspace.wrapExternal((message, rinfo) => {
^ UdpPacket(UdpPeer(rinfo.address, rinfo.port), addr, Bytes.fromIO(message));
send UdpPacket(UdpPeer(rinfo.address, rinfo.port), addr, Bytes.fromIO(message));
}));
};

2
packages/driver-websocket/src/index.js

@ -52,7 +52,7 @@ spawn named 'WebSocketFactory' { @@ -52,7 +52,7 @@ spawn named 'WebSocketFactory' {
ws.onopen = Dataspace.wrapExternal(() => { this.connected = true; });
ws.onclose = Dataspace.wrapExternal(() => { if (this.connected) { connect(); }});
ws.onmessage = Dataspace.wrapExternal((data) => { ^ DataIn(id, Bytes.fromIO(data.data)); });
ws.onmessage = Dataspace.wrapExternal((data) => { send DataIn(id, Bytes.fromIO(data.data)) });
};
const disconnect = () => {

12
packages/flappy-bird-demo/src/index.js

@ -45,9 +45,7 @@ spawn named 'game-factory' { @@ -45,9 +45,7 @@ spawn named 'game-factory' {
during GameOver() {
on stop spawnGame();
on message UI.WindowEvent('+keypress', $e) {
if (e.key !== ' ') {
^ Reset();
}
if (e.key !== ' ') send Reset();
}
}
}
@ -56,9 +54,7 @@ function spawnGame() { @@ -56,9 +54,7 @@ function spawnGame() {
spawn dataspace named 'GameInstance' {
spawn named 'game-instance-control' {
during GameOver() assert Outbound(GameOver());
on message Inbound(Reset()) {
^ $QuitDataspace;
}
on message Inbound(Reset()) send $QuitDataspace;
}
spawn named 'score' {
@ -143,9 +139,7 @@ function spawnGame() { @@ -143,9 +139,7 @@ function spawnGame() {
stop on (this.xpos < -(PILLAR_WIDTH + FLAPPY_XPOS));
on start react stop on (this.xpos <= 0) {
^ IncreaseScore();
}
on start react stop on (this.xpos <= 0) send IncreaseScore();
field this.xpos = xlocation;
on asserted Position($xpos, _) this.xpos = xlocation - xpos.value;

2
packages/syntax-playground/src/assertionspeed.js

@ -35,7 +35,7 @@ spawn named 'box' { @@ -35,7 +35,7 @@ spawn named 'box' {
spawn named 'client' {
on asserted Protocol.BoxState($v) {
// console.log('client sending SetBox', v + 1);
^ Protocol.SetBox(v + 1);
send Protocol.SetBox(v + 1);
}
on retracted Protocol.BoxState(_) {

2
packages/syntax-playground/src/chatclient.js

@ -33,7 +33,7 @@ spawn named 'chatclient' { @@ -33,7 +33,7 @@ spawn named 'chatclient' {
.on('error', Dataspace.wrapExternal((err) => { throw err; }))
.on('close', Dataspace.wrapExternal(() => { rootFacet.stop(); }))
.on('data', Dataspace.wrapExternal(
(data) => { if (data) { ^ Tcp.DataOut(id, data + '\n'); }}));
(data) => { if (data) send Tcp.DataOut(id, data + '\n'); }));
on stop process.stdin.destroy();
on message Tcp.LineIn(id, $line) { console.log(line.toString('utf-8')); }

8
packages/syntax-playground/src/chatserver.js

@ -29,11 +29,11 @@ spawn named 'chatserver' { @@ -29,11 +29,11 @@ spawn named 'chatserver' {
assert Present(me);
during Present($who) {
on start { ^ Tcp.DataOut(id, `${who} arrived.\n`); }
on stop { ^ Tcp.DataOut(id, `${who} departed.\n`); }
on start send Tcp.DataOut(id, `${who} arrived.\n`);
on stop send Tcp.DataOut(id, `${who} departed.\n`);
}
on message Tcp.LineIn(id, $line) { ^ Speak(me, line); }
on message Speak($who, $what) { ^ Tcp.DataOut(id, `${who}: ${what}\n`); }
on message Tcp.LineIn(id, $line) send Speak(me, line);
on message Speak($who, $what) send Tcp.DataOut(id, `${who}: ${what}\n`);
}
}

2
packages/syntax-playground/src/client.js

@ -34,7 +34,7 @@ spawn named 'demo' { @@ -34,7 +34,7 @@ spawn named 'demo' {
}
on message PeriodicTick(1000) {
^ WS.DataOut(wsId, Bytes.from(genUuid('timestamp')));
send WS.DataOut(wsId, Bytes.from(genUuid('timestamp')));
}
}
}

2
packages/syntax-playground/src/index.js

@ -56,7 +56,7 @@ spawn named 'view' { @@ -56,7 +56,7 @@ spawn named 'view' {
spawn named 'controller' {
on message UI.GlobalEvent('table#the-table th', 'click', $e) {
^ SetSortColumn(JSON.parse(e.target.dataset.column));
send SetSortColumn(JSON.parse(e.target.dataset.column));
}
}

2
packages/syntax-playground/src/mc.js

@ -39,7 +39,7 @@ spawn named 'multicast_demo' { @@ -39,7 +39,7 @@ spawn named 'multicast_demo' {
}
on message PeriodicTick(2000) {
^ U.UdpPacket(HANDLE, U.UdpPeer(GROUP_ADDRESS, PORT), genUuid('timestamp'));
send U.UdpPacket(HANDLE, U.UdpPeer(GROUP_ADDRESS, PORT), genUuid('timestamp'));
}
}
}

7
packages/syntax-playground/src/messagespeed.js

@ -22,14 +22,13 @@ var Dataspace = require('@syndicate-lang/core').Dataspace; @@ -22,14 +22,13 @@ var Dataspace = require('@syndicate-lang/core').Dataspace;
const N = 100000;
spawn {
on start {
^ 0;
}
on start send 0;
on message $v {
if (v === N) {
Dataspace.currentFacet().stop();
} else {
^ v + 1;
send v + 1;
}
}
}

2
packages/syntax-playground/src/nested2.js

@ -40,7 +40,7 @@ spawn dataspace named 'C' { @@ -40,7 +40,7 @@ spawn dataspace named 'C' {
spawn named 'H' on asserted Inbound(Inbound(Greeting($t))) console.log('Inner dataspace:', t);
spawn named 'I' on asserted Inbound(Inbound(Greeting('Inner!'))) {
console.log('I: Terminating F');
^ $QuitDataspace
send $QuitDataspace;
};
}

2
packages/syntax-playground/src/server.js

@ -126,7 +126,7 @@ spawn named 'websocketEchoServer' { @@ -126,7 +126,7 @@ spawn named 'websocketEchoServer' {
during Http.WebSocket($reqId, server, ['echo'], _) {
on message Http.DataIn(reqId, $message) {
console.log('got', reqId, message);
^ Http.DataOut(reqId, message);
send Http.DataOut(reqId, message);
}
stop on message Http.DataIn(reqId, "quit");

2
packages/syntax/src/generators.js

@ -139,7 +139,7 @@ export function SyndicateTypeDefinition(node) { @@ -139,7 +139,7 @@ export function SyndicateTypeDefinition(node) {
}
export function MessageSendStatement(node) {
this.token("^");
this.token("send");
this.space();
this.print(node.body, node);
this.semicolon();

23
packages/syntax/src/parser.js

@ -54,21 +54,6 @@ export default class SyndicateParser extends _original_Parser { @@ -54,21 +54,6 @@ export default class SyndicateParser extends _original_Parser {
let previousError = null;
switch (this.state.type) {
case tt.bitwiseXOR:
if (this.hasPlugin("syndicate")) {
let result = this.withBacktracking(
() => {
this.next();
const node = this.startNode();
node.body = this.parseExpression();
this.semicolon();
return this.finishNode(node, "MessageSendStatement");
},
(err) => { previousError = err; return null; });
if (result) return result;
}
break;
case tt.name:
if (this.hasPlugin("syndicate")) {
let result = this.withBacktracking(
@ -141,6 +126,14 @@ export default class SyndicateParser extends _original_Parser { @@ -141,6 +126,14 @@ export default class SyndicateParser extends _original_Parser {
return this.finishNode(node, "SyndicateReactStatement");
}
if (this.isContextual("send")) {
this.next();
const node = this.startNode();
node.body = this.parseExpression();
this.semicolon();
return this.finishNode(node, "MessageSendStatement");
}
if (this.isContextual("assertion") || this.isContextual("message")) {
const node = this.startNode();
node.expectedUse = this.state.value;

Loading…
Cancel
Save