1.1 --- a/rsvplib.py Sat Jun 05 01:39:16 2010 +0200
1.2 +++ b/rsvplib.py Fri Jun 11 00:56:08 2010 +0200
1.3 @@ -254,36 +254,19 @@
1.4 def builtins_list_new(self):
1.5 frame = self.local_sp_stack[-1]
1.6
1.7 - # The first parameter should be empty.
1.8 - # NOTE: Specific copying of tuples/lists.
1.9 + # The first parameter should be the instance.
1.10
1.11 - args_value = self.frame_stack[frame + 1]
1.12 + list_value = self.frame_stack[frame]
1.13
1.14 - # Test operand suitability.
1.15 + # Make a new sequence.
1.16 + # NOTE: Using an arbitrary size.
1.17
1.18 - if self.machine._CheckInstance(args_value.ref, self.list_class):
1.19 - sequence = self.machine.load(args_value.ref + 1)
1.20 - header = self.machine.load(sequence.ref)
1.21 - size = header.occupied_size
1.22 - elif self.machine._CheckInstance(args_value.ref, self.tuple_class):
1.23 - sequence = args_value.ref
1.24 - header = self.machine.load(sequence)
1.25 - size = header.size
1.26 - else:
1.27 - self.machine.exception = self.machine._MakeObject(2, self.type_error_instance)
1.28 - return self.machine.RaiseException()
1.29 + new_fragment = self.machine._MakeFragment(5)
1.30
1.31 - # Copy the sequence contents.
1.32 -
1.33 - new_fragment = self.machine._MakeFragment(size)
1.34 - for i in range(1, size):
1.35 - self.machine.save(new_fragment + i, self.machine.load(sequence + i))
1.36 + # Complete the list instance by saving the fragment reference.
1.37
1.38 - # Make the list instance.
1.39 -
1.40 - addr = self.machine._MakeObject(2, self.list_instance)
1.41 - self.machine.save(addr + 1, DataValue(None, new_fragment))
1.42 -
1.43 + addr = list_value.ref + 1
1.44 + self.machine.save(addr, DataValue(None, new_fragment))
1.45 self.machine.result = DataValue(addr, addr)
1.46
1.47 def builtins_list_getitem(self):
1.48 @@ -500,9 +483,9 @@
1.49 "__builtins__.object.__init__" : builtins_object_init, # NOTE: A no-operation.
1.50 "__builtins__.BaseException.__init__" : builtins_object_init, # NOTE: To be made distinct, potentially in the builtins module.
1.51
1.52 - # Native instantiators:
1.53 + # Native instantiator helpers:
1.54
1.55 - "__builtins__.list" : builtins_list_new,
1.56 + "__builtins__.list.__new__" : builtins_list_new,
1.57 }
1.58
1.59 # vim: tabstop=4 expandtab shiftwidth=4