forked from coalton-lang/coalton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoplevel-declare.lisp
26 lines (24 loc) · 1023 Bytes
/
toplevel-declare.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(in-package #:coalton-impl)
(defun process-toplevel-declarations (decl-forms env)
"Parse all the type declaration forms in DECL-FORMS and create a
HASH-TABLE mapping from the names to the declared type"
(declare (type tc:environment env))
(let ((table (make-hash-table)))
(dolist (form decl-forms)
(multiple-value-bind (name declared-type)
(parse-declaration form env)
(setf (gethash name table) declared-type)))
table))
(defun parse-declaration (declaration env)
(declare (type tc:environment env))
(assert (and (eql (first declaration) 'coalton:declare)
(= 3 (length declaration)))
() "Malformed DECLARE form ~A" declaration)
(let* ((name (second declaration))
(type-expr (third declaration))
(declared-type (tc:parse-and-resolve-type env type-expr)))
(unless (equalp
(tc:kind-of declared-type)
tc:+kstar+)
(error 'tc:type-construction-error :type declared-type))
(values name declared-type)))