def test_intcheck(self): a = MyPPCAssembler() a.lwz(r5, r4, pystructs.PyVarObject.ob_size) a.cmpwi(r5, 1) a.bne("not_one") a.lwz(r5, r4, pystructs.PyTupleObject.ob_item + 0*4) a.lwz(r5, r5, 4) a.load_word(r6, lookup("PyInt_Type")) a.cmpw(r5, r6) a.bne("not_int") a.li(r3, 1) a.b("exit") a.label("not_int") a.li(r3, 0) a.b("exit") a.label("not_one") a.li(r3, 2) a.label("exit") a.load_word(r5, lookup("PyInt_FromLong")) a.mtctr(r5) a.bctr() f = a.assemble() assert f() == 2 assert f("", "") == 2 assert f("") == 0 assert f(1) == 1
def test_less_simple(self): a = MyPPCAssembler() s = lookup("PyNumber_Add") a.load_word(r5, s) a.mtctr(r5) a.bctr() f = make_func(a, "O", "OO") raises(TypeError, f) raises(TypeError, f, 1) assert f(1, 2) == 3 raises(TypeError, f, 1, 2, 3)
def test_makestring(self): a = MyPPCAssembler() a.li(r3, 0) a.li(r4, 0) a.load_word(r5, lookup("PyString_FromStringAndSize")) a.mtctr(r5) a.bctr() f = a.assemble() assert f() == ''
def test_less_simple(self): a = MyPPCAssembler() s = lookup("PyNumber_Add") a.load_word(r5, s) a.mtctr(r5) a.bctr() f = make_func(a, "O", "OO") raises(TypeError, f) raises(TypeError, f, 1) assert f(1, 2) == 3 raises(TypeError, f, 1, 2, 3)
def test_tuplelength(self): a = MyPPCAssembler() a.lwz(3, 4, pystructs.PyVarObject.ob_size) a.load_word(5, lookup("PyInt_FromLong")) a.mtctr(5) a.bctr() f = a.assemble() assert f() == 0 assert f(1) == 1 assert f('') == 1
def test_fast_entry(self): a = MyPPCAssembler() a.blr() f = make_func(a, "O", "O") assert f(1) == 1 b = MyPPCAssembler() from pypy.jit.codegen.ppc.ppcgen import util # eurgh!: b.load_word(r0, util.access_at(id(f.code), 8) + f.FAST_ENTRY_LABEL) b.mtctr(r0) b.bctr() g = make_func(b, "O", "O") assert g(1) == 1
def test_fast_entry(self): a = MyPPCAssembler() a.blr() f = make_func(a, "O", "O") assert f(1) == 1 b = MyPPCAssembler() from pypy.jit.codegen.ppc.ppcgen import util # eurgh!: b.load_word(r0, util.access_at(id(f.code), 8) + f.FAST_ENTRY_LABEL) b.mtctr(r0) b.bctr() g = make_func(b, "O", "O") assert g(1) == 1
def test_signature2(self): a = MyPPCAssembler() a.add(r3, r3, r4) a.add(r3, r3, r5) a.add(r3, r3, r6) a.add(r3, r3, r7) s = lookup("PyInt_FromLong") a.load_word(r0, s) a.mtctr(r0) a.bctr() f = make_func(a, "O", "iiiii") raises(TypeError, f) raises(TypeError, f, 1) assert f(1, 2, 3, 4, 5) == 1 + 2 + 3 + 4 + 5 raises(TypeError, f, 1, 2, 3) raises(TypeError, f, 1, "2", 3, 4, 5)
def test_signature2(self): a = MyPPCAssembler() a.add(r3, r3, r4) a.add(r3, r3, r5) a.add(r3, r3, r6) a.add(r3, r3, r7) s = lookup("PyInt_FromLong") a.load_word(r0, s) a.mtctr(r0) a.bctr() f = make_func(a, "O", "iiiii") raises(TypeError, f) raises(TypeError, f, 1) assert f(1, 2, 3, 4, 5) == 1 + 2 + 3 + 4 + 5 raises(TypeError, f, 1, 2, 3) raises(TypeError, f, 1, "2", 3, 4, 5)
def test_numberadd(self): a = MyPPCAssembler() a.lwz(r5, r4, pystructs.PyVarObject.ob_size) a.cmpwi(r5, 2) a.bne("err_out") a.lwz(r3, r4, 12) a.lwz(r4, r4, 16) a.load_word(r5, lookup("PyNumber_Add")) a.mtctr(r5) a.bctr() a.label("err_out") a.mflr(r0) a.stw(r0, r1, 8) a.stwu(r1, r1, -80) err_set = lookup("PyErr_SetObject") exc = lookup("PyExc_TypeError") a.load_word(r5, err_set) a.mtctr(r5) a.load_from(r3, exc) a.mr(r4, r3) a.bctrl() a.li(r3, 0) a.lwz(r0, r1, 88) a.addi(r1, r1, 80) a.mtlr(r0) a.blr() f = a.assemble() raises(TypeError, f) raises(TypeError, f, '', 1) raises(TypeError, f, 1) raises(TypeError, f, 1, 2, 3) assert f(1, 2) == 3 assert f('a', 'b') == 'ab'