Permalink
Browse files

compiling to .erj

  • Loading branch information...
1 parent 24d492a commit 1aa836fdcb376e305890a7412b4bb2bd8f1423a7 @krestenkrab krestenkrab committed Dec 4, 2009
View
@@ -6,8 +6,6 @@
<classpathentry kind="lib" path="lib/OtpErlang.jar"/>
<classpathentry kind="lib" path="lib/antlr-3.2.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
- <classpathentry kind="lib" path="target/gen"/>
- <classpathentry kind="lib" path="lib/asm-all-2.2.3.jar"/>
<classpathentry kind="lib" path="lib/kilim-0.6-krab.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
View
@@ -0,0 +1,103 @@
+<?xml version="1.0"?>
+<project name="erjang" default="all">
+ <property name="erjang.version" value="0.1" />
+ <path id="erjang.classpath">
+ <pathelement location="target/classes/" />
+ <pathelement location="lib/kilim-0.6-krab.jar" />
+ <pathelement location="lib/OtpErlang.jar" />
+ <pathelement location="lib/junit.jar" />
+ <pathelement location="lib/antlr-3.2.jar" />
+ <pathelement path="${java.class.path}" />
+ </path>
+ <path id="erjang.testwovenclasspath">
+ <pathelement location="target/classes/" />
+ <pathelement location="target/test-classes/" />
+ <pathelement location="lib/kilim-0.6-krab.jar" />
+ <pathelement location="lib/OtpErlang.jar" />
+ <pathelement location="lib/junit.jar" />
+ <pathelement location="lib/antlr-3.2.jar" />
+ <pathelement path="${java.class.path}" />
+ </path>
+
+ <target name="all" depends="clean,weave,jar" />
+ <target name="test" depends="all,testwoven" />
+
+ <target name="compile">
+ <mkdir dir="target" />
+ <mkdir dir="target/classes" />
+ <mkdir dir="target/test-classes" />
+ <mkdir dir="target/compiled" />
+
+ <echo message="Compiling src ===================" />
+ <javac debug="on" srcdir="src/main/java" destdir="target/classes"
+ classpathref="erjang.classpath"/>
+ </target>
+
+ <target name="testcompile" depends="compile">
+ <echo message="Compiling test ===================" />
+ <javac debug="on" srcdir="src/test/java" destdir="target/test-classes"
+ classpathref="erjang.classpath"/>
+ </target>
+
+
+ <target name="weave" depends="testcompile">
+ <echo message="Weaving files ===================" />
+ <java classname="kilim.tools.Weaver" fork ="yes">
+ <classpath refid="erjang.classpath"/>
+ <assertions>
+ <enable/>
+ </assertions>
+ <arg value="-d" />
+ <arg value="./target/classes" />
+ <arg line="./target/classes" />
+ </java>
+ <echo message="Weaving test classes ==============" />
+ <java classname="kilim.tools.Weaver" fork ="yes">
+ <classpath refid="erjang.testwovenclasspath"/>
+ <assertions>
+ <enable/>
+ </assertions>
+ <arg value="-d" />
+ <arg value="./target/test-classes" />
+ <arg line="./target/test-classes" />
+ </java>
+
+ </target>
+
+ <target name="clean">
+ <echo message="deleting files" />
+ <delete>
+ <fileset defaultexcludes="no" dir="." includes="*~,#*,foo,bar,x,y" />
+ </delete>
+ <delete dir="./target" />
+ </target>
+
+
+ <!-- This runs those tests depend on generated classes in testclasses-->
+ <target name="testwoven" >
+ <echo message="Testing Tasks ======================" />
+ <java classname="junit.textui.TestRunner" fork="yes">
+ <classpath refid="erjang.testwovenclasspath"/>
+ <assertions>
+ <enable/>
+ </assertions>
+ <arg value="erjang.AllTests" />
+ </java>
+ </target>
+
+ <target name="jar" description="generate the distribution" depends="clean,weave">
+ <copy file="License" todir="classes/erjang" />
+ <jar jarfile="erjang-${erjang.version}.jar" basedir="target/classes">
+ <zipgroupfileset dir="lib" includes="*.jar">
+ <exclude name="junit.jar" />
+ <exclude name="asm-all-2.2.3.jar" />
+ </zipgroupfileset>
+ <exclude name="erjang/test/**" />
+ <exclude name="erjang/examples/**" />
+ <exclude name="erjang/bench/**" />
+ <manifest>
+ <attribute name="Main-Class" value="erjang.Erj"/>
+ </manifest>
+ </jar>
+ </target>
+</project>
View
Binary file not shown.
View
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+java -cp erjang-0.1.jar -Derjpath=./src/main/erl/preloaded/ebin:src/main/erl erjang.Erj fib:main
View
Binary file not shown.
View
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+java -cp erjang-0.1.jar -Derjpath=./src/main/erl/preloaded/ebin:src/main/erl erjang.Erj ring:main
View
Binary file not shown.
View
Binary file not shown.
@@ -19,6 +19,7 @@
package erjang;
import java.util.zip.Adler32;
+import java.util.zip.CRC32;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
@@ -116,6 +117,20 @@ static long adler32(long adler, int byte_value) {
}
return res;
}
+
+ public long crc() {
+ CRC32 crc = new CRC32();
+
+ int octets = bitCount() / 8;
+ if ((bitOff % 8) == 0) {
+ crc.update(data, bitOff / 8, octets);
+ } else {
+ for (int i = 0; i < octets; i++) {
+ crc.update( (byte) octetAt(i) );
+ }
+ }
+ return crc.getValue();
+ }
/**
* @return
@@ -430,4 +430,11 @@ public static void main(String[] args) {
}
}
+ /**
+ * @param arity
+ */
+ public static void ensure(int arity) {
+ get_fun_class(arity);
+ }
+
}
@@ -18,16 +18,15 @@
package erjang;
+import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executor;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import kilim.Mailbox;
import kilim.Pausable;
+import erjang.beam.Compiler;
@Module(value="erlang")
@@ -270,6 +269,7 @@ public static EAtom guard(boolean bool) {
private static final EAtom AM_TIMEOUT = EAtom.intern("timeout");
private static final EAtom am_try_case_clause = EAtom.intern("try_case_clause");
private static final EAtom am_if_clause = EAtom.intern("if_clause");
+ public static final boolean DEBUG = false;
public EBitStringBuilder bs_init(int size, int flags) {
return new EBitStringBuilder(size, flags);
@@ -470,5 +470,8 @@ public static void timeout() {
// skip //
}
-
+ static void load(EAtom module) throws IOException {
+ File f = Compiler.find_and_compile(module.getName());
+ EModule.load_module(module, f.toURI().toURL());
+ }
}
@@ -19,8 +19,8 @@
package erjang;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
-import java.net.URL;
/**
*
@@ -33,7 +33,8 @@
"prim_zip", "zlib" };
@SuppressWarnings("unchecked")
- public static void main(String[] args) throws ClassNotFoundException, MalformedURLException, InstantiationException, IllegalAccessException {
+ public static void main(String[] args)
+ throws Exception {
String m = args[0];
String f;
@@ -49,22 +50,18 @@ public static void main(String[] args) throws ClassNotFoundException, MalformedU
EAtom fun = EAtom.intern(f);
EModule[] modules = new EModule[MODULES.length];
- File preloaded_dir = new File(PRELOADED);
for (int i = 0; i < modules.length; i++) {
String mod = MODULES[i];
- File dir = preloaded_dir;
-
- File path = new File(dir, mod + ".classes");
-
- load(path, mod);
+
+ ERT.load(EAtom.intern(mod));
}
EModule.load_module(EAtom.intern("io"), new File("target/classes").toURL());
EModule.load_module(EAtom.intern("timer"), new File("target/classes").toURL());
- load(new File("src/main/erl/" + m + ".classes"), m);
+ ERT.load(EAtom.intern(m));
ESeq env = ERT.NIL;
ESeq argv = ERT.NIL;
@@ -79,17 +76,6 @@ public static void main(String[] args) throws ClassNotFoundException, MalformedU
ERT.run(p=new EProc(null, module, fun, argv ));
p.joinb();
- System.out.println("ready for second run...");
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- ERT.run(p=new EProc(null, module, fun, argv ));
- p.joinb();
-
-
System.out.println("done.");
}
@@ -40,8 +40,8 @@ public static void main(String[] args) throws OtpAuthException, IOException {
if (args[i].endsWith(".beam")) {
File in = new File(args[i]);
int idx = args[i].lastIndexOf('.');
- File out = new File(args[i].substring(0, idx) + ".classes");
- DirClassRepo jcp = new DirClassRepo(out);
+ File out = new File(args[i].substring(0, idx) + ".jar");
+ JarClassRepo jcp = new JarClassRepo(out);
System.out.println("compining "+in+" -> "+out+" ...");
new Compiler(jcp).compile(in);
@@ -29,6 +29,7 @@
import erjang.EAtom;
import erjang.EBig;
import erjang.EDouble;
+import erjang.ERT;
import erjang.ESmall;
import erjang.EObject;
import erjang.EProc;
@@ -272,8 +273,8 @@ private BuiltInFunction find_bif(Type[] parmTypes) {
for (Args a : args.generalize()) {
m = found.get(a);
if (m != null) {
-
- System.err.println("missed opportunity erlang:"
+ if (ERT.DEBUG)
+ System.err.println("missed opportunity erlang:"
+ EAtom.intern(name) + "/" + parmTypes.length + " "
+ args + ", \n\tusing " + m);
Oops, something went wrong.

0 comments on commit 1aa836f

Please sign in to comment.