javaclass

Change of bytecode.py

39:e64b08b9681f
bytecode.py
     1.1 --- a/bytecode.py	Fri Nov 12 01:32:28 2004 +0100
     1.2 +++ b/bytecode.py	Sat Nov 13 19:19:46 2004 +0100
     1.3 @@ -64,6 +64,7 @@
     1.4                  value = element.value
     1.5              else:
     1.6                  value = element
     1.7 +            # NOTE: ValueError gets raised for bad values here.
     1.8              output.append(chr(value))
     1.9          return "".join(output)
    1.10  
    1.11 @@ -122,6 +123,15 @@
    1.12              # NOTE: EXTENDED_ARG not yet supported.
    1.13              raise ValueError, value
    1.14  
    1.15 +    def _rewrite_value(self, position, value):
    1.16 +        # NOTE: Assume a 16-bit value.
    1.17 +        if value <= 0xffff:
    1.18 +            self.output[position] = (value & 0xff)
    1.19 +            self.output[position + 1] = ((value & 0xff00) >> 8)
    1.20 +        else:
    1.21 +            # NOTE: EXTENDED_ARG not yet supported.
    1.22 +            raise ValueError, value
    1.23 +
    1.24      def setup_loop(self):
    1.25          self.loops.append(self.position)
    1.26          self.output.append(opmap["SETUP_LOOP"])
    1.27 @@ -134,16 +144,12 @@
    1.28          #print "<", self.blocks, current_loop_real_start
    1.29          # Fix the iterator delta.
    1.30          # NOTE: Using 3 as the assumed length of the FOR_ITER instruction.
    1.31 -        # NOTE: 8-bit limit.
    1.32          self.jump_absolute(current_loop_real_start)
    1.33 -        self.output[current_loop_real_start + 1] = self.position - current_loop_real_start - 3
    1.34 -        self.output[current_loop_real_start + 2] = 0
    1.35 +        self._rewrite_value(current_loop_real_start + 1, self.position - current_loop_real_start - 3)
    1.36          self.pop_block()
    1.37          # Fix the loop delta.
    1.38          # NOTE: Using 3 as the assumed length of the SETUP_LOOP instruction.
    1.39 -        # NOTE: 8-bit limit.
    1.40 -        self.output[current_loop_start + 1] = self.position - current_loop_start - 3
    1.41 -        self.output[current_loop_start + 2] = 0
    1.42 +        self._rewrite_value(current_loop_start + 1, self.position - current_loop_start - 3)
    1.43  
    1.44      def jump_to_label(self, status, name):
    1.45          # Record the instruction using the jump.
    1.46 @@ -162,9 +168,7 @@
    1.47      def start_label(self, name):
    1.48          # Fill in all jump instructions.
    1.49          for jump_instruction, following_instruction in self.jumps[name]:
    1.50 -            # NOTE: 8-bit limit.
    1.51 -            self.output[jump_instruction + 1] = self.position - following_instruction
    1.52 -            self.output[jump_instruction + 2] = 0
    1.53 +            self._rewrite_value(jump_instruction + 1, self.position - following_instruction)
    1.54          del self.jumps[name]
    1.55  
    1.56      def load_const_ret(self, value):
    1.57 @@ -213,9 +217,7 @@
    1.58          target = current_exception_target.get_value()
    1.59          #print "*", current_exception_start, target
    1.60          # NOTE: Using 3 as the assumed length of the SETUP_* instruction.
    1.61 -        # NOTE: 8-bit limit.
    1.62 -        self.output[current_exception_start + 1] = target - current_exception_start - 3
    1.63 -        self.output[current_exception_start + 2] = 0
    1.64 +        self._rewrite_value(current_exception_start + 1, target - current_exception_start - 3)
    1.65  
    1.66      def start_handler(self, exc_name):
    1.67          # Where handlers are begun, produce bytecode to test the type of
    1.68 @@ -534,6 +536,8 @@
    1.69          self.method = method
    1.70  
    1.71          # NOTE: Not guaranteed.
    1.72 +        if len(method.attributes) == 0:
    1.73 +            return
    1.74          attribute = method.attributes[0]
    1.75          code, exception_table = attribute.code, attribute.exception_table
    1.76