Commit | Line | Data |
---|---|---|
53a346c2 VS |
1 | ;; Tracing macro courtesy of William Halliburton |
2 | ;; <whalliburton@gmail.com>, logs to Firebug console | |
3 | ||
4 | ;; On a happier note here is a macro I wrote to enable | |
5 | ;; tracing-ala-cl. Works with firebug. You'll need to (defvar | |
6 | ;; *trace-level*). I don't do indentation but that would be an easy | |
7 | ;; addition. | |
8 | ||
9 | (defpsmacro console (&rest rest) | |
10 | `(console.log ,@rest)) | |
11 | ||
12 | (defpsmacro defun-trace (name args &rest body) | |
13 | (let* ((sname (ps::symbol-to-js name)) | |
14 | (tname (ps-gensym name)) | |
15 | (arg-names (loop for arg in args | |
16 | unless (eq arg '&optional) | |
17 | collect (if (consp arg) (car arg) arg))) | |
18 | (argpairs | |
19 | (loop for arg in arg-names | |
20 | nconc (list (ps::symbol-to-js arg) arg)))) | |
21 | `(progn | |
22 | (defun ,name ,arg-names | |
23 | (console *trace-level* ,sname ":" ,@argpairs) | |
24 | (incf *trace-level*) | |
25 | (let* ((rtn (,tname ,@arg-names))) | |
26 | (decf *trace-level*) | |
27 | (console *trace-level* ,sname "returned" rtn) | |
28 | (return rtn))) | |
29 | (defun ,tname ,args | |
30 | ,@body)))) |