Beispiel #1
0
    def compile_block(self, statements):
        let_vector = clj.vector([])
        let_list = clj.list([clj.LET, let_vector])

        if statements:
            for statement in statements[:-1]:
                if isinstance(statement, ast.BindStatement):
                    let_vector.append(clj.ident(statement.name))
                    let_vector.append(statement.expr.accept(self))
                else:
                    let_vector.append(self.dummy_ident())
                    let_vector.append(statement.accept(self))

            if isinstance(statements[-1], ast.BindStatement):
                let_list.append(clj.ident('nil'))
            else:
                let_list.append(statements[-1].accept(self))
        else:
            let_list.append(clj.ident('nil'))

        return let_list
Beispiel #2
0
 def visit_ForStatement(self, p_forstmt):
     return clj.list([clj.ident('doseq'), clj.vector([clj.ident(p_forstmt.bind), p_forstmt.expr.accept(self)]), self.compile_block(p_forstmt.block)])
Beispiel #3
0
    def visit_FunctionLiteralExpression(self, p_literalfunc):
        
        clj_parameters = [clj.ident(parameter_name) for (_, parameter_name) in p_literalfunc.parameters]
        clj_cfunc = clj.list([clj.FN, clj.vector(clj_parameters), self.compile_block(p_literalfunc.statements)])

        return clj_cfunc
Beispiel #4
0
    def visit_FunctionStatement(self, p_function):
        #print 'funcstat', p_function.statements
        clj_parameters = [clj.ident(parameter_name) for (_, parameter_name) in p_function.parameters]
        clj_cfunc = clj.list([clj.DEFN, clj.ident(p_function.name), clj.vector(clj_parameters), self.compile_block(p_function.statements)])

        return clj_cfunc