2006-11-23 19:44:29 -05:00
|
|
|
|
2007-05-04 11:16:42 -04:00
|
|
|
(library (ikarus system parameters)
|
|
|
|
(export make-parameter)
|
|
|
|
(import (except (ikarus) make-parameter))
|
|
|
|
(define make-parameter
|
|
|
|
(case-lambda
|
|
|
|
[(x)
|
|
|
|
(case-lambda
|
|
|
|
[() x]
|
|
|
|
[(v) (set! x v)])]
|
|
|
|
[(x guard)
|
|
|
|
(unless (procedure? guard)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'make-parameter "not a procedure" guard))
|
2007-05-04 11:16:42 -04:00
|
|
|
(set! x (guard x))
|
|
|
|
(case-lambda
|
|
|
|
[() x]
|
|
|
|
[(v) (set! x (guard v))])])))
|
|
|
|
|
|
|
|
|
2007-05-04 11:25:04 -04:00
|
|
|
(library (ikarus system handlers)
|
2007-05-04 11:38:39 -04:00
|
|
|
(export
|
|
|
|
interrupt-handler $apply-nonprocedure-error-handler
|
|
|
|
$incorrect-args-error-handler $multiple-values-error $debug
|
|
|
|
$underflow-misaligned-error top-level-value-error car-error
|
|
|
|
cdr-error fxadd1-error fxsub1-error cadr-error fx+-type-error
|
|
|
|
fx+-types-error fx+-overflow-error $do-event)
|
|
|
|
(import (except (ikarus) interrupt-handler)
|
2007-05-06 20:15:49 -04:00
|
|
|
(only (ikarus system $interrupts) $interrupted? $unset-interrupted!))
|
2007-05-04 11:25:04 -04:00
|
|
|
|
|
|
|
(define interrupt-handler
|
|
|
|
(make-parameter
|
|
|
|
(lambda ()
|
2007-05-14 18:16:00 -04:00
|
|
|
(set-port-output-index! (console-output-port) 0)
|
2007-05-04 11:25:04 -04:00
|
|
|
(error #f "interrupted"))
|
|
|
|
(lambda (x)
|
|
|
|
(if (procedure? x)
|
|
|
|
x
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'interrupt-handler "not a procedure" x)))))
|
2007-05-04 11:25:04 -04:00
|
|
|
|
|
|
|
(define $apply-nonprocedure-error-handler
|
|
|
|
(lambda (x)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'apply "not a procedure" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define $incorrect-args-error-handler
|
|
|
|
(lambda (p n)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'apply "incorrect number of argument" n p)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define $multiple-values-error
|
|
|
|
(lambda args
|
|
|
|
(error 'apply
|
2007-10-25 14:32:26 -04:00
|
|
|
"incorrect number of values returned to single value context"
|
2007-05-04 11:38:39 -04:00
|
|
|
args)))
|
|
|
|
|
|
|
|
(define $debug
|
|
|
|
(lambda (x)
|
|
|
|
(foreign-call "ik_error" (cons "DEBUG" x))))
|
|
|
|
|
|
|
|
(define $underflow-misaligned-error
|
|
|
|
(lambda ()
|
|
|
|
(foreign-call "ik_error" "misaligned")))
|
|
|
|
|
|
|
|
(define top-level-value-error
|
|
|
|
(lambda (x)
|
|
|
|
(cond
|
|
|
|
[(symbol? x)
|
2007-05-06 18:21:13 -04:00
|
|
|
(if (symbol-bound? x)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'top-level-value-error "BUG: should not happen" x)
|
2007-10-25 02:19:53 -04:00
|
|
|
(error #f "unbound" (string->symbol (symbol->string x))))]
|
2007-05-04 11:38:39 -04:00
|
|
|
[else
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'top-level-value "not a symbol" x)])))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define car-error
|
|
|
|
(lambda (x)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'car "not a pair" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define cdr-error
|
|
|
|
(lambda (x)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'cdr "not a pair" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define fxadd1-error
|
|
|
|
(lambda (x)
|
|
|
|
(if (fixnum? x)
|
|
|
|
(error 'fxadd1 "overflow")
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'fxadd1 "not a fixnum" x))))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define fxsub1-error
|
|
|
|
(lambda (x)
|
|
|
|
(if (fixnum? x)
|
|
|
|
(error 'fxsub1 "underflow")
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'fxsub1 "not a fixnum" x))))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define cadr-error
|
|
|
|
(lambda (x)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'cadr "invalid list structure" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define fx+-type-error
|
|
|
|
(lambda (x)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'fx+ "not a fixnum" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define fx+-types-error
|
|
|
|
(lambda (x y)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'fx+ "not a fixnum"
|
2007-05-04 11:38:39 -04:00
|
|
|
(if (fixnum? x) y x))))
|
|
|
|
|
|
|
|
(define fx+-overflow-error
|
|
|
|
(lambda (x y)
|
|
|
|
(error 'fx+ "overflow")))
|
|
|
|
|
|
|
|
(define $do-event
|
|
|
|
(lambda ()
|
2007-09-09 23:08:26 -04:00
|
|
|
(when ($interrupted?)
|
|
|
|
($unset-interrupted!)
|
|
|
|
((interrupt-handler)))))
|
2007-05-04 11:25:04 -04:00
|
|
|
)
|