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
return ret.toString();
}
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) + "]";
private String createLocal(int i) {
// arrays start at 1 in WSL, so we need an offset
return "mjvm_locals[" + (i + 1) + "]";
while (op >= 0) {
if (originalInComments)
prl(createComment(describeOpCode(op), C_OC));
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)
if (genPrintForEachAddress) {
prl("PRINT(\"a" + counter + "\");");
if (genPauseAfterEachAddress)
break;
}
case div: {
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(createTopTwoEStack());
prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
prl("tempres := tempb DIV tempa;");
prl(createToEStack("tempres"));
+ prl(createEndVar());
break;
}
case rem: {
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(createTopTwoEStack());
prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
prl("tempres := tempb MOD tempa;");
prl(createToEStack("tempres"));
+ prl(createEndVar());
break;
}
break;
}
case return_: {
// we let the actions return
// there is nothing to clean up
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: {
break;
}
case enter: {
op = get();
if (op >= 0)
if (wasJump)
op = get();
if (op >= 0)
if (wasJump)
- prl("SKIP END");
+ prl("SKIP\n END");
else
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());
}
prl(createStandardEnd());
}