Skip to content

Commit

Permalink
[compiler][back] Generate the code of queue-free universe and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptal committed Nov 11, 2018
1 parent 58221bf commit 9b5d100
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 54 deletions.
6 changes: 3 additions & 3 deletions data/test/run-pass/NothingT.bonsai.java
@@ -1,4 +1,4 @@
// Copyright 2018 Pierre Talbot (IRCAM)
// Copyright 2018 Pierre Talbot

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[run(NothingT.test, "")]
#[run(NothingT.printNothing, "")]
#[run(NothingT.printOne, "1")]
#[run(NothingT.printFew, "1234")]
#[run(NothingT.printFew2, "1+")]
Expand All @@ -25,7 +25,7 @@

public class NothingT
{
public proc test() = nothing
public proc printNothing() = nothing
public proc printOne() = System.out.println("1")
public proc printFew() = System.out.println("1234")
public proc printFew2() = System.out.println("1111111")
Expand Down
29 changes: 29 additions & 0 deletions data/test/run-pass/QFUniverseT.bonsai.java
@@ -0,0 +1,29 @@
// Copyright 2018 Pierre Talbot

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#[run(QFUniverseT.printNothing, "")]
#[run(QFUniverseT.printOne, "1")]
#[run(QFUniverseT.printTwo, "2")]

package test;

import java.lang.System;
import java.util.*;

public class QFUniverseT
{
public proc printNothing() = universe nothing end
public proc printOne() = universe System.out.println("1") end
public proc printTwo() = universe universe System.out.println("2") end end
}
2 changes: 1 addition & 1 deletion src/ast.rs
Expand Up @@ -302,7 +302,7 @@ pub enum StmtKind {
Loop(Box<Stmt>),
ProcCall(Option<Variable>, Ident, Vec<Variable>),
ExprStmt(Expr),
Universe(Box<Stmt>),
QFUniverse(Box<Stmt>), // Queue-free universe
Nothing,
// Meta statement not appearing in the spacetime syntax.
LocalDrop(VarPath)
Expand Down
49 changes: 9 additions & 40 deletions src/back/compiler/statement.rs
Expand Up @@ -37,30 +37,12 @@ impl<'a> StatementCompiler<'a>
}
}

// Seq(Vec<Stmt>),
// Par(Vec<Stmt>),
// Space(Vec<Stmt>),
// Let(LetStmt),
// When(EntailmentRel, Box<Stmt>),
// Suspend(EntailmentRel, Box<Stmt>),
// Tell(Variable, Expr),
// Pause,
// PauseUp,
// Stop,
// Trap(Ident, Box<Stmt>),
// Exit(Ident),
// Loop(Box<Stmt>),
// ProcCall(Option<Variable>, Ident),
// ExprStmt(Expr),
// Universe(Box<Stmt>),
// Nothing


fn compile(&mut self, stmt: Stmt) {
use ast::StmtKind::*;
match stmt.node {
Nothing => self.nothing(),
ExprStmt(expr) => self.procedure(expr),
QFUniverse(body) => self.qf_universe(body),
// Seq(branches) => self.sequence(branches),
// OrPar(branches) => self.or_parallel(branches),
// AndPar(branches) => self.and_parallel(branches),
Expand All @@ -77,7 +59,6 @@ impl<'a> StatementCompiler<'a>
// ProcCall(process, args) => self.fun_call(process, args),
// ModuleCall(run_expr) => self.module_call(run_expr),
// Tell(var, expr) => self.tell(var, expr),
// Universe(body) => self.universe(body),
_ => unimplemented!("statement unimplemented.")
}
}
Expand All @@ -92,6 +73,14 @@ impl<'a> StatementCompiler<'a>
self.fmt.push(")");
}

fn qf_universe(&mut self, body: Box<Stmt>) {
self.fmt.push_line(&"new QFUniverse(");
self.fmt.indent();
self.compile(*body);
self.fmt.unindent();
self.fmt.push(")");
}

// fn nary_operator(&mut self, op_name: &str, mut branches: Vec<Stmt>)
// {
// if branches.len() == 1 {
Expand Down Expand Up @@ -282,24 +271,4 @@ impl<'a> StatementCompiler<'a>
// self.fmt.unindent();
// self.fmt.push(")");
// }

// fn trap(&mut self, name: Ident, body: Box<Stmt>) {
// self.fmt.push_line(&format!("SC.until(\"{}\",", name));
// self.fmt.indent();
// self.compile(*body);
// self.fmt.unindent();
// self.fmt.push(")");
// }

// fn exit(&mut self, name: Ident) {
// self.fmt.push(&format!("SC.generate(\"{}\")", name));
// }

