gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control systemauthor | Doni Pracner <quinnuendo@gmail.com> | |
Tue, 22 Apr 2014 20:17:55 +0000 (22:17 +0200) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Tue, 22 Apr 2014 20:17:55 +0000 (22:17 +0200) |
docs/mjc2wsl.txt | patch | blob | history | |
src-wsl/transf-exp.wsl | patch | blob | history | |
src/mjc2wsl.java | patch | blob | history |
diff --git a/docs/mjc2wsl.txt b/docs/mjc2wsl.txt
--- a/docs/mjc2wsl.txt
+++ b/docs/mjc2wsl.txt
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
diff --git a/src-wsl/transf-exp.wsl b/src-wsl/transf-exp.wsl
--- a/src-wsl/transf-exp.wsl
+++ b/src-wsl/transf-exp.wsl
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
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;
@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
@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;
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)
diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java
--- a/src/mjc2wsl.java
+++ b/src/mjc2wsl.java
+"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 := < >, ");
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) + "]";
}
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;
}
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;
}
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;
}
}
case print: {
// TODO printing numbers needs different lengths of spacing
+ prl(createStartVar("tempa", "tempb"));
+
prl(createTopTwoEStack());
prl("Print_MJ(tempb,tempa);");
+ prl(createEndVar());
break;
}