Exemplo n.º 1
0
def test_callgraph_reconstruction():
    from pycket.expand import expand_string, parse_module
    from pycket import config
    from pycket.callgraph import LOOP_PARTICIPANT, LOOP_HEADER
    from pycket.env import w_global_config as conf
    str = """
        #lang pycket
        (define (f x) (g (+ x 1)))
        (define (g x) (if (= x 0) (g 5) (h x)))
        (define (h x) x)
        (f 5)
        (f -1)
        """
    conf.reset_callgraph()
    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph": True}))
    m = interpret_module(ast, env)
    f = m.defs[W_Symbol.make("f")].closure.caselam.lams[0]
    g = m.defs[W_Symbol.make("g")].closure.caselam.lams[0]
    h = m.defs[W_Symbol.make("h")].closure.caselam.lams[0]

    assert conf.callgraph.calls == {f: {g: None}, g: {h: None, g: None}}
    assert g.body[0].should_enter

    str = """
        #lang pycket
        (define (f x) (g (+ x 1)))
        (define (g x) (if (= x 0) (f 5) (h x)))
        (define (h x) x)
        (g 0)
        """

    conf.reset_callgraph()

    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph": True}))
    m = interpret_module(ast, env)
    f = m.defs[W_Symbol.make("f")].closure.caselam.lams[0]
    g = m.defs[W_Symbol.make("g")].closure.caselam.lams[0]
    h = m.defs[W_Symbol.make("h")].closure.caselam.lams[0]

    assert conf.callgraph.calls == {f: {g: None}, g: {h: None, f: None}}
    assert (conf.callgraph.recursive == {
        f: LOOP_HEADER,
        g: LOOP_PARTICIPANT
    } or conf.callgraph.recursive == {
        f: LOOP_PARTICIPANT,
        g: LOOP_HEADER
    })
    assert g.body[0].should_enter or f.body[0].should_enter
    conf.reset_callgraph()
Exemplo n.º 2
0
def test_cont_fusion():
    from pycket.env import SymList, ToplevelEnv
    from pycket.interpreter import (
        LetCont,
        BeginCont,
        FusedLet0Let0Cont,
        FusedLet0BeginCont,
    )
    from pycket.config import get_testing_config
    args = SymList([])
    counts = [1]
    rhss = 1
    letast1 = Let(args, counts, [1], [2])
    letast2 = Let(args, counts, [1], [2])
    env = ToplevelEnv(get_testing_config(**{"pycket.fuse_conts": True}))
    prev = object()
    let2 = LetCont.make([], letast2, 0, env, prev)
    let1 = LetCont.make([], letast1, 0, env, let2)
    assert isinstance(let1, FusedLet0Let0Cont)
    assert let1.prev is prev
    assert let1.env is env

    let2 = BeginCont(letast2.counting_asts[0], env, prev)
    let1 = LetCont.make([], letast1, 0, env, let2)
    assert isinstance(let1, FusedLet0BeginCont)
    assert let1.prev is prev
    assert let1.env is env
Exemplo n.º 3
0
def test_cont_fusion():
    from pycket.env import SymList, ToplevelEnv
    from pycket.interpreter import (
        LetCont, BeginCont,
        FusedLet0Let0Cont, FusedLet0BeginCont,
    )
    from pycket.config import get_testing_config
    args = SymList([])
    counts = [1]
    rhss = 1
    letast1 = Let(args, counts, [1], [2])
    letast2 = Let(args, counts, [1], [2])
    env = ToplevelEnv(get_testing_config(**{"pycket.fuse_conts": True}))
    prev = object()
    let2 = LetCont.make([], letast2, 0, env, prev)
    let1 = LetCont.make([], letast1, 0, env, let2)
    assert isinstance(let1, FusedLet0Let0Cont)
    assert let1.prev is prev
    assert let1.env is env

    let2 = BeginCont(letast2.counting_asts[0], env, prev)
    let1 = LetCont.make([], letast1, 0, env, let2)
    assert isinstance(let1, FusedLet0BeginCont)
    assert let1.prev is prev
    assert let1.env is env
Exemplo n.º 4
0
def test_callgraph_reconstruction():
    from pycket.expand    import expand_string, parse_module
    from pycket           import config
    from pycket.callgraph import LOOP_PARTICIPANT, LOOP_HEADER
    str = """
        #lang pycket
        (define (f x) (g (+ x 1)))
        (define (g x) (if (= x 0) (g 5) (h x)))
        (define (h x) x)
        (f 5)
        (f -1)
        """

    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph":True}))
    m = interpret_module(ast, env)
    f = m.defs[W_Symbol.make("f")].closure.caselam.lams[0]
    g = m.defs[W_Symbol.make("g")].closure.caselam.lams[0]
    h = m.defs[W_Symbol.make("h")].closure.caselam.lams[0]

    assert env.callgraph.calls == {f: {g: None}, g: {h: None, g: None}}
    assert g.body[0].should_enter

    str = """
        #lang pycket
        (define (f x) (g (+ x 1)))
        (define (g x) (if (= x 0) (f 5) (h x)))
        (define (h x) x)
        (g 0)
        """

    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph":True}))
    m = interpret_module(ast, env)
    f = m.defs[W_Symbol.make("f")].closure.caselam.lams[0]
    g = m.defs[W_Symbol.make("g")].closure.caselam.lams[0]
    h = m.defs[W_Symbol.make("h")].closure.caselam.lams[0]

    assert env.callgraph.calls == {f: {g: None}, g: {h: None, f: None}}
    assert (env.callgraph.recursive == {f: LOOP_HEADER, g: LOOP_PARTICIPANT} or
            env.callgraph.recursive == {f: LOOP_PARTICIPANT, g: LOOP_HEADER})
    assert g.body[0].should_enter or f.body[0].should_enter
