# HG changeset patch # User Paul Boddie # Date 1100389494 -3600 # Node ID 576596f6971b018c0ca0db5e9c1f67ed9044923c # Parent 8e2ad0f8b10fc77e5cc7f0dfe7d096555d6ae3bb Added DUP_TOPX and SLICE+0 translations. Fixed array construction and added an implementation for multianewarray. diff -r 8e2ad0f8b10f -r 576596f6971b bytecode.py --- a/bytecode.py Sat Nov 13 23:18:10 2004 +0100 +++ b/bytecode.py Sun Nov 14 00:44:54 2004 +0100 @@ -347,6 +347,12 @@ self.position += 1 self.update_stack_depth(1) + def dup_topx(self, count): + self.output.append(opmap["DUP_TOPX"]) + self.position += 1 + self._write_value(count) + self.update_stack_depth(count) + def rot_two(self): self.output.append(opmap["ROT_TWO"]) self.position += 1 @@ -429,6 +435,10 @@ self.output.append(opmap["UNARY_NEGATIVE"]) self.position += 1 + def slice_0(self): + self.output.append(opmap["SLICE+0"]) + self.position += 1 + def slice_1(self): self.output.append(opmap["SLICE+1"]) self.position += 1 @@ -900,7 +910,7 @@ self._newarray(program) def _newarray(self, program): - program.build_list() # Stack: count, list + program.build_list(0) # Stack: count, list program.rot_two() # Stack: list, count program.setup_loop() program.load_global("range") @@ -1576,8 +1586,39 @@ pass def multianewarray(self, arguments, program): - # NOTE: To be implemented. - pass + index = (arguments[0] << 8) + arguments[1] + dimensions = arguments[2] + # Stack: count1, ..., countN-1, countN + self._newarray(program) # Stack: count1, ..., countN-1, list + for dimension in range(1, dimensions): + program.rot_two() # Stack: count1, ..., list, countN-1 + program.build_list(0) # Stack: count1, ..., list, countN-1, new-list + program.rot_three() # Stack: count1, ..., new-list, list, countN-1 + program.setup_loop() + program.load_const(0) # Stack: count1, ..., new-list, list, countN-1, 0 + program.rot_two() # Stack: count1, ..., new-list, list, 0, countN-1 + program.load_global("range") # Stack: count1, ..., new-list, list, 0, countN-1, range + program.rot_three() # Stack: count1, ..., new-list, list, range, 0, countN-1 + program.call_function(2) # Stack: count1, ..., new-list, list, range-list + program.get_iter() # Stack: count1, ..., new-list, list, iter + program.for_iter() # Stack: count1, ..., new-list, list, iter, value + program.pop_top() # Stack: count1, ..., new-list, list, iter + program.rot_three() # Stack: count1, ..., iter, new-list, list + program.slice_0() # Stack: count1, ..., iter, new-list, list[:] + program.dup_top() # Stack: count1, ..., iter, new-list, list[:], list[:] + program.rot_three() # Stack: count1, ..., iter, list[:], new-list, list[:] + program.rot_two() # Stack: count1, ..., iter, list[:], list[:], new-list + program.dup_top() # Stack: count1, ..., iter, list[:], list[:], new-list, new-list + program.load_attr("append") # Stack: count1, ..., iter, list[:], list[:], new-list, append + program.rot_three() # Stack: count1, ..., iter, list[:], append, list[:], new-list + program.rot_three() # Stack: count1, ..., iter, list[:], new-list, append, list[:] + program.call_function(1) # Stack: count1, ..., iter, list[:], new-list, None + program.pop_top() # Stack: count1, ..., iter, list[:], new-list + program.rot_two() # Stack: count1, ..., iter, new-list, list[:] + program.rot_three() # Stack: count1, ..., list[:], iter, new-list + program.rot_three() # Stack: count1, ..., new-list, list[:], iter + program.end_loop() # Stack: count1, ..., new-list, list[:], iter + program.pop_top() # Stack: count1, ..., new-list def new(self, arguments, program): # This operation is considered to be the same as the calling of the