gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
Merge branch 'vars' into work
authorDoni Pracner <quinnuendo@gmail.com>
Tue, 22 Apr 2014 20:17:55 +0000 (22:17 +0200)
committerDoni Pracner <quinnuendo@gmail.com>
Tue, 22 Apr 2014 20:17:55 +0000 (22:17 +0200)
docs/mjc2wsl.txt
src-wsl/transf-exp.wsl
src/mjc2wsl.java

index 27584dc475541da43f5c96173a208ea64b197fcd..788e0bc23835aa466233ada85c20960caf9c3c85 100644 (file)
@@ -65,5 +65,15 @@ work. Note however that the language specification is not
 allowing direct access to the memory, neither is the
 bytecode actually working directly with the heap, and that
 array and object access are done by specialised commands.
-Still there is an option for using indexes out of bounds
-that could produce unexpected behaviour.
\ No newline at end of file
+Still there is an option for using fields beyond the actuall
+object that could produce unexpected behaviour.
+Array access in the MJVM does check for indexe out of bounds
+errors.
+
+The size of the heap is not taken into consideration when
+allocating new arrays and objects. What this means is that
+there will be no heap overflow exception thrown, since our
+heap is seemingly endless.
+
+Null access does not throw explicit errors, although it
+will cause problems with the list access.
\ No newline at end of file
index 5b1bd1076663f924b6c91736545a735b1b7ed6e7..1bffdbd33f7aa2dafbe0163bf1d89747cfb160ef 100755 (executable)
@@ -20,7 +20,11 @@ License along with this program. If not, see
 
 C:"Automatic transformation tool for simplification of WSL";
 C:"code automaticaly translated from assembly using asm2wsl.";
-C:"a simple version";
+C:"experimental version";
+
+C:"set the following so that Action Systems are not automaticaly treated as regular";
+Assume_A_S_Regular := 0;
+
 MW_PROC @Process_Prog() ==
        FOREACH Statement DO
                IF @Trans?(TR_Push_Pop) THEN
@@ -31,6 +35,7 @@ MW_PROC @Process_Prog() ==
        FOREACH Statement DO
                IF @ST(@I) = T_A_S THEN 
                        C:"don't need to test for this, works for T_A_S";
+                       @Trans(TR_Simplify_Action_System, "");
                        IF @Trans?(TR_Collapse_Action_System) THEN
                                @Trans(TR_Collapse_Action_System, "");
                        FI;
@@ -40,12 +45,23 @@ MW_PROC @Process_Prog() ==
                        @Delete  
                FI
        OD;
+       FOREACH Statement DO
+               IF @Trans?(TR_Flag_Removal) THEN
+                       @Trans(TR_Flag_Removal, "");
+               FI
+       OD;
        C:"remove all the comments ";
        FOREACH Statement DO
        IF @ST(@I) = T_Comment THEN 
                        @Delete
        FI
        OD;
+       FOREACH Statement DO
+             IF @Trans?(TR_Simplify_Item) THEN
+               @Trans(TR_Simplify_Item,"")
+             FI
+       OD;
+
        C:"Convert DO loops into WHILE loops";
        FOREACH Statement DO
                IF @Trans?(TR_Floop_To_While) THEN
@@ -74,10 +90,10 @@ IF @File_Exists?(inifilename) THEN
                        @Process_Prog();
                        Get_New_Name(VAR filename);
                        @PP_Item(@Program, 80, filename);
-                       Prog_Stat(prog);
-                       PRINT("");
-                       PRINT("After Conversion");
-                       Prog_Stat(@Program)
+                       PRINT("<Metrics>");
+                       PRINT(filename);
+                       Prog_Stat_Comp(prog, @Program);
+                       PRINT("</Metrics>")
                FI;
                filename := @Read_Line(inifile)
        OD;
@@ -106,6 +122,27 @@ PROC Prog_Stat(Pro VAR)==
   SKIP
 END
 
+PROC Prog_Stat_Comp(Pro, After VAR)==
+  VAR < ma := 0, mb :=1 > :
+  ma := @McCabe(Pro);
+  mb := @McCabe(After);
+  PRINT ("McCabe ", ma, "  ", mb, "  ",(mb-ma));
+  ma := @Stat_Count(Pro);
+  mb := @Stat_Count(After);
+  PRINT ("Statem ", ma, "  ",mb, "  ",(mb-ma));
+  ma := @CFDF_Metric(Pro);
+  mb := @CFDF_Metric(After);
+  PRINT ("CF/DF  ", ma,"  ", mb,"  ", (mb-ma));
+  ma := @Total_Size(Pro);
+  mb := @Total_Size(After);
+  PRINT ("Size   ", ma,"  ", mb, "  ",(mb-ma));
+  ma := @Struct_Metric(Pro);
+  mb := @Struct_Metric(After);
+  PRINT ("Struct ", ma, "  ",mb, "  ",(mb-ma));
+  SKIP
+  ENDVAR
+END
+
 PROC Get_New_Name(VAR str) == 
        IF @Ends_With?(str, ".wsl") THEN
                str := SUBSTR(str, 0, SLENGTH(str)-4)
