Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for eval order and side effects examples + bugfix #166

Merged
merged 6 commits into from Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler-lib/src/firm/method_body_generator.rs
Expand Up @@ -269,13 +269,13 @@ impl<'a, 'ir, 'src, 'ast> MethodBodyGenerator<'ir, 'src, 'ast> {
&mut self,
res_expr: &Option<Box<Spanned<'src, ast::Expr<'src>>>>,
) -> LastBlockJumps {
let mem = self.graph.cur_store();
let res = res_expr.as_ref().map(|res_expr| {
self.gen_expr(&*res_expr)
.enforce_value(self.graph)
.mature_entry()
});

let mem = self.graph.cur_store();
let ret = self.graph.cur_block().new_return(mem, res);

self.graph.end_block().add_pred(&ret);
Expand Down
13 changes: 13 additions & 0 deletions integration-tests/binary/eval_order.mj
@@ -0,0 +1,13 @@
class EvalOrder {
public int n;
public static void main(String[] args) {
EvalOrder a = new EvalOrder();
int x = a.u();
System.out.println(x);
System.out.println(a.n);
}

public int u() {
return n = 42;
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/eval_order.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/eval_order.out.exitcode
@@ -0,0 +1 @@
0
Empty file.
2 changes: 2 additions & 0 deletions integration-tests/binary/eval_order.out.stdout
@@ -0,0 +1,2 @@
42
42
11 changes: 11 additions & 0 deletions integration-tests/binary/jls_15_12_4.mj
@@ -0,0 +1,11 @@
class Test {
public static void main(String[] args) {
Test t = new Test();
t.test(1).test(2);
}

public Test test(int i) {
System.out.println(i);
return this;
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_12_4.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_12_4.out.exitcode
@@ -0,0 +1 @@
0
Empty file.
2 changes: 2 additions & 0 deletions integration-tests/binary/jls_15_12_4.out.stdout
@@ -0,0 +1,2 @@
1
2
13 changes: 13 additions & 0 deletions integration-tests/binary/jls_15_13_1_1.mj
@@ -0,0 +1,13 @@
class Test1 {
public static void main(String[] args) {
int[] a = new int[2];
a[0] = 10;
a[1] = 11;
int[] b = new int[3];
b[0] = 2;
b[1] = 1;
b[2] = 0;

System.out.println(a[(a=b)[2]]);
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_13_1_1.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_13_1_1.out.exitcode
@@ -0,0 +1 @@
0
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_13_1_1.out.stdout
@@ -0,0 +1 @@
10
21 changes: 21 additions & 0 deletions integration-tests/binary/jls_15_13_1_2.mj
@@ -0,0 +1,21 @@
class Test2 {
public static void main(String[] args) {
Test2 t = new Test2();
System.out.println(t.array()[t.test()]);
}

public int[] array() {
System.out.println(5);
int[] ret = new int[3];
ret[0] = 5;
ret[1] = 5;
ret[2] = 5;
int x = 1 / 0;
return ret;
}

public int test() {
System.out.println(10);
return 0;
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_13_1_2.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_13_1_2.out.exitcode
@@ -0,0 +1 @@
terminated by signal or crashed.
Empty file.
Empty file.
19 changes: 19 additions & 0 deletions integration-tests/binary/jls_15_13_1_3.mj
@@ -0,0 +1,19 @@
class Test3 {
public static void main(String[] args) {
Test3 t = new Test3();
int[][] arr = new int[3][];
int i = 0;
while (i < 3) {
arr[i] = new int[1];
arr[i][0] = 5;
i = i + 1;
}
System.out.println(arr[t.test(1)][t.test(2)]);
}

public int test(int i) {
System.out.println(i);
int x = 1 / 0;
return 0;
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_13_1_3.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_13_1_3.out.exitcode
@@ -0,0 +1 @@
terminated by signal or crashed.
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions integration-tests/binary/jls_15_26.mj
@@ -0,0 +1,17 @@
class Test {
public int i;
public static void main(String[] args) {
Test t = new Test();
t.getTest().i = t.test();
}

public int test() {
System.out.println(10);
return 10;
}

public Test getTest() {
this.i = 1 / 0;
return this;
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_26.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_26.out.exitcode
@@ -0,0 +1 @@
terminated by signal or crashed.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions integration-tests/binary/jls_15_7_1_1.mj
@@ -0,0 +1,7 @@
class Test1 {
public static void main(String[] args) {
int i = 2;
int j = (i=3) * i;
System.out.println(j);
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_1_1.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_1_1.out.exitcode
@@ -0,0 +1 @@
0
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_1_1.out.stdout
@@ -0,0 +1 @@
9
7 changes: 7 additions & 0 deletions integration-tests/binary/jls_15_7_1_2.mj
@@ -0,0 +1,7 @@
class Test2 {
public static void main(String[] args) {
int a = 9;
a = a + (a = 3);
System.out.println(a);
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_1_2.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_1_2.out.exitcode
@@ -0,0 +1 @@
0
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_1_2.out.stdout
@@ -0,0 +1 @@
12
16 changes: 16 additions & 0 deletions integration-tests/binary/jls_15_7_1_3.mj
@@ -0,0 +1,16 @@
class Test3 {
public static void main(String[] args) {
Test3 t = new Test3();
int i = t.forgetIt() / t.test();
}

public int forgetIt() {
System.out.println(1);
return 1 / 0;
}

public int test() {
System.out.println(2);
return 1;
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_1_3.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_1_3.out.exitcode
@@ -0,0 +1 @@
terminated by signal or crashed.
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions integration-tests/binary/jls_15_7_2.mj
@@ -0,0 +1,13 @@
class Test {
public static void main(String[] args) {
Test t = new Test();
int divisor = 0;
int i = 1 / (divisor * t.loseBig());
}

public int loseBig() {
System.out.println(42);
System.out.flush();
return 42;
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_2.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_2.out.exitcode
@@ -0,0 +1 @@
terminated by signal or crashed.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_2.out.stdout
@@ -0,0 +1 @@
42
12 changes: 12 additions & 0 deletions integration-tests/binary/jls_15_7_3.mj
@@ -0,0 +1,12 @@
class Test {
public static void main(String[] args) {
Test t = new Test();
int x = t.test(1) + t.test(2) * t.test(3) + (t.test(4) + t.test(5)) * t.test(6);
System.out.println(x);
}

public int test(int i) {
System.out.println(i);
return i;
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_3.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_3.out.exitcode
@@ -0,0 +1 @@
0
Empty file.
7 changes: 7 additions & 0 deletions integration-tests/binary/jls_15_7_3.out.stdout
@@ -0,0 +1,7 @@
1
2
3
4
5
6
61
12 changes: 12 additions & 0 deletions integration-tests/binary/jls_15_7_4.mj
@@ -0,0 +1,12 @@
class Test1 {
public static void main(String[] args) {
Test1 t = new Test1();
int s = 1;
t.print3(s, s, s = 2);
}
public void print3(int a, int b, int c) {
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_4.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/jls_15_7_4.out.exitcode
@@ -0,0 +1 @@
0
Empty file.
3 changes: 3 additions & 0 deletions integration-tests/binary/jls_15_7_4.out.stdout
@@ -0,0 +1,3 @@
1
1
2
66 changes: 66 additions & 0 deletions integration-tests/binary/side_effects.mj
@@ -0,0 +1,66 @@
class Main {
public int i;
public static void main(String[] args) {
Main m = new Main();
int x = m.ret_side(); /* prints 0 */

System.out.write(10);

m.i = 1;
m.getSelf().i = 10; /* prints 1 */
if (m.getSelfChangeI(2).i == 2) {
System.out.println(2);
m.getSelfChangeI(2).i = 10;
if (m.i == 10) {
System.out.println(3);
}
}

System.out.write(10);

int[] arr = new int[10];
x = 0;
int y = 1;
if (arr[arr[x] = y] == 0 && arr[x] == 1) {
System.out.println(2);
}

System.out.write(10);

y = 3;
arr[(x = y)] = x;
System.out.println(x); /* prints 3 */
System.out.println(y); /* prints 3 */
System.out.println(arr[x]); /* prints 3 */
System.out.println(arr[y]); /* prints 3 */

System.out.write(10);

m.side_effect(0, m.side_effect(1, m.side_effect(2, 0))); /* prints 210 */
}

public int side_int() {
System.out.println(0);
return 0;
}

public int ret_side() {
return side_int();
}

public Main getSelf() {
System.out.println(this.i);
return this;
}

public Main getSelfChangeI(int i) {
this.i = i;
return this;
}

public int side_effect(int print, int fn) {
System.out.println(print);
return fn;
}
}

1 change: 1 addition & 0 deletions integration-tests/binary/side_effects.mj.exitcode
@@ -0,0 +1 @@
0
Empty file.
Empty file.
1 change: 1 addition & 0 deletions integration-tests/binary/side_effects.out.exitcode
@@ -0,0 +1 @@
0
Empty file.
16 changes: 16 additions & 0 deletions integration-tests/binary/side_effects.out.stdout
@@ -0,0 +1,16 @@
0

1
2
3

2

3
3
3
3

2
1
0