-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.lisp
executable file
·48 lines (43 loc) · 1.1 KB
/
trace.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;;;; Hey, Emacs, this is a -*- Mode: Lisp; Syntax: Common-Lisp -*- file!
;;;;
;;;; Lisp is a programmable programming language.
;;;; -- John Foderaro
;;;;
;;;; Name: trace.lisp
;;;;
;;;; Started: Sun Jan 16 20:13:03 2022
;;;; Modifications:
;;;;
;;;; Purpose:
;;;; Slade's macro tracing mechanism. 见 notes 467 页
;;;;
;;;;
;;;; Calling Sequence:
;;;;
;;;;
;;;; Inputs:
;;;;
;;;; Outputs:
;;;;
;;;; Example:
;;;;
;;;; Notes:
;;;;
;;;;
(defvar *macro-trace-list* '())
(defmacro macro-trace (&optional macro)
(if macro
`(pushnew ',macro *macro-trace-list*)
'*macro-trace-list*))
(defmacro macro-untrace (&optional macro)
(if macro
`(setf *macro-trace-list* (delete ',macro *macro-trace-list*))
'(setf *macro-trace-list* '())))
(defun hook (expander form env)
(if (member (first form) *macro-trace-list*)
(progn (format t "Trace: ~S~%" form)
(let ((result (funcall expander form env)))
(format t "Result: ~S~%" result)
result))
(funcall expander form env)))
(setf *macroexpand-hook* #'hook)