Merge pull request #33 from jasom/ps-dom-fixes
[parenscript.git] / extras / firebug-tracing.lisp
blobb974d3935b607a6cbb050573551122a4586fffe3
1 ;; Tracing macro courtesy of William Halliburton
2 ;; <whalliburton@gmail.com>, logs to Firebug console
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.
9 (defpsmacro console (&rest rest)
10 `(console.log ,@rest))
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))))