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

Contents of /slime/swank-allegro.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.37 - (hide annotations)
Fri Jun 18 19:27:37 2004 UTC (9 years, 10 months ago) by lgorrie
Branch: MAIN
Changes since 1.36: +5 -3 lines
From Matthew Danish:
Implemented frame-source-location-for-emacs.
1 heller 1.8 ;;;; -*- Mode: lisp; indent-tabs-mode: nil; outline-regexp: ";;;;;*"; -*-
2 heller 1.1 ;;;
3     ;;; swank-allegro.lisp --- Allegro CL specific code for SLIME.
4     ;;;
5     ;;; Created 2003, Helmut Eller
6     ;;;
7     ;;; This code has been placed in the Public Domain. All warranties
8 heller 1.14 ;;; are disclaimed. This code was written for "Allegro CL Trial
9     ;;; Edition "5.0 [Linux/X86] (8/29/98 10:57)".
10 heller 1.1 ;;;
11    
12 heller 1.21 (in-package :swank-backend)
13    
14 heller 1.1 (eval-when (:compile-toplevel :load-toplevel :execute)
15     (require :sock)
16 lgorrie 1.33 (require :process)
17 heller 1.1
18 lgorrie 1.33 (import
19     '(excl:fundamental-character-output-stream
20     excl:stream-write-char
21     excl:stream-force-output
22     excl:fundamental-character-input-stream
23     excl:stream-read-char
24     excl:stream-listen
25     excl:stream-unread-char
26     excl:stream-clear-input
27     excl:stream-line-column
28     excl:stream-read-char-no-hang)))
29 heller 1.1
30 heller 1.8 ;;;; TCP Server
31 heller 1.1
32 heller 1.21 (defimplementation preferred-communication-style ()
33     :spawn)
34 heller 1.12
35 heller 1.14 (defimplementation create-socket (host port)
36     (socket:make-socket :connect :passive :local-port port
37     :local-host host :reuse-address t))
38 heller 1.5
39 heller 1.10 (defimplementation local-port (socket)
40 heller 1.6 (socket:local-port socket))
41    
42 heller 1.10 (defimplementation close-socket (socket)
43 heller 1.6 (close socket))
44    
45 heller 1.10 (defimplementation accept-connection (socket)
46 heller 1.6 (socket:accept-connection socket :wait t))
47    
48 heller 1.34 ;; The following defitinions are workarounds for the buggy
49     ;; no-applicable-method function in Allegro 5. We have to provide an
50     ;; implementation.
51 heller 1.36 (defimplementation emacs-connected (stream)
52     (declare (ignore stream)))
53 heller 1.34
54     (defimplementation format-sldb-condition (c)
55     (princ-to-string c))
56    
57     (defimplementation condition-references (c)
58     (declare (ignore))
59     '())
60 heller 1.7
61 heller 1.9 ;;;; Unix signals
62    
63 heller 1.10 (defimplementation call-without-interrupts (fn)
64 heller 1.9 (excl:without-interrupts (funcall fn)))
65    
66 heller 1.10 (defimplementation getpid ()
67 heller 1.8 (excl::getpid))
68 heller 1.6
69 heller 1.15 (defimplementation lisp-implementation-type-name ()
70     "allegro")
71    
72 pseibel 1.28 (defimplementation set-default-directory (directory)
73     (excl:chdir directory)
74 heller 1.31 (namestring (setf *default-pathname-defaults*
75     (truename (merge-pathnames directory)))))
76 pseibel 1.28
77 heller 1.35 (defimplementation default-directory ()
78     (excl:chdir))
79    
80     (defimplementation call-with-syntax-hooks (fn)
81     (funcall fn))
82    
83 heller 1.8 ;;;; Misc
84 heller 1.1
85 heller 1.21 (defimplementation arglist (symbol)
86 lgorrie 1.30 (handler-case (excl:arglist symbol)
87     (simple-error () :not-available)))
88 heller 1.21
89     (defimplementation macroexpand-all (form)
90     (excl::walk form))
91 heller 1.1
92 heller 1.10 (defimplementation describe-symbol-for-emacs (symbol)
93 heller 1.1 (let ((result '()))
94     (flet ((doc (kind &optional (sym symbol))
95     (or (documentation sym kind) :not-documented))
96     (maybe-push (property value)
97     (when value
98     (setf result (list* property value result)))))
99     (maybe-push
100     :variable (when (boundp symbol)
101     (doc 'variable)))
102     (maybe-push
103     :function (if (fboundp symbol)
104     (doc 'function)))
105     (maybe-push
106     :class (if (find-class symbol nil)
107     (doc 'class)))
108     result)))
109    
110 heller 1.20 (defimplementation describe-definition (symbol namespace)
111     (ecase namespace
112     (:variable
113     (describe symbol))
114     ((:function :generic-function)
115     (describe (symbol-function symbol)))
116     (:class
117     (describe (find-class symbol)))))
118 heller 1.10
119 heller 1.8 ;;;; Debugger
120    
121 heller 1.1 (defvar *sldb-topframe*)
122 heller 1.4
123 heller 1.10 (defimplementation call-with-debugging-environment (debugger-loop-fn)
124 heller 1.4 (let ((*sldb-topframe* (excl::int-newest-frame))
125 heller 1.20 (excl::*break-hook* nil))
126 heller 1.4 (funcall debugger-loop-fn)))
127 heller 1.1
128     (defun nth-frame (index)
129     (do ((frame *sldb-topframe* (excl::int-next-older-frame frame))
130     (i index (1- i)))
131     ((zerop i) frame)))
132    
133 heller 1.20 (defimplementation compute-backtrace (start end)
134 heller 1.1 (let ((end (or end most-positive-fixnum)))
135     (loop for f = (nth-frame start) then (excl::int-next-older-frame f)
136     for i from start below end
137     while f
138     collect f)))
139    
140 heller 1.20 (defimplementation print-frame (frame stream)
141     (debugger:output-frame stream frame :moderate))
142 heller 1.4
143 heller 1.10 (defimplementation frame-locals (index)
144 heller 1.1 (let ((frame (nth-frame index)))
145     (loop for i from 0 below (debugger:frame-number-vars frame)
146 mbaringer 1.19 collect (list :name (debugger:frame-var-name frame i)
147 heller 1.1 :id 0
148 mbaringer 1.19 :value (debugger:frame-var-value frame i)))))
149 heller 1.1
150 heller 1.10 (defimplementation frame-catch-tags (index)
151 heller 1.1 (declare (ignore index))
152     nil)
153    
154 heller 1.21 (defimplementation disassemble-frame (index)
155     (disassemble (debugger:frame-function (nth-frame index))))
156    
157 heller 1.10 (defimplementation frame-source-location-for-emacs (index)
158 lgorrie 1.37 (let* ((frame (nth-frame index))
159     (expr (debugger:frame-expression frame))
160     (fspec (first expr)))
161     (second (first (fspec-definition-locations fspec)))))
162 heller 1.4
163 heller 1.10 (defimplementation eval-in-frame (form frame-number)
164     (debugger:eval-form-in-context
165     form
166     (debugger:environment-of-frame (nth-frame frame-number))))
167    
168 heller 1.11 (defimplementation return-from-frame (frame-number form)
169     (let ((frame (nth-frame frame-number)))
170     (multiple-value-call #'debugger:frame-return
171     frame (debugger:eval-form-in-context
172 heller 1.20 form
173     (debugger:environment-of-frame frame)))))
174 heller 1.11
175 heller 1.21 ;;; XXX doesn't work for frames with arguments
176 heller 1.11 (defimplementation restart-frame (frame-number)
177     (let ((frame (nth-frame frame-number)))
178     (debugger:frame-retry frame (debugger:frame-function frame))))
179    
180 heller 1.8 ;;;; Compiler hooks
181    
182 heller 1.1 (defvar *buffer-name* nil)
183     (defvar *buffer-start-position*)
184     (defvar *buffer-string*)
185 lgorrie 1.33 (defvar *compile-filename* nil)
186 heller 1.1
187     (defun handle-compiler-warning (condition)
188     (let ((loc (getf (slot-value condition 'excl::plist) :loc)))
189     (signal (make-condition
190     'compiler-condition
191     :original-condition condition
192     :severity :warning
193     :message (format nil "~A" condition)
194     :location (cond (*buffer-name*
195     (make-location
196     (list :buffer *buffer-name*)
197     (list :position *buffer-start-position*)))
198     (loc
199     (destructuring-bind (file . pos) loc
200     (make-location
201     (list :file (namestring (truename file)))
202     (list :position (1+ pos)))))
203 lgorrie 1.33 (*compile-filename*
204 heller 1.1 (make-location
205     (list :file *compile-filename*)
206 lgorrie 1.33 (list :position 1)))
207     (t
208     (list :error "No error location available.")))))))
209    
210     (defimplementation call-with-compilation-hooks (function)
211     (handler-bind ((warning #'handle-compiler-warning))
212     (funcall function)))
213 heller 1.1
214 heller 1.20 (defimplementation swank-compile-file (*compile-filename* load-p)
215 lgorrie 1.33 (with-compilation-hooks ()
216 heller 1.1 (let ((*buffer-name* nil))
217 heller 1.4 (compile-file *compile-filename* :load-after-compile load-p))))
218 heller 1.1
219 heller 1.20 (defimplementation swank-compile-string (string &key buffer position)
220 lgorrie 1.33 (with-compilation-hooks ()
221 heller 1.20 (let ((*buffer-name* buffer)
222 heller 1.1 (*buffer-start-position* position)
223     (*buffer-string* string))
224 heller 1.20 (funcall (compile nil (read-from-string
225 heller 1.24 (format nil "(~S () ~A)" 'lambda string)))))))
226 heller 1.1
227 heller 1.8 ;;;; Definition Finding
228    
229 heller 1.32 (defun fspec-primary-name (fspec)
230     (etypecase fspec
231     (symbol (string fspec))
232     (list (string (second fspec)))))
233    
234 heller 1.21 (defun find-fspec-location (fspec type)
235 heller 1.32 (let ((file (excl:source-file fspec)))
236 heller 1.21 (etypecase file
237     (pathname
238 heller 1.32 (let* ((start (scm:find-definition-in-file fspec type file))
239     (pos (if start
240     (list :position (1+ start))
241     (list :function-name (fspec-primary-name fspec)))))
242 heller 1.21 (make-location (list :file (namestring (truename file)))
243 heller 1.32 pos)))
244 heller 1.21 ((member :top-level)
245     (list :error (format nil "Defined at toplevel: ~A" fspec)))
246     (null
247 lgorrie 1.37 (list :error (format nil "Unknown source location for ~A" fspec))))))
248 heller 1.21
249     (defun fspec-definition-locations (fspec)
250 heller 1.1 (let ((defs (excl::find-multiple-definitions fspec)))
251 heller 1.21 (loop for (fspec type) in defs
252     collect (list fspec (find-fspec-location fspec type)))))
253    
254     (defimplementation find-definitions (symbol)
255     (fspec-definition-locations symbol))
256 heller 1.1
257 heller 1.8 ;;;; XREF
258    
259 heller 1.21 (defmacro defxref (name relation name1 name2)
260     `(defimplementation ,name (x)
261     (xref-result (xref:get-relation ,relation ,name1 ,name2))))
262    
263     (defxref who-calls :calls :wild x)
264     (defxref who-references :uses :wild x)
265     (defxref who-binds :binds :wild x)
266     (defxref who-macroexpands :macro-calls :wild x)
267     (defxref who-sets :sets :wild x)
268     (defxref list-callees :calls x :wild)
269    
270     (defun xref-result (fspecs)
271     (loop for fspec in fspecs
272     append (fspec-definition-locations fspec)))
273 heller 1.4
274 heller 1.18 ;;;; Inspecting
275    
276     (defmethod inspected-parts (o)
277     (let* ((class (class-of o))
278     (slots (clos:class-slots class)))
279     (values (format nil "~A~% is a ~A" o class)
280     (mapcar (lambda (slot)
281     (let ((name (clos:slot-definition-name slot)))
282 heller 1.20 (cons (princ-to-string name)
283 heller 1.18 (slot-value o name))))
284     slots))))
285    
286     ;;;; Multithreading
287 heller 1.8
288 heller 1.10 (defimplementation startup-multiprocessing ()
289 heller 1.8 (mp:start-scheduler))
290    
291 heller 1.10 (defimplementation spawn (fn &key name)
292 heller 1.8 (mp:process-run-function name fn))
293    
294 heller 1.13 (defimplementation thread-name (thread)
295     (mp:process-name thread))
296 heller 1.8
297 heller 1.13 (defimplementation thread-status (thread)
298     (format nil "~A ~D" (mp:process-whostate thread)
299     (mp:process-priority thread)))
300 heller 1.8
301 heller 1.10 (defimplementation make-lock (&key name)
302 heller 1.8 (mp:make-process-lock :name name))
303    
304 heller 1.10 (defimplementation call-with-lock-held (lock function)
305 heller 1.8 (mp:with-process-lock (lock) (funcall function)))
306 heller 1.12
307     (defimplementation current-thread ()
308     mp:*current-process*)
309    
310     (defimplementation all-threads ()
311 heller 1.13 (copy-list mp:*all-processes*))
312 heller 1.12
313     (defimplementation interrupt-thread (thread fn)
314     (mp:process-interrupt thread fn))
315    
316 heller 1.16 (defimplementation kill-thread (thread)
317     (mp:process-kill thread))
318    
319 heller 1.12 (defvar *mailbox-lock* (mp:make-process-lock :name "mailbox lock"))
320    
321     (defstruct (mailbox (:conc-name mailbox.))
322     (mutex (mp:make-process-lock :name "process mailbox"))
323     (queue '() :type list))
324    
325     (defun mailbox (thread)
326     "Return THREAD's mailbox."
327     (mp:with-process-lock (*mailbox-lock*)
328     (or (getf (mp:process-property-list thread) 'mailbox)
329     (setf (getf (mp:process-property-list thread) 'mailbox)
330     (make-mailbox)))))
331    
332     (defimplementation send (thread message)
333     (let* ((mbox (mailbox thread))
334     (mutex (mailbox.mutex mbox)))
335 heller 1.25 (mp:process-wait-with-timeout
336     "yielding before sending" 0.1
337     (lambda ()
338     (mp:with-process-lock (mutex)
339 heller 1.26 (< (length (mailbox.queue mbox)) 10))))
340 heller 1.12 (mp:with-process-lock (mutex)
341     (setf (mailbox.queue mbox)
342     (nconc (mailbox.queue mbox) (list message))))))
343    
344     (defimplementation receive ()
345     (let* ((mbox (mailbox mp:*current-process*))
346     (mutex (mailbox.mutex mbox)))
347     (mp:process-wait "receive" #'mailbox.queue mbox)
348     (mp:with-process-lock (mutex)
349     (pop (mailbox.queue mbox)))))
350 mbaringer 1.27
351     (defimplementation quit-lisp ()
352     (excl:exit 0 :quiet t))

  ViewVC Help
Powered by ViewVC 1.1.5