/[slime]/slime/swank-lispworks.lisp
ViewVC logotype

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.110 - (hide annotations)
Sat Aug 9 19:57:00 2008 UTC (5 years, 8 months ago) by heller
Branch: MAIN
Changes since 1.109: +18 -17 lines
Display the "Use default debugger" restart more prominently.

* swank.lisp (swank-debugger-hook): Bind a user visible restart
to invoke the native debugger.
(*global-debugger*): Make this nil by default.
(sldb-loop): Minor cleanups.
(sldb-break-with-default-debugger): Invoke the native debugger
on top of the slime debugger.

* slime.el (sldb-setup): Always pop to the debugger buffer.
(sldb-activate): Optionally select the window.

* swank-sbcl.lisp (sb-thread::get-foreground): Override this
as the default implementation is unusable for Slime.

* swank-lispworks.lisp (environment-display-notifier): Just
return t.
1 heller 1.74 ;;; -*- indent-tabs-mode: nil -*-
2 heller 1.1 ;;;
3     ;;; swank-lispworks.lisp --- LispWorks specific code for SLIME.
4     ;;;
5     ;;; Created 2003, Helmut Eller
6     ;;;
7     ;;; This code has been placed in the Public Domain. All warranties
8     ;;; are disclaimed.
9     ;;;
10    
11 heller 1.30 (in-package :swank-backend)
12 heller 1.1
13     (eval-when (:compile-toplevel :load-toplevel :execute)
14 heller 1.79 (require "comm")
15     (import-from :stream *gray-stream-symbols* :swank-backend))
16 heller 1.1
17 heller 1.62 (import-swank-mop-symbols :clos '(:slot-definition-documentation
18     :eql-specializer
19 heller 1.65 :eql-specializer-object
20     :compute-applicable-methods-using-classes))
21 msimmons 1.57
22     (defun swank-mop:slot-definition-documentation (slot)
23     (documentation slot t))
24 mbaringer 1.59
25 heller 1.65 (defun swank-mop:compute-applicable-methods-using-classes (gf classes)
26     (clos::compute-applicable-methods-from-classes gf classes))
27    
28     ;; lispworks doesn't have the eql-specializer class, it represents
29     ;; them as a list of `(EQL ,OBJECT)
30 mbaringer 1.59 (deftype swank-mop:eql-specializer () 'cons)
31    
32     (defun swank-mop:eql-specializer-object (eql-spec)
33     (second eql-spec))
34 msimmons 1.57
35 heller 1.55 (when (fboundp 'dspec::define-dspec-alias)
36     (dspec::define-dspec-alias defimplementation (name args &rest body)
37 heller 1.107 `(defun ,name ,args ,@body)))
38 heller 1.49
39 heller 1.13 ;;; TCP server
40 lgorrie 1.12
41 heller 1.30 (defimplementation preferred-communication-style ()
42     :spawn)
43 heller 1.18
44 heller 1.13 (defun socket-fd (socket)
45     (etypecase socket
46     (fixnum socket)
47     (comm:socket-stream (comm:socket-stream-socket socket))))
48    
49 heller 1.22 (defimplementation create-socket (host port)
50 heller 1.13 (multiple-value-bind (socket where errno)
51 msimmons 1.64 #-(or lispworks4.1 (and macosx lispworks4.3))
52     (comm::create-tcp-socket-for-service port :address host)
53     #+(or lispworks4.1 (and macosx lispworks4.3))
54     (comm::create-tcp-socket-for-service port)
55 heller 1.13 (cond (socket socket)
56 heller 1.14 (t (error 'network-error
57 heller 1.13 :format-control "~A failed: ~A (~D)"
58     :format-arguments (list where
59     (list #+unix (lw:get-unix-error errno))
60 heller 1.14 errno))))))
61 heller 1.13
62 lgorrie 1.17 (defimplementation local-port (socket)
63 heller 1.13 (nth-value 1 (comm:get-socket-address (socket-fd socket))))
64    
65 lgorrie 1.17 (defimplementation close-socket (socket)
66 heller 1.13 (comm::close-socket (socket-fd socket)))
67    
68 heller 1.63 (defimplementation accept-connection (socket
69 heller 1.85 &key external-format buffering timeout)
70 heller 1.88 (declare (ignore buffering timeout external-format))
71 heller 1.61 (let* ((fd (comm::get-fd-from-socket socket)))
72 heller 1.13 (assert (/= fd -1))
73     (make-instance 'comm:socket-stream :socket fd :direction :io
74     :element-type 'base-char)))
75    
76 heller 1.37 (defun set-sigint-handler ()
77     ;; Set SIGINT handler on Swank request handler thread.
78     #-win32
79     (sys::set-signal-handler +sigint+
80     (make-sigint-handler mp:*current-process*)))
81    
82 heller 1.88 ;;; Coding Systems
83    
84     (defvar *external-format-to-coding-system*
85     '(((:latin-1 :eol-style :lf)
86     "latin-1-unix" "iso-latin-1-unix" "iso-8859-1-unix")
87     ((:latin-1)
88     "latin-1" "iso-latin-1" "iso-8859-1")
89     ((:utf-8) "utf-8")
90     ((:utf-8 :eol-style :lf) "utf-8-unix")
91     ((:euc-jp) "euc-jp")
92     ((:euc-jp :eol-style :lf) "euc-jp-unix")
93     ((:ascii) "us-ascii")
94     ((:ascii :eol-style :lf) "us-ascii-unix")))
95    
96     (defimplementation find-external-format (coding-system)
97     (car (rassoc-if (lambda (x) (member coding-system x :test #'equal))
98     *external-format-to-coding-system*)))
99    
100 heller 1.15 ;;; Unix signals
101    
102 heller 1.18 (defun sigint-handler ()
103 heller 1.16 (with-simple-restart (continue "Continue from SIGINT handler.")
104     (invoke-debugger "SIGINT")))
105 heller 1.1
106 heller 1.18 (defun make-sigint-handler (process)
107     (lambda (&rest args)
108     (declare (ignore args))
109     (mp:process-interrupt process #'sigint-handler)))
110    
111 heller 1.38 (defimplementation call-without-interrupts (fn)
112 heller 1.37 (lw:without-interrupts (funcall fn)))
113 heller 1.48
114 heller 1.29 (defimplementation getpid ()
115     #+win32 (win32:get-current-process-id)
116     #-win32 (system::getpid))
117 heller 1.1
118 heller 1.23 (defimplementation lisp-implementation-type-name ()
119     "lispworks")
120    
121 heller 1.36 (defimplementation set-default-directory (directory)
122     (namestring (hcl:change-directory directory)))
123 heller 1.40
124     ;;;; Documentation
125 heller 1.36
126 msimmons 1.57 (defimplementation arglist (symbol-or-function)
127     (let ((arglist (lw:function-lambda-list symbol-or-function)))
128 heller 1.30 (etypecase arglist
129 heller 1.39 ((member :dont-know)
130     :not-available)
131     (list
132     arglist))))
133 msimmons 1.57
134     (defimplementation function-name (function)
135     (nth-value 2 (function-lambda-expression function)))
136 heller 1.1
137 lgorrie 1.17 (defimplementation macroexpand-all (form)
138 heller 1.1 (walker:walk-form form))
139    
140 heller 1.37 (defun generic-function-p (object)
141 heller 1.36 (typep object 'generic-function))
142    
143 lgorrie 1.17 (defimplementation describe-symbol-for-emacs (symbol)
144 heller 1.1 "Return a plist describing SYMBOL.
145     Return NIL if the symbol is unbound."
146     (let ((result '()))
147     (labels ((first-line (string)
148     (let ((pos (position #\newline string)))
149     (if (null pos) string (subseq string 0 pos))))
150     (doc (kind &optional (sym symbol))
151     (let ((string (documentation sym kind)))
152     (if string
153     (first-line string)
154     :not-documented)))
155     (maybe-push (property value)
156     (when value
157     (setf result (list* property value result)))))
158     (maybe-push
159     :variable (when (boundp symbol)
160     (doc 'variable)))
161     (maybe-push
162 heller 1.36 :generic-function (if (and (fboundp symbol)
163 heller 1.37 (generic-function-p (fdefinition symbol)))
164 heller 1.36 (doc 'function)))
165     (maybe-push
166     :function (if (and (fboundp symbol)
167 heller 1.37 (not (generic-function-p (fdefinition symbol))))
168 heller 1.1 (doc 'function)))
169     (maybe-push
170 heller 1.49 :setf (let ((setf-name (sys:underlying-setf-name `(setf ,symbol))))
171     (if (fboundp setf-name)
172     (doc 'setf))))
173     (maybe-push
174 heller 1.1 :class (if (find-class symbol nil)
175     (doc 'class)))
176 heller 1.30 result)))
177 heller 1.1
178 heller 1.30 (defimplementation describe-definition (symbol type)
179     (ecase type
180     (:variable (describe-symbol symbol))
181     (:class (describe (find-class symbol)))
182 heller 1.49 ((:function :generic-function) (describe-function symbol))
183     (:setf (describe-function (sys:underlying-setf-name `(setf ,symbol))))))
184 heller 1.30
185     (defun describe-function (symbol)
186     (cond ((fboundp symbol)
187     (format t "~%(~A~{ ~A~})~%~%~:[(not documented)~;~:*~A~]~%"
188     (string-downcase symbol)
189     (mapcar #'string-upcase
190     (lispworks:function-lambda-list symbol))
191     (documentation symbol 'function))
192 heller 1.38 (describe (fdefinition symbol)))
193 heller 1.30 (t (format t "~S is not fbound" symbol))))
194 heller 1.4
195 heller 1.30 (defun describe-symbol (sym)
196 heller 1.1 (format t "~A is a symbol in package ~A." sym (symbol-package sym))
197     (when (boundp sym)
198     (format t "~%~%Value: ~A" (symbol-value sym)))
199     (let ((doc (documentation sym 'variable)))
200     (when doc
201     (format t "~%~%Variable documentation:~%~A" doc)))
202     (when (fboundp sym)
203 heller 1.30 (describe-function sym)))
204 heller 1.1
205     ;;; Debugging
206    
207 heller 1.66 (defclass slime-env (env:environment)
208     ((debugger-hook :initarg :debugger-hoook)))
209    
210     (defun slime-env (hook io-bindings)
211     (make-instance 'slime-env :name "SLIME Environment"
212     :io-bindings io-bindings
213     :debugger-hoook hook))
214    
215     (defmethod env-internals:environment-display-notifier
216     ((env slime-env) &key restarts condition)
217     (declare (ignore restarts))
218     (funcall (slot-value env 'debugger-hook) condition *debugger-hook*))
219    
220     (defmethod env-internals:environment-display-debugger ((env slime-env))
221     *debug-io*)
222    
223 heller 1.110 (defimplementation call-with-debugger-hook (hook fun)
224     (let ((*debugger-hook* hook))
225     (env:with-environment ((slime-env hook '()))
226     (funcall fun))))
227 heller 1.66
228 msimmons 1.100 (defimplementation install-debugger-globally (function)
229     (setq *debugger-hook* function)
230     (setf (env:environment) (slime-env function '())))
231    
232 heller 1.110 (defmethod env-internals:environment-display-notifier
233     ((env slime-env) &key restarts condition)
234     (declare (ignore restarts))
235     ;;(funcall (swank-sym :swank-debugger-hook) condition *debugger-hook*)
236     (values t nil)
237     )
238    
239     (defmethod env-internals:environment-display-debugger ((env slime-env))
240     *debug-io*)
241    
242     (defmethod env-internals:confirm-p ((e slime-env) &optional msg &rest args)
243     (apply (swank-sym :y-or-n-p-in-emacs) msg args))
244    
245 heller 1.26 (defvar *sldb-top-frame*)
246 heller 1.1
247     (defun interesting-frame-p (frame)
248 heller 1.36 (cond ((or (dbg::call-frame-p frame)
249     (dbg::derived-call-frame-p frame)
250     (dbg::foreign-frame-p frame)
251     (dbg::interpreted-call-frame-p frame))
252     t)
253     ((dbg::catch-frame-p frame) dbg:*print-catch-frames*)
254     ((dbg::binding-frame-p frame) dbg:*print-binding-frames*)
255     ((dbg::handler-frame-p frame) dbg:*print-handler-frames*)
256     ((dbg::restart-frame-p frame) dbg:*print-restart-frames*)
257     ((dbg::open-frame-p frame) dbg:*print-open-frames*)
258     (t nil)))
259 heller 1.1
260 heller 1.41 (defun nth-next-frame (frame n)
261     "Unwind FRAME N times."
262     (do ((frame frame (dbg::frame-next frame))
263     (i n (if (interesting-frame-p frame) (1- i) i)))
264 heller 1.48 ((or (not frame)
265     (and (interesting-frame-p frame) (zerop i)))
266     frame)))
267 heller 1.41
268     (defun nth-frame (index)
269     (nth-next-frame *sldb-top-frame* index))
270    
271     (defun find-top-frame ()
272     "Return the most suitable top-frame for the debugger."
273 mbaringer 1.69 (or (do ((frame (dbg::debugger-stack-current-frame dbg::*debugger-stack*)
274     (nth-next-frame frame 1)))
275     ((or (null frame) ; no frame found!
276     (and (dbg::call-frame-p frame)
277     (eq (dbg::call-frame-function-name frame)
278     'invoke-debugger)))
279     (nth-next-frame frame 1)))
280     ;; if we can't find a invoke-debugger frame, take any old frame at the top
281     (dbg::debugger-stack-current-frame dbg::*debugger-stack*)))
282 heller 1.41
283     (defimplementation call-with-debugging-environment (fn)
284     (dbg::with-debugger-stack ()
285     (let ((*sldb-top-frame* (find-top-frame)))
286     (funcall fn))))
287 heller 1.1
288 heller 1.30 (defimplementation compute-backtrace (start end)
289 heller 1.1 (let ((end (or end most-positive-fixnum))
290     (backtrace '()))
291     (do ((frame (nth-frame start) (dbg::frame-next frame))
292     (i start))
293     ((or (not frame) (= i end)) (nreverse backtrace))
294     (when (interesting-frame-p frame)
295     (incf i)
296     (push frame backtrace)))))
297    
298 heller 1.36 (defun frame-actual-args (frame)
299 heller 1.50 (let ((*break-on-signals* nil))
300     (mapcar (lambda (arg)
301     (case arg
302     ((&rest &optional &key) arg)
303     (t
304     (handler-case (dbg::dbg-eval arg frame)
305 msimmons 1.53 (error (e) (format nil "<~A>" arg))))))
306 heller 1.50 (dbg::call-frame-arglist frame))))
307 heller 1.36
308 heller 1.30 (defimplementation print-frame (frame stream)
309     (cond ((dbg::call-frame-p frame)
310 heller 1.36 (format stream "~S ~S"
311 heller 1.30 (dbg::call-frame-function-name frame)
312 heller 1.36 (frame-actual-args frame)))
313 heller 1.30 (t (princ frame stream))))
314 heller 1.1
315 heller 1.47 (defun frame-vars (frame)
316     (first (dbg::frame-locals-format-list frame #'list 75 0)))
317    
318 lgorrie 1.17 (defimplementation frame-locals (n)
319 heller 1.29 (let ((frame (nth-frame n)))
320 heller 1.1 (if (dbg::call-frame-p frame)
321 heller 1.47 (mapcar (lambda (var)
322     (destructuring-bind (name value symbol location) var
323     (declare (ignore name location))
324     (list :name symbol :id 0
325     :value value)))
326     (frame-vars frame)))))
327    
328     (defimplementation frame-var-value (frame var)
329     (let ((frame (nth-frame frame)))
330     (destructuring-bind (_n value _s _l) (nth var (frame-vars frame))
331     (declare (ignore _n _s _l))
332     value)))
333 heller 1.1
334 lgorrie 1.17 (defimplementation frame-catch-tags (index)
335 heller 1.1 (declare (ignore index))
336     nil)
337    
338 lgorrie 1.17 (defimplementation frame-source-location-for-emacs (frame)
339 heller 1.60 (let ((frame (nth-frame frame))
340     (callee (if (plusp frame) (nth-frame (1- frame)))))
341 heller 1.1 (if (dbg::call-frame-p frame)
342 heller 1.60 (let ((dspec (dbg::call-frame-function-name frame))
343     (cname (and (dbg::call-frame-p callee)
344     (dbg::call-frame-function-name callee))))
345     (if dspec
346     (frame-location dspec cname))))))
347 heller 1.26
348     (defimplementation eval-in-frame (form frame-number)
349     (let ((frame (nth-frame frame-number)))
350     (dbg::dbg-eval form frame)))
351    
352     (defimplementation return-from-frame (frame-number form)
353     (let* ((frame (nth-frame frame-number))
354 heller 1.30 (return-frame (dbg::find-frame-for-return frame)))
355 heller 1.26 (dbg::dbg-return-from-call-frame frame form return-frame
356     dbg::*debugger-stack*)))
357    
358     (defimplementation restart-frame (frame-number)
359     (let ((frame (nth-frame frame-number)))
360     (dbg::restart-frame frame :same-args t)))
361 heller 1.1
362 heller 1.109 (defimplementation disassemble-frame (frame-number)
363     (let* ((frame (nth-frame frame-number)))
364     (when (dbg::call-frame-p frame)
365     (let ((function (dbg::get-call-frame-function frame)))
366     (disassemble function)))))
367    
368 heller 1.18 ;;; Definition finding
369    
370 heller 1.60 (defun frame-location (dspec callee-name)
371     (let ((infos (dspec:find-dspec-locations dspec)))
372     (cond (infos
373     (destructuring-bind ((rdspec location) &rest _) infos
374     (declare (ignore _))
375     (let ((name (and callee-name (symbolp callee-name)
376     (string callee-name))))
377     (make-dspec-location rdspec location
378     `(:call-site ,name)))))
379     (t
380     (list :error (format nil "Source location not available for: ~S"
381     dspec))))))
382 heller 1.4
383 heller 1.33 (defimplementation find-definitions (name)
384 heller 1.26 (let ((locations (dspec:find-name-locations dspec:*dspec-classes* name)))
385 heller 1.33 (loop for (dspec location) in locations
386     collect (list dspec (make-dspec-location dspec location)))))
387 heller 1.6
388 msimmons 1.56
389 heller 1.18 ;;; Compilation
390    
391 msimmons 1.42 (defmacro with-swank-compilation-unit ((location &rest options) &body body)
392     (lw:rebinding (location)
393     `(let ((compiler::*error-database* '()))
394     (with-compilation-unit ,options
395     ,@body
396     (signal-error-data-base compiler::*error-database* ,location)
397     (signal-undefined-functions compiler::*unknown-functions* ,location)))))
398    
399 heller 1.88 (defimplementation swank-compile-file (filename load-p external-format)
400 msimmons 1.42 (with-swank-compilation-unit (filename)
401 heller 1.88 (compile-file filename :load load-p :external-format external-format)))
402 msimmons 1.56
403 eweitz 1.70 (defvar *within-call-with-compilation-hooks* nil
404     "Whether COMPILE-FILE was called from within CALL-WITH-COMPILATION-HOOKS.")
405    
406     (defvar *undefined-functions-hash* nil
407     "Hash table to map info about undefined functions to pathnames.")
408    
409     (lw:defadvice (compile-file compile-file-and-collect-notes :around)
410     (pathname &rest rest)
411 msimmons 1.75 (multiple-value-prog1 (apply #'lw:call-next-advice pathname rest)
412 eweitz 1.70 (when *within-call-with-compilation-hooks*
413     (maphash (lambda (unfun dspecs)
414     (dolist (dspec dspecs)
415     (let ((unfun-info (list unfun dspec)))
416     (unless (gethash unfun-info *undefined-functions-hash*)
417     (setf (gethash unfun-info *undefined-functions-hash*)
418     pathname)))))
419     compiler::*unknown-functions*))))
420    
421 msimmons 1.56 (defimplementation call-with-compilation-hooks (function)
422 eweitz 1.70 (let ((compiler::*error-database* '())
423     (*undefined-functions-hash* (make-hash-table :test 'equal))
424     (*within-call-with-compilation-hooks* t))
425     (with-compilation-unit ()
426     (prog1 (funcall function)
427     (signal-error-data-base compiler::*error-database*)
428     (signal-undefined-functions compiler::*unknown-functions*)))))
429 heller 1.1
430     (defun map-error-database (database fn)
431     (loop for (filename . defs) in database do
432     (loop for (dspec . conditions) in defs do
433     (dolist (c conditions)
434 msimmons 1.98 (funcall fn filename dspec (if (consp c) (car c) c))))))
435 heller 1.1
436     (defun lispworks-severity (condition)
437     (cond ((not condition) :warning)
438     (t (etypecase condition
439 heller 1.6 (error :error)
440 heller 1.1 (style-warning :warning)
441     (warning :warning)))))
442    
443     (defun signal-compiler-condition (message location condition)
444     (check-type message string)
445     (signal
446     (make-instance 'compiler-condition :message message
447     :severity (lispworks-severity condition)
448     :location location
449     :original-condition condition)))
450    
451     (defun compile-from-temp-file (string filename)
452     (unwind-protect
453     (progn
454     (with-open-file (s filename :direction :output :if-exists :supersede)
455     (write-string string s)
456     (finish-output s))
457     (let ((binary-filename (compile-file filename :load t)))
458 heller 1.6 (when binary-filename
459     (delete-file binary-filename))))
460 heller 1.1 (delete-file filename)))
461    
462 heller 1.34 (defun dspec-buffer-position (dspec offset)
463     (etypecase dspec
464     (cons (let ((name (dspec:dspec-primary-name dspec)))
465 heller 1.37 (typecase name
466 heller 1.34 ((or symbol string)
467     (list :function-name (string name)))
468     (t (list :position offset)))))
469     (null (list :position offset))
470     (symbol (list :function-name (string dspec)))))
471 heller 1.18
472 lgorrie 1.45 (defmacro with-fairly-standard-io-syntax (&body body)
473     "Like WITH-STANDARD-IO-SYNTAX but preserve *PACKAGE* and *READTABLE*."
474     (let ((package (gensym))
475     (readtable (gensym)))
476     `(let ((,package *package*)
477     (,readtable *readtable*))
478     (with-standard-io-syntax
479     (let ((*package* ,package)
480     (*readtable* ,readtable))
481     ,@body)))))
482    
483 heller 1.52 #-(or lispworks4.1 lispworks4.2) ; no dspec:parse-form-dspec prior to 4.3
484 msimmons 1.42 (defun dspec-stream-position (stream dspec)
485 lgorrie 1.45 (with-fairly-standard-io-syntax
486 lgorrie 1.44 (loop (let* ((pos (file-position stream))
487     (form (read stream nil '#1=#:eof)))
488     (when (eq form '#1#)
489     (return nil))
490     (labels ((check-dspec (form)
491     (when (consp form)
492     (let ((operator (car form)))
493     (case operator
494     ((progn)
495     (mapcar #'check-dspec
496     (cdr form)))
497     ((eval-when locally macrolet symbol-macrolet)
498     (mapcar #'check-dspec
499     (cddr form)))
500     ((in-package)
501     (let ((package (find-package (second form))))
502     (when package
503     (setq *package* package))))
504     (otherwise
505     (let ((form-dspec (dspec:parse-form-dspec form)))
506     (when (dspec:dspec-equal dspec form-dspec)
507     (return pos)))))))))
508     (check-dspec form))))))
509 msimmons 1.42
510 heller 1.52 (defun dspec-file-position (file dspec)
511 mbaringer 1.90 (let* ((*compile-file-pathname* (pathname file))
512     (*compile-file-truename* (truename *compile-file-pathname*))
513     (*load-pathname* *compile-file-pathname*)
514     (*load-truename* *compile-file-truename*))
515     (with-open-file (stream file)
516     (let ((pos
517     #-(or lispworks4.1 lispworks4.2)
518     (dspec-stream-position stream dspec)))
519     (if pos
520     (list :position (1+ pos) t)
521     (dspec-buffer-position dspec 1))))))
522 heller 1.52
523 heller 1.25 (defun emacs-buffer-location-p (location)
524     (and (consp location)
525     (eq (car location) :emacs-buffer)))
526    
527 heller 1.60 (defun make-dspec-location (dspec location &optional hints)
528 heller 1.52 (etypecase location
529     ((or pathname string)
530     (multiple-value-bind (file err)
531     (ignore-errors (namestring (truename location)))
532     (if err
533     (list :error (princ-to-string err))
534     (make-location `(:file ,file)
535 heller 1.60 (dspec-file-position file dspec)
536     hints))))
537 heller 1.52 (symbol
538     `(:error ,(format nil "Cannot resolve location: ~S" location)))
539     ((satisfies emacs-buffer-location-p)
540     (destructuring-bind (_ buffer offset string) location
541     (declare (ignore _ string))
542     (make-location `(:buffer ,buffer)
543 heller 1.60 (dspec-buffer-position dspec offset)
544     hints)))))
545 heller 1.1
546 msimmons 1.42 (defun make-dspec-progenitor-location (dspec location)
547     (let ((canon-dspec (dspec:canonicalize-dspec dspec)))
548     (make-dspec-location
549     (if canon-dspec
550     (if (dspec:local-dspec-p canon-dspec)
551     (dspec:dspec-progenitor canon-dspec)
552     canon-dspec)
553     nil)
554     location)))
555    
556 eweitz 1.70 (defun signal-error-data-base (database &optional location)
557 heller 1.1 (map-error-database
558     database
559     (lambda (filename dspec condition)
560     (signal-compiler-condition
561     (format nil "~A" condition)
562 eweitz 1.70 (make-dspec-progenitor-location dspec (or location filename))
563 heller 1.1 condition))))
564    
565 eweitz 1.71 (defun unmangle-unfun (symbol)
566     "Converts symbols like 'SETF::|\"CL-USER\" \"GET\"| to
567     function names like \(SETF GET)."
568 heller 1.93 (cond ((sys::setf-symbol-p symbol)
569     (sys::setf-pair-from-underlying-name symbol))
570     (t symbol)))
571    
572 eweitz 1.70 (defun signal-undefined-functions (htab &optional filename)
573 heller 1.1 (maphash (lambda (unfun dspecs)
574     (dolist (dspec dspecs)
575     (signal-compiler-condition
576 eweitz 1.71 (format nil "Undefined function ~A" (unmangle-unfun unfun))
577 eweitz 1.70 (make-dspec-progenitor-location dspec
578     (or filename
579     (gethash (list unfun dspec)
580     *undefined-functions-hash*)))
581 heller 1.1 nil)))
582     htab))
583 heller 1.2
584 heller 1.99 (defimplementation swank-compile-string (string &key buffer position directory
585     debug)
586     (declare (ignore directory debug))
587 heller 1.1 (assert buffer)
588     (assert position)
589 heller 1.30 (let* ((location (list :emacs-buffer buffer position string))
590 heller 1.26 (tmpname (hcl:make-temp-file nil "lisp")))
591 msimmons 1.42 (with-swank-compilation-unit (location)
592 heller 1.26 (compile-from-temp-file
593 heller 1.68 (with-output-to-string (s)
594     (let ((*print-radix* t))
595     (print `(eval-when (:compile-toplevel)
596     (setq dspec::*location* (list ,@location)))
597     s))
598     (write-string string s))
599 msimmons 1.42 tmpname))))
600 heller 1.1
601 heller 1.3 ;;; xref
602    
603 heller 1.31 (defmacro defxref (name function)
604     `(defimplementation ,name (name)
605     (xref-results (,function name))))
606    
607     (defxref who-calls hcl:who-calls)
608 msimmons 1.42 (defxref who-macroexpands hcl:who-calls) ; macros are in the calls table too
609 heller 1.67 (defxref calls-who hcl:calls-who)
610 msimmons 1.42 (defxref list-callers list-callers-internal)
611 heller 1.68 ;; (defxref list-callees list-callees-internal)
612 msimmons 1.42
613     (defun list-callers-internal (name)
614     (let ((callers (make-array 100
615     :fill-pointer 0
616     :adjustable t)))
617     (hcl:sweep-all-objects
618     #'(lambda (object)
619     (when (and #+Harlequin-PC-Lisp (low:compiled-code-p object)
620     #-Harlequin-PC-Lisp (sys::callablep object)
621     (system::find-constant$funcallable name object))
622     (vector-push-extend object callers))))
623     ;; Delay dspec:object-dspec until after sweep-all-objects
624     ;; to reduce allocation problems.
625     (loop for object across callers
626     collect (if (symbolp object)
627     (list 'function object)
628 heller 1.63 (or (dspec:object-dspec object) object)))))
629 heller 1.36
630 heller 1.37 ;; only for lispworks 4.2 and above
631     #-lispworks4.1
632     (progn
633     (defxref who-references hcl:who-references)
634     (defxref who-binds hcl:who-binds)
635     (defxref who-sets hcl:who-sets))
636    
637 heller 1.36 (defimplementation who-specializes (classname)
638     (let ((methods (clos:class-direct-methods (find-class classname))))
639     (xref-results (mapcar #'dspec:object-dspec methods))))
640 heller 1.31
641     (defun xref-results (dspecs)
642 heller 1.63 (flet ((frob-locs (dspec locs)
643     (cond (locs
644     (loop for (name loc) in locs
645     collect (list name (make-dspec-location name loc))))
646     (t `((,dspec (:error "Source location not available")))))))
647     (loop for dspec in dspecs
648     append (frob-locs dspec (dspec:dspec-definition-locations dspec)))))
649 heller 1.66
650 heller 1.25 ;;; Inspector
651 mbaringer 1.58
652 heller 1.95 (defmethod emacs-inspect ((o t))
653 heller 1.60 (lispworks-inspect o))
654    
655 heller 1.95 (defmethod emacs-inspect ((o function))
656 heller 1.60 (lispworks-inspect o))
657    
658 heller 1.82 ;; FIXME: slot-boundp-using-class in LW works with names so we can't
659     ;; use our method in swank.lisp.
660 heller 1.95 (defmethod emacs-inspect ((o standard-object))
661 heller 1.82 (lispworks-inspect o))
662    
663 heller 1.60 (defun lispworks-inspect (o)
664 heller 1.25 (multiple-value-bind (names values _getter _setter type)
665     (lw:get-inspector-values o nil)
666     (declare (ignore _getter _setter))
667 heller 1.60 (append
668     (label-value-line "Type" type)
669 msimmons 1.91 (loop for name in names
670     for value in values
671 heller 1.96 append (label-value-line name value)))))
672 heller 1.25
673 lgorrie 1.46 ;;; Miscellaneous
674    
675     (defimplementation quit-lisp ()
676     (lispworks:quit))
677    
678 heller 1.66 ;;; Tracing
679    
680     (defun parse-fspec (fspec)
681     "Return a dspec for FSPEC."
682     (ecase (car fspec)
683 heller 1.67 ((:defmethod) `(method ,(cdr fspec)))))
684 heller 1.66
685     (defun tracedp (dspec)
686     (member dspec (eval '(trace)) :test #'equal))
687    
688 heller 1.67 (defun toggle-trace-aux (dspec)
689 heller 1.66 (cond ((tracedp dspec)
690     (eval `(untrace ,dspec))
691     (format nil "~S is now untraced." dspec))
692     (t
693     (eval `(trace (,dspec)))
694     (format nil "~S is now traced." dspec))))
695    
696 heller 1.67 (defimplementation toggle-trace (fspec)
697     (toggle-trace-aux (parse-fspec fspec)))
698 heller 1.66
699 heller 1.16 ;;; Multithreading
700    
701 mbaringer 1.86 (defimplementation initialize-multiprocessing (continuation)
702 heller 1.87 (cond ((not mp::*multiprocessing*)
703     (push (list "Initialize SLIME" '() continuation)
704     mp:*initial-processes*)
705     (mp:initialize-multiprocessing))
706     (t (funcall continuation))))
707 heller 1.16
708 heller 1.18 (defimplementation spawn (fn &key name)
709 heller 1.38 (let ((mp:*process-initial-bindings*
710     (remove (find-package :cl)
711     mp:*process-initial-bindings*
712     :key (lambda (x) (symbol-package (car x))))))
713     (mp:process-run-function name () fn)))
714 heller 1.48
715     (defvar *id-lock* (mp:make-lock))
716     (defvar *thread-id-counter* 0)
717    
718     (defimplementation thread-id (thread)
719     (mp:with-lock (*id-lock*)
720     (or (getf (mp:process-plist thread) 'id)
721     (setf (getf (mp:process-plist thread) 'id)
722     (incf *thread-id-counter*)))))
723    
724     (defimplementation find-thread (id)
725     (find id (mp:list-all-processes)
726     :key (lambda (p) (getf (mp:process-plist p) 'id))))
727 heller 1.16
728 heller 1.21 (defimplementation thread-name (thread)
729     (mp:process-name thread))
730 heller 1.16
731 heller 1.21 (defimplementation thread-status (thread)
732     (format nil "~A ~D"
733     (mp:process-whostate thread)
734     (mp:process-priority thread)))
735 heller 1.16
736 heller 1.18 (defimplementation make-lock (&key name)
737 heller 1.16 (mp:make-lock :name name))
738    
739 heller 1.18 (defimplementation call-with-lock-held (lock function)
740 heller 1.16 (mp:with-lock (lock) (funcall function)))
741 heller 1.20
742     (defimplementation current-thread ()
743     mp:*current-process*)
744 heller 1.21
745     (defimplementation all-threads ()
746     (mp:list-all-processes))
747 heller 1.20
748     (defimplementation interrupt-thread (thread fn)
749     (mp:process-interrupt thread fn))
750 heller 1.25
751     (defimplementation kill-thread (thread)
752     (mp:process-kill thread))
753 heller 1.27
754     (defimplementation thread-alive-p (thread)
755     (mp:process-alive-p thread))
756 heller 1.20
757 heller 1.102 (defstruct (mailbox (:conc-name mailbox.))
758     (mutex (mp:make-lock :name "thread mailbox"))
759     (queue '() :type list))
760    
761 heller 1.20 (defvar *mailbox-lock* (mp:make-lock))
762    
763     (defun mailbox (thread)
764     (mp:with-lock (*mailbox-lock*)
765     (or (getf (mp:process-plist thread) 'mailbox)
766     (setf (getf (mp:process-plist thread) 'mailbox)
767 heller 1.102 (make-mailbox)))))
768 heller 1.20
769     (defimplementation receive ()
770 heller 1.107 (receive-if (constantly t)))
771 heller 1.101
772     (defimplementation receive-if (test)
773 heller 1.102 (let* ((mbox (mailbox mp:*current-process*))
774     (lock (mailbox.mutex mbox)))
775     (loop
776 heller 1.106 (check-slime-interrupts)
777     (mp:with-lock (lock "receive-if/try")
778     (let* ((q (mailbox.queue mbox))
779     (tail (member-if test q)))
780     (when tail
781     (setf (mailbox.queue mbox) (nconc (ldiff q tail) (cdr tail)))
782     (return (car tail)))))
783     (mp:process-wait-with-timeout
784     "receive-if" 0.2 (lambda () (some test (mailbox.queue mbox)))))))
785 heller 1.102
786     (defimplementation send (thread message)
787     (let ((mbox (mailbox thread)))
788 heller 1.106 (mp:with-lock ((mailbox.mutex mbox))
789     (setf (mailbox.queue mbox)
790     (nconc (mailbox.queue mbox) (list message))))))
791 heller 1.3
792 heller 1.66 ;;; Some intergration with the lispworks environment
793    
794 heller 1.74 (defun swank-sym (name) (find-symbol (string name) :swank))
795 heller 1.66
796     (defimplementation emacs-connected ()
797     (when (eq (eval (swank-sym :*communication-style*))
798     nil)
799 heller 1.110 (set-sigint-handler)))
800 mkoeppe 1.77
801 eweitz 1.89
802     ;;;; Weak hashtables
803    
804     (defimplementation make-weak-key-hash-table (&rest args)
805     (apply #'make-hash-table :weak-kind :key args))
806    
807     (defimplementation make-weak-value-hash-table (&rest args)
808     (apply #'make-hash-table :weak-kind :value args))

  ViewVC Help
Powered by ViewVC 1.1.5