mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-10 07:50:24 +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>)
|
||||
;; todo: open private local bindings.
|
||||
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>)
|
||||
exp)
|
||||
(($ <module-set> src mod name public? exp)
|
||||
|
|
|
@ -761,6 +761,19 @@
|
|||
(loop (cdr l) (+ sum (car l)))))
|
||||
(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
|
||||
;; Mutability preserved.
|
||||
((lambda (x y z) (list x y z)) 1 2 3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue