5

The Smalltalk object thisContext look strange and marvelous. I can't understand what it is and how it works. And even how it enables continuations.

For C's call-stack, I can easily imagine how is it implemented and working. But for this... I can't. Please help me to understand it.

Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
eonil
  • 83,476
  • 81
  • 317
  • 516

3 Answers3

5

I think it is not an easy question. The stack is reified in the image with instances of MethodContext. A MethodContext can have a sender, which is another MethodContext. That one can have another one...generating a whole stack. MethodContext are instantiated by the VM while executing CompiledMethod (which are also reified in the language).

How MethodContext are mapped to C stack, that depends on the VM. StackVM (CogVM is on top of StackVM) is exactly a VM that better maps MethodContext con C stack.

Apart from the BlueBook that Lukas said, check

http://www.mirandabanda.org/cogblog/ check on the left the posts...

I recommend you to ask in http://lists.squeakfoundation.org/mailman/listinfo/vm-dev

4

The best explanation you can find in Smalltalk-80: The Language and its Implementation, Chapter 26 to 30. The stack frames (contexts) are explained on page 580.

Lukas Renggli
  • 8,754
  • 23
  • 46
3

It's more correct to say that thisContext is a continuation - the current continuation, in particular.

Imagine a variable c that, just before a MethodContext activates, is set to point to that context. That's thisContext.

Frank Shearar
  • 17,012
  • 8
  • 67
  • 94
  • Thanks for answer. It's hard time to me because I couldn't fully understand implementation of continuation itself yet... – eonil Jun 15 '11 at 17:20