87afb11b9791

Add a function for extracting things from the heap
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 27 Mar 2016 22:25:43 +0000
parents d80af96eaf15
children 0b1008a7fe76
branches/tags (none)
files src/wam/dump.lisp

Changes

--- a/src/wam/dump.lisp	Sun Mar 27 18:32:37 2016 +0000
+++ b/src/wam/dump.lisp	Sun Mar 27 22:25:43 2016 +0000
@@ -71,3 +71,20 @@
                  (+ addr width 1))
             addr))
 
+
+
+(defun extract-thing (wam address)
+  (let ((cell (wam-heap-cell wam (deref wam address))))
+    (cond
+      ((cell-null-p cell)
+       "NULL!")
+      ((cell-reference-p cell)
+       (format nil "var-~D" (cell-value cell)))
+      ((cell-structure-p cell)
+       (extract-thing wam (cell-value cell)))
+      ((cell-functor-p cell)
+       (let ((functor (wam-functor-lookup wam (cell-functor-index cell)))
+             (arity (cell-functor-arity cell)))
+         (list* functor
+                (loop :for i :from (1+ address) :to (+ address arity)
+                      :collect (extract-thing wam i))))))))