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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5