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

Contents of /slime/swank-allegro.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.107 - (show annotations)
Thu Aug 7 07:53:47 2008 UTC (5 years, 8 months ago) by heller
Branch: MAIN
Changes since 1.106: +20 -20 lines
* swank-allegro.lisp:(receive-if): Periodically check for interrupts.
* swank-cmucl.lisp, swank-scl.lisp: ditto.
1 ;;;; -*- indent-tabs-mode: nil; outline-regexp: ";;;;;* "; -*-
2 ;;;
3 ;;; swank-allegro.lisp --- Allegro CL specific code for SLIME.
4 ;;;
5 ;;; Created 2003
6 ;;;
7 ;;; This code has been placed in the Public Domain. All warranties
8 ;;; are disclaimed.
9 ;;;
10
11 (in-package :swank-backend)
12
13 (eval-when (:compile-toplevel :load-toplevel :execute)
14 (require :sock)
15 (require :process))
16
17 (import-from :excl *gray-stream-symbols* :swank-backend)
18
19 ;;; swank-mop
20
21 (import-swank-mop-symbols :clos '(:slot-definition-documentation))
22
23 (defun swank-mop:slot-definition-documentation (slot)
24 (documentation slot t))
25
26
27 ;;;; TCP Server
28
29 (defimplementation preferred-communication-style ()
30 :spawn)
31
32 (defimplementation create-socket (host port)
33 (socket:make-socket :connect :passive :local-port port
34 :local-host host :reuse-address t))
35
36 (defimplementation local-port (socket)
37 (socket:local-port socket))
38
39 (defimplementation close-socket (socket)
40 (close socket))
41
42 (defimplementation accept-connection (socket &key external-format buffering
43 timeout)
44 (declare (ignore buffering timeout))
45 (let ((s (socket:accept-connection socket :wait t)))
46 (when external-format
47 (setf (stream-external-format s) external-format))
48 s))
49
50 (defvar *external-format-to-coding-system*
51 '((:iso-8859-1
52 "latin-1" "latin-1-unix" "iso-latin-1-unix"
53 "iso-8859-1" "iso-8859-1-unix")
54 (:utf-8 "utf-8" "utf-8-unix")
55 (:euc-jp "euc-jp" "euc-jp-unix")
56 (:us-ascii "us-ascii" "us-ascii-unix")
57 (:emacs-mule "emacs-mule" "emacs-mule-unix")))
58
59 (defimplementation find-external-format (coding-system)
60 (let ((e (rassoc-if (lambda (x) (member coding-system x :test #'equal))
61 *external-format-to-coding-system*)))
62 (and e (excl:crlf-base-ef
63 (excl:find-external-format (car e)
64 :try-variant t)))))
65
66 (defimplementation format-sldb-condition (c)
67 (princ-to-string c))
68
69 (defimplementation call-with-syntax-hooks (fn)
70 (funcall fn))
71
72 ;;;; Unix signals
73
74 (defimplementation call-without-interrupts (fn)
75 (excl:without-interrupts (funcall fn)))
76
77 (defimplementation getpid ()
78 (excl::getpid))
79
80 (defimplementation lisp-implementation-type-name ()
81 "allegro")
82
83 (defimplementation set-default-directory (directory)
84 (let* ((dir (namestring (truename (merge-pathnames directory)))))
85 (setf *default-pathname-defaults* (pathname (excl:chdir dir)))
86 dir))
87
88 (defimplementation default-directory ()
89 (namestring (excl:current-directory)))
90
91 ;;;; Misc
92
93 (defimplementation arglist (symbol)
94 (handler-case (excl:arglist symbol)
95 (simple-error () :not-available)))
96
97 (defimplementation macroexpand-all (form)
98 (excl::walk form))
99
100 (defimplementation describe-symbol-for-emacs (symbol)
101 (let ((result '()))
102 (flet ((doc (kind &optional (sym symbol))
103 (or (documentation sym kind) :not-documented))
104 (maybe-push (property value)
105 (when value
106 (setf result (list* property value result)))))
107 (maybe-push
108 :variable (when (boundp symbol)
109 (doc 'variable)))
110 (maybe-push
111 :function (if (fboundp symbol)
112 (doc 'function)))
113 (maybe-push
114 :class (if (find-class symbol nil)
115 (doc 'class)))
116 result)))
117
118 (defimplementation describe-definition (symbol namespace)
119 (ecase namespace
120 (:variable
121 (describe symbol))
122 ((:function :generic-function)
123 (describe (symbol-function symbol)))
124 (:class
125 (describe (find-class symbol)))))
126
127 (defimplementation make-stream-interactive (stream)
128 (setf (interactive-stream-p stream) t))
129
130 ;;;; Debugger
131
132 (defvar *sldb-topframe*)
133
134 (defimplementation call-with-debugging-environment (debugger-loop-fn)
135 (let ((*sldb-topframe* (find-topframe))
136 (excl::*break-hook* nil))
137 (funcall debugger-loop-fn)))
138
139 (defimplementation sldb-break-at-start (fname)
140 ;; :print-before is kind of mis-used but we just want to stuff our break form
141 ;; somewhere. This does not work for setf, :before and :after methods, which
142 ;; need special syntax in the trace call, see ACL's doc/debugging.htm chapter 10.
143 (eval `(trace (,fname
144 :print-before
145 ((break "Function start breakpoint of ~A" ',fname)))))
146 `(:ok ,(format nil "Set breakpoint at start of ~S" fname)))
147
148 (defun find-topframe ()
149 (let ((skip-frames 3))
150 (do ((f (excl::int-newest-frame) (next-frame f))
151 (i 0 (1+ i)))
152 ((= i skip-frames) f))))
153
154 (defun next-frame (frame)
155 (let ((next (excl::int-next-older-frame frame)))
156 (cond ((not next) nil)
157 ((debugger:frame-visible-p next) next)
158 (t (next-frame next)))))
159
160 (defun nth-frame (index)
161 (do ((frame *sldb-topframe* (next-frame frame))
162 (i index (1- i)))
163 ((zerop i) frame)))
164
165 (defimplementation compute-backtrace (start end)
166 (let ((end (or end most-positive-fixnum)))
167 (loop for f = (nth-frame start) then (next-frame f)
168 for i from start below end
169 while f
170 collect f)))
171
172 (defimplementation print-frame (frame stream)
173 (debugger:output-frame stream frame :moderate))
174
175 (defimplementation frame-locals (index)
176 (let ((frame (nth-frame index)))
177 (loop for i from 0 below (debugger:frame-number-vars frame)
178 collect (list :name (debugger:frame-var-name frame i)
179 :id 0
180 :value (debugger:frame-var-value frame i)))))
181
182 (defimplementation frame-var-value (frame var)
183 (let ((frame (nth-frame frame)))
184 (debugger:frame-var-value frame var)))
185
186 (defimplementation frame-catch-tags (index)
187 (declare (ignore index))
188 nil)
189
190 (defimplementation disassemble-frame (index)
191 (disassemble (debugger:frame-function (nth-frame index))))
192
193 (defimplementation frame-source-location-for-emacs (index)
194 (let* ((frame (nth-frame index))
195 (expr (debugger:frame-expression frame))
196 (fspec (first expr)))
197 (second (first (fspec-definition-locations fspec)))))
198
199 (defimplementation eval-in-frame (form frame-number)
200 (let ((frame (nth-frame frame-number)))
201 ;; let-bind lexical variables
202 (let ((vars (loop for i below (debugger:frame-number-vars frame)
203 for name = (debugger:frame-var-name frame i)
204 if (symbolp name)
205 collect `(,name ',(debugger:frame-var-value frame i)))))
206 (debugger:eval-form-in-context
207 `(let* ,vars ,form)
208 (debugger:environment-of-frame frame)))))
209
210 (defimplementation return-from-frame (frame-number form)
211 (let ((frame (nth-frame frame-number)))
212 (multiple-value-call #'debugger:frame-return
213 frame (debugger:eval-form-in-context
214 form
215 (debugger:environment-of-frame frame)))))
216
217 (defimplementation restart-frame (frame-number)
218 (let ((frame (nth-frame frame-number)))
219 (cond ((debugger:frame-retryable-p frame)
220 (apply #'debugger:frame-retry frame (debugger:frame-function frame)
221 (cdr (debugger:frame-expression frame))))
222 (t "Frame is not retryable"))))
223
224 ;;;; Compiler hooks
225
226 (defvar *buffer-name* nil)
227 (defvar *buffer-start-position*)
228 (defvar *buffer-string*)
229 (defvar *compile-filename* nil)
230
231 (defun compiler-note-p (object)
232 (member (type-of object) '(excl::compiler-note compiler::compiler-note)))
233
234 (defun compiler-undefined-functions-called-warning-p (object)
235 (typep object 'excl:compiler-undefined-functions-called-warning))
236
237 (deftype compiler-note ()
238 `(satisfies compiler-note-p))
239
240 (defun signal-compiler-condition (&rest args)
241 (signal (apply #'make-condition 'compiler-condition args)))
242
243 (defun handle-compiler-warning (condition)
244 (declare (optimize (debug 3) (speed 0) (space 0)))
245 (cond ((and (not *buffer-name*)
246 (compiler-undefined-functions-called-warning-p condition))
247 (handle-undefined-functions-warning condition))
248 (t
249 (signal-compiler-condition
250 :original-condition condition
251 :severity (etypecase condition
252 (warning :warning)
253 (compiler-note :note))
254 :message (format nil "~A" condition)
255 :location (location-for-warning condition)))))
256
257 (defun location-for-warning (condition)
258 (let ((loc (getf (slot-value condition 'excl::plist) :loc)))
259 (cond (*buffer-name*
260 (make-location
261 (list :buffer *buffer-name*)
262 (list :position *buffer-start-position*)))
263 (loc
264 (destructuring-bind (file . pos) loc
265 (make-location
266 (list :file (namestring (truename file)))
267 (list :position (1+ pos)))))
268 (t
269 (list :error "No error location available.")))))
270
271 (defun handle-undefined-functions-warning (condition)
272 (let ((fargs (slot-value condition 'excl::format-arguments)))
273 (loop for (fname . pos-file) in (car fargs) do
274 (loop for (pos file) in pos-file do
275 (signal-compiler-condition
276 :original-condition condition
277 :severity :warning
278 :message (format nil "Undefined function referenced: ~S"
279 fname)
280 :location (make-location (list :file file)
281 (list :position (1+ pos))))))))
282
283 (defimplementation call-with-compilation-hooks (function)
284 (handler-bind ((warning #'handle-compiler-warning)
285 ;;(compiler-note #'handle-compiler-warning)
286 )
287 (funcall function)))
288
289 (defimplementation swank-compile-file (filename load-p external-format)
290 (with-compilation-hooks ()
291 (let ((*buffer-name* nil)
292 (*compile-filename* filename))
293 (compile-file *compile-filename* :load-after-compile load-p
294 :external-format external-format))))
295
296 (defun call-with-temp-file (fn)
297 (let ((tmpname (system:make-temp-file-name)))
298 (unwind-protect
299 (with-open-file (file tmpname :direction :output :if-exists :error)
300 (funcall fn file tmpname))
301 (delete-file tmpname))))
302
303 (defun compile-from-temp-file (string)
304 (call-with-temp-file
305 (lambda (stream filename)
306 (write-string string stream)
307 (finish-output stream)
308 (let ((binary-filename
309 (excl:without-redefinition-warnings
310 ;; Suppress Allegro's redefinition warnings; they are
311 ;; pointless when we are compiling via a temporary
312 ;; file.
313 (compile-file filename :load-after-compile t))))
314 (when binary-filename
315 (delete-file binary-filename))))))
316
317 (defimplementation swank-compile-string (string &key buffer position directory
318 debug)
319 (declare (ignore debug))
320 ;; We store the source buffer in excl::*source-pathname* as a string
321 ;; of the form <buffername>;<start-offset>. Quite ugly encoding, but
322 ;; the fasl file is corrupted if we use some other datatype.
323 (with-compilation-hooks ()
324 (let ((*buffer-name* buffer)
325 (*buffer-start-position* position)
326 (*buffer-string* string)
327 (*default-pathname-defaults*
328 (if directory (merge-pathnames (pathname directory))
329 *default-pathname-defaults*)))
330 (compile-from-temp-file
331 (format nil "~S ~S~%~A"
332 `(in-package ,(package-name *package*))
333 `(eval-when (:compile-toplevel :load-toplevel)
334 (setq excl::*source-pathname*
335 ',(format nil "~A;~D" buffer position)))
336 string)))))
337
338 ;;;; Definition Finding
339
340 (defun fspec-primary-name (fspec)
341 (etypecase fspec
342 (symbol fspec)
343 (list (fspec-primary-name (second fspec)))))
344
345 ;; If Emacs uses DOS-style eol conventions, \n\r are considered as a
346 ;; single character, but file-position counts them as two. Here we do
347 ;; our own conversion.
348 (defun count-cr (file pos)
349 (let* ((bufsize 256)
350 (type '(unsigned-byte 8))
351 (buf (make-array bufsize :element-type type))
352 (cr-count 0))
353 (with-open-file (stream file :direction :input :element-type type)
354 (loop for bytes-read = (read-sequence buf stream) do
355 (incf cr-count (count (char-code #\return) buf
356 :end (min pos bytes-read)))
357 (decf pos bytes-read)
358 (when (<= pos 0)
359 (return cr-count))))))
360
361 (defun find-definition-in-file (fspec type file top-level)
362 (let* ((part
363 (or (scm::find-definition-in-definition-group
364 fspec type (scm:section-file :file file)
365 :top-level top-level)
366 (scm::find-definition-in-definition-group
367 (fspec-primary-name fspec)
368 type (scm:section-file :file file)
369 :top-level top-level)))
370 (start (and part
371 (scm::source-part-start part)))
372 (pos (if start
373 (list :position (1+ (- start (count-cr file start))))
374 (list :function-name (string (fspec-primary-name fspec))))))
375 (make-location (list :file (namestring (truename file)))
376 pos)))
377
378 (defun find-definition-in-buffer (filename)
379 (let ((pos (position #\; filename :from-end t)))
380 (make-location
381 (list :buffer (subseq filename 0 pos))
382 (list :position (parse-integer (subseq filename (1+ pos)))))))
383
384 (defun find-fspec-location (fspec type file top-level)
385 (etypecase file
386 (pathname
387 (find-definition-in-file fspec type file top-level))
388 ((member :top-level)
389 (list :error (format nil "Defined at toplevel: ~A"
390 (fspec->string fspec))))
391 (string
392 (find-definition-in-buffer file))))
393
394 (defun fspec->string (fspec)
395 (etypecase fspec
396 (symbol (let ((*package* (find-package :keyword)))
397 (prin1-to-string fspec)))
398 (list (format nil "(~A ~A)"
399 (prin1-to-string (first fspec))
400 (let ((*package* (find-package :keyword)))
401 (prin1-to-string (second fspec)))))))
402
403 (defun fspec-definition-locations (fspec)
404 (cond
405 ((and (listp fspec)
406 (eql (car fspec) :top-level-form))
407 (destructuring-bind (top-level-form file &optional position) fspec
408 (list
409 (list (list nil fspec)
410 (make-location (list :buffer file)
411 (list :position position t))))))
412 ((and (listp fspec) (eq (car fspec) :internal))
413 (destructuring-bind (_internal next _n) fspec
414 (fspec-definition-locations next)))
415 (t
416 (let ((defs (excl::find-source-file fspec)))
417 (when (and (null defs)
418 (listp fspec)
419 (string= (car fspec) '#:method))
420 ;; If methods are defined in a defgeneric form, the source location is
421 ;; recorded for the gf but not for the methods. Therefore fall back to
422 ;; the gf as the likely place of definition.
423 (setq defs (excl::find-source-file (second fspec))))
424 (if (null defs)
425 (list
426 (list (list nil fspec)
427 (list :error
428 (format nil "Unknown source location for ~A"
429 (fspec->string fspec)))))
430 (loop for (fspec type file top-level) in defs
431 collect (list (list type fspec)
432 (find-fspec-location fspec type file top-level))))))))
433
434 (defimplementation find-definitions (symbol)
435 (fspec-definition-locations symbol))
436
437 ;;;; XREF
438
439 (defmacro defxref (name relation name1 name2)
440 `(defimplementation ,name (x)
441 (xref-result (xref:get-relation ,relation ,name1 ,name2))))
442
443 (defxref who-calls :calls :wild x)
444 (defxref calls-who :calls x :wild)
445 (defxref who-references :uses :wild x)
446 (defxref who-binds :binds :wild x)
447 (defxref who-macroexpands :macro-calls :wild x)
448 (defxref who-sets :sets :wild x)
449
450 (defun xref-result (fspecs)
451 (loop for fspec in fspecs
452 append (fspec-definition-locations fspec)))
453
454 ;; list-callers implemented by groveling through all fbound symbols.
455 ;; Only symbols are considered. Functions in the constant pool are
456 ;; searched recursively. Closure environments are ignored at the
457 ;; moment (constants in methods are therefore not found).
458
459 (defun map-function-constants (function fn depth)
460 "Call FN with the elements of FUNCTION's constant pool."
461 (do ((i 0 (1+ i))
462 (max (excl::function-constant-count function)))
463 ((= i max))
464 (let ((c (excl::function-constant function i)))
465 (cond ((and (functionp c)
466 (not (eq c function))
467 (plusp depth))
468 (map-function-constants c fn (1- depth)))
469 (t
470 (funcall fn c))))))
471
472 (defun in-constants-p (fun symbol)
473 (map-function-constants fun
474 (lambda (c)
475 (when (eq c symbol)
476 (return-from in-constants-p t)))
477 3))
478
479 (defun function-callers (name)
480 (let ((callers '()))
481 (do-all-symbols (sym)
482 (when (fboundp sym)
483 (let ((fn (fdefinition sym)))
484 (when (in-constants-p fn name)
485 (push sym callers)))))
486 callers))
487
488 (defimplementation list-callers (name)
489 (xref-result (function-callers name)))
490
491 (defimplementation list-callees (name)
492 (let ((result '()))
493 (map-function-constants (fdefinition name)
494 (lambda (c)
495 (when (fboundp c)
496 (push c result)))
497 2)
498 (xref-result result)))
499
500 ;;;; Profiling
501
502 ;; Per-function profiling based on description in
503 ;; http://www.franz.com/support/documentation/8.0/doc/runtime-analyzer.htm#data-collection-control-2
504
505 (defvar *profiled-functions* ())
506 (defvar *profile-depth* 0)
507
508 (defmacro with-redirected-y-or-n-p (&body body)
509 ;; If the profiler is restarted when the data from the previous
510 ;; session is not reported yet, the user is warned via Y-OR-N-P.
511 ;; As the CL:Y-OR-N-P question is (for some reason) not directly
512 ;; sent to the Slime user, the function CL:Y-OR-N-P is temporarily
513 ;; overruled.
514 `(let* ((pkg (find-package "common-lisp"))
515 (saved-pdl (excl::package-definition-lock pkg))
516 (saved-ynp (symbol-function 'cl:y-or-n-p)))
517
518 (setf (excl::package-definition-lock pkg) nil
519 (symbol-function 'cl:y-or-n-p) (symbol-function
520 (find-symbol "y-or-n-p-in-emacs"
521 "swank")))
522 (unwind-protect
523 (progn ,@body)
524
525 (setf (symbol-function 'cl:y-or-n-p) saved-ynp
526 (excl::package-definition-lock pkg) saved-pdl))))
527
528 (defun start-acl-profiler ()
529 (with-redirected-y-or-n-p
530 (prof:start-profiler :type :time :count t
531 :start-sampling-p nil :verbose nil)))
532 (defun acl-profiler-active-p ()
533 (not (eq (prof:profiler-status :verbose nil) :inactive)))
534
535 (defun stop-acl-profiler ()
536 (prof:stop-profiler :verbose nil))
537
538 (excl:def-fwrapper profile-fwrapper (&rest args)
539 ;; Ensures sampling is done during the execution of the function,
540 ;; taking into account recursion.
541 (declare (ignore args))
542 (cond ((zerop *profile-depth*)
543 (let ((*profile-depth* (1+ *profile-depth*)))
544 (prof:start-sampling)
545 (unwind-protect (excl:call-next-fwrapper)
546 (prof:stop-sampling))))
547 (t
548 (excl:call-next-fwrapper))))
549
550 (defimplementation profile (fname)
551 (unless (acl-profiler-active-p)
552 (start-acl-profiler))
553 (excl:fwrap fname 'profile-fwrapper 'profile-fwrapper)
554 (push fname *profiled-functions*))
555
556 (defimplementation profiled-functions ()
557 *profiled-functions*)
558
559 (defimplementation unprofile (fname)
560 (excl:funwrap fname 'profile-fwrapper)
561 (setq *profiled-functions* (remove fname *profiled-functions*)))
562
563 (defimplementation profile-report ()
564 (prof:show-flat-profile :verbose nil)
565 (when *profiled-functions*
566 (start-acl-profiler)))
567
568 (defimplementation profile-reset ()
569 (when (acl-profiler-active-p)
570 (stop-acl-profiler)
571 (start-acl-profiler))
572 "Reset profiling counters.")
573
574 ;;;; Inspecting
575
576 (defmethod emacs-inspect ((f function))
577 (append
578 (label-value-line "Name" (function-name f))
579 `("Formals" ,(princ-to-string (arglist f)) (:newline))
580 (let ((doc (documentation (excl::external-fn_symdef f) 'function)))
581 (when doc
582 `("Documentation:" (:newline) ,doc)))))
583
584 (defmethod emacs-inspect ((o t))
585 (allegro-inspect o))
586
587 (defmethod emacs-inspect ((o function))
588 (allegro-inspect o))
589
590 (defmethod emacs-inspect ((o standard-object))
591 (allegro-inspect o))
592
593 (defun allegro-inspect (o)
594 (loop for (d dd) on (inspect::inspect-ctl o)
595 append (frob-allegro-field-def o d)
596 until (eq d dd)))
597
598 (defun frob-allegro-field-def (object def)
599 (with-struct (inspect::field-def- name type access) def
600 (ecase type
601 ((:unsigned-word :unsigned-byte :unsigned-natural
602 :unsigned-long :unsigned-half-long
603 :unsigned-3byte)
604 (label-value-line name (inspect::component-ref-v object access type)))
605 ((:lisp :value)
606 (label-value-line name (inspect::component-ref object access)))
607 (:indirect
608 (destructuring-bind (prefix count ref set) access
609 (declare (ignore set prefix))
610 (loop for i below (funcall count object)
611 append (label-value-line (format nil "~A-~D" name i)
612 (funcall ref object i))))))))
613
614 ;;;; Multithreading
615
616 (defimplementation initialize-multiprocessing (continuation)
617 (mp:start-scheduler)
618 (funcall continuation))
619
620 (defimplementation spawn (fn &key name)
621 (mp:process-run-function name fn))
622
623 (defvar *id-lock* (mp:make-process-lock :name "id lock"))
624 (defvar *thread-id-counter* 0)
625
626 (defimplementation thread-id (thread)
627 (mp:with-process-lock (*id-lock*)
628 (or (getf (mp:process-property-list thread) 'id)
629 (setf (getf (mp:process-property-list thread) 'id)
630 (incf *thread-id-counter*)))))
631
632 (defimplementation find-thread (id)
633 (find id mp:*all-processes*
634 :key (lambda (p) (getf (mp:process-property-list p) 'id))))
635
636 (defimplementation thread-name (thread)
637 (mp:process-name thread))
638
639 (defimplementation thread-status (thread)
640 (format nil "~A ~D" (mp:process-whostate thread)
641 (mp:process-priority thread)))
642
643 (defimplementation make-lock (&key name)
644 (mp:make-process-lock :name name))
645
646 (defimplementation call-with-lock-held (lock function)
647 (mp:with-process-lock (lock) (funcall function)))
648
649 (defimplementation current-thread ()
650 mp:*current-process*)
651
652 (defimplementation all-threads ()
653 (copy-list mp:*all-processes*))
654
655 (defimplementation interrupt-thread (thread fn)
656 (mp:process-interrupt thread fn))
657
658 (defimplementation kill-thread (thread)
659 (mp:process-kill thread))
660
661 (defvar *mailbox-lock* (mp:make-process-lock :name "mailbox lock"))
662
663 (defstruct (mailbox (:conc-name mailbox.))
664 (lock (mp:make-process-lock :name "process mailbox"))
665 (queue '() :type list)
666 (gate (mp:make-gate)))
667
668 (defun mailbox (thread)
669 "Return THREAD's mailbox."
670 (mp:with-process-lock (*mailbox-lock*)
671 (or (getf (mp:process-property-list thread) 'mailbox)
672 (setf (getf (mp:process-property-list thread) 'mailbox)
673 (make-mailbox)))))
674
675 (defimplementation send (thread message)
676 (let* ((mbox (mailbox thread)))
677 (mp:with-process-lock ((mailbox.lock mbox))
678 (setf (mailbox.queue mbox)
679 (nconc (mailbox.queue mbox) (list message)))
680 (mp:open-gate (mailbox.gate mbox)))))
681
682 (defimplementation receive ()
683 (receive-if (constantly t)))
684
685 (defimplementation receive-if (test)
686 (let ((mbox (mailbox mp:*current-process*)))
687 (loop
688 (check-slime-interrupts)
689 (mp:with-process-lock ((mailbox.lock mbox))
690 (let* ((q (mailbox.queue mbox))
691 (tail (member-if test q)))
692 (when tail
693 (setf (mailbox.queue mbox) (nconc (ldiff q tail) (cdr tail)))
694 (return (car tail)))
695 (mp:close-gate (mailbox.gate mbox))))
696 (mp:process-wait-with-timeout "receive-if" 0.5
697 #'mp:gate-open-p (mailbox.gate mbox)))))
698
699 (defimplementation quit-lisp ()
700 (excl:exit 0 :quiet t))
701
702
703 ;;Trace implementations
704 ;;In Allegro 7.0, we have:
705 ;; (trace <name>)
706 ;; (trace ((method <name> <qualifier>? (<specializer>+))))
707 ;; (trace ((labels <name> <label-name>)))
708 ;; (trace ((labels (method <name> (<specializer>+)) <label-name>)))
709 ;; <name> can be a normal name or a (setf name)
710
711 (defimplementation toggle-trace (spec)
712 (ecase (car spec)
713 ((setf)
714 (toggle-trace-aux spec))
715 (:defgeneric (toggle-trace-generic-function-methods (second spec)))
716 ((setf :defmethod :labels :flet)
717 (toggle-trace-aux (process-fspec-for-allegro spec)))
718 (:call
719 (destructuring-bind (caller callee) (cdr spec)
720 (toggle-trace-aux callee
721 :inside (list (process-fspec-for-allegro caller)))))))
722
723 (defun tracedp (fspec)
724 (member fspec (eval '(trace)) :test #'equal))
725
726 (defun toggle-trace-aux (fspec &rest args)
727 (cond ((tracedp fspec)
728 (eval `(untrace ,fspec))
729 (format nil "~S is now untraced." fspec))
730 (t
731 (eval `(trace (,fspec ,@args)))
732 (format nil "~S is now traced." fspec))))
733
734 (defun toggle-trace-generic-function-methods (name)
735 (let ((methods (mop:generic-function-methods (fdefinition name))))
736 (cond ((tracedp name)
737 (eval `(untrace ,name))
738 (dolist (method methods (format nil "~S is now untraced." name))
739 (excl:funtrace (mop:method-function method))))
740 (t
741 (eval `(trace (,name)))
742 (dolist (method methods (format nil "~S is now traced." name))
743 (excl:ftrace (mop:method-function method)))))))
744
745 (defun process-fspec-for-allegro (fspec)
746 (cond ((consp fspec)
747 (ecase (first fspec)
748 ((setf) fspec)
749 ((:defun :defgeneric) (second fspec))
750 ((:defmethod) `(method ,@(rest fspec)))
751 ((:labels) `(labels ,(process-fspec-for-allegro (second fspec))
752 ,(third fspec)))
753 ((:flet) `(flet ,(process-fspec-for-allegro (second fspec))
754 ,(third fspec)))))
755 (t
756 fspec)))
757
758
759 ;;;; Weak hashtables
760
761 (defimplementation make-weak-key-hash-table (&rest args)
762 (apply #'make-hash-table :weak-keys t args))
763
764 (defimplementation make-weak-value-hash-table (&rest args)
765 (apply #'make-hash-table :values :weak args))
766
767 (defimplementation hash-table-weakness (hashtable)
768 (cond ((excl:hash-table-weak-keys hashtable) :key)
769 ((eq (excl:hash-table-values hashtable) :weak) :value)))
770
771
772
773 ;;;; Character names
774
775 (defimplementation character-completion-set (prefix matchp)
776 (loop for name being the hash-keys of excl::*name-to-char-table*
777 when (funcall matchp prefix name)
778 collect (string-capitalize name)))

  ViewVC Help
Powered by ViewVC 1.1.5