On 5 September 2010 18:46, CuppoJava <patrickli_2...@hotmail.com> wrote: > I'm writing a simple lisp for educational purposes, and I can't figure > out how to do compilation.
The final chapter of SICP [1] deals with compilation of Scheme code down to a kind of assembly language (also introduced in the book). It's fantastically written and will likely be helpful. The general idea is that you have to establish some conventions for passing arguments to functions (they might all be passed on the stack or you might permit passing some through registers or as structs on the heap with a pointer on the stack etc.). Then you need to figure out a way to translate your Lisp code into executable code which, given a bunch of arguments in the appropriate places (as per the convention for argument passing), will compute the result of the function and put it in some fixed place (another convention). Then you need to have function invocation sites store the return address on the stack, pass arguments and jump to wherever the given function resides in memory. Jumping back to the return address is the job of a bit of "linkage" to be put at the end of the function's code in memory. Once again, I highly recommend the SICP chapter (don't skip the exercises!) -- it's not enough to give one the ability to write an industrial strength compiler, but it does give a level of understanding of the issues involved. Sincerely, Michał [1] http://mitpress.mit.edu/sicp/ -- 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