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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.144 - (hide annotations)
Sun Nov 6 17:05:41 2011 UTC (2 years, 5 months ago) by heller
Branch: MAIN
Changes since 1.143: +18 -11 lines
* swank-abcl.lisp (accept-connection): Make it so.
* swank-clisp.lisp (accept-connection): Make it so.
* swank-cmucl.lisp (accept-connection): Make it so.
* swank-lispworks.lisp (accept-connection): Make it so.
* swank-sbcl.lisp (accept-connection): Make it so.
* swank-scl.lisp (accept-connection): Make it so.
1 heller 1.74 ;;; -*- indent-tabs-mode: nil -*-
2 heller 1.1 ;;;
3     ;;; swank-lispworks.lisp --- LispWorks specific code for SLIME.
4     ;;;
5     ;;; Created 2003, Helmut Eller
6     ;;;
7     ;;; This code has been placed in the Public Domain. All warranties
8     ;;; are disclaimed.
9     ;;;
10    
11 heller 1.30 (in-package :swank-backend)
12 heller 1.1
13     (eval-when (:compile-toplevel :load-toplevel :execute)
14 heller 1.79 (require "comm")
15     (import-from :stream *gray-stream-symbols* :swank-backend))
16 heller 1.1
17 heller 1.62 (import-swank-mop-symbols :clos '(:slot-definition-documentation
18 msimmons 1.129 :slot-boundp-using-class
19     :slot-value-using-class
20     :slot-makunbound-using-class
21 heller 1.62 :eql-specializer
22 heller 1.65 :eql-specializer-object
23     :compute-applicable-methods-using-classes))
24 msimmons 1.57
25     (defun swank-mop:slot-definition-documentation (slot)
26     (documentation slot t))
27 mbaringer 1.59
28 msimmons 1.129 (defun swank-mop:slot-boundp-using-class (class object slotd)
29     (clos:slot-boundp-using-class class object
30     (clos:slot-definition-name slotd)))
31    
32     (defun swank-mop:slot-value-using-class (class object slotd)
33     (clos:slot-value-using-class class object
34     (clos:slot-definition-name slotd)))
35    
36     (defun (setf swank-mop:slot-value-using-class) (value class object slotd)
37     (setf (clos:slot-value-using-class class object
38     (clos:slot-definition-name slotd))
39     value))
40    
41     (defun swank-mop:slot-makunbound-using-class (class object slotd)
42     (clos:slot-makunbound-using-class class object
43     (clos:slot-definition-name slotd)))
44    
45 heller 1.65 (defun swank-mop:compute-applicable-methods-using-classes (gf classes)
46     (clos::compute-applicable-methods-from-classes gf classes))
47    
48     ;; lispworks doesn't have the eql-specializer class, it represents
49     ;; them as a list of `(EQL ,OBJECT)
50 mbaringer 1.59 (deftype swank-mop:eql-specializer () 'cons)
51    
52     (defun swank-mop:eql-specializer-object (eql-spec)
53     (second eql-spec))
54 msimmons 1.57
55 heller 1.111 (eval-when (:compile-toplevel :execute :load-toplevel)
56     (defvar *original-defimplementation* (macro-function 'defimplementation))
57     (defmacro defimplementation (&whole whole name args &body body
58     &environment env)
59     (declare (ignore args body))
60     `(progn
61     (dspec:record-definition '(defun ,name) (dspec:location)
62     :check-redefinition-p nil)
63     ,(funcall *original-defimplementation* whole env))))
64 heller 1.49
65 heller 1.143 ;;; UTF8
66    
67     (defimplementation string-to-utf8 (string)
68     (ef:encode-lisp-string string :utf-8))
69    
70     (defimplementation utf8-to-string (octets)
71     (ef:decode-external-string octets :utf-8))
72    
73 heller 1.13 ;;; TCP server
74 lgorrie 1.12
75 heller 1.30 (defimplementation preferred-communication-style ()
76     :spawn)
77 heller 1.18
78 heller 1.13 (defun socket-fd (socket)
79     (etypecase socket
80     (fixnum socket)
81     (comm:socket-stream (comm:socket-stream-socket socket))))
82    
83 heller 1.22 (defimplementation create-socket (host port)
84 heller 1.13 (multiple-value-bind (socket where errno)
85 msimmons 1.64 #-(or lispworks4.1 (and macosx lispworks4.3))
86     (comm::create-tcp-socket-for-service port :address host)
87     #+(or lispworks4.1 (and macosx lispworks4.3))
88     (comm::create-tcp-socket-for-service port)
89 heller 1.13 (cond (socket socket)
90 heller 1.14 (t (error 'network-error
91 heller 1.13 :format-control "~A failed: ~A (~D)"
92     :format-arguments (list where
93     (list #+unix (lw:get-unix-error errno))
94 heller 1.14 errno))))))
95 heller 1.13
96 lgorrie 1.17 (defimplementation local-port (socket)
97 heller 1.13 (nth-value 1 (comm:get-socket-address (socket-fd socket))))
98    
99 lgorrie 1.17 (defimplementation close-socket (socket)
100 heller 1.13 (comm::close-socket (socket-fd socket)))
101    
102 heller 1.63 (defimplementation accept-connection (socket
103 heller 1.85 &key external-format buffering timeout)
104 heller 1.118 (declare (ignore buffering))
105 heller 1.61 (let* ((fd (comm::get-fd-from-socket socket)))
106 heller 1.13 (assert (/= fd -1))
107 heller 1.144 (cond ((not external-format)
108 heller 1.118 (make-instance 'comm:socket-stream
109     :socket fd
110     :direction :io
111     :read-timeout timeout
112 heller 1.144 :element-type '(unsigned-byte 8)))
113 heller 1.118 (t
114 heller 1.144 (assert (valid-external-format-p external-format))
115     (ecase (first external-format)
116     ((:latin-1 :ascii)
117     (make-instance 'comm:socket-stream
118     :socket fd
119     :direction :io
120     :read-timeout timeout
121     :element-type 'base-char))
122     (:utf-8
123     (make-instance 'utf8-stream :byte-stream
124     (make-instance
125     'comm:socket-stream
126     :socket fd
127     :direction :io
128     :read-timeout timeout
129     :element-type '(unsigned-byte 8)))))))))
130 heller 1.142
131     (defclass utf8-stream (stream:fundamental-character-input-stream
132     stream:fundamental-character-output-stream)
133     ((byte-stream :type comm:socket-stream
134     :initform nil
135     :initarg :byte-stream
136     :accessor utf8-stream-byte-stream)))
137    
138     ;; Helper function. Decode the next N bytes starting from INDEX.
139     ;; Return the decoded char and the new index.
140     (defun utf8-decode-aux (buffer index limit byte0 n)
141     (declare (simple-string buffer) (fixnum index limit byte0 n))
142     (if (< (- limit index) n)
143     (values nil index)
144     (do ((i 0 (1+ i))
145     (code byte0 (let ((byte (char-code (schar buffer (+ index i)))))
146     (cond ((= (ldb (byte 2 6) byte) #b10)
147     (+ (ash code 6) (ldb (byte 6 0) byte)))
148     (t
149     (error "Invalid encoding"))))))
150     ((= i n)
151     (values (cond ((<= code #xff) (code-char code))
152     ((<= #xdc00 code #xdbff)
153     (error "Invalid Unicode code point: #x~x" code))
154     ((< code char-code-limit)
155     (code-char code))
156     (t
157     (error
158     "Can't represent code point: #x~x ~
159     (char-code-limit is #x~x)"
160     code char-code-limit)))
161     (+ index n))))))
162    
163     ;; Decode one character in BUFFER starting at INDEX.
164     ;; Return 2 values: the character and the new index.
165     ;; If there aren't enough bytes between INDEX and LIMIT return nil.
166     (defun utf8-decode (buffer index limit)
167     (declare (simple-string buffer) (fixnum index limit))
168     (if (= index limit)
169     (values nil index)
170     (let ((b (char-code (schar buffer index))))
171     (if (<= b #x7f)
172     (values (code-char b) (1+ index))
173     (macrolet ((try (marker else)
174     (let* ((l (integer-length marker))
175     (n (- l 2)))
176     `(if (= (ldb (byte ,l ,(- 8 l)) b) ,marker)
177     (utf8-decode-aux buffer (1+ index) limit
178     (ldb (byte ,(- 8 l) 0) b)
179     ,n)
180     ,else))))
181     (try #b110
182     (try #b1110
183     (try #b11110
184     (try #b111110
185     (try #b1111110
186     (error "Invalid encoding")))))))))))
187    
188     ;; Decode characters from BUFFER and write them to STRING.
189     ;; Return 2 values: LASTINDEX and LASTSTART where
190     ;; LASTINDEX is the last index in BUFFER that was not decoded
191     ;; and LASTSTART is the last index in STRING not written.
192     (defun utf8-decode-into (buffer index limit string start end)
193     (declare (string string) (fixnum index limit start end))
194     (loop
195     (cond ((= start end)
196     (return (values index start)))
197     (t
198     (multiple-value-bind (c i) (utf8-decode buffer index limit)
199     (cond (c
200     (setf (aref string start) c)
201     (setq index i)
202     (setq start (1+ start)))
203     (t
204     (return (values index start)))))))))
205    
206     (defmacro utf8-encode-aux (code buffer start end n)
207     `(cond ((< (- ,end ,start) ,n)
208     ,start)
209     (t
210     (setf (schar ,buffer ,start)
211     (code-char
212     (dpb (ldb (byte ,(- 7 n) ,(* 6 (1- n))) ,code)
213     (byte ,(- 7 n) 0)
214     ,(dpb 0 (byte 1 (- 7 n)) #xff))))
215     ,@(loop for i from 0 upto (- n 2) collect
216     `(setf (schar ,buffer (+ ,start ,(- n 1 i)))
217     (code-char
218     (dpb (ldb (byte 6 ,(* 6 i)) ,code)
219     (byte 6 0)
220     #b10111111))))
221     (+ ,start ,n))))
222    
223     (defun utf8-encode (char buffer start end)
224     (declare (fixnum start end))
225     (let ((code (char-code char)))
226     (cond ((<= code #x7f)
227     (cond ((< start end)
228     (setf (schar buffer start) char)
229     (1+ start))
230     (t start)))
231     ((<= code #x7ff) (utf8-encode-aux code buffer start end 2))
232     ((<= #xd800 code #xdfff)
233     (error "Invalid Unicode code point (surrogate): #x~x" code))
234     ((<= code #xffff) (utf8-encode-aux code buffer start end 3))
235     ((<= code #x1fffff) (utf8-encode-aux code buffer start end 4))
236     ((<= code #x3ffffff) (utf8-encode-aux code buffer start end 5))
237     ((<= code #x7fffffff) (utf8-encode-aux code buffer start end 6))
238     (t (error "Can't encode ~s (~x)" char code)))))
239    
240     (defun utf8-encode-into (string start end buffer index limit)
241     (loop
242     (cond ((= start end)
243     (return (values start index)))
244     ((= index limit)
245     (return (values start index)))
246     (t
247     (let ((i2 (utf8-encode (char string start) buffer index limit)))
248     (cond ((= i2 index)
249     (return (values start index)))
250     (t
251     (setq index i2)
252     (incf start))))))))
253    
254     (defun utf8-stream-read-char (stream no-hang)
255     (with-slots (byte-stream) stream
256     (loop
257     (stream:with-stream-input-buffer (b i l) byte-stream
258     (multiple-value-bind (c i2) (utf8-decode b i l)
259     (cond (c
260     (setf i i2)
261     (return c))
262     ((and no-hang
263     (not (sys:wait-for-input-streams-returning-first
264     (list byte-stream) :timeout 0)))
265     (return nil))
266     ((stream:stream-fill-buffer byte-stream)
267     #| next iteration |# )
268     (t
269     (return :eof))))))))
270    
271     (defmethod stream:stream-read-char ((stream utf8-stream))
272     (utf8-stream-read-char stream nil))
273    
274     (defmethod stream:stream-read-char-no-hang ((stream utf8-stream))
275     (utf8-stream-read-char stream t))
276    
277     (defmethod stream:stream-read-sequence ((stream utf8-stream) (string string)
278     start end)
279     (with-slots (byte-stream) stream
280     (loop
281     (stream:with-stream-input-buffer (b i l) byte-stream
282     (multiple-value-bind (i2 s2) (utf8-decode-into b i l string start end)
283     (setq i i2)
284     (setq start s2)
285     (cond ((= start end)
286     (return start))
287     ((stream:stream-fill-buffer byte-stream)
288     #| next iteration |# )
289     (t
290     (return start))))))))
291    
292     (defmethod stream:stream-unread-char ((stream utf8-stream) (c character))
293     (with-slots (byte-stream) stream
294     (stream:with-stream-input-buffer (b i l) byte-stream
295     (declare (ignorable l))
296     (let* ((bytes (ef:encode-lisp-string (string c) :utf-8))
297     (len (length bytes))
298     (i2 (- i len)))
299     (assert (equal (utf8-decode b i2 i) c))
300     (setq i i2)
301     nil))))
302    
303     (defmethod stream:stream-write-char ((stream utf8-stream) (char character))
304     (with-slots (byte-stream) stream
305     (loop
306     (stream:with-stream-output-buffer (b i l) byte-stream
307     (let ((i2 (utf8-encode char b i l)))
308     (cond ((< i i2)
309     (setf i i2)
310     (return char))
311     ((stream:stream-flush-buffer byte-stream)
312     )
313     (t
314     (error "Can't flush buffer"))))))))
315    
316     (defmethod stream:stream-write-string ((stream utf8-stream)
317     (string string)
318     &optional (start 0)
319     (end (length string)))
320     (with-slots (byte-stream) stream
321     (loop
322     (stream:with-stream-output-buffer (b i l) byte-stream
323     (multiple-value-bind (s2 i2) (utf8-encode-into string start end
324     b i l)
325     (setf i i2)
326     (setf start s2)
327     (cond ((= start end)
328     (return string))
329     ((stream:stream-flush-buffer byte-stream)
330     )
331     (t
332     (error "Can't flush buffer"))))))))
333    
334     (defmethod stream:stream-write-sequence ((stream utf8-stream)
335     seq start end)
336     (stream:stream-write-string seq start end))
337    
338     (defmethod stream:stream-force-output ((stream utf8-stream))
339     (with-slots (byte-stream) stream (force-output byte-stream)))
340    
341     (defmethod stream:stream-finish-output ((stream utf8-stream))
342     (with-slots (byte-stream) stream (finish-output byte-stream)))
343 heller 1.13
344 heller 1.88 ;;; Coding Systems
345    
346 heller 1.118 (defun valid-external-format-p (external-format)
347     (member external-format *external-format-to-coding-system*
348     :test #'equal :key #'car))
349    
350 heller 1.88 (defvar *external-format-to-coding-system*
351     '(((:latin-1 :eol-style :lf)
352     "latin-1-unix" "iso-latin-1-unix" "iso-8859-1-unix")
353 heller 1.142 ;;((:latin-1) "latin-1" "iso-latin-1" "iso-8859-1")
354     ;;((:utf-8) "utf-8")
355 heller 1.88 ((:utf-8 :eol-style :lf) "utf-8-unix")
356 heller 1.142 ;;((:euc-jp) "euc-jp")
357 heller 1.88 ((:euc-jp :eol-style :lf) "euc-jp-unix")
358 heller 1.142 ;;((:ascii) "us-ascii")
359 heller 1.88 ((:ascii :eol-style :lf) "us-ascii-unix")))
360    
361     (defimplementation find-external-format (coding-system)
362     (car (rassoc-if (lambda (x) (member coding-system x :test #'equal))
363     *external-format-to-coding-system*)))
364    
365 heller 1.15 ;;; Unix signals
366    
367 heller 1.18 (defun sigint-handler ()
368 heller 1.16 (with-simple-restart (continue "Continue from SIGINT handler.")
369     (invoke-debugger "SIGINT")))
370 heller 1.1
371 heller 1.18 (defun make-sigint-handler (process)
372     (lambda (&rest args)
373     (declare (ignore args))
374     (mp:process-interrupt process #'sigint-handler)))
375    
376 heller 1.125 (defun set-sigint-handler ()
377     ;; Set SIGINT handler on Swank request handler thread.
378     #-win32
379     (sys::set-signal-handler +sigint+
380     (make-sigint-handler mp:*current-process*)))
381    
382     #-win32
383     (defimplementation install-sigint-handler (handler)
384     (sys::set-signal-handler +sigint+
385     (let ((self mp:*current-process*))
386     (lambda (&rest args)
387     (declare (ignore args))
388     (mp:process-interrupt self handler)))))
389    
390 heller 1.29 (defimplementation getpid ()
391     #+win32 (win32:get-current-process-id)
392     #-win32 (system::getpid))
393 heller 1.1
394 heller 1.23 (defimplementation lisp-implementation-type-name ()
395     "lispworks")
396    
397 heller 1.36 (defimplementation set-default-directory (directory)
398     (namestring (hcl:change-directory directory)))
399 heller 1.40
400     ;;;; Documentation
401 heller 1.36
402 sboukarev 1.133 (defun map-list (function list)
403     "Map over proper and not proper lists."
404     (loop for (car . cdr) on list
405     collect (funcall function car) into result
406     when (null cdr) return result
407     when (atom cdr) return (nconc result (funcall function cdr))))
408    
409 sboukarev 1.132 (defun replace-strings-with-symbols (tree)
410 sboukarev 1.133 (map-list
411     (lambda (x)
412     (typecase x
413     (list
414     (replace-strings-with-symbols x))
415     (symbol
416     x)
417     (string
418     (intern x))
419     (t
420     (intern (write-to-string x)))))
421     tree))
422 sboukarev 1.132
423 msimmons 1.57 (defimplementation arglist (symbol-or-function)
424     (let ((arglist (lw:function-lambda-list symbol-or-function)))
425 heller 1.30 (etypecase arglist
426 heller 1.39 ((member :dont-know)
427     :not-available)
428     (list
429 sboukarev 1.132 (replace-strings-with-symbols arglist)))))
430 msimmons 1.57
431     (defimplementation function-name (function)
432     (nth-value 2 (function-lambda-expression function)))
433 heller 1.1
434 lgorrie 1.17 (defimplementation macroexpand-all (form)
435 heller 1.1 (walker:walk-form form))
436    
437 heller 1.37 (defun generic-function-p (object)
438 heller 1.36 (typep object 'generic-function))
439    
440 lgorrie 1.17 (defimplementation describe-symbol-for-emacs (symbol)
441 heller 1.1 "Return a plist describing SYMBOL.
442     Return NIL if the symbol is unbound."
443     (let ((result '()))
444     (labels ((first-line (string)
445     (let ((pos (position #\newline string)))
446     (if (null pos) string (subseq string 0 pos))))
447     (doc (kind &optional (sym symbol))
448 heller 1.116 (let ((string (or (documentation sym kind))))
449 heller 1.1 (if string
450     (first-line string)
451     :not-documented)))
452     (maybe-push (property value)
453     (when value
454     (setf result (list* property value result)))))
455     (maybe-push
456     :variable (when (boundp symbol)
457     (doc 'variable)))
458     (maybe-push
459 heller 1.36 :generic-function (if (and (fboundp symbol)
460 heller 1.37 (generic-function-p (fdefinition symbol)))
461 heller 1.36 (doc 'function)))
462     (maybe-push
463     :function (if (and (fboundp symbol)
464 heller 1.37 (not (generic-function-p (fdefinition symbol))))
465 heller 1.1 (doc 'function)))
466     (maybe-push
467 heller 1.49 :setf (let ((setf-name (sys:underlying-setf-name `(setf ,symbol))))
468     (if (fboundp setf-name)
469     (doc 'setf))))
470     (maybe-push
471 heller 1.1 :class (if (find-class symbol nil)
472     (doc 'class)))
473 heller 1.30 result)))
474 heller 1.1
475 heller 1.30 (defimplementation describe-definition (symbol type)
476     (ecase type
477     (:variable (describe-symbol symbol))
478     (:class (describe (find-class symbol)))
479 heller 1.49 ((:function :generic-function) (describe-function symbol))
480     (:setf (describe-function (sys:underlying-setf-name `(setf ,symbol))))))
481 heller 1.30
482     (defun describe-function (symbol)
483     (cond ((fboundp symbol)
484 heller 1.123 (format t "(~A ~/pprint-fill/)~%~%~:[(not documented)~;~:*~A~]~%"
485     symbol
486     (lispworks:function-lambda-list symbol)
487 heller 1.30 (documentation symbol 'function))
488 heller 1.38 (describe (fdefinition symbol)))
489 heller 1.30 (t (format t "~S is not fbound" symbol))))
490 heller 1.4
491 heller 1.30 (defun describe-symbol (sym)
492 heller 1.1 (format t "~A is a symbol in package ~A." sym (symbol-package sym))
493     (when (boundp sym)
494     (format t "~%~%Value: ~A" (symbol-value sym)))
495     (let ((doc (documentation sym 'variable)))
496     (when doc
497     (format t "~%~%Variable documentation:~%~A" doc)))
498     (when (fboundp sym)
499 heller 1.30 (describe-function sym)))
500 heller 1.1
501     ;;; Debugging
502    
503 heller 1.66 (defclass slime-env (env:environment)
504     ((debugger-hook :initarg :debugger-hoook)))
505    
506     (defun slime-env (hook io-bindings)
507     (make-instance 'slime-env :name "SLIME Environment"
508     :io-bindings io-bindings
509     :debugger-hoook hook))
510    
511 heller 1.111 (defmethod env-internals:environment-display-notifier
512 heller 1.66 ((env slime-env) &key restarts condition)
513 heller 1.111 (declare (ignore restarts condition))
514 heller 1.113 (funcall (swank-sym :swank-debugger-hook) condition *debugger-hook*)
515     ;; nil
516 heller 1.111 )
517 heller 1.66
518     (defmethod env-internals:environment-display-debugger ((env slime-env))
519     *debug-io*)
520    
521 heller 1.111 (defmethod env-internals:confirm-p ((e slime-env) &optional msg &rest args)
522     (apply (swank-sym :y-or-n-p-in-emacs) msg args))
523    
524 heller 1.110 (defimplementation call-with-debugger-hook (hook fun)
525     (let ((*debugger-hook* hook))
526     (env:with-environment ((slime-env hook '()))
527     (funcall fun))))
528 heller 1.66
529 msimmons 1.100 (defimplementation install-debugger-globally (function)
530     (setq *debugger-hook* function)
531     (setf (env:environment) (slime-env function '())))
532    
533 heller 1.26 (defvar *sldb-top-frame*)
534 heller 1.1
535     (defun interesting-frame-p (frame)
536 heller 1.36 (cond ((or (dbg::call-frame-p frame)
537     (dbg::derived-call-frame-p frame)
538     (dbg::foreign-frame-p frame)
539     (dbg::interpreted-call-frame-p frame))
540     t)
541     ((dbg::catch-frame-p frame) dbg:*print-catch-frames*)
542     ((dbg::binding-frame-p frame) dbg:*print-binding-frames*)
543     ((dbg::handler-frame-p frame) dbg:*print-handler-frames*)
544     ((dbg::restart-frame-p frame) dbg:*print-restart-frames*)
545     (t nil)))
546 heller 1.1
547 heller 1.41 (defun nth-next-frame (frame n)
548     "Unwind FRAME N times."
549     (do ((frame frame (dbg::frame-next frame))
550     (i n (if (interesting-frame-p frame) (1- i) i)))
551 heller 1.48 ((or (not frame)
552     (and (interesting-frame-p frame) (zerop i)))
553     frame)))
554 heller 1.41
555     (defun nth-frame (index)
556     (nth-next-frame *sldb-top-frame* index))
557 heller 1.139
558 heller 1.41 (defun find-top-frame ()
559     "Return the most suitable top-frame for the debugger."
560 mbaringer 1.69 (or (do ((frame (dbg::debugger-stack-current-frame dbg::*debugger-stack*)
561     (nth-next-frame frame 1)))
562     ((or (null frame) ; no frame found!
563     (and (dbg::call-frame-p frame)
564     (eq (dbg::call-frame-function-name frame)
565     'invoke-debugger)))
566     (nth-next-frame frame 1)))
567     ;; if we can't find a invoke-debugger frame, take any old frame at the top
568     (dbg::debugger-stack-current-frame dbg::*debugger-stack*)))
569 heller 1.41
570     (defimplementation call-with-debugging-environment (fn)
571     (dbg::with-debugger-stack ()
572     (let ((*sldb-top-frame* (find-top-frame)))
573     (funcall fn))))
574 heller 1.1
575 heller 1.30 (defimplementation compute-backtrace (start end)
576 heller 1.1 (let ((end (or end most-positive-fixnum))
577     (backtrace '()))
578     (do ((frame (nth-frame start) (dbg::frame-next frame))
579     (i start))
580     ((or (not frame) (= i end)) (nreverse backtrace))
581     (when (interesting-frame-p frame)
582     (incf i)
583 heller 1.121 (push frame backtrace)))))
584 heller 1.1
585 heller 1.36 (defun frame-actual-args (frame)
586 msimmons 1.141 (let ((*break-on-signals* nil)
587     (kind nil))
588     (loop for arg in (dbg::call-frame-arglist frame)
589     if (eq kind '&rest)
590     nconc (handler-case
591     (dbg::dbg-eval arg frame)
592     (error (e) (list (format nil "<~A>" arg))))
593     and do (loop-finish)
594     else
595     if (member arg '(&rest &optional &key))
596     do (setq kind arg)
597     else
598     nconc
599     (handler-case
600     (nconc (and (eq kind '&key)
601     (list (cond ((symbolp arg)
602     (intern (symbol-name arg) :keyword))
603     ((and (consp arg) (symbolp (car arg)))
604     (intern (symbol-name (car arg)) :keyword))
605     (t (caar arg)))))
606     (list (dbg::dbg-eval
607     (cond ((symbolp arg) arg)
608     ((and (consp arg) (symbolp (car arg)))
609     (car arg))
610     (t (cadar arg)))
611     frame)))
612     (error (e) (list (format nil "<~A>" arg)))))))
613 heller 1.36
614 heller 1.121 (defimplementation print-frame (frame stream)
615     (cond ((dbg::call-frame-p frame)
616 msimmons 1.141 (prin1 (cons (dbg::call-frame-function-name frame)
617     (frame-actual-args frame))
618     stream))
619 heller 1.121 (t (princ frame stream))))
620 heller 1.1
621 heller 1.47 (defun frame-vars (frame)
622     (first (dbg::frame-locals-format-list frame #'list 75 0)))
623    
624 lgorrie 1.17 (defimplementation frame-locals (n)
625 heller 1.29 (let ((frame (nth-frame n)))
626 heller 1.1 (if (dbg::call-frame-p frame)
627 heller 1.47 (mapcar (lambda (var)
628     (destructuring-bind (name value symbol location) var
629     (declare (ignore name location))
630     (list :name symbol :id 0
631     :value value)))
632     (frame-vars frame)))))
633    
634     (defimplementation frame-var-value (frame var)
635     (let ((frame (nth-frame frame)))
636     (destructuring-bind (_n value _s _l) (nth var (frame-vars frame))
637     (declare (ignore _n _s _l))
638     value)))
639 heller 1.1
640 heller 1.130 (defimplementation frame-source-location (frame)
641 heller 1.60 (let ((frame (nth-frame frame))
642     (callee (if (plusp frame) (nth-frame (1- frame)))))
643 heller 1.1 (if (dbg::call-frame-p frame)
644 heller 1.60 (let ((dspec (dbg::call-frame-function-name frame))
645     (cname (and (dbg::call-frame-p callee)
646 heller 1.139 (dbg::call-frame-function-name callee)))
647     (path (and (dbg::call-frame-p frame)
648     (dbg::call-frame-edit-path frame))))
649 heller 1.60 (if dspec
650 heller 1.139 (frame-location dspec cname path))))))
651 heller 1.26
652     (defimplementation eval-in-frame (form frame-number)
653     (let ((frame (nth-frame frame-number)))
654     (dbg::dbg-eval form frame)))
655    
656     (defimplementation return-from-frame (frame-number form)
657     (let* ((frame (nth-frame frame-number))
658 heller 1.30 (return-frame (dbg::find-frame-for-return frame)))
659 heller 1.26 (dbg::dbg-return-from-call-frame frame form return-frame
660     dbg::*debugger-stack*)))
661    
662     (defimplementation restart-frame (frame-number)
663     (let ((frame (nth-frame frame-number)))
664     (dbg::restart-frame frame :same-args t)))
665 heller 1.1
666 heller 1.109 (defimplementation disassemble-frame (frame-number)
667     (let* ((frame (nth-frame frame-number)))
668     (when (dbg::call-frame-p frame)
669     (let ((function (dbg::get-call-frame-function frame)))
670     (disassemble function)))))
671    
672 heller 1.18 ;;; Definition finding
673    
674 heller 1.139 (defun frame-location (dspec callee-name edit-path)
675 heller 1.60 (let ((infos (dspec:find-dspec-locations dspec)))
676     (cond (infos
677     (destructuring-bind ((rdspec location) &rest _) infos
678     (declare (ignore _))
679     (let ((name (and callee-name (symbolp callee-name)
680 heller 1.139 (string callee-name)))
681     (path (edit-path-to-cmucl-source-path edit-path)))
682     (make-dspec-location rdspec location
683     `(:call-site ,name :edit-path ,path)))))
684 heller 1.60 (t
685     (list :error (format nil "Source location not available for: ~S"
686     dspec))))))
687 heller 1.4
688 heller 1.139 ;; dbg::call-frame-edit-path is not documented but lets assume the
689     ;; binary representation of the integer EDIT-PATH should be
690     ;; interpreted as a sequence of CAR or CDR. #b1111010 is roughly the
691     ;; same as cadadddr. Something is odd with the highest bit.
692     (defun edit-path-to-cmucl-source-path (edit-path)
693     (and edit-path
694     (cons 0
695     (let ((n -1))
696     (loop for i from (1- (integer-length edit-path)) downto 0
697     if (logbitp i edit-path) do (incf n)
698     else collect (prog1 n (setq n 0)))))))
699    
700     ;; (edit-path-to-cmucl-source-path #b1111010) => (0 3 1)
701    
702 heller 1.33 (defimplementation find-definitions (name)
703 heller 1.26 (let ((locations (dspec:find-name-locations dspec:*dspec-classes* name)))
704 heller 1.33 (loop for (dspec location) in locations
705     collect (list dspec (make-dspec-location dspec location)))))
706 heller 1.6
707 msimmons 1.56
708 heller 1.18 ;;; Compilation
709    
710 msimmons 1.42 (defmacro with-swank-compilation-unit ((location &rest options) &body body)
711     (lw:rebinding (location)
712     `(let ((compiler::*error-database* '()))
713     (with-compilation-unit ,options
714 heller 1.120 (multiple-value-prog1 (progn ,@body)
715     (signal-error-data-base compiler::*error-database*
716     ,location)
717     (signal-undefined-functions compiler::*unknown-functions*
718     ,location))))))
719 msimmons 1.42
720 heller 1.128 (defimplementation swank-compile-file (input-file output-file
721 sboukarev 1.136 load-p external-format
722     &key policy)
723     (declare (ignore policy))
724 heller 1.128 (with-swank-compilation-unit (input-file)
725     (compile-file input-file
726     :output-file output-file
727     :load load-p
728 heller 1.119 :external-format external-format)))
729 msimmons 1.56
730 eweitz 1.70 (defvar *within-call-with-compilation-hooks* nil
731     "Whether COMPILE-FILE was called from within CALL-WITH-COMPILATION-HOOKS.")
732    
733     (defvar *undefined-functions-hash* nil
734     "Hash table to map info about undefined functions to pathnames.")
735    
736     (lw:defadvice (compile-file compile-file-and-collect-notes :around)
737     (pathname &rest rest)
738 msimmons 1.75 (multiple-value-prog1 (apply #'lw:call-next-advice pathname rest)
739 eweitz 1.70 (when *within-call-with-compilation-hooks*
740     (maphash (lambda (unfun dspecs)
741     (dolist (dspec dspecs)
742     (let ((unfun-info (list unfun dspec)))
743     (unless (gethash unfun-info *undefined-functions-hash*)
744     (setf (gethash unfun-info *undefined-functions-hash*)
745     pathname)))))
746     compiler::*unknown-functions*))))
747    
748 msimmons 1.56 (defimplementation call-with-compilation-hooks (function)
749 eweitz 1.70 (let ((compiler::*error-database* '())
750     (*undefined-functions-hash* (make-hash-table :test 'equal))
751     (*within-call-with-compilation-hooks* t))
752     (with-compilation-unit ()
753     (prog1 (funcall function)
754     (signal-error-data-base compiler::*error-database*)
755     (signal-undefined-functions compiler::*unknown-functions*)))))
756 heller 1.1
757     (defun map-error-database (database fn)
758     (loop for (filename . defs) in database do
759     (loop for (dspec . conditions) in defs do
760 heller 1.140 (dolist (c conditions)
761     (multiple-value-bind (condition path)
762     (if (consp c) (values (car c) (cdr c)) (values c nil))
763     (funcall fn filename dspec condition path))))))
764 heller 1.1
765     (defun lispworks-severity (condition)
766     (cond ((not condition) :warning)
767     (t (etypecase condition
768 heller 1.6 (error :error)
769 heller 1.1 (style-warning :warning)
770     (warning :warning)))))
771    
772     (defun signal-compiler-condition (message location condition)
773     (check-type message string)
774     (signal
775     (make-instance 'compiler-condition :message message
776     :severity (lispworks-severity condition)
777     :location location
778     :original-condition condition)))
779    
780 heller 1.118 (defvar *temp-file-format* '(:utf-8 :eol-style :lf))
781    
782 heller 1.1 (defun compile-from-temp-file (string filename)
783     (unwind-protect
784     (progn
785 heller 1.118 (with-open-file (s filename :direction :output
786     :if-exists :supersede
787     :external-format *temp-file-format*)
788    
789 heller 1.1 (write-string string s)
790     (finish-output s))
791 heller 1.120 (multiple-value-bind (binary-filename warnings? failure?)
792     (compile-file filename :load t
793     :external-format *temp-file-format*)
794     (declare (ignore warnings?))
795 heller 1.6 (when binary-filename
796 heller 1.120 (delete-file binary-filename))
797     (not failure?)))
798 heller 1.1 (delete-file filename)))
799    
800 heller 1.117 (defun dspec-function-name-position (dspec fallback)
801 heller 1.34 (etypecase dspec
802     (cons (let ((name (dspec:dspec-primary-name dspec)))
803 heller 1.37 (typecase name
804 heller 1.34 ((or symbol string)
805     (list :function-name (string name)))
806 heller 1.117 (t fallback))))
807     (null fallback)
808 heller 1.34 (symbol (list :function-name (string dspec)))))
809 heller 1.18
810 lgorrie 1.45 (defmacro with-fairly-standard-io-syntax (&body body)
811     "Like WITH-STANDARD-IO-SYNTAX but preserve *PACKAGE* and *READTABLE*."
812     (let ((package (gensym))
813     (readtable (gensym)))
814     `(let ((,package *package*)
815     (,readtable *readtable*))
816     (with-standard-io-syntax
817     (let ((*package* ,package)
818     (*readtable* ,readtable))
819     ,@body)))))
820    
821 heller 1.117 (defun skip-comments (stream)
822     (let ((pos0 (file-position stream)))
823     (cond ((equal (ignore-errors (list (read-delimited-list #\( stream)))
824     '(()))
825     (file-position stream (1- (file-position stream))))
826     (t (file-position stream pos0)))))
827    
828 heller 1.52 #-(or lispworks4.1 lispworks4.2) ; no dspec:parse-form-dspec prior to 4.3
829 msimmons 1.42 (defun dspec-stream-position (stream dspec)
830 lgorrie 1.45 (with-fairly-standard-io-syntax
831 heller 1.117 (loop (let* ((pos (progn (skip-comments stream) (file-position stream)))
832 lgorrie 1.44 (form (read stream nil '#1=#:eof)))
833     (when (eq form '#1#)
834     (return nil))
835     (labels ((check-dspec (form)
836     (when (consp form)
837     (let ((operator (car form)))
838     (case operator
839     ((progn)
840     (mapcar #'check-dspec
841     (cdr form)))
842     ((eval-when locally macrolet symbol-macrolet)
843     (mapcar #'check-dspec
844     (cddr form)))
845     ((in-package)
846     (let ((package (find-package (second form))))
847     (when package
848     (setq *package* package))))
849     (otherwise
850     (let ((form-dspec (dspec:parse-form-dspec form)))
851     (when (dspec:dspec-equal dspec form-dspec)
852     (return pos)))))))))
853     (check-dspec form))))))
854 msimmons 1.42
855 heller 1.52 (defun dspec-file-position (file dspec)
856 mbaringer 1.90 (let* ((*compile-file-pathname* (pathname file))
857     (*compile-file-truename* (truename *compile-file-pathname*))
858     (*load-pathname* *compile-file-pathname*)
859     (*load-truename* *compile-file-truename*))
860     (with-open-file (stream file)
861     (let ((pos
862     #-(or lispworks4.1 lispworks4.2)
863     (dspec-stream-position stream dspec)))
864     (if pos
865 heller 1.117 (list :position (1+ pos))
866     (dspec-function-name-position dspec `(:position 1)))))))
867 heller 1.52
868 heller 1.25 (defun emacs-buffer-location-p (location)
869     (and (consp location)
870     (eq (car location) :emacs-buffer)))
871    
872 heller 1.60 (defun make-dspec-location (dspec location &optional hints)
873 heller 1.52 (etypecase location
874     ((or pathname string)
875     (multiple-value-bind (file err)
876     (ignore-errors (namestring (truename location)))
877     (if err
878     (list :error (princ-to-string err))
879     (make-location `(:file ,file)
880 heller 1.60 (dspec-file-position file dspec)
881     hints))))
882 heller 1.52 (symbol
883     `(:error ,(format nil "Cannot resolve location: ~S" location)))
884     ((satisfies emacs-buffer-location-p)
885     (destructuring-bind (_ buffer offset string) location
886     (declare (ignore _ string))
887     (make-location `(:buffer ,buffer)
888 heller 1.117 (dspec-function-name-position dspec `(:offset ,offset 0))
889 heller 1.60 hints)))))
890 heller 1.1
891 heller 1.140 (defun make-dspec-progenitor-location (dspec location edit-path)
892 msimmons 1.42 (let ((canon-dspec (dspec:canonicalize-dspec dspec)))
893     (make-dspec-location
894     (if canon-dspec
895     (if (dspec:local-dspec-p canon-dspec)
896     (dspec:dspec-progenitor canon-dspec)
897 heller 1.140 canon-dspec)
898     nil)
899     location
900     (if edit-path
901     (list :edit-path (edit-path-to-cmucl-source-path edit-path))))))
902 msimmons 1.42
903 eweitz 1.70 (defun signal-error-data-base (database &optional location)
904 heller 1.1 (map-error-database
905     database
906 heller 1.140 (lambda (filename dspec condition edit-path)
907 heller 1.1 (signal-compiler-condition
908     (format nil "~A" condition)
909 heller 1.140 (make-dspec-progenitor-location dspec (or location filename) edit-path)
910 heller 1.1 condition))))
911    
912 eweitz 1.71 (defun unmangle-unfun (symbol)
913     "Converts symbols like 'SETF::|\"CL-USER\" \"GET\"| to
914     function names like \(SETF GET)."
915 heller 1.93 (cond ((sys::setf-symbol-p symbol)
916     (sys::setf-pair-from-underlying-name symbol))
917     (t symbol)))
918    
919 eweitz 1.70 (defun signal-undefined-functions (htab &optional filename)
920 heller 1.1 (maphash (lambda (unfun dspecs)
921     (dolist (dspec dspecs)
922     (signal-compiler-condition
923 eweitz 1.71 (format nil "Undefined function ~A" (unmangle-unfun unfun))
924 heller 1.140 (make-dspec-progenitor-location
925     dspec
926     (or filename
927     (gethash (list unfun dspec) *undefined-functions-hash*))
928     nil)
929 heller 1.1 nil)))
930     htab))
931 heller 1.2
932 heller 1.126 (defimplementation swank-compile-string (string &key buffer position filename
933     policy)
934     (declare (ignore filename policy))
935 heller 1.1 (assert buffer)
936     (assert position)
937 heller 1.30 (let* ((location (list :emacs-buffer buffer position string))
938 heller 1.26 (tmpname (hcl:make-temp-file nil "lisp")))
939 msimmons 1.42 (with-swank-compilation-unit (location)
940 heller 1.26 (compile-from-temp-file
941 heller 1.68 (with-output-to-string (s)
942     (let ((*print-radix* t))
943     (print `(eval-when (:compile-toplevel)
944     (setq dspec::*location* (list ,@location)))
945     s))
946     (write-string string s))
947 msimmons 1.42 tmpname))))
948 heller 1.1
949 heller 1.3 ;;; xref
950    
951 heller 1.31 (defmacro defxref (name function)
952     `(defimplementation ,name (name)
953     (xref-results (,function name))))
954    
955     (defxref who-calls hcl:who-calls)
956 msimmons 1.42 (defxref who-macroexpands hcl:who-calls) ; macros are in the calls table too
957 heller 1.67 (defxref calls-who hcl:calls-who)
958 msimmons 1.42 (defxref list-callers list-callers-internal)
959 sboukarev 1.137 (defxref list-callees list-callees-internal)
960 msimmons 1.42
961     (defun list-callers-internal (name)
962     (let ((callers (make-array 100
963     :fill-pointer 0
964     :adjustable t)))
965     (hcl:sweep-all-objects
966     #'(lambda (object)
967     (when (and #+Harlequin-PC-Lisp (low:compiled-code-p object)
968 msimmons 1.138 #+Harlequin-Unix-Lisp (sys:callablep object)
969     #-(or Harlequin-PC-Lisp Harlequin-Unix-Lisp) (sys:compiled-code-p object)
970 msimmons 1.42 (system::find-constant$funcallable name object))
971     (vector-push-extend object callers))))
972     ;; Delay dspec:object-dspec until after sweep-all-objects
973     ;; to reduce allocation problems.
974     (loop for object across callers
975     collect (if (symbolp object)
976     (list 'function object)
977 heller 1.63 (or (dspec:object-dspec object) object)))))
978 heller 1.36
979 sboukarev 1.137 (defun list-callees-internal (name)
980 msimmons 1.138 (let ((callees '()))
981     (system::find-constant$funcallable
982     'junk name
983     :test #'(lambda (junk constant)
984     (declare (ignore junk))
985     (when (and (symbolp constant)
986     (fboundp constant))
987     (pushnew (list 'function constant) callees :test 'equal))
988     ;; Return nil so we iterate over all constants.
989     nil))
990     callees))
991 sboukarev 1.137
992 heller 1.37 ;; only for lispworks 4.2 and above
993     #-lispworks4.1
994     (progn
995     (defxref who-references hcl:who-references)
996     (defxref who-binds hcl:who-binds)
997     (defxref who-sets hcl:who-sets))
998    
999 heller 1.36 (defimplementation who-specializes (classname)
1000     (let ((methods (clos:class-direct-methods (find-class classname))))
1001     (xref-results (mapcar #'dspec:object-dspec methods))))
1002 heller 1.31
1003     (defun xref-results (dspecs)
1004 heller 1.63 (flet ((frob-locs (dspec locs)
1005     (cond (locs
1006     (loop for (name loc) in locs
1007     collect (list name (make-dspec-location name loc))))
1008     (t `((,dspec (:error "Source location not available")))))))
1009     (loop for dspec in dspecs
1010     append (frob-locs dspec (dspec:dspec-definition-locations dspec)))))
1011 heller 1.66
1012 heller 1.25 ;;; Inspector
1013 mbaringer 1.58
1014 heller 1.95 (defmethod emacs-inspect ((o t))
1015 heller 1.60 (lispworks-inspect o))
1016    
1017 heller 1.95 (defmethod emacs-inspect ((o function))
1018 heller 1.60 (lispworks-inspect o))
1019    
1020 heller 1.82 ;; FIXME: slot-boundp-using-class in LW works with names so we can't
1021     ;; use our method in swank.lisp.
1022 heller 1.95 (defmethod emacs-inspect ((o standard-object))
1023 heller 1.82 (lispworks-inspect o))
1024    
1025 heller 1.60 (defun lispworks-inspect (o)
1026 heller 1.25 (multiple-value-bind (names values _getter _setter type)
1027     (lw:get-inspector-values o nil)
1028     (declare (ignore _getter _setter))
1029 heller 1.60 (append
1030     (label-value-line "Type" type)
1031 msimmons 1.91 (loop for name in names
1032     for value in values
1033 heller 1.96 append (label-value-line name value)))))
1034 heller 1.25
1035 lgorrie 1.46 ;;; Miscellaneous
1036    
1037     (defimplementation quit-lisp ()
1038     (lispworks:quit))
1039    
1040 heller 1.66 ;;; Tracing
1041    
1042     (defun parse-fspec (fspec)
1043     "Return a dspec for FSPEC."
1044     (ecase (car fspec)
1045 heller 1.67 ((:defmethod) `(method ,(cdr fspec)))))
1046 heller 1.66
1047     (defun tracedp (dspec)
1048     (member dspec (eval '(trace)) :test #'equal))
1049    
1050 heller 1.67 (defun toggle-trace-aux (dspec)
1051 heller 1.66 (cond ((tracedp dspec)
1052     (eval `(untrace ,dspec))
1053     (format nil "~S is now untraced." dspec))
1054     (t
1055     (eval `(trace (,dspec)))
1056     (format nil "~S is now traced." dspec))))
1057    
1058 heller 1.67 (defimplementation toggle-trace (fspec)
1059     (toggle-trace-aux (parse-fspec fspec)))
1060 heller 1.66
1061 heller 1.16 ;;; Multithreading
1062    
1063 mbaringer 1.86 (defimplementation initialize-multiprocessing (continuation)
1064 heller 1.87 (cond ((not mp::*multiprocessing*)
1065     (push (list "Initialize SLIME" '() continuation)
1066     mp:*initial-processes*)
1067     (mp:initialize-multiprocessing))
1068     (t (funcall continuation))))
1069 heller 1.16
1070 heller 1.18 (defimplementation spawn (fn &key name)
1071 heller 1.127 (mp:process-run-function name () fn))
1072 heller 1.48
1073     (defvar *id-lock* (mp:make-lock))
1074     (defvar *thread-id-counter* 0)
1075    
1076     (defimplementation thread-id (thread)
1077     (mp:with-lock (*id-lock*)
1078     (or (getf (mp:process-plist thread) 'id)
1079     (setf (getf (mp:process-plist thread) 'id)
1080     (incf *thread-id-counter*)))))
1081    
1082     (defimplementation find-thread (id)
1083     (find id (mp:list-all-processes)
1084     :key (lambda (p) (getf (mp:process-plist p) 'id))))
1085 heller 1.16
1086 heller 1.21 (defimplementation thread-name (thread)
1087     (mp:process-name thread))
1088 heller 1.16
1089 heller 1.21 (defimplementation thread-status (thread)
1090     (format nil "~A ~D"
1091     (mp:process-whostate thread)
1092     (mp:process-priority thread)))
1093 heller 1.16
1094 heller 1.18 (defimplementation make-lock (&key name)
1095 heller 1.16 (mp:make-lock :name name))
1096    
1097 heller 1.18 (defimplementation call-with-lock-held (lock function)
1098 heller 1.16 (mp:with-lock (lock) (funcall function)))
1099 heller 1.20
1100     (defimplementation current-thread ()
1101     mp:*current-process*)
1102 heller 1.21
1103     (defimplementation all-threads ()
1104     (mp:list-all-processes))
1105 heller 1.20
1106     (defimplementation interrupt-thread (thread fn)
1107     (mp:process-interrupt thread fn))
1108 heller 1.25
1109     (defimplementation kill-thread (thread)
1110     (mp:process-kill thread))
1111 heller 1.27
1112     (defimplementation thread-alive-p (thread)
1113     (mp:process-alive-p thread))
1114 heller 1.20
1115 heller 1.102 (defstruct (mailbox (:conc-name mailbox.))
1116     (mutex (mp:make-lock :name "thread mailbox"))
1117     (queue '() :type list))
1118    
1119 heller 1.20 (defvar *mailbox-lock* (mp:make-lock))
1120    
1121     (defun mailbox (thread)
1122     (mp:with-lock (*mailbox-lock*)
1123     (or (getf (mp:process-plist thread) 'mailbox)
1124     (setf (getf (mp:process-plist thread) 'mailbox)
1125 heller 1.102 (make-mailbox)))))
1126 heller 1.20
1127 heller 1.112 (defimplementation receive-if (test &optional timeout)
1128 heller 1.102 (let* ((mbox (mailbox mp:*current-process*))
1129     (lock (mailbox.mutex mbox)))
1130 heller 1.112 (assert (or (not timeout) (eq timeout t)))
1131 heller 1.102 (loop
1132 heller 1.106 (check-slime-interrupts)
1133     (mp:with-lock (lock "receive-if/try")
1134     (let* ((q (mailbox.queue mbox))
1135     (tail (member-if test q)))
1136     (when tail
1137     (setf (mailbox.queue mbox) (nconc (ldiff q tail) (cdr tail)))
1138     (return (car tail)))))
1139 heller 1.112 (when (eq timeout t) (return (values nil t)))
1140 heller 1.106 (mp:process-wait-with-timeout
1141 heller 1.125 "receive-if" 0.3 (lambda () (some test (mailbox.queue mbox)))))))
1142 heller 1.102
1143     (defimplementation send (thread message)
1144     (let ((mbox (mailbox thread)))
1145 heller 1.106 (mp:with-lock ((mailbox.mutex mbox))
1146     (setf (mailbox.queue mbox)
1147     (nconc (mailbox.queue mbox) (list message))))))
1148 heller 1.3
1149 heller 1.127 (defimplementation set-default-initial-binding (var form)
1150     (setq mp:*process-initial-bindings*
1151     (acons var `(eval (quote ,form))
1152     mp:*process-initial-bindings* )))
1153    
1154 heller 1.131 (defimplementation thread-attributes (thread)
1155     (list :priority (mp:process-priority thread)
1156     :idle (mp:process-idle-time thread)))
1157    
1158 heller 1.66 ;;; Some intergration with the lispworks environment
1159    
1160 heller 1.74 (defun swank-sym (name) (find-symbol (string name) :swank))
1161 mkoeppe 1.77
1162 eweitz 1.89
1163     ;;;; Weak hashtables
1164    
1165     (defimplementation make-weak-key-hash-table (&rest args)
1166     (apply #'make-hash-table :weak-kind :key args))
1167    
1168     (defimplementation make-weak-value-hash-table (&rest args)
1169     (apply #'make-hash-table :weak-kind :value args))

  ViewVC Help
Powered by ViewVC 1.1.5