3 ;; JSCL is free software: you can redistribute it and/or
4 ;; modify it under the terms of the GNU General Public License as
5 ;; published by the Free Software Foundation, either version 3 of the
6 ;; License, or (at your option) any later version.
8 ;; JSCL is distributed in the hope that it will be useful, but
9 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;; General Public License for more details.
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with JSCL. If not, see <http://www.gnu.org/licenses/>.
16 (defparameter *features* '(:jscl :common-lisp))
18 (defun lisp-implementation-type ()
22 (let ((start (gensym))
24 `(let ((,start (get-internal-real-time))
27 (setq ,end (get-internal-real-time))
28 (format t "Execution took ~a seconds.~%" (/ (- ,end ,start) 1000.0))))))
33 ;;; This trace implementation works on symbols, replacing the function
34 ;;; with a wrapper. So it will not trace calls to the function if they
35 ;;; got the function object before it was traced.
37 ;;; An alist of the form (NAME FUNCTION), where NAME is the name of a
38 ;;; function, and FUNCTION is the function traced.
39 (defvar *traced-functions* nil)
40 (defvar *trace-level* 0)
42 (defun trace-report-call (name args)
43 (dotimes (i *trace-level*) (write-string " "))
44 (format t "~a: ~S~%" *trace-level* (cons name args)))
46 (defun trace-report-return (name values)
47 (dotimes (i *trace-level*) (write-string " "))
48 (format t "~a: ~S returned " *trace-level* name)
49 (dolist (value values) (format t "~S " value))
52 (defun trace-functions (names)
54 (mapcar #'car *traced-functions*)
55 (dolist (name names names)
56 (if (find name *traced-functions* :key #'car)
57 (format t "`~S' is already traced.~%" name)
58 (let ((func (fdefinition name)))
59 (fset name (lambda (&rest args)
61 (trace-report-call name args)
62 (let ((*trace-level* (+ *trace-level* 1)))
63 (setq values (multiple-value-list (apply func args))))
64 (trace-report-return name values)
65 (values-list values))))
66 (push (cons name func) *traced-functions*))))))
68 (defun untrace-functions (names)
70 (setq names (mapcar #'car *traced-functions*)))
72 (let ((func (cdr (find name *traced-functions* :key #'car))))
75 (format t "~S is not being traced.~%" name)))))
77 (defmacro trace (&rest names)
78 `(trace-functions ',names))
80 (defmacro untrace (&rest names)
81 `(untrace-functions ',names))