forked from alex-eg/sex
type a macro call by what it expands to
A receiver, a scrutinee or the start of a path was typed before the walk had expanded it, so (.len (the a)) had no type to dispatch on and (. (the p) x) read a pointer as a value.
This commit is contained in:
23
semen.scm
23
semen.scm
@@ -561,12 +561,7 @@
|
||||
;; expanded here rather than before the walk, so the macro body can
|
||||
;; ask `(type-of x)' about a local the walk has already passed
|
||||
((macro? form)
|
||||
(let ((expansion (parameterize
|
||||
((current-type-of
|
||||
(lambda (queried)
|
||||
(unresolve-closure-types
|
||||
(expression-type queried env)))))
|
||||
(macroexpand form (list)))))
|
||||
(let ((expansion (expand-call form env)))
|
||||
(if (and (pair? expansion) (null? (cdr expansion)))
|
||||
(walk-statement (car expansion) env)
|
||||
(cons walk-embed-result (walk-body expansion env)))))
|
||||
@@ -671,6 +666,14 @@
|
||||
(walk-parts form env))
|
||||
env)))))))))
|
||||
|
||||
;;; The forms a macro call stands for, with `(type-of x)' answered from
|
||||
;;; ENV
|
||||
(define (expand-call form env)
|
||||
(parameterize ((current-type-of
|
||||
(lambda (queried)
|
||||
(unresolve-closure-types (expression-type queried env)))))
|
||||
(macroexpand form (list))))
|
||||
|
||||
;;; `(var n _ (strlen s))' becomes `(var n size-t (strlen s))'.
|
||||
(define (resolve-wildcard form env)
|
||||
(if (and (>= (length form) 3) (wildcard-type? (third form)))
|
||||
@@ -1029,6 +1032,14 @@
|
||||
(let ((written (car parts)))
|
||||
(if (= 1 (length written)) (car written) written)))))
|
||||
((symbol? expr) (or (lookup-name env expr) (get-name-type expr)))
|
||||
;; the walk expands `(the a)' before it gets there, so its type is
|
||||
;; that of what it expands to:
|
||||
;;
|
||||
;; (.len (the a)) (match (the s) ...) (. (the a) x)
|
||||
((macro? expr)
|
||||
(let ((expansion (expand-call expr env)))
|
||||
(and (pair? expansion) (null? (cdr expansion))
|
||||
(expression-type (car expansion) env))))
|
||||
((not (and (list? expr) (pair? expr))) #f)
|
||||
;; a call of no arguments is still a call
|
||||
((< (length expr) 2)
|
||||
|
||||
Reference in New Issue
Block a user