solved severe bug in constraint solver, fixed the game

This commit is contained in:
Erik Svedäng 2016-03-17 23:37:50 +01:00
parent f75a7ddb61
commit a6e052d98c
5 changed files with 48 additions and 22 deletions

View File

@ -19,7 +19,7 @@
(defn t [] (defn t []
(dtof (glfwGetTime))) (dtof (glfwGetTime)))
^ann '(:fn ((:ref (:Array :Ship))) :void) ;;^ann '(:fn ((:ref (:Array :Ship))) :void)
(defn draw [state] (defn draw [state]
(do (do
(draw-line 300f 200f (+ 300f (* 100.0f (sinf (t)))) (+ 200f (* 100.0f (cosf (t))))) (draw-line 300f 200f (+ 300f (* 100.0f (sinf (t)))) (+ 200f (* 100.0f (cosf (t)))))

View File

@ -10,21 +10,44 @@
;; (println (str (B true))) ;; (println (str (B true)))
(defn f [s]
(println s))
;;^ann '(:fn ((:ref (:Array :string))) :void)
(defn draws [state]
(domap f state))
^ann '(:fn ((:ref (:Array :string))) :void) (defn run-app [draw-fn]
(defn draw [state] (let [state [(copy "hej") (copy "på") (copy "dig!")]]
(domap println state)) (draw-fn &state)))
(defn run-app [init-state draw-fn]
(draw-fn init-state))
(defn app [] (defn app []
(let [state ["hej" "på" "dig!"]] (run-app draws))
(run-app state draw)))
(def CONSTRS (list
{:a "x",
:b '(:BLURG :FLORP)}
{:a '("y" "c"),
:b '(("a" "b") "a")}
))
;; (println (str "1:\n" (solve-constraints (cons-last CONSTRS {:a "x" :b "y"}))))
;; (println (str "\n2:\n" (solve-constraints (cons {:a "x" :b "y"} CONSTRS))))
;; (def answer
;; (replace-subst-from-right
;; {"c" "a",
;; "x" '(:BLURG :FLORP),
;; "y" '("a" "b"),
;; "a" "a",
;; "b" "b"}
;; "a"
;; :BLURG
;; ))
;; (defn h [a b] ;; (defn h [a b]

View File

@ -1,10 +1,11 @@
(defn pretty-signature (t) (defn pretty-signature (t)
(match t (str t))
(:fn args ret) (str "(" (join ", " (map pretty-signature args)) ") -> " (pretty-signature ret)) ;; (match t
(:ref r) (str "&" (pretty-signature r) "") ;; (:fn args ret) (str "(" (join ", " (map pretty-signature args)) ") -> " (pretty-signature ret))
(:Array a) (str "Array " (pretty-signature a)) ;; (:ref r) (str "&" (pretty-signature r) "")
x (if (keyword? t) ;; (:Array a) (str "Array " (pretty-signature a))
(name t) ;; x (if (keyword? t)
(if (string? t) ;; (name t)
t ;; (if (string? t)
(error (str "Can't prettify type signature: " t)))))) ;; t
;; (error (str "Can't prettify type signature: " t))))))

View File

@ -103,7 +103,7 @@
(glClearColor 0.1f 0.1f 0.1f 1.0f) (glClearColor 0.1f 0.1f 0.1f 1.0f)
(glClear carp-gl-color-buffer-bit) (glClear carp-gl-color-buffer-bit)
(glColor3f 1.0f 1.0f 1.0f) (glColor3f 1.0f 1.0f 1.0f)
(render-callback state) (render-callback &state)
(reset! state (tick state)) (reset! state (tick state))
(glfwSwapBuffers window) (glfwSwapBuffers window)
(glfwPollEvents))) (glfwPollEvents)))

View File

@ -289,7 +289,7 @@
(if (list? existing) (if (list? existing)
(if (list? value-lookup) (if (list? value-lookup)
(let [_ (when log-substs (println "The existing binding is a list")) (let [_ (when log-substs (println "The existing binding is a list"))
new-substs (reduce (fn (s m2) (extend-substitutions substs (:e m2) (:l m2))) new-substs (reduce (fn (s m2) (extend-substitutions s (:e m2) (:l m2)))
substs substs
(map2 (fn (e l) {:e e :l l}) existing value-lookup)) (map2 (fn (e l) {:e e :l l}) existing value-lookup))
_ (when log-substs (println (str "\nBack from list, new substs: " new-substs)))] _ (when log-substs (println (str "\nBack from list, new substs: " new-substs)))]
@ -297,8 +297,10 @@
(do (do
substs)) substs))
(if (typevar? existing) (if (typevar? existing)
(do (when log-substs (println "The existing binding is a typevar, will replace from right")) (do (when log-substs (println (str "The existing binding is a typevar, will replace " existing " with " value-lookup " from right")))
(replace-subst-from-right substs existing value-lookup)) (let [result (replace-subst-from-right substs existing value-lookup)]
(do ;;(println (str "result: " result))
result)))
(do (when log-substs (println "The existing binding is not a typevar")) (do (when log-substs (println "The existing binding is not a typevar"))
(if (types-exactly-eq? existing value-lookup) (if (types-exactly-eq? existing value-lookup)
(do (when log-substs (println "Current binding matches new value")) (do (when log-substs (println "Current binding matches new value"))