4 ;;; LispWorks ILISP initializations.
6 ;;; Independently written by:
8 ;;; Jason Trenouth: jason@harlequin.co.uk
9 ;;; Qiegang Long: qlong@cs.umass.edu
11 ;;; and later merged together by Jason.
13 ;;; This file is part of ILISP.
14 ;;; Please refer to the file COPYING for copyrights and licensing
16 ;;; Please refer to the file ACKNOWLEGDEMENTS for an (incomplete) list
17 ;;; of present and past contributors.
19 ;;; $Id: lispworks.lisp,v 1.4 2002-05-30 13:59:20 wbd Exp $
23 ;; Make LispWorks interactive
25 (setf system::*force-top-level* t)
32 ;;; 19990806 Unknown Author (blame Marco Antoniotti for this)
34 (defun ilisp-eval (form package filename)
35 "Evaluate FORM in PACKAGE recording FILENAME as the source file."
36 (let ((*package* (ilisp-find-package package))
37 #+LispWorks3 (compiler::*input-pathname* (merge-pathnames filename))
38 #+LispWorks3 (compiler::*warn-on-non-top-level-defun* nil)
41 (eval (read-from-string form))
43 (dspec:at-location ((or (probe-file filename) (merge-pathnames filename)))
44 (eval (read-from-string form)))))
51 ;;; 19990806 Unknown Author (blame Marco Antoniotti for this)
53 (defun ilisp-trace (symbol package breakp)
54 "Trace SYMBOL in PACKAGE."
55 (declare (ignorable breakp))
57 (let ((real-symbol (ilisp-find-symbol symbol package)))
58 (when real-symbol (eval `(trace (,real-symbol :break ,breakp)))))))
61 (defun ilisp-callers (symbol package)
62 "Print a list of all of the functions that call FUNCTION.
63 Returns T if successful."
65 (let ((function-name (ilisp-find-symbol symbol package))
68 (*package* (find-package 'lisp))
71 (when (and function-name (fboundp function-name))
72 (setf callers (munge-who-calls
73 #+(or :lispworks3 :lispworks4) (hcl:who-calls function-name)
74 #-(or :lispworks3 :lispworks4) (lw:who-calls function-name)
76 (dolist (caller callers)
80 ;; gross hack to munge who-calls output for ILISP
81 (defun munge-who-calls (who-calls)
82 (labels ((top-level-caller (form)
85 (top-level-caller (second form)))))
86 (delete-if-not 'symbolp
87 (delete-duplicates (mapcar #'top-level-caller who-calls)))))
90 ;; Jason 6 SEP 94 -- tabularized Qiegang's code
92 ;; There are some problems lurking here:
93 ;; - the mapping ought to be done by LispWorks
94 ;; - surely you really want just three source types:
95 ;; function, type, and variable
97 (defconstant *source-type-translations*
102 ("structure" defstruct)
105 ("variable" defvar defparameter defconstant)
109 (defun translate-source-type-to-dspec (symbol type)
110 (let ((entry (find type *source-type-translations*
111 :key 'first :test 'equal)))
113 (let ((wrappers (rest entry)))
115 (loop for wrap in wrappers collecting `(,wrap ,symbol))
117 (error "unknown source type for ~S requested from ILISP: ~S"
121 (defun ilisp-source-files (symbol package type)
122 "Print each file for PACKAGE:SYMBOL's TYPE definition on a line.
123 Returns T if successful."
124 ;; A function to limit the search with type?
126 (let* ((symbol (ilisp-find-symbol symbol package))
127 (all (equal type "any"))
129 ;; 19990806 Marco Antoniotti
131 ;; (paths (when symbol (compiler::find-source-file symbol)))
132 (paths (when symbol (dspec:find-dspec-locations symbol)))
133 (dspecs (or all (translate-source-type-to-dspec symbol type)))
136 (if (and paths (not all))
138 (loop for path in paths
139 when (find (car path) dspecs :test 'equal)
144 (dolist (file (remove-duplicates paths
145 :key #'cdr :test #'equal))
146 (print (truename (cadr file))))
150 ;;; sys::get-top-loop-handler, sys::define-top-loop-handler --
154 ;;; 19990806 Unknown Author (blame Marco Antoniotti for this)
156 ;;; 19990806 Marco Antoniotti
157 ;;; I decided to leave these in, although they are a little too system
158 ;;; dependent. I will remove them if people complain.
160 (eval-when (:compile-toplevel :load-toplevel :execute)
161 (unless (fboundp 'sys::define-top-loop-handler)
163 ;; Duplicated from ccl/top-loop.lisp
164 (defmacro sys::get-top-loop-handler (command-name)
165 `(get ,command-name 'sys::top-loop-handler))
167 (defmacro sys::define-top-loop-handler (name &body body)
168 (lw:with-unique-names (top-loop-handler)
169 `(let ((,top-loop-handler #'(lambda (sys::line) ,@body)))
170 (mapc #'(lambda (name)
171 (setf (sys::get-top-loop-handler name) ,top-loop-handler))
172 (if (consp ',name) ',name '(,name))))))))
174 (sys::define-top-loop-handler :ilisp-send
175 (values (multiple-value-list (eval (cadr sys::line))) nil))
178 (eval-when (load eval)
179 (unless (compiled-function-p #'ilisp-callers)
180 (ilisp-message t "File is not compiled, use M-x ilisp-compile-inits")))
182 ;;; end of file -- lispworks.lisp --