Ejemplo n.º 1
0
    def to_python(self):
        """
        Cria um módulo Python correspondente ao módulo atual.

        Retorna uma AST Python. O módulo criado possui uma estrutura semelhante
        à forma abaixo::

            def _module():
                # imports, typedefs, funções, etc
                return {'export1': export1, ...}

            globals().update(_module())
        """
        module_func_body = (
            *cremilda_default_imports(self.get_default_imports()),
            *to_python_imports(self.imports),
            *to_python_typedefs(self.typedefs),
            *to_python_operators(self.operators),
            *to_python_functions(self.functions),
            *to_python_constants(self.constants),
            return_({x: var(x) for x in self.exposing}),
        )

        module_func = function._module()[module_func_body]
        stmt = as_stmt(var.globals().method('update', var._module()))
        return block([module_func, stmt])
Ejemplo n.º 2
0
 def Assign(name, expr):  # noqa: N802, N805
     return let(var(name), to_python_expr(expr))
Ejemplo n.º 3
0
 def Name(value):  # noqa: N802, N805
     return var(value)