Example #1
0
def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
            annotatorpolicy=None):
    if argtypes is not None and "__pypy__" in sys.builtin_module_names:
        py.test.skip("requires building cpython extension modules")
    t = Translation(fn, argtypes, gc=gcpolicy, backend="c",
                    policy=annotatorpolicy)
    if not backendopt:
        t.disable(["backendopt_lltype"])
    t.annotate()
    # XXX fish
    t.driver.config.translation.countmallocs = True
    compiled_fn = t.compile_c()
    try:
        if py.test.config.option.view:
            t.view()
    except AttributeError:
        pass
    malloc_counters = t.driver.cbuilder.get_malloc_counters()
    def checking_fn(*args, **kwds):
        if 'expected_extra_mallocs' in kwds:
            expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
        else:
            expected_extra_mallocs = 0
        res = compiled_fn(*args, **kwds)
        mallocs, frees = malloc_counters()
        if isinstance(expected_extra_mallocs, int):
            assert mallocs - frees == expected_extra_mallocs
        else:
            assert mallocs - frees in expected_extra_mallocs
        return res
    return checking_fn
Example #2
0
def test_translate_compiled_parser():
    r0 = Rule("expression", [["additive", "EOF"]])
    r1 = Rule("additive", [["multitive", "+", "additive"], ["multitive"]])
    r2 = Rule("multitive", [["primary", "*", "multitive"], ["primary"]])
    r3 = Rule("primary", [["(", "additive", ")"], ["decimal"]])
    r4 = Rule("decimal", [[symb] for symb in "0123456789"])
    p = PackratParser([r0, r1, r2, r3, r4], "expression")
    compiler = ParserCompiler(p)
    kls = compiler.compile()
    p = kls()
    tree = p.parse([
        Token(c, i, SourcePos(i, 0, i))
        for i, c in enumerate(list("2*(3+4)") + ["EOF"])
    ])
    data = [
        Token(c, i, SourcePos(i, 0, i))
        for i, c in enumerate(list("2*(3+4)") + ["EOF"])
    ]
    print tree
    p = kls()

    def parse(choose):
        tree = p.parse(data)
        return tree.symbol + " " + "-%-".join(
            [c.symbol for c in tree.children])

    t = Translation(parse)
    t.annotate([bool])
    t.backendopt()
    t.rtype()
    func = t.compile_c()
    res1 = parse(True)
    res2 = func(True)
    assert res1 == res2
Example #3
0
def test_translate_pypackrat_regex():
    from pypy.rlib.parsing.pypackrat import PackratParser

    class parser(PackratParser):
        """
        num:
            `([1-9][0-9]*)|0`;
        """

    print parser._code

    def parse(s):
        p = parser(s)
        return p.num()

    res = parse("1234")
    assert res == '1234'
    t = Translation(parse)
    t.annotate([str])
    t.rtype()
    t.backendopt()
    if option.view:
        t.view()
    func = t.compile_c()
    res = func("12345")
    assert res == '12345'
    res = func("0")
    assert res == '0'
Example #4
0
def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
            annotatorpolicy=None):
    t = Translation(fn, argtypes, gc=gcpolicy, backend="c",
                    policy=annotatorpolicy)
    if not backendopt:
        t.disable(["backendopt_lltype"])
    t.annotate()
    # XXX fish
    t.driver.config.translation.countmallocs = True
    compiled_fn = t.compile_c()
    if getattr(py.test.config.option, 'view', False):
        t.view()
    malloc_counters = t.driver.cbuilder.get_malloc_counters()
    def checking_fn(*args, **kwds):
        if 'expected_extra_mallocs' in kwds:
            expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
        else:
            expected_extra_mallocs = 0
        res = compiled_fn(*args, **kwds)
        mallocs, frees = malloc_counters()
        if isinstance(expected_extra_mallocs, int):
            assert mallocs - frees == expected_extra_mallocs
        else:
            assert mallocs - frees in expected_extra_mallocs
        return res
    return checking_fn
