import ast def process(node): nextConditionLabel = "" postConditionLabel = ast.nextLabel() #emit if and if else conditions for condition in node.tests: if nextConditionLabel != "": ast.outputLabel( nextConditionLabel ) nextConditionLabel = ast.nextLabel() dest = ast.evaluate(condition[0]) ast.outputInBlock( "unless %s, %s" % ( dest, nextConditionLabel ) ) ast.evaluate( condition[1] ) ast.outputInBlock( "branch %s" % ( postConditionLabel ) ) #else case ast.outputLabel( nextConditionLabel ) if node.else_: ast.evaluate( node.else_ ) ast.outputLabel( postConditionLabel )