peval support for memq and memv

* module/language/tree-il/peval.scm (peval): Add special handlers for
  memq and memv, as inline.scm used to have.  This is important for
  `case' clauses.  It is very ugly, though.

* test-suite/tests/tree-il.test ("partial evaluation"): Add tests.
This commit is contained in:
Andy Wingo 2011-10-10 14:42:40 +02:00
commit 4bf9e92875
2 changed files with 83 additions and 0 deletions

View file

@ -1074,6 +1074,43 @@
(and (even? 4) (odd? 7)))
(const #t))
(pass-if-peval
;; Memv with constants.
(memv 1 '(3 2 1))
(const '(1)))
(pass-if-peval
;; Memv with non-constant list. It could fold but doesn't
;; currently.
(memv 1 (list 3 2 1))
(apply (primitive memv)
(const 1)
(apply (primitive list) (const 3) (const 2) (const 1))))
(pass-if-peval
;; Memv with non-constant key, constant list, test context
(case foo
((3 2 1) 'a)
(else 'b))
(if (let (t) (_) ((toplevel foo))
(if (apply (primitive eqv?) (lexical t _) (const 3))
(const #t)
(if (apply (primitive eqv?) (lexical t _) (const 2))
(const #t)
(apply (primitive eqv?) (lexical t _) (const 1)))))
(const a)
(const b)))
(pass-if-peval
;; Memv with non-constant key, empty list, test context. Currently
;; doesn't fold entirely.
(case foo
(() 'a)
(else 'b))
(if (begin (toplevel foo) (const #f))
(const a)
(const b)))
;;
;; Below are cases where constant propagation should bail out.
;;