Save Stack Rule

When the state is "call_build_args" and the function parameters list is empty, then the following are grouped into a "context" and prepended to the stack:

  • "Variables" map
  • "Parent" stack
  • "Arguments" stack
  • "Values" stack
  • Current line number
  • Current tab number
  • "Control" map

More formally:

if the following are true:
  • expression state at time t = "call_build_args"
  • Parameters List at time t = [ ]

then stack at time (t + 1) = [ program context with variables: (Variables Map at time t) and expression state: (expression state with parent stack: (parent stack at time t) arguments: (arguments stack at time t) values: (Value Stack at time t) line: (the line at time t) tab: (the tab at time t)) and control map: (Control Map at time t), stack at time t ]

When the state is "call_build_args" and the function parameters stack is empty, Python has finished constructing the "Function Variables" map and will overwrite:
  • the current variables map with the Function Variables map
  • current line number with the first line number of the function body
  • current tab number with the first tab number of the function body

Python needs to remember the current state so that when the function call is finished, Python can return to the call site and resume execution.

For example, if the following are true:

  • expression state at time 12 = "call_build_args"
  • Parameters List at time 12 = [ ]
  • stack at time 12 = [ ]
  • Variables Map at time 12 = [ entry a: 5, [ ] ]
  • parent stack at time 12 = [ ]
  • arguments stack at time 12 = [ ]
  • Value Stack at time 12 = [ ]
  • the line at time 12 = 5
  • the tab at time 12 = 0
  • Control Map at time 12 = [ ]

then stack at time 13 = [ program context with variables: [ entry a: 5, [ ] ] and expression state: (expression state with parent stack: [ ] arguments: [ ] values: [ ] line: 5 tab: 0) and control map: [ ], [ ] ]

Try stepping through the simulator to see LW Python populate the "Stack" with the current context.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments