1.1 --- a/micropython/ast.py Sat Mar 22 22:31:54 2008 +0100
1.2 +++ b/micropython/ast.py Mon Mar 24 23:53:18 2008 +0100
1.3 @@ -48,7 +48,7 @@
1.4
1.5 "A translated module."
1.6
1.7 - def __init__(self, module, objtable, paramtable):
1.8 + def __init__(self, module, objtable, paramtable, builtins=None):
1.9
1.10 """
1.11 Initialise the translation with an inspected 'module' and an attribute
1.12 @@ -60,6 +60,10 @@
1.13 self.module = module
1.14 self.objtable = objtable
1.15 self.paramtable = paramtable
1.16 + self.builtins = builtins
1.17 +
1.18 + # The current unit being translated.
1.19 +
1.20 self.unit = None
1.21
1.22 # Wiring within the code.
1.23 @@ -410,21 +414,23 @@
1.24 elif isinstance(unit, micropython.inspect.Module):
1.25 self.new_op(AttrInstruction(unit.module_attributes()[name]))
1.26 else:
1.27 - raise TranslateError(self.module.full_name(), node, "Program unit %r has no local %r" % (unit, name))
1.28 + raise TranslateError(self.module.full_name(), node, "Program unit %r has no local %r." % (unit, name))
1.29
1.30 elif scope == "global":
1.31 globals = self.module.module_attributes()
1.32 if globals.has_key(name):
1.33 self.new_op(AttrInstruction(globals[name]))
1.34 else:
1.35 - raise TranslateError(self.module.full_name(), node, "Module %r has no attribute %r" % (self.module, name))
1.36 + raise TranslateError(self.module.full_name(), node, "Module %r has no attribute %r." % (self.module, name))
1.37
1.38 else:
1.39 - self.new_op(AttrInstruction(self._get_builtin(name)))
1.40 + self.new_op(AttrInstruction(self._get_builtin(name, node)))
1.41
1.42 - def _get_builtin(self, name):
1.43 - builtins = micropython.inspect.builtins.module_attributes()
1.44 - return builtins[name]
1.45 + def _get_builtin(self, name, node):
1.46 + if self.builtins is not None:
1.47 + return self.builtins[name]
1.48 + else:
1.49 + raise TranslateError(self.module.full_name(), node, "No __builtins__ module is available for name %r." % name)
1.50
1.51 # Optimisation methods.
1.52
1.53 @@ -460,11 +466,9 @@
1.54 context = last.attr.parent
1.55
1.56 # Handle calls to classes.
1.57 - # NOTE: That the actual invocation target will be a __new__ method
1.58 - # NOTE: which calls the __init__ method, returning the new instance.
1.59
1.60 if isinstance(target, micropython.inspect.Class):
1.61 - target = self.objtable.table[target.full_name()]["__init__"].value
1.62 + target = target.get_instantiator()
1.63 context = micropython.inspect.Instance()
1.64
1.65 # A special context is chosen to avoid generating unnecessary