-
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.
[variants] More unboxed variant tests (#217)
- Loading branch information
Showing
59 changed files
with
1,184 additions
and
1 deletion.
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,18 @@ | ||
//@execute =35 | ||
|
||
type U { | ||
case A(x: int); | ||
case B(y: int); | ||
} | ||
|
||
def f() -> (U, U) { | ||
return (U.A(12), U.B(23)); | ||
} | ||
|
||
def main() -> int { | ||
var a = f(); | ||
var b = f(); | ||
|
||
if (a != b) return -1; | ||
return U.A.!(a.0).x + U.B.!(a.1).y; | ||
} |
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,8 @@ | ||
//@execute 0=-11; 1=-51111 | ||
type U(x: int, y: int, z: int) #unboxed { } | ||
def x = [U(11, 22, 44), U(3333, 1111, 55555)]; | ||
|
||
def main(a: int) -> int { | ||
var u = x[a]; | ||
return u.x + u.y - u.z; | ||
} |
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,30 @@ | ||
//@execute 0=12;1=78;2=123 | ||
type A00 #unboxed { | ||
case X(x: i32, y: i64, z: i32); | ||
case Y(x: i32, y: i32); | ||
case Z(y: i32); | ||
} | ||
|
||
def x = A00.!(A00.X(12, 34, 56)); | ||
def y = A00.!(A00.Y(78, 90)); | ||
def z = A00.!(A00.Z(123)); | ||
|
||
def f(a: int) -> A00 { | ||
match (a) { | ||
0 => return x; | ||
1 => return y; | ||
2 => return z; | ||
} | ||
return A00.Z(123); | ||
} | ||
|
||
def main(a: int) -> int { | ||
if (f(a) != f(a)) return -1; | ||
|
||
match (a) { | ||
0 => return A00.X.!(f(a)).x; | ||
1 => return A00.Y.!(f(a)).x; | ||
2 => return A00.Z.!(f(a)).y; | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//@execute 0=100; 1=101 | ||
type MutCell<T> #unboxed { | ||
case Array(x: Array<T>, i: int) { } | ||
case Func(getf: void -> T, setf: T -> void) { } | ||
|
||
def get() -> T { | ||
match (this) { | ||
Array(x, i) => return x[i]; | ||
Func(getf, setf) => return getf(); | ||
} | ||
} | ||
def set(v: T) { | ||
match (this) { | ||
Array(x, i) => x[i] = v; | ||
Func(getf, setf) => return setf(v); | ||
} | ||
} | ||
} | ||
var y = 99; | ||
def get_y() -> int { return y; } | ||
def set_y(v: int) { y = v; } | ||
def cells = [ | ||
MutCell<int>.Array([0], 0), | ||
MutCell<int>.Func(get_y, set_y) | ||
]; | ||
def main(a: int) -> int { | ||
var cell = cells[a]; | ||
cell.set(a + 100); | ||
return cell.get(); | ||
} |
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,21 @@ | ||
//@execute 0=123; 1=-1 | ||
type Cell #unboxed { | ||
case Array(x: Array<int>); | ||
case Empty; | ||
|
||
def get() -> int { | ||
match (this) { | ||
Array(x) => return x[0]; | ||
Empty => return -1; | ||
} | ||
} | ||
} | ||
def cells = [ | ||
Cell.Array([123]), | ||
Cell.Empty | ||
]; | ||
|
||
def main(a: int) -> int { | ||
var cell = cells[a]; | ||
return cell.get(); | ||
} |
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,17 @@ | ||
//@execute 0=123 | ||
type Cell #unboxed { | ||
case Array(x: int); | ||
case Empty; | ||
|
||
def get() -> int { | ||
match (this) { | ||
Array(x) => return x; | ||
Empty => return -1; | ||
} | ||
} | ||
} | ||
|
||
def main(a: int) -> int { | ||
def cell = Cell.Array(123); | ||
return cell.get(); | ||
} |
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,22 @@ | ||
//@execute 0=123 | ||
type Cell #unboxed { | ||
case Array(x: Array<int>); | ||
case Empty; | ||
} | ||
|
||
def get(c: Cell) -> int { | ||
match (c) { | ||
Array(x) => return x[0]; | ||
Empty => return -1; | ||
} | ||
} | ||
|
||
def cells = [ | ||
Cell.Array([123]), | ||
Cell.Empty | ||
]; | ||
|
||
def main(a: int) -> int { | ||
var cell = cells[a]; | ||
return get(cell); | ||
} |
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,23 @@ | ||
//@execute 0=true;1=false;2=true;3=false | ||
type A00 #unboxed { | ||
case X; | ||
case Y(x: int); | ||
} | ||
|
||
def eq = A00.==; | ||
|
||
def main(a: int) -> bool { | ||
var a00_x: A00 = A00.X; | ||
var a00_x2: A00 = A00.X; | ||
var a00_y: A00 = A00.Y(12); | ||
var a00_y2: A00 = A00.Y(12); | ||
var a00_y3: A00 = A00.Y(13); | ||
|
||
match (a) { | ||
0 => return eq(a00_x, a00_x2); | ||
1 => return eq(a00_x, a00_y); | ||
2 => return eq(a00_y, a00_y2); | ||
3 => return eq(a00_y, a00_y3); | ||
} | ||
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,27 @@ | ||
//@execute =0 | ||
type A00 #unboxed { | ||
case X; | ||
case Y(x: int); | ||
} | ||
|
||
def eq(a: A00, b: A00) -> bool { | ||
return a == b; | ||
} | ||
|
||
def f() -> A00 { | ||
return A00.X; | ||
} | ||
|
||
def main() -> int { | ||
var x: A00 = A00.X; | ||
if (!eq(x, A00.X)) return -1; | ||
|
||
x = A00.Y(12); | ||
if (eq(x, A00.X)) return -2; | ||
if (!eq(x, A00.Y(12))) return -3; | ||
|
||
x = f(); | ||
if (!eq(x, A00.X)) return -4; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@execute 0=true | ||
type A00 #unboxed { | ||
case X(x: i32, y: i64, z: i32); | ||
case Y(x: i32, y: i32); | ||
case Z(y: i64); | ||
} | ||
|
||
def arr = [A00.X(12, 34, 56), A00.Y(12, 34), A00.Z(12)]; | ||
|
||
def main(a: int) -> bool { | ||
if (arr[0] != arr[0]) return false; | ||
|
||
return true; | ||
} |
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,17 @@ | ||
//@execute 0=true;1=false;2=true;3=false;4=true;5=false | ||
type A #unboxed { | ||
case X(b: B); | ||
case Y; | ||
} | ||
|
||
type B { | ||
case X(x: int); | ||
case Y(y: int); | ||
} | ||
|
||
def arr1 = [A.X(B.X(12)), A.X(B.X(12)), A.X(B.Y(34)), A.X(B.Y(56)), A.Y, A.Y]; | ||
def arr2 = [A.X(B.X(12)), A.X(B.X(34)), A.X(B.Y(34)), A.Y, A.Y, A.X(B.X(7))]; | ||
|
||
def main(a: int) -> bool { | ||
return arr1[a] == arr2[a]; | ||
} |
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,17 @@ | ||
//@execute 0=true;1=false;2=true;3=false;4=true;5=false | ||
type A { | ||
case X(b: B); | ||
case Y(y: int) #unboxed; | ||
} | ||
|
||
type B { | ||
case X(x: int); | ||
case Y(y: int); | ||
} | ||
|
||
def arr1 = [A.X(B.X(12)), A.X(B.X(12)), A.X(B.Y(34)), A.X(B.Y(56)), A.Y(99), A.Y(99)]; | ||
def arr2 = [A.X(B.X(12)), A.X(B.X(34)), A.X(B.Y(34)), A.Y(99), A.Y(99), A.X(B.X(7))]; | ||
|
||
def main(a: int) -> bool { | ||
return arr1[a] == arr2[a]; | ||
} |
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=true;1=true;2=true;3=true;4=true;5=true | ||
type T { | ||
case A(x: int); | ||
case B(y: int); | ||
case C(a: Array<int>) #unboxed; | ||
} | ||
|
||
def a: Array<int> = []; | ||
def b: Array<int> = [1, 2]; | ||
def arr1 = [T.A(0), T.A(10), T.B(20), T.B(30), T.C(a), T.C(b)]; | ||
def arr2 = [T.A(0), T.A(10), T.B(20), T.B(30), T.C(a), T.C(b)]; | ||
|
||
def main(a: int) -> bool { | ||
return arr1[a] == arr2[a]; | ||
} |
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=false;2=false;3=false;4=false;5=false | ||
type T { | ||
case A(x: int); | ||
case B(y: int); | ||
case C(a: Array<int>) #unboxed; | ||
} | ||
|
||
def a: Array<int> = []; | ||
def b: Array<int> = [1, 2]; | ||
def arr1 = [T.A(0), T.A(10), T.B(20), T.B(30), T.C(a), T.C(b)]; | ||
def arr2 = [T.B(20), T.B(30), T.C(a), T.C(b), T.A(0), T.A(10)]; | ||
|
||
def main(a: int) -> bool { | ||
return arr1[a] == arr2[a]; | ||
} |
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,22 @@ | ||
//@execute 0=123;1=456 | ||
type A00 #unboxed { | ||
case X { | ||
def val() -> i32 { return 123; } | ||
} | ||
case Y(a: i32) { | ||
def val() -> i32 { return a; } | ||
} | ||
|
||
def val() -> i32; | ||
} | ||
|
||
def main(a: int) -> int { | ||
var a00_x: A00 = A00.X; | ||
var a00_y: A00 = A00.Y(456); | ||
|
||
match (a) { | ||
0 => return a00_x.val(); | ||
1 => return a00_y.val(); | ||
_ => 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//@execute =35 | ||
type A00(x: int, y: int) #unboxed { | ||
def f() -> int { | ||
return x + y; | ||
} | ||
} | ||
|
||
def main() -> i32 { | ||
var x = A00(12, 23); | ||
|
||
return x.f(); | ||
} |
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,29 @@ | ||
//@execute 0=123;1=456;2=789;3=345;4=-456 | ||
type A00 #unboxed { | ||
case X { | ||
def val() -> i32 { return 123; } | ||
def f() -> i32 { return 345; } | ||
def g() -> i32 { return 789; } | ||
} | ||
case Y(a: i32) { | ||
def val() -> i32 { return a; } | ||
def f() -> i32 { return -a; } | ||
} | ||
|
||
def val() -> i32; | ||
def f() -> i32; | ||
} | ||
|
||
def main(a: int) -> i32 { | ||
var a00_x: A00 = A00.X; | ||
var a00_y: A00 = A00.Y(456); | ||
|
||
match (a) { | ||
0 => return a00_x.val(); | ||
1 => return a00_y.val(); | ||
2 => return A00.X.!(a00_x).g(); | ||
3 => return a00_x.f(); | ||
4 => return a00_y.f(); | ||
_ => return 0; | ||
} | ||
} |
Oops, something went wrong.