source: project/chicken/trunk/chicken.scm @ 15246

Last change on this file since 15246 was 15246, checked in by felix winkelmann, 12 years ago

-debug v; compile-file; all namespace decls in one file

File size: 4.6 KB
Line 
1;;;; chicken.scm - The CHICKEN Scheme compiler (loader/main-module)
2;
3; Copyright (c) 2000-2007, Felix L. Winkelmann
4; Copyright (c) 2008-2009, The Chicken Team
5; All rights reserved.
6;
7; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
8; conditions are met:
9;
10;   Redistributions of source code must retain the above copyright notice, this list of conditions and the following
11;     disclaimer.
12;   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
13;     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 promote
15;     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 EXPRESS
18; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25; POSSIBILITY OF SUCH DAMAGE.
26
27
28(declare
29  (uses chicken-syntax srfi-1 srfi-4 utils files support compiler optimizer scrutinizer driver 
30        platform backend srfi-69)
31  (compile-syntax) )                   
32
33
34(include "compiler-namespace")
35(include "tweaks")
36
37(eval-when (load) 
38  (include "chicken-ffi-syntax") )
39
40
41;;; Prefix argument list with default options:
42
43(define compiler-arguments
44  (append
45   (remove 
46    (lambda (x) (string=? x ""))
47    (string-split (or (get-environment-variable "CHICKEN_OPTIONS") "")))
48   (cdr (argv))))
49
50
51;;; Process command-line options:
52;
53; - remove runtime-options ("-:...")
54; - filter out source-filename
55; - convert options into symbols (without the initial hyphens)
56
57(define (process-command-line args)
58  (let loop ([args args] [options '()] [filename #f])
59    (if (null? args)
60        (values filename (reverse options))
61        (let* ([arg (car args)]
62               [len (string-length arg)]
63               [char0 (string-ref arg 0)] )
64          (if (and (char=? #\- char0) (> len 1))
65              (if (and (> len 1) (char=? #\: (string-ref arg 1)))
66                  (loop (cdr args) options filename)
67                  (loop (cdr args) (cons (string->symbol (substring arg 1 len)) options) filename) )
68              (if filename
69                  (loop (cdr args) (cons arg options) filename)
70                  (loop (cdr args) options arg) ) ) ) ) ) )
71
72
73;;; Run compiler with command-line options:
74
75(receive (filename options) ((or (user-options-pass) process-command-line) compiler-arguments)
76  (let loop ([os options])
77    (unless (null? os)
78      (let ([o (car os)]
79            [rest (cdr os)] )
80        (cond [(eq? 'optimize-level o)
81               (let ([level (string->number (car rest))])
82                 (case level
83                   [(0) #f]
84                   [(1)
85                    (set! options (cons 'optimize-leaf-routines options)) ]
86                   [(2)
87                    (set! options (cons 'optimize-leaf-routines options)) ] 
88                   [(3)
89                    (set! options
90                      (cons* 'optimize-leaf-routines 'local 'inline options) ) ]
91                   [(4)
92                    (set! options
93                      (cons* 'optimize-leaf-routines 'local 'inline 'unsafe options) ) ]
94                   [else (compiler-warning 'usage "invalid optimization level ~S - ignored" (car rest))] )
95                 (loop (cdr rest)) ) ]
96              [(eq? 'debug-level o)
97               (let ([level (string->number (car rest))])
98                 (case level
99                   [(0) (set! options (cons* 'no-lambda-info 'no-trace options))]
100                   [(1) (set! options (cons 'no-trace options))]
101                   [(2) #f]
102                   [else (compiler-warning 'usage "invalid debug level ~S - ignored" (car rest))] )
103                 (loop (cdr rest)) ) ]
104              [(eq? 'benchmark-mode o)
105               (set! options 
106                 (cons* 'fixnum-arithmetic 'disable-interrupts 'no-trace 'unsafe
107                        'optimize-leaf-routines 'block 'lambda-lift 'no-lambda-info
108                        'inline
109                        options) )
110               (loop rest) ]
111              [(memq o valid-compiler-options) (loop rest)]
112              [(memq o valid-compiler-options-with-argument)
113               (if (pair? rest)
114                   (loop (cdr rest))
115                   (quit "missing argument to `-~s' option" o) ) ]
116              [else
117               (compiler-warning 
118                'usage "invalid compiler option `~a' - ignored" 
119                (if (string? o) o (conc "-" o)) )
120               (loop rest) ] ) ) ) )
121  (apply compile-source-file filename options)
122  (exit) )
Note: See TracBrowser for help on using the repository browser.