gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
mjc2wsl process sub and mul
[mjc2wsl.git] / src / mjc2wsl.java
index 4a30186..c269f20 100644 (file)
@@ -185,8 +185,20 @@ public class mjc2wsl{
        private String getTop() {
                return cmdFromEStack("tempa");
        }
+       
+       private String getRelationFor(int opcode) throws Exception {
+                       switch (opcode) {
+                                       case jeq: return "=";
+                                       case jne: return "#";
+                                       case jlt: return "<";
+                                       case jle: return "<=";
+                                       case jgt: return ">";
+                                       case jge: return ">=";
+                       }
+                       throw new Exception("Wrong opcode for a relation");
+       }
 
-       public void convertStream(InputStream ins){
+       public void convertStream(InputStream ins) throws Exception{
                mainIn = ins;
                //skip start TODO make better
                for (int i = 0; i < 14; i++)
@@ -249,7 +261,8 @@ public class mjc2wsl{
                        case jgt:
                        case jge: {
                                prl(getTopTwo());
-                               prl("IF tempb >= tempa THEN CALL a" + (counter + get2())
+                               prl("IF tempb "+ getRelationFor(op)
+                                               +" tempa THEN CALL a" + (counter + get2())
                                                + " FI;");
                                break;
                        }
@@ -260,6 +273,18 @@ public class mjc2wsl{
                                prl(cmdToEStack("tempres"));
                                break;
                        }
+                       case sub: {
+                               prl(getTopTwo());
+                               prl("tempres := tempb - tempa;");
+                               prl(cmdToEStack("tempres"));
+                               break;
+                       }
+                       case mul: {
+                               prl(getTopTwo());
+                               prl("tempres := tempb * tempa;");
+                               prl(cmdToEStack("tempres"));
+                               break;
+                       }
                        case div: {
                                prl(getTopTwo());
                                prl("tempres := tempb / tempa;");
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner