;;;; type-errors-basic.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 ;; Notes ;; ;; - The type error message is built so as to `look' like those of the ;; CHICKEN "core". Only with optional information. ;; Issues ;; ;; - Maybe "... not an integer" -> "... integer required" & ;; "... not a list" -> "... list required", ;; or "... not integer", ... (declare (bound-to-procedure ##sys#signal-hook ##sys#error-hook) ) (module type-errors-basic (;export ; (define-error-type error-argument-type) ; make-location-message make-bad-argument-message make-type-name-message make-tagged-kind-message ; make-error-type-message make-error-interval-message make-warning-type-message ; signal-bounds-error signal-type-error ; error-argument-type warning-argument-type ; error-bound-value error-defined-value ; error-minimum-argument-count error-argument-count) (import scheme) (import (chicken base)) (import (chicken type)) (import (only (chicken string) ->string)) (import (chicken foreign)) ;message api (: make-location-message (* --> string)) (: make-bad-argument-message (#!optional * --> string)) (: make-type-name-message (* --> string)) (: make-tagged-kind-message (* * --> string)) (: make-error-type-message (* #!optional * --> string)) (: make-error-interval-message (* * * * #!optional * --> string)) (: make-warning-type-message (* * * #!optional * --> string)) ;warn api (: warning-argument-type (* * * #!optional * -> noreturn)) ;abort api (: signal-bounds-error (* #!rest -> noreturn)) (: signal-type-error (* #!rest -> noreturn)) (: error-argument-type (* * * #!optional * -> noreturn)) (: error-bound-value (* * #!optional * -> noreturn)) (: error-defined-value (* * #!optional * -> noreturn)) (: error-minimum-argument-count (* fixnum fixnum -> noreturn)) (: error-argument-count (* fixnum fixnum -> noreturn)) ;; (define (->boolean x) (and x #t)) ;; Locale Specific API (cond-expand (else ;default `en' (include-relative "type-errors-en.incl") ) ) ;; (define (warning-argument-type loc obj typnam #!optional argnam) (warning (make-warning-type-message loc obj typnam argnam)) ) ; (define (signal-bounds-error loc . objs) (apply ##sys#signal-hook #:bounds-error loc objs) ) (define (signal-type-error loc . objs) (apply ##sys#signal-hook #:type-error loc objs) ) ; (define (error-argument-type loc obj typnam #!optional argnam) (signal-type-error loc (make-error-type-message typnam argnam) obj) ) ; (define (error-bound-value loc obj #!optional argnam) (error-argument-type loc "#" "bound-value" argnam) ) (define (error-defined-value loc obj #!optional argnam) (error-argument-type loc "#" "defined-value" argnam) ) ; ;nothing to adds to the error message, so builtin direct (define (error-minimum-argument-count loc argc minargc) (##sys#error-hook (foreign-value "C_BAD_MINIMUM_ARGUMENT_COUNT_ERROR" int) loc minargc argc #f) ) (define (error-argument-count loc argc maxargc) (##sys#error-hook (foreign-value "C_BAD_ARGUMENT_COUNT_ERROR" int) loc maxargc argc #f) ) ; ; : is "" ; : is ; -> ; (define (error- loc obj #!optional argnam) ; (error-argument-type loc obj argnam) ) (define-syntax define-error-type (er-macro-transformer (lambda (frm rnm cmp) (let ((_define (rnm 'define)) (_#!optional (rnm '#!optional)) (_error-argument-type (rnm 'error-argument-type)) ) (let* ((typ (cadr frm)) (typstr (symbol->string typ)) (typnam (if (null? (cddr frm)) typstr (caddr frm))) (nam (string->symbol (string-append "error-" typstr))) ) `(,_define (,nam loc obj ,_#!optional argnam) (,_error-argument-type loc obj ,typnam argnam) ) ) ) ) ) ) ) ;module type-errors-basic