Next: compiler letrec wsd, Previous: compiler letrec notes, Up: compiler letrec [Index]
The basic transformations are equivalent to:
(letrec ((?lhs ?rhs) ...) ?body)
→ (let ((?lhs #!void) ...)
(let ((?tmp ?rhs) ...)
(set! ?lhs ?tmp) ...
?body))
(letrec* ((?lhs ?rhs) ...) ?body)
→ (let ((?lhs #!void) ...)
(set! ?lhs ?rhs) ...
?body)
and in recordised code are represented as:
(recbind ((?lhs ?rhs) ...) ?body)
→ (bind ((?lhs #!void) ...)
(bind ((?tmp ?rhs) ...)
(assign ?lhs ?tmp) ...
?body))
(rec*bind ((?lhs ?rhs) ...) ?body)
→ (bind ((?lhs #!void) ...)
(assign ?lhs ?rhs) ...
?body)
as example, with these transformations the library:
(library (optimize-letrec-basic-demo) (export a b c) (import (rnrs)) (define (a) 1) (define (b) (a) 2) (define (c) (b) 3))
is transformed into:
(bind ((a_0 '#!void)
(b_0 '#!void)
(c_0 '#!void))
(seq
(set! a_0 (lambda () '1))
(set! b_0 (lambda () (seq (funcall a_0) '2)))
(set! c_0 (lambda () (seq (funcall b_0) '3)))
(funcall void)))