<commit_before><commit_msg>added rpython entry-point<commit_after>"""
Dipper entry-point script
"""
from rpython.rlib.objectmodel import we_are_translated

if we_are_translated():
    from rpython.rlib.streamio import open_file_as_stream
    from rpython.jit.codewriter.policy import JitPolicy

from dip import parser, compiler, interpreter


if we_are_translated():
    def readfile(filename):
        f = open_file_as_stream(argv[1])
        data = f.readall()
        f.close()
else:
    def readfile(filename):
        f = open(argv[1])
        data = f.read()
        f.close()


def main(argv):
    if not len(argv) == 2:
        print "Usage: %s <filename>.dip\n" % argv[0]
        return 1

    data = readfile(argv[1])

    dip = parser.DipperParser(debug=False)

    #print "=============== code ==================="
    # just a debugging step so we can see the same input the parser sees
    #print dip._prepSource(data)

    #print "============== parsing ================="
    tree = dip.parse(data)
    #print tree.show()

    #print "============= compiling ================"

    args = []
    for arg in argv[1:]:
        args.append(arg)

    vm = interpreter.VirtualMachine(args, debug=False)

    for node in tree:
        assert node.type == "Function"
        ctx = compiler.FrameCompiler(node)
        #print ctx
        vm.addfunc(ctx)

    #print "============= executing ================"
    vm.run()

    return 0


if we_are_translated():
    def target(driver, args):
        return main, None

    def jitpolicy(driver):
        return JitPolicy()
        

# this only runs if the script is being run from a regular Python interpreter,
# so just call the RPython main function
if __name__ == '__main__':
    import sys
    main(sys.argv)
{'fraction_non_alphanumeric': 0.16600790513833993, 'fraction_numerical': 0.004517221908526256, 'mean_word_length': 2.911699779249448, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4567373', 'n_tokens_mistral': 559, 'n_tokens_neox': 520, 'n_words': 151}