Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
krestenkrab committed Dec 4, 2009
1 parent 1aa836f commit e10d52d
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 22 deletions.
76 changes: 71 additions & 5 deletions 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.<clinit>(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



Expand Down
Binary file modified erjang-0.1.jar
Binary file not shown.
17 changes: 14 additions & 3 deletions src/main/java/erjang/EModule.java
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/erjang/EModuleLoader.java
Expand Up @@ -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()];
Expand Down
15 changes: 1 addition & 14 deletions src/main/java/erjang/Erj.java
Expand Up @@ -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 {
Expand All @@ -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());

Expand Down

0 comments on commit e10d52d

Please sign in to comment.