Change send syntax from `^ ...` to `send ...`.
This commit is contained in:
parent
049f4696e2
commit
baa40f5699
4
TODO.md
4
TODO.md
|
@ -10,6 +10,8 @@
|
||||||
- [DONE] dataspaces, dataspace relays
|
- [DONE] dataspaces, dataspace relays
|
||||||
- [DONE? Surely there's more] pin down and fix the problems with facet field scope (!!)
|
- [DONE? Surely there's more] pin down and fix the problems with facet field scope (!!)
|
||||||
- [DONE] `npm init @syndicate`
|
- [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] timer driver
|
||||||
- [DONE] ui driver
|
- [DONE] ui driver
|
||||||
|
@ -30,5 +32,3 @@
|
||||||
some formulations of the game-restart logic in the flappy bird
|
some formulations of the game-restart logic in the flappy bird
|
||||||
demo.
|
demo.
|
||||||
|
|
||||||
- change send syntax from `^ ...` to `send ...` :-(
|
|
||||||
- it's too cute. Indentation doesn't work, and forgetting a semicolon causes silent xor!
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ spawn named 'websocketListener' {
|
||||||
during Http.WebSocket($reqId, server, ['broker'], _) spawn named ['wsConnection', reqId] {
|
during Http.WebSocket($reqId, server, ['broker'], _) spawn named ['wsConnection', reqId] {
|
||||||
on message Http.DataIn(reqId, $message) {
|
on message Http.DataIn(reqId, $message) {
|
||||||
console.log('got', reqId, new Decoder(message).next());
|
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"));
|
stop on message Http.DataIn(reqId, Bytes.from("quit"));
|
||||||
|
@ -47,7 +47,7 @@ spawn named 'tcpListener' {
|
||||||
assert Tcp.TcpAccepted(id);
|
assert Tcp.TcpAccepted(id);
|
||||||
on message Tcp.DataIn(id, $data) {
|
on message Tcp.DataIn(id, $data) {
|
||||||
console.log('got', id, data);
|
console.log('got', id, data);
|
||||||
^ Tcp.DataOut(id, data);
|
send Tcp.DataOut(id, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ export function newFragmentId() {
|
||||||
spawn named 'GlobalEventFactory' {
|
spawn named 'GlobalEventFactory' {
|
||||||
during Observe(P.GlobalEvent($selector, $eventType, _))
|
during Observe(P.GlobalEvent($selector, $eventType, _))
|
||||||
spawn named ['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) {
|
function handler(event) {
|
||||||
sender(event);
|
sender(event);
|
||||||
return dealWithPreventDefault(eventType, event);
|
return dealWithPreventDefault(eventType, event);
|
||||||
|
@ -66,7 +66,7 @@ spawn named 'GlobalEventFactory' {
|
||||||
spawn named 'WindowEventFactory' {
|
spawn named 'WindowEventFactory' {
|
||||||
during Observe(P.WindowEvent($eventType, _))
|
during Observe(P.WindowEvent($eventType, _))
|
||||||
spawn named ['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) {
|
let handler = function (event) {
|
||||||
sender(event);
|
sender(event);
|
||||||
return dealWithPreventDefault(eventType, event);
|
return dealWithPreventDefault(eventType, event);
|
||||||
|
@ -147,7 +147,7 @@ spawn named 'UIFragmentFactory' {
|
||||||
|
|
||||||
if (!(key in eventRegistrations)) {
|
if (!(key in eventRegistrations)) {
|
||||||
let sender = Dataspace.wrapExternal((e) => {
|
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) {
|
function handler(event) {
|
||||||
sender(event);
|
sender(event);
|
||||||
|
|
|
@ -218,7 +218,7 @@ function _server(host, port, httpsOptions) {
|
||||||
|
|
||||||
on asserted Observe(DataIn(id, _)) {
|
on asserted Observe(DataIn(id, _)) {
|
||||||
ws.on('message', Dataspace.wrapExternal((message) => {
|
ws.on('message', Dataspace.wrapExternal((message) => {
|
||||||
^ DataIn(id, Bytes.fromIO(message));
|
send DataIn(id, Bytes.fromIO(message));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ spawn named 'driver/TcpDriver' {
|
||||||
if (pos !== -1) {
|
if (pos !== -1) {
|
||||||
const line = this.buffer.slice(0, pos);
|
const line = this.buffer.slice(0, pos);
|
||||||
this.buffer = this.buffer.slice(pos + 1);
|
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 stop try { socket.destroy() } catch (e) { console.error(e); }
|
||||||
|
|
||||||
on start react stop on asserted Observe(DataIn(id, _)) {
|
on start react stop on asserted Observe(DataIn(id, _)) {
|
||||||
socket.on('data', Dataspace.wrapExternal((data) => {
|
socket.on('data', Dataspace.wrapExternal((data) => { send DataIn(id, Bytes.fromIO(data)); }));
|
||||||
^ DataIn(id, Bytes.fromIO(data));
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
on message DataOut(id, $data) {
|
on message DataOut(id, $data) {
|
||||||
|
|
|
@ -36,9 +36,8 @@ spawn named 'driver-timer/PeriodicTick' {
|
||||||
let handle = null;
|
let handle = null;
|
||||||
let finish = Dataspace.backgroundTask();
|
let finish = Dataspace.backgroundTask();
|
||||||
on start {
|
on start {
|
||||||
handle = setInterval(Dataspace.wrapExternal(() => {
|
handle = setInterval(Dataspace.wrapExternal(() => { send PeriodicTick(intervalMS); }),
|
||||||
^ PeriodicTick(intervalMS);
|
Float.unwrap(intervalMS));
|
||||||
}), Float.unwrap(intervalMS));
|
|
||||||
}
|
}
|
||||||
on stop {
|
on stop {
|
||||||
if (handle) {
|
if (handle) {
|
||||||
|
|
|
@ -70,7 +70,7 @@ function _socket(addr, port) {
|
||||||
|
|
||||||
socket.on('listening', Dataspace.wrapExternal(() => { this.connected = true; }));
|
socket.on('listening', Dataspace.wrapExternal(() => { this.connected = true; }));
|
||||||
socket.on('message', Dataspace.wrapExternal((message, rinfo) => {
|
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));
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ spawn named 'WebSocketFactory' {
|
||||||
|
|
||||||
ws.onopen = Dataspace.wrapExternal(() => { this.connected = true; });
|
ws.onopen = Dataspace.wrapExternal(() => { this.connected = true; });
|
||||||
ws.onclose = Dataspace.wrapExternal(() => { if (this.connected) { connect(); }});
|
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 = () => {
|
const disconnect = () => {
|
||||||
|
|
|
@ -45,9 +45,7 @@ spawn named 'game-factory' {
|
||||||
during GameOver() {
|
during GameOver() {
|
||||||
on stop spawnGame();
|
on stop spawnGame();
|
||||||
on message UI.WindowEvent('+keypress', $e) {
|
on message UI.WindowEvent('+keypress', $e) {
|
||||||
if (e.key !== ' ') {
|
if (e.key !== ' ') send Reset();
|
||||||
^ Reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,9 +54,7 @@ function spawnGame() {
|
||||||
spawn dataspace named 'GameInstance' {
|
spawn dataspace named 'GameInstance' {
|
||||||
spawn named 'game-instance-control' {
|
spawn named 'game-instance-control' {
|
||||||
during GameOver() assert Outbound(GameOver());
|
during GameOver() assert Outbound(GameOver());
|
||||||
on message Inbound(Reset()) {
|
on message Inbound(Reset()) send $QuitDataspace;
|
||||||
^ $QuitDataspace;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn named 'score' {
|
spawn named 'score' {
|
||||||
|
@ -143,9 +139,7 @@ function spawnGame() {
|
||||||
|
|
||||||
stop on (this.xpos < -(PILLAR_WIDTH + FLAPPY_XPOS));
|
stop on (this.xpos < -(PILLAR_WIDTH + FLAPPY_XPOS));
|
||||||
|
|
||||||
on start react stop on (this.xpos <= 0) {
|
on start react stop on (this.xpos <= 0) send IncreaseScore();
|
||||||
^ IncreaseScore();
|
|
||||||
}
|
|
||||||
|
|
||||||
field this.xpos = xlocation;
|
field this.xpos = xlocation;
|
||||||
on asserted Position($xpos, _) this.xpos = xlocation - xpos.value;
|
on asserted Position($xpos, _) this.xpos = xlocation - xpos.value;
|
||||||
|
|
|
@ -35,7 +35,7 @@ spawn named 'box' {
|
||||||
spawn named 'client' {
|
spawn named 'client' {
|
||||||
on asserted Protocol.BoxState($v) {
|
on asserted Protocol.BoxState($v) {
|
||||||
// console.log('client sending SetBox', v + 1);
|
// console.log('client sending SetBox', v + 1);
|
||||||
^ Protocol.SetBox(v + 1);
|
send Protocol.SetBox(v + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
on retracted Protocol.BoxState(_) {
|
on retracted Protocol.BoxState(_) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ spawn named 'chatclient' {
|
||||||
.on('error', Dataspace.wrapExternal((err) => { throw err; }))
|
.on('error', Dataspace.wrapExternal((err) => { throw err; }))
|
||||||
.on('close', Dataspace.wrapExternal(() => { rootFacet.stop(); }))
|
.on('close', Dataspace.wrapExternal(() => { rootFacet.stop(); }))
|
||||||
.on('data', Dataspace.wrapExternal(
|
.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 stop process.stdin.destroy();
|
||||||
|
|
||||||
on message Tcp.LineIn(id, $line) { console.log(line.toString('utf-8')); }
|
on message Tcp.LineIn(id, $line) { console.log(line.toString('utf-8')); }
|
||||||
|
|
|
@ -29,11 +29,11 @@ spawn named 'chatserver' {
|
||||||
|
|
||||||
assert Present(me);
|
assert Present(me);
|
||||||
during Present($who) {
|
during Present($who) {
|
||||||
on start { ^ Tcp.DataOut(id, `${who} arrived.\n`); }
|
on start send Tcp.DataOut(id, `${who} arrived.\n`);
|
||||||
on stop { ^ Tcp.DataOut(id, `${who} departed.\n`); }
|
on stop send Tcp.DataOut(id, `${who} departed.\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
on message Tcp.LineIn(id, $line) { ^ Speak(me, line); }
|
on message Tcp.LineIn(id, $line) send Speak(me, line);
|
||||||
on message Speak($who, $what) { ^ Tcp.DataOut(id, `${who}: ${what}\n`); }
|
on message Speak($who, $what) send Tcp.DataOut(id, `${who}: ${what}\n`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ spawn named 'demo' {
|
||||||
}
|
}
|
||||||
|
|
||||||
on message PeriodicTick(1000) {
|
on message PeriodicTick(1000) {
|
||||||
^ WS.DataOut(wsId, Bytes.from(genUuid('timestamp')));
|
send WS.DataOut(wsId, Bytes.from(genUuid('timestamp')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ spawn named 'view' {
|
||||||
|
|
||||||
spawn named 'controller' {
|
spawn named 'controller' {
|
||||||
on message UI.GlobalEvent('table#the-table th', 'click', $e) {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ spawn named 'multicast_demo' {
|
||||||
}
|
}
|
||||||
|
|
||||||
on message PeriodicTick(2000) {
|
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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,13 @@ var Dataspace = require('@syndicate-lang/core').Dataspace;
|
||||||
const N = 100000;
|
const N = 100000;
|
||||||
|
|
||||||
spawn {
|
spawn {
|
||||||
on start {
|
on start send 0;
|
||||||
^ 0;
|
|
||||||
}
|
|
||||||
on message $v {
|
on message $v {
|
||||||
if (v === N) {
|
if (v === N) {
|
||||||
Dataspace.currentFacet().stop();
|
Dataspace.currentFacet().stop();
|
||||||
} else {
|
} else {
|
||||||
^ v + 1;
|
send v + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ spawn dataspace named 'C' {
|
||||||
spawn named 'H' on asserted Inbound(Inbound(Greeting($t))) console.log('Inner dataspace:', t);
|
spawn named 'H' on asserted Inbound(Inbound(Greeting($t))) console.log('Inner dataspace:', t);
|
||||||
spawn named 'I' on asserted Inbound(Inbound(Greeting('Inner!'))) {
|
spawn named 'I' on asserted Inbound(Inbound(Greeting('Inner!'))) {
|
||||||
console.log('I: Terminating F');
|
console.log('I: Terminating F');
|
||||||
^ $QuitDataspace
|
send $QuitDataspace;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ spawn named 'websocketEchoServer' {
|
||||||
during Http.WebSocket($reqId, server, ['echo'], _) {
|
during Http.WebSocket($reqId, server, ['echo'], _) {
|
||||||
on message Http.DataIn(reqId, $message) {
|
on message Http.DataIn(reqId, $message) {
|
||||||
console.log('got', reqId, message);
|
console.log('got', reqId, message);
|
||||||
^ Http.DataOut(reqId, message);
|
send Http.DataOut(reqId, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop on message Http.DataIn(reqId, "quit");
|
stop on message Http.DataIn(reqId, "quit");
|
||||||
|
|
|
@ -139,7 +139,7 @@ export function SyndicateTypeDefinition(node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MessageSendStatement(node) {
|
export function MessageSendStatement(node) {
|
||||||
this.token("^");
|
this.token("send");
|
||||||
this.space();
|
this.space();
|
||||||
this.print(node.body, node);
|
this.print(node.body, node);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
|
|
|
@ -54,21 +54,6 @@ export default class SyndicateParser extends _original_Parser {
|
||||||
let previousError = null;
|
let previousError = null;
|
||||||
|
|
||||||
switch (this.state.type) {
|
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:
|
case tt.name:
|
||||||
if (this.hasPlugin("syndicate")) {
|
if (this.hasPlugin("syndicate")) {
|
||||||
let result = this.withBacktracking(
|
let result = this.withBacktracking(
|
||||||
|
@ -141,6 +126,14 @@ export default class SyndicateParser extends _original_Parser {
|
||||||
return this.finishNode(node, "SyndicateReactStatement");
|
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")) {
|
if (this.isContextual("assertion") || this.isContextual("message")) {
|
||||||
const node = this.startNode();
|
const node = this.startNode();
|
||||||
node.expectedUse = this.state.value;
|
node.expectedUse = this.state.value;
|
||||||
|
|
Loading…
Reference in New Issue