Exemplo n.º 5
0
def test_callgraph_reconstruction():
    from pycket.expand import expand_string, parse_module
    from pycket import config
    str = """
        #lang pycket
        (define (f x) (g (+ x 1)))
        (define (g x) (if (= x 0) (g 5) (h x)))
        (define (h x) x)
        (f 5)
        (f -1)
        """

    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph": True}))
    m = interpret_module(ast, env)
    f = m.defs[W_Symbol.make("f")].closure.caselam.lams[0]
    g = m.defs[W_Symbol.make("g")].closure.caselam.lams[0]
    h = m.defs[W_Symbol.make("h")].closure.caselam.lams[0]

    assert env.callgraph.calls == {f: {g: None}, g: {h: None, g: None}}
    assert g.body[0].should_enter

    str = """
        #lang pycket
        (define (f x) (g (+ x 1)))
        (define (g x) (if (= x 0) (f 5) (h x)))
        (define (h x) x)
        (g 0)
        """

    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph": True}))
    m = interpret_module(ast, env)
    f = m.defs[W_Symbol.make("f")].closure.caselam.lams[0]
    g = m.defs[W_Symbol.make("g")].closure.caselam.lams[0]
    h = m.defs[W_Symbol.make("h")].closure.caselam.lams[0]

    assert env.callgraph.calls == {f: {g: None}, g: {h: None, f: None}}
    assert env.callgraph.recursive == {f: None, g: None}
    assert g.body[0].should_enter
Exemplo n.º 6
0
 def __init__(self, pycketconfig=None):
     from rpython.config.config import Config
     self.bindings = {}
     self.version = Version()
     self.module_env = ModuleEnv(self)
     self.commandline_arguments = []
     self.callgraph = CallGraph()
     self.globalconfig = GlobalConfig()
     if pycketconfig is None:
         assert not objectmodel.we_are_translated()
         pycketconfig = get_testing_config()
     assert isinstance(pycketconfig, Config)
     self._pycketconfig = pycketconfig
Exemplo n.º 7
0
Arquivo: env.py Projeto: pycket/pycket
 def __init__(self, pycketconfig=None):
     from rpython.config.config import Config
     self.bindings = {}
     self.version = w_version
     self.module_env = ModuleEnv(self)
     self.commandline_arguments = []
     self.callgraph = CallGraph()
     self.globalconfig = w_global_config
     if pycketconfig is None:
         assert not objectmodel.we_are_translated()
         pycketconfig = get_testing_config()
     assert isinstance(pycketconfig, Config)
     self._pycketconfig = pycketconfig
Exemplo n.º 8
0
def test_callgraph_reconstruction_through_primitives():
    from pycket.expand import expand_string, parse_module
    from pycket        import config
    str = """
        #lang pycket
        (define (f k) (k (apply h '(5))))
        (define (g x) (+ (call/cc f) 7))
        (define (h x) x)
        (g 5)
        """

    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph":True}))
    m = interpret_module(ast, env)
    f = m.defs[W_Symbol.make("f")].closure.caselam.lams[0]
    g = m.defs[W_Symbol.make("g")].closure.caselam.lams[0]
    h = m.defs[W_Symbol.make("h")].closure.caselam.lams[0]

    assert env.callgraph.calls == {g: {f: None}, f: {h: None}}
Exemplo n.º 9
0
def test_callgraph_reconstruction_through_primitives():
    from pycket.expand import expand_string, parse_module
    from pycket import config
    str = """
        #lang pycket
        (define (f k) (k (apply h '(5))))
        (define (g x) (+ (call-with-current-continuation f) 7))
        (define (h x) x)
        (g 5)
        """

    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph": True}))
    m = interpret_module(ast, env)
    f = m.defs[W_Symbol.make("f")].closure.caselam.lams[0]
    g = m.defs[W_Symbol.make("g")].closure.caselam.lams[0]
    h = m.defs[W_Symbol.make("h")].closure.caselam.lams[0]

    assert env.callgraph.calls == {g: {f: None}, f: {h: None}}
Exemplo n.º 10
0
def test_should_enter_downrecursion():
    from pycket.expand import expand_string, parse_module
    from pycket        import config
    str = """
        #lang pycket

        (define (append a b)
          (if (null? a)
              b
              (cons (car a) (append (cdr a) b))))
        (append (list 1 2 3 5 6 6 7 7 8 3 4 5 3 5 4 3 5 3 5 3 3 5 4 3) (list 4 5 6))

        (define (n->f n)
          (cond
           [(zero? n) (lambda (f) (lambda (x) x))]
           [else
            (define n-1 (n->f (- n 1)))
            (lambda (f)
               (define fn-1 (n-1 f))
               (lambda (x) (f (fn-1 x))))]))
        (n->f 10)


    """

    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph":True}))
    m = interpret_module(ast, env)
    append = m.defs[W_Symbol.make("append")].closure.caselam.lams[0]
    f = m.defs[W_Symbol.make("n->f")].closure.caselam.lams[0]

    assert env.callgraph.calls == {append: {append: None}, f: {f: None}}

    assert append.body[0].should_enter
    # This is long to account for let conversion
    assert append.body[0].els.body[0].should_enter

    assert f.body[0].should_enter
    assert f.body[0].els.body[0].should_enter
Exemplo n.º 11
0
def test_should_enter_downrecursion():
    from pycket.expand import expand_string, parse_module
    from pycket import config
    str = """
        #lang pycket

        (define (append a b)
          (if (null? a)
              b
              (cons (car a) (append (cdr a) b))))
        (append (list 1 2 3 5 6 6 7 7 8 3 4 5 3 5 4 3 5 3 5 3 3 5 4 3) (list 4 5 6))

        (define (n->f n)
          (cond
           [(zero? n) (lambda (f) (lambda (x) x))]
           [else
            (define n-1 (n->f (- n 1)))
            (lambda (f)
               (define fn-1 (n-1 f))
               (lambda (x) (f (fn-1 x))))]))
        (n->f 10)


    """

    ast = parse_module(expand_string(str))
    env = ToplevelEnv(config.get_testing_config(**{"pycket.callgraph": True}))
    m = interpret_module(ast, env)
    append = m.defs[W_Symbol.make("append")].closure.caselam.lams[0]
    f = m.defs[W_Symbol.make("n->f")].closure.caselam.lams[0]

    assert env.callgraph.calls == {append: {append: None}, f: {f: None}}

    assert append.body[0].should_enter
    # This is long to account for let conversion
    assert append.body[0].els.body[0].should_enter

    assert f.body[0].should_enter
    assert f.body[0].els.body[0].should_enter
Exemplo n.º 12
0
def inst(linkl, imports=[], target=None):
    if not target:
        target = w_false

    return instantiate_linklet.call_interpret(
        [linkl, to_list(imports), target, w_false], get_testing_config())
Exemplo n.º 13
0
def eval(linkl, target, imports=[], just_return=False):
    result = instantiate_linklet.call_interpret(
        [linkl, to_list(imports), target, w_false], get_testing_config())
    return result, target
Exemplo n.º 14
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from rpython.jit.metainterp.test.support import LLJitMixin
from pycket.racket_entry import dev_mode_metainterp_fasl_zo, dev_mode_dynamic_metainterp

from pycket.env import w_global_config as glob
from pycket.config import get_testing_config

# 1

glob.set_pycketconfig(get_testing_config())

LLJitMixin().meta_interp(dev_mode_dynamic_metainterp, [], listcomp=True, listops=True, backendopt=True)



# 2
# from pycket.entry_point import make_entry_point, target
# from rpython.translator.driver import TranslationDriver
# from rpython.config.translationoption import get_combined_translation_config

# # pypy targetpycket.py --linklets --verbose 2 -I racket/kernel/init -e "1"
# entry_flags_1 = ['--linklets', '--verbose', '2', '-I', 'racket/kernel/init', '-e', '1']

# def interp_w_1():
#     make_entry_point(get_dummy_config())(entry_flags_1)

## LLJitMixin().meta_interp(interp_w_1, [], listcomp=True, listops=True, backendopt=True)

Exemplo n.º 15
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from rpython.jit.metainterp.test.support import LLJitMixin
from pycket.racket_entry import dev_mode_metainterp_fasl_zo, dev_mode_dynamic_metainterp

from pycket.env import w_global_config as glob
from pycket.config import get_testing_config

# 1

glob.set_pycketconfig(get_testing_config())

LLJitMixin().meta_interp(dev_mode_dynamic_metainterp, [],
                         listcomp=True,
                         listops=True,
                         backendopt=True)

# 2
# from pycket.entry_point import make_entry_point, target
# from rpython.translator.driver import TranslationDriver
# from rpython.config.translationoption import get_combined_translation_config

# # pypy targetpycket.py --linklets --verbose 2 -I racket/kernel/init -e "1"
# entry_flags_1 = ['--linklets', '--verbose', '2', '-I', 'racket/kernel/init', '-e', '1']

# def interp_w_1():
#     make_entry_point(get_dummy_config())(entry_flags_1)

## LLJitMixin().meta_interp(interp_w_1, [], listcomp=True, listops=True, backendopt=True)