From: Doni Pracner Date: Tue, 22 Apr 2014 18:48:46 +0000 (+0200) Subject: added local VAR wrappers to the code in the actions; applied to div and rem X-Git-Tag: v0.1.6~7^2~3 X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=commitdiff_plain;h=37bd7e6ee3efaa3a310c4cd6ead85cbeda90ca94;ds=inline added local VAR wrappers to the code in the actions; applied to div and rem --- diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index 858cae3..bc6f465 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -219,6 +219,20 @@ public class mjc2wsl{ return ret.toString(); } + private String createStartVar(String... vars){ + StringBuilder ret = new StringBuilder("VAR < "); + ret.append(vars[0] + " := 0"); + for (int i=1; i : "); + + return ret.toString(); + } + + private String createEndVar(){ + return "ENDVAR;"; + } + private String createLocal(int i) { // arrays start at 1 in WSL, so we need an offset return "mjvm_locals[" + (i + 1) + "]"; @@ -433,17 +447,21 @@ public class mjc2wsl{ break; } case div: { + prl(createStartVar("tempa", "tempb", "tempres")); prl(createTopTwoEStack()); prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;"); prl("tempres := tempb DIV tempa;"); prl(createToEStack("tempres")); + prl(createEndVar()); break; } case rem: { + prl(createStartVar("tempa", "tempb", "tempres")); prl(createTopTwoEStack()); prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;"); prl("tempres := tempb MOD tempa;"); prl(createToEStack("tempres")); + prl(createEndVar()); break; }