diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-17 17:20:41 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-17 17:20:41 -0600 |
commit | bb87a9b63707d171eb105b8d66fe9109f8e540e4 (patch) | |
tree | 38b194fc3c1980261bf6afd0c06090ff4cccdc77 /boil/library/BoilSimp.java | |
parent | 3b1571fd410096eb20a9af9ebcee124ff1ea8eac (diff) |
Fix the return statement in Boil.MethodDeclaration
Diffstat (limited to 'boil/library/BoilSimp.java')
-rw-r--r-- | boil/library/BoilSimp.java | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java index 03e18fb..4de7633 100644 --- a/boil/library/BoilSimp.java +++ b/boil/library/BoilSimp.java @@ -216,14 +216,14 @@ public class BoilSimp extends GJDepthFirst<String,String> { String mod = ""; String cls = n.f0.accept(this, args); - String id = n.f1.accept(this, args); + String id = n.f1.f0.tokenImage; TypeInstance t = this.symt.getType(id); this.vapor += String.format(" %s = HeapAllocZ(%d)\n", this.tf.alias(t.getName()), t.getSize()); - this.vapor += String.format(" if0 %s goto :error\n", - this.tf.alias(this.symt.getType(id).getName())); + // this.vapor += String.format(" if0 %s goto :error\n", + // this.tf.alias(this.symt.getType(id).getName())); n.f2.accept(this, args); return mod; } @@ -274,6 +274,13 @@ public class BoilSimp extends GJDepthFirst<String,String> { n.f11.accept(this, args); n.f12.accept(this, args); + // minor cleanup + if (n.f10.f0.which == 8 && // primary expression + ((PrimaryExpression) n.f10.f0.choice).f0.which == 3) + ret = String.format("[%s+%d]", + ret, + 0); + this.vapor += String.format(" %s = %s\n ret %s\n\n", this.tf.alias(Integer.toString(this.id++)), ret, @@ -661,35 +668,45 @@ public class BoilSimp extends GJDepthFirst<String,String> { */ public String visit(MessageSend n, String args) { String mod = ""; - String id = n.f0.accept(this, args); // gross code was required to create proper types + classes for anonymous classes... + String id; TypeInstance cur; ClassInstance cls; - if (this.symt.getType(id) != null) { + switch (n.f0.f0.which) { + case 3: + id = ((Identifier) n.f0.f0.choice).f0.tokenImage; cur = this.symt.getType(id); - } else { + break; + case 6: + id = n.f0.accept(this, args); cur = new TypeInstance(Integer.toString(this.id++), TypeEnum.ERROR); cur.addClassInstance(this.symt.getClass(id.substring(id.indexOf('_')+1))); this.vapor += String.format(" %s = HeapAllocZ(%d)\n", this.tf.alias(cur.getName()), cur.getSize()); - this.vapor += String.format(" if0 %s goto :error\n", - this.tf.alias(cur.getName())); + // this.vapor += String.format(" if0 %s goto :error\n", + // this.tf.alias(cur.getName())); this.vapor += String.format(" [%s+%d] = %s\n", this.tf.alias(cur.getName()), 0, id); + break; + default: + System.out.println("ERROR! MessageSend is not implemented for passed case! :("); + id = null; + cur = null; } + n.f1.accept(this, args); - String id2 = n.f2.accept(this, args); + String id2 = n.f2.f0.tokenImage; String tp1 = Integer.toString(this.id++); // TypeFactory likes to know who it's renting to String tp2 = "tp2"; - System.out.println("id " + id); - System.out.println("cur " + cur); + // System.out.println("id " + id); + // System.out.println("cur " + cur); int mtdIndex = cur.getClassInstance().getMethods() .indexOf(this.symt.getMethod(id2)) * 4; @@ -801,8 +818,7 @@ public class BoilSimp extends GJDepthFirst<String,String> { */ public String visit(Identifier n, String args) { String mod = ""; - mod += n.f0.tokenImage; - return mod; + return this.tf.alias(n.f0.tokenImage); } /** @@ -840,9 +856,9 @@ public class BoilSimp extends GJDepthFirst<String,String> { public String visit(AllocationExpression n, String args) { String mod = ""; n.f0.accept(this, args); - String cls = n.f1.accept(this, args); + n.f1.accept(this, args); mod += String.format(":functable_%s", - cls); + n.f1.f0.tokenImage); // System.out.println(vapor); n.f2.accept(this, args); |