>From 1891eba297ddf6ce8d6012db7e556b3570fe2c7f Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sun, 17 Aug 2014 22:13:56 +0200 Subject: [PATCH 19/19] compiler-modules: Finalize modularisation of compiler! Remove compiler-namespace.scm and private-namespace.scm, update NEWS and remove special-case handling of CHICKEN_COMPILER_OPTIONS from build system. Add all generated import libraries to distribution manifest. However, for now they're not compiled to C or installed; they are only used during generation of the compiler because the API is nowhere near finished or ready for public consumption. Once we've defined a "proper" API, these can be compiled and installed too. --- NEWS | 3 +++ batch-driver.scm | 4 ---- c-backend.scm | 4 ---- c-platform.scm | 4 ---- chicken.scm | 1 - compiler-namespace.scm | 28 --------------------------- compiler-syntax.scm | 4 ---- compiler.scm | 6 ------ defaults.make | 2 -- distribution/manifest | 12 ++++++++++-- lfa2.scm | 4 ---- optimizer.scm | 4 ---- private-namespace.scm | 49 ------------------------------------------------ rules.make | 43 ++++++++++++++++-------------------------- scripts/compile-all | 2 +- scrutinizer.scm | 4 ---- support.scm | 4 ---- 17 files changed, 30 insertions(+), 148 deletions(-) delete mode 100644 compiler-namespace.scm delete mode 100644 private-namespace.scm diff --git a/NEWS b/NEWS index a51a31b..c1a4ab4 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,9 @@ - Allow functor arguments to be optional, with default implementations. - Fixed a bug that prevented functors from being instantiated with built-in modules. + - The compiler has been modularised, for improved namespacing. This + means names from the compiler should not leak out into the compiled + program's (macro) namespace anymore. - Syntax expander - define-values, set!-values and letrec-values now support full lambda diff --git a/batch-driver.scm b/batch-driver.scm index 2eafbe2..971218a 100644 --- a/batch-driver.scm +++ b/batch-driver.scm @@ -34,10 +34,6 @@ ;; TODO: Backend should be configurable scrutinizer lfa2 c-platform c-backend) ) -;; TODO: Remove these once everything's converted to modules -(include "private-namespace") -(include "compiler-namespace") - (module batch-driver (compile-source-file diff --git a/c-backend.scm b/c-backend.scm index 3848ede..b523302 100644 --- a/c-backend.scm +++ b/c-backend.scm @@ -33,10 +33,6 @@ (uses srfi-1 data-structures c-platform compiler support)) -;; TODO: Remove these once everything's converted to modules -(include "private-namespace") -(include "compiler-namespace") - (module c-backend (generate-code ;; For "foreign" (aka chicken-ffi-syntax): diff --git a/c-platform.scm b/c-platform.scm index edd8b70..f9fea6b 100644 --- a/c-platform.scm +++ b/c-platform.scm @@ -33,10 +33,6 @@ (uses srfi-1 data-structures optimizer support compiler)) -;; TODO: Remove these once everything's converted to modules -(include "private-namespace") -(include "compiler-namespace") - (module c-platform (default-declarations default-profiling-declarations units-used-by-default diff --git a/chicken.scm b/chicken.scm index ab46a18..5e85efd 100644 --- a/chicken.scm +++ b/chicken.scm @@ -34,7 +34,6 @@ srfi-69)) -(include "compiler-namespace") (include "tweaks") (import batch-driver c-platform) diff --git a/compiler-namespace.scm b/compiler-namespace.scm deleted file mode 100644 index 6834932..0000000 --- a/compiler-namespace.scm +++ /dev/null @@ -1,28 +0,0 @@ -;;;; compiler-namespace.scm - private namespace declarations for compiler units -; -; Copyright (c) 2009-2014, The CHICKEN Team -; All rights reserved. -; -; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following -; conditions are met: -; -; Redistributions of source code must retain the above copyright notice, this list of conditions and the following -; disclaimer. -; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following -; disclaimer in the documentation and/or other materials provided with the distribution. -; Neither the name of the author nor the names of its contributors may be used to endorse or promote -; products derived from this software without specific prior written permission. -; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS -; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR -; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -; POSSIBILITY OF SUCH DAMAGE. - - -(private - compiler) diff --git a/compiler-syntax.scm b/compiler-syntax.scm index 7883497..9fed04c 100644 --- a/compiler-syntax.scm +++ b/compiler-syntax.scm @@ -29,10 +29,6 @@ (uses srfi-1 data-structures support compiler) ) -;; TODO: Remove these once everything's converted to modules -(include "private-namespace") -(include "compiler-namespace") - (module compiler-syntax (compiler-syntax-statistics) diff --git a/compiler.scm b/compiler.scm index ee897a2..88a5ee5 100644 --- a/compiler.scm +++ b/compiler.scm @@ -267,12 +267,6 @@ (uses srfi-1 extras data-structures scrutinizer support) ) -(import scrutinizer support) - -;; TODO: Remove these once everything's converted to modules -(include "private-namespace") -(include "compiler-namespace") - (module compiler (analyze-expression canonicalize-expression compute-database-statistics initialize-compiler perform-closure-conversion perform-cps-conversion diff --git a/defaults.make b/defaults.make index dfce023..25b176f 100644 --- a/defaults.make +++ b/defaults.make @@ -256,13 +256,11 @@ endif CHICKEN_OPTIONS += $(EXTRA_CHICKEN_OPTIONS) CHICKEN_LIBRARY_OPTIONS = $(CHICKEN_OPTIONS) -explicit-use -no-trace CHICKEN_PROGRAM_OPTIONS = $(CHICKEN_OPTIONS) -no-lambda-info -local -CHICKEN_COMPILER_OPTIONS = $(CHICKEN_PROGRAM_OPTIONS) -extend private-namespace.scm CHICKEN_DYNAMIC_OPTIONS = $(CHICKEN_OPTIONS) -feature chicken-compile-shared -dynamic CHICKEN_IMPORT_LIBRARY_OPTIONS = $(CHICKEN_DYNAMIC_OPTIONS) -no-trace ifndef DEBUGBUILD CHICKEN_PROGRAM_OPTIONS += -no-trace -CHICKEN_COMPILER_OPTIONS += -no-trace endif CHICKEN_PROGRAM_OPTIONS += $(if $(PROFILE_OBJECTS),-profile) diff --git a/distribution/manifest b/distribution/manifest index 5a36068..1188267 100644 --- a/distribution/manifest +++ b/distribution/manifest @@ -6,12 +6,17 @@ config-arch.sh identify.sh banner.scm batch-driver.scm +batch-driver.import.scm batch-driver.c c-backend.c +c-backend.import.scm c-platform.c +c-platform.import.scm chicken-profile.c chicken.c +chicken.import.scm compiler.c +compiler.import.scm csc.c csi.c eval.c @@ -22,8 +27,11 @@ extras.c library.c lolevel.c optimizer.c +optimizer.import.scm compiler-syntax.c +compiler-syntax.import.scm scrutinizer.c +scrutinizer.import.scm irregex.c posixunix.c posixwin.c @@ -37,6 +45,7 @@ srfi-18.c srfi-4.c stub.c support.c +support.import.scm tcp.c utils.c build.scm @@ -76,6 +85,7 @@ irregex.scm irregex-core.scm irregex-utils.scm lfa2.c +lfa2.import.scm lfa2.scm posixunix.scm posixwin.scm @@ -234,8 +244,6 @@ GNUmakefile config.make rules.make defaults.make -private-namespace.scm -compiler-namespace.scm synrules.scm expand.scm expand.c diff --git a/lfa2.scm b/lfa2.scm index 386fd16..0d976d3 100644 --- a/lfa2.scm +++ b/lfa2.scm @@ -37,10 +37,6 @@ (uses srfi-1 support) ) -;; TODO: Remove these once everything's converted to modules -(include "private-namespace") -(include "compiler-namespace") - (module lfa2 (perform-secondary-flow-analysis) diff --git a/optimizer.scm b/optimizer.scm index bc68df0..3425af9 100644 --- a/optimizer.scm +++ b/optimizer.scm @@ -30,10 +30,6 @@ (uses srfi-1 data-structures support) ) -;; TODO: Remove these once everything's converted to modules -(include "private-namespace") -(include "compiler-namespace") - (module optimizer (scan-toplevel-assignments perform-high-level-optimizations transform-direct-lambdas! determine-loop-and-dispatch diff --git a/private-namespace.scm b/private-namespace.scm deleted file mode 100644 index 997f475..0000000 --- a/private-namespace.scm +++ /dev/null @@ -1,49 +0,0 @@ -;;;; compiler-namespace.scm - A simple namespace system to keep compiler variables hidden -; -; Copyright (c) 2008-2014, The CHICKEN Team -; Copyright (c) 2007, Felix L. Winkelmann -; All rights reserved. -; -; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following -; conditions are met: -; -; Redistributions of source code must retain the above copyright notice, this list of conditions and the following -; disclaimer. -; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following -; disclaimer in the documentation and/or other materials provided with the distribution. -; Neither the name of the author nor the names of its contributors may be used to endorse or promote -; products derived from this software without specific prior written permission. -; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS -; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR -; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -; POSSIBILITY OF SUCH DAMAGE. - - -(define-syntax private - (er-macro-transformer - (lambda (form r c) - (let ((namespace (cadr form)) - (vars (cddr form))) - (##sys#check-symbol namespace 'private) - (let* ((str (symbol->string namespace)) ; somewhat questionable (renaming) - (prefix (string-append - (string (integer->char (string-length str))) - (symbol->string namespace)))) - (for-each - (lambda (var) - (put! - var 'c:namespace - (##sys#string->qualified-symbol prefix (symbol->string var)))) - vars) - '(##core#undefined) ) ) ) ) ) - -(let ((old-hook ##sys#alias-global-hook)) - (set! ##sys#alias-global-hook - (lambda (var . assign) ; must work with old chicken - (or (get var 'c:namespace) (apply old-hook var assign)) ) )) diff --git a/rules.make b/rules.make index 84f45c8..19e620f 100644 --- a/rules.make +++ b/rules.make @@ -495,30 +495,20 @@ $(foreach lib, $(SETUP_API_OBJECTS_1),\ $(foreach lib, $(filter-out chicken,$(COMPILER_OBJECTS_1)),\ $(eval $(call declare-emitted-import-lib-dependency,$(lib)))) -chicken.c: chicken.scm batch-driver.import.scm batch-driver.scm \ - c-platform.scm c-platform.import.scm -batch-driver.c: batch-driver.scm compiler.scm compiler.import.scm \ - compiler-syntax.scm compiler-syntax.import.scm \ - optimizer.scm optimizer.import.scm \ - scrutinizer.scm scrutinizer.import.scm \ - c-platform.scm c-platform.import.scm \ - lfa2.import.scm lfa2.scm \ - c-backend.scm c-backend.import.scm \ - support.scm support.import.scm -c-platform.c: c-platform.scm optimizer.scm optimizer.import.scm \ - support.scm support.import.scm \ - compiler.scm compiler.import.scm -c-backend.c: c-backend.scm c-platform.scm c-platform.import.scm \ - support.scm support.import.scm \ - compiler.scm compiler.import.scm -compiler.c: compiler.scm scrutinizer.scm scrutinizer.import.scm \ - support.scm support.import.scm -optimizer.c: optimizer.scm support.scm support.import.scm -scrutinizer.c: scrutinizer.scm support.scm support.import.scm -lfa2.c: lfa2.scm support.scm support.import.scm -compiler-syntax.c: compiler-syntax.scm \ - support.scm support.import.scm \ - compiler.scm compiler.import.scm +chicken.c: chicken.scm batch-driver.import.scm c-platform.import.scm +batch-driver.c: batch-driver.scm compiler.import.scm \ + compiler-syntax.import.scm optimizer.import.scm \ + scrutinizer.import.scm c-platform.import.scm \ + lfa2.import.scm c-backend.import.scm support.import.scm +c-platform.c: c-platform.scm optimizer.import.scm support.import.scm \ + compiler.import.scm +c-backend.c: c-backend.scm c-platform.import.scm support.import.scm \ + compiler.import.scm +compiler.c: compiler.scm scrutinizer.import.scm support.import.scm +optimizer.c: optimizer.scm support.import.scm +scrutinizer.c: scrutinizer.scm support.import.scm +lfa2.c: lfa2.scm support.import.scm +compiler-syntax.c: compiler-syntax.scm support.import.scm compiler.import.scm define profile-flags $(if $(filter $(basename $(1)),$(PROFILE_OBJECTS)),-profile) @@ -594,9 +584,8 @@ $(foreach obj, $(IMPORT_LIBRARIES),\ # Bootstrap compiler objects define declare-bootstrap-compiler-object -$(1).c: $$(SRCDIR)$(1).scm $$(SRCDIR)compiler-namespace.scm \ - $$(SRCDIR)private-namespace.scm $$(SRCDIR)tweaks.scm - $$(CHICKEN) $$< $$(CHICKEN_COMPILER_OPTIONS) -emit-import-library $(1) -output-file $$@ +$(1).c: $$(SRCDIR)$(1).scm $$(SRCDIR)tweaks.scm + $$(CHICKEN) $$< $$(CHICKEN_PROGRAM_OPTIONS) -emit-import-library $(1) -output-file $$@ endef $(foreach obj, $(COMPILER_OBJECTS_1),\ diff --git a/scripts/compile-all b/scripts/compile-all index 0754b06..c8aa16e 100755 --- a/scripts/compile-all +++ b/scripts/compile-all @@ -5,7 +5,7 @@ set -e set -x -compiler_options="-optimize-level 2 -include-path . -include-path ./ -inline -ignore-repository -feature chicken-bootstrap -feature debugbuild -scrutinize -types ./types.db -verbose -no-lambda-info -local -extend private-namespace.scm -specialize" +compiler_options="-optimize-level 2 -include-path . -include-path ./ -inline -ignore-repository -feature chicken-bootstrap -feature debugbuild -scrutinize -types ./types.db -verbose -no-lambda-info -local -specialize" library_options="-optimize-level 2 -include-path . -include-path ./ -inline -ignore-repository -feature chicken-bootstrap -feature debugbuild -scrutinize -types ./types.db -verbose -explicit-use -no-trace -specialize" diff --git a/scrutinizer.scm b/scrutinizer.scm index 3dc03f5..63f0296 100644 --- a/scrutinizer.scm +++ b/scrutinizer.scm @@ -29,10 +29,6 @@ (uses srfi-1 data-structures extras ports files support) ) -;; TODO: Remove these once everything's converted to modules -(include "private-namespace") -(include "compiler-namespace") - (module scrutinizer (scrutinize load-type-database emit-type-file validate-type check-and-validate-type install-specializations) diff --git a/support.scm b/support.scm index 2dc060d..da31c4b 100644 --- a/support.scm +++ b/support.scm @@ -29,10 +29,6 @@ (not inline ##sys#user-read-hook) ; XXX: Is this needed? (uses data-structures srfi-1 files extras ports) ) -;; TODO: Remove these once everything's converted to modules -(include "private-namespace") -(include "compiler-namespace") - (module support (compiler-cleanup-hook bomb collected-debugging-output debugging debugging-chicken with-debugging-output quit-compiling -- 1.7.10.4