Skip to content

Commit ba59ff9

Browse files
committed
add defonce variants for deftype et al, presumptive fix for #26
1 parent cf8975b commit ba59ff9

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:url "http://opensource.org/licenses/MIT"}
55
:dependencies [[primitive-math "0.1.5"]
66
[clj-tuple "0.2.2"]
7-
[manifold "0.1.4"]]
7+
[manifold "0.1.6"]]
88
:profiles {:dev {:dependencies [[org.clojure/clojure "1.8.0"]
99
[org.clojure/test.check "0.9.0"]
1010
[codox-md "0.2.0" :exclusions [org.clojure/clojure]]]}}

src/byte_streams/graph.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[clj-tuple :refer [vector]]
55
[manifold.stream :as s]
66
[byte-streams
7-
[utils :as u]
7+
[utils :as u :refer [defprotocol+ defrecord+ deftype+]]
88
[protocols :as p]])
99
(:import
1010
[java.util.concurrent
@@ -17,7 +17,7 @@
1717

1818
(declare pprint-type)
1919

20-
(deftype Conversion [f ^double cost]
20+
(deftype+ Conversion [f ^double cost]
2121
Object
2222
(equals [_ x]
2323
(and
@@ -27,7 +27,7 @@
2727
(hashCode [_]
2828
(bit-xor (System/identityHashCode f) (unchecked-int cost))))
2929

30-
(deftype Type [wrapper type]
30+
(deftype+ Type [wrapper type]
3131
Object
3232
(equals [_ x]
3333
(and
@@ -88,7 +88,7 @@
8888
:else
8989
(= a b)))))
9090

91-
(defprotocol IConversionGraph
91+
(defprotocol+ IConversionGraph
9292
(assoc-conversion [_ src dst f cost])
9393
(equivalent-targets [_ dst])
9494
(possible-sources [_])
@@ -114,7 +114,7 @@
114114
:else
115115
nil))
116116

117-
(deftype ConversionGraph [m]
117+
(deftype+ ConversionGraph [m]
118118
IConversionGraph
119119
(assoc-conversion [_ src dst f cost]
120120
(let [m' (assoc-in m [src dst] (Conversion. f cost))
@@ -156,7 +156,7 @@
156156

157157
;;;
158158

159-
(defrecord ConversionPath [path fns visited? cost]
159+
(defrecord+ ConversionPath [path fns visited? cost]
160160
Comparable
161161
(compareTo [_ x]
162162
(let [cmp (compare cost (.cost ^ConversionPath x))]

src/byte_streams/protocols.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
(ns byte-streams.protocols
2+
(:require
3+
[byte-streams.utils :refer [defprotocol+]])
24
(:import
35
[java.util.concurrent
46
ConcurrentHashMap]))
57

6-
(defprotocol Closeable
8+
(defprotocol+ Closeable
79
(close [_] "A protocol that is a superset of `java.io.Closeable`."))
810

9-
(defprotocol ByteSource
11+
(defprotocol+ ByteSource
1012
(take-bytes! [_ n options] "Takes `n` bytes from the byte source."))
1113

12-
(defprotocol ByteSink
14+
(defprotocol+ ByteSink
1315
(send-bytes! [_ bytes options] "Puts `bytes` in the byte sink."))
1416

1517
(extend-protocol Closeable

src/byte_streams/pushback_stream.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(:refer-clojure :exclude [take])
33
(:require
44
[primitive-math :as p]
5-
[byte-streams.utils :refer [doit]]
5+
[byte-streams.utils :refer [doit definterface+ deftype+]]
66
[manifold
77
[utils :as u]
88
[stream :as s]
@@ -20,7 +20,7 @@
2020

2121
(set! *unchecked-math* true)
2222

23-
(definterface PushbackStream
23+
(definterface+ PushbackStream
2424
(put [^bytes x ^int offset ^int length])
2525
(put [^java.nio.ByteBuffer buf])
2626
(pushback [^bytes ary ^int offset ^int length])
@@ -87,7 +87,7 @@
8787
body)))
8888

8989
(both
90-
(deftype (either [PushbackByteStream] [SynchronizedPushbackByteStream])
90+
(deftype+ (either [PushbackByteStream] [SynchronizedPushbackByteStream])
9191
[lock
9292
^LinkedList consumers
9393
^long buffer-capacity

src/byte_streams/utils.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
[java.util.concurrent
66
ConcurrentHashMap]))
77

8+
(defmacro defprotocol+ [name & body]
9+
(when-not (resolve name)
10+
`(defprotocol ~name ~@body)))
11+
12+
(defmacro deftype+ [name & body]
13+
(when-not (resolve name)
14+
`(deftype ~name ~@body)))
15+
16+
(defmacro defrecord+ [name & body]
17+
(when-not (resolve name)
18+
`(defrecord ~name ~@body)))
19+
20+
(defmacro definterface+ [name & body]
21+
(when-not (resolve name)
22+
`(definterface ~name ~@body)))
23+
824
(defmacro doit
925
"A version of doseq that doesn't emit all that inline-destroying chunked-seq code."
1026
[[x it] & body]

test/byte_streams_reload_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(ns byte-streams-reload-test
2+
(:require
3+
[clojure.test :refer :all]))
4+
5+
(deftest test-reload-all
6+
(dotimes [_ 5]
7+
(require 'byte-streams :reload-all)))

0 commit comments

Comments
 (0)