Skip to content

Commit

Permalink
[readonly] Add more execution tests (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer authored Feb 26, 2025
1 parent c63e78a commit 1dd55b8
Show file tree
Hide file tree
Showing 128 changed files with 1,793 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/readonly/array_init_id00.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@execute = false
def nn() -> array<byte> {
return ['0'];
}
def main() -> bool {
return nn() == nn();
}
7 changes: 7 additions & 0 deletions test/readonly/array_init_id01.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@execute = false
def nn() -> array<int> {
return [0];
}
def main() -> bool {
return nn() == nn();
}
5 changes: 5 additions & 0 deletions test/readonly/array_length01.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0 = 1
var array: array<int> = Array<int>.new(1);
def main(a: int) -> int {
return array.length;
}
5 changes: 5 additions & 0 deletions test/readonly/array_length02.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0 = 1
var x: array<int> = [0];
def main(a: int) -> int {
return x.length;
}
5 changes: 5 additions & 0 deletions test/readonly/array_length03.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0 = 3
var x: array<int> = [0, 1, 2];
def main(a: int) -> int {
return x.length;
}
5 changes: 5 additions & 0 deletions test/readonly/array_length06.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0 = 3
var x: Array<int> = [0, 1, 2];
def main(a: int) -> int {
return array<int>.length(x);
}
7 changes: 7 additions & 0 deletions test/readonly/array_length07.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@execute 0 = 3
var x: array<int> = [0, 1, 2];
def main(a: int) -> int {
var f = array<int>.length;
return f(x);
}

9 changes: 9 additions & 0 deletions test/readonly/array_length08.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@execute 0 = 3
var x: array<int> = [0, 1, 2];
def main(a: int) -> int {
var f = array<int>.length;
return do(f);
}
def do(f: array<int> -> int) -> int {
return f(x);
}
5 changes: 5 additions & 0 deletions test/readonly/array_length09.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0 = 2
var x: array<int> = Array<int>.new(1);
def main(a: int) -> int {
return x.length * 2;
}
18 changes: 18 additions & 0 deletions test/readonly/array_tuple00.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@execute 0='0'; 1='1'; 2=!BoundsCheckException; 3=!BoundsCheckException; 4=!BoundsCheckException; 5='0'; 6='x'; 7='y'; 8='z'
var a: array<(byte, byte)> = [('0', '1')];
var b: array<(byte, byte)>;
def main(arg: int) -> byte {
if (arg == 0) return a[0].0;
if (arg == 1) return a[0].1;
if (arg == 2) return a[1].0;
if (arg == 3) return a[1].1;
if (arg == 4) return a[2].0;
if (arg == 5) { b = a; return b[0].0; }
if (arg == 6) { b = [('x', 'y')]; return b[0].0; }
if (arg == 7) {
var b = Array<(byte, byte)>.new(2);
b[0] = ('x', 'y');
return b[0].1;
}
return 'z';
}
19 changes: 19 additions & 0 deletions test/readonly/array_tuple01.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@execute 0='0'; 1='1'; 2='2'; 3='3'; 4=!BoundsCheckException; 5='0'; 6='x'; 7='y'; 8='z'
var a: array<(byte, byte)> = [('0', '1'), ('2', '3')];
var b: array<(byte, byte)>;
def main(arg: int) -> byte {
if (arg == 0) return a[0].0;
if (arg == 1) return a[0].1;
if (arg == 2) return a[1].0;
if (arg == 3) return a[1].1;
if (arg == 4) return a[2].0;
if (arg == 5) { b = a; return b[0].0; }
if (arg == 6) { b = [('x', 'y')]; return b[0].0; }
if (arg == 7) {
var b = Array<(byte, byte)>.new(2);
b[0] = ('x', 'y');
return b[0].1;
}
return 'z';
}

18 changes: 18 additions & 0 deletions test/readonly/array_tuple02.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@execute 0='0'; 1='1'; 2='2'; 3='3'; 4=!BoundsCheckException; 5='0'; 6='x'; 7='y'; 8='z'
var a: array<(byte, int, byte)> = [('0', 48, '1'), ('2', 49, '3')];
var b: array<(byte, int, byte)>;
def main(arg: int) -> byte {
if (arg == 0) return a[0].0;
if (arg == 1) return a[0].2;
if (arg == 2) return a[1].0;
if (arg == 3) return a[1].2;
if (arg == 4) return a[2].0;
if (arg == 5) { b = a; return b[0].0; }
if (arg == 6) { b = [('x', 33, 'y')]; return b[0].0; }
if (arg == 7) {
var b = Array<(byte, int, byte)>.new(2);
b[0] = ('x', 34, 'y');
return b[0].2;
}
return 'z';
}
23 changes: 23 additions & 0 deletions test/readonly/array_tuple04.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@execute 0='0'; 1='1'; 2='2'; 3='3'; 4=!BoundsCheckException; 5='0'; 6='x'; 7='y'; 8='z'
class C {
def i: int;
new(i) { }
}
var a: array<(byte, C)> = [('0', C.new('1')), ('2', C.new('3'))];
var b: array<(byte, C)>;
def main(arg: int) -> byte {
if (arg == 0) return a[0].0;
if (arg == 1) return byte.view(a[0].1.i);
if (arg == 2) return a[1].0;
if (arg == 3) return byte.view(a[1].1.i);
if (arg == 4) return a[2].0;
if (arg == 5) { b = a; return b[0].0; }
if (arg == 6) { b = [('x', C.new('y'))]; return b[0].0; }
if (arg == 7) {
var b = Array<(byte, C)>.new(2);
b[0] = ('x', C.new('y'));
return byte.view(b[0].1.i);
}
return 'z';
}

27 changes: 27 additions & 0 deletions test/readonly/array_tuple05.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//@execute 0='0'; 1='1'; 2='2'; 3='3'; 4=!BoundsCheckException; 5='0'; 6='x'; 7='y'; 8='z'
class Cb {
def c: byte;
new(c) { }
}
class Ca {
def i: int;
new(i) { }
}
var a: array<(Cb, Ca)> = [(Cb.new('0'), Ca.new('1')), (Cb.new('2'), Ca.new('3'))];
var b: array<(Cb, Ca)>;
def main(arg: int) -> byte {
if (arg == 0) return a[0].0.c;
if (arg == 1) return byte.view(a[0].1.i);
if (arg == 2) return a[1].0.c;
if (arg == 3) return byte.view(a[1].1.i);
if (arg == 4) return a[2].0.c;
if (arg == 5) { b = a; return b[0].0.c; }
if (arg == 6) { b = [(Cb.new('x'), Ca.new('y'))]; return b[0].0.c; }
if (arg == 7) {
var b = Array<(Cb, Ca)>.new(2);
b[0] = (Cb.new('x'), Ca.new('y'));
return byte.view(b[0].1.i);
}
return 'z';
}

8 changes: 8 additions & 0 deletions test/readonly/array_tuple06.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@execute 0=0; 1=1; 2=2
def main(arg: int) -> int {
return n(arg).length;
}
def n(l: int) -> array<(int, int)> {
return Array<(int, int)>.new(l);
}

7 changes: 7 additions & 0 deletions test/readonly/array_tuple07.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@execute 0=0; 1=1; 2=2
def main(arg: int) -> int {
return n(arg)[0].0;
}
def n(l: int) -> array<(int, int)> {
return [(l, 0)];
}
8 changes: 8 additions & 0 deletions test/readonly/array_tuple08.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@execute 0=0; 1=1; 2=2
def main(arg: int) -> int {
return n(arg).length;
}
def n(l: int) -> array<(int, int)> {
var a = Array<(int, int)>.new(l);
return a;
}
7 changes: 7 additions & 0 deletions test/readonly/array_tuple09.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@execute 0=!NullCheckException
def main(arg: int) -> int {
return n().length;
}
def n() -> array<(int, int)> {
return null;
}
8 changes: 8 additions & 0 deletions test/readonly/array_tuple10.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@execute 0=!NullCheckException; 1=1
def main(arg: int) -> int {
return n(arg).length;
}
def n(len: int) -> array<(int, int)> {
if (len == 0) return null;
return Array<(int, int)>.new(len);
}
7 changes: 7 additions & 0 deletions test/readonly/array_tuple11.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@execute 0=0; 1=1; 2=2
def main(arg: int) -> int {
return n(arg)[1].0;
}
def n(l: int) -> array<(int, int)> {
return [(l, 0), (l, 1)];
}
5 changes: 5 additions & 0 deletions test/readonly/array_tuple12.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0=0; 1=1
def main(arg: int) -> int {
var a: array<(int, int)> = Array<(int, int)>.new(arg);
return a.length;
}
5 changes: 5 additions & 0 deletions test/readonly/array_tuple13.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0=!NullCheckException
def main(arg: int) -> int {
var a: array<(int, int)>;
return a.length;
}
5 changes: 5 additions & 0 deletions test/readonly/array_tuple15.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0=1; 1=2; 3=!BoundsCheckException
def x: array<(int, void)> = [(1, ()), (2, ())];
def main(a: int) -> int {
return x[a].0;
}
5 changes: 5 additions & 0 deletions test/readonly/array_tuple16.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0=1; 1=2; 3=!BoundsCheckException
def x: array<(int, void)> = [(1, ()), (2, ())];
def main(a: int) -> int {
return (x[a].0, x[a].1).0;
}
7 changes: 7 additions & 0 deletions test/readonly/array_tuple17.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@execute 0=1; 1=2; 3=!BoundsCheckException
component array_tuple17 {
def x: array<(array_tuple17, int, void)> = [(this, 1, ()), (this, 2, ())];
def main(a: int) -> int {
return (x[a].0, x[a].1, x[a].2).1;
}
}
15 changes: 15 additions & 0 deletions test/readonly/array_tuple23.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@execute 0=true; 1=true; 2=false
def main(a: int) -> bool {
def array = [((), true, 'b', 88), ((), false, 'c', 87)];
if (a == 0) return check(array, 0, (), true, 'b', 88);
if (a == 1) return check(array, 1, (), false, 'c', 87);
return false;
}
def check(x: array<(void, bool, byte, int)>, i: int, a: void, b: bool, c: byte, d: int) -> bool {
var t = x[i];
if (a != t.0) return false;
if (b != t.1) return false;
if (c != t.2) return false;
if (d != t.3) return false;
return true;
}
10 changes: 10 additions & 0 deletions test/readonly/ascii02.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@execute 0=true
var alpha: array<byte> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
def main(arg: int) -> bool {
var i = 0;
while (i < alpha.length) {
if (alpha[i] != 65 + i) return false;
i = i + 1;
}
return true;
}
10 changes: 10 additions & 0 deletions test/readonly/ascii03.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@execute 0=true
var alpha: array<byte> = "abcdefghijklmnopqrstuvwxyz";
def main(arg: int) -> bool {
var i = 0;
while (i < alpha.length) {
if (alpha[i] != 97 + i) return false;
i = i + 1;
}
return true;
}
21 changes: 21 additions & 0 deletions test/readonly/big_param07.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@execute (0, 1, 2, 3)=-236; (3, 2, 1, 0)=175; (5, 6, 7, 9)=-54
def x: array<int> = [0x4c, 0x8c, 0x65, 0x8b, 0xed, 0x3c, 0xe8, 0xd1, 0xb5, 0xcf, 0x53, 0x4c, 0x13, 0x8f, 0x79, 0x6d];
var index: int;
def main(a: int, b: int, c: int, d: int) -> int {
index = 0;
var x = f(a, b, c, d, (a, a, b, b), (c, c, d, d));
var y = f(a, b, c, d, (b, a, b, a), (d, c, d, c));
var z = f(a, b, c, d, (c, d, d, c), (a, b, b, a));
var w = f(a, b, c, d, (d, a, b, c), (c, d, a, b));
return x - y + z - w;
}
def f(a: int, b: int, c: int, d: int, e: (int, int, int, int), f: (int, int, int, int)) -> int {
return g(d, a, b, c) + g(e.0, e.1, e.2, e.3) + g(f.3, f.0, f.1, f.2);
}
def g(a: int, b: int, c: int, d: int) -> int {
return get(a) - get(b) + get(c) - get(d);
}
def get(i: int) -> int {
return x[(i + index++) & 0xF];
}

27 changes: 27 additions & 0 deletions test/readonly/big_param08.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//@execute (0, 1, 2, 3)=-123; (3, 2, 1, 0)=438; (5, 6, 7, 9)=-356
def x: array<int> = [0x4c, 0x8c, 0x65, 0x8b, 0xed, 0x3c, 0xe8, 0xd1, 0xb5, 0xcf, 0x53, 0x4c, 0x13, 0x8f, 0x79, 0x6d];
var index: int;
def main(a: int, b: int, c: int, d: int) -> int {
index = 0;
var x = f(a, b, c, d, (a, a, b, b), (c, c, d, d));
var y = f(a, b, c, d, (b, a, b, a), (d, c, d, c));
var z = f(a, b, c, d, (c, d, d, c), (a, b, b, a));
var w = f(a, b, c, d, (d, a, b, c), (c, d, a, b));
return x - y + z - w;
}
def f(a: int, b: int, c: int, d: int, e: (int, int, int, int), f: (int, int, int, int)) -> int {
var x = h(d, a, b, c, (e.0, e.1, e.2, e.3), (f.3, f.0, f.1, f.2));
var y = h(d, a, c, b, (e.0, e.1, e.2, e.3), (d, c, b, a));
var z = h(d, c, b, c, (f.0, f.1, f.2, f.3), (f.3, f.0, f.1, f.2));
var w = h(e.0, e.1, e.2, e.3, (a, b, c, d), (f.3, f.0, f.1, f.2));
return w - x + y - z;
}
def h(a: int, b: int, c: int, d: int, e: (int, int, int, int), f: (int, int, int, int)) -> int {
return g(d, a, b, c) + g(e.0, e.1, e.2, e.3) + g(f.3, f.0, f.1, f.2);
}
def g(a: int, b: int, c: int, d: int) -> int {
return get(a) - get(b) + get(c) - get(d);
}
def get(i: int) -> int {
return x[(i + index++) & 0xF];
}
5 changes: 5 additions & 0 deletions test/readonly/bin02.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 0=0; 1=1; 2=2; 3=3; 4=4; 5=5; 6=6; 7=7; 8=8; 9=9; 10=10; 11=11; 12=12; 13=13; 14=14; 15=15
var c: array<int> = [0b0, 0b1, 0b10, 0b11, 0b100, 0b101, 0b110, 0b111, 0b1000, 0b1001, 0b1010, 0b1011, 0b1100, 0b1101, 0b1110, 0b1111];
def main(a: int) -> int {
return c[a];
}
5 changes: 5 additions & 0 deletions test/readonly/byte_int15.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute 95=false; 97=true; 98=false
def main(arg: int) -> bool {
var a: array<int> = ['a'];
return a[0] == arg;
}
5 changes: 5 additions & 0 deletions test/readonly/byte_int16.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@execute (95, 'a')=false; (97, 'a')=true; (98, 'x')=false
def main(arg: int, b: byte) -> bool {
var a: array<int> = [b];
return a[0] == arg;
}
11 changes: 11 additions & 0 deletions test/readonly/byte_io07.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@execute 0=0; 1=1; 257=4; 65549=18; 1000000000=1789
def main(a: int) -> int {
var f: array<byte> = [
byte.view(a),
byte.view(a >> 8),
byte.view(a >> 16),
byte.view(a >> 24)
];

return f[0] + f[1] * 3 + f[2] * 5 + f[3] * 7;
}
12 changes: 12 additions & 0 deletions test/readonly/byte_io10.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@execute 0=0; 1=1; 257=4; 65549=18; 1000000000=1789
var f: Array<byte> = Array.new(4);
def main(a: int) -> int {
var f: array<byte> = [
byte.view(a),
byte.view(a >> 8),
byte.view(a >> 16),
byte.view(a >> 24)
];

return f[0] + f[1] * 3 + f[2] * 5 + f[3] * 7;
}
Loading

0 comments on commit 1dd55b8

Please sign in to comment.