// fn universe(&mut self, body: Box<Stmt>) {
// self.fmt.push_line(&format!("new Universe({},", session.config().debug));
// self.fmt.indent();
// self.compile(*body);
// self.fmt.unindent();
// self.fmt.push(")");
// }
}
6 changes: 3 additions & 3 deletions src/front/grammar.rs
Expand Up @@ -225,7 +225,7 @@ grammar! bonsai {
/ PAUSE_OS > make_pause
/ NOTHING_OS > make_nothing
/ LOOP close_sequence END_OS > make_loop
/ UNIVERSE close_sequence END_OS > make_universe
/ UNIVERSE close_sequence END_OS > make_qf_universe
/ RUN proc_call_os > make_proc_call
/ binding_os > make_let_stmt
/ variable LEFT_ARROW expr > make_tell
Expand Down Expand Up @@ -326,8 +326,8 @@ grammar! bonsai {
StmtKind::ProcCall(var, process, args)
}

fn make_universe(body: Stmt) -> StmtKind {
StmtKind::Universe(Box::new(body))
fn make_qf_universe(body: Stmt) -> StmtKind {
StmtKind::QFUniverse(Box::new(body))
}

proc_call_os = (variable DOT)? identifier LPAREN list_var RPAREN_OS
Expand Down
2 changes: 1 addition & 1 deletion src/middle/causality/causal_stmt.rs
Expand Up @@ -115,7 +115,7 @@ impl CausalStmt {
// Abort(cond, body) => self.visit_abort(cond, *body, model, continuation),
// Loop(body) => self.visit_loop(*body),
// ProcCall(var, process, args) => self.visit_proc_call(var, process, args),
// Universe(body) => self.visit_universe(*body),
// QFUniverse(body) => self.visit_qf_universe(*body),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/middle/causality/symbolic_execution.rs
Expand Up @@ -273,7 +273,7 @@ impl SymbolicExecution
// Abort(cond, body) => self.next_states_abort(cond, *body, model),
// Loop(body) => self.next_states_loop(*body),
// ProcCall(var, process, args) => self.next_states_proc_call(var, process, args),
// Universe(body) => self.next_states_universe(*body),
// QFUniverse(body) => self.next_states_qf_universe(*body),
}
}

Expand Down Expand Up @@ -343,7 +343,7 @@ impl SymbolicExecution
// Abort(cond, body) => self.reduce_abort(cond, *body, model, state),
// Loop(body) => self.reduce_loop(*body),
// ProcCall(var, process, args) => self.reduce_proc_call(var, process, args),
// Universe(body) => self.reduce_universe(*body),
// QFUniverse(body) => self.reduce_qf_universe(*body),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/visitor.rs
Expand Up @@ -103,7 +103,7 @@ pub trait Visitor<H>

fn visit_nothing(&mut self) {}

fn visit_universe(&mut self, child: Stmt) {
fn visit_qf_universe(&mut self, child: Stmt) {
self.visit_stmt(child)
}

Expand Down Expand Up @@ -195,7 +195,7 @@ pub fn walk_stmt<H, V: ?Sized>(visitor: &mut V, stmt: Stmt) where
Loop(body) => visitor.visit_loop(*body),
ExprStmt(expr) => visitor.visit_expr_stmt(expr),
ProcCall(var, process, args) => visitor.visit_proc_call(var, process, args),
Universe(body) => visitor.visit_universe(*body),
QFUniverse(body) => visitor.visit_qf_universe(*body),
Nothing => visitor.visit_nothing(),
LocalDrop(var_path) => visitor.visit_drop(var_path),
}
Expand Down Expand Up @@ -356,7 +356,7 @@ pub trait VisitorMut<H>

fn visit_nothing(&mut self) {}

fn visit_universe(&mut self, child: &mut Stmt) {
fn visit_qf_universe(&mut self, child: &mut Stmt) {
self.visit_stmt(child)
}

Expand Down Expand Up @@ -448,7 +448,7 @@ pub fn walk_stmt_mut<H, V: ?Sized>(visitor: &mut V, stmt: &mut Stmt) where
&mut Loop(ref mut body) => visitor.visit_loop(&mut **body),
&mut ProcCall(ref mut var, ref process, ref mut args) => visitor.visit_proc_call(var, process.clone(), args),
&mut ExprStmt(ref mut expr) => visitor.visit_expr_stmt(expr),
&mut Universe(ref mut body) => visitor.visit_universe(&mut **body),
&mut QFUniverse(ref mut body) => visitor.visit_qf_universe(&mut **body),
&mut Nothing => visitor.visit_nothing(),
&mut LocalDrop(ref mut var_path) => visitor.visit_drop(var_path),
}
Expand Down

0 comments on commit 9b5d100

Please sign in to comment.