|
|
|
@ -122,17 +122,21 @@
@@ -122,17 +122,21 @@
|
|
|
|
|
(define (make-empty-skeleton) |
|
|
|
|
(make-empty-skeleton/cache (make-hash))) |
|
|
|
|
|
|
|
|
|
(define (make-empty-matched-constant) |
|
|
|
|
(skeleton-matched-constant (make-hash) (make-hash))) |
|
|
|
|
|
|
|
|
|
(define (skcont-add! c i) |
|
|
|
|
(match-define (skeleton-interest _desc cs cv vs h _cleanup) i) |
|
|
|
|
(define (make-matched-constant) |
|
|
|
|
(define assertions (make-hash)) |
|
|
|
|
(define (classify-assertions) |
|
|
|
|
(define cvt (make-hash)) |
|
|
|
|
(hash-for-each (skeleton-continuation-cache c) |
|
|
|
|
(lambda (a _) |
|
|
|
|
(when (equal? (apply-projection (unscope-assertion a) cs) cv) |
|
|
|
|
(hash-set! assertions a #t)))) |
|
|
|
|
(skeleton-matched-constant assertions (make-hash))) |
|
|
|
|
(define cvt (hash-ref! (skeleton-continuation-table c) cs make-hash)) |
|
|
|
|
(define sc (hash-ref! cvt cv make-matched-constant)) |
|
|
|
|
(define avs (apply-projection (unscope-assertion a) cs)) |
|
|
|
|
(define sc (hash-ref! cvt avs make-empty-matched-constant)) |
|
|
|
|
(hash-set! (skeleton-matched-constant-cache sc) a #t))) |
|
|
|
|
cvt) |
|
|
|
|
(define cvt (hash-ref! (skeleton-continuation-table c) cs classify-assertions)) |
|
|
|
|
(define sc (hash-ref! cvt cv make-empty-matched-constant)) |
|
|
|
|
(define (make-accumulator) |
|
|
|
|
(define cache (make-bag)) |
|
|
|
|
(hash-for-each (skeleton-matched-constant-cache sc) |
|
|
|
@ -145,6 +149,10 @@
@@ -145,6 +149,10 @@
|
|
|
|
|
(hash-set! (skeleton-accumulator-handlers acc) h #t) |
|
|
|
|
(for [(vars (in-bag (skeleton-accumulator-cache acc)))] (apply h '+ vars))) |
|
|
|
|
|
|
|
|
|
(define (skeleton-matched-constant-empty? sc) |
|
|
|
|
(match-define (skeleton-matched-constant cache table) sc) |
|
|
|
|
(and (hash-empty? cache) (hash-empty? table))) |
|
|
|
|
|
|
|
|
|
(define (skcont-remove! c i) |
|
|
|
|
(match-define (skeleton-interest _desc cs cv vs h cleanup) i) |
|
|
|
|
(define cvt (hash-ref (skeleton-continuation-table c) cs #f)) |
|
|
|
@ -158,7 +166,7 @@
@@ -158,7 +166,7 @@
|
|
|
|
|
(hash-remove! (skeleton-accumulator-handlers acc) h) |
|
|
|
|
(when (hash-empty? (skeleton-accumulator-handlers acc)) |
|
|
|
|
(hash-remove! (skeleton-matched-constant-table sc) vs))) |
|
|
|
|
(when (hash-empty? (skeleton-matched-constant-table sc)) |
|
|
|
|
(when (skeleton-matched-constant-empty? sc) |
|
|
|
|
(hash-remove! cvt cv))) |
|
|
|
|
(when (hash-empty? cvt) |
|
|
|
|
(hash-remove! (skeleton-continuation-table c) cs)))) |
|
|
|
@ -259,29 +267,36 @@
@@ -259,29 +267,36 @@
|
|
|
|
|
(let ((sk (extend-skeleton! sk (skeleton-interest-desc i)))) |
|
|
|
|
(skcont-remove! (skeleton-node-continuation sk) i))) |
|
|
|
|
|
|
|
|
|
(define (skeleton-modify! sk term0 modify-skcont! modify-skconst! modify-skacc!) |
|
|
|
|
(define (skeleton-modify! sk term0 modify-skcont! on-missing-skconst modify-skconst! modify-skacc!) |
|
|
|
|
(unpack-scoped-assertion [restriction-path term0-term] term0) |
|
|
|
|
|
|
|
|
|
(define (walk-node! sk term-stack) |
|
|
|
|
(match-define (skeleton-node continuation edges) sk) |
|
|
|
|
|
|
|
|
|
(modify-skcont! continuation term0) |
|
|
|
|
(hash-for-each (skeleton-continuation-table continuation) |
|
|
|
|
(lambda (constant-proj key-proj-handler) |
|
|
|
|
(define constants (apply-projection term0-term constant-proj)) |
|
|
|
|
(define proj-handler (hash-ref key-proj-handler constants #f)) |
|
|
|
|
(when proj-handler |
|
|
|
|
(modify-skconst! proj-handler term0) |
|
|
|
|
(hash-for-each (skeleton-matched-constant-table proj-handler) |
|
|
|
|
(lambda (variable-proj acc) |
|
|
|
|
;; (when restriction-path |
|
|
|
|
;; (log-info "Restriction path ~v in effect; variable-proj is ~v, and term is ~v" |
|
|
|
|
;; restriction-path |
|
|
|
|
;; variable-proj |
|
|
|
|
;; term0)) |
|
|
|
|
(when (unrestricted? variable-proj restriction-path) |
|
|
|
|
(define vars (apply-projection term0-term variable-proj)) |
|
|
|
|
(modify-skacc! acc vars term0))))))) |
|
|
|
|
(let ((sct (skeleton-continuation-table continuation)) |
|
|
|
|
(constant-projections-to-remove '())) |
|
|
|
|
(hash-for-each sct |
|
|
|
|
(lambda (constant-proj key-proj-handler) |
|
|
|
|
(define constants (apply-projection term0-term constant-proj)) |
|
|
|
|
(define proj-handler |
|
|
|
|
(hash-ref key-proj-handler |
|
|
|
|
constants |
|
|
|
|
(lambda () (on-missing-skconst key-proj-handler constants)))) |
|
|
|
|
(when proj-handler |
|
|
|
|
(when (eq? (modify-skconst! proj-handler term0) 'remove-check) |
|
|
|
|
(when (skeleton-matched-constant-empty? proj-handler) |
|
|
|
|
(hash-remove! key-proj-handler constants) |
|
|
|
|
(when (hash-empty? key-proj-handler) |
|
|
|
|
(set! constant-projections-to-remove |
|
|
|
|
(cons constant-proj constant-projections-to-remove))))) |
|
|
|
|
(hash-for-each (skeleton-matched-constant-table proj-handler) |
|
|
|
|
(lambda (variable-proj acc) |
|
|
|
|
(when (unrestricted? variable-proj restriction-path) |
|
|
|
|
(define vars (apply-projection term0-term variable-proj)) |
|
|
|
|
(modify-skacc! acc vars term0))))))) |
|
|
|
|
(for-each (lambda (constant-proj) (hash-remove! sct constant-proj)) |
|
|
|
|
constant-projections-to-remove)) |
|
|
|
|
|
|
|
|
|
(for [(edge (in-list edges))] |
|
|
|
|
(match-define (cons (skeleton-selector pop-count index) table) edge) |
|
|
|
@ -321,13 +336,18 @@
@@ -321,13 +336,18 @@
|
|
|
|
|
(skeleton-modify! sk |
|
|
|
|
term |
|
|
|
|
add-term-to-skcont! |
|
|
|
|
(lambda (cv-table cv) |
|
|
|
|
(let ((sc (make-empty-matched-constant))) |
|
|
|
|
(hash-set! cv-table cv sc) |
|
|
|
|
sc)) |
|
|
|
|
add-term-to-skconst! |
|
|
|
|
add-term-to-skacc!)) |
|
|
|
|
|
|
|
|
|
(define (remove-term-from-skcont! skcont term) |
|
|
|
|
(hash-remove! (skeleton-continuation-cache skcont) term)) |
|
|
|
|
(define (remove-term-from-skconst! skconst term) |
|
|
|
|
(hash-remove! (skeleton-matched-constant-cache skconst) term)) |
|
|
|
|
(hash-remove! (skeleton-matched-constant-cache skconst) term) |
|
|
|
|
'remove-check) |
|
|
|
|
(define (remove-term-from-skacc! skacc vars _term) |
|
|
|
|
(define cache (skeleton-accumulator-cache skacc)) |
|
|
|
|
;; (log-info ">>>>>> At removal time for ~v, cache has ~v" _term (hash-ref cache vars 0)) |
|
|
|
@ -345,6 +365,7 @@
@@ -345,6 +365,7 @@
|
|
|
|
|
(skeleton-modify! sk |
|
|
|
|
term |
|
|
|
|
remove-term-from-skcont! |
|
|
|
|
(lambda (_cv-table _cv) #f) |
|
|
|
|
remove-term-from-skconst! |
|
|
|
|
remove-term-from-skacc!)) |
|
|
|
|
|
|
|
|
@ -352,6 +373,7 @@
@@ -352,6 +373,7 @@
|
|
|
|
|
(skeleton-modify! sk |
|
|
|
|
term |
|
|
|
|
void |
|
|
|
|
(lambda (_cv-table _cv) #f) |
|
|
|
|
void |
|
|
|
|
(lambda (skacc vars _term) |
|
|
|
|
(hash-for-each (skeleton-accumulator-handlers skacc) |
|
|
|
|