gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control system
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 944dee8)
raw | patch | inline | side by side (parent: 944dee8)
author | Doni Pracner <quinnuendo@gmail.com> | |
Sun, 19 Jan 2014 21:22:25 +0000 (22:22 +0100) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Sun, 19 Jan 2014 21:22:25 +0000 (22:22 +0100) |
src/mjc2wsl.java | patch | blob | history |
diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java
index 10e9c2c3d04fcf00f98b4f34e101a920cbf29985..3a9727031b389fd4833b5ee2f8026e5be3a9f0ea 100644 (file)
--- a/src/mjc2wsl.java
+++ b/src/mjc2wsl.java
ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\n\t");
ret.append("mjvm_locals := ARRAY(1,0), ");
ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0), ");
+ ret.append("\n\tmjvm_arrays := < >, ");
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 "mjvm_statics[" + (i+1)+"]";
}
+ private String genArray(int i){
+ return "mjvm_arrays["+ i +"]";
+ }
+
+ private String genArray(String i){
+ return "mjvm_arrays["+ i+"]";
+ }
+
/**
* Creates a WSL comment with care to quote chars.
*/
break;
}
//TODO new_ newarray
- case new_ :
- get();//needs a short, but a byte will be taken bellow as well
- case newarray :{
+ case new_ :{
prl(createComment("memory allocation not processed properly", C_ERR));
message("memory allocation not processed properly", M_ERR);
- get();
+ get2();
+ break;
+ }
+ case newarray :{
+ get();// 0 - bytes, 1 - words; ignore for now
+ //TODO take into consideration 0/1
+ prl(getTop());
+ prl("mjvm_arrays := mjvm_arrays ++ < ARRAY(tempa,0) >;");
+ prl(cmdToEStack("LENGTH(mjvm_arrays)"));
break;
}
- //TODO aload, asstore, baload, bastore
+
+ case aload:
+ case baload:{
+ prl(getTopTwo());
+ prl(cmdToEStack(genArray("tempb")+"[tempa+1]"));
+ break;
+ }
+ case astore:
+ case bastore:{
+ prl(cmdFromEStack("tempres"));
+ prl(getTopTwo());
+ //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 := "+genArray("tempb")+" > :");
+ prl("tempArray[tempa+1]:=tempres ENDVAR;");
+ break;
+ }
//TODO arraylength
//TODO dup, dup2