2007-10-25 16:27:34 -04:00
|
|
|
;;; Ikarus Scheme -- A compiler for R6RS Scheme.
|
2008-01-29 00:34:34 -05:00
|
|
|
;;; Copyright (C) 2006,2007,2008 Abdulaziz Ghuloum
|
2007-10-25 16:27:34 -04:00
|
|
|
;;;
|
|
|
|
;;; This program is free software: you can redistribute it and/or modify
|
|
|
|
;;; it under the terms of the GNU General Public License version 3 as
|
|
|
|
;;; published by the Free Software Foundation.
|
|
|
|
;;;
|
|
|
|
;;; This program is distributed in the hope that it will be useful, but
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
;;; General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2007-05-02 02:16:56 -04:00
|
|
|
|
|
|
|
|
2007-05-04 02:39:50 -04:00
|
|
|
;;; this is here to test that we can import things from other
|
|
|
|
;;; libraries within the compiler itself.
|
|
|
|
|
2007-11-19 13:34:24 -05:00
|
|
|
(library (ikarus startup)
|
RC files:
Summary:
By default, ikarus now executes the file $HOME/.ikarusrc (which
must be an R6RS script) (if it exists) before startup.
Details:
There is a default behavior for RC files which can be overriden by
command-line options.
Default RC files location:
1. If the command-line argument --no-rcfile is set, the set of RC
files is empty.
2. Otherwise, if there is at least one --rcfile <filename>
command-line argument, the specified files are used as the set
of RC files. (--rcfile and --no-rcfile are mutually exclusive)
3. Otherwise, if the environment variable IKARUS_RC_FILES is set,
the colon-separated list of files are used as the RC files.
4. Otherwise, if the file $HOME/.ikarusrc exists, only it is used.
5. Otherwise, the set is empty.
The startup sequence is now:
1. Setup the library path.
2. Execute all RC files.
3. Set command-line options (e.g., -O2, --debug, etc.).
4. Set command-line-arguments.
5. Proceed with normal operation (start repl, run an r6rs script,
compile dependencies, etc.).
2009-05-28 06:29:07 -04:00
|
|
|
(export print-greeting init-library-path host-info split-path)
|
2009-05-30 01:14:09 -04:00
|
|
|
(import (except (ikarus) host-info) (ikarus include))
|
2007-11-19 13:34:24 -05:00
|
|
|
(include "ikarus.config.ss")
|
2008-09-24 23:18:35 -04:00
|
|
|
|
|
|
|
(define (host-info) target)
|
2007-11-19 13:34:24 -05:00
|
|
|
|
RC files:
Summary:
By default, ikarus now executes the file $HOME/.ikarusrc (which
must be an R6RS script) (if it exists) before startup.
Details:
There is a default behavior for RC files which can be overriden by
command-line options.
Default RC files location:
1. If the command-line argument --no-rcfile is set, the set of RC
files is empty.
2. Otherwise, if there is at least one --rcfile <filename>
command-line argument, the specified files are used as the set
of RC files. (--rcfile and --no-rcfile are mutually exclusive)
3. Otherwise, if the environment variable IKARUS_RC_FILES is set,
the colon-separated list of files are used as the RC files.
4. Otherwise, if the file $HOME/.ikarusrc exists, only it is used.
5. Otherwise, the set is empty.
The startup sequence is now:
1. Setup the library path.
2. Execute all RC files.
3. Set command-line options (e.g., -O2, --debug, etc.).
4. Set command-line-arguments.
5. Proceed with normal operation (start repl, run an r6rs script,
compile dependencies, etc.).
2009-05-28 06:29:07 -04:00
|
|
|
(define (split-path s)
|
|
|
|
(define (nodata i s ls)
|
|
|
|
(cond
|
|
|
|
[(= i (string-length s)) ls]
|
|
|
|
[(char=? (string-ref s i) #\:) (nodata (+ i 1) s ls)]
|
|
|
|
[else (data (+ i 1) s ls (list (string-ref s i)))]))
|
|
|
|
(define (data i s ls ac)
|
|
|
|
(cond
|
|
|
|
[(= i (string-length s))
|
|
|
|
(cons (list->string (reverse ac)) ls)]
|
|
|
|
[(char=? (string-ref s i) #\:)
|
|
|
|
(nodata (+ i 1) s
|
|
|
|
(cons (list->string (reverse ac)) ls))]
|
|
|
|
[else (data (+ i 1) s ls (cons (string-ref s i) ac))]))
|
|
|
|
(reverse (nodata 0 s '())))
|
|
|
|
|
|
|
|
|
2007-11-19 13:34:24 -05:00
|
|
|
(define (print-greeting)
|
2009-01-09 03:40:55 -05:00
|
|
|
(printf "Ikarus Scheme version ~a~a~a~a\n"
|
|
|
|
ikarus-version
|
|
|
|
(if (zero? (string-length ikarus-revision)) "" "+")
|
|
|
|
(if (= (fixnum-width) 30)
|
|
|
|
""
|
|
|
|
", 64-bit")
|
|
|
|
(if (zero? (string-length ikarus-revision))
|
|
|
|
""
|
|
|
|
(format " (revision ~a, build ~a)"
|
2007-11-21 00:59:05 -05:00
|
|
|
(+ 1 (string->number ikarus-revision))
|
2007-11-19 15:37:42 -05:00
|
|
|
(let-syntax ([ds (lambda (x) (date-string))])
|
2009-01-09 03:40:55 -05:00
|
|
|
ds))))
|
2009-04-06 19:36:53 -04:00
|
|
|
(display "Copyright (c) 2006-2009 Abdulaziz Ghuloum\n\n"))
|
2007-11-19 13:34:24 -05:00
|
|
|
|
|
|
|
(define (init-library-path)
|
|
|
|
(library-path
|
2009-05-30 03:46:45 -04:00
|
|
|
(append
|
|
|
|
(cond
|
|
|
|
[(getenv "IKARUS_LIBRARY_PATH") => split-path]
|
|
|
|
[else '(".")])
|
|
|
|
(list ikarus-lib-dir)))
|
2008-10-22 21:15:12 -04:00
|
|
|
(let ([prefix
|
|
|
|
(lambda (ext ls)
|
|
|
|
(append (map (lambda (x) (string-append ext x)) ls) ls))])
|
|
|
|
(library-extensions
|
|
|
|
(prefix "/main"
|
|
|
|
(prefix ".ikarus"
|
|
|
|
(library-extensions)))))))
|
2007-05-02 02:16:56 -04:00
|
|
|
|
|
|
|
|
2006-12-06 21:05:19 -05:00
|
|
|
;;; Finally, we're ready to evaluate the files and enter the cafe.
|
2007-05-02 02:16:56 -04:00
|
|
|
|
2007-05-09 23:42:32 -04:00
|
|
|
(library (ikarus main)
|
2007-05-04 03:00:16 -04:00
|
|
|
(export)
|
2008-12-27 00:36:13 -05:00
|
|
|
(import (except (ikarus) load-r6rs-script)
|
2008-10-12 01:15:20 -04:00
|
|
|
(except (ikarus startup) host-info)
|
2009-05-17 19:08:02 -04:00
|
|
|
(only (ikarus.compiler) generate-debug-calls)
|
2009-05-21 04:47:24 -04:00
|
|
|
(only (ikarus.debugger) guarded-start)
|
2008-11-01 16:19:35 -04:00
|
|
|
(only (psyntax library-manager) current-library-expander)
|
|
|
|
(only (ikarus.reader.annotated) read-source-file)
|
2008-12-06 12:40:18 -05:00
|
|
|
(only (ikarus.symbol-table) initialize-symbol-table!)
|
2008-12-27 00:36:13 -05:00
|
|
|
(only (ikarus load) load-r6rs-script))
|
RC files:
Summary:
By default, ikarus now executes the file $HOME/.ikarusrc (which
must be an R6RS script) (if it exists) before startup.
Details:
There is a default behavior for RC files which can be overriden by
command-line options.
Default RC files location:
1. If the command-line argument --no-rcfile is set, the set of RC
files is empty.
2. Otherwise, if there is at least one --rcfile <filename>
command-line argument, the specified files are used as the set
of RC files. (--rcfile and --no-rcfile are mutually exclusive)
3. Otherwise, if the environment variable IKARUS_RC_FILES is set,
the colon-separated list of files are used as the RC files.
4. Otherwise, if the file $HOME/.ikarusrc exists, only it is used.
5. Otherwise, the set is empty.
The startup sequence is now:
1. Setup the library path.
2. Execute all RC files.
3. Set command-line options (e.g., -O2, --debug, etc.).
4. Set command-line-arguments.
5. Proceed with normal operation (start repl, run an r6rs script,
compile dependencies, etc.).
2009-05-28 06:29:07 -04:00
|
|
|
|
|
|
|
(define rcfiles #t) ;; #f for no rcfile, list for specific list
|
|
|
|
|
2009-06-01 18:12:07 -04:00
|
|
|
(define (parse-command-line-arguments)
|
|
|
|
(let f ([args (command-line-arguments)] [k void])
|
|
|
|
(define (invalid-rc-error)
|
|
|
|
(die 'ikarus "--no-rcfile is invalid with --rcfile"))
|
|
|
|
(cond
|
|
|
|
[(null? args) (values '() #f #f '() k)]
|
|
|
|
[(member (car args) '("-d" "--debug"))
|
|
|
|
(f (cdr args) (lambda () (k) (generate-debug-calls #t)))]
|
|
|
|
[(member (car args) '("-nd" "--no-debug"))
|
|
|
|
(f (cdr args) (lambda () (k) (generate-debug-calls #f)))]
|
|
|
|
[(string=? (car args) "-O2")
|
|
|
|
(f (cdr args) (lambda () (k) (optimize-level 2)))]
|
|
|
|
[(string=? (car args) "-O1")
|
|
|
|
(f (cdr args) (lambda () (k) (optimize-level 1)))]
|
|
|
|
[(string=? (car args) "-O0")
|
|
|
|
(f (cdr args) (lambda () (k) (optimize-level 0)))]
|
|
|
|
[(string=? (car args) "--no-rcfile")
|
|
|
|
(unless (boolean? rcfiles) (invalid-rc-error))
|
|
|
|
(set! rcfiles #f)
|
|
|
|
(f (cdr args) k)]
|
|
|
|
[(string=? (car args) "--rcfile")
|
|
|
|
(let ([d (cdr args)])
|
|
|
|
(when (null? d) (die 'ikarus "--rcfile requires a script name"))
|
|
|
|
(set! rcfiles
|
|
|
|
(cons (car d)
|
|
|
|
(case rcfiles
|
|
|
|
[(#t) '()]
|
|
|
|
[(#f) (invalid-rc-error)]
|
|
|
|
[else rcfiles])))
|
|
|
|
(f (cdr d) k))]
|
|
|
|
[(string=? (car args) "--")
|
|
|
|
(values '() #f #f (cdr args) k)]
|
|
|
|
[(string=? (car args) "--script")
|
|
|
|
(let ([d (cdr args)])
|
|
|
|
(cond
|
|
|
|
[(null? d) (die 'ikarus "--script requires a script name")]
|
|
|
|
[else (values '() (car d) 'script (cdr d) k)]))]
|
|
|
|
[(string=? (car args) "--r6rs-script")
|
|
|
|
(let ([d (cdr args)])
|
|
|
|
(cond
|
|
|
|
[(null? d) (die 'ikarus "--r6rs-script requires a script name")]
|
|
|
|
[else (values '() (car d) 'r6rs-script (cdr d) k)]))]
|
|
|
|
[(string=? (car args) "--r6rs-repl")
|
|
|
|
(let ([d (cdr args)])
|
|
|
|
(cond
|
|
|
|
[(null? d) (die 'ikarus "--r6rs-repl requires a script name")]
|
|
|
|
[else (values '() (car d) 'r6rs-repl (cdr d) k)]))]
|
|
|
|
[(string=? (car args) "--compile-dependencies")
|
|
|
|
(let ([d (cdr args)])
|
|
|
|
(cond
|
|
|
|
[(null? d)
|
|
|
|
(die 'ikarus "--compile-dependencies requires a script name")]
|
|
|
|
[else
|
|
|
|
(values '() (car d) 'compile (cdr d) k)]))]
|
|
|
|
[else
|
|
|
|
(let-values ([(f* script script-type a* k) (f (cdr args) k)])
|
|
|
|
(values (cons (car args) f*) script script-type a* k))])))
|
|
|
|
|
2008-12-06 12:40:18 -05:00
|
|
|
(initialize-symbol-table!)
|
2007-11-19 13:34:24 -05:00
|
|
|
(init-library-path)
|
RC files:
Summary:
By default, ikarus now executes the file $HOME/.ikarusrc (which
must be an R6RS script) (if it exists) before startup.
Details:
There is a default behavior for RC files which can be overriden by
command-line options.
Default RC files location:
1. If the command-line argument --no-rcfile is set, the set of RC
files is empty.
2. Otherwise, if there is at least one --rcfile <filename>
command-line argument, the specified files are used as the set
of RC files. (--rcfile and --no-rcfile are mutually exclusive)
3. Otherwise, if the environment variable IKARUS_RC_FILES is set,
the colon-separated list of files are used as the RC files.
4. Otherwise, if the file $HOME/.ikarusrc exists, only it is used.
5. Otherwise, the set is empty.
The startup sequence is now:
1. Setup the library path.
2. Execute all RC files.
3. Set command-line options (e.g., -O2, --debug, etc.).
4. Set command-line-arguments.
5. Proceed with normal operation (start repl, run an r6rs script,
compile dependencies, etc.).
2009-05-28 06:29:07 -04:00
|
|
|
(let-values ([(files script script-type args init-command-line-args)
|
2009-06-01 18:12:07 -04:00
|
|
|
(parse-command-line-arguments)])
|
RC files:
Summary:
By default, ikarus now executes the file $HOME/.ikarusrc (which
must be an R6RS script) (if it exists) before startup.
Details:
There is a default behavior for RC files which can be overriden by
command-line options.
Default RC files location:
1. If the command-line argument --no-rcfile is set, the set of RC
files is empty.
2. Otherwise, if there is at least one --rcfile <filename>
command-line argument, the specified files are used as the set
of RC files. (--rcfile and --no-rcfile are mutually exclusive)
3. Otherwise, if the environment variable IKARUS_RC_FILES is set,
the colon-separated list of files are used as the RC files.
4. Otherwise, if the file $HOME/.ikarusrc exists, only it is used.
5. Otherwise, the set is empty.
The startup sequence is now:
1. Setup the library path.
2. Execute all RC files.
3. Set command-line options (e.g., -O2, --debug, etc.).
4. Set command-line-arguments.
5. Proceed with normal operation (start repl, run an r6rs script,
compile dependencies, etc.).
2009-05-28 06:29:07 -04:00
|
|
|
|
2008-10-18 17:49:20 -04:00
|
|
|
(define (assert-null files who)
|
|
|
|
(unless (null? files)
|
|
|
|
(apply die 'ikarus
|
|
|
|
(format "load files not allowed for ~a" who)
|
|
|
|
files)))
|
2009-05-17 19:08:02 -04:00
|
|
|
|
|
|
|
(define (start proc)
|
|
|
|
(if (generate-debug-calls)
|
|
|
|
(guarded-start proc)
|
|
|
|
(proc)))
|
RC files:
Summary:
By default, ikarus now executes the file $HOME/.ikarusrc (which
must be an R6RS script) (if it exists) before startup.
Details:
There is a default behavior for RC files which can be overriden by
command-line options.
Default RC files location:
1. If the command-line argument --no-rcfile is set, the set of RC
files is empty.
2. Otherwise, if there is at least one --rcfile <filename>
command-line argument, the specified files are used as the set
of RC files. (--rcfile and --no-rcfile are mutually exclusive)
3. Otherwise, if the environment variable IKARUS_RC_FILES is set,
the colon-separated list of files are used as the RC files.
4. Otherwise, if the file $HOME/.ikarusrc exists, only it is used.
5. Otherwise, the set is empty.
The startup sequence is now:
1. Setup the library path.
2. Execute all RC files.
3. Set command-line options (e.g., -O2, --debug, etc.).
4. Set command-line-arguments.
5. Proceed with normal operation (start repl, run an r6rs script,
compile dependencies, etc.).
2009-05-28 06:29:07 -04:00
|
|
|
|
2009-05-17 19:08:02 -04:00
|
|
|
(define-syntax doit
|
|
|
|
(syntax-rules ()
|
|
|
|
[(_ e e* ...)
|
|
|
|
(start (lambda () e e* ...))]))
|
RC files:
Summary:
By default, ikarus now executes the file $HOME/.ikarusrc (which
must be an R6RS script) (if it exists) before startup.
Details:
There is a default behavior for RC files which can be overriden by
command-line options.
Default RC files location:
1. If the command-line argument --no-rcfile is set, the set of RC
files is empty.
2. Otherwise, if there is at least one --rcfile <filename>
command-line argument, the specified files are used as the set
of RC files. (--rcfile and --no-rcfile are mutually exclusive)
3. Otherwise, if the environment variable IKARUS_RC_FILES is set,
the colon-separated list of files are used as the RC files.
4. Otherwise, if the file $HOME/.ikarusrc exists, only it is used.
5. Otherwise, the set is empty.
The startup sequence is now:
1. Setup the library path.
2. Execute all RC files.
3. Set command-line options (e.g., -O2, --debug, etc.).
4. Set command-line-arguments.
5. Proceed with normal operation (start repl, run an r6rs script,
compile dependencies, etc.).
2009-05-28 06:29:07 -04:00
|
|
|
|
|
|
|
(define (default-rc-files)
|
|
|
|
(cond
|
|
|
|
[(getenv "IKARUS_RC_FILES") => split-path]
|
|
|
|
[(getenv "HOME") =>
|
|
|
|
(lambda (home)
|
|
|
|
(let ([f (string-append home "/.ikarusrc")])
|
|
|
|
(if (file-exists? f)
|
|
|
|
(list f)
|
|
|
|
'())))]
|
|
|
|
[else '()]))
|
|
|
|
|
|
|
|
(for-each
|
|
|
|
(lambda (filename)
|
|
|
|
(with-exception-handler
|
|
|
|
(lambda (con)
|
|
|
|
(raise-continuable
|
|
|
|
(condition
|
|
|
|
(make-who-condition 'ikarus)
|
|
|
|
(make-message-condition
|
|
|
|
(format "loading rc file ~a failed" filename))
|
|
|
|
con)))
|
|
|
|
(lambda ()
|
|
|
|
(load-r6rs-script filename #f #t))))
|
|
|
|
(case rcfiles
|
|
|
|
[(#t) (default-rc-files)]
|
|
|
|
[(#f) '()]
|
|
|
|
[else (reverse rcfiles)]))
|
|
|
|
|
|
|
|
(init-command-line-args)
|
|
|
|
|
2007-04-28 20:54:02 -04:00
|
|
|
(cond
|
2009-05-31 06:32:33 -04:00
|
|
|
[(memq script-type '(r6rs-script r6rs-repl))
|
|
|
|
(let ([f (lambda ()
|
|
|
|
(doit
|
|
|
|
(command-line-arguments (cons script args))
|
|
|
|
(for-each
|
|
|
|
(lambda (filename)
|
|
|
|
(for-each
|
|
|
|
(lambda (src)
|
|
|
|
((current-library-expander) src))
|
|
|
|
(read-source-file filename)))
|
|
|
|
files)
|
|
|
|
(load-r6rs-script script #f #t)))])
|
|
|
|
(cond
|
|
|
|
[(eq? script-type 'r6rs-script) (f)]
|
|
|
|
[else
|
|
|
|
(print-greeting)
|
|
|
|
(let ([env (f)])
|
|
|
|
(interaction-environment env)
|
|
|
|
(new-cafe
|
|
|
|
(lambda (x)
|
|
|
|
(doit (eval x env)))))]))]
|
2008-02-18 21:58:11 -05:00
|
|
|
[(eq? script-type 'compile)
|
2008-10-18 17:49:20 -04:00
|
|
|
(assert-null files "--compile-dependencies")
|
2009-05-17 19:08:02 -04:00
|
|
|
(doit
|
|
|
|
(command-line-arguments (cons script args))
|
|
|
|
(load-r6rs-script script #t #f))]
|
2007-08-26 21:24:22 -04:00
|
|
|
[(eq? script-type 'script) ; no greeting, no cafe
|
2007-04-28 20:54:02 -04:00
|
|
|
(command-line-arguments (cons script args))
|
2009-05-17 19:08:02 -04:00
|
|
|
(doit
|
|
|
|
(for-each load files)
|
|
|
|
(load script))]
|
2007-04-28 20:54:02 -04:00
|
|
|
[else
|
2007-05-04 02:39:50 -04:00
|
|
|
(print-greeting)
|
2007-11-03 20:12:31 -04:00
|
|
|
(command-line-arguments (cons "*interactive*" args))
|
2009-05-17 19:08:02 -04:00
|
|
|
(doit (for-each load files))
|
|
|
|
(new-cafe
|
|
|
|
(lambda (x)
|
|
|
|
(doit (eval x (interaction-environment)))))])
|
|
|
|
|
|
|
|
(exit 0)))
|