-;;; FIXME: could be SB!XC:DEFMACRO inside EVAL-WHEN (COMPILE EVAL)
-(defmacro get-cmt-entry (char rt)
- `(the function
- (elt (the simple-vector (character-macro-table ,rt))
- (char-code ,char))))
-
-(defun set-cmt-entry (char newvalue &optional (rt *readtable*))
- (setf (elt (the simple-vector (character-macro-table rt))
- (char-code char))
- (coerce newvalue 'function)))
+;;; the value actually stored in the character macro table. As per
+;;; ANSI #'GET-MACRO-CHARACTER and #'SET-MACRO-CHARACTER, this can
+;;; be either a function or NIL.
+(eval-when (:compile-toplevel :execute)
+ (sb!xc:defmacro get-raw-cmt-entry (char readtable)
+ `(svref (character-macro-table ,readtable)
+ (char-code ,char))))
+
+;;; the value represented by whatever is stored in the character macro
+;;; table. As per ANSI #'GET-MACRO-CHARACTER and #'SET-MACRO-CHARACTER,
+;;; a function value represents itself, and a NIL value represents the
+;;; default behavior.
+(defun get-coerced-cmt-entry (char readtable)
+ (the function
+ (or (get-raw-cmt-entry char readtable)
+ #'read-token)))
+
+(defun set-cmt-entry (char new-value-designator &optional (rt *readtable*))
+ (setf (svref (character-macro-table rt)
+ (char-code char))
+ (and new-value-designator
+ (%coerce-callable-to-fun new-value-designator))))