constraints for struct constructor args

This commit is contained in:
Erik Svedäng 2016-03-03 23:02:36 +01:00
parent f0c0b260c6
commit c7fc058627
3 changed files with 13 additions and 6 deletions

View File

@ -1,5 +1,4 @@
# Compiler
- Add constraints for struct constructor arguments based on the types in the struct
- Can't have star in function name when baking
- Don't apply borrowing rules to primitive (auto-copyable) types like int/float/bool/char
- Compile struct member lookups properly
@ -24,6 +23,7 @@
- Avoid problems with name shadowing when freeing a local variable (is this possible? disallow shadowing instead?)
- deftype (tagged unions)
- Clean up the awful 'list-to-ast' function
- Complete type constraints for binops, check for "numeric" types
# Lisp Core Libs
- assert-eq shows wrong result when the assertion fails? (in ffi situations, the wrong type is produced and compared to something else)

View File

@ -59,10 +59,6 @@
:app (let [ret-constr {:a (get ast :type) :b (get-in ast '(:head :type 2)) :doc "ret-constr for :app"}
arg-constrs (map2 (fn (a b) {:a a :b b :doc "app-arg"}) (get-in ast '(:head :type 1)) (map :type (:tail ast)))
;; func-constrs (let [app-f-sym (get-in ast '(:head :value))
;; app-f-name (str app-f-sym)
;; app-f (eval app-f-sym)]
;; )
head-constrs (generate-constraints-internal '() (:head ast) type-env)
tail-constrs (reduce (fn (constrs tail-form) (generate-constraints-internal constrs tail-form type-env))
'() (:tail ast))
@ -91,7 +87,12 @@
:lookup (if (has-key? ast :self-recursive)
constraints
(if (has-key? ast :constructor)
constraints ;; TODO: what's the correct thing to do here?
(let [member-types (array-to-list (:member-types ast))
t (:type ast)
constructor-arg-constrs (map2 (fn [a b] {:a a :b b :doc "constructor-arg"})
member-types
(nth t 1))]
constructor-arg-constrs)
(let [val (:value ast)
;;_ (println (str "not self-recursive: \n" ast))
t (get-type-of-symbol type-env val)

View File

@ -117,3 +117,9 @@
(defn trixy-5 []
(println (ref (str (ref (color 2.3))))))
(defn trixy-6 [x y z]
(Color x y z))
(def ast6 (lambda-to-ast (code trixy-6)))
(def asta6 (annotate-ast ast6))