~ chicken-core (chicken-5) c3a8576ac8e64b1c07336ce7eb2ca958f8569a35
commit c3a8576ac8e64b1c07336ce7eb2ca958f8569a35 Author: Evan Hanson <evhan@foldling.org> AuthorDate: Sun Jan 3 21:18:11 2016 +1300 Commit: Evan Hanson <evhan@foldling.org> CommitDate: Tue Mar 8 22:52:32 2016 +1300 Require imported libraries diff --git a/modules.scm b/modules.scm index b30753d9..d0acb944 100644 --- a/modules.scm +++ b/modules.scm @@ -741,9 +741,12 @@ (import-env (append vsv (import-env))) (macro-env (append vss (macro-env))) (let ((unit (module-unit mod))) - (if (and unit load?) - `(##core#require-extension (,unit) #f) - '(##core#undefined))))) + (cond ((not load?) + '(##core#undefined)) + ((symbol? unit) + `(##core#require-extension (,unit) #f)) + (else + `(##core#require-extension (,name) #f)))))) (cdr x)))))) (define (module-rename sym prefix) diff --git a/tests/meta-syntax-test.scm b/tests/meta-syntax-test.scm index 2f4b1c91..1b05ee98 100755 --- a/tests/meta-syntax-test.scm +++ b/tests/meta-syntax-test.scm @@ -1,5 +1,14 @@ ;;;; meta-syntax-test.scm +;; +;; A module's syntax definitions should be accessible through either of +;; the following import forms: +;; +;; (import-for-syntax (foo)) ; meta environment +;; +;; (begin-for-syntax ; compiler environment +;; (import-syntax (foo))) ; note that `import` will not work here +;; (module foo (bar listify) (import scheme chicken) @@ -20,12 +29,23 @@ (lambda (e r c) (call-it-123 list))))) -(module foo-usage (foo-user) +(module test-import-for-syntax (test) (import chicken scheme) - (begin-for-syntax (import (prefix foo foo:))) - (define-syntax testing + (import-for-syntax (prefix foo foo:)) + (define-syntax test-import-for-syntax (er-macro-transformer (lambda (x r c) `(,(r 'quote) ,@(foo:bar 1 2))))) - (define (foo-user) - (testing))) + (define (test) + (test-import-for-syntax))) + +(module test-begin-for-syntax (test) + (import chicken scheme) + (begin-for-syntax + (import-syntax (prefix foo foo:))) + (define-syntax test-begin-for-syntax + (er-macro-transformer + (lambda (x r c) + `(,(r 'quote) ,@(foo:bar 1 2))))) + (define (test) + (test-begin-for-syntax))) diff --git a/tests/runtests.bat b/tests/runtests.bat index 5755de13..cd4ab526 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -264,7 +264,7 @@ a.out if errorlevel 1 exit /b 1 %compile% -s use-square-functor.scm -J if errorlevel 1 exit /b 1 -%interpret% -nqe "(import sf1)" -e "(import sf2)" +%interpret% -nqe "(require-library use-square-functor)" -e "(import sf1)" -e "(import sf2)" if errorlevel 1 exit /b 1 del /f /q sf1.import.* sf2.import.* lst.import.* mod.import.* @@ -337,7 +337,7 @@ echo ======================================== module tests (command line options set module="test" %compile% test.scm -w -A -j %module% -module %module% if errorlevel 1 exit /b 1 -%interpret% -e "(import %module%)" +%interpret% -e "(import-syntax %module%)" if errorlevel 1 exit /b 1 del /f /q %module%.import.scm diff --git a/tests/runtests.sh b/tests/runtests.sh index b02b716e..88b58278 100755 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -200,10 +200,10 @@ $compile syntax-tests-2.scm ./a.out echo "======================================== meta-syntax tests ..." -$interpret -bnq meta-syntax-test.scm -e '(import foo)' -e "(assert (equal? '((1)) (bar 1 2)))" -e "(assert (equal? '(list 1 2 3) (listify)))" -e "(import foo-usage)" -e "(assert (equal? '(1) (foo-user)))" +$interpret -bnq meta-syntax-test.scm -e '(import foo)' -e "(assert (equal? '((1)) (bar 1 2)))" -e "(assert (equal? '(list 1 2 3) (listify)))" -e "(import test-import-for-syntax)" -e "(assert (equal? '(1) (test)))" -e "(import test-begin-for-syntax)" -e "(assert (equal? '(1) (test)))" $compile_s meta-syntax-test.scm -j foo $compile_s foo.import.scm -$interpret -bnq -e '(require-library meta-syntax-test)' -e '(import foo)' -e "(assert (equal? '((1)) (bar 1 2)))" -e "(assert (equal? '(list 1 2 3) (listify)))" -e "(import foo-usage)" -e "(assert (equal? '(1) (foo-user)))" +$interpret -bnq meta-syntax-test.scm -e '(import foo)' -e "(assert (equal? '((1)) (bar 1 2)))" -e "(assert (equal? '(list 1 2 3) (listify)))" -e "(import test-import-for-syntax)" -e "(assert (equal? '(1) (test)))" -e "(import test-begin-for-syntax)" -e "(assert (equal? '(1) (test)))" echo "======================================== reexport tests ..." $interpret -bnq reexport-tests.scm @@ -235,7 +235,7 @@ $interpret -bnq use-square-functor.scm $compile use-square-functor.scm ./a.out $compile -s use-square-functor.scm -J -$interpret -nqe '(import sf1)' -e '(import sf2)' +$interpret -nqe '(require-library use-square-functor)' -e '(import sf1)' -e '(import sf2)' rm -f sf1.import.* sf2.import.* lst.import.* mod.import.* echo "======================================== compiler syntax tests ..." @@ -280,7 +280,6 @@ $interpret -i -s r5rs_pitfalls.scm echo "======================================== r7rs tests ..." $interpret -i -s r7rs-tests.scm - echo "======================================== module tests ..." $interpret -include-path ${TEST_DIR}/.. -s module-tests.scm $interpret -include-path ${TEST_DIR}/.. -s module-tests-2.scm @@ -288,7 +287,7 @@ $interpret -include-path ${TEST_DIR}/.. -s module-tests-2.scm echo "======================================== module tests (command line options) ..." module="test-$(date +%s)" $compile test.scm -A -w -j "$module" -module "$module" -$interpret -e "(import $module)" +$interpret -e "(import-syntax $module)" rm -f "$module.import.scm" echo "======================================== module tests (compiled) ..." diff --git a/tests/specialization-test-2.scm b/tests/specialization-test-2.scm index 9b80922d..d63f8d80 100644 --- a/tests/specialization-test-2.scm +++ b/tests/specialization-test-2.scm @@ -2,7 +2,8 @@ (module main () -(import scheme chicken foreign foo) ; note: does not load foo! +(import scheme chicken foreign) +(import-syntax foo) ; note: does not load foo! #> static int inlined(int i) {Trap