gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control systemauthor | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 26 Jul 2014 20:38:53 +0000 (22:38 +0200) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 26 Jul 2014 20:39:49 +0000 (22:39 +0200) |
version 0.1.8
.gitignore | patch | blob | history | |
build.xml | patch | blob | history | |
res/version.properties | [new file with mode: 0644] | patch | blob |
samples/fields.mj | [new file with mode: 0644] | patch | blob |
src-wsl/transf-exp.wsl | patch | blob | history | |
src/mjc2wsl.java | patch | blob | history |
diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
# compiled versions
*.class
*.obj
+bin/*
#backups
*~
diff --git a/build.xml b/build.xml
--- a/build.xml
+++ b/build.xml
<fileset dir="${log.dir}"/>
</delete>
</target>
+
+ <!-- version tasks
+ based on ideas by Jesper Öqvist http://llbit.se/?p=1876 -->
+ <!-- this target is only run if the 'version' property is undefined -->
+
+ <target name="update-version-string" unless="version">
+ <!-- get a new version string using git describe if possible -->
+ <echo message="Updating version string..."/>
+ <exec executable="git" outputproperty="version"
+ failifexecutionfails="false">
+ <arg value="describe"/>
+ </exec>
+ <antcall target="-store-version-string"/>
+ <!-- ensure version is defined even if git was not available -->
+ <property file="${res.dir}/version.properties"/>
+ </target>
+ <target name="-store-version-string" if="version">
+ <!-- store the new version string in the correct property file -->
+ <echo message="version=${version}"/>
+ <propertyfile file="${res.dir}/version.properties">
+ <entry key="version" value="${version}"/>
+ </propertyfile>
+ <exec executable="git" failifexecutionfails="false">
+ <arg value="update-index"/>
+ <arg value="--assume-unchanged"/>
+ <arg value="${res.dir}/version.properties"/>
+ </exec>
+ </target>
+
<!-- mjc2wsl related tasks -->
- <target name="build" depends="init" description="build the mjc2wsl tool">
+ <target name="build" depends="init,update-version-string" description="build the mjc2wsl tool">
<javac srcdir="${mjc2wsl.src.dir}" destdir="${mjc2wsl.class.dir}" includeAntRuntime='no' />
</target>
diff --git a/res/version.properties b/res/version.properties
--- /dev/null
+++ b/res/version.properties
@@ -0,0 +1 @@
+version=v0.1.7
diff --git a/samples/fields.mj b/samples/fields.mj
--- /dev/null
+++ b/samples/fields.mj
@@ -0,0 +1,44 @@
+program F
+ class HolderClass {
+ int simple;
+ int[] arry;
+ }
+
+ HolderClass holder;
+
+{
+ void main()
+ int i, size;
+ {
+ holder = new HolderClass;
+ holder.simple = 5;
+
+ print(holder.simple,10);
+
+ print(chr(10));
+
+ size = 5;
+ holder.arry = new int[size];
+ holder.arry[0] = size+1;
+ i = 1;
+ while (i < size){
+ holder.arry[i] = holder.arry[i-1]-1;
+ i++;
+ }
+
+ i = 0;
+ while (i < size){
+ print(holder.arry[i],3);
+ i++;
+ }
+ print(chr(10));
+
+ i = 0;
+ while (i < size){
+ holder.arry[i]--;
+ print(holder.arry[i],3);
+ i++;
+ }
+
+ }
+}
\ 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
@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
@Trans(TR_Floop_To_While, "");
FI
OD;
+ FOREACH Statement DO
+ IF @Trans?(TR_Flag_Removal) THEN
+ @Trans(TR_Flag_Removal, "");
+ FI
+ OD;
C:"Go back to the start, and remove redundant";
@GOTO(< >);
@Trans(TR_Delete_All_Redundant, "");
diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java
--- a/src/mjc2wsl.java
+++ b/src/mjc2wsl.java
* @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
*/
public class mjc2wsl{
- public static String versionN = "0.1.7";
+ //default version name, used if the file is not found
+ private static String versionN = "0.1.x";
+ private String versionFile = "version.properties";
+
private TransMessages messages = new TransMessages();
private boolean genPauseAfterEachAddress=false,
private boolean genPopPush=false;
+ private boolean genInlinePrint=false;
+
/** Constant used for marking a regular comment from the original file */
public static final char C_REG = ' ';
/**
return opMap;
}
+ private Properties versionData;
+
+ private String getVersion() {
+ if (versionData == null) {
+ versionData = new Properties();
+ try {
+ versionData.load(getClass().getResourceAsStream(versionFile));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ String ver = versionData.getProperty("version");
+ if (ver != null)
+ return ver;
+ else
+ return versionN;
+ }
+
public String getOpString(int op) {
return getOpMap().get(op);
}
public String createStandardStart(int numWords){
StringBuilder ret = new StringBuilder(
"C:\" This file automatically converted from microjava bytecode\";\n"
- +"C:\" with mjc2wsl v "+versionN+"\";\n");
+ +"C:\" with mjc2wsl v "+getVersion()+"\";\n");
ret.append("\nBEGIN");
ret.append("\nVAR <\n\t");
ret.append("\t@List_To_String(< num >)\n");
ret.append("END\n");
- ret.append("\nPROC Print_MJ(val, format VAR)==\n");
- ret.append(createComment("print spacing", C_SPEC));
- ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
- ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
- ret.append("\tFI;\n\tPRINFLUSH(val)\nEND\n");
-
- ret.append("\nPROC Print_MJ_CHAR(val, format VAR)==\n");
- ret.append(createComment("print spacing", C_SPEC));
- ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
- ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
- ret.append("\tFI;\n\tPRINFLUSH(CHR(val))\n");
- ret.append("END\n");
+ if (!genInlinePrint) {
+ ret.append("\nPROC Print_MJ(val, format VAR)==\n");
+ ret.append(createComment("print spacing", C_SPEC));
+ ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
+ ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
+ ret.append("\tFI;\n\tPRINFLUSH(val)\nEND\n");
+
+ ret.append("\nPROC Print_MJ_CHAR(val, format VAR)==\n");
+ ret.append(createComment("print spacing", C_SPEC));
+ ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
+ ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
+ ret.append("\tFI;\n\tPRINFLUSH(CHR(val))\n");
+ ret.append("END\n");
+ }
ret.append("\nEND");
return ret.toString();
case getfield: {
int f = get2();
+ prl(createStartVar("tempa"));
prl(createTopEStack());
prl(createToEStack(createObject("tempa") + "[" + (f + 1) + "]"));
+ prl(createEndVar());
break;
}
case putfield: {
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(createTopTwoEStack());
- prl("VAR < tempArray := " + createObject("tempb") + " > :");
- prl("tempArray[" + (f + 1) + "]:=tempa ENDVAR;");
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopTwoEStack());
+ prl(createObject("tempb") + "[" + (f + 1) + "]:=tempa;");
+ prl(createEndVar());
break;
}
break;
}
+ case const_m1: {
+ prl(createToEStack(-1));
+ break;
+ }
+
case const_0:
case const_1:
case const_2:
case bprint: {
prl(createStartVar("tempa", "tempb"));
prl(createTopTwoEStack());
- prl("Print_MJ_CHAR(tempb,tempa);");
+ if (genInlinePrint){
+ prl(createComment("print spacing and transformation",C_SPEC));
+ prl("PRINFLUSH(SUBSTR(\" \", 0, MIN(10, MAX(0,tempa-1))), @List_To_String(< tempb >));");
+ } else
+ prl("Print_MJ_CHAR(tempb,tempa);");
prl(createEndVar());
break;
}
prl(createStartVar("tempa", "tempb"));
prl(createTopTwoEStack());
- prl("Print_MJ(tempb,tempa);");
+ if (genInlinePrint){
+ prl(createComment("print spacing",C_SPEC));
+ prl("PRINFLUSH(SUBSTR(\" \", 0, MIN(10, MAX(0, tempa-SLENGTH(@String(tempb))))), tempb);");
+ }
+ else
+ prl("Print_MJ(tempb,tempa);");
prl(createEndVar());
break;
}
public void printHelpDirectives(){
System.out.println("Alternatives for code generation:");
System.out.println(" --genPopPush generate POP/PUSH instead of TAIL/HEAD");
+ System.out.println(" --genHeadTail generate TAIL/HEAD instead of POP/PUSH ");
+ System.out.println();
+ System.out.println(" --genInlinePrint generate prints directly instead of procedure calls");
+ System.out.println(" --genProcedurePrint generate prints as custom procedure calls");
}
public void printHelpHelp() {
}
public void printVersion() {
- System.out.println("MicroJava bytecode to WSL converter. v " + versionN
+ System.out.println("MicroJava bytecode to WSL converter. v " + getVersion()
+ ", by Doni Pracner");
}
genPauseAfterEachAddress = true;
} else if (args[i].compareToIgnoreCase("--genPopPush") == 0) {
genPopPush = true;
+ } else if (args[i].compareToIgnoreCase("--genInlinePrint") == 0) {
+ genInlinePrint = true;
+ } else if (args[i].compareToIgnoreCase("--genHeadTail") == 0) {
+ genPopPush = false;
+ } else if (args[i].compareToIgnoreCase("--genProcedurePrint") == 0) {
+ genInlinePrint = false;
}
i++;
}