X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=blobdiff_plain;f=src%2Fmjc2wsl.java;h=c8da105e4bff4a081b92d20fd690f4a16f6fbc64;hp=552fe9d33ee5ab6d18eccc67aec7a8c5e9ab629d;hb=16b6eee0dce46948aca7f014514d5cfc76b4774e;hpb=f25da8c872d094e151a362529b68af80d449accf diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index 552fe9d..c8da105 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -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)+"]"; } /** @@ -406,52 +406,55 @@ public class mjc2wsl{ } case call: { - prl(cmdToMStack(counter+2)); prl("CALL a" + (counter + get2()) + ";"); break; } case return_: { - prl("IF EMPTY?(mjvm_mstack) THEN CALL Z ELSE"); + prl("IF EMPTY?(mjvm_mstack) THEN CALL Z FI"); //else we let things return - prl(cmdFromMStack("tempa")); - prl("SKIP FI"); prl("END b"+counter+" =="); 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 - case read: { + // read, print + case read:{ + //TODO make it a char for read + message("char is read like a number", M_WAR); + prl(createComment("char is read like a number",C_SPEC)); + } + case bread: { 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 print:{ + // TODO need to make it a char on print + message("chars will be printed as number codes", M_WAR); + prl(createComment("char will be printed as a number code",C_SPEC)); } - case print: { - // TODO need to make it a char + case bprint: { + // 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 +494,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,6 +536,13 @@ 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; genPrintForEachAddress = true;