Restore Variables After Method Call Property

If LW Python has finished executing a method body, then restore the "Variables" map from the stack.

if the following are true:

  • the line at time t = i
  • the tab at time t = j
  • statement at line i, tab k = s
  • k < j
  • value at (j - 1) in map (Control Map at time t) = pair ("method", mname)
  • stack at time t = [ program context with variables: varis and expression state: (expression state with parent stack: parent_stack arguments: arg_stack values: value_stack line: line tab: tab) and control map: control_map, rest ]

then Variables Map at time (t + 1) = varis

After a method body has completed, LW Python returns to the call site and resumes execution. To resume execution, it restores the "Variable" map that was pushed to the stack just before jumping to the method. For example,

if the following are true:

  • the line at time 50 = 6
  • the tab at time 50 = 2
  • statement at line 6, tab 1 = def age_in_months(self):
  • value at (2 - 1) in map (Control Map at time 50) = pair ("method", "__init__")
  • stack at time 50 = [ program context with variables: [ ] and expression state: (expression state with parent stack: [ ] arguments: [ ] values: [ ] line: 8 tab: 0) and control map: [ entry 0: (pair ("class", "Person")), [ ] ], [ ] ]

then Variables Map at time (50 + 1) = [ ]

Try stepping through the simulator to see LW Python restore the "Variables" map from the stack.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments