X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=blobdiff_plain;f=src%2Fmjc2wsl.java;h=858cae30017462a3e99346d55bb7e958db7230f6;hp=9eff3add933badbc57bfa5fd18639bfabb8f0318;hb=8d84760b785210c951543762c5d10b9f78845c53;hpb=786d08226c4b4749d7004aff32276c612feef110 diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index 9eff3ad..858cae3 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -192,20 +192,31 @@ public class mjc2wsl{ "C:\" This file automatically converted from microjava bytecode\";\n" +"C:\" with mjc2wsl v "+versionN+"\";\n"); + ret.append("BEGIN "); ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\n\t"); ret.append("mjvm_locals := ARRAY(1,0), "); ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0), "); ret.append("\n\tmjvm_arrays := < >, "); ret.append("\n\tmjvm_objects := < >, "); - ret.append("\n mjvm_estack := < >, mjvm_mstack := < >, "); - ret.append("\n mjvm_fp := 0, mjvm_sp := 0,"); - ret.append("\n t_e_m_p := 0 > :"); + ret.append("\n mjvm_estack := < >, mjvm_mstack := < > > : "); return ret.toString(); } public String createStandardEnd(){ - return "SKIP\nENDVAR"; + StringBuilder ret = new StringBuilder("SKIP\nENDVAR"); + ret.append("\nWHERE\n"); + + ret.append("\nPROC Print_MJ(val, format VAR)==\n"); + ret.append(createComment("print spacing", C_SPEC)); + + ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO "); + ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n"); + ret.append("\tFI;\n\tPRINFLUSH(val)\nEND\n"); + + ret.append("\nEND\n"); + + return ret.toString(); } private String createLocal(int i) { @@ -328,13 +339,12 @@ public class mjc2wsl{ int mainAdr = get4(); prl(createStandardStart(numberOfWords)); - prl("SKIP;\n ACTIONS A_S_start:\n A_S_start == CALL a" + (14 + mainAdr) - + " END"); + prl("SKIP;\n ACTIONS a" + (14 + mainAdr) + " :"); int op = get(); while (op >= 0) { if (originalInComments) prl(createComment(describeOpCode(op), C_OC)); - prl("a" + counter + " == "); + prl(" a" + counter + " == "); if (genPrintForEachAddress) { prl("PRINT(\"a" + counter + "\");"); if (genPauseAfterEachAddress) @@ -501,13 +511,8 @@ public class mjc2wsl{ } case arraylength: { prl(createTopEStack()); - // TODO make an array length function of some sort! - prl(createComment( - "array length not known - LENGTH not aplicable to arrays", - C_ERR)); - messages.message("array length not known - LENGTH not aplicable to arrays", TransMessages.M_ERR); - prl(createComment("put 1 on the stack for consistency", C_SPEC)); - prl(createToEStack(1)); + prl("tempb := LENGTH("+ createArray("tempa") + ");"); + prl(createToEStack("tempb")); break; } @@ -557,7 +562,7 @@ public class mjc2wsl{ case return_: { // we let the actions return // there is nothing to clean up - prl("SKIP END b" + counter + " =="); + prl("SKIP\n END\n b" + counter + " =="); break; } case enter: { @@ -597,9 +602,7 @@ public class mjc2wsl{ case print: { // TODO printing numbers needs different lengths of spacing prl(createTopTwoEStack()); - 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);"); + prl("Print_MJ(tempb,tempa);"); break; } @@ -618,11 +621,11 @@ public class mjc2wsl{ op = get(); if (op >= 0) if (wasJump) - prl("SKIP END"); + prl("SKIP\n END"); else - prl("CALL a" + counter + " END"); + prl("CALL a" + counter + "\n END"); } - prl("CALL Z;\nSKIP END\nENDACTIONS;\n"); + prl("SKIP\n END\nENDACTIONS;\n"); prl(createStandardEnd()); } @@ -671,9 +674,10 @@ public class mjc2wsl{ } public void printHelpHelp() { - System.out.println("Help options"); + System.out.println("Help and info options"); System.out.println(" -h basic help"); System.out.println(" --help print more detailed help"); + System.out.println(" --version or -version print version and exit"); } public void printUsage(){ @@ -704,6 +708,10 @@ public class mjc2wsl{ } else if (args[i].compareTo("--help") == 0) { printLongHelp(); return; + } else if (args[i].compareTo("--version") == 0 + || args[i].compareTo("-version") == 0) { + printVersion(); + return; } else if (args[i].compareTo("-o") == 0 || args[i].startsWith("--oc")) { if (args[i].length() == 2)