~ chicken-core (chicken-5) 24325e3a6e1e829e9e9be8d22e28d1711a796bd2


commit 24325e3a6e1e829e9e9be8d22e28d1711a796bd2
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Sun Dec 17 14:40:36 2017 +0100
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Fri Dec 29 20:51:12 2017 +0100

    Include definitions of default modules into modules.scm for "eval"
    
    We also inject (eval '(import scheme chicken.base chicken.syntax))
    into program preludes through batch-driver.scm, so that the initial
    eval environment is populated (else it's initially completely empty).
    
    This fixes several tests which assume that eval environments are
    nonempty by default.
    
    This is a (hopefully) temporary workaround, as including just these
    imports is quite specific and only really works for the default
    situation.  Statically linked programs cannot eval arbitrary imports
    right now.  Because it's meant to be temporary, we still build and
    install the chicken.base.import.so and chicken.syntax.import.so
    compiled import libraries even though they'll never be used as the
    module definitions are now built into modules.scm.
    
    Signed-off-by: felix <felix@call-with-current-continuation.org>

diff --git a/batch-driver.scm b/batch-driver.scm
index 883dd6cf..ebd62ea6 100644
--- a/batch-driver.scm
+++ b/batch-driver.scm
@@ -187,7 +187,14 @@
 			     `((uses ,@default-units)))))
 		     ,@(if explicit-use-flag
 			   '()
-			   `((import ,@default-imports)))))
+			   `((import ,@default-imports)))
+		     ;; Ensure the same default environment is
+		     ;; available from eval, as well.  See notes at
+		     ;; the end of internal.scm and modules.scm.
+		     ,@(if explicit-use-flag
+			   '()
+			   `((scheme#eval '(import-for-syntax ,@default-syntax-imports))
+			     (scheme#eval '(import ,@default-imports))))))
         (verbose (memq 'verbose options))
 	(outfile (cond ((memq 'output-file options) 
 			=> (lambda (node)
diff --git a/internal.scm b/internal.scm
index 5d5da250..8f624140 100644
--- a/internal.scm
+++ b/internal.scm
@@ -211,6 +211,8 @@
 
 ;; WARNING: These import libs must all exist.  They cannot be emitted,
 ;; because the compiler itself needs them to expand macros!
+;; WARNING: These also need to be built into modules.scm, so that
+;; statically linked programs can eval the imports for these modules.
 
 (define default-imports '(scheme chicken.base chicken.syntax))
 (define default-syntax-imports '(scheme chicken.base chicken.syntax))
diff --git a/modules.scm b/modules.scm
index 9241958a..8e5179c6 100644
--- a/modules.scm
+++ b/modules.scm
@@ -1130,3 +1130,10 @@
 	 'module-environment "undefined module" mname)
 	(##sys#make-structure
 	 'environment ename (car (module-saved-environments mod)) #t))))
+
+;; Ensure default modules are available in "eval", too
+;; TODO: Figure out a better way to make this work for static programs.
+;; The actual imports are handled by the prelude inserted by
+;; batch-driver.scm
+(include "chicken.base.import.scm")
+(include "chicken.syntax.import.scm")
diff --git a/tests/scrutiny.expected b/tests/scrutiny.expected
index 44afef85..75910d11 100644
--- a/tests/scrutiny.expected
+++ b/tests/scrutiny.expected
@@ -43,10 +43,10 @@ Warning: at toplevel:
   assignment of value of type `fixnum' to toplevel variable `scheme#car' does not match declared type `(forall (a) (procedure scheme#car ((pair a *)) a))'
 
 Warning: at toplevel:
-  expected a single result in `let' binding of `g19', but received 2 results
+  expected a single result in `let' binding of `g118', but received 2 results
 
 Warning: at toplevel:
-  in procedure call to `g19', expected a value of type `(procedure () *)' but was given a value of type `fixnum'
+  in procedure call to `g118', expected a value of type `(procedure () *)' but was given a value of type `fixnum'
 
 Note: in toplevel procedure `foo':
   expected a value of type boolean in conditional, but was given a value of type `(procedure bar () *)' which is always true:
Trap