1.1 --- a/lib/builtins.py Sun May 17 00:58:27 2009 +0200
1.2 +++ b/lib/builtins.py Sun May 17 20:01:13 2009 +0200
1.3 @@ -228,12 +228,11 @@
1.4 class FloatingPointError(Exception): pass
1.5 class FutureWarning(Warning): pass
1.6 class GeneratorExit(Exception): pass
1.7 -class IndexError(Exception): pass
1.8 -class IOError(Exception): pass
1.9 class ImportError(Exception): pass
1.10 class ImportWarning(Warning): pass
1.11 class IndentationError(Exception): pass
1.12 class IndexError(Exception): pass
1.13 +class IOError(Exception): pass
1.14 class KeyError(Exception): pass
1.15 class KeyboardInterrupt(Exception): pass
1.16 class LookupError(Exception): pass
1.17 @@ -336,6 +335,7 @@
1.18 AttributeError
1.19 StopIteration
1.20 TypeError
1.21 +IndexError
1.22
1.23 list
1.24 tuple
2.1 --- a/micropython/ast.py Sun May 17 00:58:27 2009 +0200
2.2 +++ b/micropython/ast.py Sun May 17 20:01:13 2009 +0200
2.3 @@ -441,7 +441,13 @@
2.4
2.5 def visitSlice(self, node): raise TranslationNotImplementedError(self.module.full_name(), node, "Slice")
2.6
2.7 - def visitSubscript(self, node): raise TranslationNotImplementedError(self.module.full_name(), node, "Subscript")
2.8 + def visitSubscript(self, node):
2.9 + self.dispatch(node.expr)
2.10 + self._startCallFunc()
2.11 + self._generateAttr(node, "__getitem__", self.attribute_load_instructions)
2.12 + temp, target = self._generateCallFunc(node.subs, node)
2.13 + self._doCallFunc(temp, target)
2.14 + self._endCallFunc(temp, target)
2.15
2.16 def visitTuple(self, node):
2.17 self._generateSequence("tuple", node)
3.1 --- a/micropython/inspect.py Sun May 17 00:58:27 2009 +0200
3.2 +++ b/micropython/inspect.py Sun May 17 20:01:13 2009 +0200
3.3 @@ -745,7 +745,9 @@
3.4
3.5 visitSub = _visitBinary
3.6
3.7 - visitSubscript = OP
3.8 + def visitSubscript(self, node):
3.9 + self.importer.use_name("__getitem__")
3.10 + self.OP(node)
3.11
3.12 def visitTryExcept(self, node):
3.13 self.dispatch(node.body)
4.1 --- a/micropython/trans.py Sun May 17 00:58:27 2009 +0200
4.2 +++ b/micropython/trans.py Sun May 17 20:01:13 2009 +0200
4.3 @@ -924,11 +924,11 @@
4.4 self._endCallFuncArgs(1)
4.5 self._doCallFunc(temp_method)
4.6 self._endCallFunc(temp_method)
4.7 - self.new_op(Jump(end_block))
4.8
4.9 # Store the result.
4.10
4.11 temp_out = self.get_temp()
4.12 + self.new_op(Jump(end_block))
4.13
4.14 # Raise a TypeError.
4.15
5.1 --- a/rsvp.py Sun May 17 00:58:27 2009 +0200
5.2 +++ b/rsvp.py Sun May 17 20:01:13 2009 +0200
5.3 @@ -123,6 +123,7 @@
5.4
5.5 self.attr_error = objlist.access("__builtins__", "AttributeError").get_value().location
5.6 self.type_error = objlist.access("__builtins__", "TypeError").get_value().location
5.7 + self.index_error = objlist.access("__builtins__", "IndexError").get_value().location
5.8
5.9 # Native class constants.
5.10
5.11 @@ -707,6 +708,37 @@
5.12 else:
5.13 self.result = self.false_constant, self.false_constant
5.14
5.15 + def builtins_int_neg(self):
5.16 + frame = self.local_sp_stack[-1]
5.17 +
5.18 + # Get operands addresses.
5.19 +
5.20 + left_context, left = self.frame_stack[frame]
5.21 +
5.22 + # Test operand suitability.
5.23 +
5.24 + if not self._CheckInstance(left, self.int_class_location):
5.25 + self.exception = self.type_error
5.26 + return self.RaiseException()
5.27 +
5.28 + # NOTE: Assume single location for data.
5.29 +
5.30 + left_data = left + 1
5.31 +
5.32 + # Make a new object.
5.33 +
5.34 + addr = self._MakeObject(2, self.int_instance_location)
5.35 +
5.36 + # Store the result.
5.37 + # NOTE: The data is considered ready to use.
5.38 +
5.39 + self.save(addr + 1, -self.load(left_data))
5.40 +
5.41 + # Return the new object.
5.42 + # Introduce object as context for the new object.
5.43 +
5.44 + self.result = addr, addr
5.45 +
5.46 def builtins_bool_bool(self):
5.47 frame = self.local_sp_stack[-1]
5.48
5.49 @@ -729,14 +761,40 @@
5.50
5.51 self.result = list, list
5.52
5.53 + def builtins_list_getitem(self):
5.54 + frame = self.local_sp_stack[-1]
5.55 +
5.56 + # Get operands addresses.
5.57 +
5.58 + obj_context, obj = self.frame_stack[frame]
5.59 + item_context, item = self.frame_stack[frame + 1]
5.60 +
5.61 + header = self.load(obj)
5.62 + nelements = header.size - 1
5.63 +
5.64 + # NOTE: Assume single location for data.
5.65 +
5.66 + item_pos = self.load(item + 1)
5.67 + if item_pos >= 0 and item_pos < nelements:
5.68 + pass
5.69 + elif item_pos < 0 and item_pos >= -nelements:
5.70 + item_pos = nelements + item_pos
5.71 + else:
5.72 + self.exception = self.index_error
5.73 + return self.RaiseException()
5.74 +
5.75 + self.result = self.load(obj + 1 + item_pos)
5.76 +
5.77 def builtins_object_init(self):
5.78 pass
5.79
5.80 native_functions = {
5.81 "__builtins__.int.__add__" : builtins_int_add,
5.82 "__builtins__.int.__bool__" : builtins_int_bool,
5.83 + "__builtins__.int.__neg__" : builtins_int_neg,
5.84 "__builtins__.bool.__bool__" : builtins_bool_bool,
5.85 "__builtins__.list" : builtins_list_new,
5.86 + "__builtins__.list.__getitem__" : builtins_list_getitem,
5.87 "__builtins__.object.__init__" : builtins_object_init,
5.88 }
5.89
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/tests/call_func_star_parameter_unpack.py Sun May 17 20:01:13 2009 +0200
6.3 @@ -0,0 +1,9 @@
6.4 +#!/usr/bin/env python
6.5 +
6.6 +def f(*args):
6.7 + a, b, c = args
6.8 + return c
6.9 +
6.10 +x = f(1, 2, 3)
6.11 +
6.12 +# vim: tabstop=4 expandtab shiftwidth=4
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/tests/subscripts.py Sun May 17 20:01:13 2009 +0200
7.3 @@ -0,0 +1,8 @@
7.4 +#!/usr/bin/env python
7.5 +
7.6 +l = [1, 2, 3]
7.7 +x = l[0]
7.8 +y = l[1]
7.9 +z = l[-1]
7.10 +
7.11 +# vim: tabstop=4 expandtab shiftwidth=4