X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=blobdiff_plain;f=src%2Fmjc2wsl.java;h=14cc9e415809c6cc591e4b4bc8e187e72d1e282e;hp=6cd59e08a6d90082ee5b013cdd2519579713afe2;hb=c71486b667051ba56ee13c49f887822b61572748;hpb=0c263247bdd9af3332ba985639070e4dc2ff9f6f diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index 6cd59e0..14cc9e4 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -38,6 +38,8 @@ public class mjc2wsl{ private boolean genPopPush=false; + private boolean genInlinePrint=false; + /** Constant used for marking a regular comment from the original file */ public static final char C_REG = ' '; /** @@ -222,18 +224,20 @@ public class mjc2wsl{ ret.append("\t@List_To_String(< num >)\n"); ret.append("END\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("\nPROC Print_MJ_CHAR(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(CHR(val))\n"); - ret.append("END\n"); + if (!genInlinePrint) { + 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("\nPROC Print_MJ_CHAR(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(CHR(val))\n"); + ret.append("END\n"); + } ret.append("\nEND"); return ret.toString(); @@ -436,17 +440,18 @@ public class mjc2wsl{ case getfield: { int f = get2(); + prl(createStartVar("tempa")); prl(createTopEStack()); prl(createToEStack(createObject("tempa") + "[" + (f + 1) + "]")); + prl(createEndVar()); break; } case putfield: { int f = get2(); - // we need to use a temparray as a pointer, WSL - // otherwise tries to access it as a list of lists and fails - prl(createTopTwoEStack()); - prl("VAR < tempArray := " + createObject("tempb") + " > :"); - prl("tempArray[" + (f + 1) + "]:=tempa ENDVAR;"); + prl(createStartVar("tempa", "tempb")); + prl(createTopTwoEStack()); + prl(createObject("tempb") + "[" + (f + 1) + "]:=tempa;"); + prl(createEndVar()); break; } @@ -455,6 +460,11 @@ public class mjc2wsl{ break; } + case const_m1: { + prl(createToEStack(-1)); + break; + } + case const_0: case const_1: case const_2: @@ -682,7 +692,11 @@ public class mjc2wsl{ case bprint: { prl(createStartVar("tempa", "tempb")); prl(createTopTwoEStack()); - prl("Print_MJ_CHAR(tempb,tempa);"); + if (genInlinePrint){ + prl(createComment("print spacing and transformation",C_SPEC)); + prl("PRINFLUSH(SUBSTR(\" \", 0, MIN(10, MAX(0,tempa-1))), @List_To_String(< tempb >));"); + } else + prl("Print_MJ_CHAR(tempb,tempa);"); prl(createEndVar()); break; } @@ -691,7 +705,12 @@ public class mjc2wsl{ prl(createStartVar("tempa", "tempb")); prl(createTopTwoEStack()); - prl("Print_MJ(tempb,tempa);"); + if (genInlinePrint){ + prl(createComment("print spacing",C_SPEC)); + prl("PRINFLUSH(SUBSTR(\" \", 0, MIN(10, MAX(0, tempa-1))), tempb);"); + } + else + prl("Print_MJ(tempb,tempa);"); prl(createEndVar()); break; } @@ -768,6 +787,10 @@ public class mjc2wsl{ public void printHelpDirectives(){ System.out.println("Alternatives for code generation:"); System.out.println(" --genPopPush generate POP/PUSH instead of TAIL/HEAD"); + System.out.println(" --genHeadTail generate TAIL/HEAD instead of POP/PUSH "); + System.out.println(); + System.out.println(" --genInlinePrint generate prints directly instead of procedure calls"); + System.out.println(" --genProcedurePrint generate prints as custom procedure calls"); } public void printHelpHelp() { @@ -840,6 +863,12 @@ public class mjc2wsl{ genPauseAfterEachAddress = true; } else if (args[i].compareToIgnoreCase("--genPopPush") == 0) { genPopPush = true; + } else if (args[i].compareToIgnoreCase("--genInlinePrint") == 0) { + genInlinePrint = true; + } else if (args[i].compareToIgnoreCase("--genHeadTail") == 0) { + genPopPush = false; + } else if (args[i].compareToIgnoreCase("--genProcedurePrint") == 0) { + genInlinePrint = false; } i++; }