# Path: phi/dsl.py
# def _fmap(opt):
#     def method(self, other):
#         def h(x, state):
# def _fmap_flip(opt):
#     def method(self, other):
#         def h(x, state):
# def _unary_fmap(opt):
#     def method(self):
#     def __getattr__(self, name):
#     def __getitem__(self, name):
#     def __call__(self, *args, **kwargs):
#     def __init__(self, next_refs):
#     def __enter__(self):
#     def __exit__(self, *args):
#     def __init__(self, name, value=utils.NO_VALUE):
#     def __call__(self, *optional):
#     def write(self, x):
#     def __init__(self, __builder__):
#     def __getattr__(self, name):
#     def __call__ (self, name):
#     def __do__(self, name):
#     def __init__(self, __builder__):
#     def __getattr__(self, name):
#         def method_proxy(*args, **kwargs):
#     def __init__(self, __builder__):
#     def __call__(self, attr):
#     def __getattr__ (self, attr):
#     def __init__(self,*arg,**kw):
#     def __getattr__ (self, attr):
#     def __init__(self, new_scope):
#     def __enter__(self):
#     def __exit__(self, *args):
#     def __init__(self, f=utils.state_identity):
#     def __unit__(self, f, _return_type=None):
#     def __then__(self, other, **kwargs):
#     def __call__(self, __x__, *__return_state__, **state):
#     def __hash__(self):
#     def F(self, expr):
#     def Pipe(self, *sequence, **kwargs):
#     def ThenAt(self, n, f, *_args, **kwargs):
#         def g(x):
#     def Then0(self, f, *args, **kwargs):
#     def Then(self, f, *args, **kwargs):
#     def Then2(self, f, arg1, *args, **kwargs):
#     def Then3(self, f, arg1, arg2, *args, **kwargs):
#     def Then4(self, f, arg1, arg2, arg3, *args, **kwargs):
#     def Then5(self, f, arg1, arg2, arg3, arg4, *args, **kwargs):
#     def List(self, *branches, **kwargs):
#         def h(x, state):
#     def Tuple(self, *expressions, **kwargs):
#     def Set(self, *expressions, **kwargs):
#     def Seq(self, *sequence, **kwargs):
#         def g(x, state):
#     def Dict(self, **branches):
#         def h(x, state):
#     def Rec(self):
#     def With(self, context_manager, *body, **kwargs):
#         def g(x, state):
#     def Read(self):
#     def ReadList(self, *branches, **kwargs):
#     def Write(self, *state_args, **state_dict):
#         def g(x, state):
#     def Rec(self):
#     def Obj(self):
#     def Ref(self):
#     def Val(self, val, **kwargs):
#     def If(self, condition, *then, **kwargs):
#     def Else(self, *Else, **kwargs):
#     def Elif(self, condition, *then, **kwargs):
#     def Context(*args):
#     def __rshift__(self, other):
#     def __rrshift__(self, prev):
#     def __unit__(self, f, _return_type=None):
#     def __then__(self, other, **kwargs):
#     def __call__(self, __x__, *__return_state__, **state):
#     def __getitem__(self, key):
# def _add_else(ast, next_else):
# def _compile_if(ast):
#     def g(x, state):
# def _parse(code):
# class _RefProxy(object):
# class _StateContextManager(object):
# class Ref(object):
# class _ReadProxy(object):
# class _ObjectProxy(object):
# class _RecordProxy(object):
# class _RecordObject(dict):
# class _WithContextManager(object):
# class Expression(object):
#     REFS = None
#     WITH_GLOBAL_CONTEXT = utils.NO_VALUE
# E = Expression()


from phi.api import *
from phi import dsl
import pytest

class TestDSL(object):
    """docstring for TestDSL."""

    def test_compile(self):
        f = Seq(P + 1, P * 2)
        assert f(2) == 6

    def test_read(self):
        refs = dict(
            x = 10
        )

        f = Read('x')

        y, new_refs = f(None, True, **refs)

        assert refs == new_refs #read doesnt modify
        assert y == 10

    def test_write(self):

# Path: phi/dsl.py
# def _fmap(opt):
#     def method(self, other):
#         def h(x, state):
# def _fmap_flip(opt):
#     def method(self, other):
#         def h(x, state):
# def _unary_fmap(opt):
#     def method(self):
#     def __getattr__(self, name):
#     def __getitem__(self, name):
#     def __call__(self, *args, **kwargs):
#     def __init__(self, next_refs):
#     def __enter__(self):
#     def __exit__(self, *args):
#     def __init__(self, name, value=utils.NO_VALUE):
#     def __call__(self, *optional):
#     def write(self, x):
#     def __init__(self, __builder__):
#     def __getattr__(self, name):
#     def __call__ (self, name):
#     def __do__(self, name):
#     def __init__(self, __builder__):
#     def __getattr__(self, name):
#         def method_proxy(*args, **kwargs):
#     def __init__(self, __builder__):
#     def __call__(self, attr):
#     def __getattr__ (self, attr):
#     def __init__(self,*arg,**kw):
#     def __getattr__ (self, attr):
#     def __init__(self, new_scope):
#     def __enter__(self):
#     def __exit__(self, *args):
#     def __init__(self, f=utils.state_identity):
#     def __unit__(self, f, _return_type=None):
#     def __then__(self, other, **kwargs):
#     def __call__(self, __x__, *__return_state__, **state):
#     def __hash__(self):
#     def F(self, expr):
#     def Pipe(self, *sequence, **kwargs):
#     def ThenAt(self, n, f, *_args, **kwargs):
#         def g(x):
#     def Then0(self, f, *args, **kwargs):
#     def Then(self, f, *args, **kwargs):
#     def Then2(self, f, arg1, *args, **kwargs):
#     def Then3(self, f, arg1, arg2, *args, **kwargs):
#     def Then4(self, f, arg1, arg2, arg3, *args, **kwargs):
#     def Then5(self, f, arg1, arg2, arg3, arg4, *args, **kwargs):
#     def List(self, *branches, **kwargs):
#         def h(x, state):
#     def Tuple(self, *expressions, **kwargs):
#     def Set(self, *expressions, **kwargs):
#     def Seq(self, *sequence, **kwargs):
#         def g(x, state):
#     def Dict(self, **branches):
#         def h(x, state):
#     def Rec(self):
#     def With(self, context_manager, *body, **kwargs):
#         def g(x, state):
#     def Read(self):
#     def ReadList(self, *branches, **kwargs):
#     def Write(self, *state_args, **state_dict):
#         def g(x, state):
#     def Rec(self):
#     def Obj(self):
#     def Ref(self):
#     def Val(self, val, **kwargs):
#     def If(self, condition, *then, **kwargs):
#     def Else(self, *Else, **kwargs):
#     def Elif(self, condition, *then, **kwargs):
#     def Context(*args):
#     def __rshift__(self, other):
#     def __rrshift__(self, prev):
#     def __unit__(self, f, _return_type=None):
#     def __then__(self, other, **kwargs):
#     def __call__(self, __x__, *__return_state__, **state):
#     def __getitem__(self, key):
# def _add_else(ast, next_else):
# def _compile_if(ast):
#     def g(x, state):
# def _parse(code):
# class _RefProxy(object):
# class _StateContextManager(object):
# class Ref(object):
# class _ReadProxy(object):
# class _ObjectProxy(object):
# class _RecordProxy(object):
# class _RecordObject(dict):
# class _WithContextManager(object):
# class Expression(object):
#     REFS = None
#     WITH_GLOBAL_CONTEXT = utils.NO_VALUE
# E = Expression()


# Path: phi/tests/test_dsl.py
from phi.api import *
from phi import dsl
import pytest


class TestDSL(object):
    """docstring for TestDSL."""

    def test_compile(self):
        f = Seq(P + 1, P * 2)
        assert f(2) == 6

    def test_read(self):
        refs = dict(
            x = 10
        )

        f = Read('x')

        y, new_refs = f(None, True, **refs)

        assert refs == new_refs #read doesnt modify
        assert y == 10

    def test_write(self):

        r = dsl.Ref('r')