javaclass

Change of bytecode.py

24:7121c7af1076
bytecode.py
     1.1 --- a/bytecode.py	Wed Nov 10 16:23:37 2004 +0100
     1.2 +++ b/bytecode.py	Wed Nov 10 16:50:43 2004 +0100
     1.3 @@ -203,7 +203,18 @@
     1.4          # NOTE: 8-bit limit.
     1.5          self.output[current_exception_start + 1] = target - current_exception_start - 3
     1.6          self.output[current_exception_start + 2] = 0
     1.7 -        # NOTE: The POP_BLOCK instruction gets slipped in before this method is called.
     1.8 +
     1.9 +    def start_handler(self, exc_name):
    1.10 +        # Where handlers are begun, produce bytecode to test the type of
    1.11 +        # the exception.
    1.12 +        self.dup_top()                      # Stack: exception, exception
    1.13 +        self.load_global(str(exc_name))     # Stack: exception, exception, handled-exception
    1.14 +        self.compare_op("exception match")  # Stack: exception, result
    1.15 +        self.jump_to_label(1, "handler")
    1.16 +        self.pop_top()
    1.17 +        self.end_finally()
    1.18 +        self.start_label("handler")
    1.19 +        self.pop_top()
    1.20  
    1.21      # Complicated methods.
    1.22  
    1.23 @@ -534,11 +545,8 @@
    1.24                  program.end_exception()
    1.25                  if exception.catch_type == 0:
    1.26                      self.in_finally = 1
    1.27 -
    1.28 -            # Where handlers are begun, do not produce equivalent bytecode since
    1.29 -            # the first handler instruction typically involves saving a local
    1.30 -            # variable that is not applicable to the Python VM.
    1.31 -            #if not exception_block_handler.get(self.java_position, []):
    1.32 +                else:
    1.33 +                    program.start_handler(self.class_file.constants[exception.catch_type - 1].get_python_name())
    1.34  
    1.35              # Process the bytecode at the current position.
    1.36              bytecode = ord(code[self.java_position])
    1.37 @@ -800,6 +808,8 @@
    1.38          print "(setup_finally %s)" % target
    1.39      def end_exception(self):
    1.40          print "(end_exception)"
    1.41 +    def start_handler(self, exc_name):
    1.42 +        print "(start_handler %s)" % exc_name
    1.43      def pop_block(self):
    1.44          print "(pop_block)"
    1.45