예제 #1
0
def test_simple_exception():
    jitcode = JitCode("test")
    jitcode.setup(  # residual_call_ir_i $<* fn g>, I[%i9], R[], <Descr>  %i8
        "\x01\xFF\x01\x09\x00\x00\x00\x08"
        "\x00\x0D\x00"  #     catch_exception L1
        "\x02\x08"  #     int_return %i8
        "\x03\x2A",  # L1: int_return $42
        [321])  # <-- address of the function g
    blackholeinterp = getblackholeinterp(
        {
            'catch_exception/L': 0,
            'residual_call_ir_i/iIRd>i': 1,
            'int_return/i': 2,
            'int_return/c': 3
        }, ["<calldescr>"])
    #
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(0x9, 100)
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 200
    #
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(0x9, -100)
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 42
예제 #2
0
def test_simple_bigconst():
    jitcode = JitCode("test")
    jitcode.setup("\x00\xFD\x01\x02"
                  "\x01\x02",
                  [666, 666, 10042, 666])
    blackholeinterp = getblackholeinterp({'int_sub/ii>i': 0,
                                          'int_return/i': 1})
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(1, 10000)
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 42
예제 #3
0
def test_simple_bigconst():
    jitcode = JitCode("test")
    jitcode.setup("\x00\xFD\x01\x02" "\x01\x02", [666, 666, 10042, 666])
    blackholeinterp = getblackholeinterp({
        'int_sub/ii>i': 0,
        'int_return/i': 1
    })
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(1, 10000)
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 42
예제 #4
0
def test_simple():
    jitcode = JitCode("test")
    jitcode.setup("\x00\x00\x01\x02"
                  "\x01\x02",
                  [])
    blackholeinterp = getblackholeinterp({'int_add/ii>i': 0,
                                          'int_return/i': 1})
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(0, 40)
    blackholeinterp.setarg_i(1, 2)
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 42
예제 #5
0
def test_simple():
    jitcode = JitCode("test")
    jitcode.setup("\x00\x00\x01\x02" "\x01\x02", [])
    blackholeinterp = getblackholeinterp({
        'int_add/ii>i': 0,
        'int_return/i': 1
    })
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(0, 40)
    blackholeinterp.setarg_i(1, 2)
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 42
예제 #6
0
파일: codewriter.py 프로젝트: Mu-L/pypy
 def transform_func_to_jitcode(self, func, values):
     """For testing."""
     rtyper = support.annotate(func, values)
     graph = rtyper.annotator.translator.graphs[0]
     jitcode = JitCode("test")
     self.transform_graph_to_jitcode(graph, jitcode, True, 0)
     return jitcode
예제 #7
0
def test_simple_loop():
    jitcode = JitCode("test")
    jitcode.setup("\x00\x16\x02\x10\x00"  # L1: goto_if_not_int_gt %i0, 2, L2
                  "\x01\x17\x16\x17"      #     int_add %i1, %i0, %i1
                  "\x02\x16\x01\x16"      #     int_sub %i0, $1, %i0
                  "\x03\x00\x00"          #     goto L1
                  "\x04\x17",             # L2: int_return %i1
                  [])
    blackholeinterp = getblackholeinterp({'goto_if_not_int_gt/icL': 0,
                                          'int_add/ii>i': 1,
                                          'int_sub/ic>i': 2,
                                          'goto/L': 3,
                                          'int_return/i': 4})
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(0x16, 6)    # %i0
    blackholeinterp.setarg_i(0x17, 100)  # %i1
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 100+6+5+4+3
예제 #8
0
def test_simple_loop():
    jitcode = JitCode("test")
    jitcode.setup(
        "\x00\x16\x02\x10\x00"  # L1: goto_if_not_int_gt %i0, 2, L2
        "\x01\x17\x16\x17"  #     int_add %i1, %i0, %i1
        "\x02\x16\x01\x16"  #     int_sub %i0, $1, %i0
        "\x03\x00\x00"  #     goto L1
        "\x04\x17",  # L2: int_return %i1
        [])
    blackholeinterp = getblackholeinterp({
        'goto_if_not_int_gt/icL': 0,
        'int_add/ii>i': 1,
        'int_sub/ic>i': 2,
        'goto/L': 3,
        'int_return/i': 4
    })
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(0x16, 6)  # %i0
    blackholeinterp.setarg_i(0x17, 100)  # %i1
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 100 + 6 + 5 + 4 + 3
예제 #9
0
 class MyMIFrame:
     jitcode = JitCode("test")
     jitcode.setup(
         "\xFF"  # illegal instruction
         "\x00\x00\x01\x02"  # int_add/ii>i
         "\x01\x02",  # int_return/i
         [],
         num_regs_i=3,
         num_regs_r=0,
         num_regs_f=0)
     jitcode.jitdriver_sd = "foo"  # not none
     pc = 1
     registers_i = [resoperation.InputArgInt(40), history.ConstInt(2), None]
예제 #10
0
 class MyMIFrame:
     jitcode = JitCode("test")
     jitcode.setup(
         "\xFF"  # illegal instruction
         "\x00\x00\x01\x02"  # int_add/ii>i
         "\x01\x02",  # int_return/i
         [],
         num_regs_i=3,
         num_regs_r=0,
         num_regs_f=0)
     jitcode.is_portal = True
     pc = 1
     registers_i = [history.BoxInt(40), history.ConstInt(2), None]
예제 #11
0
def test_simple_exception():
    jitcode = JitCode("test")
    jitcode.setup(    # residual_call_ir_i $<* fn g>, I[%i9], R[], <Descr>  %i8
                  "\x01\xFF\x01\x09\x00\x00\x00\x08"
                  "\x00\x0D\x00"          #     catch_exception L1
                  "\x02\x08"              #     int_return %i8
                  "\x03\x2A",             # L1: int_return $42
                  [321])   # <-- address of the function g
    blackholeinterp = getblackholeinterp({'catch_exception/L': 0,
                                          'residual_call_ir_i/iIRd>i': 1,
                                          'int_return/i': 2,
                                          'int_return/c': 3},
                                         ["<calldescr>"])
    #
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(0x9, 100)
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 200
    #
    blackholeinterp.setposition(jitcode, 0)
    blackholeinterp.setarg_i(0x9, -100)
    blackholeinterp.run()
    assert blackholeinterp._final_result_anytype() == 42