* entire system librarified
This commit is contained in:
parent
b772735658
commit
00326031d8
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -1,214 +1,33 @@
|
|||
|
||||
|
||||
(library (flush me top-level-and-module-init)
|
||||
(export)
|
||||
(import (scheme))
|
||||
|
||||
;;; this junk should all go away soon
|
||||
;;; this file is one big hack that initializes the whole system.
|
||||
|
||||
(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
|
||||
include parameterize trace untrace trace-lambda trace-define
|
||||
rec library
|
||||
time))
|
||||
|
||||
(define (public-primitives)
|
||||
'(
|
||||
null? pair? char? fixnum? bignum? 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
|
||||
string->list list->string uuid string-append substring string=?
|
||||
string<? string<=? string>? string>=? remprop putprop getprop
|
||||
property-list $$apply apply map for-each andmap ormap memq memv assq
|
||||
assv assoc eq? eqv? equal? reverse string->symbol symbol->string
|
||||
top-level-value set-top-level-value! top-level-bound?
|
||||
gensym gensym-count gensym-prefix print-gensym
|
||||
gensym->unique-string call-with-values values make-parameter
|
||||
dynamic-wind display write print-graph fasl-write printf fprintf format
|
||||
print-error read-token read comment-handler error warning exit call/cc
|
||||
error-handler eval current-eval compile alt-compile compile-file
|
||||
alt-compile-file
|
||||
new-cafe load system expand sc-expand current-expand expand-mode
|
||||
environment? interaction-environment identifier?
|
||||
free-identifier=? bound-identifier=? literal-identifier=?
|
||||
datum->syntax-object syntax-object->datum syntax-error
|
||||
syntax->list generate-temporaries record? record-set! record-ref
|
||||
record-length record-type-descriptor make-record-type
|
||||
record-printer record-name record-field-accessor
|
||||
record-field-mutator record-predicate record-constructor
|
||||
record-type-name record-type-symbol record-type-field-names
|
||||
hash-table? make-hash-table get-hash-table put-hash-table!
|
||||
assembler-output $make-environment
|
||||
command-line-arguments port? input-port? output-port?
|
||||
make-input-port make-output-port make-input/output-port
|
||||
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
|
||||
with-output-to-string
|
||||
get-output-string with-output-to-file call-with-output-file
|
||||
open-input-string
|
||||
with-input-from-file call-with-input-file date-string
|
||||
file-exists? delete-file + - add1 sub1 * / expt
|
||||
quotient+remainder quotient remainder modulo number? positive?
|
||||
negative? zero? number->string logand = < > <= >=
|
||||
last-pair
|
||||
make-guardian weak-cons collect
|
||||
interrupt-handler
|
||||
time-it
|
||||
posix-fork fork waitpid env environ
|
||||
pretty-print
|
||||
even? odd? member char-whitespace? char-alphabetic?
|
||||
char-downcase max min complex? real? rational?
|
||||
exact? inexact? integer?
|
||||
string->number exact->inexact
|
||||
flonum? flonum->string string->flonum
|
||||
sin cos atan sqrt
|
||||
chi-top-library
|
||||
compile-time-core-eval
|
||||
))
|
||||
|
||||
(define (system-primitives)
|
||||
'(
|
||||
$primitive-call/cc
|
||||
$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
|
||||
$fxremainder $fxmodulo $fxsll $fxsra $fxlognot $fxlogor
|
||||
$fxlogand $fxlogxor $fixnum->char $char->fixnum $char= $char<
|
||||
$char<= $char> $char>= $car $cdr $set-car! $set-cdr!
|
||||
$make-vector $vector-ref $vector-set! $vector-length
|
||||
$make-string $string-ref $string-set! $string-length $string
|
||||
$symbol-string $symbol-unique-string $symbol-value
|
||||
$set-symbol-string! $set-symbol-unique-string!
|
||||
$set-symbol-value! $set-symbol-function! $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
|
||||
$code-set! $code->closure list*->code* make-code code?
|
||||
set-code-reloc-vector! code-reloc-vector code-freevars
|
||||
code-size code-ref code-set! $frame->continuation $fp-at-base
|
||||
$current-frame $arg-list $seal-frame-and-call
|
||||
$make-call-with-values-procedure $make-values-procedure
|
||||
do-overflow $make-tcbucket $tcbucket-next $tcbucket-key
|
||||
$tcbucket-val $set-tcbucket-next! $set-tcbucket-val!
|
||||
$set-tcbucket-tconc!
|
||||
call/cf
|
||||
trace-symbol! untrace-symbol! make-traced-procedure
|
||||
fixnum->string
|
||||
$interrupted? $unset-interrupted! $do-event
|
||||
$fasl-read
|
||||
;;; TODO: must open-code
|
||||
$make-port/input $make-port/output $make-port/both
|
||||
$make-input-port $make-output-port $make-input/output-port
|
||||
$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!
|
||||
;;; better open-code
|
||||
$write-char $read-char $peek-char $unread-char
|
||||
;;; never open-code
|
||||
$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*
|
||||
;;;
|
||||
compile-core-expr-to-port
|
||||
compiler-giveup-tally
|
||||
))
|
||||
|
||||
;;; first, it defines all public primitives to their primref values.
|
||||
;;; (cross your fingers they're all defined in code)
|
||||
(for-each
|
||||
(lambda (x)
|
||||
($set-symbol-value! x (primitive-ref x)))
|
||||
(public-primitives))
|
||||
|
||||
;;; second, it hacks a |#system| module by defining all system and
|
||||
;;; public primitives to be (core-primitive . name) syntaxes.
|
||||
(let ()
|
||||
(define add-prim
|
||||
(lambda (x)
|
||||
(let ([g (gensym (symbol->string x))])
|
||||
(putprop x '|#system| g)
|
||||
(putprop g '*sc-expander* (cons 'core-primitive x)))))
|
||||
(for-each add-prim (public-primitives))
|
||||
(for-each add-prim (system-primitives)))
|
||||
|
||||
;;; third, all macros that are defined in the compiler |#system| are
|
||||
;;; added to the top-level, and those defined in the top-level are
|
||||
;;; added to the |#system|.
|
||||
(for-each
|
||||
(lambda (x)
|
||||
(cond
|
||||
[(getprop x '*sc-expander*) =>
|
||||
(lambda (p)
|
||||
(let ([g (gensym (symbol->string x))])
|
||||
(putprop x '|#system| g)
|
||||
(putprop g '*sc-expander* p)))]
|
||||
[(getprop x '|#system|) =>
|
||||
(lambda (g)
|
||||
(let ([p (getprop g '*sc-expander*)])
|
||||
(putprop x '*sc-expander* p)))]
|
||||
[else (error #f "~s is not a macro" x)]))
|
||||
(macros))
|
||||
|
||||
;;; Now we hack the read #system and scheme modules by forging
|
||||
;;; interfaces and putting property lists.
|
||||
(let ([gsys (gensym "#system")] [gsch (gensym "*scheme*")])
|
||||
(define (make-stx x)
|
||||
(vector 'syntax-object x
|
||||
(list '(top)
|
||||
(vector 'ribcage
|
||||
(vector x)
|
||||
(vector '(top))
|
||||
(vector (getprop x '|#system|))))))
|
||||
(define (make-module stx* name)
|
||||
(cons '$module (vector 'interface '(top) (list->vector stx*) name)))
|
||||
(putprop '|#system| '|#system| gsys)
|
||||
(putprop 'scheme '|#system| gsch)
|
||||
(putprop 'scheme '*scheme* gsch)
|
||||
(let* ([schls (append '(scheme) (public-primitives) (macros))]
|
||||
[sysls (append '(|#system|) (system-primitives) schls)])
|
||||
(let ([sysmod (make-module (map make-stx sysls) '|#system|)]
|
||||
[schmod (make-module (map make-stx schls) '*scheme*)])
|
||||
(for-each
|
||||
(lambda (x)
|
||||
(putprop x '*scheme* (getprop x '|#system|)))
|
||||
schls)
|
||||
(putprop gsch '*sc-expander* schmod)
|
||||
(putprop gsys '*sc-expander* sysmod)
|
||||
(putprop '|#system| '*sc-expander* sysmod)
|
||||
(putprop 'scheme '*sc-expander* schmod))))
|
||||
)
|
||||
|
||||
;;; Finally, we're ready to evaluate the files and enter the cafe.
|
||||
(library (ikarus interaction)
|
||||
(export)
|
||||
(import (scheme))
|
||||
|
||||
(define sc-expand
|
||||
(lambda (x)
|
||||
(if (and (pair? x) (equal? (car x) "noexpand"))
|
||||
(cadr x)
|
||||
(chi-top-library x))))
|
||||
|
||||
(primitive-set! 'expand-mode
|
||||
(make-parameter 'eval))
|
||||
|
||||
(primitive-set! 'current-expand
|
||||
(make-parameter sc-expand
|
||||
(lambda (f)
|
||||
(if (procedure? f)
|
||||
f
|
||||
(error 'current-expand "~s is not a procedure" f)))))
|
||||
|
||||
(primitive-set! 'expand
|
||||
(lambda (x)
|
||||
((current-expand) x)))
|
||||
|
||||
(let-values ([(files script args)
|
||||
(let f ([args (command-line-arguments)])
|
||||
(cond
|
||||
|
|
112
src/makefile.ss
112
src/makefile.ss
|
@ -13,7 +13,9 @@
|
|||
;;; 6.1: * added case-lambda, dropped lambda
|
||||
;;; 6.0: * basic compiler
|
||||
|
||||
|
||||
(library (ikarus makefile)
|
||||
(export)
|
||||
(import (scheme))
|
||||
|
||||
(define macros
|
||||
'(|#primitive| lambda case-lambda set! quote begin define if letrec
|
||||
|
@ -160,75 +162,6 @@
|
|||
))
|
||||
|
||||
|
||||
|
||||
(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)
|
||||
#'(quote ,(date-string))))
|
||||
(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? "" "")
|
||||
(error #f "SEVERELY OUT OF DATE!\n")
|
||||
(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.
|
||||
(load "libintelasm-6.9.ss") ; uses make-code, etc.
|
||||
(load "libfasl-6.7.ss") ; uses code? etc.
|
||||
(load "libcompile-8.1.ss") ; uses fasl-write
|
||||
)
|
||||
|
||||
|
||||
(whack-system-env #t)
|
||||
|
||||
(define scheme-library-files
|
||||
'(["libhandlers.ss" "libhandlers.fasl" p0 onepass]
|
||||
["libcontrol.ss" "libcontrol.fasl" p0 onepass]
|
||||
|
@ -247,8 +180,7 @@
|
|||
["libfasl.ss" "libfasl.fasl" p0 onepass]
|
||||
["libtrace.ss" "libtrace.fasl" p0 onepass]
|
||||
["libcompile.ss" "libcompile.fasl" p1 onepass]
|
||||
["psyntax-7.1.ss" "psyntax.fasl" p0 onepass]
|
||||
["syntax.ss" "syntax.fasl" p0 onepass]
|
||||
["syntax.ss" "syntax.fasl" p0 onepass]
|
||||
["libpp.ss" "libpp.fasl" p0 onepass]
|
||||
["libcafe.ss" "libcafe.fasl" p0 onepass]
|
||||
["libposix.ss" "libposix.fasl" p0 onepass]
|
||||
|
@ -256,7 +188,6 @@
|
|||
["libtoplevel.ss" "libtoplevel.fasl" p0 onepass]
|
||||
))
|
||||
|
||||
|
||||
(define (read-file ifile)
|
||||
(with-input-from-file ifile
|
||||
(lambda ()
|
||||
|
@ -266,9 +197,6 @@
|
|||
'()
|
||||
(cons x (f))))))))
|
||||
|
||||
(define (expand-file ifile)
|
||||
(map sc-expand (read-file ifile)))
|
||||
|
||||
|
||||
(define (join s ls)
|
||||
(cond
|
||||
|
@ -285,27 +213,6 @@
|
|||
(display s str)
|
||||
(f (car d) (cdr d))])))]))
|
||||
|
||||
(define (compile-all)
|
||||
(define (compile-library ifile ofile which-compile)
|
||||
(parameterize ([assembler-output #f]
|
||||
[expand-mode 'bootstrap]
|
||||
[interaction-environment system-env])
|
||||
(let ([proc
|
||||
(case which-compile
|
||||
[(onepass) compile-file]
|
||||
[(chaitin) alt-compile-file]
|
||||
[else (error 'compile-library "unknown compile ~s"
|
||||
which-compile)])])
|
||||
(printf "compiling ~a ... \n" ifile)
|
||||
(proc ifile ofile 'replace))))
|
||||
|
||||
(for-each
|
||||
(lambda (x)
|
||||
(compile-library (car x) (cadr x) (cadddr x)))
|
||||
scheme-library-files)
|
||||
(system
|
||||
(format "cat ~a > ikarus.boot"
|
||||
(join " " (map cadr scheme-library-files)))))
|
||||
|
||||
|
||||
;;; ;;; NEW ARCHITECTURE
|
||||
|
@ -340,24 +247,21 @@
|
|||
'()
|
||||
(cons x (f))))))))
|
||||
(define (expand-library ifile)
|
||||
(parameterize ([expand-mode 'bootstrap]
|
||||
[interaction-environment system-env])
|
||||
(expand (cons 'begin (slurp-file ifile)))))
|
||||
(map chi-top-library (slurp-file ifile)))
|
||||
(define (expand-all ls)
|
||||
(map (lambda (x) (expand-library (car x))) ls))
|
||||
(apply append (map (lambda (x) (expand-library (car x))) ls)))
|
||||
(printf "expanding ...\n")
|
||||
(let ([core* (expand-all scheme-library-files)])
|
||||
(printf "compiling ...\n")
|
||||
(let ([p (open-output-file "ikarus.boot" 'replace)])
|
||||
(for-each
|
||||
(lambda (x) (#%compile-core-expr-to-port x p))
|
||||
(lambda (x) (compile-core-expr-to-port x p))
|
||||
core*)
|
||||
(close-output-port p))))
|
||||
|
||||
;(compile-all)
|
||||
(new-compile-all)
|
||||
|
||||
(printf "Happy Happy Joy Joy\n")
|
||||
(exit)
|
||||
;(#%compiler-giveup-tally)
|
||||
)
|
||||
; vim:syntax=scheme
|
||||
|
|
|
@ -976,6 +976,7 @@
|
|||
[interrupt-handler interrupt-handler-label (core-prim . interrupt-handler)]
|
||||
[exit exit-label (core-prim . exit)]
|
||||
[compile compile-label (core-prim . compile)]
|
||||
[compile-core-expr-to-port compile-core-expr-to-port-label (core-prim . compile-core-expr-to-port)]
|
||||
[eval eval-label (core-prim . eval)]
|
||||
[load load-label (core-prim . load)]
|
||||
[expand-mode expand-mode-label (core-prim . expand-mode)]
|
||||
|
@ -1015,6 +1016,7 @@
|
|||
[syntax-error syntax-error-label (core-prim . syntax-error)]
|
||||
[generate-temporaries generate-temporaries-label (core-prim . x:generate-temporaries)]
|
||||
[free-identifier=? free-identifier=?-label (core-prim . x:free-identifier=?)]
|
||||
[chi-top-library chi-top-library-label (core-prim . chi-top-library)]
|
||||
;;; codes
|
||||
[$closure-code $closure-code-label (core-prim . $closure-code)]
|
||||
[$code? $code?-label (core-prim . $code?)]
|
||||
|
|
Loading…
Reference in New Issue