[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stack consing

    Date: Mon, 27 Jun 88 13:58 PDT
    From: Siskind.pa@Xerox.COM

    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? 

Yes, although we reserve the right to change this in future machine offerings.

		     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?  

No.  Actually it's correct a lot of the time, but is incorrect in circumstances
that are too much trouble to explain.

In general, you should use only the documented interfaces and not listen to me,
unless you don't care whether your program continues to run in future releases
and don't care whether your program ports to future machine offerings.

						   If so is the following code

I didn't try running the code.  This technique will work a lot of the time,
however cross-function-call stack allocation isn't guaranteed.

    (defun foo (x)
       (reverse-on-data-stack x))))

    (defun reverse-on-data-stack (x)
     (if (null 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)

    (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?

Often.  Not always.