Return State Rule
After a function has finished executing, Python returns to the line where the function was called (call site). The expression state is now set to "call_returned." More formally,
if the following are true:
- the line at time t = i
- the tab at time t = j
- statement at line i, tab j =
return rex
- 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 ]
- expression state at time t = "end_expr"
then expression state at time (t + 1) = "call_returned"
For example,
if the following are true:
- the line at time 26 = 3
- the tab at time 26 = 1
- statement at line 3, tab 1 =
return z
- stack at time 26 = [ program context with variables: [ entry a: 5, [ ] ] and expression state: (expression state with parent stack: [ ] arguments: [ ] values: [ ] line: 5 tab: 0) and control map: [ ], [ ] ]
- expression state at time 26 = "end_expr"
then expression state at time (26 + 1) = "call_returned"
Try stepping through the simulator to see LW Python update the "Expression State."
Code Editor
LW Python State
Current Line | 1 | Current Tab | 0 | Time | 0 |
LW Python Simulator
Comments
Please log in to add comments