# HG changeset patch # User Paul Boddie # Date 1200614111 -3600 # Node ID 4f83a4f9373acb62cf138a52b07c3863d8a2c77b # Parent 84d41da209193bdbc417d82f85b24f9d9959c17f Added assignment counting for names plus notes on potential optimisations. Added missing Sliceobj handler. Added comments about local imports. diff -r 84d41da20919 -r 4f83a4f9373a README.txt --- a/README.txt Sun Jan 13 02:50:21 2008 +0100 +++ b/README.txt Fri Jan 18 00:55:11 2008 +0100 @@ -167,3 +167,13 @@ Using the approach where arguments are treated like attributes in some kind of structure, we could choose to allocate frames in places other than a stack. This would produce something somewhat similar to a plain tuple object. + +Optimisations +============= + +Where attributes of modules, classes and instances are only set once and are +effectively constant, it should be possible to circumvent the attribute lookup +mechanism and to directly reference the attribute value. This may only be of +relevance where the values are modules, classes or functions, and it may be +difficult to detect eligible attributes on instances due to the need for some +kind of type inference or abstract execution. diff -r 84d41da20919 -r 4f83a4f9373a micropython/inspect.py --- a/micropython/inspect.py Sun Jan 13 02:50:21 2008 +0100 +++ b/micropython/inspect.py Fri Jan 18 00:55:11 2008 +0100 @@ -68,6 +68,10 @@ self.namespace = {} self.globals = set() + # Number of assignments per name. + + self.assignments = {} + def __getitem__(self, name): return self.namespace[name] @@ -78,6 +82,13 @@ if name not in self.globals: self.namespace[name] = value + # Record the number of assignments to each name. + + if not self.assignments.has_key(name): + self.assignments[name] = 1 + else: + self.assignments[name] += 1 + def __delitem__(self, name): del self.namespace[name] @@ -648,6 +659,9 @@ if module is None: print "Warning:", node.modname, "not imported." + # NOTE: This could produce local names instead of globals where import + # NOTE: is used within functions. + for name, alias in node.names: if name != "*": if module is not None and module.namespace.has_key(name): @@ -731,6 +745,9 @@ if self.importer is None: raise InspectError, "Please use the micropython.Importer class for code which uses the 'import' statement." + # NOTE: This could produce local names instead of globals where import + # NOTE: is used within functions. + for name, alias in node.names: if alias is not None: self[alias] = self.importer.load(name, 1) or UnresolvedName(None, name) @@ -793,6 +810,8 @@ visitSlice = NOP + visitSliceobj = NOP + def visitStmt(self, node): for n in node.nodes: self.dispatch(n)