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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.68 - (show annotations)
Tue Mar 22 10:12:19 2005 UTC (9 years, 1 month ago) by heller
Branch: MAIN
Changes since 1.67: +17 -5 lines
(swank-compile-string): Bind *print-radix* to t, to avoid problems if
somebody uses different values for *print-base* and *read-base*.
Reported by Alain Picard.

(emacs-connected): Add default methods for
environment-display-notifier and environment-display-debugger.
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 (with-output-to-string (s)
524 (let ((*print-radix* t))
525 (print `(eval-when (:compile-toplevel)
526 (setq dspec::*location* (list ,@location)))
527 s))
528 (write-string string s))
529 tmpname))))
530
531 ;;; xref
532
533 (defmacro defxref (name function)
534 `(defimplementation ,name (name)
535 (xref-results (,function name))))
536
537 (defxref who-calls hcl:who-calls)
538 (defxref who-macroexpands hcl:who-calls) ; macros are in the calls table too
539 (defxref calls-who hcl:calls-who)
540 (defxref list-callers list-callers-internal)
541 ;; (defxref list-callees list-callees-internal)
542
543 (defun list-callers-internal (name)
544 (let ((callers (make-array 100
545 :fill-pointer 0
546 :adjustable t)))
547 (hcl:sweep-all-objects
548 #'(lambda (object)
549 (when (and #+Harlequin-PC-Lisp (low:compiled-code-p object)
550 #-Harlequin-PC-Lisp (sys::callablep object)
551 (system::find-constant$funcallable name object))
552 (vector-push-extend object callers))))
553 ;; Delay dspec:object-dspec until after sweep-all-objects
554 ;; to reduce allocation problems.
555 (loop for object across callers
556 collect (if (symbolp object)
557 (list 'function object)
558 (or (dspec:object-dspec object) object)))))
559
560 ;; only for lispworks 4.2 and above
561 #-lispworks4.1
562 (progn
563 (defxref who-references hcl:who-references)
564 (defxref who-binds hcl:who-binds)
565 (defxref who-sets hcl:who-sets))
566
567 (defimplementation who-specializes (classname)
568 (let ((methods (clos:class-direct-methods (find-class classname))))
569 (xref-results (mapcar #'dspec:object-dspec methods))))
570
571 (defun xref-results (dspecs)
572 (flet ((frob-locs (dspec locs)
573 (cond (locs
574 (loop for (name loc) in locs
575 collect (list name (make-dspec-location name loc))))
576 (t `((,dspec (:error "Source location not available")))))))
577 (loop for dspec in dspecs
578 append (frob-locs dspec (dspec:dspec-definition-locations dspec)))))
579
580 ;;; Inspector
581 (defclass lispworks-inspector (inspector)
582 ())
583
584 (defimplementation make-default-inspector ()
585 (make-instance 'lispworks-inspector))
586
587 (defimplementation inspect-for-emacs ((o t) (inspector lispworks-inspector))
588 (declare (ignore inspector))
589 (lispworks-inspect o))
590
591 (defimplementation inspect-for-emacs ((o function)
592 (inspector lispworks-inspector))
593 (declare (ignore inspector))
594 (lispworks-inspect o))
595
596 (defun lispworks-inspect (o)
597 (multiple-value-bind (names values _getter _setter type)
598 (lw:get-inspector-values o nil)
599 (declare (ignore _getter _setter))
600 (values "A value."
601 (append
602 (label-value-line "Type" type)
603 (mapcan #'label-value-line names values)))))
604
605 ;;; Miscellaneous
606
607 (defimplementation quit-lisp ()
608 (lispworks:quit))
609
610 ;;; Tracing
611
612 (defun parse-fspec (fspec)
613 "Return a dspec for FSPEC."
614 (ecase (car fspec)
615 ((:defmethod) `(method ,(cdr fspec)))))
616
617 (defun tracedp (dspec)
618 (member dspec (eval '(trace)) :test #'equal))
619
620 (defun toggle-trace-aux (dspec)
621 (cond ((tracedp dspec)
622 (eval `(untrace ,dspec))
623 (format nil "~S is now untraced." dspec))
624 (t
625 (eval `(trace (,dspec)))
626 (format nil "~S is now traced." dspec))))
627
628 (defimplementation toggle-trace (fspec)
629 (toggle-trace-aux (parse-fspec fspec)))
630
631 ;;; Multithreading
632
633 (defimplementation startup-multiprocessing ()
634 (mp:initialize-multiprocessing))
635
636 (defimplementation spawn (fn &key name)
637 (let ((mp:*process-initial-bindings*
638 (remove (find-package :cl)
639 mp:*process-initial-bindings*
640 :key (lambda (x) (symbol-package (car x))))))
641 (mp:process-run-function name () fn)))
642
643 (defvar *id-lock* (mp:make-lock))
644 (defvar *thread-id-counter* 0)
645
646 (defimplementation thread-id (thread)
647 (mp:with-lock (*id-lock*)
648 (or (getf (mp:process-plist thread) 'id)
649 (setf (getf (mp:process-plist thread) 'id)
650 (incf *thread-id-counter*)))))
651
652 (defimplementation find-thread (id)
653 (find id (mp:list-all-processes)
654 :key (lambda (p) (getf (mp:process-plist p) 'id))))
655
656 (defimplementation thread-name (thread)
657 (mp:process-name thread))
658
659 (defimplementation thread-status (thread)
660 (format nil "~A ~D"
661 (mp:process-whostate thread)
662 (mp:process-priority thread)))
663
664 (defimplementation make-lock (&key name)
665 (mp:make-lock :name name))
666
667 (defimplementation call-with-lock-held (lock function)
668 (mp:with-lock (lock) (funcall function)))
669
670 (defimplementation current-thread ()
671 mp:*current-process*)
672
673 (defimplementation all-threads ()
674 (mp:list-all-processes))
675
676 (defimplementation interrupt-thread (thread fn)
677 (mp:process-interrupt thread fn))
678
679 (defimplementation kill-thread (thread)
680 (mp:process-kill thread))
681
682 (defimplementation thread-alive-p (thread)
683 (mp:process-alive-p thread))
684
685 (defvar *mailbox-lock* (mp:make-lock))
686
687 (defun mailbox (thread)
688 (mp:with-lock (*mailbox-lock*)
689 (or (getf (mp:process-plist thread) 'mailbox)
690 (setf (getf (mp:process-plist thread) 'mailbox)
691 (mp:make-mailbox)))))
692
693 (defimplementation receive ()
694 (mp:mailbox-read (mailbox mp:*current-process*)))
695
696 (defimplementation send (thread object)
697 (mp:mailbox-send (mailbox thread) object))
698
699 ;;; Some intergration with the lispworks environment
700
701 (defun swank-sym (name) (find-symbol (string name) (string :swank)))
702
703 (defimplementation emacs-connected ()
704 (when (eq (eval (swank-sym :*communication-style*))
705 nil)
706 (set-sigint-handler))
707 ;; pop up the slime debugger by default
708 (let ((lw:*handle-warn-on-redefinition* :warn))
709 (defmethod env-internals:environment-display-notifier
710 (env &key restarts condition)
711 (declare (ignore restarts))
712 (funcall (find-symbol (string :swank-debugger-hook) :swank)
713 condition *debugger-hook*))
714 (defmethod env-internals:environment-display-debugger (env)
715 *debug-io*)))
716
717 (defimplementation make-stream-interactive (stream)
718 (unless (find-method #'stream:stream-soft-force-output nil `((eql ,stream))
719 nil)
720 (let ((lw:*handle-warn-on-redefinition* :warn))
721 (defmethod stream:stream-soft-force-output ((o (eql stream)))
722 (force-output o)))))
723
724 (defmethod env-internals:confirm-p ((e slime-env) &optional msg &rest args)
725 (let ((prompt (cond (msg (apply #'format nil msg args))
726 (t ""))))
727 (funcall (swank-sym :eval-in-emacs) `(y-or-n-p ,prompt))))

  ViewVC Help
Powered by ViewVC 1.1.5