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
* @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
*/
public class mjc2wsl{
* @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
*/
public class mjc2wsl{
- public static String versionN = "0.1.3";
+ public static String versionN = "0.1.4";
public static final int M_ERR = 2, M_WAR = 1, M_DEB = 0;
public static final int M_ERR = 2, M_WAR = 1, M_DEB = 0;
"C:\" This file automatically converted from microjava bytecode\";\n"
+"C:\" with mjc2wsl v "+versionN+"\";\n");
"C:\" This file automatically converted from microjava bytecode\";\n"
+"C:\" with mjc2wsl v "+versionN+"\";\n");
- ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\n");
+ ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\n\t");
for (int i = 0; i <= 3; i++)
for (int i = 0; i <= 3; i++)
- ret.append("loc" + i + " := 0, ");
- ret.append("\n estack := < >, t_e_m_p := 0 > :");
+ ret.append("mjvm_loc" + i + " := 0, ");
+ ret.append("\n mjvm_estack := < >, mjvm_mstack := < >, ");
+ ret.append("\n mjvm_fp := 0, mjvm_sp := 0,");
+ ret.append("\n t_e_m_p := 0 > :");
return ret.toString();
}
return ret.toString();
}
private boolean originalInComments = false;
private boolean originalInComments = false;
+ private HashMap<Integer,String> opMap = null;
+
+ private String opCodeFile = "mj-bytecodes.properties";
+
+ private HashMap<Integer,String> getOpMap() {
+ if (opMap==null) {
+ opMap = new HashMap<Integer, String> (60, 0.98f);
+ try{
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(getClass().getResourceAsStream(opCodeFile)));
+ String str = in.readLine();
+ while (str != null) {
+ String[] ss = str.split("=");
+ opMap.put(Integer.parseInt(ss[0]),ss[1]);
+ str = in.readLine();
+ }
+ in.close();
+ }catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ return opMap;
+ }
+
+ public String getOpString(int op) {
+ return getOpMap().get(op);
+ }
+
+ public String describeOpCode(int op) {
+ return op + " (" + getOpString(op) + ")";
+ }
+
private InputStream mainIn;
private PrintWriter out = null;
private int counter = -1;
private InputStream mainIn;
private PrintWriter out = null;
private int counter = -1;
}
private String loc(int i){
}
private String loc(int i){
- return "loc" + i;
+ return "mjvm_loc" + i;
}
/**
}
/**
return "C:\"" + type + str.replace("\"", "''") + "\";";
}
return "C:\"" + type + str.replace("\"", "''") + "\";";
}
+ //Expression stack
+
private String cmdToEStack(int i) {
private String cmdToEStack(int i) {
- return "estack := <" + i + " > ++ estack;";
+ return "mjvm_estack := <" + i + " > ++ mjvm_estack;";
}
private String cmdToEStack(String i) {
}
private String cmdToEStack(String i) {
- return "estack := <" + i + " > ++ estack;";
+ return "mjvm_estack := <" + i + " > ++ mjvm_estack;";
}
private String cmdFromEStack(String st) {
}
private String cmdFromEStack(String st) {
- return st + " := HEAD(estack); estack := TAIL(estack);";
+ return st + " := HEAD(mjvm_estack); mjvm_estack := TAIL(mjvm_estack);";
}
private String getTopTwo(){
}
private String getTopTwo(){
return cmdFromEStack("tempa");
}
return cmdFromEStack("tempa");
}
+ //Method stack
+
+ private String cmdToMStack(int i) {
+ return "mjvm_mstack := <" + i + " > ++ mjvm_mstack;";
+ }
+
+ private String cmdToMStack(String i) {
+ return "mjvm_mstack := <" + i + " > ++ mjvm_mstack;";
+ }
+
+ private String cmdFromMStack(String st) {
+ return st + " := HEAD(mjvm_mstack); mjvm_mstack := TAIL(mjvm_mstack);";
+ }
+
private String getRelationFor(int opcode) throws Exception {
switch (opcode) {
case jeq: return "=";
private String getRelationFor(int opcode) throws Exception {
switch (opcode) {
case jeq: return "=";
int op = get();
while (op >= 0) {
if (originalInComments)
int op = get();
while (op >= 0) {
if (originalInComments)
- prl(createComment("" + op, C_OC));
+ prl(createComment(describeOpCode(op), C_OC));
prl("a" + counter + " == ");
switch (op) {
case load: {
prl("a" + counter + " == ");
switch (op) {
case load: {
break;
}
break;
}
- //TODO call
+ case call: {
+ prl(cmdToMStack(counter+2));
+ prl("CALL a" + (counter + get2()) + ";");
+ break;
+ }
case return_: {
case return_: {
- prl(createComment("return not fully procesed yet"));
- message("return not fully procesed yet", M_WAR);
+ prl("IF EMPTY?(mjvm_mstack) THEN CALL Z ELSE");
+ //else we let things return
+ prl(cmdFromMStack("tempa"));
+ prl("SKIP FI");
+ prl("END b"+counter+" ==");
break;
}
case enter: {
break;
}
case enter: {
}
//TODO read, print
}
//TODO read, print
+ case read: {
+ prl("tempa := @String_To_Num(@Read_Line(Standard_Input_Port));");
+ prl(cmdToEStack("tempa"));
+ break;
+ }
// the prints
case bprint: {
// the prints
case bprint: {