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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5