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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.93 - (show annotations)
Sat Nov 24 08:18:59 2007 UTC (6 years, 5 months ago) by heller
Branch: MAIN
Changes since 1.92: +4 -16 lines
Drop remaining dependencies on nregex.

* swank-lispworks.lisp (unmangle-unfun): Use sys::setf-symbol-p
instead of regexp matching.

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

  ViewVC Help
Powered by ViewVC 1.1.5