summaryrefslogtreecommitdiff
path: root/src/tg/type-macros.lisp
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-10-18 07:31:03 +0300
committerGravatar Uko Kokņevičs2025-10-18 07:31:03 +0300
commitf4b8d8e58b82b29b3cc765c44045b86d6ec44054 (patch)
tree331be6aa8104328e14f42b4077345e8ef86b1433 /src/tg/type-macros.lisp
parentfixmeup (diff)
downloadukkoclot-f4b8d8e58b82b29b3cc765c44045b86d6ec44054.tar.gz
ukkoclot-f4b8d8e58b82b29b3cc765c44045b86d6ec44054.tar.xz
ukkoclot-f4b8d8e58b82b29b3cc765c44045b86d6ec44054.zip
Utilise alexandria:with-gensyms
Diffstat (limited to 'src/tg/type-macros.lisp')
-rw-r--r--src/tg/type-macros.lisp30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/tg/type-macros.lisp b/src/tg/type-macros.lisp
index 390781f..5f99cba 100644
--- a/src/tg/type-macros.lisp
+++ b/src/tg/type-macros.lisp
@@ -3,6 +3,7 @@
3(defpackage :ukkoclot/tg/type-macros 3(defpackage :ukkoclot/tg/type-macros
4 (:documentation "Macros for easy defining TG types.") 4 (:documentation "Macros for easy defining TG types.")
5 (:use :c2cl :iterate) 5 (:use :c2cl :iterate)
6 (:import-from :alexandria :with-gensyms)
6 (:import-from :com.dieggsy.f-string :enable-f-strings) 7 (:import-from :com.dieggsy.f-string :enable-f-strings)
7 (:import-from :ukkoclot/serializing :parse-value) 8 (:import-from :ukkoclot/serializing :parse-value)
8 (:import-from :ukkoclot/hash-tables :gethash-lazy) 9 (:import-from :ukkoclot/hash-tables :gethash-lazy)
@@ -54,7 +55,7 @@
54 `(list ,(field-hash-key field) ,value ',(field-type field))) 55 `(list ,(field-hash-key field) ,value ',(field-type field)))
55 56
56 (defun emit-collect-nondefault-fields (name fields obj collector) 57 (defun emit-collect-nondefault-fields (name fields obj collector)
57 (let ((value (gensym "VALUE"))) 58 (with-gensyms (value)
58 (iter (for field in (reverse fields)) 59 (iter (for field in (reverse fields))
59 (collect 60 (collect
60 (if (field-skip-if-default field) 61 (if (field-skip-if-default field)
@@ -70,8 +71,7 @@
70 `(gethash-lazy ,(field-hash-key field) ,source ,(field-default field))) 71 `(gethash-lazy ,(field-hash-key field) ,source ,(field-default field)))
71 72
72 (defun emit-jzon-coerced-fields (name fields) 73 (defun emit-jzon-coerced-fields (name fields)
73 (let ((obj (gensym "OBJ")) 74 (with-gensyms (obj result)
74 (result (gensym "RESULT")))
75 `(defmethod jzon:coerced-fields ((,obj ,name)) 75 `(defmethod jzon:coerced-fields ((,obj ,name))
76 (let (,result) 76 (let (,result)
77 ,@(emit-collect-nondefault-fields 77 ,@(emit-collect-nondefault-fields
@@ -85,9 +85,8 @@
85 (parse-value ',(field-type field) ,(emit-gethash field source)))) 85 (parse-value ',(field-type field) ,(emit-gethash field source))))
86 86
87 (defun emit-parse-value (name fields) 87 (defun emit-parse-value (name fields)
88 (let ((type-sym (gensym "TYPE-SYM")) 88 (with-gensyms (source type)
89 (source (gensym "SOURCE"))) 89 `(defmethod parse-value ((,type (eql ',name)) ,source)
90 `(defmethod parse-value ((,type-sym (eql ',name)) ,source)
91 (let (,@(iter (for field in fields) 90 (let (,@(iter (for field in fields)
92 (collect (emit-let-gethash field source)))) 91 (collect (emit-let-gethash field source))))
93 (,(type-constructor name) 92 (,(type-constructor name)
@@ -95,10 +94,7 @@
95 (appending (emit-constructor-args field)))))))) 94 (appending (emit-constructor-args field))))))))
96 95
97 (defun emit-printer (name printer-name fields) 96 (defun emit-printer (name printer-name fields)
98 (let ((obj (gensym "OBJ")) 97 (with-gensyms (depth obj pprint-args stream)
99 (stream (gensym "STREAM"))
100 (depth (gensym "DEPTH"))
101 (pprint-args (gensym "PPRINT-ARGS")))
102 `(defun ,printer-name (,obj ,stream ,depth) ; lint:suppress lambda-list-invalid 98 `(defun ,printer-name (,obj ,stream ,depth) ; lint:suppress lambda-list-invalid
103 (declare (ignore ,depth)) 99 (declare (ignore ,depth))
104 (let (,pprint-args) 100 (let (,pprint-args)
@@ -117,10 +113,10 @@
117 `(,(field-name field) ,(field-default field) :type ,(field-type field)))) 113 `(,(field-name field) ,(field-default field) :type ,(field-type field))))
118 114
119(defmacro define-tg-type (name &body field-specs) 115(defmacro define-tg-type (name &body field-specs)
120 (let ((fields (parse-field-specs field-specs)) 116 (let ((fields (parse-field-specs field-specs)))
121 (printer-name (gensym "PRINTER"))) 117 (with-gensyms (printer)
122 `(progn 118 `(progn
123 ,(emit-struct name printer-name fields) 119 ,(emit-struct name printer fields)
124 ,(emit-printer name printer-name fields) 120 ,(emit-printer name printer fields)
125 ,(emit-parse-value name fields) 121 ,(emit-parse-value name fields)
126 ,(emit-jzon-coerced-fields name fields)))) 122 ,(emit-jzon-coerced-fields name fields)))))