diff options
-rw-r--r-- | boil.sh | 17 | ||||
-rw-r--r-- | boil/library/BoilSimp.java | 46 | ||||
-rw-r--r-- | boil/tests/ex1.java | 11 | ||||
-rw-r--r-- | boil/tests/ex1.vapor | 5 | ||||
-rw-r--r-- | boil/tests/ex2.vapor | 11 | ||||
-rw-r--r-- | boil/tests/ex31.java | 2 | ||||
-rw-r--r-- | boil/tests/ex32.java | 2 | ||||
-rw-r--r-- | boil/tests/ex33.java | 5 | ||||
-rw-r--r-- | boil/tests/ex34.java | 20 | ||||
-rw-r--r-- | boil/tests/ex35.java | 13 | ||||
-rw-r--r-- | vaporize/tests/BinaryTree.opt.vapor (renamed from boil/tests/BinaryTree.opt.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/BinaryTree.vapor (renamed from boil/tests/BinaryTree.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/BubbleSort.opt.vapor (renamed from boil/tests/BubbleSort.opt.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/BubbleSort.vapor (renamed from boil/tests/BubbleSort.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/Factorial.opt.vapor (renamed from boil/tests/Factorial.opt.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/Factorial.vapor (renamed from boil/tests/Factorial.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/LinearSearch.opt.vapor (renamed from boil/tests/LinearSearch.opt.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/LinearSearch.vapor (renamed from boil/tests/LinearSearch.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/LinkedList.opt.vapor (renamed from boil/tests/LinkedList.opt.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/LinkedList.vapor (renamed from boil/tests/LinkedList.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/MoreThan4.opt.vapor (renamed from boil/tests/MoreThan4.opt.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/MoreThan4.vapor (renamed from boil/tests/MoreThan4.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/QuickSort.opt.vapor (renamed from boil/tests/QuickSort.opt.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/QuickSort.vapor (renamed from boil/tests/QuickSort.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/ShortCircuit.opt.vapor (renamed from boil/tests/ShortCircuit.opt.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/ShortCircuit.vapor (renamed from boil/tests/ShortCircuit.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/TreeVisitor.opt.vapor (renamed from boil/tests/TreeVisitor.opt.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/TreeVisitor.vapor (renamed from boil/tests/TreeVisitor.vapor) | 0 | ||||
-rw-r--r-- | vaporize/tests/ex30.vapor (renamed from boil/tests/ex30.vapor) | 0 |
29 files changed, 89 insertions, 43 deletions
@@ -0,0 +1,17 @@ +#!/bin/sh + +for i in ./boil/tests/*.java; do + [ -f "$i" ] || break + n=${i%.java} + javac -g $i + + expected=$(java -cp ./boil/tests/ ${n##*/}) + + java J2V < $i > test.vapor + actual=$(java -jar vapor.jar run test.vapor) + + echo -n "$(basename ${i}): " + [[ $expected == $actual ]] && echo 'PASSED' || echo -e "FAILED" +done + +rm test.vapor diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java index 9a69b2c..fd5b389 100644 --- a/boil/library/BoilSimp.java +++ b/boil/library/BoilSimp.java @@ -166,7 +166,7 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { } this.vapor += "\n"; n.f2.accept(this, symt); - n.f3.accept(this, symt); + // n.f3.accept(this, symt); n.f4.accept(this, symt); n.f5.accept(this, symt); @@ -212,7 +212,7 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { TypeInstance t = symt.getType(id); this.vapor += String.format(" %s = HeapAllocZ(%d)\n", this.tf.alias(t), - t.getSize()); // FIXME add proper allocation size + t.getSize()); this.vapor += String.format(" if0 %s goto :error\n", this.tf.alias(symt.getType(id))); n.f2.accept(this, symt); @@ -254,19 +254,22 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { for (TypeInstance attr : symt.getMethod(id) .getClassInstance() .getLocals()) { - String.format(" %s = this\n", - this.tf.alias(attr)); + this.vapor += String.format(" %s = this\n", + this.tf.alias(attr)); } n.f7.accept(this, symt); n.f8.accept(this, symt); n.f9.accept(this, symt); - n.f10.accept(this, symt); // FIXME + String ret = n.f10.accept(this, symt); // FIXME n.f11.accept(this, symt); n.f12.accept(this, symt); - this.vapor += " ret\n\n"; - + TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); + this.vapor += String.format(" %s = %s\n ret %s\n\n", + this.tf.alias(tp1), + ret, + this.tf.alias(tp1)); symt.removeActive(TypeEnum.method); return mod; @@ -389,10 +392,20 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { String mod = ""; String id = n.f0.accept(this, symt); - vapor += String.format(" [%s] = ", this.tf.alias(symt.getType(id))); + + ClassInstance cls; + int attr_index = (cls = symt.getClass(symt.getActive(TypeEnum.classname))) + .getLocals().indexOf(symt.getType(id)) * 4; + + if (attr_index < 0) + attr_index = 0; + else + attr_index += cls.getMethods().size() * 4; + n.f1.accept(this, symt); - vapor += n.f2.accept(this, symt); + n.f2.accept(this, symt); n.f3.accept(this, symt); + return mod; } @@ -472,8 +485,8 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); vapor += String.format(" %s = %s\n", - this.tf.alias(tp1), - expr); + this.tf.alias(tp1), + expr); vapor += String.format(" PrintIntS(%s)\n", this.tf.retrieveRecentList(1)); @@ -625,6 +638,9 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { TypeInstance cur = symt.getType(id); + System.out.println("id: " + id); + System.out.println("id2: " + id2); + System.out.println("cur: " + symt.getType(id)); int mtdIndex = cur.getClassInstance() .getMethods().indexOf(symt.getMethod(id2)) * 4; @@ -778,11 +794,15 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { String mod = ""; n.f0.accept(this, symt); String cls = n.f1.accept(this, symt); - mod += String.format(":functable_%s\n", cls); + vapor += String.format(" [%s+%d] = :functable_%s\n", + this.tf.retrieveRecentList(1), + 0, + cls); + System.out.println(vapor); n.f2.accept(this, symt); n.f3.accept(this, symt); - return mod; + return cls; } /** diff --git a/boil/tests/ex1.java b/boil/tests/ex1.java deleted file mode 100644 index 22f0aa0..0000000 --- a/boil/tests/ex1.java +++ /dev/null @@ -1,11 +0,0 @@ -class ex1{ - public static void main(String[] a){ - System.out.println(1); - } -} - -class A { - public int foo() { - return 1 ; - } -} diff --git a/boil/tests/ex1.vapor b/boil/tests/ex1.vapor deleted file mode 100644 index bcfb38c..0000000 --- a/boil/tests/ex1.vapor +++ /dev/null @@ -1,5 +0,0 @@ -const functable_A - :A_foo - -func A_foo(this) - ret
\ No newline at end of file diff --git a/boil/tests/ex2.vapor b/boil/tests/ex2.vapor deleted file mode 100644 index 25811b3..0000000 --- a/boil/tests/ex2.vapor +++ /dev/null @@ -1,11 +0,0 @@ -const functable_A - :A_foo - -const functable_B - :B_bar - -func A_foo (this) - ret - -func B_bar(this) - ret
\ No newline at end of file diff --git a/boil/tests/ex31.java b/boil/tests/ex31.java index d5a6980..d276e68 100644 --- a/boil/tests/ex31.java +++ b/boil/tests/ex31.java @@ -1,5 +1,5 @@ class ex31 { - public static void main(String[] a) { + public static void main(String[] z) { A a ; a = new A() ; } diff --git a/boil/tests/ex32.java b/boil/tests/ex32.java index 2527e04..4ab80d6 100644 --- a/boil/tests/ex32.java +++ b/boil/tests/ex32.java @@ -1,5 +1,5 @@ class ex32 { - public static void main(String[] a) { + public static void main(String[] z) { A a ; a = new A() ; System.out.println(a.foo(12, 14, 15, 12 + 23)) ; diff --git a/boil/tests/ex33.java b/boil/tests/ex33.java index 3325ea8..d0eb045 100644 --- a/boil/tests/ex33.java +++ b/boil/tests/ex33.java @@ -1,5 +1,5 @@ class ex33 { - public static void main(String[] a) { + public static void main(String[] z) { A a ; a = new A() ; System.out.println(a.bar(0-1, 400, 6*7)) ; @@ -8,6 +8,9 @@ class ex33 { } class A { + + int o ; + public int foo(int a, int b) { return 22 ; } diff --git a/boil/tests/ex34.java b/boil/tests/ex34.java new file mode 100644 index 0000000..eb5b18f --- /dev/null +++ b/boil/tests/ex34.java @@ -0,0 +1,20 @@ +class ex34 { + public static void main(String[] z) { + A a ; + a = new A() ; + System.out.println(1) ; + System.out.println(a.foo(2)) ; + } +} + +class A { + + int c ; + + public int foo(int b) { + int c ; + c = 42 ; + return c ; + } + +} diff --git a/boil/tests/ex35.java b/boil/tests/ex35.java new file mode 100644 index 0000000..32c855b --- /dev/null +++ b/boil/tests/ex35.java @@ -0,0 +1,13 @@ +class ex35{ + public static void main(String[] a){ + System.out.println(new Fac().ComputeFac(10)); + } +} + +class Fac { + public int ComputeFac(int num){ + int num_aux ; + num_aux = 4 ; + return num_aux ; + } +} diff --git a/boil/tests/BinaryTree.opt.vapor b/vaporize/tests/BinaryTree.opt.vapor index ef6ac4e..ef6ac4e 100644 --- a/boil/tests/BinaryTree.opt.vapor +++ b/vaporize/tests/BinaryTree.opt.vapor diff --git a/boil/tests/BinaryTree.vapor b/vaporize/tests/BinaryTree.vapor index 275cfe3..275cfe3 100644 --- a/boil/tests/BinaryTree.vapor +++ b/vaporize/tests/BinaryTree.vapor diff --git a/boil/tests/BubbleSort.opt.vapor b/vaporize/tests/BubbleSort.opt.vapor index a118894..a118894 100644 --- a/boil/tests/BubbleSort.opt.vapor +++ b/vaporize/tests/BubbleSort.opt.vapor diff --git a/boil/tests/BubbleSort.vapor b/vaporize/tests/BubbleSort.vapor index cedba69..cedba69 100644 --- a/boil/tests/BubbleSort.vapor +++ b/vaporize/tests/BubbleSort.vapor diff --git a/boil/tests/Factorial.opt.vapor b/vaporize/tests/Factorial.opt.vapor index aca17fe..aca17fe 100644 --- a/boil/tests/Factorial.opt.vapor +++ b/vaporize/tests/Factorial.opt.vapor diff --git a/boil/tests/Factorial.vapor b/vaporize/tests/Factorial.vapor index 28e1126..28e1126 100644 --- a/boil/tests/Factorial.vapor +++ b/vaporize/tests/Factorial.vapor diff --git a/boil/tests/LinearSearch.opt.vapor b/vaporize/tests/LinearSearch.opt.vapor index 302de05..302de05 100644 --- a/boil/tests/LinearSearch.opt.vapor +++ b/vaporize/tests/LinearSearch.opt.vapor diff --git a/boil/tests/LinearSearch.vapor b/vaporize/tests/LinearSearch.vapor index db4884a..db4884a 100644 --- a/boil/tests/LinearSearch.vapor +++ b/vaporize/tests/LinearSearch.vapor diff --git a/boil/tests/LinkedList.opt.vapor b/vaporize/tests/LinkedList.opt.vapor index aaca62c..aaca62c 100644 --- a/boil/tests/LinkedList.opt.vapor +++ b/vaporize/tests/LinkedList.opt.vapor diff --git a/boil/tests/LinkedList.vapor b/vaporize/tests/LinkedList.vapor index bebdf94..bebdf94 100644 --- a/boil/tests/LinkedList.vapor +++ b/vaporize/tests/LinkedList.vapor diff --git a/boil/tests/MoreThan4.opt.vapor b/vaporize/tests/MoreThan4.opt.vapor index a59d1b5..a59d1b5 100644 --- a/boil/tests/MoreThan4.opt.vapor +++ b/vaporize/tests/MoreThan4.opt.vapor diff --git a/boil/tests/MoreThan4.vapor b/vaporize/tests/MoreThan4.vapor index 6067f8e..6067f8e 100644 --- a/boil/tests/MoreThan4.vapor +++ b/vaporize/tests/MoreThan4.vapor diff --git a/boil/tests/QuickSort.opt.vapor b/vaporize/tests/QuickSort.opt.vapor index 6e14e5a..6e14e5a 100644 --- a/boil/tests/QuickSort.opt.vapor +++ b/vaporize/tests/QuickSort.opt.vapor diff --git a/boil/tests/QuickSort.vapor b/vaporize/tests/QuickSort.vapor index 3fe3798..3fe3798 100644 --- a/boil/tests/QuickSort.vapor +++ b/vaporize/tests/QuickSort.vapor diff --git a/boil/tests/ShortCircuit.opt.vapor b/vaporize/tests/ShortCircuit.opt.vapor index 8275acd..8275acd 100644 --- a/boil/tests/ShortCircuit.opt.vapor +++ b/vaporize/tests/ShortCircuit.opt.vapor diff --git a/boil/tests/ShortCircuit.vapor b/vaporize/tests/ShortCircuit.vapor index 31cc088..31cc088 100644 --- a/boil/tests/ShortCircuit.vapor +++ b/vaporize/tests/ShortCircuit.vapor diff --git a/boil/tests/TreeVisitor.opt.vapor b/vaporize/tests/TreeVisitor.opt.vapor index dfa80a6..dfa80a6 100644 --- a/boil/tests/TreeVisitor.opt.vapor +++ b/vaporize/tests/TreeVisitor.opt.vapor diff --git a/boil/tests/TreeVisitor.vapor b/vaporize/tests/TreeVisitor.vapor index d8aa63b..d8aa63b 100644 --- a/boil/tests/TreeVisitor.vapor +++ b/vaporize/tests/TreeVisitor.vapor diff --git a/boil/tests/ex30.vapor b/vaporize/tests/ex30.vapor index 200baee..200baee 100644 --- a/boil/tests/ex30.vapor +++ b/vaporize/tests/ex30.vapor |