push the module resolution info for variables down into glil
authorAndy Wingo <wingo@pobox.com>
Thu, 15 May 2008 11:03:10 +0000 (13:03 +0200)
committerAndy Wingo <wingo@pobox.com>
Thu, 15 May 2008 11:03:10 +0000 (13:03 +0200)
* module/system/il/compile.scm (make-glil-var): Make the :mod of the
  glil-var actually a guile module, not a ghil-env.

* module/system/il/ghil.scm (module-lookup, ghil-lookup): For module
  variables, encode the location where we found the variable in the
  ghil-var.

module/system/il/compile.scm
module/system/il/ghil.scm
module/system/vm/assemble.scm

index db22124..f0e636b 100644 (file)
         ((eq? e (ghil-var-env var))
          (make-glil-external op depth (ghil-var-index var)))))
     ((module)
-     (make-glil-module op (ghil-var-env var) (ghil-var-name var)))
+     (make-glil-module op (ghil-mod-module (ghil-env-mod (ghil-var-env var)))
+                       (ghil-var-name var)))
     (else (error "Unknown kind of variable:" var))))
 
 (define (codegen ghil)
index e2b2bfa..c3f3f82 100644 (file)
 ;;; Public interface
 ;;;
 
+(define (module-lookup module sym)
+  (let ((iface (module-import-interface module sym)))
+    (and iface
+         (make-ghil-env (make-ghil-mod iface)))))
+
 ;; looking up a var has side effects?
 (define (ghil-lookup env sym)
   (or (ghil-env-ref env sym)
       (let loop ((e (ghil-env-parent env)))
         (record-case e
           ((<ghil-mod> module table imports)
-           (or (assq-ref table sym)
-               ;; a free variable that we have not resolved
-               (make-ghil-var #f sym 'module)))
+           (cond ((assq-ref table sym))
+                 ((module-lookup module sym)
+                  => (lambda (found-env)
+                       (make-ghil-var found-env sym 'module)))
+                 (else
+                  ;; a free variable that we have not resolved
+                  (warn "unresolved variable during compilation:" sym)
+                  (make-ghil-var #f sym 'module))))
           ((<ghil-env> mod parent table variables)
            (let ((found (assq-ref table sym)))
              (if found
index 19e633b..bcc7ab0 100644 (file)
                     (push-code! `(external-set ,(+ n index)))))))
 
           ((<glil-module> op module name)
+            (pk op module name)
             (case op
               ((ref)
                (push-object! (make-vlink :module module :name name))