This page holds a quick and dirty compiler for a tiny subset of Scheme into Befunge 98. The compiler is written in (hopefully ANSI) Common Lisp.
lambda
with proper lexical scope and closures.
It doesn't support variadic argument lists.
if
set!
begin
let
letrec
(lambda (x y) (_+ x y))
).
The following datatypes are supported:
_pair?
_cons
_car
_cdr
_integer?
_+
_-
_*
_/
_%
_=
true
and false
instead of #t
and #f
):
_boolean?
_not
_procedure?
call/cc
. However, since the compiler transforms the
code to CPS,
it shouldn't be difficult to add.
quote
are supported.
define
... and in general no every other form not mentioned before :)
let
and letrec
into
lambda
abstractions.
lambda
s recursively, transforming them into toplevel definitions.
main program (row 0) memory ("heap") (row 1) error handling (row 2) routine handlers (from row 3 on)
g
(get)
and p
(put) instructions. The first cells are
used as internal registers:
x
instruction)
is used. The compiler calculates the offset and hardcodes it.
Here it is the compiler. The Scheme code to be compiled is hardcoded in the source code, and so is the output file. You might want to modify it to do something fancier such as reading the code from a file, like normal people do.
The Befunge object code is reeeally big, but it seems to work in at least some examples. Please be patient when you run the result!
Now writing an Unlambda to Befunge compiler should be almost a trivial task :)
Happy hacking!