mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-10 15:50:50 +02:00
peval: Recognize module-refs to primitives.
* module/language/tree-il/optimize.scm (peval): Handle module-refs to primitives. * test-suite/tests/tree-il.test ("partial evaluation"): Add test, using `pmatch'.
This commit is contained in:
parent
014de9e25d
commit
16d50b8e89
2 changed files with 22 additions and 0 deletions
|
@ -708,6 +708,15 @@ it does not handle <fix> and <let-values>, it should be called before
|
||||||
(($ <toplevel-ref>)
|
(($ <toplevel-ref>)
|
||||||
;; todo: open private local bindings.
|
;; todo: open private local bindings.
|
||||||
exp)
|
exp)
|
||||||
|
(($ <module-ref> src module (? effect-free-primitive? name) #f)
|
||||||
|
(let ((module (false-if-exception
|
||||||
|
(resolve-module module #:ensure #f))))
|
||||||
|
(if (module? module)
|
||||||
|
(let ((var (module-variable module name)))
|
||||||
|
(if (eq? var (module-variable the-scm-module name))
|
||||||
|
(make-primitive-ref src name)
|
||||||
|
exp))
|
||||||
|
exp)))
|
||||||
(($ <module-ref>)
|
(($ <module-ref>)
|
||||||
exp)
|
exp)
|
||||||
(($ <module-set> src mod name public? exp)
|
(($ <module-set> src mod name public? exp)
|
||||||
|
|
|
@ -761,6 +761,19 @@
|
||||||
(loop (cdr l) (+ sum (car l)))))
|
(loop (cdr l) (+ sum (car l)))))
|
||||||
(const 10))
|
(const 10))
|
||||||
|
|
||||||
|
(pass-if-peval
|
||||||
|
;; Primitives in module-refs are resolved (the expansion of `pmatch'
|
||||||
|
;; below leads to calls to (@@ (system base pmatch) car) and
|
||||||
|
;; similar, which is what we want to be inlined.)
|
||||||
|
(begin
|
||||||
|
(use-modules (system base pmatch))
|
||||||
|
(pmatch '(a b c d)
|
||||||
|
((a b . _)
|
||||||
|
#t)))
|
||||||
|
(begin
|
||||||
|
(apply . _)
|
||||||
|
(const #t)))
|
||||||
|
|
||||||
(pass-if-peval
|
(pass-if-peval
|
||||||
;; Mutability preserved.
|
;; Mutability preserved.
|
||||||
((lambda (x y z) (list x y z)) 1 2 3)
|
((lambda (x y z) (list x y z)) 1 2 3)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue