Push Self To Values Property
When evaluating a method call, LW Python pushes the reference to the object to "Argument Values." More formally,
if the following are true:
- expression state at time t = "call_function_begin"
- the expression at time t = obj_name.method_name(args)
- value at obj_name in map (Variables Map at time t) = Python reference index
- the element at index index of stack (Python Object Store at time t) = Python object: [ entry "__class_name__": class_name, e_rest ]
- Value Stack at time t = [ values, v_stack ]
- definition of method method_name of class class_name in (Class Map at time t) = method_map
then Argument Values at time (t + 1) = [ Python reference index, reverse of values ]
In a function call, "Argument Values" is just the reverse of the top of the "Values" stack. However, in a method call, "self" is always the first argument, so LW Python adds it on top. For example,
if the following are true:
- expression state at time 56 = "call_function_begin"
- Value Stack at time 56 = [ [ ], [ ] ]
- the expression at time 56 =
p.age_in_months()
- value at p in map (Variables Map at time 56) = Python reference 0
- the element at index 0 of stack (Python Object Store at time 56) = Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ entry "last_name": "Smith", [ entry "age": 25, [ ] ] ] ] ]
- definition of method "age_in_months" of class "Person" in (Class Map at time 56) = [ entry "params": [ self, [ ] ], [ entry "line": 6, [ ] ] ]
then Argument Values at time (56 + 1) = [ Python reference 0, reverse of [ ] ]
Try stepping through the simulator to see LW Python populate "Argument Values."
Code Editor
LW Python State
Current Line | 1 | Current Tab | 0 | Time | 0 |
LW Python Simulator
Comments
Please log in to add comments