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 | |
parent | 6377548c75f05f0b8599dcfb8d61a56240692334 (diff) |
Add 'if' statement functionality, booleans in BoilSimp
Diffstat (limited to 'boil')
-rw-r--r-- | boil/library/BoilSimp.java | 25 | ||||
-rw-r--r-- | boil/tests/ex42.java | 2 | ||||
-rw-r--r-- | boil/tests/ex43.java | 22 |
3 files changed, 45 insertions, 4 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; } diff --git a/boil/tests/ex42.java b/boil/tests/ex42.java index 05af17a..8ea74b3 100644 --- a/boil/tests/ex42.java +++ b/boil/tests/ex42.java @@ -2,7 +2,7 @@ class ex42 { public static void main(String[] z) { A a ; a = new A() ; - System.out.println(a.Init()) ; + System.out.println(a.Init(42, 10000, true, 156, 123)) ; } } diff --git a/boil/tests/ex43.java b/boil/tests/ex43.java new file mode 100644 index 0000000..80657d9 --- /dev/null +++ b/boil/tests/ex43.java @@ -0,0 +1,22 @@ +class ex43 { + public static void main(String[] z) { + A a ; + a = new A() ; + System.out.println(a.foo()) ; + } +} + +class A { + + public int foo() { + int v ; + v = 1 ; + if (5 < v) { + System.out.println(1) ; + } else { + System.out.println(0) ; + } + return v ; + } + +} |