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

Contents of /slime/swank-lispworks.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.85 - (hide annotations)
Thu Aug 10 11:53:35 2006 UTC (7 years, 8 months ago) by heller
Branch: MAIN
Changes since 1.84: +2 -3 lines
swank-backend.lisp (definterface): Drop that incredibly unportable
CLOS stuff. Use plists and plain functions instead.  Update backends
accordingly.
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 dcrosher 1.83 (declare (ignore buffering timeout))
71 heller 1.85 (assert (member external-format '(nil :iso-latin-1-unix)))
72 heller 1.61 (let* ((fd (comm::get-fd-from-socket socket)))
73 heller 1.13 (assert (/= fd -1))
74     (make-instance 'comm:socket-stream :socket fd :direction :io
75     :element-type 'base-char)))
76    
77 heller 1.74 (defun find-external-format (coding-system &optional default)
78     (case coding-system
79     (:iso-latin-1-unix '(:latin-1 :eol-style :lf))
80     (:utf-8-unix '(:utf-8 :eol-style :lf))
81     (t default)))
82    
83 heller 1.37 (defun set-sigint-handler ()
84     ;; Set SIGINT handler on Swank request handler thread.
85     #-win32
86     (sys::set-signal-handler +sigint+
87     (make-sigint-handler mp:*current-process*)))
88    
89 heller 1.15 ;;; Unix signals
90    
91 heller 1.18 (defun sigint-handler ()
92 heller 1.16 (with-simple-restart (continue "Continue from SIGINT handler.")
93     (invoke-debugger "SIGINT")))
94 heller 1.1
95 heller 1.18 (defun make-sigint-handler (process)
96     (lambda (&rest args)
97     (declare (ignore args))
98     (mp:process-interrupt process #'sigint-handler)))
99    
100 heller 1.38 (defimplementation call-without-interrupts (fn)
101 heller 1.37 (lw:without-interrupts (funcall fn)))
102 heller 1.48
103 heller 1.29 (defimplementation getpid ()
104     #+win32 (win32:get-current-process-id)
105     #-win32 (system::getpid))
106 heller 1.1
107 heller 1.23 (defimplementation lisp-implementation-type-name ()
108     "lispworks")
109    
110 heller 1.36 (defimplementation set-default-directory (directory)
111     (namestring (hcl:change-directory directory)))
112 heller 1.40
113     ;;;; Documentation
114 heller 1.36
115 msimmons 1.57 (defimplementation arglist (symbol-or-function)
116     (let ((arglist (lw:function-lambda-list symbol-or-function)))
117 heller 1.30 (etypecase arglist
118 heller 1.39 ((member :dont-know)
119     :not-available)
120     (list
121     arglist))))
122 msimmons 1.57
123     (defimplementation function-name (function)
124     (nth-value 2 (function-lambda-expression function)))
125 heller 1.1
126 lgorrie 1.17 (defimplementation macroexpand-all (form)
127 heller 1.1 (walker:walk-form form))
128    
129 heller 1.37 (defun generic-function-p (object)
130 heller 1.36 (typep object 'generic-function))
131    
132 lgorrie 1.17 (defimplementation describe-symbol-for-emacs (symbol)
133 heller 1.1 "Return a plist describing SYMBOL.
134     Return NIL if the symbol is unbound."
135     (let ((result '()))
136     (labels ((first-line (string)
137     (let ((pos (position #\newline string)))
138     (if (null pos) string (subseq string 0 pos))))
139     (doc (kind &optional (sym symbol))
140     (let ((string (documentation sym kind)))
141     (if string
142     (first-line string)
143     :not-documented)))
144     (maybe-push (property value)
145     (when value
146     (setf result (list* property value result)))))
147     (maybe-push
148     :variable (when (boundp symbol)
149     (doc 'variable)))
150     (maybe-push
151 heller 1.36 :generic-function (if (and (fboundp symbol)
152 heller 1.37 (generic-function-p (fdefinition symbol)))
153 heller 1.36 (doc 'function)))
154     (maybe-push
155     :function (if (and (fboundp symbol)
156 heller 1.37 (not (generic-function-p (fdefinition symbol))))
157 heller 1.1 (doc 'function)))
158     (maybe-push
159 heller 1.49 :setf (let ((setf-name (sys:underlying-setf-name `(setf ,symbol))))
160     (if (fboundp setf-name)
161     (doc 'setf))))
162     (maybe-push
163 heller 1.1 :class (if (find-class symbol nil)
164     (doc 'class)))
165 heller 1.30 result)))
166 heller 1.1
167 heller 1.30 (defimplementation describe-definition (symbol type)
168     (ecase type
169     (:variable (describe-symbol symbol))
170     (:class (describe (find-class symbol)))
171 heller 1.49 ((:function :generic-function) (describe-function symbol))
172     (:setf (describe-function (sys:underlying-setf-name `(setf ,symbol))))))
173 heller 1.30
174     (defun describe-function (symbol)
175     (cond ((fboundp symbol)
176     (format t "~%(~A~{ ~A~})~%~%~:[(not documented)~;~:*~A~]~%"
177     (string-downcase symbol)
178     (mapcar #'string-upcase
179     (lispworks:function-lambda-list symbol))
180     (documentation symbol 'function))
181 heller 1.38 (describe (fdefinition symbol)))
182 heller 1.30 (t (format t "~S is not fbound" symbol))))
183 heller 1.4
184 heller 1.30 (defun describe-symbol (sym)
185 heller 1.1 (format t "~A is a symbol in package ~A." sym (symbol-package sym))
186     (when (boundp sym)
187     (format t "~%~%Value: ~A" (symbol-value sym)))
188     (let ((doc (documentation sym 'variable)))
189     (when doc
190     (format t "~%~%Variable documentation:~%~A" doc)))
191     (when (fboundp sym)
192 heller 1.30 (describe-function sym)))
193 heller 1.1
194     ;;; Debugging
195    
196 heller 1.66 (defclass slime-env (env:environment)
197     ((debugger-hook :initarg :debugger-hoook)))
198    
199     (defun slime-env (hook io-bindings)
200     (make-instance 'slime-env :name "SLIME Environment"
201     :io-bindings io-bindings
202     :debugger-hoook hook))
203    
204     (defmethod env-internals:environment-display-notifier
205     ((env slime-env) &key restarts condition)
206     (declare (ignore restarts))
207     (funcall (slot-value env 'debugger-hook) condition *debugger-hook*))
208    
209     (defmethod env-internals:environment-display-debugger ((env slime-env))
210     *debug-io*)
211    
212     (defimplementation call-with-debugger-hook (hook fun)
213     (let ((*debugger-hook* hook))
214     (env:with-environment ((slime-env hook '()))
215     (funcall fun))))
216    
217 heller 1.26 (defvar *sldb-top-frame*)
218 heller 1.1
219     (defun interesting-frame-p (frame)
220 heller 1.36 (cond ((or (dbg::call-frame-p frame)
221     (dbg::derived-call-frame-p frame)
222     (dbg::foreign-frame-p frame)
223     (dbg::interpreted-call-frame-p frame))
224     t)
225     ((dbg::catch-frame-p frame) dbg:*print-catch-frames*)
226     ((dbg::binding-frame-p frame) dbg:*print-binding-frames*)
227     ((dbg::handler-frame-p frame) dbg:*print-handler-frames*)
228     ((dbg::restart-frame-p frame) dbg:*print-restart-frames*)
229     ((dbg::open-frame-p frame) dbg:*print-open-frames*)
230     (t nil)))
231 heller 1.1
232 heller 1.41 (defun nth-next-frame (frame n)
233     "Unwind FRAME N times."
234     (do ((frame frame (dbg::frame-next frame))
235     (i n (if (interesting-frame-p frame) (1- i) i)))
236 heller 1.48 ((or (not frame)
237     (and (interesting-frame-p frame) (zerop i)))
238     frame)))
239 heller 1.41
240     (defun nth-frame (index)
241     (nth-next-frame *sldb-top-frame* index))
242    
243     (defun find-top-frame ()
244     "Return the most suitable top-frame for the debugger."
245 mbaringer 1.69 (or (do ((frame (dbg::debugger-stack-current-frame dbg::*debugger-stack*)
246     (nth-next-frame frame 1)))
247     ((or (null frame) ; no frame found!
248     (and (dbg::call-frame-p frame)
249     (eq (dbg::call-frame-function-name frame)
250     'invoke-debugger)))
251     (nth-next-frame frame 1)))
252     ;; if we can't find a invoke-debugger frame, take any old frame at the top
253     (dbg::debugger-stack-current-frame dbg::*debugger-stack*)))
254 heller 1.41
255     (defimplementation call-with-debugging-environment (fn)
256     (dbg::with-debugger-stack ()
257     (let ((*sldb-top-frame* (find-top-frame)))
258     (funcall fn))))
259 heller 1.1
260 heller 1.30 (defimplementation compute-backtrace (start end)
261 heller 1.1 (let ((end (or end most-positive-fixnum))
262     (backtrace '()))
263     (do ((frame (nth-frame start) (dbg::frame-next frame))
264     (i start))
265     ((or (not frame) (= i end)) (nreverse backtrace))
266     (when (interesting-frame-p frame)
267     (incf i)
268     (push frame backtrace)))))
269    
270 heller 1.36 (defun frame-actual-args (frame)
271 heller 1.50 (let ((*break-on-signals* nil))
272     (mapcar (lambda (arg)
273     (case arg
274     ((&rest &optional &key) arg)
275     (t
276     (handler-case (dbg::dbg-eval arg frame)
277 msimmons 1.53 (error (e) (format nil "<~A>" arg))))))
278 heller 1.50 (dbg::call-frame-arglist frame))))
279 heller 1.36
280 heller 1.30 (defimplementation print-frame (frame stream)
281     (cond ((dbg::call-frame-p frame)
282 heller 1.36 (format stream "~S ~S"
283 heller 1.30 (dbg::call-frame-function-name frame)
284 heller 1.36 (frame-actual-args frame)))
285 heller 1.30 (t (princ frame stream))))
286 heller 1.1
287 heller 1.47 (defun frame-vars (frame)
288     (first (dbg::frame-locals-format-list frame #'list 75 0)))
289    
290 lgorrie 1.17 (defimplementation frame-locals (n)
291 heller 1.29 (let ((frame (nth-frame n)))
292 heller 1.1 (if (dbg::call-frame-p frame)
293 heller 1.47 (mapcar (lambda (var)
294     (destructuring-bind (name value symbol location) var
295     (declare (ignore name location))
296     (list :name symbol :id 0
297     :value value)))
298     (frame-vars frame)))))
299    
300     (defimplementation frame-var-value (frame var)
301     (let ((frame (nth-frame frame)))
302     (destructuring-bind (_n value _s _l) (nth var (frame-vars frame))
303     (declare (ignore _n _s _l))
304     value)))
305 heller 1.1
306 lgorrie 1.17 (defimplementation frame-catch-tags (index)
307 heller 1.1 (declare (ignore index))
308     nil)
309    
310 lgorrie 1.17 (defimplementation frame-source-location-for-emacs (frame)
311 heller 1.60 (let ((frame (nth-frame frame))
312     (callee (if (plusp frame) (nth-frame (1- frame)))))
313 heller 1.1 (if (dbg::call-frame-p frame)
314 heller 1.60 (let ((dspec (dbg::call-frame-function-name frame))
315     (cname (and (dbg::call-frame-p callee)
316     (dbg::call-frame-function-name callee))))
317     (if dspec
318     (frame-location dspec cname))))))
319 heller 1.26
320     (defimplementation eval-in-frame (form frame-number)
321     (let ((frame (nth-frame frame-number)))
322     (dbg::dbg-eval form frame)))
323    
324     (defimplementation return-from-frame (frame-number form)
325     (let* ((frame (nth-frame frame-number))
326 heller 1.30 (return-frame (dbg::find-frame-for-return frame)))
327 heller 1.26 (dbg::dbg-return-from-call-frame frame form return-frame
328     dbg::*debugger-stack*)))
329    
330     (defimplementation restart-frame (frame-number)
331     (let ((frame (nth-frame frame-number)))
332     (dbg::restart-frame frame :same-args t)))
333 heller 1.1
334 heller 1.18 ;;; Definition finding
335    
336 heller 1.60 (defun frame-location (dspec callee-name)
337     (let ((infos (dspec:find-dspec-locations dspec)))
338     (cond (infos
339     (destructuring-bind ((rdspec location) &rest _) infos
340     (declare (ignore _))
341     (let ((name (and callee-name (symbolp callee-name)
342     (string callee-name))))
343     (make-dspec-location rdspec location
344     `(:call-site ,name)))))
345     (t
346     (list :error (format nil "Source location not available for: ~S"
347     dspec))))))
348 heller 1.4
349 heller 1.33 (defimplementation find-definitions (name)
350 heller 1.26 (let ((locations (dspec:find-name-locations dspec:*dspec-classes* name)))
351 heller 1.33 (loop for (dspec location) in locations
352     collect (list dspec (make-dspec-location dspec location)))))
353 heller 1.6
354 msimmons 1.56
355 heller 1.18 ;;; Compilation
356    
357 msimmons 1.42 (defmacro with-swank-compilation-unit ((location &rest options) &body body)
358     (lw:rebinding (location)
359     `(let ((compiler::*error-database* '()))
360     (with-compilation-unit ,options
361     ,@body
362     (signal-error-data-base compiler::*error-database* ,location)
363     (signal-undefined-functions compiler::*unknown-functions* ,location)))))
364    
365 heller 1.74 (defimplementation swank-compile-file (filename load-p
366     &optional external-format)
367 msimmons 1.42 (with-swank-compilation-unit (filename)
368 heller 1.74 (let ((ef (if external-format
369     (find-external-format external-format)
370     :default)))
371     (compile-file filename :load load-p :external-format ef))))
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 msimmons 1.75 (multiple-value-prog1 (apply #'lw:call-next-advice pathname rest)
382 eweitz 1.70 (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 eweitz 1.73 (let ((slime-nregex::*regex-groupings* 0)
537     (slime-nregex::*regex-groups* (make-array 10))
538 eweitz 1.71 (symbol-name (symbol-name symbol)))
539     (and (funcall (load-time-value
540 eweitz 1.73 (compile nil (slime-nregex:regex-compile "^\"(.+)\" \"(.+)\"$")))
541 eweitz 1.71 symbol-name)
542     (list 'setf
543     (intern (apply #'subseq symbol-name
544 eweitz 1.73 (aref slime-nregex::*regex-groups* 2))
545 eweitz 1.71 (find-package
546     (apply #'subseq symbol-name
547 eweitz 1.73 (aref slime-nregex::*regex-groups* 1))))))))
548 eweitz 1.71 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 heller 1.84 (defmethod inspect-for-emacs ((o t) (inspector lispworks-inspector))
635 mbaringer 1.58 (declare (ignore inspector))
636 heller 1.60 (lispworks-inspect o))
637    
638 heller 1.84 (defmethod inspect-for-emacs ((o function)
639     (inspector lispworks-inspector))
640 heller 1.60 (declare (ignore inspector))
641     (lispworks-inspect o))
642    
643 heller 1.82 ;; FIXME: slot-boundp-using-class in LW works with names so we can't
644     ;; use our method in swank.lisp.
645 heller 1.84 (defmethod inspect-for-emacs ((o standard-object)
646     (inspector lispworks-inspector))
647 heller 1.82 (declare (ignore inspector))
648     (lispworks-inspect o))
649    
650 heller 1.60 (defun lispworks-inspect (o)
651 heller 1.25 (multiple-value-bind (names values _getter _setter type)
652     (lw:get-inspector-values o nil)
653     (declare (ignore _getter _setter))
654 mbaringer 1.58 (values "A value."
655 heller 1.60 (append
656     (label-value-line "Type" type)
657     (mapcan #'label-value-line names values)))))
658 heller 1.25
659 lgorrie 1.46 ;;; Miscellaneous
660    
661     (defimplementation quit-lisp ()
662     (lispworks:quit))
663    
664 heller 1.66 ;;; Tracing
665    
666     (defun parse-fspec (fspec)
667     "Return a dspec for FSPEC."
668     (ecase (car fspec)
669 heller 1.67 ((:defmethod) `(method ,(cdr fspec)))))
670 heller 1.66
671     (defun tracedp (dspec)
672     (member dspec (eval '(trace)) :test #'equal))
673    
674 heller 1.67 (defun toggle-trace-aux (dspec)
675 heller 1.66 (cond ((tracedp dspec)
676     (eval `(untrace ,dspec))
677     (format nil "~S is now untraced." dspec))
678     (t
679     (eval `(trace (,dspec)))
680     (format nil "~S is now traced." dspec))))
681    
682 heller 1.67 (defimplementation toggle-trace (fspec)
683     (toggle-trace-aux (parse-fspec fspec)))
684 heller 1.66
685 heller 1.16 ;;; Multithreading
686    
687 heller 1.80 (defimplementation initialize-multiprocessing ()
688 heller 1.16 (mp:initialize-multiprocessing))
689    
690 heller 1.18 (defimplementation spawn (fn &key name)
691 heller 1.38 (let ((mp:*process-initial-bindings*
692     (remove (find-package :cl)
693     mp:*process-initial-bindings*
694     :key (lambda (x) (symbol-package (car x))))))
695     (mp:process-run-function name () fn)))
696 heller 1.48
697     (defvar *id-lock* (mp:make-lock))
698     (defvar *thread-id-counter* 0)
699    
700     (defimplementation thread-id (thread)
701     (mp:with-lock (*id-lock*)
702     (or (getf (mp:process-plist thread) 'id)
703     (setf (getf (mp:process-plist thread) 'id)
704     (incf *thread-id-counter*)))))
705    
706     (defimplementation find-thread (id)
707     (find id (mp:list-all-processes)
708     :key (lambda (p) (getf (mp:process-plist p) 'id))))
709 heller 1.16
710 heller 1.21 (defimplementation thread-name (thread)
711     (mp:process-name thread))
712 heller 1.16
713 heller 1.21 (defimplementation thread-status (thread)
714     (format nil "~A ~D"
715     (mp:process-whostate thread)
716     (mp:process-priority thread)))
717 heller 1.16
718 heller 1.18 (defimplementation make-lock (&key name)
719 heller 1.16 (mp:make-lock :name name))
720    
721 heller 1.18 (defimplementation call-with-lock-held (lock function)
722 heller 1.16 (mp:with-lock (lock) (funcall function)))
723 heller 1.20
724     (defimplementation current-thread ()
725     mp:*current-process*)
726 heller 1.21
727     (defimplementation all-threads ()
728     (mp:list-all-processes))
729 heller 1.20
730     (defimplementation interrupt-thread (thread fn)
731     (mp:process-interrupt thread fn))
732 heller 1.25
733     (defimplementation kill-thread (thread)
734     (mp:process-kill thread))
735 heller 1.27
736     (defimplementation thread-alive-p (thread)
737     (mp:process-alive-p thread))
738 heller 1.20
739     (defvar *mailbox-lock* (mp:make-lock))
740    
741     (defun mailbox (thread)
742     (mp:with-lock (*mailbox-lock*)
743     (or (getf (mp:process-plist thread) 'mailbox)
744     (setf (getf (mp:process-plist thread) 'mailbox)
745     (mp:make-mailbox)))))
746    
747     (defimplementation receive ()
748     (mp:mailbox-read (mailbox mp:*current-process*)))
749    
750     (defimplementation send (thread object)
751     (mp:mailbox-send (mailbox thread) object))
752 heller 1.3
753 heller 1.66 ;;; Some intergration with the lispworks environment
754    
755 heller 1.74 (defun swank-sym (name) (find-symbol (string name) :swank))
756 heller 1.66
757     (defimplementation emacs-connected ()
758     (when (eq (eval (swank-sym :*communication-style*))
759     nil)
760 heller 1.68 (set-sigint-handler))
761     ;; pop up the slime debugger by default
762     (let ((lw:*handle-warn-on-redefinition* :warn))
763     (defmethod env-internals:environment-display-notifier
764     (env &key restarts condition)
765     (declare (ignore restarts))
766 heller 1.74 (funcall (swank-sym :swank-debugger-hook) condition *debugger-hook*))
767 heller 1.68 (defmethod env-internals:environment-display-debugger (env)
768     *debug-io*)))
769 heller 1.66
770     (defimplementation make-stream-interactive (stream)
771     (unless (find-method #'stream:stream-soft-force-output nil `((eql ,stream))
772     nil)
773     (let ((lw:*handle-warn-on-redefinition* :warn))
774     (defmethod stream:stream-soft-force-output ((o (eql stream)))
775     (force-output o)))))
776    
777 mkoeppe 1.77 (defmethod env-internals:confirm-p ((e slime-env) &optional msg &rest args)
778     (apply (swank-sym :y-or-n-p-in-emacs) msg args))
779    

  ViewVC Help
Powered by ViewVC 1.1.5