1.1 --- a/lib/builtins.py Mon Jun 01 21:10:47 2009 +0200
1.2 +++ b/lib/builtins.py Mon Jun 01 23:06:55 2009 +0200
1.3 @@ -214,7 +214,8 @@
1.4 # Exceptions and warnings.
1.5
1.6 class BaseException(object):
1.7 - def __init__(self, *args): pass
1.8 + def __init__(self, *args):
1.9 + self.args = args
1.10
1.11 class Exception(BaseException): pass
1.12 class Warning(object): pass
2.1 --- a/micropython/ast.py Mon Jun 01 21:10:47 2009 +0200
2.2 +++ b/micropython/ast.py Mon Jun 01 23:06:55 2009 +0200
2.3 @@ -86,6 +86,7 @@
2.4 self.label_number = 0
2.5 self.loop_blocks = []
2.6 self.exception_blocks = []
2.7 + self.in_exception_handler = 0
2.8
2.9 self.reset()
2.10
2.11 @@ -906,6 +907,10 @@
2.12 self.dispatch(compiler.ast.Name("None"))
2.13
2.14 self.new_op(StoreResult())
2.15 +
2.16 + if self.in_exception_handler:
2.17 + self.new_op(ClearException())
2.18 +
2.19 self.new_op(Return())
2.20
2.21 def visitTryExcept(self, node):
2.22 @@ -956,7 +961,10 @@
2.23
2.24 # Produce the handler code, then jump to the exit.
2.25
2.26 + self.in_exception_handler = 1
2.27 self.dispatch(handler)
2.28 + self.in_exception_handler = 0
2.29 +
2.30 self.new_op(Jump(exit_block))
2.31
2.32 self.set_block(next_block)
2.33 @@ -969,7 +977,6 @@
2.34
2.35 if node.else_ is not None:
2.36 self.set_block(else_block)
2.37 -
2.38 self.dispatch(node.else_)
2.39
2.40 # Clear the exception.
3.1 --- a/micropython/data.py Mon Jun 01 21:10:47 2009 +0200
3.2 +++ b/micropython/data.py Mon Jun 01 23:06:55 2009 +0200
3.3 @@ -274,11 +274,14 @@
3.4 # Number of assignments per name.
3.5
3.6 self.assignments = None
3.7 + self.referenced = 0
3.8
3.9 def set_referenced(self):
3.10
3.11 "Indicate that the contents are referenced via a namespace."
3.12
3.13 + self.referenced = 1
3.14 +
3.15 for value in self.get_values():
3.16 if value is not None:
3.17 value.set_referenced()
3.18 @@ -317,6 +320,13 @@
3.19 else:
3.20 self.assignments += AtLeast(1)
3.21
3.22 + # Communicate referencing information.
3.23 +
3.24 + if self.referenced:
3.25 + for context, value in context_values:
3.26 + if value is not None:
3.27 + value.set_referenced()
3.28 +
3.29 self.context_values.update(context_values)
3.30
3.31 def is_class_attribute(self):
3.32 @@ -787,6 +797,8 @@
3.33
3.34 if instattr.has_key(name):
3.35 instattr[name].add(attr.position)
3.36 + else:
3.37 + instattr[name] = set([attr.position])
3.38
3.39 # Build the dictionary of attributes using the existing positions known
3.40 # for each name.
4.1 --- a/micropython/inspect.py Mon Jun 01 21:10:47 2009 +0200
4.2 +++ b/micropython/inspect.py Mon Jun 01 23:06:55 2009 +0200
4.3 @@ -114,6 +114,7 @@
4.4 self.in_loop = 0 # Note loop "membership", affecting assignments.
4.5 self.namespaces = []
4.6 self.module = None
4.7 + self.functions = []
4.8
4.9 def parse(self, filename):
4.10
4.11 @@ -128,11 +129,16 @@
4.12
4.13 self.astnode = self.module = module
4.14 processed = self.dispatch(module)
4.15 +
4.16 + for node, namespaces in self.functions:
4.17 + self._visitFunctionBody(node, namespaces)
4.18 +
4.19 if self.has_key("__all__"):
4.20 all = self["__all__"]
4.21 if isinstance(all, compiler.ast.List):
4.22 for n in all.nodes:
4.23 self.store(n.value, self.importer.add_module(self.name + "." + n.value))
4.24 +
4.25 return processed
4.26
4.27 def vacuum(self):
4.28 @@ -346,22 +352,7 @@
4.29 self.expr = self.dispatch(n)
4.30 function.store_default(self.expr)
4.31
4.32 - # Enter the function.
4.33 -
4.34 - self.namespaces.append(function)
4.35 -
4.36 - # Current namespace is the function.
4.37 - # Previous namespace is the class.
4.38 -
4.39 - if len(self.namespaces) > 1 and isinstance(self.namespaces[-2], Class):
4.40 - if name == "__init__":
4.41 - self.in_init = 1
4.42 - self.in_method = 1
4.43 -
4.44 - self.dispatch(node.code)
4.45 - self.in_init = 0
4.46 - self.in_method = 0
4.47 - self.namespaces.pop()
4.48 + self.functions.append((node, self.namespaces + [function]))
4.49
4.50 if name is not None:
4.51 self.store(name, function)
4.52 @@ -383,6 +374,24 @@
4.53
4.54 return function
4.55
4.56 + def _visitFunctionBody(self, node, namespaces):
4.57 +
4.58 + "Enter the function."
4.59 +
4.60 + # Current namespace is the function.
4.61 + # Previous namespace is the class.
4.62 +
4.63 + if len(namespaces) > 1 and isinstance(namespaces[-2], Class):
4.64 + if namespaces[-1].name == "__init__":
4.65 + self.in_init = 1
4.66 + self.in_method = 1
4.67 +
4.68 + self.namespaces = namespaces
4.69 + self.dispatch(node.code)
4.70 +
4.71 + self.in_init = 0
4.72 + self.in_method = 0
4.73 +
4.74 # Specific handler methods.
4.75
4.76 visitAdd = _visitBinary
5.1 --- a/rsvp.py Mon Jun 01 21:10:47 2009 +0200
5.2 +++ b/rsvp.py Mon Jun 01 23:06:55 2009 +0200
5.3 @@ -925,6 +925,7 @@
5.4 "__builtins__.list" : builtins_list_new,
5.5 "__builtins__.list.__getitem__" : builtins_list_getitem,
5.6 "__builtins__.object.__init__" : builtins_object_init,
5.7 + "__builtins__.BaseException.__init__" : builtins_object_init, # NOTE: To be made distinct.
5.8 }
5.9
5.10 # Convenience functions.
6.1 --- a/tests/exception.py Mon Jun 01 21:10:47 2009 +0200
6.2 +++ b/tests/exception.py Mon Jun 01 23:06:55 2009 +0200
6.3 @@ -1,6 +1,6 @@
6.4 #!/usr/bin/env python
6.5
6.6 -class E:
6.7 +class E(Exception):
6.8 pass
6.9
6.10 def f(x, y):
6.11 @@ -13,6 +13,6 @@
6.12 def g(x):
6.13 raise E, x
6.14
6.15 -f(1, 2)
6.16 +result_2 = f(1, 2)
6.17
6.18 # vim: tabstop=4 expandtab shiftwidth=4