Exemple #1
0
def test_try_compute_step_runs(term):
    for step in xrange(5):
        with xfail_if_not_implemented():
            result = bohm.try_compute_step(term)
        if is_normal(term):
            assert result is None
            return
        else:
            assert isinstance(result, Term)
Exemple #2
0
def test_try_compute_step_runs(code):
    for step in xrange(5):
        with xfail_if_not_implemented():
            result = try_compute_step(code)
        if is_normal(code):
            assert result is None
            return
        else:
            assert is_code(result)
Exemple #3
0
def step(string, steps=10, fmt='auto'):
    """Step through reduction sequence of bohm library."""
    if fmt == 'auto':
        fmt = guess_format(string)
    print('Format: {}'.format(fmt))
    parse, print_, simplify = FORMATS[fmt]
    code = simplify(string)
    print(print_(code))
    for step in xrange(steps):
        code = bohm.try_compute_step(code)
        if code is None:
            print('DONE')
            return step
        print(print_(code))
    return None
Exemple #4
0
def trace(*part_names, **kwargs):
    """Trace an approximation to A.

    Possible names: all base copy div bot swap preconj postconj compose

    Kwargs:
      steps = 10
      type = '(FUN r (FUN s (FUN f (FUN x (r (f (s x)))))))'
      inhab = '(FUN x x)'
      fmt = 'sexpr' (one of: 'sexpr', 'tiny')
    """
    print_ = PRINTERS[kwargs.get('fmt', 'sexpr')]

    # Construct an approximation of A with only a few parts.
    if 'all' in part_names:
        part_names = PARTS.keys()
    for name in part_names:
        print('{} = {}'.format(name, print_(simplify(PARTS[name]))))
        assert name in PARTS, name
    A = simplify(build_A(*part_names))
    print('A = {}'.format(print_(A)))

    # Cast a candidate inhabitant via the defined type.
    type_ = sexpr_simplify(kwargs.get('type', default_type))
    inhab = sexpr_simplify(kwargs.get('inhab', default_inhab))
    term = simplify(app(A, type_, inhab))
    print('0\t{}'.format(print_(term)))

    # Print a reduction sequence.
    steps = int(kwargs.get('steps', 10))
    for step in xrange(steps):
        term = try_compute_step(term)
        if term is None:
            print '--- Normalized ---'
            return
        print('{}\t{}'.format(1 + step, print_(term)))
    print('... Not normalized ...')
Exemple #5
0
def test_try_compute_step_terminates(term):
    term = sexpr_simplify(term)
    bohm.try_compute_step(term)
Exemple #6
0
def test_try_compute_step(term, expected):
    with xfail_if_not_implemented():
        assert bohm.try_compute_step(term) is expected
Exemple #7
0
def test_try_compute_step(code, expected):
    with xfail_if_not_implemented():
        assert try_compute_step(code) is expected