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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.92 - (hide annotations)
Thu Aug 23 19:03:37 2007 UTC (6 years, 8 months ago) by heller
Branch: MAIN
Changes since 1.91: +4 -5 lines
Introduce backend-inspector class.

* swank-backend.lisp (backend-inspector): New class. Introduce a named
  class to give as another way to dispatch to backend methods.

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

  ViewVC Help
Powered by ViewVC 1.1.5