diff --git a/exec/binary_ops.mj b/exec/binary_ops.mj new file mode 100644 index 0000000000000000000000000000000000000000..da4fac0661077e3e6075cdbe214fc70fb6494ea1 --- /dev/null +++ b/exec/binary_ops.mj @@ -0,0 +1,26 @@ +class A { + public static void main(String[] args) { + System.out.println(2 - 1); // 1 + System.out.println(4 / 2); // 2 + System.out.println(1 + 2); // 3 + System.out.println(2 * 2); // 4 + System.out.println(11 % 6); // 5 + + if (false || true) { System.out.println(6); } + if (true || false) { System.out.println(7); } + if (true && false) { } else { System.out.println(8); } + if (true && true) { System.out.println(9); } + if (1 == 1) { System.out.println(10); } + if (1 == 2) { } else { System.out.println(11); } + if (1 != 2) { System.out.println(12); } + if (1 != 1) { } else { System.out.println(13); } + if (1 < 2) { System.out.println(14); } + if (1 < 1) { } else { System.out.println(15); } + if (2 > 1) { System.out.println(16); } + if (1 > 1) { } else { System.out.println(17); } + if (1 <= 1) { System.out.println(18); } + if (2 <= 1) { } else { System.out.println(19); } + if (1 >= 1) { System.out.println(20); } + if (1 >= 2) { } else { System.out.println(21); } + } +} diff --git a/exec/binary_ops.mj.out b/exec/binary_ops.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..759a7a36476c5d0ee315a9b79dc09c4d11b3e041 --- /dev/null +++ b/exec/binary_ops.mj.out @@ -0,0 +1,20 @@ +1 +2 +3 +4 +5 +6 +7 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 diff --git a/exec/can_call.mj b/exec/can_call.mj new file mode 100644 index 0000000000000000000000000000000000000000..d2b11f0f8e59d4d440e45ba11fc70858318aa3b0 --- /dev/null +++ b/exec/can_call.mj @@ -0,0 +1,11 @@ +class Foo { + public int ret_int() { + return 48; + } + + public static void main(String[] args) { + Foo a = new Foo(); + int b = a.ret_int(); + System.out.println(b); + } +} diff --git a/exec/can_call.mj.out b/exec/can_call.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..21e72e8ac3d7e23bd6532b5f1f4a6bdf8362e6cf --- /dev/null +++ b/exec/can_call.mj.out @@ -0,0 +1 @@ +48 diff --git a/exec/can_short_circuit.mj b/exec/can_short_circuit.mj new file mode 100644 index 0000000000000000000000000000000000000000..3954359c42b8ff403bd2d266daeb4657869c0510 --- /dev/null +++ b/exec/can_short_circuit.mj @@ -0,0 +1,35 @@ +class A { + public boolean side_effect() { + System.out.write(70); // + System.out.write(10); // newline + return false; + } + + public static void main(String[] args) { + A a = new A(); + if (true || a.side_effect()) { + System.out.write(79); // O + System.out.write(75); // K + System.out.write(10); // newline + } + + if (false && a.side_effect()) { + } else { + System.out.write(79); // O + System.out.write(75); // K + System.out.write(10); // newline + } + + if (!(false && a.side_effect())) { + System.out.write(79); // O + System.out.write(75); // K + System.out.write(10); // newline + } + + if ((true || a.side_effect()) && true) { + System.out.write(79); // O + System.out.write(75); // K + System.out.write(10); // newline + } + } +} diff --git a/exec/can_short_circuit.mj.out b/exec/can_short_circuit.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..b462a5a7baa4fe959ffeb8c904beeb2f0c97c996 --- /dev/null +++ b/exec/can_short_circuit.mj.out @@ -0,0 +1,4 @@ +OK +OK +OK +OK diff --git a/exec/field_init.mj b/exec/field_init.mj new file mode 100644 index 0000000000000000000000000000000000000000..1b088a1ae8b9f79536802f08d7866856bdc8af66 --- /dev/null +++ b/exec/field_init.mj @@ -0,0 +1,31 @@ +class A { + public int a; + + public void print_as() { + System.out.println(a); + System.out.println(this.a); + } + + public static void main(String[] args) { + A a = new A(); + a.print_as(); + B b = new B(); + + if (b.b) { + System.out.println(1); + } else { + System.out.println(0); + } + + if (b.c == null) { + System.out.println(0); + } else { + System.out.println(1); + } + } +} + +class B { + public boolean b; + public A c; +} diff --git a/exec/field_init.mj.out b/exec/field_init.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..44e0be8e3569542122ae0a5b046af7f8fe713943 --- /dev/null +++ b/exec/field_init.mj.out @@ -0,0 +1,4 @@ +0 +0 +0 +0 diff --git a/exec/if_else.mj b/exec/if_else.mj new file mode 100644 index 0000000000000000000000000000000000000000..62efd85c1d17fee3fc009fba35fc9c5362aec9d3 --- /dev/null +++ b/exec/if_else.mj @@ -0,0 +1,15 @@ +class Foo { + public static void main(String[] args) { + if (true) { + System.out.println(1); + } else { + System.out.println(0); + } + + if (false) { + System.out.println(0); + } else { + System.out.println(1); + } + } +} diff --git a/exec/if_else.mj.out b/exec/if_else.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..6ed281c757a969ffe22f3dcfa5830c532479c726 --- /dev/null +++ b/exec/if_else.mj.out @@ -0,0 +1,2 @@ +1 +1 diff --git a/exec/indirect_system_calls.mj b/exec/indirect_system_calls.mj new file mode 100644 index 0000000000000000000000000000000000000000..a0f74caba63f88c355d70d5dcbca55afc7817f7d --- /dev/null +++ b/exec/indirect_system_calls.mj @@ -0,0 +1,6 @@ +class A { + + public static void main(String[] args) { + ((System).out).println(4); + } +} diff --git a/exec/indirect_system_calls.mj.out b/exec/indirect_system_calls.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..b8626c4cff2849624fb67f87cd0ad72b163671ad --- /dev/null +++ b/exec/indirect_system_calls.mj.out @@ -0,0 +1 @@ +4 diff --git a/exec/invoke_object_returned_by_expression.mj b/exec/invoke_object_returned_by_expression.mj new file mode 100644 index 0000000000000000000000000000000000000000..d113020ad2405a4003b6df2cbc76768c8f07c698 --- /dev/null +++ b/exec/invoke_object_returned_by_expression.mj @@ -0,0 +1,19 @@ +class A { + public B get_object() { + return new B(); + } + + public static void main(String[] args) { + A a = new A(); + int res = (a.get_object()).get_number(); + System.out.println(res); + } +} + +class B { + + public int get_number() { + return 99; + } + +} diff --git a/exec/invoke_object_returned_by_expression.mj.out b/exec/invoke_object_returned_by_expression.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..3ad5abd03aea89f7de126c4861363e4f64355973 --- /dev/null +++ b/exec/invoke_object_returned_by_expression.mj.out @@ -0,0 +1 @@ +99 diff --git a/exec/multiassign.mj b/exec/multiassign.mj new file mode 100644 index 0000000000000000000000000000000000000000..05d333ed3208f10e9fdf1ca8d0b068be609e996f --- /dev/null +++ b/exec/multiassign.mj @@ -0,0 +1,9 @@ +eass A { + + public static void main(String[] args) { + int x = 8; + int y = x = 4; + System.out.println(x); + System.out.println(y); + } +} diff --git a/exec/multiassign.mj.out b/exec/multiassign.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..7290ba859f4adbf90d68526fe0ab1f8cbcf65098 --- /dev/null +++ b/exec/multiassign.mj.out @@ -0,0 +1,2 @@ +4 +4 diff --git a/exec/return.mj b/exec/return.mj new file mode 100644 index 0000000000000000000000000000000000000000..0e5df5e7bd20282047b82547d8dc90488af18cf0 --- /dev/null +++ b/exec/return.mj @@ -0,0 +1,12 @@ +class A { + + public int loopy_1() { + int i = 3; + while (i < 5) { return i; } + } + + public static void main(String[] args) { + System.out.println((new A()).loopy_1()); + } +} + diff --git a/exec/return.mj.out b/exec/return.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..00750edc07d6415dcc07ae0351e9397b0222b7ba --- /dev/null +++ b/exec/return.mj.out @@ -0,0 +1 @@ +3 diff --git a/exec/unary_ops.mj b/exec/unary_ops.mj new file mode 100644 index 0000000000000000000000000000000000000000..934bc55dbbfc3489c0ddb257548e5b7731da775a --- /dev/null +++ b/exec/unary_ops.mj @@ -0,0 +1,10 @@ +class A { + public static void main(String[] args) { + int x = 4; + System.out.println(-x); + + if (!false) { System.out.println(-3); } + if (!true) { } else { System.out.println(-2); } + if (!!!true) { } else { System.out.println(-1); } + } +} diff --git a/exec/unary_ops.mj.out b/exec/unary_ops.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..cc86190095aa23b86c2c6c6d4295f66fec0cec32 --- /dev/null +++ b/exec/unary_ops.mj.out @@ -0,0 +1,4 @@ +-4 +-3 +-2 +-1 diff --git a/exec/while.mj b/exec/while.mj new file mode 100644 index 0000000000000000000000000000000000000000..2b966fb2a41ca03fe838e663a4c5e5eb8b5eebf8 --- /dev/null +++ b/exec/while.mj @@ -0,0 +1,13 @@ +class A { + + public static void main(String[] args) { + int x = 0; + boolean a = false; + while(a) { x = 1; } + System.out.println(x); + + while(x < 5) { x = x + 1; } + System.out.println(x); + } +} + diff --git a/exec/while.mj.out b/exec/while.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..fd3306644d5e1b02d04173108535270ac9a218b5 --- /dev/null +++ b/exec/while.mj.out @@ -0,0 +1,2 @@ +0 +5