def test_funny_links(): from rpython.flowspace.model import Block, FunctionGraph, \ Variable, Constant, Link from rpython.flowspace.operation import op for i in range(2): v_i = Variable("i") block = Block([v_i]) g = FunctionGraph("is_one", block) op1 = op.eq(v_i, Constant(1)) block.operations.append(op1) block.exitswitch = op1.result tlink = Link([Constant(1)], g.returnblock, True) flink = Link([Constant(0)], g.returnblock, False) links = [tlink, flink] if i: links.reverse() block.closeblock(*links) t = TranslationContext() a = t.buildannotator() a.build_graph_types(g, [annmodel.SomeInteger()]) rtyper = t.buildrtyper() rtyper.specialize() interp = LLInterpreter(rtyper) assert interp.eval_graph(g, [1]) == 1 assert interp.eval_graph(g, [0]) == 0
def unpack_sequence(self, w_iterable, expected_length): w_len = op.len(w_iterable).eval(self) w_correct = op.eq(w_len, const(expected_length)).eval(self) if not self.guessbool(op.bool(w_correct).eval(self)): w_exc = self.exc_from_raise(const(ValueError), const(None)) raise Raise(w_exc) return [op.getitem(w_iterable, const(i)).eval(self) for i in range(expected_length)]
def cmp_eq(self, w_1, w_2): return op.eq(w_1, w_2).eval(self)