[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: stack consing
Though it is not 100% apparent from the documentation, I seem to infer that
WITH-STACK-LIST allocates storage on the control stack, while MAKE-STACK-ARRAY,
WITH-STACK-ARRAY, and WITH-DATA-STACK allocate storage on the data stack.
Is that correct? In my naievite I further infer that function calling and returning
only uses the control stack and not the data stack so that the allocation
and freeing of storage on the data stack can be independent and thus cross
function calling boundaries. Is this correct? If so is the following code
correct?
(defun foo (x)
(WITH-DATA-STACK
(a-function-which-examines-but-does-not-retain-a-pointer-to-its-argument
(reverse-on-data-stack x))))
(defun reverse-on-data-stack (x)
(if (null x)
x
(append1-on-data-stack (reverse-on-data-stack (fake-cdr x)) (fake-car x))))
(defun append1-on-data-stack (x e)
(if (null x)
(fake-cons e nil)
(fake-cons (fake-car x) (append1-on-data-stack (fake-cdr x) e))))
(defun fake-cons (x y)
(let ((z MAKE-STACK-ARRAY 2))
(setf (aref z 0) x)
(setf (aref z 1) y)
z))
(defun fake-car (x)
(aref x 0))
(defun fake-cdr (x)
(aref x 1))
The idea is that one function creates a data stack frame and then calls other functions
which allocate storage. Will this work?
Thanks again for your help,
Jeff
-------