Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ast/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ pub fn walk_statement<V: Visitor>(v: &mut V, stmt: &Statement) {
for s in &c.body { v.visit_statement(s); }
}
Statement::Expression(e) => v.visit_expr(&e.node),
Statement::WorkerSpawn(_) | Statement::Complain(_)
Statement::SendMessage(s) => v.visit_expr(&s.message.node),
Statement::WorkerSpawn(_) | Statement::ReceiveMessage(_)
| Statement::AwaitWorker(_) | Statement::CancelWorker(_)
| Statement::Complain(_)
| Statement::Break(_) | Statement::Continue(_) => {}
Statement::EmoteAnnotated(e) => v.visit_statement(&e.statement),
Statement::Decide(d) => {
Expand Down
24 changes: 24 additions & 0 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,30 @@ impl Interpreter {
Ok(Value::Unit)
}

Statement::SendMessage(send) => Err(RuntimeError::new(format!(
"Worker-addressed message passing is not implemented: cannot `send` to worker '{}'. \
Use a channel created in the main scope and pass it to the worker instead.",
send.target
))),

Statement::ReceiveMessage(recv) => Err(RuntimeError::new(format!(
"Worker-addressed message passing is not implemented: cannot `receive` from worker '{}'. \
Use a channel created in the main scope and pass it to the worker instead.",
recv.source
))),

Statement::AwaitWorker(await_worker) => Err(RuntimeError::new(format!(
"Awaiting a worker by name is not implemented: cannot `await` worker '{}'. \
Workers run detached; synchronise via a channel created in the main scope.",
await_worker.worker_name
))),

Statement::CancelWorker(cancel) => Err(RuntimeError::new(format!(
"Cancelling a worker by name is not implemented: cannot `cancel` worker '{}'. \
Workers run detached and cannot currently be cancelled.",
cancel.worker_name
))),

Statement::Complain(complain) => Err(RuntimeError {
message: complain.message.clone(),
}),
Expand Down
31 changes: 31 additions & 0 deletions src/sexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ fn stmt_to_sexpr(stmt: &Statement, out: &mut String, indent: usize) {
Statement::WorkerSpawn(w) => {
out.push_str(&format!("(spawn-worker \"{}\")", w.worker_name));
}
Statement::SendMessage(s) => {
out.push_str(&format!("(send :to \"{}\" ", s.target));
expr_to_sexpr(&s.message.node, out, indent + 2);
out.push(')');
}
Statement::ReceiveMessage(r) => {
out.push_str(&format!("(receive :from \"{}\")", r.source));
}
Statement::AwaitWorker(a) => {
out.push_str(&format!("(await-worker \"{}\")", a.worker_name));
}
Statement::CancelWorker(c) => {
out.push_str(&format!("(cancel-worker \"{}\")", c.worker_name));
}
Statement::Complain(c) => {
out.push_str(&format!("(complain \"{}\")", c.message));
}
Expand Down Expand Up @@ -710,6 +724,23 @@ fn stmt_to_json(stmt: &Statement) -> serde_json::Value {
"type": "spawn_worker",
"name": w.worker_name
}),
Statement::SendMessage(s) => serde_json::json!({
"type": "send_message",
"target": s.target,
"message": expr_to_json(&s.message.node)
}),
Statement::ReceiveMessage(r) => serde_json::json!({
"type": "receive_message",
"source": r.source
}),
Statement::AwaitWorker(a) => serde_json::json!({
"type": "await_worker",
"name": a.worker_name
}),
Statement::CancelWorker(c) => serde_json::json!({
"type": "cancel_worker",
"name": c.worker_name
}),
Statement::Complain(c) => serde_json::json!({
"type": "complain",
"message": c.message
Expand Down
Loading