;;;; 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", ... (module type-errors-basic (;export ; 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 make-arity-low-message make-arity-message ; signal-bounds-error signal-type-error signal-arity-error ; error-argument-type warning-argument-type ; error-bound-value error-defined-value ; error-minimum-argument-count error-argument-count ; define-error-type) (import scheme) (import (chicken base)) (import (chicken type)) (import (only (chicken string) ->string) (only (chicken format) format)) (define (->boolean x) (and x #t)) ;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)) (: make-arity-low-message (fixnum fixnum -> string)) (: make-arity-message (fixnum fixnum -> string)) (cond-expand (else ;default `en' (include-relative "type-errors-en.incl") ) ) ;; (define-syntax warning-argument-type (syntax-rules () ((warning-argument-type ?loc ?obj ?typnam) (warning-argument-type ?loc ?obj ?typnam #f) ) ((warning-argument-type ?loc ?obj ?typnam ?argnam) (warning (make-warning-type-message ?loc ?obj ?typnam ?argnam)) ) ) ) ; (define-syntax signal-bounds-error (syntax-rules () ((signal-bounds-error ?loc ?objs ...) (##sys#signal-hook #:bounds-error ?loc ?objs ...) ) ) ) (define-syntax signal-type-error (syntax-rules () ((signal-type-error ?loc ?objs ...) (##sys#signal-hook #:type-error ?loc ?objs ...) ) ) ) (define-syntax signal-arity-error (syntax-rules () ((signal-arity-error ?loc ?objs ...) (##sys#signal-hook #:arity-error ?loc ?objs ...) ) ) ) ; (define-syntax error-argument-type (syntax-rules () ((error-argument-type ?loc ?obj ?typnam) (error-argument-type ?loc ?obj ?typnam #f) ) ((error-argument-type ?loc ?obj ?typnam ?argnam) (signal-type-error ?loc (make-error-type-message ?typnam ?argnam) ?obj) ) ) ) ; (define-syntax error-bound-value (syntax-rules () ((error-bound-value ?loc ?obj) (error-bound-value ?loc ?obj #f) ) ((error-bound-value ?loc ?obj ?argnam) (error-argument-type ?loc "#" "bound-value" ?argnam) ) ) ) (define-syntax error-defined-value (syntax-rules () ((error-defined-value ?loc ?obj) (error-defined-value ?loc ?obj #f) ) ((error-defined-value ?loc ?obj ?argnam) (error-argument-type ?loc "#" "defined-value" ?argnam) ) ) ) ; ;nothing to add to the error message, so builtin direct (define-syntax error-argument-count (syntax-rules () ((error-argument-count ?loc ?argc ?maxargc) (signal-arity-error ?loc (make-arity-message ?argc ?maxargc)) ) ) ) (define-syntax error-minimum-argument-count (syntax-rules () ((error-minimum-argument-count ?loc ?argc ?minargc) (signal-arity-error ?loc (make-arity-low-message ?argc ?minargc)) ) ) ) ; ; : is "" ; : is ; (actually weaker preconditions than the above) ; -> ; (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)) #; ;FIXME apply for known, single, optional arg - #!optional needs rnm? (_#!optional (rnm '#!optional)) (_loc (rnm 'loc)) (_obj (rnm 'obj)) (_argnam (rnm 'argnam)) (_error-argument-type (rnm 'error-argument-type)) ) (let* ((*typ (strip-syntax (cadr frm))) (typnam (if (null? (cddr frm)) *typ (caddr frm))) (nam (symbol-append 'error- *typ)) ) `(,_define (,nam ,_loc ,_obj #!optional ,_argnam) (,_error-argument-type ,_loc ,_obj ',typnam ,_argnam) ) ) ) ) ) ) ) ;module type-errors-basic