Skip to content

Commit

Permalink
Call unifier/prep in defrules, other clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed May 15, 2024
1 parent 312d8b8 commit 5dab294
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 37 deletions.
1 change: 1 addition & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:lint-as {kibit.rules.util/defrules clj-kondo.lint-as/def-catch-all}}
16 changes: 7 additions & 9 deletions src/kibit/check.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns kibit.check
"Kibit's integration point and public API"
(:require [clojure.java.io :as io]
[clojure.core.logic.unifier :as unifier]
[kibit.core :as core]
[kibit.rules :as core-rules]
[kibit.reporters :as reporters]
Expand Down Expand Up @@ -67,12 +66,13 @@
"Construct the canonical simplify-map
given an expression and a simplified expression."
[expr simplified-expr]
{:expr expr
:line (-> expr meta :line)
:column (-> expr meta :column)
:end-line (-> expr meta :end-line)
:end-column (-> expr meta :end-column)
:alt simplified-expr})
(let [expr-meta (meta expr)]
{:expr expr
:line (:line expr-meta)
:column (:column expr-meta)
:end-line (:end-line expr-meta)
:end-column (:end-column expr-meta)
:alt simplified-expr}))

;; ### Guarding the check

Expand Down Expand Up @@ -169,7 +169,6 @@
(merge default-args
{:resolution :toplevel}
(apply hash-map kw-opts))
rules (map unifier/prep rules)
simplify-fn #((res->simplify resolution) % rules)]
(check-aux expr simplify-fn guard)))

Expand All @@ -178,7 +177,6 @@
(let [{:keys [rules guard resolution init-ns]}
(merge default-args
(apply hash-map kw-opts))
rules (map unifier/prep rules)
simplify-fn #((res->simplify resolution) % rules)]
(keep #(check-aux % simplify-fn guard)
((res->read-seq resolution) reader init-ns))))
Expand Down
5 changes: 1 addition & 4 deletions src/kibit/rules/arithmetic.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@
[(dec (Math/exp ?x)) (Math/expm1 ?x)]

;;ugly rounding tricks
[(long (+ ?x 0.5)) (Math/round ?x)]
)


[(long (+ ?x 0.5)) (Math/round ?x)])
21 changes: 0 additions & 21 deletions src/kibit/rules/control_structures.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,3 @@
(while ?test . ?exprs)]
[(let ?binding (do . ?exprs)) (let ?binding . ?exprs)]
[(loop ?binding (do . ?exprs)) (loop ?binding . ?exprs)])

(comment
(when (not (pred? x y)) (f x y))

(if (all-streams-complete?)
(do
(deliver @all-clear :true)
(info "All streams complete.")))

(if (pred? x)
(do (action a)
(action b)
(if-let [x (f a b c)
y (g a b c)
z (h a b c)]
(do (+ 1 0)
(= 1 1)
(< 1 0)))
(action d)
(action f))
nil))
7 changes: 4 additions & 3 deletions src/kibit/rules/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

(defmacro defrules [name & rules]
`(let [rules# (for [rule# '~rules]
(if (raw-rule? rule#)
(eval rule#) ;; raw rule, no need to compile
(compile-rule rule#)))]
(unifier/prep
(if (raw-rule? rule#)
(eval rule#) ;; raw rule, no need to compile
(compile-rule rule#))))]
(def ~name (vec rules#))))

0 comments on commit 5dab294

Please sign in to comment.