<commit_before>from pycket.expand import load_json_ast_rpython
from pycket.interpreter import interpret_one
from pycket.error import SchemeException

from rpython.rlib import jit

def main(argv):
    jit.set_param(None, "trace_limit", 20000)
    # XXX crappy argument handling
    try:
        index = argv.index("--jit")
    except ValueError:
        pass
    else:
        if index == len(argv) - 1:
            print "missing argument after --jit"
            return 2
        jitarg = argv[index + 1]
        del argv[index:index+2]
        jit.set_user_param(None, jitarg)

    if len(argv) != 2:
        print "need exactly one argument, the json file to run"
        return 3
    ast = load_json_ast_rpython(argv[1])
    try:
        val = interpret_one(ast)
    except SchemeException, e:
        print "ERROR:", e.msg
        raise # to see interpreter-level traceback
    else:
        print val.tostring()
        return 0

def target(*args):
    return main

if __name__ == '__main__':
    import sys
    main(sys.argv)<commit_msg>Add auto-pdb fallback when not in translated mode for target<commit_after>from pycket.expand import load_json_ast_rpython
from pycket.interpreter import interpret_one
from pycket.error import SchemeException

from rpython.rlib import jit

from rpython.rlib.objectmodel import we_are_translated

def main(argv):
    jit.set_param(None, "trace_limit", 20000)
    # XXX crappy argument handling
    try:
        index = argv.index("--jit")
    except ValueError:
        pass
    else:
        if index == len(argv) - 1:
            print "missing argument after --jit"
            return 2
        jitarg = argv[index + 1]
        del argv[index:index+2]
        jit.set_user_param(None, jitarg)

    if len(argv) != 2:
        print "need exactly one argument, the json file to run"
        return 3
    ast = load_json_ast_rpython(argv[1])
    try:
        val = interpret_one(ast)
    except SchemeException, e:
        print "ERROR:", e.msg
        raise # to see interpreter-level traceback
    else:
        print val.tostring()
        return 0

def target(*args):
    return main

if __name__ == '__main__':
    assert not we_are_translated()
    from rpython.translator.driver import TranslationDriver
    f, _ = target(TranslationDriver(), sys.argv)
    try:
        sys.exit(f(sys.argv))
    except SystemExit:
        pass
    except:
        import pdb, traceback
        _type, value, tb = sys.exc_info()
        traceback.print_exception(_type, value, tb)
        pdb.post_mortem(tb)
{'fraction_non_alphanumeric': 0.08740157480314961, 'fraction_numerical': 0.010236220472440945, 'mean_word_length': 2.4808219178082194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5073189', 'n_tokens_mistral': 818, 'n_tokens_neox': 781, 'n_words': 228}