fix define-module ordering
authorAndy Wingo <wingo@pobox.com>
Sat, 21 May 2011 16:29:03 +0000 (18:29 +0200)
committerAndy Wingo <wingo@pobox.com>
Sat, 21 May 2011 16:29:03 +0000 (18:29 +0200)
* module/ice-9/boot-9.scm (define-module): Fix to load the #:use-module
  clauses in the order in which they appear in the define-module form.
  Thanks to Jan Nieuwenhuizen for the report.

* test-suite/standalone/test-import-order: Add new test that
  define-module and use-modules resolve the interface in the right
  order.

* test-suite/standalone/Makefile.am:
* test-suite/standalone/test-import-order-a.scm:
* test-suite/standalone/test-import-order-b.scm:
* test-suite/standalone/test-import-order-c.scm:
* test-suite/standalone/test-import-order-d.scm: Aux files.

module/ice-9/boot-9.scm
test-suite/standalone/Makefile.am
test-suite/standalone/test-import-order [new file with mode: 0755]
test-suite/standalone/test-import-order-a.scm [new file with mode: 0644]
test-suite/standalone/test-import-order-b.scm [new file with mode: 0644]
test-suite/standalone/test-import-order-c.scm [new file with mode: 0644]
test-suite/standalone/test-import-order-d.scm [new file with mode: 0644]

index 60d133f..539eac9 100644 (file)
@@ -3070,15 +3070,15 @@ module '(ice-9 q) '(make-q q-length))}."
          #`(#:filename 'f . #,(parse #'args imp exp rex rep aut)))
         ((#:use-module (name name* ...) . args)
          (and (and-map symbol? (syntax->datum #'(name name* ...))))
-         (parse #'args (cons #'((name name* ...)) imp) exp rex rep aut))
+         (parse #'args #`(#,@imp ((name name* ...))) exp rex rep aut))
         ((#:use-syntax (name name* ...) . args)
          (and (and-map symbol? (syntax->datum #'(name name* ...))))
          #`(#:transformer '(name name* ...)
-            . #,(parse #'args (cons #'((name name* ...)) imp) exp rex rep aut)))
+            . #,(parse #'args #`(#,@imp ((name name* ...))) exp rex rep aut)))
         ((#:use-module ((name name* ...) arg ...) . args)
          (and (and-map symbol? (syntax->datum #'(name name* ...))))
          (parse #'args
-                (cons #`((name name* ...) #,@(parse-iface #'(arg ...))) imp)
+                #`(#,@imp ((name name* ...) #,@(parse-iface #'(arg ...))))
                 exp rex rep aut))
         ((#:export (ex ...) . args)
          (parse #'args imp #`(#,@exp ex ...) rex rep aut))
index cf1fc4f..e239ac3 100644 (file)
@@ -75,6 +75,11 @@ TESTS += test-require-extension
 check_SCRIPTS += test-guile-snarf
 TESTS += test-guile-snarf
 
+check_SCRIPTS += test-import-order
+TESTS += test-import-order
+EXTRA_DIST += test-import-order-a.scm test-import-order-b.scm \
+  test-import-order-c.scm test-import-order-d.scm
+
 # test-num2integral
 test_num2integral_SOURCES = test-num2integral.c
 test_num2integral_CFLAGS = ${test_cflags}
diff --git a/test-suite/standalone/test-import-order b/test-suite/standalone/test-import-order
new file mode 100755 (executable)
index 0000000..333f2a4
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+exec guile -q -L "$builddir" -s "$0" "$@"
+!#
+
+(define-module (base)
+  #:export (push! order))
+
+(define order '())
+(define (push!)
+  (set! order `(,@order ,(module-name (current-module)))))
+
+(define-module (test-1)
+  #:use-module (base)
+  #:use-module (test-import-order-a)
+  #:use-module (test-import-order-b))
+
+(use-modules (test-import-order-c) (test-import-order-d))
+
+(if (not (equal? order
+                 '((test-import-order-a)
+                   (test-import-order-b)
+                   (test-import-order-c)
+                   (test-import-order-d))))
+    (begin
+      (format (current-error-port) "Unexpected import order: ~a" order)
+      (exit 1))
+    (exit 0))
+
+;; Local Variables:
+;; mode: scheme
+;; End:
\ No newline at end of file
diff --git a/test-suite/standalone/test-import-order-a.scm b/test-suite/standalone/test-import-order-a.scm
new file mode 100644 (file)
index 0000000..d6fa29d
--- /dev/null
@@ -0,0 +1,4 @@
+(define-module (test-import-order-a)
+  #:use-module (base))
+
+(push!)
diff --git a/test-suite/standalone/test-import-order-b.scm b/test-suite/standalone/test-import-order-b.scm
new file mode 100644 (file)
index 0000000..bc41bdf
--- /dev/null
@@ -0,0 +1,4 @@
+(define-module (test-import-order-b)
+  #:use-module (base))
+
+(push!)
diff --git a/test-suite/standalone/test-import-order-c.scm b/test-suite/standalone/test-import-order-c.scm
new file mode 100644 (file)
index 0000000..4b58c3d
--- /dev/null
@@ -0,0 +1,4 @@
+(define-module (test-import-order-c)
+  #:use-module (base))
+
+(push!)
diff --git a/test-suite/standalone/test-import-order-d.scm b/test-suite/standalone/test-import-order-d.scm
new file mode 100644 (file)
index 0000000..fb071be
--- /dev/null
@@ -0,0 +1,4 @@
+(define-module (test-import-order-d)
+  #:use-module (base))
+
+(push!)