Skip to content

Commit

Permalink
Added docstrings for ObjectMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bystroushaak committed Sep 30, 2019
1 parent 9aefa84 commit 003210d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/tinySelf/vm/object_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,12 @@ def __init__(self):
self.parameters = []

def clone(self):
"""
Create new map with same properties.
Returns:
ObjectMap: Shallow copy of this map.
"""
new_map = ObjectMap()

new_map._slots = self._slots.copy()
Expand All @@ -626,12 +632,28 @@ def clone(self):

# meta-modifications
def add_slot(self, slot_name, index):
"""
Meta operation; add slot.
Args:
slot_name (str):
index (int): Index in the Object's ._slot_values list.
"""
assert isinstance(index, int)

self._slots[slot_name] = index
self.inc_version()

def remove_slot(self, slot_name):
"""
Meta operation; remove slot.
Args:
slot_name (str):
Returns:
bool: True if the slot was successfully removed.
"""
if slot_name not in self._slots:
return False

Expand All @@ -641,6 +663,14 @@ def remove_slot(self, slot_name):
return True

def insert_slot(self, slot_index, slot_name, index):
"""
Meta operation; insert slot to `slot_index`.
Args:
slot_index (int): Where to put it.
slot_name (str):
index (int): Index in the Object's ._slot_values list.
"""
if slot_index < 0:
slot_index = 0

Expand All @@ -658,12 +688,23 @@ def insert_slot(self, slot_index, slot_name, index):
self.inc_version()

def add_parent(self, parent_name, index):
"""
Meta operation; Add parent.
Args:
parent_name (str): Name of the parent slot.
index (int): Index in the Object's ._parent.slot_values list.
"""
assert isinstance(index, int)

self._parent_slots[parent_name] = index
self.inc_version()

def remove_parent(self, parent_name):
"""
Meta operation; Remove parent.
Args:
parent_name (str): Name of the parent slot.
"""
if not self._parent_slots.has_key(parent_name):
return False

Expand All @@ -673,5 +714,8 @@ def remove_parent(self, parent_name):
return True

def inc_version(self):
"""
Increase the `_version` property.
"""
self._version += 1
inc_version._always_inline_ = True

0 comments on commit 003210d

Please sign in to comment.