javaclass

Change of bytecode.py

47:576596f6971b
bytecode.py
     1.1 --- a/bytecode.py	Sat Nov 13 23:18:10 2004 +0100
     1.2 +++ b/bytecode.py	Sun Nov 14 00:44:54 2004 +0100
     1.3 @@ -347,6 +347,12 @@
     1.4          self.position += 1
     1.5          self.update_stack_depth(1)
     1.6  
     1.7 +    def dup_topx(self, count):
     1.8 +        self.output.append(opmap["DUP_TOPX"])
     1.9 +        self.position += 1
    1.10 +        self._write_value(count)
    1.11 +        self.update_stack_depth(count)
    1.12 +
    1.13      def rot_two(self):
    1.14          self.output.append(opmap["ROT_TWO"])
    1.15          self.position += 1
    1.16 @@ -429,6 +435,10 @@
    1.17          self.output.append(opmap["UNARY_NEGATIVE"])
    1.18          self.position += 1
    1.19  
    1.20 +    def slice_0(self):
    1.21 +        self.output.append(opmap["SLICE+0"])
    1.22 +        self.position += 1
    1.23 +
    1.24      def slice_1(self):
    1.25          self.output.append(opmap["SLICE+1"])
    1.26          self.position += 1
    1.27 @@ -900,7 +910,7 @@
    1.28          self._newarray(program)
    1.29  
    1.30      def _newarray(self, program):
    1.31 -        program.build_list()        # Stack: count, list
    1.32 +        program.build_list(0)       # Stack: count, list
    1.33          program.rot_two()           # Stack: list, count
    1.34          program.setup_loop()
    1.35          program.load_global("range")
    1.36 @@ -1576,8 +1586,39 @@
    1.37          pass
    1.38  
    1.39      def multianewarray(self, arguments, program):
    1.40 -        # NOTE: To be implemented.
    1.41 -        pass
    1.42 +        index = (arguments[0] << 8) + arguments[1]
    1.43 +        dimensions = arguments[2]
    1.44 +        # Stack: count1, ..., countN-1, countN
    1.45 +        self._newarray(program)             # Stack: count1, ..., countN-1, list
    1.46 +        for dimension in range(1, dimensions):
    1.47 +            program.rot_two()               # Stack: count1, ..., list, countN-1
    1.48 +            program.build_list(0)           # Stack: count1, ..., list, countN-1, new-list
    1.49 +            program.rot_three()             # Stack: count1, ..., new-list, list, countN-1
    1.50 +            program.setup_loop()
    1.51 +            program.load_const(0)           # Stack: count1, ..., new-list, list, countN-1, 0
    1.52 +            program.rot_two()               # Stack: count1, ..., new-list, list, 0, countN-1
    1.53 +            program.load_global("range")    # Stack: count1, ..., new-list, list, 0, countN-1, range
    1.54 +            program.rot_three()             # Stack: count1, ..., new-list, list, range, 0, countN-1
    1.55 +            program.call_function(2)        # Stack: count1, ..., new-list, list, range-list
    1.56 +            program.get_iter()              # Stack: count1, ..., new-list, list, iter
    1.57 +            program.for_iter()              # Stack: count1, ..., new-list, list, iter, value
    1.58 +            program.pop_top()               # Stack: count1, ..., new-list, list, iter
    1.59 +            program.rot_three()             # Stack: count1, ..., iter, new-list, list
    1.60 +            program.slice_0()               # Stack: count1, ..., iter, new-list, list[:]
    1.61 +            program.dup_top()               # Stack: count1, ..., iter, new-list, list[:], list[:]
    1.62 +            program.rot_three()             # Stack: count1, ..., iter, list[:], new-list, list[:]
    1.63 +            program.rot_two()               # Stack: count1, ..., iter, list[:], list[:], new-list
    1.64 +            program.dup_top()               # Stack: count1, ..., iter, list[:], list[:], new-list, new-list
    1.65 +            program.load_attr("append")     # Stack: count1, ..., iter, list[:], list[:], new-list, append
    1.66 +            program.rot_three()             # Stack: count1, ..., iter, list[:], append, list[:], new-list
    1.67 +            program.rot_three()             # Stack: count1, ..., iter, list[:], new-list, append, list[:]
    1.68 +            program.call_function(1)        # Stack: count1, ..., iter, list[:], new-list, None
    1.69 +            program.pop_top()               # Stack: count1, ..., iter, list[:], new-list
    1.70 +            program.rot_two()               # Stack: count1, ..., iter, new-list, list[:]
    1.71 +            program.rot_three()             # Stack: count1, ..., list[:], iter, new-list
    1.72 +            program.rot_three()             # Stack: count1, ..., new-list, list[:], iter
    1.73 +            program.end_loop()              # Stack: count1, ..., new-list, list[:], iter
    1.74 +            program.pop_top()               # Stack: count1, ..., new-list
    1.75  
    1.76      def new(self, arguments, program):
    1.77          # This operation is considered to be the same as the calling of the