(define impc:ti:pointer-ref-check
(lambda (ast vars kts request?)
;; (println 'pointer-ref-check: 'ast: ast 'request? request?) ;'vars: vars 'kts: kts)
(if (<> (length ast) 3)
(impc:compiler:print-bad-arity-error ast))
(if (or (impc:ir:type? request?) (atom? request?)) (set! request? (list request?)))
(let ((a (impc:ti:type-check (cadr ast) vars kts ;; '())) ;request?))
(map (lambda (k) (impc:ir:pointer++ k))
(cl:remove-if-not impc:ir:type? request?))))
;; b should be fixed point
(b (impc:ti:type-check (caddr ast) vars kts (list *impc:ir:si64* *impc:ir:si32*))))
(if (impc:ir:type? a) (set! a (list a)))
(if (and (not (null? a))
(< (impc:ir:get-ptr-depth (car a)) 1))
(impc:compiler:print-bad-type-error (impc:ir:pretty-print-type (car a))
"Cannot de-reference non-pointer type"))
(if (null? a)
a
(list (impc:ir:pointer-- (car a)))))))