1.1 --- a/micropython/__init__.py Fri Mar 21 02:14:30 2008 +0100
1.2 +++ b/micropython/__init__.py Sat Mar 22 22:31:54 2008 +0100
1.3 @@ -65,6 +65,11 @@
1.4 self.modules = {"__builtins__" : micropython.inspect.builtins}
1.5 self.loading = set()
1.6
1.7 + # Remember the tables once generated.
1.8 +
1.9 + self.objtable = None
1.10 + self.paramtable = None
1.11 +
1.12 def vacuum(self):
1.13
1.14 "Tidy up the modules."
1.15 @@ -81,12 +86,12 @@
1.16
1.17 return self.modules.values()
1.18
1.19 - def get_image(self, objtable=None, paramtable=None, with_builtins=0):
1.20 + def get_image(self, with_builtins=0):
1.21
1.22 "Return a dictionary mapping modules to structures."
1.23
1.24 - objtable = objtable or self.get_object_table()
1.25 - paramtable = paramtable or self.get_parameter_table()
1.26 + objtable = self.get_object_table()
1.27 + paramtable = self.get_parameter_table()
1.28
1.29 image = []
1.30
1.31 @@ -191,24 +196,40 @@
1.32
1.33 "Return a table with details of attributes for classes and modules."
1.34
1.35 - t = micropython.table.Table()
1.36 - for module in self.get_modules():
1.37 - t.add(module.full_name(), module.module_attributes())
1.38 - for obj in module.all_objects:
1.39 - if isinstance(obj, micropython.inspect.Class):
1.40 - t.add(obj.full_name(), obj.all_attributes())
1.41 - return t
1.42 + if self.objtable is None:
1.43 + t = self.objtable = micropython.table.Table()
1.44 + for module in self.get_modules():
1.45 + t.add(module.full_name(), module.module_attributes())
1.46 + for obj in module.all_objects:
1.47 + if isinstance(obj, micropython.inspect.Class):
1.48 + t.add(obj.full_name(), obj.all_attributes())
1.49 +
1.50 + return self.objtable
1.51
1.52 def get_parameter_table(self):
1.53
1.54 "Return a table with details of parameters for functions and methods."
1.55
1.56 - t = micropython.table.Table()
1.57 - for module in self.get_modules():
1.58 - for obj in module.all_objects:
1.59 - if isinstance(obj, micropython.inspect.Function):
1.60 - t.add(obj.full_name(), obj.parameters())
1.61 - return t
1.62 + # Need the object table to get at class details.
1.63 +
1.64 + objtable = self.get_object_table()
1.65 +
1.66 + if self.paramtable is None:
1.67 + t = self.paramtable = micropython.table.Table()
1.68 + for module in self.get_modules():
1.69 + for obj in module.all_objects:
1.70 + if isinstance(obj, micropython.inspect.Function):
1.71 + t.add(obj.full_name(), obj.parameters())
1.72 +
1.73 + # Classes are callable, too.
1.74 + # Copy details of the appropriate __init__ method to make an
1.75 + # entry for the class.
1.76 +
1.77 + elif isinstance(obj, micropython.inspect.Class):
1.78 + init_method = objtable.table[obj.full_name()]["__init__"].value
1.79 + t.add(obj.full_name(), init_method.parameters())
1.80 +
1.81 + return self.paramtable
1.82
1.83 # Import methods.
1.84
2.1 --- a/micropython/inspect.py Fri Mar 21 02:14:30 2008 +0100
2.2 +++ b/micropython/inspect.py Sat Mar 22 22:31:54 2008 +0100
2.3 @@ -1228,10 +1228,12 @@
2.4 # NOTE: Temporary measure - provide detailed built-ins.
2.5
2.6 cls = Class("list", self, self)
2.7 + cls.set("__init__", Function("__init__", cls, [], 0, 0, cls))
2.8 cls.set("__iter__", Function("__iter__", cls, [], 0, 0, cls))
2.9 self.store("list", cls)
2.10
2.11 cls = Class("listiterator", self, self)
2.12 + cls.set("__init__", Function("__init__", cls, [], 0, 0, cls))
2.13 cls.set("next", Function("next", cls, [], 0, 0, cls))
2.14 self.store("listiterator", cls)
2.15