c64-livecoding/wip-duuqnd/user-side-compiler/reference.lisp

36 lines
1.3 KiB
Common Lisp

(in-package #:user-side-compiler)
(defclass reference ()
((%name :accessor name :initarg :name)))
(defgeneric ref-constantp (reference) (:method (reference) nil))
(defclass reference-constant (reference)
((%value :accessor ref-value :initarg :value)))
(defmethod ref-constantp ((reference reference-constant))
t)
(defmethod print-object ((object reference-constant) stream)
(print-unreadable-object (object stream :type t)
(format stream "~A" (if (slot-boundp object '%value)
(ref-value object)
"?"))))
(defmethod ref= ((a reference-constant) (b reference-constant))
(= (value a) (value b)))
(defclass reference-variable (reference)
((%index :accessor ref-index :initarg :index)))
(defmethod print-object ((object reference-variable) stream)
(print-unreadable-object (object stream :type t)
(when (slot-boundp object '%name)
(write-string (name object) stream))
(when (and (slot-boundp object '%name) (slot-boundp object '%index))
(write-string " " stream))
(when (slot-boundp object '%index)
(format stream "@~A" (ref-index object)))))
(define-transformation (ref (reference-constant reference)) ref)
(define-transformation (ref (reference-variable reference)) ref)