]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blobdiff - utilities.lisp
integer encoding/decoding tests
[cl-protobufs.git] / utilities.lisp
index 447789957be1f65eb247b0cc54cd902fef1387d3..06603bab22cfa0629bd88a96fd4a7b5743cf2dd3 100644 (file)
 ;; 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) (*)))
 (deftype sfixed32 () '(signed-byte 32))
 (deftype sfixed64 () '(signed-byte 64))
 
+;; Type expansion
+(defun type-expand (type)
+  #+allegro (excl:normalize-type type :default type)
+  #+ccl (ccl::type-expand type)
+  #+clisp (ext:type-expand type)
+  #+cmu (kernel:type-expand type)
+  #+lispworks (type:expand-user-type type)
+  #+sbcl (sb-ext:typexpand type)
+  #-(or allegro ccl clisp cmu lispworks sbcl) type)
 
 ;;; Code generation utilities
 
                 (excl:double-float-to-shorts x)
               (logior (ash us1 16) us0)
               (logior (ash us3 16) us2))
-  #+ccl  (ccl::double-float-bits x)
+  #+ccl  (multiple-value-bind (high low)
+             (ccl::double-float-bits x)
+           (values low high))
   #+cmu  (values (kernel:double-float-low-bits x)
                  (kernel:double-float-high-bits x))
   #+sbcl (values (sb-kernel:double-float-low-bits x)