From fec434a4e2d0ff65510581e461d87a945d25759a Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Thu, 23 Oct 2025 10:17:00 +0300 Subject: Use serapeum's -> & defsubst --- src/enum.lisp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/enum.lisp') diff --git a/src/enum.lisp b/src/enum.lisp index b7cce15..3599174 100644 --- a/src/enum.lisp +++ b/src/enum.lisp @@ -4,8 +4,9 @@ (:documentation "Macro for generating an enum type.") (:use :c2cl :iterate) (:import-from :alexandria :with-gensyms) - (:import-from :ukkoclot/src/serializing :fixup-value :parse-value) + (:import-from :serapeum :->) (:import-from :string-case :string-case) + (:import-from :ukkoclot/src/serializing :fixup-value :parse-value) (:local-nicknames (:jzon :com.inuoe.jzon)) (:export :define-enum)) @@ -14,36 +15,46 @@ (eval-when (:compile-toplevel :load-toplevel :execute) (defstruct (field (:constructor make-field%)) name string) + (-> make-field (symbol string) field) (defun make-field (name string) "Better constructor for `field'." (make-field% :name name :string string)) + ;; TODO: list-of-fields, list-of-field-specs + (-> parse-field-specs (list) list) (defun parse-field-specs (field-specs) "Parse a list of field specs into a list of fields." (iter (for field-spec in field-specs) (collect (apply #'make-field field-spec)))) + (-> emit-defconst (field) list) (defun emit-defconst (field) "Emit the `defconstant' statement for a specific field." `(defconstant ,(field-name field) ',(field-name field))) + ;; TODO: list-of-fields + (-> emit-deftype (symbol list) list) (defun emit-deftype (name fields) "Emit the `deftype' statement for the enum." `(deftype ,name () '(member ,@(iter (for field in fields) (collect (field-name field)))))) + (-> emit-fixup-method (field) list) (defun emit-fixup-method (field) "Emit the `fixup-value' specialization for the enum." (with-gensyms (arg) `(defmethod fixup-value ((,arg (eql ',(field-name field)))) ,(field-string field)))) + (-> emit-jzon-write-method (field) list) (defun emit-jzon-write-method (field) "Emit the `json:write-value' specialization for the enum." (with-gensyms (arg writer) `(defmethod jzon:write-value ((,writer jzon:writer) (,arg (eql ',(field-name field)))) (jzon:write-value ,writer ,(field-string field))))) + ;; TODO: list-of-fields + (-> emit-parse-value (symbol list) list) (defun emit-parse-value (name fields) "Emit the `parse-value' specialization for the enum." (with-gensyms (source type) -- cgit v1.2.3