Example #5
0
def test_translate_compiled_parser():
    r0 = Rule("expression", [["additive", "EOF"]])
    r1 = Rule("additive", [["multitive", "+", "additive"], ["multitive"]])
    r2 = Rule("multitive", [["primary", "*", "multitive"], ["primary"]])
    r3 = Rule("primary", [["(", "additive", ")"], ["decimal"]])
    r4 = Rule("decimal", [[symb] for symb in "0123456789"])
    p = PackratParser([r0, r1, r2, r3, r4], "expression")
    compiler = ParserCompiler(p)
    kls = compiler.compile()
    p = kls()
    tree = p.parse([Token(c, i, SourcePos(i, 0, i))
                        for i, c in enumerate(list("2*(3+4)") + ["EOF"])])
    data = [Token(c, i, SourcePos(i, 0, i))
               for i, c in enumerate(list("2*(3+4)") + ["EOF"])]
    print tree
    p = kls()
    def parse(choose):
        tree = p.parse(data)
        return tree.symbol + " " + "-%-".join([c.symbol for c in tree.children])
    t = Translation(parse)
    t.annotate([bool])
    t.backendopt()
    t.rtype()
    func = t.compile_c()
    res1 = parse(True)
    res2 = func(True)
    assert res1 == res2
Example #6
0
def test_translate_ast_visitor():
    from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
    regexs, rules, ToAST = parse_ebnf("""
DECIMAL: "0|[1-9][0-9]*";
IGNORE: " ";
additive: multitive ["+!"] additive | <multitive>;
multitive: primary ["*!"] multitive | <primary>; #nonsense!
primary: "(" <additive> ")" | <DECIMAL>;
""")
    parse = make_parse_function(regexs, rules)

    def f():
        tree = parse("(0 +! 10) *! (999 +! 10) +! 1")
        tree = ToAST().visit_additive(tree)
        assert len(tree) == 1
        tree = tree[0]
        return tree.symbol + " " + "-&-".join(
            [c.symbol for c in tree.children])

    res1 = f()
    t = Translation(f)
    t.annotate()
    t.rtype()
    t.backendopt()
    func = t.compile_c()
    res2 = func()
    assert res1 == res2
Example #7
0
def compile(fn,
            argtypes,
            view=False,
            gcpolicy="ref",
            backendopt=True,
            annotatorpolicy=None):
    t = Translation(fn,
                    argtypes,
                    gc=gcpolicy,
                    backend="c",
                    policy=annotatorpolicy)
    if not backendopt:
        t.disable(["backendopt_lltype"])
    t.annotate()
    # XXX fish
    t.driver.config.translation.countmallocs = True
    compiled_fn = t.compile_c()
    if getattr(py.test.config.option, 'view', False):
        t.view()
    malloc_counters = t.driver.cbuilder.get_malloc_counters()

    def checking_fn(*args, **kwds):
        if 'expected_extra_mallocs' in kwds:
            expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
        else:
            expected_extra_mallocs = 0
        res = compiled_fn(*args, **kwds)
        mallocs, frees = malloc_counters()
        if isinstance(expected_extra_mallocs, int):
            assert mallocs - frees == expected_extra_mallocs
        else:
            assert mallocs - frees in expected_extra_mallocs
        return res

    return checking_fn
Example #8
0
 def test_translate_simple(self):
     digits = RangeExpression("0", "9")
     lower = RangeExpression("a", "z")
     upper = RangeExpression("A", "Z")
     keywords = StringExpression("if") | StringExpression("else") | StringExpression("def") | StringExpression("class")
     underscore = StringExpression("_")
     atoms = lower + (upper | lower | digits | underscore).kleene()
     vars = underscore | (upper + (upper | lower | underscore | digits).kleene())
     integers = StringExpression("0") | (RangeExpression("1", "9") + digits.kleene())
     white = StringExpression(" ")
     l1 = self.get_lexer([keywords, atoms, vars, integers, white], ["KEYWORD", "ATOM", "VAR", "INT", "WHITE"])
     l2 = self.get_lexer([keywords, atoms, vars, integers, white], ["KEYWORD", "ATOM", "VAR", "INT", "WHITE"], ["WHITE"])
     def lex(s, ignore=False):
         if ignore:
             tokens = l2.tokenize(s)
         else:
             tokens = l1.tokenize(s)
         return "-%-".join([t.name for t in tokens])
     res = lex("if A a 12341 0 else").split("-%-")
     assert res == ("KEYWORD WHITE VAR WHITE ATOM WHITE INT WHITE "
                    "INT WHITE KEYWORD").split()
     res = lex("if A a 12341 0 else", True).split("-%-")
     assert res == "KEYWORD VAR ATOM INT INT KEYWORD".split()
     t = Translation(lex)
     t.annotate([str, bool])
     t.rtype()
     func = t.compile_c()
     res = lex("if A a 12341 0 else", False).split("-%-")
     assert res == ("KEYWORD WHITE VAR WHITE ATOM WHITE INT WHITE "
                    "INT WHITE KEYWORD").split()
     res = lex("if A a 12341 0 else", True).split("-%-")
     assert res == "KEYWORD VAR ATOM INT INT KEYWORD".split()
