;;;; type-errors-basic.impl.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 ;;;; Kon Lovett, Apr '09 ;; 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", ... ;; 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) ) ) ) ) ) )