summaryrefslogtreecommitdiff
path: root/src/util.lisp
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2024-06-01 11:06:53 -0700
committercolin <colin@cicadas.surf>2024-06-01 11:06:53 -0700
commit1ff8ffb793a988de0bea7b3c7e663886801e9ce9 (patch)
tree012617eb72e51adf6501e8074ab1416202a6f260 /src/util.lisp
parent4c7cc04c6c23d8d84295d9d4ed446521597d7e6d (diff)
Add: types.lisp, singletonc lasses, debugging instr.lisp
Diffstat (limited to 'src/util.lisp')
-rw-r--r--src/util.lisp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util.lisp b/src/util.lisp
index 5899b36..e561778 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -82,3 +82,23 @@ CLASS-OPTIONS is a PLIST of class options."
`(defclass ,name ,supers
(,@slot-defs)
,@options))))
+
+;;; SINGLETON CLASSES
+
+(defclass singleton (closer-mop:standard-class)
+ ((instance :reader singleton-instance
+ :initarg :instance
+ :documentation "The instance of a singleton class."))
+ (:documentation "Metaclass for singleton classes."))
+
+
+(defmethod closer-mop:validate-superclass
+ ((sub singleton) (sup closer-mop:standard-class))
+ t)
+
+(defmethod make-instance ((class singleton) &rest kwargs)
+ (declare (ignorable kwargs))
+ (if (slot-boundp class 'instance)
+ (slot-value class 'instance)
+ (setf (slot-value class 'instance) (call-next-method))))
+