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

Contents of /slime/swank-abcl.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.46 - (hide annotations)
Sat Feb 9 18:38:58 2008 UTC (6 years, 2 months ago) by heller
Branch: MAIN
Changes since 1.45: +3 -3 lines
Inspector cleanups.

* swank.lisp (emacs-inspect): Renamed from inspect-for-emacs.
Changed all method-defs acordingly.
(common-seperated-spec, inspector-princ): Moved to
swank-fancy-inspector.lisp.
(inspector-content): Renamed from inspector-content-for-emacs.
(value-part): Renamed from value-part-for-emacs.
(action-part): Renamed from action-part-for-emacs.
(inspect-list): Renamed from inspect-for-emacs-list.
(inspect-list-aux): New.
(inspect-cons): Renamed from inspect-for-emacs-simple-cons.
(*inspect-length*): Deleted.
(inspect-list): Ignore max-length stuff.
(inspector-content): Don't allow nil elements.
(emacs-inspect array): Make the label of element type more
consistent with the others.
1 heller 1.41 ;;;; -*- indent-tabs-mode: nil; outline-regexp: ";;;;;*"; -*-
2 heller 1.1 ;;;
3     ;;; swank-abcl.lisp --- Armedbear CL specific code for SLIME.
4     ;;;
5 asimon 1.9 ;;; Adapted from swank-acl.lisp, Andras Simon, 2004
6 heller 1.1 ;;;
7     ;;; This code has been placed in the Public Domain. All warranties
8 asimon 1.9 ;;; are disclaimed.
9 heller 1.1 ;;;
10    
11     (in-package :swank-backend)
12    
13     (eval-when (:compile-toplevel :load-toplevel :execute)
14     (require :collect) ;just so that it doesn't spoil the flying letters
15 asimon 1.17 (require :pprint))
16    
17 heller 1.25 (defun sys::break (&optional (format-control "BREAK called")
18     &rest format-arguments)
19 aruttenberg 1.31 (let ((*saved-backtrace* (backtrace-as-list-ignoring-swank-calls)))
20 asimon 1.20 (with-simple-restart (continue "Return from BREAK.")
21     (invoke-debugger
22     (sys::%make-condition 'simple-condition
23     (list :format-control format-control
24     :format-arguments format-arguments))))
25     nil))
26    
27 asimon 1.19 (defimplementation make-fn-streams (input-fn output-fn)
28     (let* ((output (ext:make-slime-output-stream output-fn))
29     (input (ext:make-slime-input-stream input-fn output)))
30     (values input output)))
31 heller 1.1
32 aruttenberg 1.34 (defimplementation call-with-compilation-hooks (function)
33     (funcall function))
34    
35 asimon 1.12 ;;; swank-mop
36 asimon 1.13
37 aruttenberg 1.36 ;;dummies and definition
38 asimon 1.15
39 asimon 1.12 (defclass standard-slot-definition ()())
40 asimon 1.15
41 aruttenberg 1.36 ;(defun class-finalized-p (class) t)
42 asimon 1.15
43     (defun slot-definition-documentation (slot) #+nil (documentation slot 't))
44 asimon 1.13 (defun slot-definition-type (slot) t)
45 asimon 1.14 (defun class-prototype (class))
46     (defun generic-function-declarations (gf))
47 aruttenberg 1.36 (defun specializer-direct-methods (spec) (mop::class-direct-methods spec))
48    
49     (defun slot-definition-name (slot)
50     (mop::%slot-definition-name slot))
51    
52     (defun class-slots (class)
53     (mop::%class-slots class))
54    
55     (defun method-generic-function (method)
56     (mop::%method-generic-function method))
57    
58     (defun method-function (method)
59     (mop::%method-function method))
60    
61 aruttenberg 1.37 (defun slot-boundp-using-class (class object slotdef)
62     (system::slot-boundp object (slot-definition-name slotdef)))
63    
64     (defun slot-value-using-class (class object slotdef)
65     (system::slot-value object (slot-definition-name slotdef)))
66 asimon 1.12
67     (import-to-swank-mop
68     '( ;; classes
69     cl:standard-generic-function
70     standard-slot-definition ;;dummy
71     cl:method
72     cl:standard-class
73     ;; standard-class readers
74 asimon 1.26 mop::class-default-initargs
75     mop::class-direct-default-initargs
76     mop::class-direct-slots
77     mop::class-direct-subclasses
78     mop::class-direct-superclasses
79     mop::eql-specializer
80 aruttenberg 1.36 mop::class-finalized-p
81 asimon 1.12 cl:class-name
82 asimon 1.26 mop::class-precedence-list
83 asimon 1.14 class-prototype ;;dummy
84 aruttenberg 1.36 class-slots
85     specializer-direct-methods
86 asimon 1.17 ;; eql-specializer accessors
87 asimon 1.26 mop::eql-specializer-object
88 asimon 1.12 ;; generic function readers
89 asimon 1.26 mop::generic-function-argument-precedence-order
90 asimon 1.14 generic-function-declarations ;;dummy
91 asimon 1.26 mop::generic-function-lambda-list
92     mop::generic-function-methods
93     mop::generic-function-method-class
94     mop::generic-function-method-combination
95     mop::generic-function-name
96 asimon 1.12 ;; method readers
97 aruttenberg 1.36 method-generic-function
98     method-function
99 asimon 1.26 mop::method-lambda-list
100     mop::method-specializers
101     mop::method-qualifiers
102 asimon 1.12 ;; slot readers
103 asimon 1.26 mop::slot-definition-allocation
104 asimon 1.13 slot-definition-documentation ;;dummy
105 asimon 1.26 mop::slot-definition-initargs
106     mop::slot-definition-initform
107     mop::slot-definition-initfunction
108 aruttenberg 1.36 slot-definition-name
109 asimon 1.13 slot-definition-type ;;dummy
110 asimon 1.26 mop::slot-definition-readers
111 aruttenberg 1.37 mop::slot-definition-writers
112     slot-boundp-using-class
113     slot-value-using-class
114     ))
115 asimon 1.12
116 heller 1.1 ;;;; TCP Server
117    
118    
119     (defimplementation preferred-communication-style ()
120     :spawn)
121    
122    
123    
124     (defimplementation create-socket (host port)
125     (ext:make-server-socket port))
126    
127    
128     (defimplementation local-port (socket)
129     (java:jcall (java:jmethod "java.net.ServerSocket" "getLocalPort") socket))
130    
131    
132     (defimplementation close-socket (socket)
133     (ext:server-socket-close socket))
134    
135 heller 1.23 (defimplementation accept-connection (socket
136 heller 1.40 &key external-format buffering timeout)
137 heller 1.41 (declare (ignore buffering timeout external-format))
138 heller 1.1 (ext:get-socket-stream (ext:socket-accept socket)))
139    
140     ;;;; Unix signals
141    
142     (defimplementation call-without-interrupts (fn)
143     (funcall fn))
144    
145     (defimplementation getpid ()
146 trittweiler 1.44 (if (not (find :unix *features*))
147     0
148     (let* ((runtime
149     (java:jstatic "getRuntime" "java.lang.Runtime"))
150     (command
151     (java:jnew-array-from-array
152     "java.lang.String" #("sh" "-c" "echo $PPID")))
153     (runtime-exec-jmethod
154     ;; Complicated because java.lang.Runtime.exec() is
155     ;; overloaded on a non-primitive type (array of
156     ;; java.lang.String), so we have to use the actual parameter
157     ;; instance to get java.lang.Class
158     (java:jmethod "java.lang.Runtime" "exec"
159     (java:jcall
160     (java:jmethod "java.lang.Object" "getClass")
161     command)))
162     (process
163     (java:jcall runtime-exec-jmethod runtime command))
164     (output
165     (java:jcall (java:jmethod "java.lang.Process" "getInputStream")
166     process)))
167     (java:jcall (java:jmethod "java.lang.Process" "waitFor") process)
168     (loop
169     :with b
170     :do (setq b
171     (java:jcall (java:jmethod "java.io.InputStream" "read")
172     output))
173     :until (member b '(-1 #x0a)) ; Either EOF or LF
174     :collecting (code-char b) :into result
175     :finally (return
176     (values
177     (parse-integer (coerce result 'string))))))))
178 heller 1.1
179     (defimplementation lisp-implementation-type-name ()
180     "armedbear")
181    
182     (defimplementation set-default-directory (directory)
183     (let ((dir (sys::probe-directory directory)))
184     (when dir (setf *default-pathname-defaults* dir))
185     (namestring dir)))
186    
187    
188     ;;;; Misc
189    
190 heller 1.40 (defimplementation arglist (fun)
191     (cond ((symbolp fun)
192     (multiple-value-bind (arglist present) (sys::arglist fun)
193     (if present arglist :not-available)))
194     (t :not-available)))
195 asimon 1.13
196     (defimplementation function-name (function)
197     (nth-value 2 (function-lambda-expression function)))
198 heller 1.1
199     (defimplementation macroexpand-all (form)
200     (macroexpand form))
201    
202     (defimplementation describe-symbol-for-emacs (symbol)
203     (let ((result '()))
204     (flet ((doc (kind &optional (sym symbol))
205     (or (documentation sym kind) :not-documented))
206     (maybe-push (property value)
207     (when value
208     (setf result (list* property value result)))))
209     (maybe-push
210     :variable (when (boundp symbol)
211     (doc 'variable)))
212     (maybe-push
213     :function (if (fboundp symbol)
214     (doc 'function)))
215     (maybe-push
216     :class (if (find-class symbol nil)
217     (doc 'class)))
218     result)))
219    
220    
221     (defimplementation describe-definition (symbol namespace)
222     (ecase namespace
223     (:variable
224     (describe symbol))
225     ((:function :generic-function)
226     (describe (symbol-function symbol)))
227     (:class
228     (describe (find-class symbol)))))
229    
230     (defimplementation describe-definition (symbol namespace)
231     (ecase namespace
232     (:variable
233     (describe symbol))
234     ((:function :generic-function)
235     (describe (symbol-function symbol)))
236     (:class
237     (describe (find-class symbol)))))
238    
239    
240     ;;;; Debugger
241    
242     (defvar *sldb-topframe*)
243    
244 aruttenberg 1.31 (defun backtrace-as-list-ignoring-swank-calls ()
245     (let ((list (ext:backtrace-as-list)))
246 aruttenberg 1.33 (subseq list (1+ (or (position (intern "SWANK-DEBUGGER-HOOK" 'swank) list :key 'car) -1)))))
247 aruttenberg 1.31
248 heller 1.1 (defimplementation call-with-debugging-environment (debugger-loop-fn)
249 aruttenberg 1.31 (let ((*sldb-topframe* (car (backtrace-as-list-ignoring-swank-calls)) #+nil (excl::int-newest-frame)))
250 heller 1.1 (funcall debugger-loop-fn)))
251    
252     (defun nth-frame (index)
253 aruttenberg 1.31 (nth index (backtrace-as-list-ignoring-swank-calls)))
254 heller 1.1
255     (defimplementation compute-backtrace (start end)
256     (let ((end (or end most-positive-fixnum)))
257 aruttenberg 1.31 (subseq (backtrace-as-list-ignoring-swank-calls) start end)))
258 heller 1.1
259     (defimplementation print-frame (frame stream)
260 heller 1.25 (write-string (string-trim '(#\space #\newline)
261     (prin1-to-string frame))
262     stream))
263 heller 1.1
264     (defimplementation frame-locals (index)
265 aruttenberg 1.31 `(,(list :name "??" :id 0 :value "??")))
266 heller 1.25
267 heller 1.1
268     (defimplementation frame-catch-tags (index)
269     (declare (ignore index))
270     nil)
271    
272     #+nil
273     (defimplementation disassemble-frame (index)
274     (disassemble (debugger:frame-function (nth-frame index))))
275    
276     (defimplementation frame-source-location-for-emacs (index)
277     (list :error (format nil "Cannot find source for frame: ~A"
278     (nth-frame index))))
279    
280     #+nil
281     (defimplementation eval-in-frame (form frame-number)
282     (debugger:eval-form-in-context
283     form
284     (debugger:environment-of-frame (nth-frame frame-number))))
285    
286     #+nil
287     (defimplementation return-from-frame (frame-number form)
288     (let ((frame (nth-frame frame-number)))
289     (multiple-value-call #'debugger:frame-return
290     frame (debugger:eval-form-in-context
291     form
292     (debugger:environment-of-frame frame)))))
293    
294     ;;; XXX doesn't work for frames with arguments
295     #+nil
296     (defimplementation restart-frame (frame-number)
297     (let ((frame (nth-frame frame-number)))
298     (debugger:frame-retry frame (debugger:frame-function frame))))
299    
300     ;;;; Compiler hooks
301    
302     (defvar *buffer-name* nil)
303     (defvar *buffer-start-position*)
304     (defvar *buffer-string*)
305     (defvar *compile-filename*)
306    
307 aruttenberg 1.38 (in-package :swank-backend)
308    
309 heller 1.1 (defun handle-compiler-warning (condition)
310 aruttenberg 1.38 (let ((loc nil));(getf (slot-value condition 'excl::plist) :loc)))
311     (unless (member condition *abcl-signaled-conditions*) ; filter condition signaled more than once.
312     (push condition *abcl-signaled-conditions*)
313     (signal (make-condition
314     'compiler-condition
315     :original-condition condition
316     :severity :warning
317     :message (format nil "~A" condition)
318     :location (cond (*buffer-name*
319     (make-location
320     (list :buffer *buffer-name*)
321     (list :position *buffer-start-position*)))
322     (loc
323     (destructuring-bind (file . pos) loc
324     (make-location
325     (list :file (namestring (truename file)))
326     (list :position (1+ pos)))))
327     (t
328 heller 1.1 (make-location
329 aruttenberg 1.38 (list :file *compile-filename*)
330     (list :position 1)))))))))
331    
332     (defvar *abcl-signaled-conditions*)
333 heller 1.1
334 heller 1.41 (defimplementation swank-compile-file (filename load-p external-format)
335 heller 1.27 (declare (ignore external-format))
336 aruttenberg 1.38 (let ((jvm::*resignal-compiler-warnings* t)
337     (*abcl-signaled-conditions* nil))
338     (handler-bind ((warning #'handle-compiler-warning))
339     (let ((*buffer-name* nil)
340     (*compile-filename* filename))
341     (multiple-value-bind (fn warn fail) (compile-file filename)
342     (when (and load-p (not fail))
343     (load fn)))))))
344 heller 1.1
345 pseibel 1.10 (defimplementation swank-compile-string (string &key buffer position directory)
346     (declare (ignore directory))
347 aruttenberg 1.38 (let ((jvm::*resignal-compiler-warnings* t)
348     (*abcl-signaled-conditions* nil))
349     (handler-bind ((warning #'handle-compiler-warning))
350     (let ((*buffer-name* buffer)
351     (*buffer-start-position* position)
352     (*buffer-string* string))
353     (funcall (compile nil (read-from-string
354     (format nil "(~S () ~A)" 'lambda string))))))))
355 heller 1.1
356     #|
357     ;;;; Definition Finding
358    
359     (defun find-fspec-location (fspec type)
360     (let ((file (excl::fspec-pathname fspec type)))
361     (etypecase file
362     (pathname
363     (let ((start (scm:find-definition-in-file fspec type file)))
364     (make-location (list :file (namestring (truename file)))
365     (if start
366     (list :position (1+ start))
367     (list :function-name (string fspec))))))
368     ((member :top-level)
369     (list :error (format nil "Defined at toplevel: ~A" fspec)))
370     (null
371     (list :error (format nil "Unkown source location for ~A" fspec))))))
372    
373     (defun fspec-definition-locations (fspec)
374     (let ((defs (excl::find-multiple-definitions fspec)))
375     (loop for (fspec type) in defs
376     collect (list fspec (find-fspec-location fspec type)))))
377    
378     (defimplementation find-definitions (symbol)
379     (fspec-definition-locations symbol))
380    
381     |#
382    
383 asimon 1.2 (defun source-location (symbol)
384 asimon 1.24 (when (pathnamep (ext:source-pathname symbol))
385 asimon 1.2 `(((,symbol)
386     (:location
387     (:file ,(namestring (ext:source-pathname symbol)))
388 asimon 1.9 (:position ,(or (ext:source-file-position symbol) 0) t)
389 asimon 1.2 (:snippet nil))))))
390 asimon 1.24
391 asimon 1.2
392     (defimplementation find-definitions (symbol)
393     (source-location symbol))
394    
395 asimon 1.17 #|
396     Uncomment this if you have patched xref.lisp, as in
397     http://article.gmane.org/gmane.lisp.slime.devel/2425
398     Also, make sure that xref.lisp is loaded by modifying the armedbear
399     part of *sysdep-pathnames* in swank.loader.lisp.
400 asimon 1.2
401 heller 1.1 ;;;; XREF
402 asimon 1.17 (setq pxref:*handle-package-forms* '(cl:in-package))
403 heller 1.1
404     (defmacro defxref (name function)
405     `(defimplementation ,name (name)
406     (xref-results (,function name))))
407    
408     (defxref who-calls pxref:list-callers)
409     (defxref who-references pxref:list-readers)
410     (defxref who-binds pxref:list-setters)
411     (defxref who-sets pxref:list-setters)
412     (defxref list-callers pxref:list-callers)
413     (defxref list-callees pxref:list-callees)
414    
415     (defun xref-results (symbols)
416     (let ((xrefs '()))
417     (dolist (symbol symbols)
418 asimon 1.17 (push (list symbol (cadar (source-location symbol))) xrefs))
419 heller 1.1 xrefs))
420     |#
421    
422 asimon 1.15 ;;;; Inspecting
423    
424 heller 1.46 (defmethod emacs-inspect ((slot mop::slot-definition))
425 asimon 1.15 (values "A slot."
426 asimon 1.28 `("Name: " (:value ,(mop::%slot-definition-name slot))
427 asimon 1.15 (:newline)
428     "Documentation:" (:newline)
429     ,@(when (slot-definition-documentation slot)
430     `((:value ,(slot-definition-documentation slot)) (:newline)))
431     "Initialization:" (:newline)
432 asimon 1.28 " Args: " (:value ,(mop::%slot-definition-initargs slot)) (:newline)
433     " Form: " ,(if (mop::%slot-definition-initfunction slot)
434     `(:value ,(mop::%slot-definition-initform slot))
435 asimon 1.15 "#<unspecified>") (:newline)
436 asimon 1.28 " Function: " (:value ,(mop::%slot-definition-initfunction slot))
437 asimon 1.15 (:newline))))
438 asimon 1.16
439 heller 1.46 (defmethod emacs-inspect ((f function))
440 asimon 1.16 (values "A function."
441 asimon 1.17 `(,@(when (function-name f)
442     `("Name: "
443     ,(princ-to-string (function-name f)) (:newline)))
444     ,@(multiple-value-bind (args present)
445     (sys::arglist f)
446     (when present `("Argument list: " ,(princ-to-string args) (:newline))))
447 asimon 1.16 (:newline)
448     #+nil,@(when (documentation f t)
449     `("Documentation:" (:newline) ,(documentation f t) (:newline)))
450     ,@(when (function-lambda-expression f)
451     `("Lambda expression:"
452 asimon 1.17 (:newline) ,(princ-to-string (function-lambda-expression f)) (:newline))))))
453 asimon 1.15
454 heller 1.1 #|
455    
456 heller 1.46 (defmethod emacs-inspect ((o t))
457 heller 1.1 (let* ((class (class-of o))
458 asimon 1.26 (slots (mop::class-slots class)))
459 heller 1.1 (values (format nil "~A~% is a ~A" o class)
460     (mapcar (lambda (slot)
461 asimon 1.26 (let ((name (mop::slot-definition-name slot)))
462 heller 1.1 (cons (princ-to-string name)
463     (slot-value o name))))
464     slots))))
465     |#
466 asimon 1.15
467 heller 1.1 ;;;; Multithreading
468    
469     (defimplementation startup-multiprocessing ()
470     #+nil(mp:start-scheduler))
471    
472     (defimplementation spawn (fn &key name)
473 asimon 1.8 (ext:make-thread (lambda () (funcall fn)) :name name))
474 heller 1.1
475 heller 1.6 (defvar *thread-props-lock* (ext:make-thread-lock))
476    
477     (defvar *thread-props* (make-hash-table) ; should be a weak table
478     "A hashtable mapping threads to a plist.")
479    
480     (defvar *thread-id-counter* 0)
481    
482     (defimplementation thread-id (thread)
483     (ext:with-thread-lock (*thread-props-lock*)
484     (or (getf (gethash thread *thread-props*) 'id)
485     (setf (getf (gethash thread *thread-props*) 'id)
486     (incf *thread-id-counter*)))))
487    
488     (defimplementation find-thread (id)
489     (find id (all-threads)
490 asimon 1.7 :key (lambda (thread)
491 heller 1.6 (getf (gethash thread *thread-props*) 'id))))
492    
493 heller 1.1 (defimplementation thread-name (thread)
494 asimon 1.8 (ext:thread-name thread))
495 heller 1.1
496     (defimplementation thread-status (thread)
497 asimon 1.4 (format nil "Thread is ~:[dead~;alive~]" (ext:thread-alive-p thread)))
498 heller 1.1
499     (defimplementation make-lock (&key name)
500     (ext:make-thread-lock))
501    
502     (defimplementation call-with-lock-held (lock function)
503     (ext:with-thread-lock (lock) (funcall function)))
504    
505     (defimplementation current-thread ()
506     (ext:current-thread))
507    
508     (defimplementation all-threads ()
509     (copy-list (ext:mapcar-threads #'identity)))
510    
511     (defimplementation interrupt-thread (thread fn)
512     (ext:interrupt-thread thread fn))
513    
514     (defimplementation kill-thread (thread)
515     (ext:destroy-thread thread))
516    
517     (defun mailbox (thread)
518     "Return THREAD's mailbox."
519 heller 1.6 (ext:with-thread-lock (*thread-props-lock*)
520     (or (getf (gethash thread *thread-props*) 'mailbox)
521     (setf (getf (gethash thread *thread-props*) 'mailbox)
522 asimon 1.5 (ext:make-mailbox)))))
523 heller 1.1
524 asimon 1.5 (defimplementation send (thread object)
525     (ext:mailbox-send (mailbox thread) object))
526 heller 1.1
527     (defimplementation receive ()
528 asimon 1.5 (ext:mailbox-read (mailbox (ext:current-thread))))
529 heller 1.1
530 asimon 1.29 ;;; Auto-flush streams
531    
532     ;; XXX race conditions
533     (defvar *auto-flush-streams* '())
534    
535     (defvar *auto-flush-thread* nil)
536    
537     (defimplementation make-stream-interactive (stream)
538     (setq *auto-flush-streams* (adjoin stream *auto-flush-streams*))
539     (unless *auto-flush-thread*
540     (setq *auto-flush-thread*
541     (ext:make-thread #'flush-streams
542     :name "auto-flush-thread"))))
543    
544     (defun flush-streams ()
545     (loop
546     (setq *auto-flush-streams*
547     (remove-if (lambda (x)
548     (not (and (open-stream-p x)
549     (output-stream-p x))))
550     *auto-flush-streams*))
551     (mapc #'finish-output *auto-flush-streams*)
552     (sleep 0.15)))
553    
554 heller 1.1 (defimplementation quit-lisp ()
555     (ext:exit))
556 asimon 1.12
557 heller 1.43 ;; WORKAROUND: call/initialize accessors at load time
558     (let ((c (make-condition 'compiler-condition
559     :original-condition nil
560     :severity ':note :message "" :location nil))
561     (slots `(severity message short-message references location)))
562     (dolist (slot slots)
563     (funcall slot c)))

  ViewVC Help
Powered by ViewVC 1.1.5