gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
mjc2wsl - jumps have ELSE branches, so that actions have normal ends for the recursiv...
[mjc2wsl.git] / src / mjc2wsl.java
index 512d238..2f6aa8d 100644 (file)
@@ -32,6 +32,9 @@ public class mjc2wsl{
                        out.println("total errors:"+messageCounters[M_ERR]+" warnings:"+messageCounters[M_WAR]);
        }
        
+       private boolean addPauseAfterEachAddress=false, 
+               addPrintForEachAddress = false;
+       
        /** Constant used for marking a regular comment from the original file */
        public static final char C_REG = ' ';
        /**
@@ -267,6 +270,10 @@ public class mjc2wsl{
                        }
                        throw new Exception("Wrong opcode for a relation");
        }
+       
+       private boolean isJumpCode(int opcode) {
+                       return (opcode>=jmp) && (opcode<=jge);
+       }
 
        public void convertStream(InputStream ins) throws Exception{
                mainIn = ins;
@@ -280,12 +287,17 @@ public class mjc2wsl{
                int mainAdr = get4();
                
                prl(getStandardStart());
-               prl("SKIP;\n ACTIONS A_S_start:\n A_S_start == CALL a14 END");
+               prl("SKIP;\n ACTIONS A_S_start:\n A_S_start == CALL a"+(14+mainAdr)+" END");
                int op = get();
                while (op >= 0) {
                        if (originalInComments)
                                prl(createComment(describeOpCode(op), C_OC));
                        prl("a" + counter + " == ");
+                       if (addPrintForEachAddress) {
+                                       prl("PRINT(\"a"+counter+"\");");
+                                       if (addPauseAfterEachAddress)
+                                                       prl("debug_disposable_string := @Read_Line(Standard_Input_Port);");
+                       }
                        switch (op) {
                        case load: {
                                prl(cmdToEStack(loc(get())));
@@ -381,6 +393,7 @@ public class mjc2wsl{
                                prl(getTopTwo());
                                prl("IF tempb "+ getRelationFor(op)
                                                +" tempa THEN CALL a" + (counter + get2())
+                                               +" ELSE CALL a" + (counter+1)
                                                + " FI;");
                                break;
                        }
@@ -402,8 +415,11 @@ public class mjc2wsl{
                        case enter: {
                                prl(createComment("enter not fully procesed yet"));
                                message("enter not fully procesed yet", M_WAR);
+                               int parameters = get();
+                               
                                get();
-                               get();
+                               for (int i = parameters-1; i >= 0; i--)
+                                               prl(cmdFromEStack("mjvm_loc" + i));
                                break;
                        }
                        case exit: {
@@ -447,9 +463,13 @@ public class mjc2wsl{
                                break;
                        }
 
+                       boolean wasJump = isJumpCode(op);
                        op = get();
                        if (op >= 0)
-                               prl("CALL a" + counter + " END");
+                               if (wasJump)
+                                               prl("SKIP END");
+                               else
+                                               prl("CALL a" + counter + " END");
                }
                prl("CALL Z;\nSKIP END\nENDACTIONS;\n");
                prl(getStandardEnd());
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner