X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=blobdiff_plain;f=src%2Fmjc2wsl.java;h=6813fbf9c351bf863aaf96d599a1d10ee565286f;hp=b7edf0bec3d47fd6718b2dff997ae57c90e01bb8;hb=efaa20740f926a087c2cd8b4e0827f226483c4f2;hpb=2050d4ec077043d9e84577d28951ba072e3688bf diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index b7edf0b..6813fbf 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -125,6 +125,38 @@ public class mjc2wsl{ private boolean originalInComments = false; + private HashMap opMap = null; + + private String opCodeFile = "mj-bytecodes.properties"; + + private HashMap getOpMap() { + if (opMap==null) { + opMap = new HashMap (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; @@ -247,7 +279,7 @@ public class mjc2wsl{ 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: { @@ -376,6 +408,11 @@ public class mjc2wsl{ } //TODO read, print + case read: { + prl("tempa := @String_To_Num(@Read_Line(Standard_Input_Port));"); + prl(cmdToEStack("tempa")); + break; + } // the prints case bprint: {