mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
Allow targets to preclude unbound variables
Allowing variables to hold an unbound value and requiring a check on each load is suboptimal; the fixing letrec boolean check is better. So other runtimes (hoot) might preclude unbound variables by construction. Allow them to do so. * module/language/cps/guile-vm.scm (target-has-unbound-boxes?): New definition. * module/language/tree-il/compile-cps.scm (target-has-unbound-boxes?): (%box-ref): Only residualize an unbound check if the target has unbound boxes.
This commit is contained in:
parent
83449a8683
commit
5ef0ea30fa
2 changed files with 32 additions and 13 deletions
|
@ -31,7 +31,8 @@
|
||||||
#:export (make-lowerer
|
#:export (make-lowerer
|
||||||
available-optimizations
|
available-optimizations
|
||||||
target-symbol-hash
|
target-symbol-hash
|
||||||
target-symbol-hash-bits))
|
target-symbol-hash-bits
|
||||||
|
target-has-unbound-boxes?))
|
||||||
|
|
||||||
;; This hash function is originally from
|
;; This hash function is originally from
|
||||||
;; http://burtleburtle.net/bob/c/lookup3.c by Bob Jenkins, May 2006,
|
;; http://burtleburtle.net/bob/c/lookup3.c by Bob Jenkins, May 2006,
|
||||||
|
@ -107,3 +108,5 @@
|
||||||
|
|
||||||
(define (available-optimizations)
|
(define (available-optimizations)
|
||||||
'())
|
'())
|
||||||
|
|
||||||
|
(define target-has-unbound-boxes? #t)
|
||||||
|
|
|
@ -486,20 +486,36 @@
|
||||||
($continue k src
|
($continue k src
|
||||||
($primcall 'set-cdr! #f (pair val)))))))))
|
($primcall 'set-cdr! #f (pair val)))))))))
|
||||||
|
|
||||||
|
(define target-has-unbound-boxes?
|
||||||
|
(let ((cache (make-hash-table)))
|
||||||
|
(lambda ()
|
||||||
|
(let ((rt (target-runtime)))
|
||||||
|
(match (hashq-get-handle cache rt)
|
||||||
|
((k . v) v)
|
||||||
|
(#f (let ((iface (resolve-interface `(language cps ,rt))))
|
||||||
|
(define v (module-ref iface 'target-has-unbound-boxes?))
|
||||||
|
(hashq-set! cache rt v)
|
||||||
|
v)))))))
|
||||||
|
|
||||||
(define-primcall-converter %box-ref
|
(define-primcall-converter %box-ref
|
||||||
(lambda (cps k src op param box)
|
(lambda (cps k src op param box)
|
||||||
(define unbound
|
(cond
|
||||||
#(misc-error "variable-ref" "Unbound variable: ~S"))
|
((target-has-unbound-boxes?)
|
||||||
(with-cps cps
|
(define unbound
|
||||||
(letv val)
|
#(misc-error "variable-ref" "Unbound variable: ~S"))
|
||||||
(letk kunbound ($kargs () () ($throw src 'throw/value unbound (box))))
|
(with-cps cps
|
||||||
(letk kbound ($kargs () () ($continue k src ($values (val)))))
|
(letv val)
|
||||||
(letk ktest
|
(letk kunbound ($kargs () () ($throw src 'throw/value unbound (box))))
|
||||||
($kargs ('val) (val)
|
(letk kbound ($kargs () () ($continue k src ($values (val)))))
|
||||||
($branch kbound kunbound src 'undefined? #f (val))))
|
(letk ktest
|
||||||
(build-term
|
($kargs ('val) (val)
|
||||||
($continue ktest src
|
($branch kbound kunbound src 'undefined? #f (val))))
|
||||||
($primcall 'box-ref #f (box)))))))
|
(build-term
|
||||||
|
($continue ktest src
|
||||||
|
($primcall 'box-ref #f (box))))))
|
||||||
|
(else
|
||||||
|
(with-cps cps
|
||||||
|
($continue k src ($primcall 'box-ref #f (box))))))))
|
||||||
|
|
||||||
(define-primcall-converter %box-set!
|
(define-primcall-converter %box-set!
|
||||||
(lambda (cps k src op param box val)
|
(lambda (cps k src op param box val)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue