[racket] I've implemented a Scheme Interpreter. But it's too slow. Next step?

From: Patrick Li (patrickli.2001 at gmail.com)
Date: Mon Mar 21 12:42:07 EDT 2011

Hello everyone,

For educational purposes, I've implemented a simple Scheme interpreter in C,
but it's way too slow at the moment. (eg. just macroexpanding and evaluating
a function definition takes a few seconds.) I would like some advice on how
to proceed next to get a adequately performing Scheme system.

My goal is simply to get out of C as quickly as possible. ie. Get the basic
forms and a macro system working which will allow me to write the rest of it
in Scheme.

So far this is what I have done:

I wrote a simple Scheme interpreter in Scheme in continuation-passing style,
so that I can get call/cc working.

Then I basically just manually translated that code into C. So all
continuations are heap allocated.

How should I proceed from here? These are the options that I've come up
with:

(1) Optimize variable lookup. Currently the environment is represented as a
list of key-value pairs. Variable lookup is done by searching through the
list.

(2) "Analyze" the code before evaluating it (ie. as in SICP). Ie. for an
(if) form, it will determine that it is an if form during the analysis
phase, so that at execution stage it won't have to repeatedly figure out
what sort of form it is.

(3) Write a very simple VM, and develop a simple byte-code compiler.  The
problem here is that I don't really know how to deal with first-class
continuations.

Thanks for your help
  -Patrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110321/3867fb82/attachment.html>

Posted on the users mailing list.