# HG changeset patch # User Paul Boddie # Date 1202582258 -3600 # Node ID 88cac9d8f47e4f2b447248062d7305973f3990f8 # Parent 850db0ec0ccfcd323ca458e70ca775d11db8332a Fixed local name access in the code generator. Changed code generation to produce class top-level code in sequence with other code, rather than together with attribute definitions. Changed notes about module structures. diff -r 850db0ec0ccf -r 88cac9d8f47e README.txt --- a/README.txt Sat Feb 09 02:35:57 2008 +0100 +++ b/README.txt Sat Feb 09 19:37:38 2008 +0100 @@ -82,16 +82,18 @@ function locals are completely distinct from this structure and are not comparable to attributes. -For modules, the invocation reference would point to the start of the -module's code: +For modules, there is no meaningful invocation reference: Module m: 0 1 2 3 4 - code for m code module type attribute ... - reference reference (global) + code for m (unused) module type attribute ... + reference (global) reference +Both classes and modules have code in their definitions, but this would be +generated in order and not referenced externally. + Invocation Operation -------------------- diff -r 850db0ec0ccf -r 88cac9d8f47e micropython/__init__.py --- a/micropython/__init__.py Sat Feb 09 02:35:57 2008 +0100 +++ b/micropython/__init__.py Sat Feb 09 19:37:38 2008 +0100 @@ -134,17 +134,7 @@ image += module.to_list(attributes) pos += len(attributes.keys()) - # Append the class-level code to the image. - # NOTE: An extra optimisation would involve - # NOTE: pre-initialisation of attributes and no code being - # NOTE: generated here, or perhaps the pre-initialisation of - # NOTE: methods and only other attribute-related code being - # NOTE: generated here. - - obj.code_location = pos - code = trans.get_code(obj) - image += code - pos += len(code) + # Class-level code is generated separately. # NOTE: Generate module and function code here. diff -r 850db0ec0ccf -r 88cac9d8f47e micropython/ast.py --- a/micropython/ast.py Sat Feb 09 02:35:57 2008 +0100 +++ b/micropython/ast.py Sat Feb 09 19:37:38 2008 +0100 @@ -142,7 +142,7 @@ if scope == "local": unit = self.unit if isinstance(unit, micropython.inspect.Function): - self.new_op(NameInstruction(unit.locals()[name])) + self.new_op(NameInstruction(unit.all_locals()[name])) elif isinstance(unit, micropython.inspect.Class): self.new_op(AttrInstruction(unit.all_class_attributes()[name])) elif isinstance(unit, micropython.inspect.Module): @@ -269,7 +269,11 @@ self.new_op(DropFrame()) - def visitClass(self, node): pass + def visitClass(self, node): + unit = self.unit + self.unit = node.cls + self.dispatch(node.code) + self.unit = unit def visitCompare(self, node):