Fixes a bug in which effectful meta-function applications were cached.

This commit is contained in:
Casey Klein 2010-06-17 13:48:45 -05:00
parent 318ec585bc
commit dc8fc24e89

View File

@ -189,12 +189,12 @@
"let-void") "let-void")
(--> (V S ((x_0 h_0) ...) T ((let-void-box n e) i ...)) (--> (V S ((x_0 h_0) ...) T ((let-void-box n e) i ...))
(V (push ((box x_n) ...) S) ((x_n undefined) ... (x_0 h_0) ...) T (e i ...)) (V (push ((box x_n) ...) S) ((x_n undefined) ... (x_0 h_0) ...) T (e i ...))
(where (x_n ...) (n-gensyms n)) (where (x_n ...) (n-freshes n x_0 ... T))
"let-void-box"))) "let-void-box")))
(define-metafunction runtime (define-metafunction runtime
[(n-gensyms n) [(n-freshes n x ... T)
,(build-list (term n) (λ (_) (gensym 'x)))]) ,(variables-not-in (term (x ... T)) (build-list (term n) (λ (_) 'x)))])
(define miscellaneous-rules (define miscellaneous-rules
(reduction-relation (reduction-relation
@ -249,119 +249,149 @@
concat : (any ...) ... -> (any ...) concat : (any ...) ... -> (any ...)
[(concat any ...) ,(apply append (term (any ...)))]) [(concat any ...) ,(apply append (term (any ...)))])
; load : e T -> (e H T)
; load : e φ (x ...) -> (e H T (x ...))
; load* : ((e φ) ...) (x ...) -> ((e ...) H T (x ...))
(define-metafunction loader (define-metafunction loader
[(load e ((x_0 e_0) ...)) [(load e ((x_0 e_0) ...))
(uninit (uninit (((ε))) H (concat ((x_0 e_0*) ...) T) (e_*))
(((ε))) (where ((e_* e_0* ...) H T (y ...))
(concat H H_0 ...) (load* ((e -) (e_0 -) ...) (x_0 ...)))])
(concat T ((x_0 e_0*) ...) T_0 ...)
(e_*))
(where (e_* H T) (load* e -))
(where ((e_0* H_0 T_0) ...) ((load* e_0 -) ...))])
(define-metafunction loader (define-metafunction loader
[(φ+ - n) -] [(φ+ - n) -]
[(φ+ (n_p n_a x) n) (,(+ (term n) (term n_p)) n_a x)]) [(φ+ (n_p n_a x) n) (,(+ (term n) (term n_p)) n_a x)])
(define-metafunction loader (define-metafunction loader
[(load-lam-rec (lam (τ_0 ...) (n_0 ... n_i n_i+1 ...) e) n_i) [(load-lam-rec (lam (τ_0 ...) (n_0 ... n_i n_i+1 ...) e) n_i (y ...))
; When a closure captures itself multiple times, only the last ; When a closure captures itself multiple times, only the last
; occurrence is considered a self-reference. ; occurrence is considered a self-reference.
((lam n (n_0 ... n_i n_i+1 ...) x) H ((x e_*) (x_0 e_0) ...)) ((lam n (n_0 ... n_i n_i+1 ...) x) H (concat ((x e_*)) T) (y_* ...))
(where n ,(length (term (τ_0 ...)))) (where n ,(length (term (τ_0 ...))))
(where x ,(gensym 'x)) (where x (fresh-in (y ...)))
(where (e_* H ((x_0 e_0) ...)) (where (e_* H T (y_* ...))
(load* e (,(length (term (n_0 ...))) n x))) (load e (,(length (term (n_0 ...))) n x) (x y ...)))
(side-condition (not (memq (term n_i) (term (n_i+1 ...)))))] (side-condition (not (memq (term n_i) (term (n_i+1 ...)))))]
[(load-lam-rec l n_j) (load* l -)]) [(load-lam-rec l n_j (y ...)) (load l - (y ...))])
(define-metafunction loader (define-metafunction loader
[(load* (application (loc-noclr n) e_1 ...) (n_p n_a x)) [(load-lam-rec* () (y ...)) (() () () (y ...))]
((self-app x (loc-noclr n) e_1* ...) [(load-lam-rec* ((l_0 n_0) (l_1 n_1) ...) (y ...))
(concat H_1 ...) ((l_0* l_1* ...) (concat H_0 H_1) (concat T_0 T_1) (y_** ...))
(concat T_1 ...)) (where (l_0* H_0 T_0 (y_* ...))
(load-lam-rec l_0 n_0 (y ...)))
(where ((l_1* ...) H_1 T_1 (y_** ...))
(load-lam-rec* ((l_1 n_1) ...) (y_* ...)))])
(define-metafunction loader
[(load (application (loc-noclr n) e_1 ...) (n_p n_a x) (y ...))
((self-app x (loc-noclr n) e_1* ...) H T (y_* ...))
(side-condition (= (term n) (+ (term n_p) (length (term (e_1 ...)))))) (side-condition (= (term n) (+ (term n_p) (length (term (e_1 ...))))))
(side-condition (= (term n_a) (length (term (e_1 ...))))) (side-condition (= (term n_a) (length (term (e_1 ...)))))
(where ((e_1* H_1 T_1) ...) ((load* e_1 -) ...))] (where ((e_1* ...) H T (y_* ...)) (load* ((e_1 -) ...) (y ...)))]
[(load* (let-rec (l_0 ...) e) φ) [(load (let-rec (l_0 ...) e) φ (y ...))
((let-rec (l_0* ...) e_*) ((let-rec (l_0* ...) e_*)
(concat H H_0 ...) (concat H_0 H_1)
(concat T T_0 ...)) (concat T_0 T_1)
(where (e_* H T) (load* e φ)) (y_** ...))
(where (e_* H_0 T_0 (y_* ...)) (load e φ (y ...)))
(where (n_0 ...) (count-up ,(length (term (l_0 ...))))) (where (n_0 ...) (count-up ,(length (term (l_0 ...)))))
(where ((l_0* H_0 T_0) ...) ((load-lam-rec l_0 n_0) ...))] (where ((l_0* ...) H_1 T_1 (y_** ...))
(load-lam-rec* ((l_0 n_0) ...) (y_* ...)))]
[(load* (application e_0 e_1 ...) φ) [(load (application e_0 e_1 ...) φ (y ...))
((application e_0* ...) ((application e_0* e_1* ...) H T (y_* ...))
(concat H_0 ...) (where ((e_0* e_1* ...) H T (y_* ...))
(concat T_0 ...)) (load* ((e_0 -) (e_1 -) ...) (y ...)))]
(where ((e_0* H_0 T_0) ...) ((load* e_0 -) (load* e_1 -) ...))]
[(load* (let-one e_r e_b) φ) [(load (let-one e_r e_b) φ (y ...))
((let-one e_r* e_b*) (concat H_r H_b) (concat T_r T_b)) ((let-one e_r* e_b*) (concat H_r H_b) (concat T_r T_b) (y_** ...))
(where (e_r* H_r T_r) (load* e_r -)) (where (e_r* H_r T_r (y_* ...)) (load e_r - (y ...)))
(where (e_b* H_b T_b) (load* e_b (φ+ φ 1)))] (where (e_b* H_b T_b (y_** ...)) (load e_b (φ+ φ 1) (y_* ...)))]
[(load* (let-void n e) φ) [(load (let-void n e) φ (y ...))
((let-void n e_*) H T) ((let-void n e_*) H T (y_* ...))
(where (e_* H T) (load* e (φ+ φ n)))] (where (e_* H T (y_* ...)) (load e (φ+ φ n) (y ...)))]
[(load* (let-void-box n e) φ) [(load (let-void-box n e) φ (y ...))
((let-void-box n e_*) H T) ((let-void-box n e_*) H T (y_* ...))
(where (e_* H T) (load* e (φ+ φ n)))] (where (e_* H T (y_* ...)) (load e (φ+ φ n) (y ...)))]
[(load* (boxenv n e) φ) [(load (boxenv n e) φ (y ...))
((boxenv n e_*) H T) ((boxenv n e_*) H T (y_* ...))
(where (e_* H T) (load* e φ))] (where (e_* H T (y_* ...)) (load e φ (y ...)))]
[(load* (install-value n e_r e_b) φ) [(load (install-value n e_r e_b) φ (y ...))
((install-value n e_r* e_b*) ((install-value n e_r* e_b*)
(concat H_r H_b) (concat H_r H_b)
(concat T_r T_b)) (concat T_r T_b)
(where (e_r* H_r T_r) (load* e_r -)) (y_* ...))
(where (e_b* H_b T_b) (load* e_b φ))] (where (e_r* H_r T_r (y_* ...)) (load e_r - (y ...)))
[(load* (install-value-box n e_r e_b) φ) (where (e_b* H_b T_b (y_** ...)) (load e_b φ (y_* ...)))]
[(load (install-value-box n e_r e_b) φ (y ...))
((install-value-box n e_r* e_b*) ((install-value-box n e_r* e_b*)
(concat H_r H_b) (concat H_r H_b)
(concat T_r T_b)) (concat T_r T_b)
(where (e_r* H_r T_r) (load* e_r -)) (y_** ...))
(where (e_b* H_b T_b) (load* e_b φ))] (where (e_r* H_r T_r (y_* ...)) (load e_r - (y ...)))
(where (e_b* H_b T_b (y_** ...)) (load e_b φ (y_* ...)))]
[(load* (seq e_0 ... e_n) φ) [(load (seq e_0 ... e_n) φ (y ...))
((seq e_0* ... e_n*) ((seq e_0* ... e_n*)
(concat H_0 ... H_n) (concat H_0 H_1)
(concat T_0 ... T_n)) (concat T_0 T_1)
(where ((e_0* H_0 T_0) ...) ((load* e_0 -) ...)) (y_** ...))
(where (e_n* H_n T_n) (load* e_n φ))] (where ((e_0* ...) H_0 T_0 (y_* ...)) (load* ((e_0 -) ...) (y ...)))
(where (e_n* H_1 T_1 (y_** ...)) (load e_n φ (y_* ...)))]
[(load* (branch e_c e_t e_f) φ) [(load (branch e_c e_t e_f) φ (y ...))
((branch e_c* e_t* e_f*) ((branch e_c* e_t* e_f*)
(concat H_c H_t H_f) (concat H_c H_t H_f)
(concat T_c T_t T_f )) (concat T_c T_t T_f )
(where (e_c* H_c T_c) (load* e_c -)) (y_*** ...))
(where (e_t* H_t T_t) (load* e_t φ)) (where (e_c* H_c T_c (y_* ...)) (load e_c - (y ...)))
(where (e_f* H_f T_f) (load* e_f φ))] (where (e_t* H_t T_t (y_** ...)) (load e_t φ (y_* ...)))
(where (e_f* H_f T_f (y_*** ...)) (load e_f φ (y_** ...)))]
[(load* (lam (τ_0 ...) (n_0 ...) e) φ) [(load (lam (τ_0 ...) (n_0 ...) e) φ (y ...))
((lam n (n_0 ...) x) H ((x e_*) (x_0 e_0) ...)) ((lam n (n_0 ...) x) H (concat ((x e_*)) T) (y_* ...))
(where x ,(gensym 'x)) (where x (fresh-in (y ...)))
(where n ,(length (term (τ_0 ...)))) (where n ,(length (term (τ_0 ...))))
(where (e_* H ((x_0 e_0) ...)) (load* e -))] (where (e_* H T (y_* ...)) (load e - (x y ...)))]
[(load* (proc-const (τ_0 ...) e) φ) [(load (proc-const (τ_0 ...) e) φ (y ...))
((clos x) ((clos x)
((x ((clos n () x_*))) (x_0 h_0) ...) (concat ((x ((clos n () x_*)))) H)
((x_* e_*) (x_i e_i) ...)) (concat ((x_* e_*)) T)
(where x ,(gensym 'x)) (y_* ...))
(where x_* ,(gensym 'x)) (where x (fresh-in (y ...)))
(where x_* (fresh-in (x y ...)))
(where n ,(length (term (τ_0 ...)))) (where n ,(length (term (τ_0 ...))))
(where (e_* ((x_0 h_0) ...) ((x_i e_i) ...)) (load* e -))] (where (e_* H T (y_* ...)) (load e - (x x_* y ...)))]
[(load* (case-lam l_0 ...) φ) [(load (case-lam l_0 ...) φ (y ...))
((case-lam l_0* ...) (concat H_0 ...) (concat T_0 ...)) ((case-lam l_0* ...) H T (y_* ...))
(where ((l_0* H_0 T_0) ...) ((load* l_0 φ) ...))] (where ((l_0* ...) H T (y_* ...))
(load* ((l_0 φ) ...) (y ...)))]
[(load* e φ) (e () ())]) [(load e φ (y ...)) (e () () (y ...))])
(define-metafunction loader
[(load* () (y ...)) (() () () (y ...))]
[(load* ((e_0 φ_0) (e_1 φ_1) ...) (y ...))
((e_0* e_1* ...)
(concat H_0 H_1)
(concat T_0 T_1)
(y_** ...))
(where (e_0* H_0 T_0 (y_* ...))
(load e_0 φ_0 (y ...)))
(where ((e_1* ...) H_1 T_1 (y_** ...))
(load* ((e_1 φ_1) ...) (y_* ...)))])
(define-metafunction loader
[(fresh-in (x ...))
,(variable-not-in (term (x ...)) 'x)])
(define-metafunction (define-metafunction
runtime runtime