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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5