From: Doni Pracner Date: Sat, 1 Sep 2012 20:45:26 +0000 (+0200) Subject: individual commands into actions X-Git-Tag: v0.1.1 X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=5c5334e8a486165126a1e1f2f1afc4a3501e380b;p=mjc2wsl.git individual commands into actions --- diff --git a/mjc2wsl.java b/mjc2wsl.java index e65bd1d..c89fbab 100644 --- a/mjc2wsl.java +++ b/mjc2wsl.java @@ -9,7 +9,7 @@ import java.util.*; * @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com */ public class mjc2wsl{ - public static String versionN = "0.1"; + public static String versionN = "0.1.2"; //regular comments from the original file //OC when original code is inserted in the file, next to the translations @@ -97,6 +97,7 @@ public class mjc2wsl{ private InputStream mainIn; private PrintWriter out = null; + private int counter = 0; private void pr(int i){ out.print(i); @@ -122,6 +123,7 @@ public class mjc2wsl{ }catch (IOException ex){ ex.printStackTrace(); } + counter++; return res; } @@ -181,10 +183,11 @@ public class mjc2wsl{ for (int i=0;i<14;i++) get(); prl(getStandardStart()); - + prl("SKIP;\n ACTIONS A_S_start:\n A_S_start == CALL a14 END"); int op = get(); while (op>=0){ if (originalInComments) prl(createComment(""+op,C_OC)); + prl("a"+counter+" == "); switch(op) { case load: { prl(cmdToEStack(loc(get()))); @@ -214,14 +217,14 @@ public class mjc2wsl{ } case jmp: { - prl(createComment("CALL "+get2())); + prl("CALL a"+(counter+get2())+";"); break; } case jeq: case jne: case jlt: case jle: case jgt: case jge: { prl(getTopTwo()); - prl(createComment("IF CALL "+get2())); + prl("IF tempb >= tempa THEN CALL a"+(counter+get2())+" FI;"); break; } @@ -267,8 +270,11 @@ public class mjc2wsl{ default: prl(createComment("unknown op error: "+op,C_ERR)); break; } + op = get(); + if (op>=0) prl("CALL a"+counter+" END"); } + prl("CALL Z;\nSKIP END\nENDACTIONS;\n"); prl(getStandardEnd()); } diff --git a/samples/sample0.wsl b/samples/sample0.wsl index 905cb16..cc20ab3 100644 --- a/samples/sample0.wsl +++ b/samples/sample0.wsl @@ -3,39 +3,66 @@ C:" with mjc2wsl v 0.1"; VAR < tempa := 0, tempb := 0, tempres :=0, loc0 := 0, loc1 := 0, loc2 := 0, loc3 := 0, estack := < >, t_e_m_p := 0 > : +SKIP; ACTIONS A_S_start: - A_S_start == - + A_S_start == CALL a14 END +a15 == C:" enter not fully procesed yet"; +CALL a18 END +a18 == estack := <0 > ++ estack; -loc0 := HEAD(estack); estack := TAIL(estack); CALL a19 END -a19 == +a19 == +loc0 := HEAD(estack); estack := TAIL(estack); +CALL a20 END +a20 == estack := ++ estack; +CALL a21 END +a21 == estack := <5 > ++ estack; +CALL a22 END +a22 == tempa := HEAD(estack); estack := TAIL(estack); tempb := HEAD(estack); estack := TAIL(estack); -C:" IF CALL 13"; -IF tempb >= tempa THEN CALL a34 FI; +IF tempb >= tempa THEN CALL a35 FI; +CALL a25 END +a25 == estack := ++ estack; +CALL a26 END +a26 == estack := <0 > ++ estack; +CALL a27 END +a27 == tempa := HEAD(estack); estack := TAIL(estack); -tempa := HEAD(estack); estack := TAIL(estack); -PRINT(tempa); +tempb := HEAD(estack); estack := TAIL(estack); +PRINT(tempb); +CALL a28 END +a28 == estack := ++ estack; +CALL a29 END +a29 == estack := <1 > ++ estack; +CALL a30 END +a30 == tempa := HEAD(estack); estack := TAIL(estack); tempb := HEAD(estack); estack := TAIL(estack); tempres := tempb + tempa; estack := ++ estack; +CALL a31 END +a31 == loc0 := HEAD(estack); estack := TAIL(estack); -C:" CALL -12"; -CALL a19 END -a34 == +CALL a32 END +a32 == +CALL a20; +CALL a35 END +a35 == C:" exit not fully procesed yet"; +CALL a36 END +a36 == C:" return not fully procesed yet"; -CALL Z -END +CALL Z; +SKIP END ENDACTIONS; + SKIP ENDVAR