Get loader to work with R7RS files processed with SF.
authorChris Hanson <org/chris-hanson/cph>
Mon, 8 Oct 2018 01:07:19 +0000 (18:07 -0700)
committerChris Hanson <org/chris-hanson/cph>
Mon, 8 Oct 2018 01:07:19 +0000 (18:07 -0700)
src/runtime/library-loader.scm
src/runtime/library-standard.scm
src/runtime/load.scm
src/runtime/make.scm
src/runtime/mit-macros.scm
src/runtime/runtime.pkg
src/runtime/syntax-environment.scm
src/runtime/syntax-low.scm
src/runtime/syntax.scm

index 11e83f335fdbe043e653452858bd7801caed7250..a3f1ff743e8bb2f05a444a7d01bebb89886e1c05 100644 (file)
@@ -233,7 +233,14 @@ USA.
                  (scode-library->library library filename))
                (r7rs-scode-file-libraries scode)))))
     (register-libraries! libraries db)
-    (for-each library-eval-result libraries)))
+    (let loop ((libraries libraries) (result unspecific))
+      (if (pair? libraries)
+         (loop (cdr libraries)
+               (let* ((library (car libraries))
+                      (result* (library-eval-result library)))
+                 (or (library-name library)
+                     result*)))
+         result))))
 
 (define (scode-library->library library filename)
   (make-library (scode-library-name library)
@@ -262,39 +269,4 @@ USA.
        (let ((p (assq name export-alist)))
          (if (not p)
              (error "Not an exported name:" name))
-         (cdr p))))))
-\f
-;;;; Load
-
-#|
-(define (load db)
-  (for-each (lambda (parsed)
-             (load-library (syntax-library parsed db)
-                           db))
-           parsed-libraries)
-  (if (pair? imports)
-      (let ((environment*
-            (imports->environment
-             (expand-import-sets imports db))))
-       (let loop ((exprs body) (value unspecific))
-         (if (pair? exprs)
-             (loop (cdr exprs)
-                   (eval (car exprs) environment*))
-             value)))))
-
-(define (load-library library-name db)
-  (or (db 'get-loaded library-name #f)
-      (let ((syntaxed (db 'get-syntaxed library-name)))
-       (let ((environment
-              (imports->environment
-               (syntaxed-library-imports syntaxed)
-               db)))
-         (scode-eval (syntaxed-library-body syntaxed)
-                     environment)
-         (let ((loaded
-                (make-loaded-library (syntaxed-library-name syntaxed)
-                                     (syntaxed-library-exports syntaxed)
-                                     environment)))
-           (db 'save-loaded! loaded)
-           loaded)))))
-|#
\ No newline at end of file
+         (cdr p))))))
\ No newline at end of file
index 73bdd8eeae32ab056d48ed4ee8a5a33c54553ac1..74e5a3f031a76182c18a40a268708dcd894b89ac 100644 (file)
@@ -89,7 +89,8 @@ USA.
              imports))
 
 (define (define-standard-library name exports)
-  (let ((p (assoc name standard-libraries)))
+  (let ((p (assoc name standard-libraries))
+       (exports (extend-with-macro-deps exports)))
     (if p
        (set-cdr! p exports)
        (begin
@@ -101,6 +102,71 @@ USA.
 
 (define standard-libraries '())
 \f
+;; Make sure that the names introduced by macro expansions are also included.
+;; This is a kludge to work around our inability to address names globally.
+(define (extend-with-macro-deps names)
+  (define (scan-new to-scan new names)
+    (cond ((pair? to-scan)
+          (let ((name (car to-scan))
+                (rest (cdr to-scan)))
+            (let ((p (assq name macro-dependencies)))
+              (if p
+                  (scan-deps (cdr p) rest new names)
+                  (scan-new rest new names)))))
+         ((pair? new)
+          (scan-new new '() names))
+         (else names)))
+
+  (define (scan-deps deps rest new names)
+    (if (pair? deps)
+       (let ((dep (car deps)))
+         (if (memq dep names)
+             (scan-deps (cdr deps) rest new names)
+             (scan-deps (cdr deps)
+                        rest
+                        (cons dep new)
+                        (cons dep names))))
+       (scan-new rest new names)))
+
+  (scan-new names '() names))
+
+(define macro-dependencies
+  '((and if)
+    (and-let* and begin let)
+    (assert error if not)
+    (begin0 let)
+    (bundle alist->bundle cons list)
+    (case begin eq? eqv? if let or quote)
+    (case-lambda apply default-object? error fix:= fix:>= if lambda length let)
+    (circular-stream cons delay letrec)
+    (cond begin if let)
+    (cond-expand begin)
+    (cons-stream cons delay)
+    (cons-stream* cons delay)
+    (define lambda named-lambda)
+    (define-integrable begin lambda let set! shallow-fluid-bind)
+    (define-record-type define new-make-record-type quote record-accessor
+                       record-constructor record-modifier record-predicate)
+    (define-values begin call-with-values define lambda set!)
+    (delay delay-force make-promise)
+    (delay-force lambda make-unforced-promise)
+    (do begin if let)
+    (guard begin call-with-current-continuation if lambda let raise-continuable
+          with-exception-handler)
+    (include begin)
+    (include-ci begin)
+    (let declare lambda letrec letrec* named-lambda)
+    (let* let)
+    (let-syntax* let-syntax)
+    (letrec lambda let set!)
+    (letrec* begin lambda let)
+    (local-declare declare let)
+    (parameterize cons lambda list parameterize*)
+    (quasiquote append cons list list->vector quote vector)
+    (receive call-with-values lambda)
+    (unless begin if not)
+    (when begin if)))
+\f
 (define-standard-library '(scheme base)
   '(*
     +
index 8c1d14f13def14901301a943d1927e5afd9c34db..a7f43e83e4a93f2a8ae5a9836b3243e5f18ca621 100644 (file)
@@ -124,7 +124,7 @@ USA.
     (receive (pathname* loader notifier) (choose-fasload-method pathname)
       (if pathname*
          (values pathname*
-                 (wrap-loader pathname (fasloader->loader loader))
+                 (wrap-loader pathname (fasloader->loader pathname loader))
                  notifier)
          (let ((pathname*
                 (if (file-regular? pathname)
@@ -138,11 +138,13 @@ USA.
                        (loading-notifier pathname*))
                (values #f #f #f)))))))
 
-(define (fasloader->loader loader)
+(define (fasloader->loader pathname loader)
   (lambda (environment purify?)
     (let ((scode (loader)))
       (if purify? (purify (load/purification-root scode)))
-      (extended-scode-eval scode environment))))
+      (if (r7rs-scode-file? scode)
+         (eval-r7rs-scode-file scode pathname (current-load-library-db))
+         (extended-scode-eval scode environment)))))
 
 (define (source-loader pathname)
   (lambda (environment purify?)
@@ -173,7 +175,7 @@ USA.
 
 (define (file-fasloadable? pathname)
   (receive (pathname* loader notifier) (choose-fasload-method pathname)
-    loader notifier
+    (declare (ignore loader notifier))
     (if pathname* #t #f)))
 
 (define (choose-fasload-method pathname)
index c76c91dfe65014c0dd0faa8e1b67bded262f0558..a0b9d9ce96e17f1e145985a8b66236028116df50 100644 (file)
@@ -527,6 +527,7 @@ USA.
    (runtime unsyntaxer)
    (runtime pretty-printer)
    (runtime extended-scode-eval)
+   (runtime syntax low)
    (runtime syntax items)
    (runtime syntax rename)
    (runtime syntax top-level)
index a970b77332f390f44b8b0cbe6a010d9e28562eee..3ed2e05df8a98be0b61a0b963af7455a3b441f95 100644 (file)
@@ -927,4 +927,4 @@ USA.
   (syntax-rules ()
     ((_ predicate name ...)
      (alist->bundle predicate
-                  (list (cons 'name name) ...)))))
\ No newline at end of file
+                    (list (cons 'name name) ...)))))
\ No newline at end of file
index 89d1dcb620a5f3061bdf355927cf70dafc2877e8..59da5d0fc32bfe4aa72b4403ef77ad4af7b5c549 100644 (file)
@@ -4555,7 +4555,8 @@ USA.
          sc-macro-transformer->keyword-item
          spar-classifier->keyword
          spar-classifier->runtime
-         spar-macro-transformer->keyword-item))
+         spar-macro-transformer->keyword-item
+         top-level-senv))
 
 (define-package (runtime syntax items)
   (files "syntax-items")
index 1991bce5ba96f436da048da582cff1d7463cf9f5..2ac7e941b631fd3b17dff45014081a5ab9a9c744 100644 (file)
@@ -283,6 +283,8 @@ USA.
             => cdr)
            ((environment-lookup-macro env identifier))
            (else
+            (if (not (environment-bound? env identifier))
+                (warn "Reference to unbound variable:" identifier))
             ;; Capture free runtime references:
             (let ((item (var-item identifier)))
               (set! free (cons (cons identifier item) free))
index 605fc1c78152c2a160c944155a644658454d1e3d..95c05fae0680139d6a163c1da10adede9ecad343 100644 (file)
@@ -149,13 +149,15 @@ USA.
                            form
                            use-senv
                            hist
-                           (runtime-environment->syntactic
-                            (if (default-object? env)
-                                system-global-environment
-                                env)))
+                           (if (default-object? env)
+                               (top-level-senv)
+                               (runtime-environment->syntactic env)))
                 use-senv
                 hist))))
 
+(define-deferred top-level-senv
+  (make-unsettable-parameter #f))
+
 (define (syntactic-keyword->item keyword environment)
   (let ((item (environment-lookup-macro environment keyword)))
     (if (not item)
index 0dbaae9713e3bb89b75198eddabd0a78119336f8..a04a2d7cda7801a4bf126dc5f4d90de7aed7b5d5 100644 (file)
@@ -67,11 +67,12 @@ USA.
                 (get-free)))))))
 
 (define (syntax-internal forms senv)
-  (compile-item
-   (body-item #f
-     (map-in-order (lambda (form)
-                    (classify-form form senv (initial-hist form)))
-                  forms))))
+  (parameterize ((top-level-senv senv))
+    (compile-item
+     (body-item #f
+       (map-in-order (lambda (form)
+                      (classify-form form senv (initial-hist form)))
+                    forms)))))
 \f
 ;;;; Classifier