~ chicken-core (chicken-5) /tests/module-tests-compiled.scm


 1;;;; module-tests-compiled.scm
 2
 3
 4(include "test.scm")
 5
 6(test-begin "modules/compiled")
 7
 8
 9;; inlines where walked twice (once for extracting mutable constants)
10;; and then when expanded, this caused inline function names to be
11;; aliased/renamed twice - also, aliasing in syntax-defs could make
12;; inline func unrecognizable for canonicalizer.
13
14(module m1 (f1)
15  (import scheme (chicken base))
16  (define-inline (bar x) (cons x '(foo)))
17  (define-syntax s1
18    (syntax-rules ()
19      ((_ x) (list (bar x)))))
20  (define (f1 x) (s1 x)))
21
22(import m1)
23(test-equal "inline in syntax" (f1 'ok) '((ok foo)))
24
25
26;; here, the identical names of alias/real id pairs in primitive
27;; modules with prefix applied would cause the second to be marked
28;; ##core#aliase'd. That would avoid renaming of the newly defined
29;; vector-fill!.
30
31(module m2 (vector-fill!)
32  (import (except scheme vector-fill!)
33          (prefix (only scheme vector-fill!) %))
34  (define (vector-fill! x v)
35    (%vector-fill! v x)
36    v))
37
38(import m2)
39(define v (vector 1 2 3))
40(test-equal "unmarked primitive exports" (vector-fill! 99 v) '#(99 99 99))
41
42(module m3 (op)
43  (import scheme)
44  (define op -))
45
46(module m4 (op)
47  (import scheme)
48  (define op +))
49
50;; Lexically scoped import, see #1437
51
52(import m4)
53(test-equal "lexically scoped import uses imported module"
54	    3 (let () (import m3) (op 5 2)))
55
56(test-equal "After leaving scope, fall back to old import" 7 (op 5 2))
57
58(eval '(import m4))
59(test-equal "Interpreted code behaves identically on lexical import"
60	    3 (eval '(let () (import m3) (op 5 2))))
61
62(test-equal "Interpreted code behaves identically after leaving scope"
63	    7 (eval '(op 5 2)))
64
65;; This was the remaining bug: imports would be evaluated during
66;; macro expansion, mutating ##sys#current-environment, but the
67;; code walker would keep the old syntax environment.
68(begin
69  (import m3)
70  (test-equal "In begin, imports are seen immediately" 3 (op 5 2)))
71
72(test-equal "begin splices; imports still active afterwards" 3 (op 5 2))
73
74(test-end "modules")
75
76(test-exit)
Trap