summaryrefslogtreecommitdiff
path: root/boil
diff options
context:
space:
mode:
Diffstat (limited to 'boil')
-rw-r--r--boil/library/BoilSimp.java74
-rw-r--r--boil/library/TypeFactory.java28
-rw-r--r--boil/tests/ex32.java4
3 files changed, 70 insertions, 36 deletions
diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java
index 991319f..b8fee08 100644
--- a/boil/library/BoilSimp.java
+++ b/boil/library/BoilSimp.java
@@ -204,9 +204,9 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
n.f0.accept(this, symt);
String id = n.f1.accept(this, symt);
mod += String.format(" %s = HeapAllocZ(32)\n",
- this.tf.addNewAlias(symt.getType(id))); // FIXME add proper allocation size
+ this.tf.alias(symt.getType(id))); // FIXME add proper allocation size
mod += String.format(" if0 %s goto :error\n",
- this.tf.retrieveAlias(symt.getType(id)));
+ this.tf.alias(symt.getType(id)));
mod += n.f2.accept(this, symt);
return mod;
}
@@ -372,7 +372,7 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
String mod = "";
String id = n.f0.accept(this, symt);
- mod += String.format(" [%s] = ", this.tf.retrieveAlias(symt.getType(id)));
+ mod += String.format(" [%s] = ", this.tf.alias(symt.getType(id)));
mod += n.f1.accept(this, symt);
mod += n.f2.accept(this, symt);
mod += n.f3.accept(this, symt);
@@ -508,7 +508,6 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
String oper1 = n.f0.accept(this, symt);
mod += n.f1.accept(this, symt);
String oper2 = n.f2.accept(this, symt);
- TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR);
mod += String.format("Add(%s %s)",
oper1,
@@ -524,9 +523,15 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
*/
public String visit(MinusExpression n, SymbolTable symt) {
String mod = "";
- mod += n.f0.accept(this, symt);
+ String oper1 = n.f0.accept(this, symt);
mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
+ String oper2 = n.f2.accept(this, symt);
+
+ mod += String.format("Sub(%s %s)",
+ oper1,
+ oper2);
+
+
return mod;
}
@@ -537,9 +542,15 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
*/
public String visit(TimesExpression n, SymbolTable symt) {
String mod = "";
- mod += n.f0.accept(this, symt);
+ String oper1 = n.f0.accept(this, symt);
mod += n.f1.accept(this, symt);
- mod += n.f2.accept(this, symt);
+ String oper2 = n.f2.accept(this, symt);
+
+ mod += String.format("Mul(%s %s)",
+ oper1,
+ oper2);
+
+
return mod;
}
@@ -593,35 +604,27 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
.getMethods().indexOf(symt.getMethod(id2)) * 4;
mod += String.format(" %s = [%s+%d]\n",
- this.tf.addNewAlias(tp1),
- this.tf.retrieveAlias(cur),
+ this.tf.alias(tp1),
+ this.tf.alias(cur),
0);
mod += String.format(" %s = [%s+%d]\n",
- this.tf.addNewAlias(tp2),
- this.tf.retrieveAlias(tp1),
+ this.tf.alias(tp2),
+ this.tf.alias(tp1),
mtdIndex);
mod += n.f3.accept(this, symt);
- String args = n.f4.accept(this, symt);
+ mod += n.f4.accept(this, symt);
mod += n.f5.accept(this, symt);
- TypeInstance tp3 = new TypeInstance("tp3", TypeEnum.ERROR);
-
- if (!args.isEmpty())
- mod += String.format(" %s = %s\n",
- this.tf.addNewAlias(tp3),
- args);
-
mod += String.format(" call %s(%s",
- this.tf.retrieveAlias(tp2),
- this.tf.retrieveAlias(cur));
+ this.tf.alias(tp2),
+ this.tf.alias(cur));
- if (!args.isEmpty())
- mod += String.format(" %s",
- this.tf.retrieveAlias(tp3));
-
- mod += ")\n";
+ mod += String.format("%s)\n",
+ this.tf.retrieveRecentList(symt.getMethod(id2)
+ .getArguments()
+ .size()));
return mod;
}
@@ -632,8 +635,15 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
*/
public String visit(ExpressionList n, SymbolTable symt) {
String mod = "";
- mod += n.f0.accept(this, symt);
+ String rhs = n.f0.accept(this, symt);
+ TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR);
+
+ mod += String.format(" %s = %s\n",
+ this.tf.alias(tp1),
+ rhs);
+
mod += n.f1.accept(this, symt);
+
return mod;
}
@@ -644,7 +654,13 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
public String visit(ExpressionRest n, SymbolTable symt) {
String mod = "";
mod += n.f0.accept(this, symt);
- mod += n.f1.accept(this, symt);
+ String rhs = n.f1.accept(this, symt);
+ TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR);
+
+ mod += String.format(" %s = %s\n",
+ this.tf.alias(tp1),
+ rhs);
+
return mod;
}
diff --git a/boil/library/TypeFactory.java b/boil/library/TypeFactory.java
index 8dd910e..c84f64e 100644
--- a/boil/library/TypeFactory.java
+++ b/boil/library/TypeFactory.java
@@ -13,13 +13,31 @@ public class TypeFactory {
this.map = new HashMap<>();
}
- public String addNewAlias(TypeInstance t) {
- String alias = String.format("t.%d", this.type_num++);
- this.map.put(t, alias);
+ public String alias(TypeInstance t) {
+ /**
+ * Given a TypeInstance, return the designated
+ * vapor alias. If the alias does not exist, create it.
+ */
+ String alias;
+ if ((alias = this.map.get(t)) == null) {
+ alias = String.format("t.%d", this.type_num++);
+ this.map.put(t, alias);
+ }
+
return alias;
}
- public String retrieveAlias(TypeInstance t) {
- return this.map.get(t);
+ public String retrieveRecentList(int x) {
+ /**
+ * Given int x, retrieve a space-delimited
+ * list of the x most recent entries.
+ */
+ String rtn = "";
+ for (int i = type_num-x; i < type_num; ++i) {
+ rtn += String.format(" t.%d",
+ i);
+ }
+
+ return rtn;
}
}
diff --git a/boil/tests/ex32.java b/boil/tests/ex32.java
index af4dcd7..2527e04 100644
--- a/boil/tests/ex32.java
+++ b/boil/tests/ex32.java
@@ -2,12 +2,12 @@ class ex32 {
public static void main(String[] a) {
A a ;
a = new A() ;
- System.out.println(a.foo(12 + 13)) ;
+ System.out.println(a.foo(12, 14, 15, 12 + 23)) ;
}
}
class A {
- public int foo(int a) {
+ public int foo(int a, int b, int c, int d) {
return 22 ;
}
}