Download presentation
Presentation is loading. Please wait.
1
And more store-passing interpreters
Desugaring letrec And more store-passing interpreters
2
Store-passing recap
3
(let loop ([x ivx] [y ivy] …)
body) (letrec ([loop (lambda (x y …) body)]) (loop ivx ivy …))
4
(define (sum from to) (define total 0) (let loop () (set! total (+ total from)) (set! from (+ from 1)) (if (<= from to) (loop) total)))
5
(define (sum from to) (let loop ([i from] [total 0]) (if (<= i to) (loop (+ i 1) (+ total i)) total)))
6
env maps variables to addresses
(x, env, st) env maps variables to addresses st maps addresses to values The current size of the store is the next address: | st |
7
(e2, env’[x ↦ |st2|], st2[|st2| ↦ v1]) ⇓ (v2, st3)
(e0, env, st0) ⇓ (((λ (x) e2), env’), st1) (e1, env, st1) ⇓ (v1, st2) ((e0 e1), env, st0) ⇓ (v2, st3) ((λ (x) e), env, st) ⇓ (((λ (x) e), env), st) (x, env, st) ⇓ (st(env(x)), st)
8
(letrec* ([x0 e0] …) body)
(let ([x0 ‘undefined] …) (set! x0 e0) ... body)
9
(letrec ([x0 e0] …) body) (let ([x0 ‘undefined] …) (let ([t0 e0]) (set! x0 t0) ... body))
10
Let’s code this up.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.