summaryrefslogtreecommitdiff
path: root/test-suite
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2008-10-30 10:57:36 +0100
committerAndy Wingo <wingo@pobox.com>2008-10-30 10:57:36 +0100
commit3de80ed52f7482faee2ce883d3df21eb8a38ee7a (patch)
treef33bf42499307ad99a5c78031e6497cddf47d89e /test-suite
parent21497600d23534b2878f82401ffaf5551fdb6efd (diff)
downloadguile-3de80ed52f7482faee2ce883d3df21eb8a38ee7a.tar.gz
recompiling with compile environments, fluid languages, cleanups
* ice-9/boot-9.scm (compile-time-environment): Remove definition from boot-9 -- instead, autoload it and `compile' from (system base compile). * libguile/objcodes.h: * libguile/objcodes.c (scm_objcode_to_program): Add an optional argument, `external', the external list to set on the returned program. * libguile/vm-i-system.c (externals): New instruction, returns the external list. Only used by (compile-time-environment). * libguile/vm.c (scm_load_compiled_with_vm): Adapt to scm_objcode_to_program change. * module/language/scheme/translate.scm (translate): Actually pay attention to the environment passed as an argument. (custom-transformer-table): Expand out (compile-time-environment) to something that can be passed to `compile'. * module/system/base/compile.scm (*current-language*): Instead of hard-coding `scheme' in various places, use a current language fluid, initialized to `scheme'. (compile-file, load-source-file): Adapt to *current-language*. (load-source-file): Ada (scheme-eval): Removed, no one used this. (compiled-file-name): Don't hard-code "scm" and "go"; instead use the %load-extensions and %load-compiled-extensions. (cenv-module, cenv-ghil-env, cenv-externals): Some accessors for compile-time environments. (compile-time-environment): Here we define (compile-time-environment) to something that will return #f; the compiler however produces different code as noted above. (compile): New function, compiles an expression into a thunk, then runs the thunk to get the value. Useful for procedures. The optional second argument can be either a module or a compile-time-environment; in the latter case, we can recompile even with lexical bindings. (compile-in): If the env specifies a module, set that module for the duration of the compilation. * module/system/base/syntax.scm (%compute-initargs): Fix a bug where the default value for a field would always replace a user-supplied value. Whoops. * module/system/il/ghil.scm (ghil-env-dereify): New function, takes the result of ghil-env-reify and turns it back into a GHIL environment. * scripts/compile (compile): Remove some of the tricky error handling, as the library procedures handle this for us. * test-suite/tests/compiler.test: Add a test for the dynamic compilation bits.
Diffstat (limited to 'test-suite')
-rw-r--r--test-suite/tests/compiler.test62
1 files changed, 62 insertions, 0 deletions
diff --git a/test-suite/tests/compiler.test b/test-suite/tests/compiler.test
new file mode 100644
index 000000000..dc27d6dc1
--- /dev/null
+++ b/test-suite/tests/compiler.test
@@ -0,0 +1,62 @@
+;;;; compiler.test --- tests for the compiler -*- scheme -*-
+;;;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1999, 2001, 2006 Free Software Foundation, Inc.
+;;;;
+;;;; This library is free software; you can redistribute it and/or
+;;;; modify it under the terms of the GNU Lesser General Public
+;;;; License as published by the Free Software Foundation; either
+;;;; version 2.1 of the License, or (at your option) any later version.
+;;;;
+;;;; This library is distributed in the hope that it will be useful,
+;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;;; Lesser General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU Lesser General Public
+;;;; License along with this library; if not, write to the Free Software
+;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+(define-module (test-suite tests compiler)
+ :use-module (test-suite lib)
+ :use-module (test-suite guile-test)
+ :use-module (system vm program))
+
+
+(with-test-prefix "environments"
+
+ (pass-if "compile-time-environment in evaluator"
+ (eq? (primitive-eval '(compile-time-environment)) #f))
+
+ (pass-if "compile-time-environment in compiler"
+ (equal? (compile '(compile-time-environment))
+ (cons (current-module)
+ (cons '() '()))))
+
+ (let ((env (compile
+ '(let ((x 0)) (set! x 1) (compile-time-environment)))))
+ (pass-if "compile-time-environment in compiler, heap-allocated var"
+ (equal? env
+ (cons (current-module)
+ (cons '((x . 0)) '(1)))))
+
+ ;; fixme: compiling with #t or module
+ (pass-if "recompiling with environment"
+ (equal? ((compile '(lambda () x) env))
+ 1))
+
+ (pass-if "recompiling with environment/2"
+ (equal? ((compile '(lambda () (set! x (1+ x)) x) env))
+ 2))
+
+ (pass-if "recompiling with environment/3"
+ (equal? ((compile '(lambda () x) env))
+ 2))
+ )
+
+ (pass-if "compile environment is #f"
+ (equal? ((compile '(lambda () 10)))
+ 10))
+
+ (pass-if "compile environment is a module"
+ (equal? ((compile '(lambda () 10) (current-module)))
+ 10))
+ ) \ No newline at end of file