Example #9
0
def test_name():
    def f():
        return 3

    f.c_name = 'pypy_xyz_f'

    t = Translation(f, [], backend="c")
    t.annotate()
    compiled_fn = t.compile_c()
    if py.test.config.option.view:
        t.view()
    assert 'pypy_xyz_f' in t.driver.cbuilder.c_source_filename.read()
Example #10
0
def test_name():
    def f():
        return 3

    f.c_name = 'pypy_xyz_f'

    t = Translation(f, [], backend="c")
    t.annotate()
    compiled_fn = t.compile_c()
    if py.test.config.option.view:
        t.view()
    assert 'pypy_xyz_f' in t.driver.cbuilder.c_source_filename.read()
Example #11
0
def test_simple_source():
    def f(x, y):
        return x, y

    t = Translation(f, backend='c')
    t.annotate([int, int])
    t.source()
    assert 'source_c' in t.driver.done

    t = Translation(f, [int, int])
    t.source_c()
    assert 'source_c' in t.driver.done

    t = Translation(f, [int, int])
    py.test.raises(Exception, "t.source()")
Example #12
0
def test_simple_rtype():
    def f(x, y):
        return x + y

    t = Translation(f, [int, int])
    s = t.annotate()
    t.rtype()

    assert "rtype_lltype" in t.driver.done

    t = Translation(f)
    s = t.annotate([int, int])
    t.rtype()

    assert "rtype_lltype" in t.driver.done
Example #13
0
def test_simple_rtype():
    def f(x, y):
        return x + y

    t = Translation(f, [int, int])
    s = t.annotate()
    t.rtype()

    assert 'rtype_lltype' in t.driver.done

    t = Translation(f)
    s = t.annotate([int, int])
    t.rtype()

    assert 'rtype_lltype' in t.driver.done
Example #14
0
def test_exportstruct():
    from pypy.rlib.exports import export_struct
    def f():
        return 42
    FOO = Struct("FOO", ("field1", Signed))
    foo = malloc(FOO, flavor="raw")
    foo.field1 = 43
    export_struct("BarStruct", foo._obj)
    t = Translation(f, [], backend="c")
    t.annotate()
    compiled_fn = t.compile_c()
    if py.test.config.option.view:
        t.view()
    assert ' BarStruct ' in t.driver.cbuilder.c_source_filename.read()
    free(foo, flavor="raw")
Example #15
0
def test_entrypoints():
    def f():
        return 3

    key = "test_entrypoints42"
    @entrypoint(key, [int], "foobar")
    def g(x):
        return x + 42

    t = Translation(f, [], backend="c", secondaryentrypoints="test_entrypoints42")
    t.annotate()
    compiled_fn = t.compile_c()
    if py.test.config.option.view:
        t.view()
    assert 'foobar' in t.driver.cbuilder.c_source_filename.read()
def test_simple_source():
    def f(x, y):
        return x,y

    t = Translation(f, backend='c')
    t.annotate([int, int])
    t.source()
    assert 'source_c' in t.driver.done

    t = Translation(f, [int, int])
    t.source_c()
    assert 'source_c' in t.driver.done

    t = Translation(f, [int, int])
    py.test.raises(Exception, "t.source()")
Example #17
0
def test_exportstruct():
    from pypy.rlib.exports import export_struct

    def f():
        return 42

    FOO = Struct("FOO", ("field1", Signed))
    foo = malloc(FOO, flavor="raw")
    foo.field1 = 43
    export_struct("BarStruct", foo._obj)
    t = Translation(f, [], backend="c")
    t.annotate()
    compiled_fn = t.compile_c()
    if py.test.config.option.view:
        t.view()
    assert ' BarStruct ' in t.driver.cbuilder.c_source_filename.read()
    free(foo, flavor="raw")
