Add let bindings
This commit is contained in:
parent
4176d439e5
commit
ad1ca1d796
2 changed files with 22 additions and 0 deletions
|
@ -134,6 +134,26 @@
|
|||
[(heap1 addr-a) (instantiate-body a env heap0)])
|
||||
(allocate-node heap1 (list addr-f addr-a)))]
|
||||
[(? symbol?) (values heap (lookup-globals env e))]
|
||||
[(list 'let binds e)
|
||||
(let-values ([(env heap) (instantiate-binds binds env heap)])
|
||||
(instantiate-body e env heap))]
|
||||
[_ (error "unimplemented")]))
|
||||
|
||||
(: instantiate-binds (-> CoreBinds Globals Heap (Values Globals Heap)))
|
||||
(define (instantiate-binds binds old-env heap)
|
||||
(for/fold
|
||||
([env : Globals old-env]
|
||||
[heap : Heap heap])
|
||||
([bind : CoreBind binds])
|
||||
(instantiate-bind bind old-env env heap)))
|
||||
|
||||
(: instantiate-bind (-> CoreBind Globals Globals Heap (Values Globals Heap)))
|
||||
(define (instantiate-bind bind old-env new-env heap)
|
||||
(let ([x (first bind)]
|
||||
[e (second bind)])
|
||||
(let-values ([(heap addr) (instantiate-body e old-env heap)])
|
||||
(values (update-globals new-env x addr) heap))))
|
||||
|
||||
|
||||
|
||||
(provide (all-defined-out))
|
||||
|
|
|
@ -28,3 +28,5 @@
|
|||
|
||||
(check-equal? (exp-final-node (ap-exp 'S 'K 'K 3)) 3)
|
||||
(check-equal? (exp-final-node (ap-exp 'K 100 99)) 100)
|
||||
(check-equal? (exp-final-node `(let ((x ,(ap-exp 'S 'K 'K 3)) (y 5)) ,(ap-exp 'K 'x 'x))) 3)
|
||||
(check-equal? (exp-final-node `(let ((x ,(ap-exp 'S 'K 'K 3)) (y 5)) ,(ap-exp 'K 'y 'x))) 5)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue