~ chicken-core (master) /chicken.scm
Trap1;;;; chicken.scm - The CHICKEN Scheme compiler (loader/main-module)2;3; Copyright (c) 2008-2022, The CHICKEN Team4; Copyright (c) 2000-2007, Felix L. Winkelmann5; All rights reserved.6;7; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following8; conditions are met:9;10; Redistributions of source code must retain the above copyright notice, this list of conditions and the following11; disclaimer.12; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following13; disclaimer in the documentation and/or other materials provided with the distribution.14; Neither the name of the author nor the names of its contributors may be used to endorse or promote15; products derived from this software without specific prior written permission.16;17; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS18; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY19; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR20; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR21; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR22; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR24; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE25; POSSIBILITY OF SUCH DAMAGE.262728(declare29 (uses chicken-syntax chicken-ffi-syntax30 srfi-4 extras data-structures31 lolevel ; unused, but loaded to make foldable bindings available32 support compiler optimizer lfa2 compiler-syntax scrutinizer33 batch-driver c-platform c-backend user-pass))3435(module chicken.compiler.chicken ()3637(import scheme38 chicken.base39 chicken.compiler.batch-driver40 chicken.compiler.c-platform41 chicken.compiler.support42 chicken.compiler.user-pass43 chicken.fixnum44 chicken.process-context45 chicken.string)4647(include "tweaks")48(include "mini-srfi-1.scm")4950;;; Prefix argument list with default options:5152(define compiler-arguments53 (let ((args (cdr (argv))))54 (if (null? args)55 '()56 (append (take args 1) ; Leave source filename argument first.57 (string-split (or (get-environment-variable "CHICKEN_OPTIONS") ""))58 (drop args 1)))))596061;;; Process command-line options:62;63; - remove runtime-options ("-:...")64; - filter out source-filename65; - convert options into symbols (without the initial hyphens)6667(define (process-command-line args)68 (let loop ((args args) (options '()) (filename #f))69 (if (null? args)70 (values filename (reverse options))71 (let* ((arg (car args))72 (len (string-length arg))73 (char0 (string-ref arg 0)) )74 (if (and (char=? #\- char0) (> len 1))75 (if (and (> len 1) (char=? #\: (string-ref arg 1)))76 (loop (cdr args) options filename)77 (loop (cdr args) (cons (string->symbol (substring arg 1 len)) options) filename) )78 (if filename79 (loop (cdr args) (cons arg options) filename)80 (loop (cdr args) options arg) ) ) ) ) ) )818283;;; Run compiler with command-line options:8485(receive (filename options) ((or (user-options-pass) process-command-line) compiler-arguments)86 ;; TODO: Perhaps option parsing should be moved to batch-driver?87 (let loop ((os options))88 (unless (null? os)89 (let ((o (car os))90 (rest (cdr os)) )91 (cond ((eq? 'optimize-level o)92 (let ((level (string->number (car rest))))93 (case level94 ((0)95 (set! options96 (cons* 'no-compiler-syntax 'no-usual-integrations options)) )97 ((1)98 (set! options99 (cons* 'optimize-leaf-routines100 'merge-reusable-closures101 options)) )102 ((2)103 (set! options104 (cons* 'optimize-leaf-routines105 'inline106 'merge-reusable-closures107 'merge-shareable-closures108 'lfa2109 options)) )110 ((3)111 (set! options112 (cons* 'optimize-leaf-routines113 'inline114 'inline-global115 'local116 'merge-reusable-closures117 'merge-shareable-closures118 'lfa2119 'specialize120 options) ) )121 ((4)122 (set! options123 (cons* 'optimize-leaf-routines124 'inline125 'inline-global126 'specialize127 'merge-reusable-closures128 'merge-shareable-closures129 'lfa2130 'local131 'unsafe132 options) ) )133 (else134 (when (>= level 5)135 (set! options136 (cons* 'disable-interrupts137 'no-trace138 'unsafe139 'block140 'specialize141 'optimize-leaf-routines142 'no-lambda-info143 'inline144 'inline-global145 'lfa2146 'merge-reusable-closures147 'merge-shareable-closures148 options) ) ) ) )149 (loop (cdr rest)) ) )150 ((eq? 'debug-level o)151 (case (string->number (car rest))152 ((0) (set! options (cons* 'no-lambda-info 'no-trace options)))153 ((1) (set! options (cons 'no-trace options)))154 ((2)) ; default behaviour155 ((3) (set! options (cons 'debug-info options)))156 (else (quit-compiling "invalid debug level: ~a" (car rest))))157 (loop (cdr rest)))158 ((memq o valid-compiler-options) (loop rest))159 ((memq o valid-compiler-options-with-argument)160 (if (pair? rest)161 (loop (cdr rest))162 (quit-compiling "missing argument to `-~s' option" o) ) )163 (else164 (warning165 "invalid compiler option (ignored)"166 (if (string? o) o (conc "-" o)) )167 (loop rest) ) ) ) ) )168 (apply compile-source-file filename compiler-arguments options)169 (exit)))