def test_parser():
    def f(x):
        if x:
            s = "a(X, Y, Z)."
        else:
            s = "f(a, X, _, _, X, f(X, 2.455))."
        term = parsing.parse_file(s)
        assert isinstance(term, parsing.Nonterminal)
        return term.symbol
    assert f(True) == "file"
    assert f(True) == "file"
    t = Translation(f)
    t.annotate([bool])
    t.rtype()
    t.backendopt()
    func = t.compile_c()
    assert func(True) == "file"
    assert func(False) == "file"
Example #19
0
def test_entrypoints():
    def f():
        return 3

    key = "test_entrypoints42"

    @entrypoint(key, [int], "foobar")
    def g(x):
        return x + 42

    t = Translation(f, [],
                    backend="c",
                    secondaryentrypoints="test_entrypoints42")
    t.annotate()
    compiled_fn = t.compile_c()
    if py.test.config.option.view:
        t.view()
    assert 'foobar' in t.driver.cbuilder.c_source_filename.read()
Example #20
0
def test_parser():
    def f(x):
        if x:
            s = "a(X, Y, Z)."
        else:
            s = "f(a, X, _, _, X, f(X, 2.455))."
        term = parsing.parse_file(s)
        assert isinstance(term, parsing.Nonterminal)
        return term.symbol

    assert f(True) == "file"
    assert f(True) == "file"
    t = Translation(f)
    t.annotate([bool])
    t.rtype()
    t.backendopt()
    func = t.compile_c()
    assert func(True) == "file"
    assert func(False) == "file"
Example #21
0
def test_simple_annotate():
    def f(x, y):
        return x + y

    t = Translation(f, [int, int])
    assert t.context is t.driver.translator
    assert t.config is t.driver.config is t.context.config

    s = t.annotate([int, int])
    assert s.knowntype == int

    t = Translation(f, [int, int])
    s = t.annotate()
    assert s.knowntype == int

    t = Translation(f)
    s = t.annotate([int, int])
    assert s.knowntype == int

    t = Translation(f, [int, int])
    py.test.raises(Exception, "t.annotate([int, float])")
Example #22
0
def test_simple_annotate():
    def f(x, y):
        return x + y

    t = Translation(f, [int, int])
    assert t.context is t.driver.translator
    assert t.config is t.driver.config is t.context.config

    s = t.annotate([int, int])
    assert s.knowntype == int

    t = Translation(f, [int, int])
    s = t.annotate()
    assert s.knowntype == int

    t = Translation(f)
    s = t.annotate([int, int])
    assert s.knowntype == int

    t = Translation(f, [int, int])
    py.test.raises(Exception, "t.annotate([int, float])")
Example #23
0
    def test_translate_simple(self):
        digits = RangeExpression("0", "9")
        lower = RangeExpression("a", "z")
        upper = RangeExpression("A", "Z")
        keywords = StringExpression("if") | StringExpression(
            "else") | StringExpression("def") | StringExpression("class")
        underscore = StringExpression("_")
        atoms = lower + (upper | lower | digits | underscore).kleene()
        vars = underscore | (upper +
                             (upper | lower | underscore | digits).kleene())
        integers = StringExpression("0") | (RangeExpression("1", "9") +
                                            digits.kleene())
        white = StringExpression(" ")
        l1 = self.get_lexer([keywords, atoms, vars, integers, white],
                            ["KEYWORD", "ATOM", "VAR", "INT", "WHITE"])
        l2 = self.get_lexer([keywords, atoms, vars, integers, white],
                            ["KEYWORD", "ATOM", "VAR", "INT", "WHITE"],
                            ["WHITE"])

        def lex(s, ignore=False):
            if ignore:
                tokens = l2.tokenize(s)
            else:
                tokens = l1.tokenize(s)
            return "-%-".join([t.name for t in tokens])

        res = lex("if A a 12341 0 else").split("-%-")
        assert res == ("KEYWORD WHITE VAR WHITE ATOM WHITE INT WHITE "
                       "INT WHITE KEYWORD").split()
        res = lex("if A a 12341 0 else", True).split("-%-")
        assert res == "KEYWORD VAR ATOM INT INT KEYWORD".split()
        t = Translation(lex)
        t.annotate([str, bool])
        t.rtype()
        func = t.compile_c()
        res = lex("if A a 12341 0 else", False).split("-%-")
        assert res == ("KEYWORD WHITE VAR WHITE ATOM WHITE INT WHITE "
                       "INT WHITE KEYWORD").split()
        res = lex("if A a 12341 0 else", True).split("-%-")
        assert res == "KEYWORD VAR ATOM INT INT KEYWORD".split()
