def Interp(expr, funDict, env, k):

    bouncer = ToBounce(expr, env, k)

    set_param(jitdriver, "trace_limit", 25000)
    
    while 1:

        jitdriver.jit_merge_point(funDict=funDict, bouncer=bouncer, expr=expr, env=env, k=k)
        if isinstance(bouncer, NoMoreBounce):
            break
        elif isinstance(bouncer, ToBounce):
            expr = bouncer.expr
            env = bouncer.env
            k = bouncer.k
            
            if isinstance(expr, treeClass.App):
                enter = True
            else:
                enter = False
            bouncer = Trampoline(bouncer, funDict)
            if enter:
                expr = bouncer.expr
                env = bouncer.env
                k = bouncer.k
                jitdriver.can_enter_jit(funDict=funDict, bouncer=bouncer, expr=expr, env=env, k=k)
                
    assert isinstance(bouncer, NoMoreBounce)
    return bouncer.value
예제 #2
0
 def loop2(g, r):
     set_param(None, "function_threshold", 0)
     while r > 0:
         myjitdriver2.can_enter_jit(g=g, r=r)
         myjitdriver2.jit_merge_point(g=g, r=r)
         r += loop1(r, g) - 1
     return r
예제 #3
0
파일: interp_jit.py 프로젝트: njues/Sypy
def set_param(space, __args__):
    '''Configure the tunable JIT parameters.
        * set_param(name=value, ...)            # as keyword arguments
        * set_param("name=value,name=value")    # as a user-supplied string
        * set_param("off")                      # disable the jit
        * set_param("default")                  # restore all defaults
    '''
    # XXXXXXXXX
    args_w, kwds_w = __args__.unpack()
    if len(args_w) > 1:
        msg = "set_param() takes at most 1 non-keyword argument, %d given"
        raise operationerrfmt(space.w_TypeError, msg, len(args_w))
    if len(args_w) == 1:
        text = space.str_w(args_w[0])
        try:
            jit.set_user_param(None, text)
        except ValueError:
            raise OperationError(space.w_ValueError,
                                 space.wrap("error in JIT parameters string"))
    for key, w_value in kwds_w.items():
        if key == 'enable_opts':
            jit.set_param(None, 'enable_opts', space.str_w(w_value))
        else:
            intval = space.int_w(w_value)
            for name, _ in unroll_parameters:
                if name == key and name != 'enable_opts':
                    jit.set_param(None, name, intval)
                    break
            else:
                raise operationerrfmt(space.w_TypeError,
                                      "no JIT parameter '%s'", key)
예제 #4
0
        def f(n, threshold):
            set_param(myjitdriver, 'threshold', threshold)
            i = j = x = 0
            pos = 0
            op = '-'
            while pos < len(bytecode):
                myjitdriver.jit_merge_point(pos=pos, i=i, j=j, n=n, x=x)
                op = bytecode[pos]
                if op == 'z':
                    j = 0
                elif op == 'i':
                    i += 1
                    pos = 0
                    myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x)
                    continue
                elif op == 'j':
                    j += 1
                    pos = 2
                    myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x)
                    continue
                elif op == 'I':
                    if not (i < n):
                        pos = 5
                elif op == 'J':
                    if not (j <= i):
                        pos = 4
                elif op == 'x':
                    x = x + (i & j)

                pos += 1

            return x
예제 #5
0
파일: test_loop.py 프로젝트: Debug-Orz/Sypy
        def f(n, threshold):
            set_param(myjitdriver, 'threshold', threshold)        
            i = j = x = 0
            pos = 0
            op = '-'
            while pos < len(bytecode):
                myjitdriver.jit_merge_point(pos=pos, i=i, j=j, n=n, x=x)
                op = bytecode[pos]
                if op == 'z':
                    j = 0
                elif op == 'i':
                    i += 1
                    pos = 0
                    myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x)
                    continue
                elif op == 'j':
                    j += 1
                    pos = 2
                    myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x)
                    continue
                elif op == 'I':
                    if not (i < n):
                        pos = 5
                elif op == 'J':
                    if not (j <= i):
                        pos = 4
                elif op == 'x':
                    x = x + (i&j)

                pos += 1

            return x
예제 #6
0
파일: test_loop.py 프로젝트: Debug-Orz/Sypy
        def f(nval, threshold):
            set_param(myjitdriver, 'threshold', threshold)        
            i, j, x = A(0), A(0), A(0)
            n = A(nval)
            pos = 0
            op = '-'
            while pos < len(bytecode):
                myjitdriver.jit_merge_point(pos=pos, i=i, j=j, n=n, x=x)
                op = bytecode[pos]
                if op == 'z':
                    j = A(0)
                elif op == 'i':
                    i = i.add(1)
                    pos = 0
                    myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x)
                    continue
                elif op == 'j':
                    j = j.add(1)
                    pos = 2
                    myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x)
                    continue
                elif op == 'I':
                    if not (i.val < n.val):
                        pos = 5
                elif op == 'J':
                    if not (j.val <= i.val):
                        pos = 4
                elif op == 'x':
                    x = x.add(i.val & j.val)

                pos += 1

            return x.val
예제 #7
0
 def loop2(g, r):
     set_param(None, 'function_threshold', 0)
     while r > 0:
         myjitdriver2.can_enter_jit(g=g, r=r)
         myjitdriver2.jit_merge_point(g=g, r=r)
         r += loop1(r, g) - 1
     return r
예제 #8
0
def Interpret(tree):
    """Interpret the tree."""

    set_param(jitdriver, "trace_limit", 25000)

    env = mtSub()
    k = EndK()
    bouncer = KeepBouncing(tree, env, k)

    while 1:
        jitdriver.jit_merge_point(tree=tree, env=env, k=k, bouncer=bouncer)
        
        if isinstance(bouncer, FinalBounce):
            break
        elif isinstance(bouncer, KeepBouncing):
            tree = bouncer.tree
            env = bouncer.env
            k = bouncer.k
            bouncer = bouncer.bounce()
            jitdriver.can_enter_jit(tree=tree, env=env, k=k, bouncer=bouncer)
        else:
            bouncer = FinalBounce( ErrorV(" Bouncer not a bounce ?!"))

    assert isinstance(bouncer, FinalBounce)
    return bouncer.bounce()
예제 #9
0
def set_param(space, __args__):
    '''Configure the tunable JIT parameters.
        * set_param(name=value, ...)            # as keyword arguments
        * set_param("name=value,name=value")    # as a user-supplied string
        * set_param("off")                      # disable the jit
        * set_param("default")                  # restore all defaults
    '''
    # XXXXXXXXX
    args_w, kwds_w = __args__.unpack()
    if len(args_w) > 1:
        msg = "set_param() takes at most 1 non-keyword argument, %d given"
        raise operationerrfmt(space.w_TypeError, msg, len(args_w))
    if len(args_w) == 1:
        text = space.str_w(args_w[0])
        try:
            jit.set_user_param(None, text)
        except ValueError:
            raise OperationError(space.w_ValueError,
                                 space.wrap("error in JIT parameters string"))
    for key, w_value in kwds_w.items():
        if key == 'enable_opts':
            jit.set_param(None, 'enable_opts', space.str_w(w_value))
        else:
            intval = space.int_w(w_value)
            for name, _ in unroll_parameters:
                if name == key and name != 'enable_opts':
                    jit.set_param(None, name, intval)
                    break
            else:
                raise operationerrfmt(space.w_TypeError,
                                      "no JIT parameter '%s'", key)
예제 #10
0
        def f(nval, threshold):
            set_param(myjitdriver, 'threshold', threshold)
            i, j, x = A(0), A(0), A(0)
            n = A(nval)
            pos = 0
            op = '-'
            while pos < len(bytecode):
                myjitdriver.jit_merge_point(pos=pos, i=i, j=j, n=n, x=x)
                op = bytecode[pos]
                if op == 'z':
                    j = A(0)
                elif op == 'i':
                    i = i.add(1)
                    pos = 0
                    myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x)
                    continue
                elif op == 'j':
                    j = j.add(1)
                    pos = 2
                    myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x)
                    continue
                elif op == 'I':
                    if not (i.val < n.val):
                        pos = 5
                elif op == 'J':
                    if not (j.val <= i.val):
                        pos = 4
                elif op == 'x':
                    x = x.add(i.val & j.val)

                pos += 1

            return x.val
예제 #11
0
 def loop(n):            
     set_param(myjitdriver, "threshold", 10)
     pc = 0
     while n:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         n = recursive(n)
         n -= 1
     return n
예제 #12
0
def Interpret(tree):
    """Interpret the tree, iteratively."""

    set_param(jitdriver, "trace_limit", 25000)

    register = ReturnType()
    tree = tree
    env = Map()
    k = EndK()

    while 1:
        jitdriver.jit_merge_point(tree=tree, env=env, k=k, register=register)

        if isinstance(k, FinalK):
            break

        if isinstance(tree, parser.Num):
            register, tree, env, k = k._apply(NumV(tree.val), tree, env, k)

        elif isinstance(tree, parser.Op):
            k = Op1K(tree.op, tree.lhs, tree.rhs, env, k)
            tree = tree.lhs

        elif isinstance(tree, parser.Id):
            promote(env)
            register = env.getvalue(tree.name)
            if isinstance(register, ErrorV):
                k = FinalK()
            else:
                register, tree, env, k = k._apply(register, tree, env, k)

        elif isinstance(tree, parser.If):
            k = If0K(tree.nul, tree.true, tree.false, env, k)
            tree = tree.nul

        elif isinstance(tree, parser.Func):
            assert isinstance(tree.arg, parser.Id)
            register, tree, env, k = k._apply(ClosureV(tree.arg, tree.body, env), tree, env, k)

        elif isinstance(tree, parser.App):
            k = App1K(tree.fun, env, k)
            tree = tree.arg
            jitdriver.can_enter_jit(tree=tree, env=env, k=k, register=register)

        elif isinstance(tree, parser.Rec):
            k = RecK(tree.funName, tree.body, tree.expr, k)
            dummy = NumV(42)
            promote(env)
            env = env.add_attribute(tree.funName, dummy)
            tree = tree.body

        else:
            msg = "Parsing error, tree %s is not valid" % tree.__str__()
            register = ErrorV(msg)
            k = FinalK()

    return register
예제 #13
0
 def g(m):
     set_param(None, 'inlining', True)
     # carefully chosen threshold to make sure that the inner function
     # cannot be inlined, but the inner function on its own is small
     # enough
     set_param(None, 'trace_limit', 40)
     if m > 1000000:
         f('', 0)
     result = 0
     for i in range(m):
         result += f('-c-----------l-', i+100)
예제 #14
0
 def loop(n):
     set_param(None, "threshold", 4)
     set_param(None, "trace_eagerness", 2)
     while n:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         if n % 5 == 0:
             n -= 1
         if n < 50:
             n = recursive(n)
         n -= 1
     return n
예제 #15
0
 def entrypoint(argv):
     jit.set_param(myjitdriver, 'threshold', 2)
     jit.set_param(myjitdriver, 'trace_eagerness', 0)
     n = 16
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         n -= 1
         check0()
         check1(0)
         check2(0, 1)
         check3(0, 1, 2)
     return 0
예제 #16
0
 def entrypoint(argv):
     jit.set_param(myjitdriver, 'threshold', 2)
     jit.set_param(myjitdriver, 'trace_eagerness', 0)
     n = 16
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         n -= 1
         check0()
         check1(0)
         check2(0, 1)
         check3(0, 1, 2)
     return 0
예제 #17
0
 def main(inline):
     set_param(None, "threshold", 10)
     set_param(None, 'function_threshold', 60)
     if inline:
         set_param(None, 'inlining', True)
     else:
         set_param(None, 'inlining', False)
     return loop(100)
예제 #18
0
 def myportal(i):
     set_param(jitdriver, "threshold", 3)
     set_param(jitdriver, "trace_eagerness", 2)
     total = 0
     n = i
     while True:
         jitdriver.can_enter_jit(n=n, total=total)
         jitdriver.jit_merge_point(n=n, total=total)
         try:
             total += f(n, total)
         except ValueError:
             total += 1
         try:
             total += g(n)
         except ValueError:
             total -= 1
         n -= h(n).meth()   # this is to force a GUARD_CLASS
예제 #19
0
 def myportal(i):
     set_param(jitdriver, "threshold", 3)
     set_param(jitdriver, "trace_eagerness", 2)
     total = 0
     n = i
     while True:
         jitdriver.can_enter_jit(n=n, total=total)
         jitdriver.jit_merge_point(n=n, total=total)
         try:
             total += f(n, total)
         except ValueError:
             total += 1
         try:
             total += g(n)
         except ValueError:
             total -= 1
         n -= h(n).meth()  # this is to force a GUARD_CLASS
예제 #20
0
 def main(i):
     set_param(jitdriver, "threshold", 3)
     set_param(jitdriver, "trace_eagerness", 2)
     total = 0
     n = i
     while n > 3:
         jitdriver.can_enter_jit(n=n, total=total)
         jitdriver.jit_merge_point(n=n, total=total)
         try:
             total += f(n)
         except ValueError:
             total += 1
         try:
             total += g(n)
         except ValueError:
             total -= 1
         n -= 1
     return total * 10
예제 #21
0
 def f(i):
     for param, defl in unroll_parameters:
         set_param(jitdriver, param, defl)
     set_param(jitdriver, "threshold", 3)
     set_param(jitdriver, "trace_eagerness", 2)
     total = 0
     frame = Frame(i)
     while frame.l[0] > 3:
         jitdriver.can_enter_jit(frame=frame, total=total)
         jitdriver.jit_merge_point(frame=frame, total=total)
         total += frame.l[0]
         if frame.l[0] >= 20:
             frame.l[0] -= 2
         frame.l[0] -= 1
     return total * 10
예제 #22
0
 def f(i, j):
     for param, _ in unroll_parameters:
         defl = PARAMETERS[param]
         set_param(jitdriver, param, defl)
     set_param(jitdriver, "threshold", 3)
     set_param(jitdriver, "trace_eagerness", 2)
     total = 0
     frame = Frame(i)
     while frame.i > 3:
         jitdriver.can_enter_jit(frame=frame, total=total, j=j)
         jitdriver.jit_merge_point(frame=frame, total=total, j=j)
         total += frame.i
         if frame.i >= 20:
             frame.i -= 2
         frame.i -= 1
         j *= -0.712
         if j + (-j): raise ValueError
         k = myabs(j)
         if k - abs(j): raise ValueError
         if k - abs(-j): raise ValueError
     return chr(total % 253)
예제 #23
0
 def f(i, j):
     for param, _ in unroll_parameters:
         defl = PARAMETERS[param]
         set_param(jitdriver, param, defl)
     set_param(jitdriver, "threshold", 3)
     set_param(jitdriver, "trace_eagerness", 2)
     total = 0
     frame = Frame(i)
     j = float(j)
     while frame.i > 3:
         jitdriver.can_enter_jit(frame=frame, total=total, j=j)
         jitdriver.jit_merge_point(frame=frame, total=total, j=j)
         total += frame.i
         if frame.i >= 20:
             frame.i -= 2
         frame.i -= 1
         j *= -0.712
         if j + (-j):    raise ValueError
         k = myabs(j)
         if k - abs(j):  raise ValueError
         if k - abs(-j): raise ValueError
     return chr(total % 253)
예제 #24
0
def Interpk(expr, funDict, env):
    """ Interpret the ifF1WAE AST given a set of defined functions. We use deferred substitution and eagerness."""

    val = -1
    funDict = funDict
    expr = expr
    env = env
    cont = Idk()

    set_param(jitdriver, "trace_limit", 25000)

    while 1:
        #
        jitdriver.jit_merge_point(val=val, expr=expr, env=env, cont=cont, funDict=funDict)
        if isinstance(cont, Endk):
            break
        #
        if isinstance(expr, treeClass.Num):
            val = expr.n
            ex, en, co, va = cont.apply(expr,env,val) 
            expr = ex
            env = en
            cont = co
            val = va
        #
        elif isinstance(expr, treeClass.Id):
            val = GetInEnv(env, expr.name)
            ex, en, co, va = cont.apply(expr,env,val) 
            expr = ex
            env = en
            cont = co
            val = va
        #
        elif isinstance(expr, treeClass.With):
            cont = Withk(expr.body, env, cont, expr.name)
            expr = expr.nameExpr
        #
        elif isinstance(expr, treeClass.If):
            cont = Ifk(env, cont, expr.ctrue, expr.cfalse)
            expr = expr.cond
        #
        elif isinstance(expr, treeClass.Op):
            cont = Op1k(env, cont, expr.op, expr.rhs)
            expr = expr.lhs
        #
        elif isinstance(expr, treeClass.App):
            fun = GetFunc(funDict, expr.funName)
            if isinstance(fun, treeClass.NoneFunc):
                cont = Endk(2)
            else:
                body = fun.body
                arg = fun.argName
                expr = expr.arg
                cont = Appk(body, cont, arg)
                jitdriver.can_enter_jit(val=val, expr=expr, env=env, cont=cont, funDict=funDict)
        #
        else: # Not an <instr>
            print("Argument of Interpk is not a <instr>:\n")
            cont = Endk(2)
        # End of while
    assert isinstance(cont, Endk)
    return cont.val
예제 #25
0
 def f(n, enable_opts):
     set_param(None, 'enable_opts', hlstr(enable_opts))
     return g(n)
예제 #26
0
 def f(n, enable_opts):
     set_param(None, 'enable_opts', hlstr(enable_opts))
     return g(n)
예제 #27
0
def Interpret(expr, funDict, env):
    """ Interpret the ifF1WAE AST given a set of defined functions. We use deferred substituion and eagerness."""

    set_param(jitdriver, "trace_limit", 25000)
    
    jitdriver.jit_merge_point(expr=expr,funDict=funDict, env=env)

    if isinstance(expr, treeClass.Num):
        return expr.n
    #
    elif isinstance(expr, treeClass.Op):
        left = Interpret(expr.lhs, funDict, env)
        right = Interpret(expr.rhs, funDict, env)
        if expr.op == '+':
            return left + right
        elif expr.op == '-':
            return left - right
        elif expr.op == '*':
            return left * right
        elif expr.op == '/':
            return left/right
        elif expr.op == '%':
            return left % right
        elif expr.op == '=':
            if left == right:
                return 1
            else:
                return 0
        else:
            print("Parsing Error, symobl "+ expr.op+" shouldn't be here.")
            return 2
    #
    elif isinstance(expr, treeClass.With):
        val = Interpret(expr.nameExpr, funDict, env)
        env[expr.name] = val #Eager
        return Interpret(expr.body, funDict, env)
    #
    elif isinstance(expr, treeClass.Id):
        return GetInEnv(env, expr.name)
    #
    elif isinstance(expr, treeClass.App):
        funDef = GetFunc(funDict, expr.funName)
        if not isinstance(funDef, treeClass.NoneFunc):
            #
            val = Interpret(expr.arg, funDict, env)
            #
            if not isinstance(funDef, treeClass.Func):
                print("Wrong Dictionnary.")
            #
            env = {funDef.argName: val} # Eager
            expr = funDef.body
            jitdriver.can_enter_jit(expr=expr, funDict=funDict, env=env)
            return Interpret(expr, funDict, env)
        #
        else:
            return 2
    #
    elif isinstance(expr, treeClass.If):
        condition = Interpret(expr.cond, funDict, env)
        if condition != 0: #True
            return Interpret(expr.ctrue, funDict, env)
        else:
            return Interpret(expr.cfalse, funDict, env)
    #
    else: # Not an <ifF1WAE>
        print("Argument of Interpret is not a <ifF1WAE>:\n")
        return 2  
예제 #28
0
 def main(n):
     set_param(None, 'threshold', 3)
     set_param(None, 'trace_eagerness', 5)            
     return f("c-l", n)
예제 #29
0
 def main(c, i, _set_param, v):
     if _set_param:
         set_param(driver, 'function_threshold', 0)
     portal(c, i, v)