gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
mjc2wsl - shr and shl added
[mjc2wsl.git] / src / mjc2wsl.java
index 6f7efe1..1682978 100644 (file)
@@ -121,6 +121,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("mjvm_locals := ARRAY(1,0), ");
                ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0), ");
                ret.append("\n\tmjvm_arrays := < >, ");
+               ret.append("\n\tmjvm_objects := < >, ");
                ret.append("\n  mjvm_estack := < >, mjvm_mstack := < >, "); 
                ret.append("\n  mjvm_fp := 0, mjvm_sp := 0,");
                ret.append("\n  t_e_m_p := 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 > :");
@@ -224,6 +225,10 @@ public class mjc2wsl{
                        return "mjvm_arrays["+ i+"]";
        }
        
                        return "mjvm_arrays["+ i+"]";
        }
        
+       private String genObject(String i){
+                       return "mjvm_objects["+ i+"]";
+       }
+       
        /**
         * Creates a WSL comment with care to quote chars.
         */
        /**
         * Creates a WSL comment with care to quote chars.
         */
@@ -362,12 +367,20 @@ public class mjc2wsl{
                                prl(cmdFromEStack(genStatic(get2())));
                                break;
                        }
                                prl(cmdFromEStack(genStatic(get2())));
                                break;
                        }
-                       //TODO getfield, putfield
-                       case getfield:
+
+                       case getfield:{
+                                       int f = get2();
+                                       prl(getTop());
+                                       prl(cmdToEStack(genObject("tempa")+"["+(f+1)+"]"));
+                                       break;
+                       }
                        case putfield:{
                        case putfield:{
-                                       prl(createComment("fields are not processed properly", C_ERR));
-                                       message("fields are not processed properly", M_ERR);
-                                       get2();
+                                       int f = get2();
+                                       //we need to use a temparray as a pointer, WSL
+                                       //otherwise tries to access it as a list of lists and fails
+                                       prl(getTopTwo());
+                                       prl("VAR < tempArray := "+genObject("tempb")+" > :");
+                                       prl("tempArray["+(f+1)+"]:=tempa ENDVAR;");                             
                                        break;
                        }
                        
                                        break;
                        }
                        
@@ -424,18 +437,35 @@ public class mjc2wsl{
                                prl(cmdToEStack("-tempa"));
                                break;
                        }                       
                                prl(cmdToEStack("-tempa"));
                                break;
                        }                       
-                       //TODO shl, shr
-                       
+
+                       case shl  : {
+                               prl(getTopTwo());
+                               prl("VAR <tempres :=tempb, i:=1 >:");
+                               prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres * 2 OD;");
+                               prl(cmdToEStack("tempres"));
+                               prl("ENDVAR;");
+                               break;
+                       }
+                       case shr  : {
+                               prl(getTopTwo());
+                               prl("VAR <tempres :=tempb, i:=1 >:");
+                               prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres DIV 2 OD;");
+                               prl(cmdToEStack("tempres"));
+                               prl("ENDVAR;");
+                               break;
+                       }
+
                        case inc  : {
                                int b1 = get(), b2 = get();
                                prl(loc(b1)+" := " +loc(b1)+" + "+b2+";");
                                break;
                        }
                        case inc  : {
                                int b1 = get(), b2 = get();
                                prl(loc(b1)+" := " +loc(b1)+" + "+b2+";");
                                break;
                        }
-                       //TODO new_ newarray
+
                        case new_ :{
                        case new_ :{
-                                       prl(createComment("memory allocation not processed properly", C_ERR));
-                                       message("memory allocation  not processed properly", M_ERR);
-                                       get2();
+                                       int size = get2();
+                                       //TODO maybe objects and arrays should be in the same list?
+                                       prl("mjvm_objects := mjvm_objects ++ < ARRAY("+size+",0) >;");
+                                       prl(cmdToEStack("LENGTH(mjvm_objects)"));
                                        break;
                        }
                        case newarray :{
                                        break;
                        }
                        case newarray :{
@@ -473,7 +503,20 @@ public class mjc2wsl{
                                break;
                        }
                        
                                break;
                        }
                        
-                       //TODO dup, dup2
+                       case dup : {
+                                       prl(getTop());
+                                       prl(cmdToEStack("tempa"));
+                                       prl(cmdToEStack("tempa"));
+                                       break;                                  
+                       }
+                       case dup2 : {
+                                       prl(getTopTwo());
+                                       prl(cmdToEStack("tempb"));
+                                       prl(cmdToEStack("tempa"));
+                                       prl(cmdToEStack("tempb"));
+                                       prl(cmdToEStack("tempa"));
+                                       break;                                  
+                       }
                        
                        case pop : {
                                        prl(cmdPopEStack());
                        
                        case pop : {
                                        prl(cmdPopEStack());
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner