import ast def process(node): exceptionHandlerLabel = "_" + ast.nextLabel() + "_handler" afterExceptionHandler = ast.nextLabel(); ast.outputInBlock("push_eh %s" % ( exceptionHandlerLabel ) ) ast.evaluate( node.body ) ast.outputInBlock("clear_eh" ) ast.outputInBlock("branch %s" % ( afterExceptionHandler ) ) ast.outputLabel( exceptionHandlerLabel ) for x in node.handlers: #print x[0] #print x[1] ast.evaluate( x[2] ) ast.outputLabel( afterExceptionHandler ) if ( node.else_ ): ast.evaluate( node.else_ )