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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5