-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
196 additions
and
6 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
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
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 @@ | ||
//@execute false=111 | ||
|
||
type Value { | ||
case I32(val: u32); | ||
case I64(val: u64); | ||
} | ||
class Throwable { } | ||
class ArrayStack<T> { | ||
var elems = Array<T>.new(100); | ||
} | ||
class WasmStack { } | ||
|
||
type Result2 { | ||
case Return(vals: Range<Value>); | ||
case Throw(thrown: Throwable); | ||
case Suspend(stack: WasmStack, valrefs: Range<Value>); | ||
} | ||
|
||
enum StackState { | ||
EMPTY, // contains no frames | ||
SUSPENDED, // contains one or more frames, waiting for inputs | ||
RESUMABLE, // all inputs set; can be resumed | ||
RUNNING, // currently running Wasm or host code | ||
RETURNING, // used internally | ||
THROWING, // used internally | ||
} | ||
|
||
def resume(parent: WasmStack) -> Result2 { | ||
// Set the initial state to running and loop until return, throw, or suspend. | ||
// Return the appropriate result. | ||
var r: Result2; | ||
match (state_) { | ||
THROWING => { | ||
r = Result2.Throw(thrown); | ||
} | ||
RETURNING => { | ||
var vals = values.elems[0 ... 1]; | ||
r = Result2.Return(vals); | ||
} | ||
_ => { | ||
} | ||
} | ||
return r; | ||
} | ||
|
||
var thrown: Throwable; | ||
var state_: StackState; | ||
def values = ArrayStack<Value>.new(); | ||
|
||
def main(a: bool) -> int { | ||
var stack: WasmStack; | ||
if (a) { | ||
thrown = Throwable.new(); | ||
state_ = StackState.THROWING; | ||
stack = WasmStack.new(); | ||
values.elems[0] = Value.I32(11); | ||
values.elems[1] = Value.I32(12); | ||
values.elems[2] = Value.I64(13); | ||
values.elems = null; | ||
} | ||
resume(stack); | ||
return 111; | ||
} |
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,11 @@ | ||
//@execute -2=204797952; -1=204797952; 0=0; 1=0; 2=0 | ||
def main(a: int) -> int { | ||
var x = 99999; | ||
var shift: byte = if(a < 0, 11, 33); | ||
if (a < 0) { | ||
x = if(a == -1, x << shift, x << shift); | ||
} else { | ||
x = if(a == 1, x << shift, x << shift); | ||
} | ||
return x; | ||
} |
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,20 @@ | ||
//@execute -1=42; 0=249977; 1=499954; 2=62494; 3=976; 4=0; 5=976; 6=7811; 7=0; 8=42 | ||
def shift(a: bool, s1: byte, s2: byte) -> int { | ||
var x = 999909; | ||
if (a) x = x >> s1; | ||
else x = x >> s2; | ||
return x; | ||
} | ||
def main(a: int) -> int { | ||
match (a) { | ||
0 => return shift(false, 1, 2); | ||
1 => return shift(true, 1, 2); | ||
2 => return shift(false, 10, 4); | ||
3 => return shift(true, 10, 4); | ||
4 => return shift(false, 10, 44); | ||
5 => return shift(true, 10, 44); | ||
6 => return shift(false, 33, 7); | ||
7 => return shift(true, 33, 7); | ||
} | ||
return 42; | ||
} |
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,19 @@ | ||
//@execute -1=42; 0=999909; 1=499954; 2=999909; 3=976; 4=999909; 5=976; 6=999909; 7=0; 8=42 | ||
def shift(a: bool, s1: byte, s2: byte) -> int { | ||
var x = 999909; | ||
if (a) x = x >> s1; | ||
return x; | ||
} | ||
def main(a: int) -> int { | ||
match (a) { | ||
0 => return shift(false, 1, 2); | ||
1 => return shift(true, 1, 2); | ||
2 => return shift(false, 10, 4); | ||
3 => return shift(true, 10, 4); | ||
4 => return shift(false, 10, 44); | ||
5 => return shift(true, 10, 44); | ||
6 => return shift(false, 33, 7); | ||
7 => return shift(true, 33, 7); | ||
} | ||
return 42; | ||
} |
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,15 @@ | ||
//@execute 0=false; 1=true; 2=false; 3=false; 4=false | ||
def split(a: bool, f: float) -> bool { | ||
var r: bool; | ||
if (a) r = i32.?(f); | ||
return r; | ||
} | ||
def main(a: int) -> bool { | ||
match (a) { | ||
0 => return split(false, 0.0f); | ||
1 => return split(true, 0.0f); | ||
2 => return split(false, 1.1f); | ||
3 => return split(true, 1.1f); | ||
} | ||
return false; | ||
} |
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,13 @@ | ||
//@execute 0=true; 1=true; 2=true; 3=true; 2000000000=false | ||
def main(a: int) -> bool { | ||
var f = float.!(a) + 1.0f; | ||
var r: bool; | ||
match (a) { | ||
0 => r = i32.?(f); | ||
1 => r = i31.?(f); | ||
2 => r = i30.?(f); | ||
3 => r = i29.?(f); | ||
_ => r = i6.?(f); | ||
} | ||
return r; | ||
} |
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,13 @@ | ||
//@execute 0=1; 1=2; 2=3; 3=4; 2000000000=31 | ||
def main(a: int) -> int { | ||
var f = float.!(a) + 1.0f; | ||
var r: int; | ||
match (a) { | ||
0 => r = i32.truncf(f); | ||
1 => r = i31.truncf(f); | ||
2 => r = i30.truncf(f); | ||
3 => r = i29.truncf(f); | ||
_ => r = i6.truncf(f); | ||
} | ||
return r; | ||
} |
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
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,14 @@ | ||
//@execute -2=0; -1=4; 0=0; 1=4; 2=0 | ||
|
||
def x = "aabb"; | ||
def y: Array<byte>; | ||
|
||
def main(a: int) -> int { | ||
var z: Range<byte>; | ||
if (a < 0) { | ||
z = if(a == -1, x, y); | ||
} else { | ||
z = if(a == 1, x, y); | ||
} | ||
return z.length; | ||
} |
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,12 @@ | ||
//@execute -2=0; -1=4; 0=0; 1=0; 2=0 | ||
|
||
def x = "aabb"; | ||
def y: Array<byte>; | ||
|
||
def main(a: int) -> int { | ||
var z: Range<byte>; | ||
if (a < 0) { | ||
z = if(a == -1, x, y); | ||
} | ||
return z.length; | ||
} |