# HG changeset patch # User Paul Boddie # Date 1206221514 -3600 # Node ID 1725bf186f7381289266890739104897e7482ae0 # Parent 04456ecc182e64f4e555144bd4f097c912b6f23c Introduced caching of object and parameter tables. Added parameter table entries for classes, referring to the appropriate __init__ method which should be called when a class is invoked. Added missing __init__ methods to list and listiterator. diff -r 04456ecc182e -r 1725bf186f73 micropython/__init__.py --- a/micropython/__init__.py Fri Mar 21 02:14:30 2008 +0100 +++ b/micropython/__init__.py Sat Mar 22 22:31:54 2008 +0100 @@ -65,6 +65,11 @@ self.modules = {"__builtins__" : micropython.inspect.builtins} self.loading = set() + # Remember the tables once generated. + + self.objtable = None + self.paramtable = None + def vacuum(self): "Tidy up the modules." @@ -81,12 +86,12 @@ return self.modules.values() - def get_image(self, objtable=None, paramtable=None, with_builtins=0): + def get_image(self, with_builtins=0): "Return a dictionary mapping modules to structures." - objtable = objtable or self.get_object_table() - paramtable = paramtable or self.get_parameter_table() + objtable = self.get_object_table() + paramtable = self.get_parameter_table() image = [] @@ -191,24 +196,40 @@ "Return a table with details of attributes for classes and modules." - t = micropython.table.Table() - for module in self.get_modules(): - t.add(module.full_name(), module.module_attributes()) - for obj in module.all_objects: - if isinstance(obj, micropython.inspect.Class): - t.add(obj.full_name(), obj.all_attributes()) - return t + if self.objtable is None: + t = self.objtable = micropython.table.Table() + for module in self.get_modules(): + t.add(module.full_name(), module.module_attributes()) + for obj in module.all_objects: + if isinstance(obj, micropython.inspect.Class): + t.add(obj.full_name(), obj.all_attributes()) + + return self.objtable def get_parameter_table(self): "Return a table with details of parameters for functions and methods." - t = micropython.table.Table() - for module in self.get_modules(): - for obj in module.all_objects: - if isinstance(obj, micropython.inspect.Function): - t.add(obj.full_name(), obj.parameters()) - return t + # Need the object table to get at class details. + + objtable = self.get_object_table() + + if self.paramtable is None: + t = self.paramtable = micropython.table.Table() + for module in self.get_modules(): + for obj in module.all_objects: + if isinstance(obj, micropython.inspect.Function): + t.add(obj.full_name(), obj.parameters()) + + # Classes are callable, too. + # Copy details of the appropriate __init__ method to make an + # entry for the class. + + elif isinstance(obj, micropython.inspect.Class): + init_method = objtable.table[obj.full_name()]["__init__"].value + t.add(obj.full_name(), init_method.parameters()) + + return self.paramtable # Import methods. diff -r 04456ecc182e -r 1725bf186f73 micropython/inspect.py --- a/micropython/inspect.py Fri Mar 21 02:14:30 2008 +0100 +++ b/micropython/inspect.py Sat Mar 22 22:31:54 2008 +0100 @@ -1228,10 +1228,12 @@ # NOTE: Temporary measure - provide detailed built-ins. cls = Class("list", self, self) + cls.set("__init__", Function("__init__", cls, [], 0, 0, cls)) cls.set("__iter__", Function("__iter__", cls, [], 0, 0, cls)) self.store("list", cls) cls = Class("listiterator", self, self) + cls.set("__init__", Function("__init__", cls, [], 0, 0, cls)) cls.set("next", Function("next", cls, [], 0, 0, cls)) self.store("listiterator", cls)