solved super annoying bug in constraint solver (nested lists were not

substituted correctly)
This commit is contained in:
Erik 2016-02-25 19:56:12 +01:00
parent fc060d6dcb
commit d5e5101c68
4 changed files with 85 additions and 11 deletions

View File

@ -1,7 +1,6 @@
(load-lisp (str carp-dir "lisp/generics_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"))
(load-lisp (str carp-dir "lisp/baking_tests.carp"))

View File

@ -79,9 +79,49 @@
"t1" :float})
(assert-eq solution solution-backwards))))
(defn test-constraint-solving-7 ()
(let [;;_ (println "\n- Constraint solving 7 -")
constraints (list {:a "t0" :b "t1"}
{:a '(:Array "t1") :b '(:Array "t2")}
{:a "t2" :b :int})
solution (solve-constraints constraints)
;;_ (println "\n- Backwards -")
solution-backwards (solve-constraints (reverse constraints))]
(do
(assert-eq solution {"t0" :int
"t1" :int
"t2" :int})
(assert-eq solution solution-backwards))))
(defn test-constraint-solving-8 ()
(let [;;_ (println "\n- Constraint solving 8 -")
constraints (list
{:a '(:fn (:Array "t3")) :b "t2"}
{:a '(:fn (:Array "t1")) :b "t2"}
{:a "t3" :b :int}
)
solution (solve-constraints constraints)
;;_ (println "\n- Backwards -")
solution-backwards (solve-constraints (reverse constraints))]
(do
(assert-eq solution {
"t1" :int
"t2" '(:fn (:Array :int))
"t3" :int})
(assert-eq solution solution-backwards))))
(defn test-subst-in-nested-list []
(assert-eq
{"a" '(:foo (:goo :int))}
(replace-subst-from-right {"a" '(:foo (:goo "b"))} "b" :int)))
(test-subst-in-nested-list)
(test-constraint-solving-1)
(test-constraint-solving-2)
(test-constraint-solving-3)
(test-constraint-solving-4)
(test-constraint-solving-5)
(test-constraint-solving-6)
(test-constraint-solving-7)
(test-constraint-solving-8)

View File

@ -197,7 +197,9 @@
() ()
(x & xs) (if (= x replace-this)
(cons with-this (replace-in-list xs replace-this with-this))
(cons x (replace-in-list xs replace-this with-this))))))
(if (list? x)
(cons (replace-in-list x replace-this with-this) (replace-in-list xs replace-this with-this))
(cons x (replace-in-list xs replace-this with-this)))))))
(defn maybe-replace-binding (key value replace-this with-this)
(do

View File

@ -82,6 +82,22 @@
(defn test-int-array []
(+ 100 (nth (array-of-size 3) 0)))
(defn array-literal []
[10 20 30])
(def last (lambda-to-ast (code array-literal)))
;;(def lcon (gencon last))
;;(def tlast (infer-types last nil))
;;(def lasta (annotate-ast last))
(defn test-array-literal []
nil)
(defn small-array []
(let [a (array-of-size 3)
b (array-set a 0 10)
@ -89,6 +105,29 @@
d (array-set c 2 30)]
d))
(def small-ast (lambda-to-ast (code small-array)))
(def small-con (gencon small-ast))
(def small-sol (solve-constraints small-con))
(def small-asta (annotate-ast small-ast))
(defn small-array-2 []
;;(array-set
(array-set
(array-set
(array-of-size 3)
0 10)
1 20)
;;2 30)
)
(def small-2-ast (lambda-to-ast (code small-array-2)))
(def small-2-con (gencon small-2-ast))
(def small-2-sol (solve-constraints small-2-con))
(def small-2-asta (annotate-ast small-2-ast))
(defn print-small-array []
(let [a (small-array)]
(do (print "[")
@ -99,13 +138,7 @@
(print (itos (nth a 2)))
(println "]"))))
(defn array-literal []
[10 20 30])
(def last (lambda-to-ast (code array-literal)))
;;(def lcon (gencon last))
;;(def tlast (infer-types last nil))
;;(def lasta (annotate-ast last))
(defn test-array-literal []
nil)