nlfiedler / bakeneko

Scheme R7RS interpreter in Go
BSD 3-Clause "New" or "Revised" License
2 stars 0 forks source link

Compile to bytecode #8

Closed nlfiedler closed 10 years ago

nlfiedler commented 11 years ago

All of the really cool Scheme interpreters compile the Scheme code to some form of bytecode to improve performance. Some even compile to native code, though that may be a bit far given my resources.

nlfiedler commented 10 years ago

Look at the Java byte code format [1] for ideas, although Java byte code seems a bit low level. Basically, the primitive expressions in Scheme need to have corresponding byte codes, while nearly everything else is derived from those primitive expressions. The built-in procedures for the various types will continue to be implemented in Go for sake of performance.

Consider the impact this may have on the (read) and (eval) procedures; perhaps eval would perform JIT compilation to byte code.

Consider writing the compiled byte code to a file to avoid compiling the same code repeatedly. See the Java class file format for ideas [2].

[1] http://en.wikipedia.org/wiki/Java_bytecode [2] http://en.wikipedia.org/wiki/Java_class_file

nlfiedler commented 10 years ago

Using Eli Bendersky's "bob" [1] Scheme compiler/interpreter written in Python (ignoring the C++ version for now) as a guide for implementing the equivalent in Go.

[1] https://github.com/eliben/bobscheme

nlfiedler commented 10 years ago

Fixed in commit cdbc261.