-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[runtime][compiler] Add the pause statement and test.
- Loading branch information
Showing
4 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
63 changes: 63 additions & 0 deletions
63
runtime/src/main/java/bonsai/runtime/synchronous/statements/Pause.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters