about summary refs log tree commit diff stats
path: root/uuid.lsp
diff options
context:
space:
mode:
authorDarren Bane <darren.bane@gmail.com>2020-05-11 01:15:06 +0100
committerDarren Bane <darren.bane@gmail.com>2020-05-11 01:15:06 +0100
commitc066ab2a55a069802009568a051673b3505503d4 (patch)
tree3cf0613bb334461c1f39f55a78a4ff79d3fb971f /uuid.lsp
parent5eba13b70414e1a40ef2418978082c6e4ac37c19 (diff)
downloadlsp-c066ab2a55a069802009568a051673b3505503d4.tar.gz
Lots of unfinished stuff
Diffstat (limited to 'uuid.lsp')
-rw-r--r--uuid.lsp38
1 files changed, 38 insertions, 0 deletions
diff --git a/uuid.lsp b/uuid.lsp
new file mode 100644
index 0000000..f0caaef
--- /dev/null
+++ b/uuid.lsp
@@ -0,0 +1,38 @@
+#!/usr/bin/env uxlisp -shell
+(defpackage #:uuid
+  (:use #:openlisp)
+  (:export
+    #:main))
+(in-package #:uuid)
+(defclass <uuid> () ((time-low :accessor time-low)
+                      (time-mid :accessor time-mid)
+                      (time-hi-and-version :accessor time-hi-and-version)
+                      (clock-seq-hi-and-reserved :accessor clock-seq-hi-and-reserved)
+                      (clock-seq-low :accessor clock-seq-low)
+                      (node :accessor node)))
+(defgeneric format-v1 (obj clockseq timestamp node))
+(defmethod format-v1 ((obj <uuid>) clock-seq timestamp node)
+  (setf (time-low obj) (logand timestamp #xFFFFFFFF))
+  (setf (time-mid obj) (logand (ash timestamp -32) #xFFFF))
+  (setf (time-hi-and-version obj) (logand (ash timestamp -48) #x0FFF))
+  (setf (time-hi-and-version obj) (logior (time-hi-and-version obj) (ash 1 12)))
+  (setf (clock-seq-low obj) (logand clock-seq #xFF))
+  (setf (clock-seq-hi-and-reserved obj) (ash (logand clock-seq #x3F00) -8))
+  (setf (clock-seq-hi-and-reserved obj) (logior (clock-seq-hi-and-reserved obj) #x80))
+  (setf (node obj) node))
+(defun get-current-time ()
+  )
+
+(defmethod initialize-object :after ((self <uuid>) initargs)
+  (let ((timestamp (get-current-time))
+         (node (get-ieee-node-identifier)))
+    (format-v1 self clockseq timestamp node)))
+(defgeneric print-object (obj))
+(defmethod print-object ((obj <uuid>))
+  (format (standard-output) ""))
+(defun main ()
+  (let ((u (create (class <uuid>))))
+    (format (standard-output) "(create (class <uuid>)): ")
+    (print-object u)))
+(provide "uuid")
+(main)