Пример #1
0
    def run(self, code):
        space = FakeSpace()
        
        def f(code):
            interp = numpy_compile(hlstr(code))
            interp.run(space)
            res = interp.results[-1]
            w_res = res.eval(0).wrap(interp.space)
            if isinstance(w_res, BoolObject):
                return float(w_res.boolval)
            elif isinstance(w_res, FloatObject):
                return w_res.floatval
            elif isinstance(w_res, IntObject):
                return w_res.intval
            else:
                return -42.

        if self.graph is None:
            interp, graph = self.meta_interp(f, [llstr(code)],
                                             listops=True,
                                             backendopt=True,
                                             graph_and_interp_only=True)
            self.__class__.interp = interp
            self.__class__.graph = graph

        reset_stats()
        pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear()
        return self.interp.eval_graph(self.graph, [llstr(code)])
Пример #2
0
def test_streq_nonnull_char():
    func = LLtypeHelpers._ll_2_str_eq_nonnull_char.im_func
    assert func(llstr("wor"), "x") == False
    assert func(llstr("w"), "x") == False
    assert func(llstr(""), "x") == False
    assert func(llstr("x"), "x") == True
    py.test.raises(AttributeError, func, llstr(None), "x")
Пример #3
0
def test_streq_checknull_char():
    func = LLtypeHelpers._ll_2_str_eq_checknull_char.im_func
    assert func(llstr("wor"), "x") == False
    assert func(llstr("w"), "x") == False
    assert func(llstr(""), "x") == False
    assert func(llstr("x"), "x") == True
    assert func(llstr(None), "x") == False
Пример #4
0
    def test_set_param_enable_opts(self):
        from pypy.rpython.annlowlevel import llstr, hlstr

        myjitdriver = JitDriver(greens=[], reds=['n'])

        class A(object):
            def m(self, n):
                return n - 1

        def g(n):
            while n > 0:
                myjitdriver.can_enter_jit(n=n)
                myjitdriver.jit_merge_point(n=n)
                n = A().m(n)
            return n

        def f(n, enable_opts):
            set_param(None, 'enable_opts', hlstr(enable_opts))
            return g(n)

        # check that the set_param will override the default
        res = self.meta_interp(f, [10, llstr('')])
        assert res == 0
        self.check_resops(new_with_vtable=1)

        res = self.meta_interp(f, [10, llstr(ALL_OPTS_NAMES)], enable_opts='')
        assert res == 0
        self.check_resops(new_with_vtable=0)
Пример #5
0
    def test_set_param_enable_opts(self):
        from pypy.rpython.annlowlevel import llstr, hlstr
        
        myjitdriver = JitDriver(greens = [], reds = ['n'])
        class A(object):
            def m(self, n):
                return n-1
            
        def g(n):
            while n > 0:
                myjitdriver.can_enter_jit(n=n)
                myjitdriver.jit_merge_point(n=n)
                n = A().m(n)
            return n
        def f(n, enable_opts):
            myjitdriver.set_param('enable_opts', hlstr(enable_opts))
            return g(n)

        # check that the set_param will override the default
        res = self.meta_interp(f, [10, llstr('')])
        assert res == 0
        self.check_loops(new_with_vtable=1)

        res = self.meta_interp(f, [10, llstr(ALL_OPTS_NAMES)],
                               enable_opts='')
        assert res == 0
        self.check_loops(new_with_vtable=0)
Пример #6
0
 def test_simple(self):
     sb = StringBuilderRepr.ll_new(3)
     StringBuilderRepr.ll_append_char(sb, 'x')
     StringBuilderRepr.ll_append(sb, llstr("abc"))
     StringBuilderRepr.ll_append_slice(sb, llstr("foobar"), 2, 5)
     StringBuilderRepr.ll_append_multiple_char(sb, 'y', 3)
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "xabcobayyy"
Пример #7
0
 def test_simple(self):
     sb = StringBuilderRepr.ll_new(3)
     StringBuilderRepr.ll_append_char(sb, 'x')
     StringBuilderRepr.ll_append(sb, llstr("abc"))
     StringBuilderRepr.ll_append_slice(sb, llstr("foobar"), 2, 5)
     StringBuilderRepr.ll_append_multiple_char(sb, 'y', 3)
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "xabcobayyy"
Пример #8
0
def test_streq_slice_nonnull():
    p1 = llstr("hello world")
    p2 = llstr("wor")
    func = LLtypeHelpers._ll_4_str_eq_slice_nonnull.im_func
    assert func(p1, 6, 3, p2) == True
    assert func(p1, 6, 2, p2) == False
    assert func(p1, 5, 3, p2) == False
    py.test.raises(AttributeError, func, p1, 2, 1, llstr(None))
Пример #9
0
def test_streq_slice_checknull():
    p1 = llstr("hello world")
    p2 = llstr("wor")
    func = LLtypeHelpers._ll_4_str_eq_slice_checknull.im_func
    assert func(p1, 6, 3, p2) == True
    assert func(p1, 6, 2, p2) == False
    assert func(p1, 5, 3, p2) == False
    assert func(p1, 2, 1, llstr(None)) == False
Пример #10
0
 def getvar(self, arg):
     if not arg:
         return ConstInt(0)
     try:
         return ConstInt(int(arg))
     except ValueError:
         if self.is_float(arg):
             return ConstFloat(float(arg))
         if arg.startswith('"') or arg.startswith("'"):
             # XXX ootype
             info = arg.strip("'\"")
             return ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF,
                                                    llstr(info)))
         if arg.startswith('ConstClass('):
             name = arg[len('ConstClass('):-1]
             return self.get_const(name, 'class')
         elif arg == 'None':
             return None
         elif arg == 'NULL':
             if self.type_system == 'lltype':
                 return ConstPtr(ConstPtr.value)
             else:
                 return ConstObj(ConstObj.value)
         elif arg.startswith('ConstPtr('):
             name = arg[len('ConstPtr('):-1]
             return self.get_const(name, 'ptr')
         return self.vars[arg]
Пример #11
0
def test_streq_slice_char():
    p1 = llstr("hello world")
    func = LLtypeHelpers._ll_4_str_eq_slice_char.im_func
    assert func(p1, 6, 3, "w") == False
    assert func(p1, 6, 0, "w") == False
    assert func(p1, 6, 1, "w") == True
    assert func(p1, 6, 1, "x") == False
Пример #12
0
 def getvar(self, arg):
     if not arg:
         return ConstInt(0)
     try:
         return ConstInt(int(arg))
     except ValueError:
         if self.is_float(arg):
             return ConstFloat(float(arg))
         if arg.startswith('"') or arg.startswith("'"):
             # XXX ootype
             info = arg.strip("'\"")
             return ConstPtr(
                 lltype.cast_opaque_ptr(llmemory.GCREF, llstr(info)))
         if arg.startswith('ConstClass('):
             name = arg[len('ConstClass('):-1]
             return self.get_const(name, 'class')
         elif arg == 'None':
             return None
         elif arg == 'NULL':
             if self.type_system == 'lltype':
                 return ConstPtr(ConstPtr.value)
             else:
                 return ConstObj(ConstObj.value)
         elif arg.startswith('ConstPtr('):
             name = arg[len('ConstPtr('):-1]
             return self.get_const(name, 'ptr')
         return self.vars[arg]
Пример #13
0
 def f():
     a = llstr("xyz")
     b = (llmemory.cast_ptr_to_adr(a) +
          llmemory.offsetof(STR, 'chars') +
          llmemory.itemoffsetof(STR.chars, 0))
     buf = rffi.cast(rffi.VOIDP, b)
     return buf[2]
Пример #14
0
def read_code():
    from pypy.module.marshal.interp_marshal import dumps

    filename = 'pypyjit_demo.py'
    source = readfile(filename)
    ec = space.getexecutioncontext()
    code = ec.compiler.compile(source, filename, 'exec', 0)
    return llstr(space.str_w(dumps(space, code, space.wrap(2))))
Пример #15
0
def read_code():
    from pypy.module.marshal.interp_marshal import dumps
    
    filename = 'pypyjit_demo.py'
    source = readfile(filename)
    ec = space.getexecutioncontext()
    code = ec.compiler.compile(source, filename, 'exec', 0)
    return llstr(space.str_w(dumps(space, code, space.wrap(2))))
Пример #16
0
def get_const_ptr_for_string(s):
    from pypy.rpython.annlowlevel import llstr
    if not we_are_translated():
        try:
            return _const_ptr_for_string[s]
        except KeyError:
            pass
    result = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, llstr(s)))
    if not we_are_translated():
        _const_ptr_for_string[s] = result
    return result
Пример #17
0
def apply_jit(policy, interp, graph, CPUClass):
    print 'warmspot.jittify_and_run() started...'
    option.view = True
    LIST = graph.getargs()[0].concretetype
    lst = LIST.TO.ll_newlist(len(ARGS))
    for i, arg in enumerate(ARGS):
        lst.ll_setitem_fast(i, llstr(arg))
    warmspot.jittify_and_run(interp, graph, [lst], policy=policy,
                             listops=True, CPUClass=CPUClass,
                             backendopt=True, inline=True,
                             optimizer=OPTIMIZER_FULL)
Пример #18
0
def get_const_ptr_for_string(s):
    from pypy.rpython.annlowlevel import llstr
    if not we_are_translated():
        try:
            return _const_ptr_for_string[s]
        except KeyError:
            pass
    result = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, llstr(s)))
    if not we_are_translated():
        _const_ptr_for_string[s] = result
    return result
Пример #19
0
def test_streq_nonnull():
    p1 = llstr("wor")
    p2 = llstr("wor")
    assert p1 != p2
    func = LLtypeHelpers._ll_2_str_eq_nonnull.im_func
    assert func(p1, p1) == True
    assert func(p1, p2) == True
    assert func(p1, llstr("wrl")) == False
    assert func(p1, llstr("world")) == False
    assert func(p1, llstr("w")) == False
    py.test.raises(AttributeError, func, p1, llstr(None))
    py.test.raises(AttributeError, func, llstr(None), p2)
Пример #20
0
def apply_jit(policy, interp, graph, CPUClass):
    print 'warmspot.jittify_and_run() started...'
    option.view = True
    LIST = graph.getargs()[0].concretetype
    lst = LIST.TO.ll_newlist(len(ARGS))
    for i, arg in enumerate(ARGS):
        lst.ll_setitem_fast(i, llstr(arg))
    warmspot.jittify_and_run(interp,
                             graph, [lst],
                             policy=policy,
                             listops=True,
                             CPUClass=CPUClass,
                             backendopt=True,
                             inline=True,
                             optimizer=OPTIMIZER_FULL)
 def f(arg):
     s = llstr(hlstr(arg))
     return len(s.chars)
 def test_llstr(self):
     s = llstr("abc")
     assert len(s.chars) == 3
     assert s.chars[0] == "a"
     assert s.chars[1] == "b"
     assert s.chars[2] == "c"
Пример #23
0
 def ll_str(self, none):
     return llstr("None")
Пример #24
0
 def test_nooveralloc(self):
     sb = StringBuilderRepr.ll_new(3)
     StringBuilderRepr.ll_append(sb, llstr("abc"))
     assert StringBuilderRepr.ll_build(sb) == sb.buf
Пример #25
0
 def f(arg):
     s = llstr(hlstr(arg))
     return len(s.chars)
Пример #26
0
    def test_translation(self):
        # we import main to check if the target compiles
        from pypy.translator.goal.targetnumpystandalone import main

        interpret(main, [llstr('af+'), 100])
Пример #27
0
 def conststr(self, str):
     ll = llstr(str)
     return history.ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, ll))
Пример #28
0
 def meta_interp_search(self, pattern, string, repeat=1):
     r = get_code(pattern)
     return self.meta_interp(entrypoint2, [list2array(r), llstr(string),
                                           repeat],
                             listcomp=True, backendopt=True)
Пример #29
0
 def test_nooveralloc(self):
     sb = StringBuilderRepr.ll_new(3)
     StringBuilderRepr.ll_append(sb, llstr("abc"))
     assert StringBuilderRepr.ll_build(sb) == sb.buf
Пример #30
0
 def ll_str(self, none):
     return llstr("None")
Пример #31
0
def ll_float_str(repr, f):
    return llstr(formatd("%f", f))
Пример #32
0
def resop_getopname(llop):
    return llstr(_cast_to_resop(llop).getopname())
Пример #33
0
def resop_getopname(llop):
    return llstr(_cast_to_resop(llop).getopname())
Пример #34
0
 def f():
     a = llstr("xyz")
     b = (llmemory.cast_ptr_to_adr(a) + llmemory.offsetof(STR, 'chars')
          + llmemory.itemoffsetof(STR.chars, 0))
     buf = rffi.cast(rffi.VOIDP, b)
     return buf[2]
Пример #35
0
 def test_llstr(self):
     s = llstr("abc")
     assert len(s.chars) == 3
     assert s.chars[0] == "a"
     assert s.chars[1] == "b"
     assert s.chars[2] == "c"
Пример #36
0
def ll_float_str(repr, f):
    from pypy.rlib.rfloat import formatd
    return llstr(formatd(f, 'f', 6))