compiler/stmt.py
def _write_except_dispatcher(self, exc, tb, handlers):
    """Outputs a Go code that jumps to the appropriate except handler.

    Args:
      exc: Go variable holding the current exception.
      tb: Go variable holding the current exception's traceback.
      handlers: A list of ast.ExceptHandler nodes.

    Returns:
      A list of Go labels indexes corresponding to the exception handlers.

    Raises:
      ParseError: Except handlers are in an invalid order.
    """
    handler_labels = []
    for i, except_node in enumerate(handlers):
      handler_labels.append(self.block.genlabel())
      if except_node.type:
        with self.visit_expr(except_node.type) as type_,\
            self.block.alloc_temp('bool') as is_inst:
          self.writer.write_checked_call2(
              is_inst, 'πg.IsInstance(πF, {}.ToObject(), {})', exc, type_.expr)
          self.writer.write_tmpl(textwrap.dedent("""\
              if $is_inst {
              \tgoto Label$label
              }"""), is_inst=is_inst.expr, label=handler_labels[-1])
      else:
        # This is a bare except. It should be the last handler.
        if i != len(handlers) - 1:
          msg = "default 'except:' must be last"
          raise util.ParseError(except_node, msg)
        self.writer.write('goto Label{}'.format(handler_labels[-1]))
    if handlers[-1].type:
      # There's no bare except, so the fallback is to re-raise.
      self.writer.write(
          'πE = πF.Raise({}.ToObject(), nil, {}.ToObject())'.format(exc, tb))
      self.writer.write('continue')
    return handler_labels
def _write_except_dispatcher(self, exc, tb, handlers):
    """Outputs a Go code that jumps to the appropriate except handler.

    Args:
      exc: Go variable holding the current exception.
      tb: Go variable holding the current exception's traceback.
      handlers: A list of ast.ExceptHandler nodes.

    Returns:
      A list of Go labels indexes corresponding to the exception handlers.

    Raises:
      ParseError: Except handlers are in an invalid order.
    """
    handler_labels = []
    for i, except_node in enumerate(handlers):
      handler_labels.append(self.block.genlabel())
      if except_node.type:
        with self.visit_expr(except_node.type) as type_,\
            self.block.alloc_temp('bool') as is_inst:
          self.writer.write_checked_call2(
              is_inst, 'πg.IsInstance(πF, {}.ToObject(), {})', exc, type_.expr)
          self.writer.write_tmpl(textwrap.dedent("""\
              if $is_inst {
              \tgoto Label$label
              }"""), is_inst=is_inst.expr, label=handler_labels[-1])
      else:
        # This is a bare except. It should be the last handler.
        if i != len(handlers) - 1:
          msg = "default 'except:' must be last"
          raise util.ParseError(except_node, msg)
        self.writer.write('goto Label{}'.format(handler_labels[-1]))
    if handlers[-1].type:
      # There's no bare except, so the fallback is to re-raise.
      self.writer.write(
          'πE = πF.Raise({}.ToObject(), nil, {}.ToObject())'.format(exc, tb))
      self.writer.write('continue')
    return handler_labels
def _write_except_dispatcher ( self , exc , tb , handlers ) : handler_labels = [ ] for i , except_node in enumerate ( handlers ) : handler_labels . append ( self . block . genlabel ( ) ) if except_node . type : with self . visit_expr ( except_node . type ) as type_ , self . block . alloc_temp ( 'bool' ) as is_inst : self . writer . write_checked_call2 ( is_inst , 'πg.IsInstance(πF, {}.ToObject(), {})',  e c,  t pe_.e x pr) self . writer . write_tmpl ( textwrap . dedent ( """\
              if $is_inst {
              \tgoto Label$label
              }""" ) , is_inst = is_inst . expr , label = handler_labels [ - 1 ] ) else : # This is a bare except. It should be the last handler. if i != len ( handlers ) - 1 : msg = "default 'except:' must be last" raise util . ParseError ( except_node , msg ) self . writer . write ( 'goto Label{}' . format ( handler_labels [ - 1 ] ) ) if handlers [ - 1 ] . type : # There's no bare except, so the fallback is to re-raise. self . writer . write ( 'πE = πF.Raise({}.ToObject(), nil, {}.ToObject())'.f o rmat(e x c,  t )) self . writer . write ( 'continue' ) return handler_labels
Outputs a Go code that jumps to the appropriate except handler.

    Args:
      exc: Go variable holding the current exception.
      tb: Go variable holding the current exception's traceback.
      handlers: A list of ast.ExceptHandler nodes.

    Returns:
      A list of Go labels indexes corresponding to the exception handlers.

    Raises:
      ParseError: Except handlers are in an invalid order.
Outputs a Go code that jumps to the appropriate except handler .