So I got thinking about clojure pypy tonight, and got thinking how
easy it would be to adapt my old code to run as a interpreter. So I
pulled in a few files, implemented a few methods, and I have prototype
running (+ 1 2)  as interpreted lisp code.

I slapped it up on github...it's ugly, but it's a start:
https://github.com/halgari/clj-pypy

The idea here is simple. Every object in the VM must implement
evaluate(self). Functions must then implement invoke(self, args). Most
objects will simply return themselves when evaluate is called, there
are some exceptions:

Var objects return the result of evaluating their most recent binding
Symbols find a var that corresponds to their name, and runs evaluate() on that
Lists have the following code in evaluate():

   def evaluate(self):
           f = self.first().evaluate()
           print "f = ", f
           args = []
           h = self.rest()
           while h is not None:
                   args.append(h.first().evaluate())
                   h = h.rest()
           return f.invoke(args)

Basically lists evaluate all their arguments, then construct a arglist
and pass the arguments to the first item in the list. The awesome
thing about this is that this all would be quite expensive in most
VMs, but the majority of this will be optimized away by the pypy JIT.
I have to admit, I'm very excited about this project. PyPy's JIT goes
bug nuts when it can work with immutable structures, I think we'll
start to realize over time that the tracing JIT is a excellent fit for
a LISP like language. And the fact that (at least in my vm) we don't
have bytecode, this means that we can truly have code be the same as
data.

BTW...the code on github probably won't compile with PyPy yet. I just
ran it in Python 2.7. I want to get the code in scratchspace.clj
working first then I'll get it to run in RPython.

Timothy


-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to