|
102 | 102 | :else |
103 | 103 | (g/type (eval x)))) |
104 | 104 |
|
| 105 | +(defn- tag-metadata-for [^Type src] |
| 106 | + (if (and (instance? Class (.type src)) |
| 107 | + (not (.wrapper src))) |
| 108 | + {:tag (if (= src (normalize-type-descriptor 'bytes)) |
| 109 | + 'bytes |
| 110 | + (.getName ^Class (.type src)))} |
| 111 | + {})) |
| 112 | + |
105 | 113 | (defmacro def-conversion |
106 | 114 | "Defines a conversion from one type to another." |
107 | 115 | [[src dst :as conversion] params & body] |
108 | 116 | (let [^Type src (normalize-type-descriptor src) |
109 | 117 | dst (normalize-type-descriptor dst)] |
110 | 118 | `(let [f# |
111 | 119 | (fn [~(with-meta (first params) |
112 | | - {:tag (when (and (instance? Class (.type src)) (not (.wrapper src))) |
113 | | - (if (= src (normalize-type-descriptor 'bytes)) |
114 | | - 'bytes |
115 | | - (.getName ^Class (.type src))))}) |
| 120 | + (tag-metadata-for src)) |
116 | 121 | ~(if-let [options (second params)] |
117 | 122 | options |
118 | 123 | `_#)] |
|
127 | 132 | "Defines a byte transfer from one type to another." |
128 | 133 | [[src dst] params & body] |
129 | 134 | (let [src (normalize-type-descriptor src) |
130 | | - dst (normalize-type-descriptor dst)] |
| 135 | + dst (normalize-type-descriptor dst) |
| 136 | + src-meta (tag-metadata-for src) |
| 137 | + dst-meta (tag-metadata-for dst)] |
131 | 138 | `(swap! src->dst->transfer assoc-in [~src ~dst] |
132 | | - (fn [~(with-meta (first params) {:tag src}) |
133 | | - ~(with-meta (second params) {:tag dst}) |
| 139 | + (fn [~(with-meta (first params) src-meta) |
| 140 | + ~(with-meta (second params) dst-meta) |
134 | 141 | ~(if-let [options (get params 2)] options (gensym "options"))] |
135 | 142 | ~@body)))) |
136 | 143 |
|
|
0 commit comments