mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-11 12:37:32 +03:00
fixed bug where a generic function using other generics would fail to compile
This commit is contained in:
parent
8481921756
commit
354bfedf2f
@ -77,7 +77,7 @@
|
||||
|
||||
(defn visit-arg-explicit (c arg)
|
||||
(let [result (visit-form c arg true)]
|
||||
(str-append! c (str (indent) (type-build (:type arg)) " " (:arg-name arg) " = " (get result :c) ";\n"))))
|
||||
(str-append! c (str (indent) (type-build (:type arg)) " " (c-ify-name (:arg-name arg)) " = " (get result :c) ";\n"))))
|
||||
|
||||
(defn visit-args-explicit (c args)
|
||||
(let []
|
||||
@ -118,7 +118,7 @@
|
||||
|
||||
_ (let [result-name (get-maybe arg :result-name)]
|
||||
(if (nil? result-name)
|
||||
(do (str-append! c (str (indent) (type-build arg-type) " " arg-name " = " (:c result) ";\n"))
|
||||
(do (str-append! c (str (indent) (type-build arg-type) " " (c-ify-name arg-name) " = " (:c result) ";\n"))
|
||||
{:c (:arg-name arg)})
|
||||
{:c result-name}))
|
||||
|
||||
@ -267,7 +267,7 @@
|
||||
x (error (str "visit-form failed to match " x)))))
|
||||
|
||||
(defn arg-list-build (args)
|
||||
(join ", " (map (fn (arg) (str (type-build (get arg :type)) " " (get arg :name)))args)))
|
||||
(join ", " (map (fn (arg) (str (type-build (get arg :type)) " " (c-ify-name (str (:name arg)))))args)))
|
||||
|
||||
(defn visit-function (builder ast func-name)
|
||||
(let [t (:type ast)
|
||||
|
@ -1,10 +1,10 @@
|
||||
|
||||
(load-lisp (str carp-dir "lisp/generics_tests.carp"))
|
||||
(load-lisp (str carp-dir "lisp/baking_tests.carp"))
|
||||
(load-lisp (str carp-dir "lisp/test_stack_trace.carp"))
|
||||
(load-lisp (str carp-dir "lisp/test_line_numbers.carp"))
|
||||
(load-lisp (str carp-dir "lisp/array_tests.carp"))
|
||||
(load-lisp (str carp-dir "lisp/struct_tests.carp"))
|
||||
(load-lisp (str carp-dir "lisp/constraint_tests.carp"))
|
||||
(load-lisp (str carp-dir "lisp/generics_tests.carp"))
|
||||
(load-lisp (str carp-dir "lisp/ownership_tests.carp"))
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
(defn generic-safe-name (t)
|
||||
(match t
|
||||
(:fn args ret) (str "Fn_" (join "" (map pretty-signature args)) "->" (pretty-signature ret))
|
||||
(:fn args ret) (str "Fn-" (join "" (map pretty-signature args)) "-" (pretty-signature ret))
|
||||
(:ref r) (str "RefTo-" (generic-safe-name r) "")
|
||||
(:Array a) (str "ArrayOf-" (generic-safe-name a) "")
|
||||
x (if (keyword? t)
|
||||
@ -35,9 +35,9 @@
|
||||
is-generic (meta-get lookup-t :generic)
|
||||
]
|
||||
(if (and (lambda? global-lookup) is-generic)
|
||||
(do
|
||||
(when (generic-type? t)
|
||||
(error (str "Found generic lambda type with missing type information, can't compile concrete version:\n" t)))
|
||||
(if (generic-type? t)
|
||||
(do (println (str "Lambda with missing type information, can't compile concrete version:\n" t))
|
||||
ast)
|
||||
(let [n (generic-name lookup-sym t)]
|
||||
(do
|
||||
;;(println (str "generic lookup of '" lookup-sym "', t: " t ", lookup-t: " lookup-t ", n: " generic-name))
|
||||
@ -51,9 +51,9 @@
|
||||
(let [ast0 (assoc-in ast '(:value) (symbol n))] ;; make it call another function...
|
||||
ast0))))
|
||||
(if (and (primop? global-lookup) is-generic)
|
||||
(do
|
||||
(when (generic-type? t)
|
||||
(error (str "Found generic primop type with missing type information, can't compile concrete version:\n" t)))
|
||||
(if (generic-type? t)
|
||||
(do (println (str "Primop with missing type information, can't compile concrete version:\n" t))
|
||||
ast)
|
||||
(let [n (generic-name lookup-sym t)]
|
||||
(do
|
||||
;; (println (str "Found a generic primop to bake: " lookup-sym))
|
||||
|
@ -65,3 +65,15 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defn function-as-argument [x y]
|
||||
(itos (+ x y)))
|
||||
|
||||
(defn generic-function-calling-generic-functions [prob-f prob-a prob-b]
|
||||
(prob-f prob-a prob-b))
|
||||
|
||||
(defn try-it-out [] (generic-function-calling-generic-functions function-as-argument 10 20))
|
||||
|
||||
(bake try-it-out)
|
||||
(assert-eq "30" (try-it-out))
|
||||
|
@ -75,28 +75,3 @@
|
||||
;;(defn fa [] 200)
|
||||
;;(bake fa)
|
||||
|
||||
|
||||
|
||||
(defn problematic [prob-f prob-a prob-b]
|
||||
;;(println (ref (str )))
|
||||
(prob-f (ref prob-a) (str prob-b))
|
||||
)
|
||||
|
||||
;; (defn problematic [x y z]
|
||||
;; (x z))
|
||||
|
||||
|
||||
(def prob-ast (lambda-to-ast (code problematic)))
|
||||
;; (def prob-asta (annotate-ast prob-ast))
|
||||
|
||||
;; (println (str (let [ast-func-deps (find-func-deps prob-ast '())
|
||||
;; ast-typed (infer-types ast-func-deps '())
|
||||
;; ast-named (generate-names (copy {}) ast-typed)
|
||||
;; ast-lifetimes (calculate-lifetimes ast-named)
|
||||
;; _ (println (str ast-lifetimes))
|
||||
;; ;;ast-generics (visit-generic-funcs ast-lifetimes)
|
||||
;; ]
|
||||
;; ;;ast-lifetimes
|
||||
;; ;;ast-generics
|
||||
;; nil
|
||||
;; )))
|
||||
|
Loading…
Reference in New Issue
Block a user