Working on a Scheme interpreter written in Rust


#1

I am working on a Scheme interpreter written in Rust, which you can find here.

It is very incomplete, and doesn’t even compile yet. Pretty much all I can say is that the GC works (according to one test case).

Nevertheless, I would love suggestions and/or contributions from anyone who can help.

Here is the plan so far:

  • Bytecode compiler and VM.
  • Compiler written in Scheme (except for the reader) – this allows it to manipulate Scheme source (which is just Scheme data structures) easily, and allows me to use a macro expander written by somebody else (which is written in Scheme). Already started, but very incomplete.
  • VM is accumulator-based: instructions can reference any of the top 256 elements of the stack, but mostly push their result on the stack. Again, the VM is very incomplete.
  • Reader: non-recursive (like the rest of the VM). Written in Rust. Skeleton already written.
  • Embedding API: not yet started, but the plan is for Rust code to create interpreter instances, manipulate Scheme objects, store Rust data structures as Scheme objects, and both provide and call Scheme functions, all in safe code. This will also be how Scheme code can access the outside world.

#2

I absolutely :heart: interpreters! Have written a small self interpreter this weekend: https://github.com/matklad/s :slight_smile:


#3

Do you have any suggestions for how to go about finishing my project? Specifically, any thoughts on what the interpreter I am writing would need to have to be practically useful for actual projects?


#4

No, I have not implemented anything production quality myself. I would suggest to talk to Piston folks, they have their own scripting language, but a lisp might be a nice alternative.