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)
|
2008-09-24 23:18:35 -04:00
|
|
|
(export print-greeting init-library-path host-info)
|
|
|
|
(import (except (ikarus) host-info))
|
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
|
|
|
|
|
|
|
(define (print-greeting)
|
2007-11-19 15:37:42 -05:00
|
|
|
(printf "Ikarus Scheme version ~a\n"
|
|
|
|
(if (zero? (string-length ikarus-revision))
|
|
|
|
ikarus-version
|
2008-07-19 01:21:57 -04:00
|
|
|
(format "~a+ (revision ~a, build ~a~a)"
|
2007-11-19 15:37:42 -05:00
|
|
|
ikarus-version
|
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))])
|
2008-07-19 01:21:57 -04:00
|
|
|
ds)
|
|
|
|
(if (= (fixnum-width) 30)
|
|
|
|
""
|
|
|
|
", 64-bit"))))
|
2008-01-21 01:01:28 -05:00
|
|
|
(display "Copyright (c) 2006-2008 Abdulaziz Ghuloum\n\n"))
|
2007-11-19 13:34:24 -05:00
|
|
|
|
|
|
|
(define (init-library-path)
|
|
|
|
(define (split 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 '())))
|
|
|
|
(library-path
|
|
|
|
(cons "."
|
|
|
|
(append
|
|
|
|
(split (getenv "IKARUS_LIBRARY_PATH"))
|
2007-12-27 15:16:08 -05:00
|
|
|
(list ikarus-lib-dir))))
|
|
|
|
(library-extensions
|
|
|
|
(append
|
|
|
|
(map (lambda (x) (string-append ".ikarus" x))
|
|
|
|
(library-extensions))
|
|
|
|
(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)
|
2007-05-09 07:35:31 -04:00
|
|
|
(import (ikarus)
|
2008-10-12 01:15:20 -04:00
|
|
|
(except (ikarus startup) host-info)
|
2007-05-09 07:35:31 -04:00
|
|
|
(only (ikarus load) load-r6rs-top-level))
|
2007-11-19 13:34:24 -05:00
|
|
|
(init-library-path)
|
2007-05-09 07:35:31 -04:00
|
|
|
(let-values ([(files script script-type args)
|
2007-04-28 20:54:02 -04:00
|
|
|
(let f ([args (command-line-arguments)])
|
|
|
|
(cond
|
2007-05-09 07:35:31 -04:00
|
|
|
[(null? args) (values '() #f #f '())]
|
2008-06-28 05:25:44 -04:00
|
|
|
[(string=? (car args) "-O2")
|
|
|
|
(optimize-level 2)
|
|
|
|
(f (cdr args))]
|
|
|
|
[(string=? (car args) "-O1")
|
|
|
|
(optimize-level 1)
|
|
|
|
(f (cdr args))]
|
|
|
|
[(string=? (car args) "-O0")
|
|
|
|
(optimize-level 0)
|
|
|
|
(f (cdr args))]
|
2007-04-28 20:54:02 -04:00
|
|
|
[(string=? (car args) "--")
|
2007-05-09 07:35:31 -04:00
|
|
|
(values '() #f #f (cdr args))]
|
2007-04-28 20:54:02 -04:00
|
|
|
[(string=? (car args) "--script")
|
|
|
|
(let ([d (cdr args)])
|
|
|
|
(cond
|
2007-05-09 07:35:31 -04:00
|
|
|
[(null? d)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'ikarus "--script requires a script name")]
|
2007-04-28 20:54:02 -04:00
|
|
|
[else
|
2007-05-09 07:35:31 -04:00
|
|
|
(values '() (car d) 'script (cdr d))]))]
|
|
|
|
[(string=? (car args) "--r6rs-script")
|
|
|
|
(let ([d (cdr args)])
|
|
|
|
(cond
|
|
|
|
[(null? d)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'ikarus "--r6rs-script requires a script name")]
|
2007-05-09 07:35:31 -04:00
|
|
|
[else
|
|
|
|
(values '() (car d) 'r6rs-script (cdr d))]))]
|
2008-02-18 21:58:11 -05:00
|
|
|
[(string=? (car args) "--compile-dependencies")
|
2008-02-18 20:28:54 -05:00
|
|
|
(let ([d (cdr args)])
|
|
|
|
(cond
|
|
|
|
[(null? d)
|
|
|
|
(die 'ikarus
|
2008-03-01 21:14:35 -05:00
|
|
|
"--compile-dependencies requires a script name")]
|
2008-02-18 20:28:54 -05:00
|
|
|
[else
|
2008-02-18 21:58:11 -05:00
|
|
|
(values '() (car d) 'compile (cdr d))]))]
|
2007-04-28 20:54:02 -04:00
|
|
|
[else
|
2007-05-09 07:35:31 -04:00
|
|
|
(let-values ([(f* script script-type a*) (f (cdr args))])
|
|
|
|
(values (cons (car args) f*) script script-type a*))]))])
|
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)))
|
2007-04-28 20:54:02 -04:00
|
|
|
(cond
|
2007-05-09 07:35:31 -04:00
|
|
|
[(eq? script-type 'r6rs-script)
|
2008-10-18 17:49:20 -04:00
|
|
|
(assert-null files "--r6rs-script")
|
2007-05-09 07:35:31 -04:00
|
|
|
(command-line-arguments (cons script args))
|
2008-02-18 20:28:54 -05:00
|
|
|
(load-r6rs-top-level script 'run)
|
|
|
|
(exit 0)]
|
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")
|
2008-02-18 20:28:54 -05:00
|
|
|
(command-line-arguments (cons script args))
|
|
|
|
(load-r6rs-top-level script 'compile)
|
2007-05-09 07:35:31 -04:00
|
|
|
(exit 0)]
|
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))
|
|
|
|
(for-each load files)
|
|
|
|
(load script)
|
|
|
|
(exit 0)]
|
|
|
|
[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))
|
2007-04-28 20:54:02 -04:00
|
|
|
(for-each load files)
|
|
|
|
(new-cafe)
|
|
|
|
(exit 0)])))
|