From d79d46138214f50714c7cbafcf8bdfe5530ee7c2 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sun, 17 Dec 2017 14:40:36 +0100 Subject: [PATCH 3/3] 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. --- batch-driver.scm | 9 ++++++++- internal.scm | 2 ++ modules.scm | 7 +++++++ tests/scrutiny.expected | 4 ++-- 4 files changed, 19 insertions(+), 3 deletions(-) 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 9e9af19e..375c151f 100644 --- a/modules.scm +++ b/modules.scm @@ -1133,3 +1133,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: -- 2.11.0