index 44c0c67b202fe0d5b532eefdf470fa32e4e45816..388f1ad39b965402297e05535b2a157482c3cd27 100644 (file)
@@ -193,7 +193,7 @@ public class mjc2wsl{
                        +"C:\" with mjc2wsl v "+versionN+"\";\n");
        
                ret.append("BEGIN ");
-               ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\n\t");
+               ret.append("VAR < \n\t");
                ret.append("mjvm_locals := ARRAY(1,0), ");
                ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0), ");
                ret.append("\n\tmjvm_arrays := < >, ");
@@ -219,6 +219,20 @@ public class mjc2wsl{
                return ret.toString();
        }
 
+       private String createStartVar(String... vars){
+               StringBuilder ret = new StringBuilder("VAR < ");
+               ret.append(vars[0] + " := 0");
+               for (int i=1; i<vars.length; i++)
+                               ret.append(", "+ vars[i] +" := 0");
+               ret.append(" > : ");
+               
+               return ret.toString();
+       }
+       
+       private String createEndVar(){
+               return "ENDVAR;";
+       }
+       
        private String createLocal(int i) {
                // arrays start at 1 in WSL, so we need an offset
                return "mjvm_locals[" + (i + 1) + "]";
@@ -415,41 +429,53 @@ public class mjc2wsl{
                        }
 
                        case add: {
+                               prl(createStartVar("tempa", "tempb", "tempres"));
                                prl(createTopTwoEStack());
                                prl("tempres := tempb + tempa;");
                                prl(createToEStack("tempres"));
+                               prl(createEndVar());
                                break;
                        }
                        case sub: {
+                               prl(createStartVar("tempa", "tempb", "tempres"));
                                prl(createTopTwoEStack());
                                prl("tempres := tempb - tempa;");
                                prl(createToEStack("tempres"));
+                               prl(createEndVar());
                                break;
                        }
                        case mul: {
+                               prl(createStartVar("tempa", "tempb", "tempres"));
                                prl(createTopTwoEStack());
                                prl("tempres := tempb * tempa;");
                                prl(createToEStack("tempres"));
+                               prl(createEndVar());
                                break;
                        }
                        case div: {
+                               prl(createStartVar("tempa", "tempb", "tempres"));
                                prl(createTopTwoEStack());
                                prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
                                prl("tempres := tempb DIV tempa;");
                                prl(createToEStack("tempres"));
+                               prl(createEndVar());
                                break;
                        }
                        case rem: {
+                               prl(createStartVar("tempa", "tempb", "tempres"));
                                prl(createTopTwoEStack());
                                prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
                                prl("tempres := tempb MOD tempa;");
                                prl(createToEStack("tempres"));
+                               prl(createEndVar());
                                break;
                        }
 
                        case neg: {
+                               prl(createStartVar("tempa"));
                                prl(createTopEStack());
                                prl(createToEStack("-tempa"));
+                               prl(createEndVar());                            
                                break;
                        }
 
@@ -547,10 +573,13 @@ public class mjc2wsl{
                        case jle:
                        case jgt:
                        case jge: {
+                               prl(createStartVar("tempa", "tempb"));
                                prl(createTopTwoEStack());
                                prl("IF tempb " + getRelationFor(op) + " tempa THEN CALL a"
                                                + (counter + get2()) + " ELSE CALL a" + (counter + 1)
                                                + " FI;");
+                               prl(createEndVar());
+                               
                                break;
                        }
 
@@ -587,8 +616,10 @@ public class mjc2wsl{
                                prl(createComment("char is read like a number", C_SPEC));
                        }
                        case read: {
+                               prl(createStartVar("tempa"));
                                prl("tempa := @String_To_Num(@Read_Line(Standard_Input_Port));");
                                prl(createToEStack("tempa"));
+                               prl(createEndVar());
                                break;
                        }
 
@@ -601,8 +632,11 @@ public class mjc2wsl{
                        }
                        case print: {
                                // TODO printing numbers needs different lengths of spacing
+                               prl(createStartVar("tempa", "tempb"));
+
                                prl(createTopTwoEStack());
                                prl("Print_MJ(tempb,tempa);");
+                               prl(createEndVar());
                                break;
                        }
 
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner