def opgrouper(visitor, prefix='op_'): """ op_add, op_mul, ... -> op_binary """ handlers = mergedicts(unop_handlers(visitor.op_unary, prefix), binop_handlers(visitor.op_binary, prefix), compare_handlers(visitor.op_compare, prefix)) return combine(visitor, handlers)
def test_combinator(self): visitor = SampleVisitor() def op_blah(op): visitor.recorded.append(op.opcode) comb = combine(visitor, {'op_blah': op_blah}) with self.b.at_front(self.entry): self.b.emit(Op('blah', None, [])) visit(comb, self.f) self.eq(visitor.recorded, ['blah', 'mul'])
def test_combinator(self): visitor = SampleVisitor() def op_blah(op): visitor.recorded.append(op.opcode) comb = combine(visitor, {"op_blah": op_blah}) with self.b.at_front(self.entry): self.b.emit(Op("blah", None, [])) visit(comb, self.f) self.eq(visitor.recorded, ["blah", "mul"])
def verify_semantics(func, env=None): verifier = combine(Verifier(), env and env.get("verify.handlers")) visit(verifier, func)