2006-12-04 09:54:28 -05:00
|
|
|
#!/Users/aghuloum/.opt/bin/ikarus --script
|
2006-11-23 19:44:29 -05:00
|
|
|
|
2006-11-23 19:48:14 -05:00
|
|
|
;;; 9.1: * starting with libnumerics
|
|
|
|
;;; 9.0: * graph marks for both reader and writer
|
|
|
|
;;; * circularity detection during read
|
|
|
|
;;; 8.1: * using chez-style io ports
|
2006-11-23 19:44:29 -05:00
|
|
|
;;; 6.9: * creating a *system* environment
|
|
|
|
;;; 6.8: * creating a core-primitive form in the expander
|
|
|
|
;;; 6.2: * side-effects now modify the dirty-vector
|
|
|
|
;;; * added bwp-object?
|
|
|
|
;;; * added pointer-value
|
|
|
|
;;; * added tcbuckets
|
|
|
|
;;; 6.1: * added case-lambda, dropped lambda
|
|
|
|
;;; 6.0: * basic compiler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define macros
|
|
|
|
'(|#primitive| lambda case-lambda set! quote begin define if letrec
|
|
|
|
foreign-call $apply
|
|
|
|
quasiquote unquote unquote-splicing
|
|
|
|
define-syntax identifier-syntax let-syntax letrec-syntax
|
|
|
|
fluid-let-syntax alias meta eval-when with-implicit with-syntax
|
|
|
|
type-descriptor
|
|
|
|
syntax-case syntax-rules module $module import $import import-only
|
|
|
|
syntax quasisyntax unsyntax unsyntax-splicing datum
|
|
|
|
let let* let-values cond case define-record or and when unless do
|
2006-12-05 13:28:23 -05:00
|
|
|
include parameterize trace untrace trace-lambda trace-define))
|
2006-11-23 19:44:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define public-primitives
|
2006-12-05 19:18:36 -05:00
|
|
|
'(
|
|
|
|
|
|
|
|
null? pair? char? fixnum? symbol? gensym? string? vector? list?
|
|
|
|
boolean? procedure? not eof-object eof-object? bwp-object?
|
|
|
|
void fx= fx< fx<= fx> fx>= fxzero? fx+ fx- fx* fxadd1 fxsub1
|
|
|
|
fxquotient fxremainder fxmodulo fxsll fxsra fxlognot fxlogor
|
|
|
|
fxlogand fxlogxor integer->char char->integer char=? char<?
|
|
|
|
char<=? char>? char>=? cons car cdr set-car! set-cdr! caar
|
|
|
|
cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr
|
|
|
|
caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr cdaaar
|
|
|
|
cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr list list*
|
|
|
|
make-list length list-ref append make-vector vector-ref
|
|
|
|
vector-set! vector-length vector vector->list list->vector
|
|
|
|
make-string string-ref string-set! string-length string
|
2006-12-06 18:26:37 -05:00
|
|
|
string->list list->string uuid string-append substring string=?
|
|
|
|
string<? string<=? string>? string>=? remprop putprop getprop
|
2006-12-05 19:18:36 -05:00
|
|
|
property-list apply map for-each andmap ormap memq memv assq
|
2006-12-05 19:21:58 -05:00
|
|
|
assv assoc eq? eqv? equal? reverse string->symbol symbol->string
|
|
|
|
oblist top-level-value set-top-level-value! top-level-bound?
|
|
|
|
gensym gensym-count gensym-prefix print-gensym
|
2006-12-05 19:18:36 -05:00
|
|
|
gensym->unique-string call-with-values values make-parameter
|
|
|
|
dynamic-wind display write print-graph fasl-write printf format
|
|
|
|
print-error read-token read comment-handler error exit call/cc
|
|
|
|
error-handler eval current-eval interpret compile compile-file
|
|
|
|
new-cafe load system expand sc-expand current-expand expand-mode
|
|
|
|
environment? interaction-environment identifier?
|
|
|
|
free-identifier=? bound-identifier=? literal-identifier=?
|
2006-11-23 19:44:29 -05:00
|
|
|
datum->syntax-object syntax-object->datum syntax-error
|
2006-12-05 19:18:36 -05:00
|
|
|
syntax->list generate-temporaries record? record-set! record-ref
|
|
|
|
record-length record-type-descriptor make-record-type
|
2006-11-23 19:44:29 -05:00
|
|
|
record-printer record-name record-field-accessor
|
|
|
|
record-field-mutator record-predicate record-constructor
|
2006-12-05 19:18:36 -05:00
|
|
|
record-type-name record-type-symbol record-type-field-names
|
2006-11-23 19:44:29 -05:00
|
|
|
hash-table? make-hash-table get-hash-table put-hash-table!
|
2006-12-05 19:18:36 -05:00
|
|
|
assembler-output $make-environment features
|
|
|
|
command-line-arguments port? input-port? output-port?
|
2006-11-23 19:48:14 -05:00
|
|
|
make-input-port make-output-port make-input/output-port
|
2006-12-05 19:18:36 -05:00
|
|
|
port-handler port-input-buffer port-input-index port-input-size
|
|
|
|
port-output-buffer port-output-index port-output-size
|
|
|
|
set-port-input-index! set-port-input-size!
|
|
|
|
set-port-output-index! set-port-output-size! port-name
|
|
|
|
input-port-name output-port-name write-char read-char
|
|
|
|
unread-char peek-char newline reset-input-port!
|
|
|
|
flush-output-port close-input-port close-output-port
|
|
|
|
console-input-port current-input-port standard-output-port
|
|
|
|
standard-error-port console-output-port current-output-port
|
|
|
|
open-output-file open-input-file open-output-string
|
|
|
|
get-output-string with-output-to-file call-with-output-file
|
|
|
|
with-input-from-file call-with-input-file date-string
|
2006-12-06 20:53:54 -05:00
|
|
|
file-exists? delete-file + - add1 sub1 * expt
|
|
|
|
quotient+remainder quotient remainder number? positive?
|
2006-12-05 19:18:36 -05:00
|
|
|
negative? zero? number->string logand = < > <= >=))
|
2006-11-23 19:44:29 -05:00
|
|
|
|
|
|
|
(define system-primitives
|
2006-12-02 05:02:05 -05:00
|
|
|
'(
|
2006-12-05 19:18:36 -05:00
|
|
|
|
|
|
|
$closure-code immediate? $unbound-object? $forward-ptr?
|
|
|
|
pointer-value primitive-ref primitive-set! $fx= $fx< $fx<= $fx>
|
|
|
|
$fx>= $fxzero? $fx+ $fx- $fx* $fxadd1 $fxsub1 $fxquotient
|
2006-12-02 05:02:05 -05:00
|
|
|
$fxremainder $fxmodulo $fxsll $fxsra $fxlognot $fxlogor
|
|
|
|
$fxlogand $fxlogxor $fixnum->char $char->fixnum $char= $char<
|
|
|
|
$char<= $char> $char>= $car $cdr $set-car! $set-cdr!
|
2006-11-23 19:44:29 -05:00
|
|
|
$make-vector $vector-ref $vector-set! $vector-length
|
2006-12-05 19:18:36 -05:00
|
|
|
$make-string $string-ref $string-set! $string-length $string
|
2006-11-23 19:44:29 -05:00
|
|
|
$symbol-string $symbol-unique-string $symbol-value
|
2006-12-02 05:02:05 -05:00
|
|
|
$set-symbol-string! $set-symbol-unique-string!
|
|
|
|
$set-symbol-value! $make-symbol $set-symbol-plist!
|
|
|
|
$symbol-plist $sc-put-cte $record? $record/rtd? $record-set!
|
|
|
|
$record-ref $record-rtd $make-record $record $base-rtd $code?
|
|
|
|
$code-reloc-vector $code-freevars $code-size $code-ref
|
2006-12-05 19:18:36 -05:00
|
|
|
$code-set! $code->closure list*->code* make-code code?
|
|
|
|
set-code-reloc-vector! code-reloc-vector code-freevars
|
2006-12-03 15:32:40 -05:00
|
|
|
code-size code-ref code-set! $frame->continuation $fp-at-base
|
2006-12-02 05:02:05 -05:00
|
|
|
$current-frame $arg-list $seal-frame-and-call
|
2006-11-23 19:44:29 -05:00
|
|
|
$make-call-with-values-procedure $make-values-procedure
|
2006-12-02 05:02:05 -05:00
|
|
|
do-overflow collect $make-tcbucket $tcbucket-next $tcbucket-key
|
2006-12-05 19:18:36 -05:00
|
|
|
$tcbucket-val $set-tcbucket-next! $set-tcbucket-val!
|
2006-12-02 05:02:05 -05:00
|
|
|
$set-tcbucket-tconc! $tcbucket-dlink-prev $tcbucket-dlink-next
|
|
|
|
$set-tcbucket-dlink-prev! $set-tcbucket-dlink-next! call/cf
|
2006-12-05 19:18:36 -05:00
|
|
|
trace-symbol! untrace-symbol! make-traced-procedure
|
2006-12-05 19:12:28 -05:00
|
|
|
fixnum->string
|
2006-12-02 05:02:05 -05:00
|
|
|
|
|
|
|
;;; TODO: must open-code
|
|
|
|
|
|
|
|
$make-port/input $make-port/output $make-port/both
|
2006-11-23 19:48:14 -05:00
|
|
|
$make-input-port $make-output-port $make-input/output-port
|
2006-12-02 05:02:05 -05:00
|
|
|
$port-handler $port-input-buffer $port-input-index
|
|
|
|
$port-input-size $port-output-buffer $port-output-index
|
|
|
|
$port-output-size $set-port-input-index! $set-port-input-size!
|
2006-11-23 19:48:14 -05:00
|
|
|
$set-port-output-index! $set-port-output-size!
|
2006-11-23 19:44:29 -05:00
|
|
|
|
2006-11-23 19:48:14 -05:00
|
|
|
;;; better open-code
|
2006-12-02 05:02:05 -05:00
|
|
|
|
2006-11-23 19:48:14 -05:00
|
|
|
$write-char $read-char $peek-char $unread-char
|
2006-11-23 19:44:29 -05:00
|
|
|
|
2006-11-23 19:48:14 -05:00
|
|
|
;;; never open-code
|
2006-12-02 05:02:05 -05:00
|
|
|
|
|
|
|
$reset-input-port! $close-input-port $close-output-port
|
|
|
|
$flush-output-port *standard-output-port* *standard-error-port*
|
|
|
|
*current-output-port* *standard-input-port* *current-input-port*
|
|
|
|
|
2006-12-05 22:29:00 -05:00
|
|
|
;;;
|
|
|
|
compiler-giveup-tally
|
2006-11-23 19:44:29 -05:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (whack-system-env setenv?)
|
|
|
|
(define add-prim
|
|
|
|
(lambda (x)
|
|
|
|
(let ([g (gensym (symbol->string x))])
|
|
|
|
(putprop x '|#system| g)
|
|
|
|
(putprop g '*sc-expander* (cons 'core-primitive x)))))
|
|
|
|
(define add-macro
|
|
|
|
(lambda (x)
|
|
|
|
(let ([g (gensym (symbol->string x))]
|
|
|
|
[e (getprop x '*sc-expander*)])
|
|
|
|
(when e
|
|
|
|
(putprop x '|#system| g)
|
|
|
|
(putprop g '*sc-expander* e)))))
|
|
|
|
(define (foo)
|
|
|
|
(eval
|
|
|
|
`(begin
|
|
|
|
(define-syntax compile-time-date-string
|
|
|
|
(lambda (x)
|
2006-11-23 19:48:14 -05:00
|
|
|
#'(quote ,(date-string))))
|
2006-11-23 19:44:29 -05:00
|
|
|
(define-syntax public-primitives
|
|
|
|
(lambda (x)
|
|
|
|
#'(quote ,public-primitives)))
|
|
|
|
(define-syntax system-primitives
|
|
|
|
(lambda (x)
|
|
|
|
#'(quote ,system-primitives)))
|
|
|
|
(define-syntax macros
|
|
|
|
(lambda (x)
|
|
|
|
#'(quote ,macros))))))
|
|
|
|
(set! system-env ($make-environment '|#system| #t))
|
|
|
|
(for-each add-macro macros)
|
|
|
|
(for-each add-prim public-primitives)
|
|
|
|
(for-each add-prim system-primitives)
|
|
|
|
(if setenv?
|
|
|
|
(parameterize ([interaction-environment system-env])
|
|
|
|
(foo))
|
|
|
|
(foo)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(when (eq? "" "")
|
2006-12-02 05:02:05 -05:00
|
|
|
(error #f "SEVERELY OUT OF DATE!\n")
|
2006-11-23 19:44:29 -05:00
|
|
|
(load "chez-compat.ss")
|
|
|
|
(set! primitive-ref top-level-value)
|
|
|
|
(set! primitive-set! set-top-level-value!)
|
|
|
|
(set! chez-expand sc-expand)
|
|
|
|
(set! chez-current-expand current-expand)
|
|
|
|
(printf "loading psyntax.pp ...\n")
|
|
|
|
(load "psyntax-7.1.pp")
|
|
|
|
(chez-current-expand
|
|
|
|
(lambda (x . args)
|
|
|
|
(apply chez-expand (sc-expand x) args)))
|
|
|
|
(whack-system-env #f)
|
|
|
|
(printf "loading psyntax.ss ...\n")
|
|
|
|
(load "psyntax-7.1-6.9.ss")
|
|
|
|
(chez-current-expand
|
|
|
|
(lambda (x . args)
|
|
|
|
(apply chez-expand (sc-expand x) args)))
|
|
|
|
(whack-system-env #t)
|
|
|
|
(printf "ok\n")
|
|
|
|
(load "libassembler-compat-6.7.ss") ; defines make-code etc.
|
2006-11-23 19:48:14 -05:00
|
|
|
(load "libintelasm-6.9.ss") ; uses make-code, etc.
|
2006-11-23 19:44:29 -05:00
|
|
|
(load "libfasl-6.7.ss") ; uses code? etc.
|
2006-11-23 19:48:14 -05:00
|
|
|
(load "libcompile-8.1.ss") ; uses fasl-write
|
2006-11-23 19:44:29 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
(whack-system-env #t)
|
|
|
|
|
|
|
|
(define scheme-library-files
|
2006-11-23 20:37:04 -05:00
|
|
|
'(["libhandlers.ss" #t "libhandlers.fasl"]
|
|
|
|
["libcontrol.ss" #t "libcontrol.fasl"]
|
|
|
|
["libcollect.ss" #t "libcollect.fasl"]
|
|
|
|
["librecord.ss" #t "librecord.fasl"]
|
|
|
|
["libcxr.ss" #t "libcxr.fasl"]
|
|
|
|
["libnumerics.ss" #t "libnumerics.fasl"]
|
|
|
|
["libcore.ss" #t "libcore.fasl"]
|
|
|
|
["libchezio.ss" #t "libchezio.fasl"]
|
|
|
|
["libhash.ss" #t "libhash.fasl"]
|
|
|
|
["libwriter.ss" #t "libwriter.fasl"]
|
|
|
|
["libtokenizer.ss" #t "libtokenizer.fasl"]
|
|
|
|
["libassembler.ss" #t "libassembler.fasl"]
|
|
|
|
["libintelasm.ss" #t "libintelasm.fasl"]
|
|
|
|
["libfasl.ss" #t "libfasl.fasl"]
|
|
|
|
["libcompile.ss" #t "libcompile.fasl"]
|
|
|
|
["psyntax-7.1.ss" #t "psyntax.fasl"]
|
|
|
|
["libinterpret.ss" #t "libinterpret.fasl"]
|
|
|
|
["libcafe.ss" #t "libcafe.fasl"]
|
|
|
|
["libtrace.ss" #t "libtrace.fasl"]
|
|
|
|
["libposix.ss" #t "libposix.fasl"]
|
|
|
|
["libtoplevel.ss" #t "libtoplevel.fasl"]
|
2006-11-23 19:44:29 -05:00
|
|
|
))
|
|
|
|
|
|
|
|
|
2006-12-06 21:20:15 -05:00
|
|
|
(define (expand-file ifile)
|
|
|
|
(with-input-from-file ifile
|
|
|
|
(lambda ()
|
|
|
|
(let f ()
|
|
|
|
(let ([x (read)])
|
|
|
|
(unless (eof-object? x)
|
|
|
|
(sc-expand x)
|
|
|
|
(f)))))))
|
2006-11-23 19:44:29 -05:00
|
|
|
|
|
|
|
(define (compile-library ifile ofile)
|
|
|
|
(parameterize ([assembler-output #f]
|
|
|
|
[expand-mode 'bootstrap]
|
|
|
|
[interaction-environment system-env])
|
2006-12-02 05:59:09 -05:00
|
|
|
(printf "compiling ~a ... " ifile)
|
|
|
|
(compile-file ifile ofile 'replace)
|
2006-12-06 21:20:15 -05:00
|
|
|
;(expand-file ifile)
|
2006-12-02 05:59:09 -05:00
|
|
|
(newline)))
|
2006-11-23 19:44:29 -05:00
|
|
|
|
|
|
|
(for-each
|
|
|
|
(lambda (x)
|
2006-11-23 19:48:14 -05:00
|
|
|
(when (cadr x)
|
|
|
|
(compile-library (car x) (caddr x))))
|
2006-11-23 19:44:29 -05:00
|
|
|
scheme-library-files)
|
|
|
|
|
|
|
|
(define (join s ls)
|
|
|
|
(cond
|
|
|
|
[(null? ls) ""]
|
|
|
|
[else
|
|
|
|
(let ([str (open-output-string)])
|
|
|
|
(let f ([a (car ls)] [d (cdr ls)])
|
|
|
|
(cond
|
|
|
|
[(null? d)
|
|
|
|
(display a str)
|
|
|
|
(get-output-string str)]
|
|
|
|
[else
|
|
|
|
(display a str)
|
|
|
|
(display s str)
|
|
|
|
(f (car d) (cdr d))])))]))
|
|
|
|
|
|
|
|
|
|
|
|
(system
|
2006-11-23 20:18:02 -05:00
|
|
|
(format "cat ~a > ikarus.boot"
|
2006-11-23 19:48:14 -05:00
|
|
|
(join " " (map caddr scheme-library-files))))
|
2006-12-02 05:02:05 -05:00
|
|
|
|
2006-12-07 01:38:04 -05:00
|
|
|
(#%compiler-giveup-tally)
|
2006-12-05 22:29:00 -05:00
|
|
|
|