diff --git a/semen.scm b/semen.scm index 43e1672..dc08160 100644 --- a/semen.scm +++ b/semen.scm @@ -485,25 +485,6 @@ (set! (hash-table-ref env :scopes) (list parameters)) env)) -;;; `(p (* struct point))' writes the type in one piece and -;;; `(p * struct point)' spreads it over the rest; both are -;;; `(* struct point)' -(define (named-arg-type param) - (if (null? (cddr param)) - (second param) - (cdr param))) - -;;; (fn sum ((a int) (b int)) int ...) -> (fn ((int) (int)) int), and -;;; (self * const v) is ((* const v)) just as (self (* const v)) is. -;;; Anything that names nothing -- a variadic tail -- goes through -;;; untouched. -(define (arglist-types arglist) - (map (lambda (param) - (if (named-arg? param) - (list (named-arg-type param)) - param)) - arglist)) - (define (fn-type-of fn-form) `(fn ,(arglist-types (sex-fn-arglist fn-form)) ,(sex-fn-return-type fn-form))) diff --git a/sex-modules.scm b/sex-modules.scm index 76bc34f..1752213 100644 --- a/sex-modules.scm +++ b/sex-modules.scm @@ -198,13 +198,7 @@ (if (list? fields) (map second (normalize-fields fields)) (list))) (define (signature-types args ret) - (cons ret (map arg-type (remove comment-form? args)))) - -;;; (f1 float) -> float, (n unsigned int) -> (unsigned int), (int) -> (int) -(define (arg-type arg) - (cond ((not (named-arg? arg)) arg) - ((null? (cddr arg)) (second arg)) - (else (cdr arg)))) + (cons ret (arglist-types (remove comment-form? args)))) ;;; Each name TYPE mentions, and whether it is behind a pointer: ;;; @@ -247,7 +241,7 @@ (filter-map (lambda (form) (and (pair? form) - (let* ((core (if (pub-form? form) (cdr form) form)) + (let* ((core (strip-pub form)) (name (and (pair? core) (pair? (cdr core)) (if (and (eq? (car core) 'define) (pair? (second core))) (car (second core)) diff --git a/tests/types.module.scm b/tests/types.module.scm index e2fb4bd..d905dff 100644 --- a/tests/types.module.scm +++ b/tests/types.module.scm @@ -42,6 +42,9 @@ type-head? named-arg? + named-arg-type + arglist-types + strip-pub array-bound? array-element-type) "../types.scm") diff --git a/types.module.scm b/types.module.scm index 95c350a..d4b98e1 100644 --- a/types.module.scm +++ b/types.module.scm @@ -42,6 +42,9 @@ type-head? named-arg? + named-arg-type + arglist-types + strip-pub array-bound? array-element-type) "types.scm") diff --git a/types.scm b/types.scm index 3d91404..2fa6098 100644 --- a/types.scm +++ b/types.scm @@ -390,6 +390,25 @@ (pair? (cdr arg)) ; 1 element args are always type (not (type-head? arg)))) +;;; `(p (* struct point))' writes the type in one piece and +;;; `(p * struct point)' spreads it over the rest; both are +;;; `(* struct point)' +(define (named-arg-type param) + (if (null? (cddr param)) + (second param) + (cdr param))) + +;;; (fn sum ((a int) (b int)) int ...) -> (fn ((int) (int)) int), and +;;; (self * const v) is ((* const v)) just as (self (* const v)) is. +;;; Anything that names nothing -- a variadic tail -- goes through +;;; untouched. +(define (arglist-types arglist) + (map (lambda (param) + (if (named-arg? param) + (list (named-arg-type param)) + param)) + arglist)) + ;;; The last element is a bound unless what precedes it is still ;;; waiting for a type name -- a `*', a qualifier, a tag's keyword. C ;;; spells a type with one name at most, so a name after a name, or