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

This commit is contained in:
Tony Garnock-Jones 2018-11-16 11:17:59 +00:00
parent 049f4696e2
commit baa40f5699
20 changed files with 40 additions and 57 deletions

View File

@ -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 @@
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!

View File

@ -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' {
assert Tcp.TcpAccepted(id);
on message Tcp.DataIn(id, $data) {
console.log('got', id, data);
^ Tcp.DataOut(id, data);
send Tcp.DataOut(id, data);
}
}
}

View File

@ -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' {
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' {
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);

View File

@ -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));
}));
}

View File

@ -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) {
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) {

View File

@ -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) {

View File

@ -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));
}));
};

View File

@ -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 = () => {

View File

@ -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() {
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() {
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;

View File

@ -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(_) {

View File

@ -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')); }

View File

@ -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`);
}
}

View File

@ -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')));
}
}
}

View File

@ -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));
}
}

View File

@ -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'));
}
}
}

View File

@ -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;
}
}
}

View File

@ -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;
};
}

View File

@ -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");

View File

@ -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();

View File

@ -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 {
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;