Class Get Attribute Property
When it is time to get the object's attribute, LW Python looks in the Values Stack to see where the object is in the Object Store. Then it looks for the attribute in the object and returns the corresponding value. More formally,
if the following are true:
- Expression Stack at time t = [ [ ], [ [ obj.attr, ys ], rest ] ]
- Value Stack at time t = [ [ Python reference index, [ ] ], [ next_level, other_levels ] ]
- the element at index index of stack (Python Object Store at time t) = Python object: attributes
then Value Stack at time (t + 1) = [ [ value at attr in map attributes, next_level ], other_levels ]
- Expression Stack at time 49 = [ [ ], [ [
self.age
, [ 12, [ ] ] ], [ [__mul__(self.age, 12)
, [ ] ], [ ] ] ] ] - Value Stack at time 49 = [ [ Python reference 0, [ ] ], [ [ ], [ [ ], [ ] ] ] ]
- Python Object Store at time 49 = [ Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ entry "last_name": "Smith", [ entry "age": 25, [ ] ] ] ] ], [ ] ]
Here is a table view of the "Object Store:"
Index | Type | Contents | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
0 | class instance | __class_name__ | Person | ||||||||
first_name | John | ||||||||||
last_name | Smith | ||||||||||
age | 25 |
Then we claim that
the element at index 0 of stack (Python Object Store at time 49) = Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ entry "last_name": "Smith", [ entry "age": 25, [ ] ] ] ] ]
Here is a table view of the object at index 0:
Attribute | Value |
---|---|
__class_name__ | Person |
first_name | John |
last_name | Smith |
age | 25 |
Then we conclude that:
Value Stack at time (49 + 1) = [ [ value at "age" in map [ entry "__class_name__": "Person", [ entry "first_name": "John", [ entry "last_name": "Smith", [ entry "age": 25, [ ] ] ] ] ], [ ] ], [ [ ], [ ] ] ]
We claim that:
value at "age" in map [ entry "__class_name__": "Person", [ entry "first_name": "John", [ entry "last_name": "Smith", [ entry "age": 25, [ ] ] ] ] ] = 25
We conclude that:
Value Stack at time (49 + 1) = [ [ 25, [ ] ], [ [ ], [ ] ] ]
Which simplifies to:
Value Stack at time 50 = [ [ 25, [ ] ], [ [ ], [ ] ] ]
See here for the full proof.
The object is in index 0 of the "Object Store" and the "age" of this object is 25. Try stepping through the simulator to see LW Python push 25 to the Values Stack.
Current Line | 1 | Current Tab | 0 | Time | 0 |
Comments
Please log in to add comments