>> Oh. How is the stack represented? > > As usual, as successive locations in memory. > I have the impression that CPython uses the same stack C does.
Actually, it doesn't (at least not for the evaluation stack). In CPython, when a Python function starts, the maximum depth of the evaluation stack is known, but it depends on the specific function (of course). So Python needs to allocate an array for the evaluation stack with known size, but can't do so on the C stack (at least not portably), since you can't allocate dynamically-sized array as a local variable in C. So instead, pymalloc is used to allocate the evaluation stack, and it is part of the frame object (so the entire frame object is allocated in one chunk, and then split up into local variables and evaluation stack. > While conceptually, CPython may put objects on the stack, I am pretty > sure it actually stacks references (C pointers) to objects in heap memory. Correct. >> Does it keep track of which stack >> positions (TOS, TOS1, etc.) are in what registers? > > I am sure they are not in registers, just normal memory. Correct. As discussed above, they are located on the heap (making Python's frame stack a spaghetti stack). Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list