|
192 | 192 | (sci.impl.deftype/->type-impl '~rec-type ~record-name ~record-name (zipmap ~(list 'quote fields) ~fields))) |
193 | 193 | protocol-impls)))) |
194 | 194 |
|
195 | | -(defn ^:private standard-record-path |
| 195 | +(defn ^:private analyze-defrecord* |
196 | 196 | "Record-specific path — protocol implementations with keyword-based field access." |
197 | 197 | [ctx form rec-type record-name constructor-fn-sym map-factory-sym |
198 | 198 | field-set protocol-impls] |
|
253 | 253 | (emit-record-type rec-type record-name constructor-fn-sym map-factory-sym |
254 | 254 | protocol-impls))) |
255 | 255 |
|
256 | | -(defn deftype-macro |
257 | | - "Macro expansion for deftype. Emits a (do (declare ->TypeName) (deftype* ...) (import ...)) |
258 | | - so that macroexpand reveals the constructor for static-analysis tools (e.g. Clerk). |
259 | | - The declare is overwritten at analysis time by analyze-deftype*." |
260 | | - [[_fname] _ record-name fields & raw-protocol-impls] |
261 | | - (let [ns-name (utils/current-ns-name) |
262 | | - tagged-name (symbol (str ns-name) (str record-name)) |
263 | | - class-name (symbol (str (munge ns-name) "." record-name)) |
264 | | - factory-fn-sym (symbol (str "->" record-name)) |
265 | | - protocol-impls (utils/split-when symbol? raw-protocol-impls) |
266 | | - interfaces (mapv first protocol-impls) |
267 | | - method-counts (mapv #(count (rest %)) protocol-impls) |
268 | | - methods (mapcat rest protocol-impls)] |
269 | | - (list 'do |
270 | | - (list 'declare factory-fn-sym) |
271 | | - (list* 'deftype* tagged-name class-name fields |
272 | | - :implements (with-meta interfaces {:method-counts method-counts}) |
273 | | - methods) |
274 | | - (list 'import (list (symbol (str ns-name)) record-name))))) |
275 | | - |
276 | 256 | (defn analyze-deftype* |
277 | 257 | "Analyzer handler for deftype* special form. |
278 | 258 | Generates the type definition and protocol implementations, |
|
304 | 284 | ;; (factory fns are in the macro expansion) |
305 | 285 | (let [constructor-fn-sym (symbol (str "__" factory-fn-str "__ctor__")) |
306 | 286 | map-factory-sym (symbol (str "map->" record-name))] |
307 | | - (standard-record-path ctx form rec-type record-name |
308 | | - constructor-fn-sym map-factory-sym |
309 | | - field-set protocol-impls)) |
| 287 | + (analyze-defrecord* ctx form rec-type record-name |
| 288 | + constructor-fn-sym map-factory-sym |
| 289 | + field-set protocol-impls)) |
310 | 290 | ;; Standard deftype code generation |
311 | 291 | #?(:clj |
312 | 292 | (let [deftype-fn (:deftype-fn ctx) |
|
447 | 427 | [:namespaces (symbol (namespace tagged-name)) :types] |
448 | 428 | assoc record-name (sci.lang.Type. {:sci.impl/type-name rec-type})) |
449 | 429 | (@utils/analyze ctx result))))) |
| 430 | + |
| 431 | +(defn deftype-macro |
| 432 | + "Macro expansion for deftype. Emits a (do (declare ->TypeName) (deftype* ...) (import ...)) |
| 433 | + so that macroexpand reveals the constructor for static-analysis tools (e.g. Clerk). |
| 434 | + The declare is overwritten at analysis time by analyze-deftype*." |
| 435 | + [[_fname] _ record-name fields & raw-protocol-impls] |
| 436 | + (let [ns-name (utils/current-ns-name) |
| 437 | + tagged-name (symbol (str ns-name) (str record-name)) |
| 438 | + class-name (symbol (str (munge ns-name) "." record-name)) |
| 439 | + factory-fn-sym (symbol (str "->" record-name)) |
| 440 | + protocol-impls (utils/split-when symbol? raw-protocol-impls) |
| 441 | + interfaces (mapv first protocol-impls) |
| 442 | + method-counts (mapv #(count (rest %)) protocol-impls) |
| 443 | + methods (mapcat rest protocol-impls)] |
| 444 | + (list 'do |
| 445 | + (list 'declare factory-fn-sym) |
| 446 | + (list* 'deftype* tagged-name class-name fields |
| 447 | + :implements (with-meta interfaces {:method-counts method-counts}) |
| 448 | + methods) |
| 449 | + (list 'import (list (symbol (str ns-name)) record-name))))) |
0 commit comments