Ejemplo n.º 1
0
def link(code):
    code = as_code(code)
    free = free_vars(code)
    to_bind = sorted(var for var in free if var[1].startswith('lib.'))
    for var in to_bind:
        code = bind(code, var)

    return code
Ejemplo n.º 2
0
def context_pop(context, *terms):
    if context.stack is not None:
        arg, stack = context.stack
        return arg, Context(stack, context.bound)
    else:
        avoid = frozenset()
        for term in terms:
            avoid |= free_vars(term)
        arg = fresh(avoid)
        bound = arg, context.bound
        return arg, Context(context.stack, bound)
Ejemplo n.º 3
0
    def _compile(self):
        assert not hasattr(self, '_code')
        var = NVAR('_{}'.format(self.__name__))
        self._code = var

        code = _compile(self, actual_fun=self._fun)
        rec_code = try_abstract(var, code)
        if rec_code is not None:
            code = rec(rec_code)

        free = free_vars(code)
        if free:
            raise SyntaxError('Unbound variables: {}'.format(
                ' '.join(v[1] for v in free)))

        self._code = code
Ejemplo n.º 4
0
def test_free_vars(code, free):
    assert free_vars(code) == frozenset(free)
Ejemplo n.º 5
0
def test_free_vars_runs(code):
    free_vars(code)