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/tg/method-macros.lisp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/tg/method-macros.lisp') diff --git a/src/tg/method-macros.lisp b/src/tg/method-macros.lisp index 0d33ffb..9ab9e89 100644 --- a/src/tg/method-macros.lisp +++ b/src/tg/method-macros.lisp @@ -5,10 +5,10 @@ (:use :c2cl :iterate) (:import-from :alexandria :make-keyword :with-gensyms) (:import-from :com.dieggsy.f-string :enable-f-strings) - (:import-from :serapeum :take) + (:import-from :serapeum :-> :take) (:import-from :state) (:import-from :str) - (:import-from :ukkoclot/src/transport :do-call) + (:import-from :ukkoclot/src/transport :do-call :http-method) (:export :define-tg-method)) (in-package :ukkoclot/src/tg/method-macros) @@ -21,6 +21,7 @@ (defparameter +unique+ (gensym)) ;; TODO: Fix optional-and-key ! + (-> make-param (symbol t &optional t &key (:skip-if-default boolean)) param) (defun make-param (name type ; lint:suppress avoid-optional-and-key &optional (default +unique+) &key (skip-if-default (not (eq default +unique+)))) @@ -32,26 +33,34 @@ :default default :skip-if-default skip-if-default))) + ;; TODO: list-of-params, list-of-param-specs + (-> parse-param-specs (list) list) (defun parse-param-specs (param-specs) (iter (for param-spec in param-specs) (collect (apply #'make-param param-spec)))) + (-> path-from-name (symbol) string) (defun path-from-name (name) (let ((str (str:camel-case name))) (if (str:ends-with-p "%" str :ignore-case nil) (take (- (length str) 1) str) str))) + (-> emit-append-to-args (param symbol) list) (defun emit-append-to-args (param args) `(setf ,args (acons ',(param-name param) ,(param-name param) ,args))) + (-> emit-arg-type (param) list) (defun emit-arg-type (param) `(,(make-keyword (param-name param)) ,(param-type param))) + (-> emit-defun-arg (param) list) (defun emit-defun-arg (param) `(,(param-name param) ,(param-default param))) + ;; TODO: list-of-params + (-> emit-defun (symbol t list http-method) list) (defun emit-defun (name return-type params method) (with-gensyms (args) `(defun ,name (&key ,@(iter (for param in params) ; lint:suppress lambda-list-invalid @@ -65,11 +74,13 @@ (emit-append-to-args param args)))) (do-call ,method ,(path-from-name name) ',return-type ,args))))) + ;; TODO: list-of-params + (-> emit-ftype (symbol t list) list) (defun emit-ftype (name return-type params) - `(declaim (ftype (function (&key ,@(iter (for param in params) - (collect (emit-arg-type param)))) - ,return-type) - ,name)))) + `(-> ,name + (&key ,@(iter (for param in params) + (collect (emit-arg-type param)))) + ,return-type))) (defmacro define-tg-method ((name type &optional (method :POST)) &body param-specs) -- cgit v1.2.3