Call stack retainstack? namestack?

This Factor manual page talks about these types of stacks stored in continuations:

  • datastack
  • retainstack
  • Callstack
  • namestack
  • catchstack

What exactly do these stacks do? The three most confusing me are a freeze call, a freeze frame and an icon.

+6
source share
1 answer

Of course, I am not a guru factor, but since their names seem to imply their use:

  • datastack: used for normal clicking and displaying values. 3 4 + uses datastack to press β€œ3”, then press β€œ4”. Running "+" pushes 2 values ​​from the data set and pushes the response, 5, back to the data table. Starting an interactive factor session (at least on Linux) prints the contents of this stack after each interaction:

     $> 1 --- Data stack: 1 $> 2 --- Data stack: 1 2 $> + --- Data stack: 3 $> . 3 $> 
  • callstack: used to store those words that are being executed, and their individual progress when executing their component words. Imagine that you have determined the best version of the sum:: : sum' ( seq-of-int -- summmation ) 0 [ + ] reduce 20 + ; (this is better because you get an extra 20 for free!). Desiring to reuse the code, you used the word reduce , which comes with a standard coefficient. While the sum' runtime is running, it invokes the reduce implementation. But, since we still need to add an extra 20, someone should write down where to start again as soon as reduce returns. These notes are stored in a callstack, most likely with some supporting data during debugging runs to help debuggers understand what is going on.

  • keepstack: used to save values ​​as an auxiliary data table. In Fort, you can abuse the Forth analog to the callstack to act like a still image. One of the problems with this approach is that returning from your word without clearing a dirty hack will cause you to go to the wrong places and destroy the general chaos. Forth runtime will see your values, expecting them to become good notes that he makes when he calls out words and gets confused. By using a separate stack for return addresses, Factor can avoid this.

  • namestack: used to store the data needed to implement dynamic variables . Using the stack, you can hide the old names with the new ones by executing the routine, then place the binding and the old names will be restored.

  • catchstack: used to support exception handling. Using the stack, routines can register their own specialty handlers for exceptions and default shadow behavior. Then, as soon as the word returns, the old handlers can be easily restored by jumping out of the stack.

+8
source

Source: https://habr.com/ru/post/908860/


All Articles