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

Contents of /slime/swank-abcl.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5