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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.66 - (show annotations)
Thu Feb 24 18:08:59 2005 UTC (9 years, 1 month ago) by heller
Branch: MAIN
Changes since 1.65: +63 -20 lines
(slime-env): New class.
(call-with-debugger-hook): Use env:with-environment to pop up our
debugger on a BREAK.

(toggle-trace-method, parse-fspec, tracedp, toggle-trace): Implement
method tracing.
1 ;;; -*- Mode: lisp; 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
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 (import-swank-mop-symbols :clos '(:slot-definition-documentation
29 :eql-specializer
30 :eql-specializer-object
31 :compute-applicable-methods-using-classes))
32
33 (defun swank-mop:slot-definition-documentation (slot)
34 (documentation slot t))
35
36 (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 (deftype swank-mop:eql-specializer () 'cons)
42
43 (defun swank-mop:eql-specializer-object (eql-spec)
44 (second eql-spec))
45
46 (when (fboundp 'dspec::define-dspec-alias)
47 (dspec::define-dspec-alias defimplementation (name args &rest body)
48 `(defmethod ,name ,args ,@body)))
49
50 ;;; TCP server
51
52 (defimplementation preferred-communication-style ()
53 :spawn)
54
55 (defun socket-fd (socket)
56 (etypecase socket
57 (fixnum socket)
58 (comm:socket-stream (comm:socket-stream-socket socket))))
59
60 (defimplementation create-socket (host port)
61 (multiple-value-bind (socket where errno)
62 #-(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 (cond (socket socket)
67 (t (error 'network-error
68 :format-control "~A failed: ~A (~D)"
69 :format-arguments (list where
70 (list #+unix (lw:get-unix-error errno))
71 errno))))))
72
73 (defimplementation local-port (socket)
74 (nth-value 1 (comm:get-socket-address (socket-fd socket))))
75
76 (defimplementation close-socket (socket)
77 (comm::close-socket (socket-fd socket)))
78
79 (defimplementation accept-connection (socket
80 &key (external-format :iso-latin-1-unix))
81 (assert (eq external-format :iso-latin-1-unix))
82 (let* ((fd (comm::get-fd-from-socket socket)))
83 (assert (/= fd -1))
84 (make-instance 'comm:socket-stream :socket fd :direction :io
85 :element-type 'base-char)))
86
87 (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 ;;; Unix signals
94
95 (defun sigint-handler ()
96 (with-simple-restart (continue "Continue from SIGINT handler.")
97 (invoke-debugger "SIGINT")))
98
99 (defun make-sigint-handler (process)
100 (lambda (&rest args)
101 (declare (ignore args))
102 (mp:process-interrupt process #'sigint-handler)))
103
104 (defimplementation call-without-interrupts (fn)
105 (lw:without-interrupts (funcall fn)))
106
107 (defimplementation getpid ()
108 #+win32 (win32:get-current-process-id)
109 #-win32 (system::getpid))
110
111 (defimplementation lisp-implementation-type-name ()
112 "lispworks")
113
114 (defimplementation set-default-directory (directory)
115 (namestring (hcl:change-directory directory)))
116
117 ;;;; Documentation
118
119 (defimplementation arglist (symbol-or-function)
120 (let ((arglist (lw:function-lambda-list symbol-or-function)))
121 (etypecase arglist
122 ((member :dont-know)
123 :not-available)
124 (list
125 arglist))))
126
127 (defimplementation function-name (function)
128 (nth-value 2 (function-lambda-expression function)))
129
130 (defimplementation macroexpand-all (form)
131 (walker:walk-form form))
132
133 (defun generic-function-p (object)
134 (typep object 'generic-function))
135
136 (defimplementation describe-symbol-for-emacs (symbol)
137 "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 :generic-function (if (and (fboundp symbol)
156 (generic-function-p (fdefinition symbol)))
157 (doc 'function)))
158 (maybe-push
159 :function (if (and (fboundp symbol)
160 (not (generic-function-p (fdefinition symbol))))
161 (doc 'function)))
162 (maybe-push
163 :setf (let ((setf-name (sys:underlying-setf-name `(setf ,symbol))))
164 (if (fboundp setf-name)
165 (doc 'setf))))
166 (maybe-push
167 :class (if (find-class symbol nil)
168 (doc 'class)))
169 result)))
170
171 (defimplementation describe-definition (symbol type)
172 (ecase type
173 (:variable (describe-symbol symbol))
174 (:class (describe (find-class symbol)))
175 ((:function :generic-function) (describe-function symbol))
176 (:setf (describe-function (sys:underlying-setf-name `(setf ,symbol))))))
177
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 (describe (fdefinition symbol)))
186 (t (format t "~S is not fbound" symbol))))
187
188 (defun describe-symbol (sym)
189 (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 (describe-function sym)))
197
198 ;;; Debugging
199
200 (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 (defvar *sldb-top-frame*)
222
223 (defun interesting-frame-p (frame)
224 (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
236 (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 ((or (not frame)
241 (and (interesting-frame-p frame) (zerop i)))
242 frame)))
243
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 (do ((frame (dbg::debugger-stack-current-frame dbg::*debugger-stack*)
250 (nth-next-frame frame 1)))
251 ((and (dbg::call-frame-p frame)
252 (eq (dbg::call-frame-function-name frame)
253 'invoke-debugger))
254 (nth-next-frame frame 1))))
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 (with-swank-compilation-unit (filename)
368 (compile-file filename :load load-p)))
369
370 (defimplementation call-with-compilation-hooks (function)
371 ;; #'pray instead of #'handler-bind
372 (funcall function))
373
374 (defun map-error-database (database fn)
375 (loop for (filename . defs) in database do
376 (loop for (dspec . conditions) in defs do
377 (dolist (c conditions)
378 (funcall fn filename dspec c)))))
379
380 (defun lispworks-severity (condition)
381 (cond ((not condition) :warning)
382 (t (etypecase condition
383 (error :error)
384 (style-warning :warning)
385 (warning :warning)))))
386
387 (defun signal-compiler-condition (message location condition)
388 (check-type message string)
389 (signal
390 (make-instance 'compiler-condition :message message
391 :severity (lispworks-severity condition)
392 :location location
393 :original-condition condition)))
394
395 (defun compile-from-temp-file (string filename)
396 (unwind-protect
397 (progn
398 (with-open-file (s filename :direction :output :if-exists :supersede)
399 (write-string string s)
400 (finish-output s))
401 (let ((binary-filename (compile-file filename :load t)))
402 (when binary-filename
403 (delete-file binary-filename))))
404 (delete-file filename)))
405
406 (defun dspec-buffer-position (dspec offset)
407 (etypecase dspec
408 (cons (let ((name (dspec:dspec-primary-name dspec)))
409 (typecase name
410 ((or symbol string)
411 (list :function-name (string name)))
412 (t (list :position offset)))))
413 (null (list :position offset))
414 (symbol (list :function-name (string dspec)))))
415
416 (defmacro with-fairly-standard-io-syntax (&body body)
417 "Like WITH-STANDARD-IO-SYNTAX but preserve *PACKAGE* and *READTABLE*."
418 (let ((package (gensym))
419 (readtable (gensym)))
420 `(let ((,package *package*)
421 (,readtable *readtable*))
422 (with-standard-io-syntax
423 (let ((*package* ,package)
424 (*readtable* ,readtable))
425 ,@body)))))
426
427 #-(or lispworks4.1 lispworks4.2) ; no dspec:parse-form-dspec prior to 4.3
428 (defun dspec-stream-position (stream dspec)
429 (with-fairly-standard-io-syntax
430 (loop (let* ((pos (file-position stream))
431 (form (read stream nil '#1=#:eof)))
432 (when (eq form '#1#)
433 (return nil))
434 (labels ((check-dspec (form)
435 (when (consp form)
436 (let ((operator (car form)))
437 (case operator
438 ((progn)
439 (mapcar #'check-dspec
440 (cdr form)))
441 ((eval-when locally macrolet symbol-macrolet)
442 (mapcar #'check-dspec
443 (cddr form)))
444 ((in-package)
445 (let ((package (find-package (second form))))
446 (when package
447 (setq *package* package))))
448 (otherwise
449 (let ((form-dspec (dspec:parse-form-dspec form)))
450 (when (dspec:dspec-equal dspec form-dspec)
451 (return pos)))))))))
452 (check-dspec form))))))
453
454 (defun dspec-file-position (file dspec)
455 (with-open-file (stream file)
456 (let ((pos
457 #-(or lispworks4.1 lispworks4.2)
458 (dspec-stream-position stream dspec)))
459 (if pos
460 (list :position (1+ pos) t)
461 (dspec-buffer-position dspec 1)))))
462
463 (defun emacs-buffer-location-p (location)
464 (and (consp location)
465 (eq (car location) :emacs-buffer)))
466
467 (defun make-dspec-location (dspec location &optional hints)
468 (etypecase location
469 ((or pathname string)
470 (multiple-value-bind (file err)
471 (ignore-errors (namestring (truename location)))
472 (if err
473 (list :error (princ-to-string err))
474 (make-location `(:file ,file)
475 (dspec-file-position file dspec)
476 hints))))
477 (symbol
478 `(:error ,(format nil "Cannot resolve location: ~S" location)))
479 ((satisfies emacs-buffer-location-p)
480 (destructuring-bind (_ buffer offset string) location
481 (declare (ignore _ string))
482 (make-location `(:buffer ,buffer)
483 (dspec-buffer-position dspec offset)
484 hints)))))
485
486 (defun make-dspec-progenitor-location (dspec location)
487 (let ((canon-dspec (dspec:canonicalize-dspec dspec)))
488 (make-dspec-location
489 (if canon-dspec
490 (if (dspec:local-dspec-p canon-dspec)
491 (dspec:dspec-progenitor canon-dspec)
492 canon-dspec)
493 nil)
494 location)))
495
496 (defun signal-error-data-base (database location)
497 (map-error-database
498 database
499 (lambda (filename dspec condition)
500 (declare (ignore filename))
501 (signal-compiler-condition
502 (format nil "~A" condition)
503 (make-dspec-progenitor-location dspec location)
504 condition))))
505
506 (defun signal-undefined-functions (htab filename)
507 (maphash (lambda (unfun dspecs)
508 (dolist (dspec dspecs)
509 (signal-compiler-condition
510 (format nil "Undefined function ~A" unfun)
511 (make-dspec-progenitor-location dspec filename)
512 nil)))
513 htab))
514
515 (defimplementation swank-compile-string (string &key buffer position directory)
516 (declare (ignore directory))
517 (assert buffer)
518 (assert position)
519 (let* ((location (list :emacs-buffer buffer position string))
520 (tmpname (hcl:make-temp-file nil "lisp")))
521 (with-swank-compilation-unit (location)
522 (compile-from-temp-file
523 (format nil "~S~%~A" `(eval-when (:compile-toplevel)
524 (setq dspec::*location* (list ,@location)))
525 string)
526 tmpname))))
527
528 ;;; xref
529
530 (defmacro defxref (name function)
531 `(defimplementation ,name (name)
532 (xref-results (,function name))))
533
534 (defxref who-calls hcl:who-calls)
535 (defxref who-macroexpands hcl:who-calls) ; macros are in the calls table too
536 (defxref list-callees hcl:calls-who)
537 (defxref list-callers list-callers-internal)
538
539 (defun list-callers-internal (name)
540 (let ((callers (make-array 100
541 :fill-pointer 0
542 :adjustable t)))
543 (hcl:sweep-all-objects
544 #'(lambda (object)
545 (when (and #+Harlequin-PC-Lisp (low:compiled-code-p object)
546 #-Harlequin-PC-Lisp (sys::callablep object)
547 (system::find-constant$funcallable name object))
548 (vector-push-extend object callers))))
549 ;; Delay dspec:object-dspec until after sweep-all-objects
550 ;; to reduce allocation problems.
551 (loop for object across callers
552 collect (if (symbolp object)
553 (list 'function object)
554 (or (dspec:object-dspec object) object)))))
555
556 ;; only for lispworks 4.2 and above
557 #-lispworks4.1
558 (progn
559 (defxref who-references hcl:who-references)
560 (defxref who-binds hcl:who-binds)
561 (defxref who-sets hcl:who-sets))
562
563 (defimplementation who-specializes (classname)
564 (let ((methods (clos:class-direct-methods (find-class classname))))
565 (xref-results (mapcar #'dspec:object-dspec methods))))
566
567 (defun xref-results (dspecs)
568 (flet ((frob-locs (dspec locs)
569 (cond (locs
570 (loop for (name loc) in locs
571 collect (list name (make-dspec-location name loc))))
572 (t `((,dspec (:error "Source location not available")))))))
573 (loop for dspec in dspecs
574 append (frob-locs dspec (dspec:dspec-definition-locations dspec)))))
575
576 ;;; Inspector
577 (defclass lispworks-inspector (inspector)
578 ())
579
580 (defimplementation make-default-inspector ()
581 (make-instance 'lispworks-inspector))
582
583 (defimplementation inspect-for-emacs ((o t) (inspector lispworks-inspector))
584 (declare (ignore inspector))
585 (lispworks-inspect o))
586
587 (defimplementation inspect-for-emacs ((o function)
588 (inspector lispworks-inspector))
589 (declare (ignore inspector))
590 (lispworks-inspect o))
591
592 (defun lispworks-inspect (o)
593 (multiple-value-bind (names values _getter _setter type)
594 (lw:get-inspector-values o nil)
595 (declare (ignore _getter _setter))
596 (values "A value."
597 (append
598 (label-value-line "Type" type)
599 (mapcan #'label-value-line names values)))))
600
601 ;;; Miscellaneous
602
603 (defimplementation quit-lisp ()
604 (lispworks:quit))
605
606 ;;; Tracing
607
608 (defun parse-fspec (fspec)
609 "Return a dspec for FSPEC."
610 (ecase (car fspec)
611 (:defmethod `(method ,@(cdr fspec)))))
612
613 (defun tracedp (dspec)
614 (member dspec (eval '(trace)) :test #'equal))
615
616 (defun toggle-trace (dspec)
617 (cond ((tracedp dspec)
618 (eval `(untrace ,dspec))
619 (format nil "~S is now untraced." dspec))
620 (t
621 (eval `(trace (,dspec)))
622 (format nil "~S is now traced." dspec))))
623
624 (defimplementation toggle-trace-method (fspec)
625 (toggle-trace (parse-fspec fspec)))
626
627 ;;; Multithreading
628
629 (defimplementation startup-multiprocessing ()
630 (mp:initialize-multiprocessing))
631
632 (defimplementation spawn (fn &key name)
633 (let ((mp:*process-initial-bindings*
634 (remove (find-package :cl)
635 mp:*process-initial-bindings*
636 :key (lambda (x) (symbol-package (car x))))))
637 (mp:process-run-function name () fn)))
638
639 (defvar *id-lock* (mp:make-lock))
640 (defvar *thread-id-counter* 0)
641
642 (defimplementation thread-id (thread)
643 (mp:with-lock (*id-lock*)
644 (or (getf (mp:process-plist thread) 'id)
645 (setf (getf (mp:process-plist thread) 'id)
646 (incf *thread-id-counter*)))))
647
648 (defimplementation find-thread (id)
649 (find id (mp:list-all-processes)
650 :key (lambda (p) (getf (mp:process-plist p) 'id))))
651
652 (defimplementation thread-name (thread)
653 (mp:process-name thread))
654
655 (defimplementation thread-status (thread)
656 (format nil "~A ~D"
657 (mp:process-whostate thread)
658 (mp:process-priority thread)))
659
660 (defimplementation make-lock (&key name)
661 (mp:make-lock :name name))
662
663 (defimplementation call-with-lock-held (lock function)
664 (mp:with-lock (lock) (funcall function)))
665
666 (defimplementation current-thread ()
667 mp:*current-process*)
668
669 (defimplementation all-threads ()
670 (mp:list-all-processes))
671
672 (defimplementation interrupt-thread (thread fn)
673 (mp:process-interrupt thread fn))
674
675 (defimplementation kill-thread (thread)
676 (mp:process-kill thread))
677
678 (defimplementation thread-alive-p (thread)
679 (mp:process-alive-p thread))
680
681 (defvar *mailbox-lock* (mp:make-lock))
682
683 (defun mailbox (thread)
684 (mp:with-lock (*mailbox-lock*)
685 (or (getf (mp:process-plist thread) 'mailbox)
686 (setf (getf (mp:process-plist thread) 'mailbox)
687 (mp:make-mailbox)))))
688
689 (defimplementation receive ()
690 (mp:mailbox-read (mailbox mp:*current-process*)))
691
692 (defimplementation send (thread object)
693 (mp:mailbox-send (mailbox thread) object))
694
695 ;;; Some intergration with the lispworks environment
696
697 (defun swank-sym (name) (find-symbol (string name) (string :swank)))
698
699 (defimplementation emacs-connected ()
700 (when (eq (eval (swank-sym :*communication-style*))
701 nil)
702 (set-sigint-handler)))
703
704 (defimplementation make-stream-interactive (stream)
705 (unless (find-method #'stream:stream-soft-force-output nil `((eql ,stream))
706 nil)
707 (let ((lw:*handle-warn-on-redefinition* :warn))
708 (defmethod stream:stream-soft-force-output ((o (eql stream)))
709 (force-output o)))))
710
711 (defmethod env-internals:confirm-p ((e slime-env) &optional msg &rest args)
712 (let ((prompt (cond (msg (apply #'format nil msg args))
713 (t ""))))
714 (funcall (swank-sym :eval-in-emacs) `(y-or-n-p ,prompt))))

  ViewVC Help
Powered by ViewVC 1.1.5