Example #24
0
def test_translate_pypackrat():
    from pypy.rlib.parsing.pypackrat import PackratParser

    class parser(PackratParser):
        """
        expr:
            additive;
        additive:
            a = additive
            '-'
            b = multitive
            return {'(%s - %s)' % (a, b)}
          | multitive;
        multitive:
            a = multitive
            '*'
            b = simple
            return {'(%s * %s)' % (a, b)}
          | simple;
        simple:
            ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9');
        """

    print parser._code

    def parse(s):
        p = parser(s)
        return p.expr()

    res = parse("5-5-5")
    assert res == '((5 - 5) - 5)'
    t = Translation(parse)
    t.annotate([str])
    t.rtype()
    t.backendopt()
    if option.view:
        t.view()
    func = t.compile_c()
    res = func("5-5-5")
    assert res == '((5 - 5) - 5)'
Example #25
0
def compile(fn,
            argtypes,
            view=False,
            gcpolicy="ref",
            backendopt=True,
            annotatorpolicy=None):
    if argtypes is not None and "__pypy__" in sys.builtin_module_names:
        py.test.skip("requires building cpython extension modules")
    t = Translation(fn,
                    argtypes,
                    gc=gcpolicy,
                    backend="c",
                    policy=annotatorpolicy)
    if not backendopt:
        t.disable(["backendopt_lltype"])
    t.annotate()
    # XXX fish
    t.driver.config.translation.countmallocs = True
    compiled_fn = t.compile_c()
    try:
        if py.test.config.option.view:
            t.view()
    except AttributeError:
        pass
    malloc_counters = t.driver.cbuilder.get_malloc_counters()

    def checking_fn(*args, **kwds):
        if 'expected_extra_mallocs' in kwds:
            expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
        else:
            expected_extra_mallocs = 0
        res = compiled_fn(*args, **kwds)
        mallocs, frees = malloc_counters()
        if isinstance(expected_extra_mallocs, int):
            assert mallocs - frees == expected_extra_mallocs
        else:
            assert mallocs - frees in expected_extra_mallocs
        return res

    return checking_fn
def test_engine():
    e = get_engine("""
        g(a, a).
        g(a, b).
        g(b, c).
        f(X, Z) :- g(X, Y), g(Y, Z).
    """)
    t1 = parse_query_term("f(a, c).")
    t2 = parse_query_term("f(X, c).")
    def run():
        e.run(t1)
        e.run(t2)
        v0 = e.heap.getvar(0)
        if isinstance(v0, Atom):
            return v0.name
        return "no!"
    assert run() == "a"
    t = Translation(run)
    t.annotate()
    t.rtype()
    func = t.compile_c()
    assert func() == "a"
Example #27
0
def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
            annotatorpolicy=None):
    t = Translation(fn, argtypes, gc=gcpolicy, backend="c",
                    policy=annotatorpolicy)
    if not backendopt:
        t.disable(["backendopt_lltype"])
    t.annotate()
    # XXX fish
    t.driver.config.translation.countmallocs = True
    compiled_fn = t.compile_c()
    if conftest.option.view:
        t.view()
    # XXX fish fish fish some more
    module = t.driver.cbuilder.c_ext_module
    def checking_fn(*args, **kwds):
        if 'expected_extra_mallocs' in kwds:
            expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
        else:
            expected_extra_mallocs = 0
        res = compiled_fn(*args, **kwds)
        mallocs, frees = module.malloc_counters()
        assert mallocs - frees == expected_extra_mallocs
        return res
    return checking_fn
