Skip to content

Commit

Permalink
[runtime][compiler] Add the pause statement and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptal committed Nov 14, 2018
1 parent b0d2c2c commit 2769f3d
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 5 deletions.
47 changes: 47 additions & 0 deletions data/test/run-pass/Delay.bonsai.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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(Delay.pauseNothing, "")]
#[run(Delay.onePausePrint, "1")]
#[run(Delay.twoPausePrint, "1234")]
#[run(Delay.pausePrintPause, "1")]
#[run(Delay.pausePrintPausePrint, "12")]
#[run(Delay.pauseDecl, "122")]

package test;

import java.lang.System;
import java.util.*;
import bonsai.runtime.lattices.LMax;

public class Delay
{
public proc pauseNothing() = pause; nothing end
public proc onePausePrint() = pause; System.out.println("1") end
public proc twoPausePrint() = pause; pause; System.out.println("1234") end

public proc pausePrintPause() = pause; System.out.print(1); pause; end
public proc pausePrintPausePrint() =
pause; System.out.print(1); pause; System.out.print(2); end

public proc pauseDecl() =
single_space LMax a = new LMax(1);
System.out.println(read a);
pause;
readwrite a.inc();
System.out.println(read a);
pause;
System.out.println(read a);
end
}
68 changes: 68 additions & 0 deletions data/test/run-pass/SeqUnivDelay.bonsai.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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(SeqUnivDelay.pauseNothing, "")]
#[run(SeqUnivDelay.onePausePrint, "1")]
#[run(SeqUnivDelay.delay3, "12")]
#[run(SeqUnivDelay.print123321, "123321")]
#[run(SeqUnivDelay.print1234321, "1234321")]

package test;

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

public class SeqUnivDelay
{
public proc pauseNothing() = universe pause; nothing end
public proc onePausePrint() = pause; universe System.out.println("1") end end
public proc delay3() =
pause; System.out.print("1");
universe pause; System.out.println("2") end;
pause
end

public proc print123321() =
System.out.print(1);
universe
System.out.print(2);
universe
System.out.print(3);
end;
pause;
universe
System.out.print(3);
end;
System.out.print(2);
end;
System.out.print(1);
end

public proc print1234321() =
System.out.print(1);
universe
System.out.print(2);
universe
System.out.print(3);
end;
pause;
System.out.print(4);
universe
System.out.print(3);
end;
System.out.print(2);
end;
System.out.print(1);
end
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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.

package bonsai.runtime.synchronous.statements;

import java.util.*;
import bonsai.runtime.core.*;
import bonsai.runtime.synchronous.*;
import bonsai.runtime.synchronous.interfaces.*;
import bonsai.runtime.synchronous.env.*;

public class Pause extends ASTNode implements Program
{
private CompletionCode k;
public Pause() {
super();
prepare();
}

public void prepare() {
k = CompletionCode.WAIT;
}

public void canInstant(int layersRemaining, Layer layer) {
checkNoSubLayer(layersRemaining, "Pause.canInstant");
}

public boolean canTerminate() {
return k == CompletionCode.TERMINATE;
}

public void abort(Layer layer) {}
public void suspend(Layer layer) {}

public CompletionCode execute(int layersRemaining, Layer layer){
checkNoSubLayer(layersRemaining, "Pause.execute");
if (k == CompletionCode.WAIT) {
k = CompletionCode.PAUSE;
}
else if (k == CompletionCode.PAUSE) {
k = CompletionCode.TERMINATE;
}
return k;
}

public boolean canWriteOn(int layersRemaining, String uid, boolean inSurface) {
checkNoSubLayer(layersRemaining, "Pause.canWriteOn");
return false;
}

public int countLayers() { return 0; }
}
14 changes: 9 additions & 5 deletions src/back/compiler/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ impl<'a> StatementCompiler<'a>
QFUniverse(body) => self.qf_universe(body),
Let(body) => self.let_decl(body),
Seq(branches) => self.sequence(branches),
DelayStmt(delay) => self.delay(delay),
// OrPar(branches) => self.or_parallel(branches),
// AndPar(branches) => self.and_parallel(branches),
// Space(branches) => self.space(branches),
// When(entailment, body) => self.when(entailment, body),
// Suspend(entailment, body) => self.suspend(entailment, body),
// Pause => self.pause(),
// PauseUp => self.pause_up(),
// Stop => self.stop(),
// Loop(body) => self.loop_stmt(body),
Expand Down Expand Up @@ -132,6 +132,14 @@ impl<'a> StatementCompiler<'a>
self.nary_operator("Sequence", branches);
}

fn delay(&mut self, delay: Delay) {
match delay.kind {
DelayKind::Pause => self.fmt.push("new Pause()"),
DelayKind::PauseUp => unimplemented!("statement unimplemented: pause up"),
DelayKind::Stop => unimplemented!("statement unimplemented: stop")
}
}

// fn binding(&mut self, binding: Binding, is_field: bool, uid_fn: &str)
// {
// match binding.kind {
Expand Down Expand Up @@ -264,10 +272,6 @@ impl<'a> StatementCompiler<'a>
// self.fmt.push(")");
// }

// fn pause(&mut self) {
// self.fmt.push("SC.stop()");
// }

// fn pause_up(&mut self) {
// self.fmt.push("new PauseUp()");
// }
Expand Down

0 comments on commit 2769f3d

Please sign in to comment.