Added William Halliburton <whalliburton@gmail.com>'s tracing macro to extras folder.
authorVladimir Sedach <vsedach@gmail.com>
Sun, 7 Dec 2008 22:12:12 +0000 (15:12 -0700)
committerVladimir Sedach <vsedach@gmail.com>
Sun, 7 Dec 2008 22:12:12 +0000 (15:12 -0700)
extras/firebug-tracing.cl [new file with mode: 0644]

diff --git a/extras/firebug-tracing.cl b/extras/firebug-tracing.cl
new file mode 100644 (file)
index 0000000..b974d39
--- /dev/null
@@ -0,0 +1,30 @@
+;; Tracing macro courtesy of William Halliburton
+;; <whalliburton@gmail.com>, logs to Firebug console
+
+;; On a happier note here is a macro I wrote to enable
+;; tracing-ala-cl. Works with firebug. You'll need to (defvar
+;; *trace-level*). I don't do indentation but that would be an easy
+;; addition.
+
+(defpsmacro console (&rest rest)
+  `(console.log ,@rest))
+
+(defpsmacro defun-trace (name args &rest body)
+  (let* ((sname (ps::symbol-to-js name))
+         (tname (ps-gensym name))
+         (arg-names (loop for arg in args
+                       unless (eq arg '&optional)
+                       collect (if (consp arg) (car arg) arg)))
+         (argpairs
+          (loop for arg in arg-names
+             nconc (list (ps::symbol-to-js arg) arg))))
+    `(progn
+       (defun ,name ,arg-names
+         (console *trace-level* ,sname ":" ,@argpairs)
+         (incf *trace-level*)
+         (let* ((rtn (,tname ,@arg-names)))
+           (decf *trace-level*)
+           (console *trace-level* ,sname "returned" rtn)
+           (return rtn)))
+       (defun ,tname ,args
+         ,@body))))
\ No newline at end of file