Example #28
0
def test_engine():
    e = get_engine("""
        g(a, a).
        g(a, b).
        g(b, c).
        f(X, Z) :- g(X, Y), g(Y, Z).
    """)
    t1 = parse_query_term("f(a, c).")
    t2 = parse_query_term("f(X, c).")

    def run():
        e.run(t1)
        e.run(t2)
        v0 = e.heap.getvar(0)
        if isinstance(v0, Atom):
            return v0.name
        return "no!"

    assert run() == "a"
    t = Translation(run)
    t.annotate()
    t.rtype()
    func = t.compile_c()
    assert func() == "a"
Example #29
0
def test_translate_pypackrat_regex():
    from pypy.rlib.parsing.pypackrat import PackratParser
    class parser(PackratParser):
        """
        num:
            `([1-9][0-9]*)|0`;
        """
    print parser._code
    def parse(s):
        p = parser(s)
        return p.num()
    res = parse("1234")
    assert res == '1234'
    t = Translation(parse)
    t.annotate([str])
    t.rtype()
    t.backendopt()
    if option.view:
        t.view()
    func = t.compile_c()
    res = func("12345")
    assert res == '12345'
    res = func("0")
    assert res == '0'
Example #30
0
def test_translate_ast_visitor():
    from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
    regexs, rules, ToAST = parse_ebnf("""
DECIMAL: "0|[1-9][0-9]*";
IGNORE: " ";
additive: multitive ["+!"] additive | <multitive>;
multitive: primary ["*!"] multitive | <primary>; #nonsense!
primary: "(" <additive> ")" | <DECIMAL>;
""")
    parse = make_parse_function(regexs, rules)
    def f():
        tree = parse("(0 +! 10) *! (999 +! 10) +! 1")
        tree = ToAST().visit_additive(tree)
        assert len(tree) == 1
        tree = tree[0]
        return tree.symbol + " " + "-&-".join([c.symbol for c in tree.children])
    res1 = f()
    t = Translation(f)
    t.annotate()
    t.rtype()
    t.backendopt()
    func = t.compile_c()
    res2 = func()
    assert res1 == res2
Example #31
0
def test_translate_pypackrat():
    from pypy.rlib.parsing.pypackrat import PackratParser
    class parser(PackratParser):
        """
        expr:
            additive;
        additive:
            a = additive
            '-'
            b = multitive
            return {'(%s - %s)' % (a, b)}
          | multitive;
        multitive:
            a = multitive
            '*'
            b = simple
            return {'(%s * %s)' % (a, b)}
          | simple;
        simple:
            ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9');
        """
    print parser._code
    def parse(s):
        p = parser(s)
        return p.expr()
    res = parse("5-5-5")
    assert res == '((5 - 5) - 5)'
    t = Translation(parse)
    t.annotate([str])
    t.rtype()
    t.backendopt()
    if option.view:
        t.view()
    func = t.compile_c()
    res = func("5-5-5")
    assert res == '((5 - 5) - 5)'
def test_simple_rtype_with_type_system():

    def f(x,y):
        return x+y

    t = Translation(f, [int, int])
    s = t.annotate()
    t.rtype(type_system='lltype')

    assert 'rtype_lltype' in t.driver.done    

    t = Translation(f, [int, int])
    s = t.annotate()
    t.rtype(type_system='ootype')
    assert 'rtype_ootype' in t.driver.done        

    t = Translation(f, type_system='ootype')
    s = t.annotate([int, int])
    t.rtype()
    assert 'rtype_ootype' in t.driver.done    

    t = Translation(f)
    s = t.annotate([int, int])
    t.rtype(backend='cli')
    assert 'rtype_ootype' in t.driver.done


    t = Translation(f, backend='cli', type_system='ootype')
    s = t.annotate([int, int])
    t.rtype()
    assert 'rtype_ootype' in t.driver.done        

    t = Translation(f, type_system='lltype')
    s = t.annotate([int, int])
    py.test.raises(Exception, "t.rtype(backend='cli')")

    t = Translation(f, backend='cli')
    s = t.annotate([int, int])
    py.test.raises(Exception, "t.rtype(type_system='lltype')")
