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-04 11:16:42 -04:00
|
|
|
(library (ikarus system parameters)
|
|
|
|
(export make-parameter)
|
|
|
|
(import (except (ikarus) make-parameter))
|
|
|
|
(define make-parameter
|
2008-06-19 04:58:59 -04:00
|
|
|
(let ()
|
|
|
|
(import (ikarus))
|
|
|
|
(case-lambda
|
|
|
|
[(x guard) (make-parameter x guard)]
|
|
|
|
[(x) (make-parameter x)]))))
|
2007-05-04 11:16:42 -04:00
|
|
|
|
2008-12-05 01:48:49 -05:00
|
|
|
(library (ikarus.pointer-value)
|
|
|
|
(export pointer-value)
|
|
|
|
(import (only (ikarus) define import))
|
|
|
|
(define (pointer-value x)
|
|
|
|
(import (ikarus))
|
|
|
|
(pointer-value x)))
|
|
|
|
|
|
|
|
|
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
|
2008-04-29 00:10:49 -04:00
|
|
|
fx+-types-error fx+-overflow-error $do-event engine-handler)
|
|
|
|
(import (except (ikarus) interrupt-handler engine-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-12-10 07:28:03 -05:00
|
|
|
; FIXME
|
|
|
|
;(set-port-output-index! (console-output-port) 0)
|
2007-11-15 13:40:36 -05:00
|
|
|
(raise-continuable
|
|
|
|
(condition
|
|
|
|
(make-interrupted-condition)
|
|
|
|
(make-message-condition "received an interrupt signal"))))
|
2007-05-04 11:25:04 -04:00
|
|
|
(lambda (x)
|
|
|
|
(if (procedure? x)
|
|
|
|
x
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'interrupt-handler "not a procedure" x)))))
|
2007-05-04 11:25:04 -04:00
|
|
|
|
2008-04-29 00:10:49 -04:00
|
|
|
(define engine-handler
|
|
|
|
(make-parameter
|
|
|
|
void
|
|
|
|
(lambda (x)
|
|
|
|
(if (procedure? x)
|
|
|
|
x
|
|
|
|
(die 'engine-handler "not a procedure" x)))))
|
|
|
|
|
2007-05-04 11:25:04 -04:00
|
|
|
(define $apply-nonprocedure-error-handler
|
|
|
|
(lambda (x)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'apply "not a procedure" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define $incorrect-args-error-handler
|
2008-03-25 22:15:10 -04:00
|
|
|
(lambda (p . ls)
|
|
|
|
(apply die 'apply "incorrect number of arguments" p ls)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define $multiple-values-error
|
|
|
|
(lambda args
|
2007-12-15 08:22:49 -05:00
|
|
|
(die '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-12-15 08:22:49 -05:00
|
|
|
(die 'top-level-value-error "BUG: should not happen" x)
|
|
|
|
(die #f "unbound" (string->symbol (symbol->string x))))]
|
2007-05-04 11:38:39 -04:00
|
|
|
[else
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'top-level-value "not a symbol" x)])))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define car-error
|
|
|
|
(lambda (x)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'car "not a pair" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define cdr-error
|
|
|
|
(lambda (x)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'cdr "not a pair" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define fxadd1-error
|
|
|
|
(lambda (x)
|
|
|
|
(if (fixnum? x)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'fxadd1 "overflow")
|
|
|
|
(die 'fxadd1 "not a fixnum" x))))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define fxsub1-error
|
|
|
|
(lambda (x)
|
|
|
|
(if (fixnum? x)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'fxsub1 "underflow")
|
|
|
|
(die 'fxsub1 "not a fixnum" x))))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define cadr-error
|
|
|
|
(lambda (x)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'cadr "invalid list structure" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define fx+-type-error
|
|
|
|
(lambda (x)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'fx+ "not a fixnum" x)))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define fx+-types-error
|
|
|
|
(lambda (x y)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'fx+ "not a fixnum"
|
2007-05-04 11:38:39 -04:00
|
|
|
(if (fixnum? x) y x))))
|
|
|
|
|
|
|
|
(define fx+-overflow-error
|
|
|
|
(lambda (x y)
|
2007-12-15 08:22:49 -05:00
|
|
|
(die 'fx+ "overflow")))
|
2007-05-04 11:38:39 -04:00
|
|
|
|
|
|
|
(define $do-event
|
|
|
|
(lambda ()
|
2008-04-29 00:10:49 -04:00
|
|
|
(cond
|
|
|
|
[($interrupted?)
|
|
|
|
($unset-interrupted!)
|
|
|
|
((interrupt-handler))]
|
|
|
|
[else
|
|
|
|
((engine-handler))])))
|
|
|
|
|
2007-05-04 11:25:04 -04:00
|
|
|
)
|