Skip to content

Commit

Permalink
Merge pull request #2 from onionpancakes/feature/directly-extend-cons…
Browse files Browse the repository at this point in the history
…tants

Extend string and numbers directly instead of through Constable
  • Loading branch information
onionpancakes committed Mar 12, 2024
2 parents bf7757f + 8180c3f commit 8a3820c
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 3 deletions.
58 changes: 55 additions & 3 deletions src/dev/onionpancakes/chassis/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,61 @@
;; Works for now...
(if (constant? val) val this))
this))
;; Constable catches Strings, constant Numbers
;; (not mutable accumulator Numbers), and a bit more.
java.lang.constant.Constable
String
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Short
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Integer
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Long
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
BigInteger
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Float
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
Double
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
BigDecimal
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
clojure.lang.BigInt
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
clojure.lang.Ratio
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
Expand Down
50 changes: 50 additions & 0 deletions test/dev/onionpancakes/chassis/tests/test_compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,64 @@
(and (instance? dev.onionpancakes.chassis.core.RawString ret)
(= (c/fragment ret) (c/html node))))
nil
0
0N
0.0
0.0M
3/2
""
[:div]
[:div#foo.bar "123"]
[:div {:foo "bar"} "123"]
[:div [:p "foo"] [:p "bar"]]
[:div [1 2 3 4]]
[:div #{1 2 3 4}]

;; Macros
(example-elem-macro "123")
(example-elem-macro-nested "123")
[:div [:p "foo"] (example-elem-macro "123") [:p "bar"]]
[:div [:p "foo"] (example-elem-macro-nested "123") [:p "bar"]]

;; Var consts
[:div {:foo example-constant}]
[c/doctype-html5 [:div "foo" c/nbsp "bar"]]))

(deftest test-compile-node-full-compaction
(are [node] (let [ret (cc/compile-node node)]
(and (instance? dev.onionpancakes.chassis.core.RawString ret)
(= (c/fragment ret) (c/html node))))
nil
0
0N
0.0
0.0M
3/2
""
(short 0)
(int 0)
(long 0)
(bigint 0)
(biginteger 0)
(float 0)
(double 0)
(bigdec 0)

[:div]
[:div#foo.bar "123"]
[:div {:foo "bar"} "123"]
[:div [:p "foo"] [:p "bar"]]
[:div [1 2 3 4]]
[:div #{1 2 3 4}]

;; Alias
[::Foo]
[::Foo nil "foo"]

;; Fns
(example-elem-fn "123")
[:div (example-elem-fn "123")]

;; Macros
(example-elem-macro "123")
(example-elem-macro-nested "123")
Expand Down

0 comments on commit 8a3820c

Please sign in to comment.