Example #33
0
def test_simple_rtype_with_type_system():
    def f(x, y):
        return x + y

    t = Translation(f, [int, int])
    s = t.annotate()
    t.rtype(type_system='lltype')

    assert 'rtype_lltype' in t.driver.done

    t = Translation(f, [int, int])
    s = t.annotate()
    t.rtype(type_system='ootype')
    assert 'rtype_ootype' in t.driver.done

    t = Translation(f, type_system='ootype')
    s = t.annotate([int, int])
    t.rtype()
    assert 'rtype_ootype' in t.driver.done

    t = Translation(f)
    s = t.annotate([int, int])
    t.rtype(backend='cli')
    assert 'rtype_ootype' in t.driver.done

    t = Translation(f, backend='cli', type_system='ootype')
    s = t.annotate([int, int])
    t.rtype()
    assert 'rtype_ootype' in t.driver.done

    t = Translation(f, type_system='lltype')
    s = t.annotate([int, int])
    py.test.raises(Exception, "t.rtype(backend='cli')")

    t = Translation(f, backend='cli')
    s = t.annotate([int, int])
    py.test.raises(Exception, "t.rtype(type_system='lltype')")
Example #34
0
        return True


if '--subprocess' in sys.argv:
    os.putenv('SDL_WINDOWID', sys.argv[-1])

    def pypy_entry_point():
        def jitpolicy(*args):
            from pypy.jit.metainterp.policy import JitPolicy
            return JitPolicy()

        brain = Brain()
        brain.loop()

    if '--pypy' in sys.argv:
        from pypy.translator.interactive import Translation
        t = Translation(pypy_entry_point)
        ## NotImplementedError: --gcrootfinder=asmgcc requires standalone ##
        #t.config.translation.suggest(jit=True, jit_debug='steps', jit_backend='x86', gc='boehm')
        t.annotate()
        t.rtype()
        f = t.compile_c()
        f()
    else:
        pypy_entry_point()

else:
    a = App()
    gtk.main()
    print '-------------------exit toplevel-----------------'
Example #35
0
    # create a network with two input, two hidden, and two output nodes
    n = NN(2, 3, 1)
    # train it with some patterns
    n.train(pat, 2000)
    # test it
    n.test(pat)



if __name__ == '__main__':
    print 'Loading...'
    from pypy.translator.interactive import Translation
    t = Translation(demo)
    
    print 'Annotating...'
    t.annotate([])
    t.viewcg()

    print 'Specializing...'
    t.rtype()   # enable this to see (some) lower-level Cish operations
    
    print 'Compiling...'
    f = t.compile_c()

    print 'Running...'
    T = time.time()
    for i in range(10):
        f()
    t1 = time.time() - T
    print "that took", t1
Example #36
0
def test_annotated():
    from pypy.translator.interactive import Translation
    t = Translation(is_prime)
    t.annotate([int])
    t.viewcg()
Example #37
0
def test_annotated():
    from pypy.translator.interactive import Translation
    t = Translation(is_prime)
    t.annotate([int])
    t.viewcg()
						func = getattr(self, func)
						func( eval(arg) )
		return True


if '--subprocess' in sys.argv:
	os.putenv('SDL_WINDOWID', sys.argv[-1])
	def pypy_entry_point():
		def jitpolicy(*args):
			from pypy.jit.metainterp.policy import JitPolicy
			return JitPolicy()

		brain = Brain()
		brain.loop()
	if '--pypy' in sys.argv:
		from pypy.translator.interactive import Translation
		t = Translation( pypy_entry_point )
		## NotImplementedError: --gcrootfinder=asmgcc requires standalone ##
		#t.config.translation.suggest(jit=True, jit_debug='steps', jit_backend='x86', gc='boehm')
		t.annotate()
		t.rtype()
		f = t.compile_c()
		f()
	else:
		pypy_entry_point()

else:
	a = App()
	gtk.main()
	print '-------------------exit toplevel-----------------'
Example #39
0
    # create a network with two input, two hidden, and two output nodes
    n = NN(2, 3, 1)
    # train it with some patterns
    n.train(pat, 2000)
    # test it
    n.test(pat)


if __name__ == '__main__':
    print 'Loading...'
    from pypy.translator.interactive import Translation
    t = Translation(demo)

    print 'Annotating...'
    t.annotate([])
    t.viewcg()

    print 'Specializing...'
    t.rtype()  # enable this to see (some) lower-level Cish operations

    print 'Compiling...'
    f = t.compile_c()

    print 'Running...'
    T = time.time()
    for i in range(10):
        f()
    t1 = time.time() - T
    print "that took", t1