1.1 --- a/rsvp.py Sun May 17 00:58:27 2009 +0200
1.2 +++ b/rsvp.py Sun May 17 20:01:13 2009 +0200
1.3 @@ -123,6 +123,7 @@
1.4
1.5 self.attr_error = objlist.access("__builtins__", "AttributeError").get_value().location
1.6 self.type_error = objlist.access("__builtins__", "TypeError").get_value().location
1.7 + self.index_error = objlist.access("__builtins__", "IndexError").get_value().location
1.8
1.9 # Native class constants.
1.10
1.11 @@ -707,6 +708,37 @@
1.12 else:
1.13 self.result = self.false_constant, self.false_constant
1.14
1.15 + def builtins_int_neg(self):
1.16 + frame = self.local_sp_stack[-1]
1.17 +
1.18 + # Get operands addresses.
1.19 +
1.20 + left_context, left = self.frame_stack[frame]
1.21 +
1.22 + # Test operand suitability.
1.23 +
1.24 + if not self._CheckInstance(left, self.int_class_location):
1.25 + self.exception = self.type_error
1.26 + return self.RaiseException()
1.27 +
1.28 + # NOTE: Assume single location for data.
1.29 +
1.30 + left_data = left + 1
1.31 +
1.32 + # Make a new object.
1.33 +
1.34 + addr = self._MakeObject(2, self.int_instance_location)
1.35 +
1.36 + # Store the result.
1.37 + # NOTE: The data is considered ready to use.
1.38 +
1.39 + self.save(addr + 1, -self.load(left_data))
1.40 +
1.41 + # Return the new object.
1.42 + # Introduce object as context for the new object.
1.43 +
1.44 + self.result = addr, addr
1.45 +
1.46 def builtins_bool_bool(self):
1.47 frame = self.local_sp_stack[-1]
1.48
1.49 @@ -729,14 +761,40 @@
1.50
1.51 self.result = list, list
1.52
1.53 + def builtins_list_getitem(self):
1.54 + frame = self.local_sp_stack[-1]
1.55 +
1.56 + # Get operands addresses.
1.57 +
1.58 + obj_context, obj = self.frame_stack[frame]
1.59 + item_context, item = self.frame_stack[frame + 1]
1.60 +
1.61 + header = self.load(obj)
1.62 + nelements = header.size - 1
1.63 +
1.64 + # NOTE: Assume single location for data.
1.65 +
1.66 + item_pos = self.load(item + 1)
1.67 + if item_pos >= 0 and item_pos < nelements:
1.68 + pass
1.69 + elif item_pos < 0 and item_pos >= -nelements:
1.70 + item_pos = nelements + item_pos
1.71 + else:
1.72 + self.exception = self.index_error
1.73 + return self.RaiseException()
1.74 +
1.75 + self.result = self.load(obj + 1 + item_pos)
1.76 +
1.77 def builtins_object_init(self):
1.78 pass
1.79
1.80 native_functions = {
1.81 "__builtins__.int.__add__" : builtins_int_add,
1.82 "__builtins__.int.__bool__" : builtins_int_bool,
1.83 + "__builtins__.int.__neg__" : builtins_int_neg,
1.84 "__builtins__.bool.__bool__" : builtins_bool_bool,
1.85 "__builtins__.list" : builtins_list_new,
1.86 + "__builtins__.list.__getitem__" : builtins_list_getitem,
1.87 "__builtins__.object.__init__" : builtins_object_init,
1.88 }
1.89