diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-17 22:22:13 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-17 22:22:13 -0600 |
commit | 950155889fbb028322a11c711942c7feef234491 (patch) | |
tree | 99a38fdca1f11ded314c09e06228eaa5562b4335 /boil/library | |
parent | 6377548c75f05f0b8599dcfb8d61a56240692334 (diff) |
Add 'if' statement functionality, booleans in BoilSimp
Diffstat (limited to 'boil/library')
-rw-r--r-- | boil/library/BoilSimp.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java index 6d8e401..e5c622c 100644 --- a/boil/library/BoilSimp.java +++ b/boil/library/BoilSimp.java @@ -491,13 +491,32 @@ public class BoilSimp extends GJDepthFirst<String,String> { */ public String visit(IfStatement n, String args) { String mod = ""; + int if_id = this.id++; n.f0.accept(this, args); n.f1.accept(this, args); - n.f2.accept(this, args); + String cond = n.f2.accept(this, args); + + vapor += String.format(" %s = %s\n", + this.tf.alias(Integer.toString(this.id++)), + cond); + vapor += String.format(" if0 %s goto :if%d_else\nif%d_body:\n", + this.tf.alias(Integer.toString(this.id-1)), + if_id, + if_id); + n.f3.accept(this, args); n.f4.accept(this, args); + + vapor += String.format(" goto :if%d_end\nif%d_else:\n", + if_id, + if_id); + n.f5.accept(this, args); n.f6.accept(this, args); + + vapor += String.format("if%d_end:\n", + if_id); + return mod; } @@ -830,7 +849,7 @@ public class BoilSimp extends GJDepthFirst<String,String> { */ public String visit(TrueLiteral n, String args) { String mod = ""; - n.f0.accept(this, args); + mod += "1"; return mod; } @@ -839,7 +858,7 @@ public class BoilSimp extends GJDepthFirst<String,String> { */ public String visit(FalseLiteral n, String args) { String mod = ""; - n.f0.accept(this, args); + mod += "0"; return mod; } |