X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=blobdiff_plain;f=src%2Fmjc2wsl.java;h=05a8a32fab2ee297acf28a8f17d53d57c682886d;hp=1b31bbae3bdcdb92af2861b96a0b75d4e5730775;hb=349aa12e360d3b0f056f20b7b1207e24d3aea2a4;hpb=93c984eaa8163d40b0ee51feaf42559cfc3e8cd8 diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index 1b31bba..05a8a32 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -114,8 +114,7 @@ public class mjc2wsl{ +"C:\" with mjc2wsl v "+versionN+"\";\n"); ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\n\t"); - for (int i = 0; i <= 3; i++) - ret.append(loc(i) + " := 0, "); + ret.append("mjvm_locals := ARRAY(1,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 > :"); @@ -203,7 +202,8 @@ public class mjc2wsl{ } private String loc(int i){ - return "mjvm_loc" + i; + //arrays start at 1 in WSL, so we need an offset + return "mjvm_locals[" + (i+1)+"]"; } /** @@ -420,38 +420,38 @@ public class mjc2wsl{ break; } case enter: { - prl(createComment("enter not fully procesed yet")); - message("enter not fully procesed yet", M_WAR); int parameters = get(); - get(); + int locals = get(); + prl(cmdToMStack("mjvm_locals")); + prl("mjvm_locals := ARRAY("+locals+",0);"); for (int i = parameters-1; i >= 0; i--) prl(cmdFromEStack(loc(i))); break; } case exit: { - prl(createComment("exit not fully procesed yet")); - message("exit not fully procesed yet", M_WAR); + prl(cmdFromMStack("mjvm_locals")); break; } - //TODO read, print + // read, print + case bread: case read: { + //TODO make it a char for read prl("tempa := @String_To_Num(@Read_Line(Standard_Input_Port));"); prl(cmdToEStack("tempa")); break; } // the prints - case bprint: { - prl(getTopTwo()); - prl("PRINT(tempb);"); - break; - } + case bprint: case print: { - // TODO need to make it a char + // TODO need to make it a char on print + // TODO printing numbers needs different lengths of spacing prl(getTopTwo()); - prl("PRINT(tempb);"); + 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);"); break; }