gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
array assignment simplified
[mjc2wsl.git] / src / mjc2wsl.java
index 113bfef..18551d1 100644 (file)
@@ -28,7 +28,7 @@ import java.util.*;
  * @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
  */
 public class mjc2wsl{
-       public static String versionN = "0.1.6";
+       public static String versionN = "0.1.7";
 
        private TransMessages messages = new TransMessages();
 
@@ -201,6 +201,7 @@ public class mjc2wsl{
                ret.append("mjvm_locals := ARRAY(1,0),");
                ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0),");
                ret.append("\n\tmjvm_arrays := < >,");
+               ret.append("\n\tmjvm_flag_jump := 0,");
                ret.append("\n\tmjvm_objects := < >,");
                ret.append("\n\tmjvm_estack := < >, mjvm_mstack := < > > :");
 
@@ -569,12 +570,11 @@ public class mjc2wsl{
                        }
                        case astore:
                        case bastore: {
+                               prl(createStartVar("tempa", "tempb", "tempres"));
                                prl(createFromEStack("tempres"));
                                prl(createTopTwoEStack());
-                               // 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 := " + createArray("tempb") + " > :");
-                               prl("tempArray[tempa+1]:=tempres ENDVAR;");
+                               prl("mjvm_arrays[tempb][tempa+1]:=tempres;");
+                               prl(createEndVar());
                                break;
                        }
                        case arraylength: {
@@ -617,10 +617,15 @@ public class mjc2wsl{
                        case jge: {
                                prl(createStartVar("tempa", "tempb"));
                                prl(createTopTwoEStack());
-                               prl("IF tempb " + getRelationFor(op) + " tempa THEN CALL a"
-                                               + (counter + get2()) + " ELSE CALL a" + (counter + 1)
+                               prl("IF tempb " + getRelationFor(op) 
+                                               + " tempa THEN mjvm_flag_jump := 1"
+                                               + " ELSE mjvm_flag_jump := 0" 
                                                + " FI;");
                                prl(createEndVar());
+                               prl("IF mjvm_flag_jump = 1 THEN CALL a"
+                                               + (counter + get2()) 
+                                               + " ELSE CALL a" + (counter + 1)
+                                               + " FI;");
                                
                                break;
                        }
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner