Brainfuck interpreter and jit-compiler in Java

139 visualizzazioni
Passa al primo messaggio da leggere

sleepnova

da leggere,
10 gen 2009, 04:14:1710/01/09
a JVM Languages
I don't know if this subject is appropriate here, if not, please
ignore it.

I just want to share to you my first experiment project related to
language, compiler and bytecode manipulation stuff - a toy interpreter/
jit-compiler for Brainfuck implementation in Java.

I put it here - http://code.google.com/p/bfj/
Hope you enjoy the toy. :)

Eugene Kuleshov

da leggere,
10 gen 2009, 10:10:4210/01/09
a JVM Languages

There is also a bf compiler in examples from ASM framework. :-)

regards,
Eugene


On Jan 10, 4:14 am, sleepnova <wanpee...@gmail.com> wrote:
> I don't know if this subject is appropriate here, if not, please
> ignore it.
>
> I just want to share to you my first experiment project related to
> language, compiler and bytecode manipulation stuff - a toy interpreter/
> jit-compiler for Brainfuck implementation in Java.
>
> I put it here -http://code.google.com/p/bfj/

Jon Harrop

da leggere,
10 gen 2009, 10:58:1010/01/09
a jvm-la...@googlegroups.com

Wonderful. I wanted to benchmark a Java version against my OCaml/LLVM and
F#/CIL versions. Thanks!

--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

Charles Oliver Nutter

da leggere,
10 gen 2009, 22:04:4610/01/09
a jvm-la...@googlegroups.com
Jon Harrop wrote:
> Wonderful. I wanted to benchmark a Java version against my OCaml/LLVM and
> F#/CIL versions. Thanks!

Looking forward to seeing that and other comparisons! We shall band
together to make sure BF/JVM is the fastest BF in the world!

- Charlie

Charles Oliver Nutter

da leggere,
10 gen 2009, 22:05:1110/01/09
a jvm-la...@googlegroups.com

Any particularly interesting things you learned from the exercise?

- Charlie

Jon Harrop

da leggere,
11 gen 2009, 01:12:5411/01/09
a jvm-la...@googlegroups.com

I will surely advertise that fact in my forthcoming BF for Scientists book
which will cover ANSI BF in detail.

Jon Harrop

da leggere,
11 gen 2009, 01:26:3611/01/09
a jvm-la...@googlegroups.com
On Saturday 10 January 2009 09:14:17 sleepnova wrote:

SlocCount says this is 66k lines of code. Is that really right?

Liwei

da leggere,
11 gen 2009, 06:07:2511/01/09
a jvm-la...@googlegroups.com
I'm willing to know the result. :)

2009/1/10 Jon Harrop <j...@ffconsultancy.com>

Jon Harrop

da leggere,
11 gen 2009, 07:01:4211/01/09
a jvm-la...@googlegroups.com
On Sunday 11 January 2009 11:07:25 Liwei wrote:
> I'm willing to know the result. :)

I cannot even get it to run:

$ export
CLASSPATH="/home/jdh30/src/bfj-read-only/bfj/lib/asm-3.1.jar:/home/jdh30/src/bfj-read-only/bfj/src/"
$ java bf.runner.ParseCompileRunner
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at bf.runner.ParseCompileRunner.main(ParseCompileRunner.java:16)

Sounds like it is failing because it assumed argvs would contain a BF program
to run, i.e. the compiler is actually running. But:

$ java bf.runner.ParseCompileRunner ../bf/mandelbrot.b
compile and run: ../bf/mandelbrot.b
Exception in thread "main" java.lang.NoClassDefFoundError:
bf/util/BrainfuckParser
at bf.runner.ParseCompileRunner.main(ParseCompileRunner.java:20)
Caused by: java.lang.ClassNotFoundException: bf.util.BrainfuckParser
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
... 1 more

Sounds like the generated code doesn't run. Does it use Windows specific
invocations internally?

I figured out why there is so much Java code in there: the bfj distro contains
some precompiled BF programs as Java source. Removing those, it is only 1,588
LOC. Still 11x longer than the OCaml/LLVM though...

Liwei

da leggere,
11 gen 2009, 10:12:3611/01/09
a jvm-la...@googlegroups.com
bfj didn't use any of Windows specific functionality, I tested it on both Windows and Linux system.
It just does in memory translation to JVM bytecode and execute it directly.

It seems that you have encountered some classpath issues.
You got NoClassDefFoundError while loading bf.util.BrainfuckParser.

1. Check if all java file are properly compiled and class files are properly placed in package structure.
2. I suggest you to use -cp to specify your classpath.

I use following command to execute:
java -cp ../lib/asm-3.1.jar:. bf.runner.ParseCompileRunner ../bf/mandelbrot.b in Linux
java -cp ../lib/asm-3.1.jar;. bf.runner.ParseCompileRunner ../bf/mandelbrot.b in Windows

About the bloated LOC...
The ParseCompileRunner implementation is mixed with the interpreter code.
I did implement some translation only BF2BytecodeRunner which is about 200 LOC, but they are not yet apply some basic optimizations.
I'll update them so that you can have a fare compare of the LOC in different languages.

:)

2009/1/11 Jon Harrop <j...@ffconsultancy.com>

Liwei

da leggere,
11 gen 2009, 12:19:2911/01/09
a jvm-la...@googlegroups.com
I have update my the simple translate and go version, which is about 230 LOC and slightly faster than the old one.

Related source:
src\bf\runner\BF2BytecodeRunner.java
src\bf\program\State.java

Use following command to execute:
java -cp ../lib/asm-3.1.jar:. bf.runner.BF2BytecodeRunner ../bf/mandelbrot.b in Linux
java -cp ../lib/asm-3.1.jar;. bf.runner.BF2BytecodeRunner ../bf/mandelbrot.b in Windows

Jim White

da leggere,
12 gen 2009, 01:12:0512/01/09
a jvm-la...@googlegroups.com
This is probably even less appropriate, although there are Java
implementations, so close enuf:

http://lolcode.com/examples/gimmeh

Better yet would be a Java-to-LOLCode xlator! ;-)

Jim

Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi