Skip to content

Commit

Permalink
(remove-dead-threads): New function.
Browse files Browse the repository at this point in the history
(lookup-thread): Use it.

(print-arglist): New function. This time without binding pretty
dispatch table.
(format-arglist): Use it.

(inspected-parts): Add method for hash-tables.
  • Loading branch information
Helmut Eller committed Mar 4, 2004
1 parent 0f59487 commit bcb7772
Showing 1 changed file with 59 additions and 6 deletions.
65 changes: 59 additions & 6 deletions swank.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ determined at compile time."
(defvar *active-threads* '())
(defvar *thread-counter* 0)

(defun remove-dead-threads ()
(setq *active-threads*
(remove-if-not #'thread-alive-p *active-threads*)))

(defun add-thread (thread)
(let ((id (mod (1+ *thread-counter*) most-positive-fixnum)))
(setq *active-threads* (acons id thread *active-threads*)
Expand All @@ -324,7 +328,13 @@ element."
(assert pair)
(car pair)))

(defvar *lookup-counter* nil
"A simple counter used to remove dead threads from *active-threads*.")

(defun lookup-thread (thread)
(when (zerop (decf *lookup-counter*))
(setf *lookup-counter* 50)
(remove-dead-threads))
(let ((probe (rassoc thread *active-threads*)))
(cond (probe (car probe))
(t (add-thread thread)))))
Expand All @@ -338,7 +348,8 @@ element."
(defun dispatch-loop (socket-io connection)
(let ((*emacs-connection* connection)
(*active-threads* '())
(*thread-counter* 0))
(*thread-counter* 0)
(*lookup-counter* 50))
(loop (with-simple-restart (abort "Retstart dispatch loop.")
(loop (dispatch-event (receive) socket-io))))))

Expand Down Expand Up @@ -718,12 +729,38 @@ Call LAMBDA-LIST-FN with the symbol corresponding to FUNCTION-NAME."
(let ((symbol (find-symbol-or-lose function-name)))
(values (funcall lambda-list-fn symbol))))
(cond (condition (format nil "(-- ~A)" condition))
(t (if (null arglist)
(t (if (null arglist)
"()"
(let ((*print-case* :downcase)
(*print-level* nil)
(*print-length* nil))
(princ-to-string arglist)))))))
(print-arglist-to-string arglist))))))

(defun print-arglist-to-string (arglist)
(with-output-to-string (*standard-output*)
(print-arglist arglist)))

(defun print-arglist (arglist)
(let ((*print-case* :downcase)
(*print-pretty* t))
(pprint-logical-block (*standard-output* arglist :prefix "(" :suffix ")")
(loop
(let ((arg (pprint-pop)))
(etypecase arg
(symbol (princ arg))
(cons (pprint-logical-block (*standard-output* arg :prefix "("
:suffix ")")
(princ (car arg))
(write-char #\space)
(pprint-fill *standard-output* (cdr arg) nil))))
(pprint-exit-if-list-exhausted)
(write-char #\space)
(pprint-newline :fill))))))

(defun test-print-arglist (list string)
(string= (print-arglist-to-string list) string))

(assert (test-print-arglist '(function cons) "(function cons)"))
(assert (test-print-arglist '(quote cons) "(quote cons)"))
;; (assert (test-print-arglist '(&key (function #'f)) "(&key (function #'f))"))
;; (assert (test-print-arglist '(&key ((function f))) "(&key ((function f)))"))


;;;; Debugger
Expand Down Expand Up @@ -1519,6 +1556,22 @@ nil if there's no second element."
(push (cons (string 'rest) in-list) reversed-elements)
(done "The object is an improper list of length ~S.~%")))))))

(defmethod inspected-parts ((o hash-table))
(values (format nil "~A~% is a ~A" o (class-of o))
(list*
(cons "Test" (hash-table-test o))
(cons "Count" (hash-table-count o))
(cons "Size" (hash-table-size o))
(cons "Rehash-Threshold" (hash-table-rehash-threshold o))
(cons "Rehash-Size" (hash-table-rehash-size o))
(cons "---" :---)
(let ((pairs '()))
(maphash (lambda (key value)
(push (cons (to-string key) value)
pairs))
o)
pairs))))

(defslimefun inspect-in-frame (string index)
(reset-inspector)
(inspect-object (eval-in-frame (from-string string) index)))
Expand Down

0 comments on commit bcb7772

Please sign in to comment.