gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
mjc2wsl - enter/exit proper storage of local variables on the stack in procedure...
authorDoni Pracner <quinnuendo@gmail.com>
Wed, 8 Jan 2014 21:31:08 +0000 (22:31 +0100)
committerDoni Pracner <quinnuendo@gmail.com>
Wed, 8 Jan 2014 21:31:08 +0000 (22:31 +0100)
src/mjc2wsl.java

index 1b31bbae3bdcdb92af2861b96a0b75d4e5730775..d098bd8e2069d97e23df332a754c6e835aa487b8 100644 (file)
@@ -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,18 +420,17 @@ 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;
                        }
 
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner