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

Contents of /slime/swank-allegro.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.39 - (hide annotations)
Fri Jun 25 08:05:21 2004 UTC (9 years, 9 months ago) by heller
Branch: MAIN
Changes since 1.38: +8 -4 lines
(frame-var-value): New backend function.
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 heller 1.39 (declare (ignore c))
59 heller 1.34 '())
60 heller 1.7
61 heller 1.39 (defimplementation call-with-syntax-hooks (fn)
62     (funcall fn))
63    
64 heller 1.9 ;;;; Unix signals
65    
66 heller 1.10 (defimplementation call-without-interrupts (fn)
67 heller 1.9 (excl:without-interrupts (funcall fn)))
68    
69 heller 1.10 (defimplementation getpid ()
70 heller 1.8 (excl::getpid))
71 heller 1.6
72 heller 1.15 (defimplementation lisp-implementation-type-name ()
73     "allegro")
74    
75 pseibel 1.28 (defimplementation set-default-directory (directory)
76     (excl:chdir directory)
77 heller 1.31 (namestring (setf *default-pathname-defaults*
78     (truename (merge-pathnames directory)))))
79 pseibel 1.28
80 heller 1.35 (defimplementation default-directory ()
81     (excl:chdir))
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.39 (defimplementation frame-var-value (frame var)
151     (let ((frame (nth-frame frame)))
152     (debugger:frame-var-value frame var)))
153    
154 heller 1.10 (defimplementation frame-catch-tags (index)
155 heller 1.1 (declare (ignore index))
156     nil)
157    
158 heller 1.21 (defimplementation disassemble-frame (index)
159     (disassemble (debugger:frame-function (nth-frame index))))
160    
161 heller 1.10 (defimplementation frame-source-location-for-emacs (index)
162 lgorrie 1.37 (let* ((frame (nth-frame index))
163     (expr (debugger:frame-expression frame))
164     (fspec (first expr)))
165     (second (first (fspec-definition-locations fspec)))))
166 heller 1.4
167 heller 1.10 (defimplementation eval-in-frame (form frame-number)
168     (debugger:eval-form-in-context
169     form
170     (debugger:environment-of-frame (nth-frame frame-number))))
171    
172 heller 1.11 (defimplementation return-from-frame (frame-number form)
173     (let ((frame (nth-frame frame-number)))
174     (multiple-value-call #'debugger:frame-return
175     frame (debugger:eval-form-in-context
176 heller 1.20 form
177     (debugger:environment-of-frame frame)))))
178 heller 1.11
179 heller 1.21 ;;; XXX doesn't work for frames with arguments
180 heller 1.11 (defimplementation restart-frame (frame-number)
181     (let ((frame (nth-frame frame-number)))
182     (debugger:frame-retry frame (debugger:frame-function frame))))
183    
184 heller 1.8 ;;;; Compiler hooks
185    
186 heller 1.1 (defvar *buffer-name* nil)
187     (defvar *buffer-start-position*)
188     (defvar *buffer-string*)
189 lgorrie 1.33 (defvar *compile-filename* nil)
190 heller 1.1
191     (defun handle-compiler-warning (condition)
192     (let ((loc (getf (slot-value condition 'excl::plist) :loc)))
193     (signal (make-condition
194     'compiler-condition
195     :original-condition condition
196     :severity :warning
197     :message (format nil "~A" condition)
198     :location (cond (*buffer-name*
199     (make-location
200     (list :buffer *buffer-name*)
201     (list :position *buffer-start-position*)))
202     (loc
203     (destructuring-bind (file . pos) loc
204     (make-location
205     (list :file (namestring (truename file)))
206     (list :position (1+ pos)))))
207 lgorrie 1.33 (*compile-filename*
208 heller 1.1 (make-location
209     (list :file *compile-filename*)
210 lgorrie 1.33 (list :position 1)))
211     (t
212     (list :error "No error location available.")))))))
213    
214     (defimplementation call-with-compilation-hooks (function)
215     (handler-bind ((warning #'handle-compiler-warning))
216     (funcall function)))
217 heller 1.1
218 heller 1.20 (defimplementation swank-compile-file (*compile-filename* load-p)
219 lgorrie 1.33 (with-compilation-hooks ()
220 heller 1.1 (let ((*buffer-name* nil))
221 heller 1.4 (compile-file *compile-filename* :load-after-compile load-p))))
222 heller 1.1
223 heller 1.20 (defimplementation swank-compile-string (string &key buffer position)
224 lgorrie 1.33 (with-compilation-hooks ()
225 heller 1.20 (let ((*buffer-name* buffer)
226 heller 1.1 (*buffer-start-position* position)
227     (*buffer-string* string))
228 heller 1.20 (funcall (compile nil (read-from-string
229 heller 1.24 (format nil "(~S () ~A)" 'lambda string)))))))
230 heller 1.1
231 heller 1.8 ;;;; Definition Finding
232    
233 heller 1.32 (defun fspec-primary-name (fspec)
234     (etypecase fspec
235     (symbol (string fspec))
236     (list (string (second fspec)))))
237    
238 heller 1.21 (defun find-fspec-location (fspec type)
239 heller 1.32 (let ((file (excl:source-file fspec)))
240 heller 1.21 (etypecase file
241     (pathname
242 heller 1.32 (let* ((start (scm:find-definition-in-file fspec type file))
243     (pos (if start
244     (list :position (1+ start))
245     (list :function-name (fspec-primary-name fspec)))))
246 heller 1.21 (make-location (list :file (namestring (truename file)))
247 heller 1.32 pos)))
248 heller 1.21 ((member :top-level)
249     (list :error (format nil "Defined at toplevel: ~A" fspec)))
250     (null
251 lgorrie 1.37 (list :error (format nil "Unknown source location for ~A" fspec))))))
252 heller 1.21
253     (defun fspec-definition-locations (fspec)
254 heller 1.1 (let ((defs (excl::find-multiple-definitions fspec)))
255 heller 1.21 (loop for (fspec type) in defs
256     collect (list fspec (find-fspec-location fspec type)))))
257    
258     (defimplementation find-definitions (symbol)
259     (fspec-definition-locations symbol))
260 heller 1.1
261 heller 1.8 ;;;; XREF
262    
263 heller 1.21 (defmacro defxref (name relation name1 name2)
264     `(defimplementation ,name (x)
265     (xref-result (xref:get-relation ,relation ,name1 ,name2))))
266    
267     (defxref who-calls :calls :wild x)
268     (defxref who-references :uses :wild x)
269     (defxref who-binds :binds :wild x)
270     (defxref who-macroexpands :macro-calls :wild x)
271     (defxref who-sets :sets :wild x)
272     (defxref list-callees :calls x :wild)
273    
274     (defun xref-result (fspecs)
275     (loop for fspec in fspecs
276     append (fspec-definition-locations fspec)))
277 heller 1.4
278 heller 1.18 ;;;; Inspecting
279    
280     (defmethod inspected-parts (o)
281     (let* ((class (class-of o))
282     (slots (clos:class-slots class)))
283     (values (format nil "~A~% is a ~A" o class)
284     (mapcar (lambda (slot)
285     (let ((name (clos:slot-definition-name slot)))
286 heller 1.20 (cons (princ-to-string name)
287 lgorrie 1.38 (if (slot-boundp o name)
288     (slot-value o name)
289     (make-unbound-slot-filler)))))
290 heller 1.18 slots))))
291    
292     ;;;; Multithreading
293 heller 1.8
294 heller 1.10 (defimplementation startup-multiprocessing ()
295 heller 1.8 (mp:start-scheduler))
296    
297 heller 1.10 (defimplementation spawn (fn &key name)
298 heller 1.8 (mp:process-run-function name fn))
299    
300 heller 1.13 (defimplementation thread-name (thread)
301     (mp:process-name thread))
302 heller 1.8
303 heller 1.13 (defimplementation thread-status (thread)
304     (format nil "~A ~D" (mp:process-whostate thread)
305     (mp:process-priority thread)))
306 heller 1.8
307 heller 1.10 (defimplementation make-lock (&key name)
308 heller 1.8 (mp:make-process-lock :name name))
309    
310 heller 1.10 (defimplementation call-with-lock-held (lock function)
311 heller 1.8 (mp:with-process-lock (lock) (funcall function)))
312 heller 1.12
313     (defimplementation current-thread ()
314     mp:*current-process*)
315    
316     (defimplementation all-threads ()
317 heller 1.13 (copy-list mp:*all-processes*))
318 heller 1.12
319     (defimplementation interrupt-thread (thread fn)
320     (mp:process-interrupt thread fn))
321    
322 heller 1.16 (defimplementation kill-thread (thread)
323     (mp:process-kill thread))
324    
325 heller 1.12 (defvar *mailbox-lock* (mp:make-process-lock :name "mailbox lock"))
326    
327     (defstruct (mailbox (:conc-name mailbox.))
328     (mutex (mp:make-process-lock :name "process mailbox"))
329     (queue '() :type list))
330    
331     (defun mailbox (thread)
332     "Return THREAD's mailbox."
333     (mp:with-process-lock (*mailbox-lock*)
334     (or (getf (mp:process-property-list thread) 'mailbox)
335     (setf (getf (mp:process-property-list thread) 'mailbox)
336     (make-mailbox)))))
337    
338     (defimplementation send (thread message)
339     (let* ((mbox (mailbox thread))
340     (mutex (mailbox.mutex mbox)))
341 heller 1.25 (mp:process-wait-with-timeout
342     "yielding before sending" 0.1
343     (lambda ()
344     (mp:with-process-lock (mutex)
345 heller 1.26 (< (length (mailbox.queue mbox)) 10))))
346 heller 1.12 (mp:with-process-lock (mutex)
347     (setf (mailbox.queue mbox)
348     (nconc (mailbox.queue mbox) (list message))))))
349    
350     (defimplementation receive ()
351     (let* ((mbox (mailbox mp:*current-process*))
352     (mutex (mailbox.mutex mbox)))
353     (mp:process-wait "receive" #'mailbox.queue mbox)
354     (mp:with-process-lock (mutex)
355     (pop (mailbox.queue mbox)))))
356 mbaringer 1.27
357     (defimplementation quit-lisp ()
358     (excl:exit 0 :quiet t))

  ViewVC Help
Powered by ViewVC 1.1.5