gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
mjc2wsl - prints and reads, using the same code blocks, support spacings, prints...
[mjc2wsl.git] / src / mjc2wsl.java
index 886cd7d..05a8a32 100644 (file)
@@ -32,8 +32,8 @@ public class mjc2wsl{
                        out.println("total errors:"+messageCounters[M_ERR]+" warnings:"+messageCounters[M_WAR]);
        }
        
-       private boolean addPauseAfterEachAddress=false, 
-               addPrintForEachAddress = false,
+       private boolean genPauseAfterEachAddress=false, 
+               genPrintForEachAddress = false,
                genPrintEStackOnChange = false;
        
        /** Constant used for marking a regular comment from the original file */
@@ -114,8 +114,7 @@ public class mjc2wsl{
                        +"C:\" with mjc2wsl v "+versionN+"\";\n");
 
                ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\n\t");
-               for (int i = 0; i <= 3; i++)
-                       ret.append(loc(i) + " := 0, ");
+               ret.append("mjvm_locals := ARRAY(1,0), ");
                ret.append("\n  mjvm_estack := < >, mjvm_mstack := < >, "); 
                ret.append("\n  mjvm_fp := 0, mjvm_sp := 0,");
                ret.append("\n  t_e_m_p := 0 > :");
@@ -203,7 +202,8 @@ public class mjc2wsl{
        }
        
        private String loc(int i){
-               return "mjvm_loc" + i;
+               //arrays start at 1 in WSL, so we need an offset
+               return "mjvm_locals[" + (i+1)+"]";
        }
        
        /**
@@ -300,9 +300,9 @@ public class mjc2wsl{
                        if (originalInComments)
                                prl(createComment(describeOpCode(op), C_OC));
                        prl("a" + counter + " == ");
-                       if (addPrintForEachAddress) {
+                       if (genPrintForEachAddress) {
                                        prl("PRINT(\"a"+counter+"\");");
-                                       if (addPauseAfterEachAddress)
+                                       if (genPauseAfterEachAddress)
                                                        prl("debug_disposable_string := @Read_Line(Standard_Input_Port);");
                        }
                        switch (op) {
@@ -420,38 +420,38 @@ public class mjc2wsl{
                                break;
                        }
                        case enter: {
-                               prl(createComment("enter not fully procesed yet"));
-                               message("enter not fully procesed yet", M_WAR);
                                int parameters = get();
                                
-                               get();
+                               int locals = get();
+                               prl(cmdToMStack("mjvm_locals"));
+                               prl("mjvm_locals := ARRAY("+locals+",0);");
                                for (int i = parameters-1; i >= 0; i--)
                                                prl(cmdFromEStack(loc(i)));
                                break;
                        }
                        case exit: {
-                               prl(createComment("exit not fully procesed yet"));
-                               message("exit not fully procesed yet", M_WAR);
+                               prl(cmdFromMStack("mjvm_locals"));
                                break;
                        }
 
-                       //TODO read, print
+                       // read, print
+                       case bread:
                        case read: {
+                               //TODO make it a char for read
                                prl("tempa := @String_To_Num(@Read_Line(Standard_Input_Port));");
                                prl(cmdToEStack("tempa"));
                                break;
                        }
 
                        // the prints
-                       case bprint: {
-                               prl(getTopTwo());
-                               prl("PRINT(tempb);");
-                               break;
-                       }
+                       case bprint: 
                        case print: {
-                               // TODO need to make it a char
+                               // TODO need to make it a char on print
+                               // TODO printing numbers needs different lengths of spacing
                                prl(getTopTwo());
-                               prl("PRINT(tempb);");
+                               pr(createComment("print spacing",C_SPEC));
+                               prl("IF tempa>1 THEN FOR i:=2 TO tempa STEP 1 DO PRINFLUSH(\" \") OD FI;");
+                               prl("PRINFLUSH(tempb);");
                                break;
                        }
 
@@ -491,7 +491,7 @@ public class mjc2wsl{
        public void printHelp() {
                System.out.println("MicroJava bytecode to WSL converter. v " + versionN
                                + ", by Doni Pracner");
-               System.out.println("usage:\n\t {options} mjc2wsl  filename [outfile]");
+               System.out.println("usage:\n\t mjc2wsl {options} filename [outfile]");
                System.out.println("options:\n\t--screen print output to screen");
                System.out.println("\t-o --oc[+-] include original code in comments");
                System.out.println("\t-v verbose, print warning messages");
@@ -533,10 +533,17 @@ public class mjc2wsl{
                                        printLevel = M_ERR+1;//no printing                              
                                } else if (args[i].compareToIgnoreCase("--genEStackPrint") == 0) {
                                        genPrintEStackOnChange = true;
+                               } else if (args[i].compareToIgnoreCase("--genAddrPause") == 0) {
+                                       genPauseAfterEachAddress = true;
+                               } else if (args[i].compareToIgnoreCase("--genAddrPrint") == 0) {
+                                       genPrintForEachAddress = true;
+                               } else if (args[i].compareToIgnoreCase("--genAddr") == 0) {
+                                       genPrintForEachAddress = true;
+                                       genPauseAfterEachAddress = true;
                                } else if (args[i].compareToIgnoreCase("--genAll") == 0) {
                                        genPrintEStackOnChange = true;
-                                       addPrintForEachAddress = true;
-                                       addPauseAfterEachAddress = true;
+                                       genPrintForEachAddress = true;
+                                       genPauseAfterEachAddress = true;
                                }i++;
                        }
 
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner