Esempio n. 1
0
def fatalerror(msg):
    # print the RPython traceback and abort with a fatal error
    if not we_are_translated():
        raise FatalError(msg)
    from rpython.rtyper.lltypesystem import lltype
    from rpython.rtyper.lltypesystem.lloperation import llop
    llop.debug_print_traceback(lltype.Void)
    llop.debug_fatalerror(lltype.Void, msg)
Esempio n. 2
0
def fatalerror(msg):
    # print the RPython traceback and abort with a fatal error
    if not we_are_translated():
        raise FatalError(msg)
    from rpython.rtyper.lltypesystem import lltype
    from rpython.rtyper.lltypesystem.lloperation import llop
    llop.debug_print_traceback(lltype.Void)
    llop.debug_fatalerror(lltype.Void, msg)
Esempio n. 3
0
def entry_point(argv):
    repl_env = Env()

    def REP(str, env):
        return PRINT(EVAL(READ(str), env))

    # core.py: defined using python
    for k, v in core.ns.items():
        repl_env.set(_symbol(unicode(k)), MalFunc(v))
    repl_env.set(types._symbol(u'eval'),
                 MalEval(None, env=repl_env, EvalFunc=EVAL))
    mal_args = []
    if len(argv) >= 3:
        for a in argv[2:]:
            mal_args.append(MalStr(unicode(a)))
    repl_env.set(_symbol(u'*ARGV*'), MalList(mal_args))

    # core.mal: defined using the language itself
    REP("(def! *host-language* \"rpython\")", repl_env)
    REP("(def! not (fn* (a) (if a false true)))", repl_env)
    REP(
        "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))",
        repl_env)
    REP(
        "(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))",
        repl_env)
    REP("(def! inc (fn* [x] (+ x 1)))", repl_env)
    REP(
        "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))",
        repl_env)
    REP(
        "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))",
        repl_env)

    if len(argv) >= 2:
        REP('(load-file "' + argv[1] + '")', repl_env)
        return 0

    REP("(println (str \"Mal [\" *host-language* \"]\"))", repl_env)
    while True:
        try:
            line = mal_readline.readline("user> ")
            if line == "": continue
            print(REP(line, repl_env))
        except EOFError as e:
            break
        except reader.Blank:
            continue
        except types.MalException as e:
            print(u"Error: %s" % printer._pr_str(e.object, False))
        except Exception as e:
            print("Error: %s" % e)
            if IS_RPYTHON:
                llop.debug_print_traceback(lltype.Void)
            else:
                print("".join(traceback.format_exception(*sys.exc_info())))
    return 0
Esempio n. 4
0
def optimize_vector(trace, metainterp_sd, jitdriver_sd, warmstate,
                    loop_info, loop_ops, jitcell_token=None):
    """ Enter the world of SIMD. Bails if it cannot transform the trace. """
    user_code = not jitdriver_sd.vec and warmstate.vec_all
    e = len(loop_ops)-1
    assert e > 0
    assert rop.is_final(loop_ops[e].getopnum())
    loop = VectorLoop(loop_info.label_op, loop_ops[:e], loop_ops[-1])
    if user_code and user_loop_bail_fast_path(loop, warmstate):
        return loop_info, loop_ops
    # the original loop (output of optimize_unroll)
    info = LoopVersionInfo(loop_info)
    version = info.snapshot(loop)
    loop.setup_vectorization()
    try:
        debug_start("vec-opt-loop")
        metainterp_sd.logger_noopt.log_loop([], loop.finaloplist(label=True), -2, None, None, "pre vectorize")
        metainterp_sd.profiler.count(Counters.OPT_VECTORIZE_TRY)
        #
        start = time.clock()
        opt = VectorizingOptimizer(metainterp_sd, jitdriver_sd, warmstate.vec_cost)
        index_vars = opt.run_optimization(info, loop)
        gso = GuardStrengthenOpt(index_vars)
        gso.propagate_all_forward(info, loop, user_code)
        end = time.clock()
        #
        metainterp_sd.profiler.count(Counters.OPT_VECTORIZED)
        metainterp_sd.logger_noopt.log_loop([], loop.finaloplist(label=True), -2, None, None, "post vectorize")
        nano = int((end-start)*10.0**9)
        debug_print("# vecopt factor: %d opcount: (%d -> %d) took %dns" % \
                      (opt.unroll_count+1, len(version.loop.operations), len(loop.operations), nano))
        debug_stop("vec-opt-loop")
        #
        info.label_op = loop.label
        return info, loop.finaloplist(jitcell_token=jitcell_token, reset_label_token=False)
    except NotAVectorizeableLoop:
        debug_stop("vec-opt-loop")
        # vectorization is not possible
        return loop_info, version.loop.finaloplist()
    except NotAProfitableLoop:
        debug_stop("vec-opt-loop")
        # cost model says to skip this loop
        return loop_info, version.loop.finaloplist()
    except Exception as e:
        debug_stop("vec-opt-loop")
        debug_print("failed to vectorize loop. THIS IS A FATAL ERROR!")
        if we_are_translated():
            from rpython.rtyper.lltypesystem import lltype
            from rpython.rtyper.lltypesystem.lloperation import llop
            llop.debug_print_traceback(lltype.Void)
        else:
            raise
    finally:
        loop.teardown_vectorization()
    return loop_info, loop_ops
Esempio n. 5
0
def entry_point(argv):
    repl_env = Env()
    def REP(str, env):
        return PRINT(EVAL(READ(str), env))

    # core.py: defined using python
    for k, v in core.ns.items():
        repl_env.set(_symbol(unicode(k)), MalFunc(v))
    repl_env.set(types._symbol(u'eval'),
                 MalEval(None, env=repl_env, EvalFunc=EVAL))
    mal_args = []
    if len(argv) >= 3:
        for a in argv[2:]: mal_args.append(MalStr(unicode(a)))
    repl_env.set(_symbol(u'*ARGV*'), MalList(mal_args))

    # core.mal: defined using the language itself
    REP("(def! *host-language* \"rpython\")", repl_env)
    REP("(def! not (fn* (a) (if a false true)))", repl_env)
    REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env)
    REP("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))", repl_env)
    REP("(def! inc (fn* [x] (+ x 1)))", repl_env)
    REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", repl_env)
    REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env)

    if len(argv) >= 2:
        REP('(load-file "' + argv[1] + '")', repl_env)
        return 0

    REP("(println (str \"Mal [\" *host-language* \"]\"))", repl_env)
    while True:
        try:
            line = mal_readline.readline("user> ")
            if line == "": continue
            print(REP(line, repl_env))
        except EOFError as e:
            break
        except reader.Blank:
            continue
        except types.MalException as e:
            print(u"Error: %s" % printer._pr_str(e.object, False))
        except Exception as e:
            print("Error: %s" % e)
            if IS_RPYTHON:
                llop.debug_print_traceback(lltype.Void)
            else:
                print("".join(traceback.format_exception(*sys.exc_info())))
    return 0
Esempio n. 6
0
 def recovery():
     llop.debug_print_traceback(lltype.Void)
Esempio n. 7
0
 def recovery():
     llop.debug_print_traceback(lltype.Void)
Esempio n. 8
0
def debug_print_traceback():
    # print to stderr the RPython traceback of the last caught exception,
    # but without interrupting the program
    from rpython.rtyper.lltypesystem import lltype
    from rpython.rtyper.lltypesystem.lloperation import llop
    llop.debug_print_traceback(lltype.Void)
Esempio n. 9
0
def debug_print_traceback():
    # print to stderr the RPython traceback of the last caught exception,
    # but without interrupting the program
    from rpython.rtyper.lltypesystem import lltype
    from rpython.rtyper.lltypesystem.lloperation import llop
    llop.debug_print_traceback(lltype.Void)