From 950155889fbb028322a11c711942c7feef234491 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Wed, 17 Apr 2024 22:22:13 -0600 Subject: Add 'if' statement functionality, booleans in BoilSimp --- boil/library/BoilSimp.java | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'boil/library/BoilSimp.java') 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 { */ 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 { */ 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 { */ public String visit(FalseLiteral n, String args) { String mod = ""; - n.f0.accept(this, args); + mod += "0"; return mod; } -- cgit v1.2.3