X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=utilities.lisp;h=d524371058ec9b1d5901e7fa749bdbbd701eda01;hb=6cba7853012e0d02dc9f41a375f0a1d54f22609a;hp=d8fedc6a393308afd5265e5ba32d4d86c3b40ecc;hpb=8bbe17b09cc57e90f583efd49436ecd2fc2e4d63;p=cl-protobufs.git diff --git a/utilities.lisp b/utilities.lisp index d8fedc6..d524371 100644 --- a/utilities.lisp +++ b/utilities.lisp @@ -258,6 +258,11 @@ ,@body))))) +(defmacro appendf (place tail) + "Append 'tail' to the list given by 'place', then set the place to the new list." + `(setf ,place (append ,place ,tail))) + + ;;; Functional programming, please (defun curry (function &rest args) @@ -286,15 +291,15 @@ ;; A parameterized list type for repeated fields ;; The elements aren't type-checked (deftype list-of (type) - (if (eq type 'nil) ; a list that cannot have any element (element-type nil) is null. + (if (eq type 'nil) ;a list that cannot have any element (element-type nil) is null 'null 'list)) ;; The same, but use a (stretchy) vector (deftype vector-of (type) - (if (eq type 'nil); an array that cannot have any element (element-type nil) is of size 0. + (if (eq type 'nil) ;an array that cannot have any element (element-type nil) is of size 0 '(array * (0)) - '(array * (*)))) ;an 1-dimensional array of any type + '(array * (*)))) ;a 1-dimensional array of any type ;; This corresponds to the :bytes Protobufs type (deftype byte-vector () '(array (unsigned-byte 8) (*))) @@ -314,11 +319,23 @@ (deftype sfixed32 () '(signed-byte 32)) (deftype sfixed64 () '(signed-byte 64)) +;; Type expansion +(defun type-expand (type) + #+(or abcl xcl) (system::expand-deftype type) + #+allegro (excl:normalize-type type :default type) + #+ccl (ccl::type-expand type) + #+clisp (ext:type-expand type) + #+cmu (kernel:type-expand type) + #+(or ecl mkcl) (si::expand-deftype type) + #+lispworks (type:expand-user-type type) + #+sbcl (sb-ext:typexpand type) + #-(or abcl allegro ccl clisp cmu ecl lispworks mkcl sbcl xcl) type) + ;;; Code generation utilities -(defvar *proto-name-separators* '(#\- #\_ #\/ #\space)) -(defvar *camel-case-field-names* nil) +(defparameter *proto-name-separators* '(#\- #\_ #\/ #\space)) +(defparameter *camel-case-field-names* nil) (defun find-proto-package (name) "A very fuzzy definition of 'find-package'." @@ -625,7 +642,7 @@ (ldb (byte 16 0) high) (ldb (byte 16 16) low) (ldb (byte 16 0) low)) - #+ccl (ccl::double-float-from-bits high low) + #+ccl (ccl::double-float-from-bits (logand high #xffffffff) low) #+cmu (kernel:make-double-float high low) #+sbcl (sb-kernel:make-double-float high low) #+lispworks (lispworks-float:make-double-float high low))