diff --git a/TODO.md b/TODO.md index 5f8e9c61..8c52c797 100644 --- a/TODO.md +++ b/TODO.md @@ -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) diff --git a/lisp/infer_types.carp b/lisp/infer_types.carp index 542849cd..7ce32464 100644 --- a/lisp/infer_types.carp +++ b/lisp/infer_types.carp @@ -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) diff --git a/out/project.carp b/out/project.carp index 99a070fb..36cc7286 100644 --- a/out/project.carp +++ b/out/project.carp @@ -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))