diff --git a/README b/README index b5c4b55d..2324dcce 100644 --- a/README +++ b/README @@ -1,12 +1,78 @@ -Erjang Readme +Erjang - a JVM-based Erlang VM --- + Wiki Pages: www.erjang.org + Discussion: http://groups.google.com/group/erjang + Source: http://github.com/krestenkrab/erjang -At this stage nothing works, so don't get your hopes up. -You cannot even compile "hello world". +-- + +BUILDING + + +You should be able to do "ant jar", and thereafter run the sample +with + + prompt% ant jar + ... + prompt% ./ring_test.sh + ... + loading io + loading timer + loading ring + loading erlang + io:format "~p Starting message~n" [{1259,922511,63000}] + io:format "~p Around ring ~p times ~n" [{1259,922512,434000},10000] + io:format "~p Around ring ~p times ~n" [{1259,922513,600000},20000] + io:format "~p Around ring ~p times ~n" [{1259,922514,763000},30000] + io:format "~p Around ring ~p times ~n" [{1259,922515,930000},40000] + io:format "~p Around ring ~p times ~n" [{1259,922517,117000},50000] + .... + +The source for the few samples are in src/main/erl. + +-- + +RUNNING + +When running, it writes files named ".erj/module-${CRC}.jar". These +files are written in response to erlang:compile_module(Module,Binary). + +These files also serve as a cache of files translated from beam -> jar. +If something goes astray, it may help to remove the .erj directory +forcing Erjang to recompile next time it runs. + +-- + +PREREQUISITES + +I have only been testing this with Erlang/OTP R13B02. + +While we are still bootstrapping, the compiler uses a remote +erlang process to parse beam files (using beam_disasm), so you +need to have this running: + + prompt% cd src/main/erl + prompt% erl -sname beam_loader@localhost -s beam_loader + +Otherwise you will get errors like this: + +Exception in thread "main" java.lang.Error: java.io.IOException: Cannot connect to peer node + at erjang.beam.Compiler.(Compiler.java:55) + at erjang.EModule.load_module(EModule.java:429) + at erjang.Erj.main(Erj.java:61) + +Eventually this will obviously be self-hosted in Erjang. + + +To run the tests, you need an OTP distribution, and go edit src/test/java/erjang/TestAll.java +to tell it where your OTP_HOME is. + + + +Cheers! Kresten Krab Thorup -krab@trifork.com +krab _at_ trifork dot com diff --git a/erjang-0.1.jar b/erjang-0.1.jar index 1b048835..f03a5535 100644 Binary files a/erjang-0.1.jar and b/erjang-0.1.jar differ diff --git a/src/main/java/erjang/EModule.java b/src/main/java/erjang/EModule.java index d5cce4e8..10006bc5 100644 --- a/src/main/java/erjang/EModule.java +++ b/src/main/java/erjang/EModule.java @@ -74,7 +74,7 @@ public int compare(Field o1, Field o2) { * @throws IllegalAccessException * @throws IllegalArgumentException */ - synchronized boolean add_import(Field ref) throws Exception { + synchronized boolean add_import(final Field ref) throws Exception { resolve_points.add(ref); if (resolved_value != null) { //System.out.println("binding "+fun+" "+resolved_value+" -> "+ref); @@ -86,8 +86,19 @@ synchronized boolean add_import(Field ref) throws Exception { public EObject invoke(EProc proc, EObject[] args) throws Pausable { - System.out.println("undefined "+fun); - throw new ErlangUndefined(fun.module, fun.function, ESmall.make(fun.arity)); + EFun found = null; + try { + ERT.load(fun.module); + found = EModule.resolve(fun); + } catch (Throwable ex) { + System.out.println("unable to load module for "+fun); + } + + if (found == null) { + throw new ErlangUndefined(fun.module, fun.function, ESmall.make(fun.arity)); + } else { + return found.invoke(proc, args); + } } }); ref.set(null, h); diff --git a/src/main/java/erjang/EModuleLoader.java b/src/main/java/erjang/EModuleLoader.java index 6d8b4c9e..39ce3473 100644 --- a/src/main/java/erjang/EModuleLoader.java +++ b/src/main/java/erjang/EModuleLoader.java @@ -77,6 +77,10 @@ protected Class findClass(String name) throws ClassNotFoundException { if (name.startsWith("kilim.S_")) { InputStream resource = super.getResourceAsStream(name.replace('.', '/') + ".class"); + + if (resource == null) { + throw new ClassNotFoundException(name, new Error("while loading "+this.getURLs()[0])); + } try { byte[] bb = new byte[resource.available()]; diff --git a/src/main/java/erjang/Erj.java b/src/main/java/erjang/Erj.java index 084cb17d..4bacbac9 100644 --- a/src/main/java/erjang/Erj.java +++ b/src/main/java/erjang/Erj.java @@ -27,11 +27,6 @@ */ public class Erj { - public static String PRELOADED = "src/main/erl/preloaded/ebin"; - public static String[] MODULES = new String[] { "erl_prim_loader", - "erlang", "init", "otp_ring0", "prim_file", "prim_inet", - "prim_zip", "zlib" }; - @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { @@ -49,15 +44,7 @@ public static void main(String[] args) EAtom module = EAtom.intern(m); EAtom fun = EAtom.intern(f); - EModule[] modules = new EModule[MODULES.length]; - - for (int i = 0; i < modules.length; i++) { - - String mod = MODULES[i]; - - ERT.load(EAtom.intern(mod)); - } - + // TODO: remove this hack, it prevents loading real modules for these EModule.load_module(EAtom.intern("io"), new File("target/classes").toURL()); EModule.load_module(EAtom.intern("timer"), new File("target/classes").toURL());