Not for scheme, but I'm a huge fan of http://www.amazon.com/Advanced-Compiler ... 1558603204. Its invaluable reference for anyone building compilers and JITs. Not a beginners book by any means but its terrific!tufty wrote:As far as building compilers for scheme goes:
SICP, as pointed out by Bakul
'Let's build a compiler' by Crenshaw (pascal compiler, but relevant)
Abdulaziz Ghuloum's work
'Compiling with continuations'
'90 minute scheme to C compiler'
Getting there. Still beating my head around register allocation (I'm implementing linear scan, the theory is simple but shoehorning it into the compiler is hard - it's b0rked at the moment) so the following code does a whole load of register spilling and unspilling instead and is therefore "a bit" inefficient.Bakul Shah wrote:This page is a great resource on Scheme implementation techniques. I should also mention Lisp in Small Pieces
Looking forward to your compiler, Simon!
Code: Select all
(lambda (x y)
(if (< x #xfeedface)
(cons x (cons y '()))
(cons y '())))
Code: Select all
(((stm db !) sp (r0-12 lr))
((mov) fp sp)
((sub) sp -4)
((ldr) r0 (fp 64))
((str) r0 (fp -4))
((ldr) r0 "L_3")
((ldr) r10 (fp -4))
((cmp) r0 r10)
((msr ge) apsr_nzcvq 0)
((msr lt) apsr_nzcvq 1073741824)
((b ne) "L_4")
(label "L_0")
((ldrex) r0 (r9))
((add) r0 r0 8)
((strex) r10 r0 (r9))
((teq) r10 0)
((b ne) "L_0")
((orr) r0 r0 1)
((str) r0 (fp -4))
((ldr) r0 (fp 64))
((ldr) r10 (fp -4))
((str) r0 (r10 -1))
(label "L_1")
((ldrex) r0 (r9))
((add) r0 r0 8)
((strex) r10 r0 (r9))
((teq) r10 0)
((b ne) "L_1")
((orr) r0 r0 1)
((str) r0 (fp -8))
((ldr) r0 (fp 60))
((ldr) r10 (fp -8))
((str) r0 (r10 -1))
((movw) r0 1151)
((ldr) r10 (fp -8))
((str) r0 (r10 3))
((mov) r0 r10)
((ldr) r10 (fp -4))
((str) r0 (r10 3))
((mov) r0 r10)
((b) "L_5")
(label "L_4")
(label "L_2")
((ldrex) r0 (r9))
((add) r0 r0 8)
((strex) r10 r0 (r9))
((teq) r10 0)
((b ne) "L_2")
((orr) r0 r0 1)
((str) r0 (fp -4))
((ldr) r0 (fp 60))
((ldr) r10 (fp -4))
((str) r0 (r10 -1))
((movw) r0 1151)
((ldr) r10 (fp -4))
((str) r0 (r10 3))
((mov) r0 r10)
(label "L_5")
((add) sp -4)
((ldm ia) sp (r0-12 pc))
(label "L_3")
(word 34216072816))
Is something like BURG (Bottom Up tree Rewriting code generator Generator) of any use? IIRC, lcc's backend uses it. Don't know if there is a Scheme implementation of BURG.tufty wrote:Getting there. Still beating my head around register allocation (I'm implementing linear scan, the theory is simple but shoehorning it into the compiler is hard - it's b0rked at the moment) so the following code does a whole load of register spilling and unspilling instead and is therefore "a bit" inefficient.
Code: Select all
; get_nums. Takes an integer and returns a list of that length,
; populated with random numbers (1 - 12)
(define (get_nums i)
(cond
((= i 0) '())
(else (cons (+ 1 (random 12)) (get_nums (- i 1))))))