Skip to content

Commit

Permalink
Handle built-in tagged literals #inst/#uuid for compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
onionpancakes committed Apr 4, 2024
1 parent 5597fe8 commit 9e688db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/dev/onionpancakes/chassis/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,18 @@
;; Works for now...
(if (constant? val) val this))
this))
java.util.Date
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] false) ; Not constant because not immutable.
(evaluated? [_] true)
(resolved [this] this)
java.util.UUID
(attrs? [_] false)
(not-attrs? [_] true)
(constant? [_] true)
(evaluated? [_] true)
(resolved [this] this)
String
(attrs? [_] false)
(not-attrs? [_] true)
Expand Down
12 changes: 12 additions & 0 deletions test/dev/onionpancakes/chassis/tests/test_compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#{}
'()
[]
#inst "2007-01-04"
#uuid "00000000-0000-0000-0000-000000000000"

[:div]
[:div nil]
Expand Down Expand Up @@ -140,12 +142,15 @@
0.0M
3/2
""
#uuid "00000000-0000-0000-0000-000000000000"

[:div]
[:div#foo.bar "123"]
[:div {:foo "bar"} "123"]
[:div [:p "foo"] [:p "bar"]]
[:div [1 2 3 4]]
[:div #{1 2 3 4}]
[:div #uuid "00000000-0000-0000-0000-000000000000"]

;; Macros
(example-elem-macro "123")
Expand All @@ -168,6 +173,8 @@
0.0M
3/2
""
#uuid "00000000-0000-0000-0000-000000000000"

(short 0)
(int 0)
(long 0)
Expand All @@ -183,6 +190,7 @@
[:div [:p "foo"] [:p "bar"]]
[:div [1 2 3 4]]
[:div #{1 2 3 4}]
[:div #uuid "00000000-0000-0000-0000-000000000000"]

;; Alias
[::Foo]
Expand Down Expand Up @@ -219,6 +227,10 @@
(do
;; Compile attrs reflection examples

;; Tagged literals
(cc/compile [:div #inst "2007-01-04"])
(cc/compile [:div #uuid "00000000-0000-0000-0000-000000000000"])

;; java.util.Map
(let [attrs nil]
(cc/compile [:div ^java.util.Map attrs "foobar"]))
Expand Down

0 comments on commit 9e688db

Please sign in to comment.