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
ret.append("mjvm_locals := ARRAY(1,0),");
ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0),");
ret.append("\n\tmjvm_arrays := < >,");
+ ret.append("\n\tmjvm_flag_jump := 0,");
ret.append("\n\tmjvm_objects := < >,");
ret.append("\n\tmjvm_estack := < >, mjvm_mstack := < > > :");
}
case shl: {
+ prl(createStartVar("tempa", "tempb"));
prl(createTopTwoEStack());
prl("VAR <tempres :=tempb, i:=1 >:");
prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres * 2 OD;");
prl(createToEStack("tempres"));
prl("ENDVAR;");
+ prl(createEndVar());
break;
}
case shr: {
+ prl(createStartVar("tempa", "tempb"));
prl(createTopTwoEStack());
prl("VAR <tempres :=tempb, i:=1 >:");
prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres DIV 2 OD;");
prl(createToEStack("tempres"));
prl("ENDVAR;");
+ prl(createEndVar());
break;
}
case newarray: {
get();// 0 - bytes, 1 - words; ignore for now
// TODO take into consideration 0/1
+ prl(createStartVar("tempa"));
prl(createTopEStack());
prl("mjvm_arrays := mjvm_arrays ++ < ARRAY(tempa,0) >;");
prl(createToEStack("LENGTH(mjvm_arrays)"));
+ prl(createEndVar());
break;
}
case aload:
case baload: {
+ prl(createStartVar("tempa", "tempb"));
prl(createTopTwoEStack());
prl(createToEStack(createArray("tempb") + "[tempa+1]"));
+ prl(createEndVar());
break;
}
case astore:
case bastore: {
+ prl(createStartVar("tempa", "tempb", "tempres"));
prl(createFromEStack("tempres"));
prl(createTopTwoEStack());
- // we need to use a temparray as a pointer, WSL
- // otherwise tries to access it as a list of lists and fails
- prl("VAR < tempArray := " + createArray("tempb") + " > :");
- prl("tempArray[tempa+1]:=tempres ENDVAR;");
+ prl("mjvm_arrays[tempb][tempa+1]:=tempres;");
+ prl(createEndVar());
break;
}
case arraylength: {
+ prl(createStartVar("tempa", "tempb"));
prl(createTopEStack());
prl("tempb := LENGTH("+ createArray("tempa") + ");");
prl(createToEStack("tempb"));
+ prl(createEndVar());
break;
}
case dup: {
+ prl(createStartVar("tempa", "tempb"));
prl(createTopEStack());
prl(createToEStack("tempa"));
prl(createToEStack("tempa"));
+ prl(createEndVar());
break;
}
case dup2: {
+ prl(createStartVar("tempa", "tempb"));
prl(createTopTwoEStack());
prl(createToEStack("tempb"));
prl(createToEStack("tempa"));
prl(createToEStack("tempb"));
prl(createToEStack("tempa"));
+ prl(createEndVar());
break;
}
case jge: {
prl(createStartVar("tempa", "tempb"));
prl(createTopTwoEStack());
- prl("IF tempb " + getRelationFor(op) + " tempa THEN CALL a"
- + (counter + get2()) + " ELSE CALL a" + (counter + 1)
+ prl("IF tempb " + getRelationFor(op)
+ + " tempa THEN mjvm_flag_jump := 1"
+ + " ELSE mjvm_flag_jump := 0"
+ " FI;");
prl(createEndVar());
+ prl("IF mjvm_flag_jump = 1 THEN CALL a"
+ + (counter + get2())
+ + " ELSE CALL a" + (counter + 1)
+ + " FI;");
break;
}