Beispiel #1
0
Datei: mangles.py Projekt: eal/hy
 def visit(self, tree):
     if isinstance(tree, HyExpression) and tree != []:
         call = tree[0]
         if call == "fn" and self.should_hoist():
             new_name = HySymbol(self.unique_name())
             new_name.replace(tree)
             fn_def = HyExpression([HySymbol("def"),
                                    new_name,
                                    tree])
             fn_def.replace(tree)
             self.hoist(fn_def)
             return new_name
Beispiel #2
0
 def visit(self, tree):
     """
     Visit all the nodes in the Hy code tree.
     """
     if isinstance(tree, HyExpression) and tree != []:
         call = tree[0]
         if call == "fn" and self.should_hoist():
             # if we have a Function and we should hoist it --
             new_name = HySymbol(self.unique_name())
             new_name.replace(tree)
             fn_def = HyExpression([HySymbol("def"), new_name, tree])
             fn_def.replace(tree)
             self.hoist(fn_def)
             return new_name
Beispiel #3
0
 def visit(self, tree):
     """
     Visit all the nodes in the Hy code tree.
     """
     if isinstance(tree, HyExpression) and tree != []:
         call = tree[0]
         if call == "fn" and self.should_hoist():
             # if we have a Function and we should hoist it --
             new_name = HySymbol(self.unique_name())
             new_name.replace(tree)
             fn_def = HyExpression([HySymbol("def"),
                                    new_name,
                                    tree])
             fn_def.replace(tree)
             self.hoist(fn_def)
             return new_name
Beispiel #4
0
    def compile_symbol(self, symbol):
        if "." in symbol:
            glob, local = symbol.rsplit(".", 1)
            glob = HySymbol(glob)
            glob.replace(symbol)

            return ast.Attribute(lineno=symbol.start_line,
                                 col_offset=symbol.start_column,
                                 value=self.compile_symbol(glob),
                                 attr=ast_str(local),
                                 ctx=ast.Load())

        return ast.Name(id=ast_str(symbol),
                        arg=ast_str(symbol),
                        ctx=ast.Load(),
                        lineno=symbol.start_line,
                        col_offset=symbol.start_column)
Beispiel #5
0
    def compile_symbol(self, symbol):
        if "." in symbol:
            glob, local = symbol.rsplit(".", 1)
            glob = HySymbol(glob)
            glob.replace(symbol)

            return ast.Attribute(
                lineno=symbol.start_line,
                col_offset=symbol.start_column,
                value=self.compile_symbol(glob),
                attr=str(local),
                ctx=ast.Load()
            )

        return ast.Name(id=str(symbol), ctx=ast.Load(),
                        lineno=symbol.start_line,
                        col_offset=symbol.start_column)
Beispiel #6
0
    def compile_dotted_expression(self, expr):
        ofn = expr.pop(0)  # .join

        fn = HySymbol(ofn[1:])
        fn.replace(ofn)

        obj = expr.pop(0)  # [1 2 3 4]

        return ast.Call(func=ast.Attribute(lineno=expr.start_line,
                                           col_offset=expr.start_column,
                                           value=self.compile(obj),
                                           attr=ast_str(fn),
                                           ctx=ast.Load()),
                        args=[self.compile(x) for x in expr],
                        keywords=[],
                        lineno=expr.start_line,
                        col_offset=expr.start_column,
                        starargs=None,
                        kwargs=None)
Beispiel #7
0
    def compile_dotted_expression(self, expr):
        ofn = expr.pop(0)  # .join

        fn = HySymbol(ofn[1:])
        fn.replace(ofn)

        obj = expr.pop(0)  # [1 2 3 4]

        return ast.Call(
            func=ast.Attribute(
                lineno=expr.start_line,
                col_offset=expr.start_column,
                value=self.compile(obj),
                attr=ast_str(fn),
                ctx=ast.Load()),
            args=[self.compile(x) for x in expr],
            keywords=[],
            lineno=expr.start_line,
            col_offset=expr.start_column,
            starargs=None,
            kwargs=None)