~ chicken-core (chicken-5) 80d5a0a393e429be92ad8d1c639cfd26d62c4dd2
commit 80d5a0a393e429be92ad8d1c639cfd26d62c4dd2 Author: Evan Hanson <evhan@foldling.org> AuthorDate: Mon Apr 4 16:06:56 2016 +1200 Commit: Peter Bex <peter@more-magic.net> CommitDate: Sun Apr 17 17:31:54 2016 +0200 Move user-pass parameters to dedicated module Now that the compiler driver is a module, the parameters containing user-defined compilation passes need to be exposed so that that they can be imported and used in compiler extensions. Also, add a test for these parameters while we're in the neighborhood. Signed-off-by: Peter Bex <peter@more-magic.net> diff --git a/README b/README index bf4e13d1..fb49fec6 100644 --- a/README +++ b/README @@ -287,6 +287,7 @@ | | `-- 8 | | |-- chicken.import.so | | |-- chicken.bitwise.import.so + | | |-- chicken.compiler.user-pass.import.so | | |-- chicken.continuation.import.so | | |-- chicken.data-structures.import.so | | |-- chicken.eval.import.so diff --git a/batch-driver.scm b/batch-driver.scm index c8906788..0d319e89 100644 --- a/batch-driver.scm +++ b/batch-driver.scm @@ -32,13 +32,10 @@ (uses extras data-structures files support compiler-syntax compiler optimizer ;; TODO: Backend should be configurable - scrutinizer lfa2 c-platform c-backend) ) + scrutinizer lfa2 c-platform c-backend user-pass)) (module chicken.compiler.batch-driver - (compile-source-file - - user-options-pass user-read-pass user-preprocessor-pass user-pass - user-post-analysis-pass) + (compile-source-file) (import chicken scheme chicken.data-structures @@ -54,19 +51,14 @@ chicken.compiler.scrutinizer chicken.compiler.lfa2 chicken.compiler.c-platform - chicken.compiler.c-backend) + chicken.compiler.c-backend + chicken.compiler.user-pass) (include "tweaks") (include "mini-srfi-1.scm") (define-constant funny-message-timeout 60000) -(define user-options-pass (make-parameter #f)) -(define user-read-pass (make-parameter #f)) -(define user-preprocessor-pass (make-parameter #f)) -(define user-pass (make-parameter #f)) -(define user-post-analysis-pass (make-parameter #f)) - ;;; Emit collected information from various statistics about the program (define (print-program-statistics db) diff --git a/chicken.scm b/chicken.scm index d8b9c309..ac9dba87 100644 --- a/chicken.scm +++ b/chicken.scm @@ -30,8 +30,8 @@ srfi-4 extras data-structures lolevel ; unused, but loaded to make foldable bindings available support compiler optimizer lfa2 compiler-syntax scrutinizer - ;; TODO: These three need to be made configurable somehow - batch-driver c-platform c-backend)) + ;; TODO: Backend should be configurable + batch-driver c-platform c-backend user-pass)) (module chicken.compiler.chicken () @@ -39,6 +39,7 @@ chicken.compiler.batch-driver chicken.compiler.c-platform chicken.compiler.support + chicken.compiler.user-pass chicken.data-structures) (include "tweaks") diff --git a/defaults.make b/defaults.make index cce0e26a..15d54407 100644 --- a/defaults.make +++ b/defaults.make @@ -266,6 +266,7 @@ PRIMITIVE_IMPORT_LIBRARIES = chicken csi chicken.foreign DYNAMIC_IMPORT_LIBRARIES = setup-api setup-download srfi-4 DYNAMIC_CHICKEN_IMPORT_LIBRARIES = bitwise fixnum flonum format gc io \ keyword locative posix pretty-print random time +DYNAMIC_CHICKEN_COMPILER_IMPORT_LIBRARIES = user-pass DYNAMIC_CHICKEN_UNIT_IMPORT_LIBRARIES = continuation data-structures \ eval expand files internal irregex lolevel ports read-syntax \ repl tcp utils @@ -284,7 +285,8 @@ CHICKEN_DEBUGGER_PROGRAM ?= $(PROGRAM_PREFIX)feathers$(PROGRAM_SUFFIX)$(SCRIPT_E IMPORT_LIBRARIES = $(DYNAMIC_IMPORT_LIBRARIES) \ $(PRIMITIVE_IMPORT_LIBRARIES) \ $(foreach lib,$(DYNAMIC_CHICKEN_IMPORT_LIBRARIES),chicken.$(lib)) \ - $(foreach lib,$(DYNAMIC_CHICKEN_UNIT_IMPORT_LIBRARIES),chicken.$(lib)) + $(foreach lib,$(DYNAMIC_CHICKEN_UNIT_IMPORT_LIBRARIES),chicken.$(lib)) \ + $(foreach lib,$(DYNAMIC_CHICKEN_COMPILER_IMPORT_LIBRARIES),chicken.compiler.$(lib)) ifdef STATICBUILD CHICKEN_STATIC_EXECUTABLE = $(CHICKEN_PROGRAM)$(EXE) diff --git a/distribution/manifest b/distribution/manifest index ef5763fb..eb93a5fc 100644 --- a/distribution/manifest +++ b/distribution/manifest @@ -47,6 +47,7 @@ chicken.compiler.support.import.scm repl.c tcp.c utils.c +user-pass.c feathers.in feathers.bat.in feathers.tcl @@ -251,6 +252,8 @@ chicken.import.scm chicken.import.c chicken.bitwise.import.scm chicken.bitwise.import.c +chicken.compiler.user-pass.import.scm +chicken.compiler.user-pass.import.c chicken.continuation.import.scm chicken.continuation.import.c chicken.data-structures.import.scm diff --git a/manual/Using the compiler b/manual/Using the compiler index bcc4a0f5..c7c22a8f 100644 --- a/manual/Using the compiler +++ b/manual/Using the compiler @@ -367,6 +367,9 @@ can be set to procedures that are called to perform certain compilation passes instead of the usual processing (for more information about parameters see [[Supported language]]). +These parameters are provided by the {{(chicken compiler user-pass)}} +module. + <parameter>user-options-pass</parameter> Holds a procedure that will be called with a list of command-line arguments and should return two values: the source filename and the actual list of options, where compiler switches have their leading {{-}} (hyphen) removed and are converted to symbols. Note that this parameter is invoked '''before''' processing of the {{-extend}} option, and so can only be changed in compiled user passes. diff --git a/rules.make b/rules.make index f6b309c8..12b84da3 100644 --- a/rules.make +++ b/rules.make @@ -45,7 +45,7 @@ LIBCHICKEN_STATIC_OBJECTS = $(LIBCHICKEN_OBJECTS_1:=-static$(O)) COMPILER_OBJECTS_1 = \ chicken batch-driver core optimizer lfa2 compiler-syntax scrutinizer support \ - c-platform c-backend + c-platform c-backend user-pass COMPILER_OBJECTS = $(COMPILER_OBJECTS_1:=$(O)) COMPILER_STATIC_OBJECTS = $(COMPILER_OBJECTS_1:=-static$(O)) @@ -534,6 +534,7 @@ chicken.c: chicken.scm mini-srfi-1.scm \ chicken.compiler.batch-driver.import.scm \ chicken.compiler.c-platform.import.scm \ chicken.compiler.support.import.scm \ + chicken.compiler.user-pass.import.scm \ chicken.data-structures.import.scm batch-driver.c: batch-driver.scm mini-srfi-1.scm \ chicken.compiler.core.import.scm \ @@ -544,6 +545,7 @@ batch-driver.c: batch-driver.scm mini-srfi-1.scm \ chicken.compiler.lfa2.import.scm \ chicken.compiler.c-backend.import.scm \ chicken.compiler.support.import.scm \ + chicken.compiler.user-pass.import.scm \ chicken.data-structures.import.scm \ chicken.files.import.scm \ chicken.format.import.scm \ diff --git a/tests/runtests.sh b/tests/runtests.sh index 4ca92325..8d307067 100755 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -429,6 +429,9 @@ echo "======================================== executable tests ..." $compile executable-tests.scm ./a.out "$TEST_DIR/a.out" +echo "======================================== user pass tests ..." +$compile -extend user-pass-tests.scm null.scm + echo "======================================== embedding (1) ..." $compile embedded1.c ./a.out diff --git a/tests/user-pass-tests.scm b/tests/user-pass-tests.scm new file mode 100644 index 00000000..0ef5f931 --- /dev/null +++ b/tests/user-pass-tests.scm @@ -0,0 +1,33 @@ +;;; Test user compilation passes + +(import (chicken compiler user-pass) + (chicken io) + (chicken pretty-print)) + +(define passes '()) ; track user passes + +(user-read-pass + (lambda (_ _ _) + (set! passes (cons 'user-read-pass passes)) + (list 'ok))) ; ignore file and use single datum + +(user-preprocessor-pass + (lambda (x) + (set! passes (cons 'user-preprocessor-pass passes)) + (values x))) + +(user-pass + (lambda (x) + (set! passes (cons 'user-pass passes)) + (values x))) + +(user-post-analysis-pass + (lambda (_ _ _ _ _ _ _) + (set! passes (cons 'user-post-analysis-pass passes)))) + +(on-exit + (lambda () + (assert (memq 'user-read-pass passes) "user-read-pass not called") + (assert (memq 'user-pass passes) "user-pass not called") + (assert (memq 'user-preprocessor-pass passes) "user-preprocessor-pass not called") + (assert (memq 'user-post-analysis-pass passes) "user-post-analysis-pass not called"))) diff --git a/user-pass.scm b/user-pass.scm new file mode 100644 index 00000000..4d6c19b6 --- /dev/null +++ b/user-pass.scm @@ -0,0 +1,42 @@ +;;;; user-pass.scm - User compilation passes +; +; Copyright (c) 2008-2016, The CHICKEN Team +; Copyright (c) 2000-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. + +(declare (unit user-pass)) + +(module chicken.compiler.user-pass + (user-options-pass + user-read-pass + user-preprocessor-pass + user-pass + user-post-analysis-pass) + +(import scheme chicken) + +(define user-options-pass (make-parameter #f)) +(define user-read-pass (make-parameter #f)) +(define user-preprocessor-pass (make-parameter #f)) +(define user-pass (make-parameter #f)) +(define user-post-analysis-pass (make-parameter #f)))Trap