>From f6655a89ef19875be7be5e0927366b6527b088bf Mon Sep 17 00:00:00 2001 From: Evan Hanson Date: Tue, 7 Apr 2015 08:23:43 +1200 Subject: [PATCH] Make the "-module" option take the module name as an argument Allows specifying the module name at the command line, aliases this option as "-m", and adds a "-main-module" option (aliased as "-M") that provides the old behaviour (a default module name of "main"). Also removes the long-since-deprecated "-scrutinize" option and fixes a missing import of c.c.support in chicken.scm (for `quit-compiling`, and possibly other procedures). --- NEWS | 3 +++ batch-driver.scm | 17 ++++++++++------- c-platform.scm | 9 ++++----- chicken.scm | 13 +++++++------ csc.scm | 12 +++++++----- manual/Unit utils | 2 +- manual/Using the compiler | 6 ++++-- rules.make | 1 + scripts/compile-all | 4 ++-- support.scm | 4 +++- tests/runtests.bat | 16 ++++++++++++++-- tests/runtests.sh | 12 ++++++++++-- 12 files changed, 66 insertions(+), 33 deletions(-) diff --git a/NEWS b/NEWS index fc7c0c6..58d5b57 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,9 @@ - Compiler - Fixed an off by one allocation problem in generated C code for (list ...). + - The "-scrutinize" compiler option has been removed. + - The "-module" compiler option (aliased as "-m") now expects a module + name, with the new "-main-module" (or "-M") option defaulting to "main". - Core libraries - Removed support for memory-mapped files (posix), queues (data-structures), diff --git a/batch-driver.scm b/batch-driver.scm index 82351f9..31de335 100644 --- a/batch-driver.scm +++ b/batch-driver.scm @@ -223,8 +223,11 @@ (dumpnodes #f) (start-time #f) (upap #f) - (wrap-module (memq 'module options)) - (ssize (or (memq 'nursery options) (memq 'stack-size options))) ) + (ssize (or (memq 'nursery options) (memq 'stack-size options))) + (module-name + (cond ((memq 'module options) => option-arg) + ((memq 'main-module options) "main") + (else #f)))) (define (cputime) (current-milliseconds)) @@ -567,11 +570,11 @@ ;; Canonicalize s-expressions (let* ((exps0 (map canonicalize-expression (let ((forms (append initforms forms))) - (if wrap-module - `((##core#module main () - (import scheme chicken) - ,@forms)) - forms)))) + (if (not module-name) + forms + `((##core#module + ,(string->symbol module-name) () + ,@forms)))))) (exps (append (map (lambda (ic) `(set! ,(cdr ic) ',(car ic))) immutable-constants) (map (lambda (n) `(##core#callunit ,n)) used-units) diff --git a/c-platform.scm b/c-platform.scm index 7ba952b..4089dc7 100644 --- a/c-platform.scm +++ b/c-platform.scm @@ -95,10 +95,9 @@ compile-syntax tag-pointers accumulate-profile disable-stack-overflow-checks raw specialize emit-external-prototypes-first release local inline-global - analyze-only dynamic - scrutinize ; OBSOLETE + analyze-only dynamic main-module no-argc-checks no-procedure-checks no-parentheses-synonyms - no-procedure-checks-for-toplevel-bindings module + no-procedure-checks-for-toplevel-bindings no-bound-checks no-procedure-checks-for-usual-bindings no-compiler-syntax no-parentheses-synonyms no-symbol-escape r5rs-syntax emit-all-import-libraries strict-types clustering lfa2 @@ -106,8 +105,8 @@ (define valid-compiler-options-with-argument '(debug - output-file include-path heap-size stack-size unit uses keyword-style require-extension - inline-limit profile-name + output-file include-path heap-size stack-size unit uses module + keyword-style require-extension inline-limit profile-name prelude postlude prologue epilogue nursery extend feature no-feature types emit-import-library emit-inline-file static-extension consult-inline-file emit-type-file diff --git a/chicken.scm b/chicken.scm index fac1817..b55c7c6 100644 --- a/chicken.scm +++ b/chicken.scm @@ -37,6 +37,7 @@ (import chicken.compiler.batch-driver chicken.compiler.c-platform + chicken.compiler.support chicken.data-structures chicken.utils) @@ -138,12 +139,12 @@ options) ) ) ) ) (loop (cdr rest)) ) ) ((eq? 'debug-level o) - (let ((level (string->number (car rest)))) - (case level - ((0) (set! options (cons* 'no-lambda-info 'no-trace options))) - ((1) (set! options (cons 'no-trace options))) - (else (set! options (cons 'scrutinize options)))) - (loop (cdr rest)) ) ) + (case (string->number (car rest)) + ((0) (set! options (cons* 'no-lambda-info 'no-trace options))) + ((1) (set! options (cons 'no-trace options))) + ((2)) ; default behaviour + (else (quit-compiling "invalid debug level: ~a" (car rest)))) + (loop (cdr rest))) ((memq o valid-compiler-options) (loop rest)) ((memq o valid-compiler-options-with-argument) (if (pair? rest) diff --git a/csc.scm b/csc.scm index 44c9f4d..243cfdc 100644 --- a/csc.scm +++ b/csc.scm @@ -147,12 +147,12 @@ -check-syntax -case-insensitive -shared -compile-syntax -no-lambda-info -dynamic -disable-stack-overflow-checks -local -emit-external-prototypes-first -inline -release - -scrutinize ; OBSOLETE + -main-module -analyze-only -keep-shadowed-macros -inline-global -ignore-repository -no-symbol-escape -no-parentheses-synonyms -r5rs-syntax -no-argc-checks -no-bound-checks -no-procedure-checks -no-compiler-syntax -emit-all-import-libraries -setup-mode -no-elevation -no-module-registration - -no-procedure-checks-for-usual-bindings -module + -no-procedure-checks-for-usual-bindings -specialize -strict-types -clustering -lfa2 -no-procedure-checks-for-toplevel-bindings)) @@ -164,13 +164,14 @@ -feature -debug-level -consult-inline-file -emit-import-library + -module -no-feature)) (define-constant shortcuts '((-h "-help") (-s "-shared") - (-S "-scrutinize") ; OBSOLETE - (-M "-module") + (-m "-module") + (-M "-main-module") (|-P| "-check-syntax") (-f "-fixnum-arithmetic") (|-D| "-feature") @@ -359,7 +360,8 @@ Usage: #{csc} FILENAME | OPTION ... -J -emit-all-import-libraries emit import-libraries for all defined modules -no-module-registration do not generate module registration code -no-compiler-syntax disable expansion of compiler-macros - -M -module wrap compiled code into implicit module + -m -module NAME wrap compiled code in a module + -M -main-module wrap compiled code in a module called "main" Translation options: diff --git a/manual/Unit utils b/manual/Unit utils index ea4f730..ccccd1a 100644 --- a/manual/Unit utils +++ b/manual/Unit utils @@ -79,7 +79,7 @@ Notes: A parameter that holds a list of default options that should be given to {{csc}} after invocation of the {{compile-file}} procedure. -The initial default options are {{-scrutinize -O2 -d2}}. +The initial default options are {{-O2 -d2}}. === Scanning through an input port diff --git a/manual/Using the compiler b/manual/Using the compiler index a770e2f..e57ffca 100644 --- a/manual/Using the compiler +++ b/manual/Using the compiler @@ -40,7 +40,7 @@ the source text should be read from standard input. -debug-level 0 is equivalent to -no-trace -no-lambda-info -debug-level 1 is equivalent to -no-trace - -debug-level 2 is equivalent to -scrutinize + -debug-level 2 is the default behaviour ; -disable-interrupts : Equivalent to the {{(disable-interrupts)}} declaration. No interrupt-checks are generated for compiled programs. @@ -90,7 +90,9 @@ the source text should be read from standard input. ; -lfa2 : Does an additional lightweight flow-analysis pass on the fully optimized program to remove more type checks. -; -module : wraps the compiled code in an implicit module named {{main}}, importing the {{scheme}} and {{chicken}} modules. +; -main-module : wraps the compiled code in an implicit module named {{main}}, importing the {{scheme}} and {{chicken}} modules. + +; -module NAME : wraps the compiled code in an implicit module of the given {{NAME}}, importing the {{scheme}} and {{chicken}} modules. ; -no-argc-checks : disable argument count checks diff --git a/rules.make b/rules.make index 7130f34..5d36a53 100644 --- a/rules.make +++ b/rules.make @@ -514,6 +514,7 @@ chicken.posix.import.scm: $(POSIXFILE).c 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.data-structures.import.scm \ chicken.utils.import.scm batch-driver.c: batch-driver.scm mini-srfi-1.scm \ diff --git a/scripts/compile-all b/scripts/compile-all index c17d48b..000c181 100755 --- a/scripts/compile-all +++ b/scripts/compile-all @@ -5,9 +5,9 @@ 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 -specialize" +compiler_options="-optimize-level 2 -include-path . -include-path ./ -inline -ignore-repository -feature chicken-bootstrap -feature debugbuild -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" +library_options="-optimize-level 2 -include-path . -include-path ./ -inline -ignore-repository -feature chicken-bootstrap -feature debugbuild -types ./types.db -verbose -explicit-use -no-trace -specialize" compiler="$1" shift diff --git a/support.scm b/support.scm index fcff0e1..b01a705 100644 --- a/support.scm +++ b/support.scm @@ -1653,7 +1653,9 @@ Usage: chicken FILENAME OPTION ... -emit-all-import-libraries emit import-libraries for all defined modules -no-module-registration do not generate module registration code -no-compiler-syntax disable expansion of compiler-macros - -module wrap compiled code into implicit module + -main-module wrap compiled code into implicit module + -module NAME wrap compiled code in a module + -main-module wrap compiled code in a module called "main" Translation options: diff --git a/tests/runtests.bat b/tests/runtests.bat index f44330b..0f5a7fd 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -54,7 +54,7 @@ echo ======================================== scrutiny tests ... if errorlevel 1 exit /b 1 a.out if errorlevel 1 exit /b 1 -%compile% scrutiny-tests.scm -A -scrutinize -verbose 2>scrutiny.out +%compile% scrutiny-tests.scm -A -verbose 2>scrutiny.out if errorlevel 1 exit /b 1 rem this is sensitive to gensym-names, so make it optional @@ -63,7 +63,7 @@ if not exist scrutiny.expected copy /Y scrutiny.out scrutiny.expected fc /w scrutiny.expected scrutiny.out if errorlevel 1 exit /b 1 -%compile% scrutiny-tests-2.scm -A -scrutinize -analyze-only -verbose 2>scrutiny-2.out +%compile% scrutiny-tests-2.scm -A -verbose 2>scrutiny-2.out if errorlevel 1 exit /b 1 if not exist scrutiny-2.expected copy /Y scrutiny-2.out scrutiny-2.expected @@ -331,6 +331,18 @@ if errorlevel 1 exit /b 1 %interpret% -include-path %TEST_DIR%/.. -s module-tests-2.scm if errorlevel 1 exit /b 1 +echo ======================================== module tests (command line options) ... +set module="test" +%compile% test.scm -w -A -j %module% -module %module% +if errorlevel 1 exit /b 1 +%compile% test.scm -w -A -j main -main-module +if errorlevel 1 exit /b 1 +%interpret% -e "(import %module%)" +if errorlevel 1 exit /b 1 +%interpret% -e "(import main)" +if errorlevel 1 exit /b 1 +del /f /q %module%.import.scm main.import.scm + echo ======================================== module tests (compiled) ... %compile% module-tests-compiled.scm if errorlevel 1 exit /b 1 diff --git a/tests/runtests.sh b/tests/runtests.sh index e07bdf9..2148c96 100755 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -96,7 +96,7 @@ $CHICKEN_PROFILE TEST.profile echo "======================================== scrutiny tests ..." $compile typematch-tests.scm -specialize -w ./a.out -$compile scrutiny-tests.scm -A -scrutinize 2>scrutiny.out -verbose +$compile scrutiny-tests.scm -A 2>scrutiny.out -verbose # this is sensitive to gensym-names, so make it optional if test \! -f scrutiny.expected; then @@ -105,7 +105,7 @@ fi diff $DIFF_OPTS scrutiny.expected scrutiny.out -$compile scrutiny-tests-2.scm -A -scrutinize -analyze-only 2>scrutiny-2.out -verbose +$compile scrutiny-tests-2.scm -A 2>scrutiny-2.out -verbose # this is sensitive to gensym-names, so make it optional if test \! -f scrutiny-2.expected; then @@ -284,6 +284,14 @@ echo "======================================== module tests ..." $interpret -include-path ${TEST_DIR}/.. -s module-tests.scm $interpret -include-path ${TEST_DIR}/.. -s module-tests-2.scm +echo "======================================== module tests (command line options) ..." +module="test-$(date +%s)" +$compile test.scm -A -w -j "$module" -module "$module" +$compile test.scm -A -w -j main -main-module +$interpret -e "(import $module)" +$interpret -e "(import main)" +rm -f "$module.import.scm" main.import.scm + echo "======================================== module tests (compiled) ..." $compile module-tests-compiled.scm ./a.out -- 2.5.3