gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control systemdiff --git a/src/mjc2wsl.java b/src/mjc2wsl.java
--- a/src/mjc2wsl.java
+++ b/src/mjc2wsl.java
"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), ");
}
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 createStartVar(String... vars){
+ StringBuilder ret = new StringBuilder("VAR < ");
+ ret.append(vars[0] + " := 0");
+ for (int i=1; i<vars.length; i++)
+ ret.append(", "+ vars[i] +" := 0");
+ ret.append(" > : ");
+
+ return ret.toString();
+ }
+
+ private String createEndVar(){
+ return "ENDVAR;";
+ }
+
private String createLocal(int i) {
// arrays start at 1 in WSL, so we need an offset
return "mjvm_locals[" + (i + 1) + "]";
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)
break;
}
case div: {
+ prl(createStartVar("tempa", "tempb", "tempres"));
prl(createTopTwoEStack());
prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
prl("tempres := tempb DIV tempa;");
prl(createToEStack("tempres"));
+ prl(createEndVar());
break;
}
case rem: {
+ prl(createStartVar("tempa", "tempb", "tempres"));
prl(createTopTwoEStack());
prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
prl("tempres := tempb MOD tempa;");
prl(createToEStack("tempres"));
+ prl(createEndVar());
break;
}
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: {
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;
}
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("\nSKIP END\nENDACTIONS;\n");
+ prl("SKIP\n END\nENDACTIONS;\n");
prl(createStandardEnd());
}