コード例 #1
0
ファイル: compiler.py プロジェクト: toymachine/misc
 def visit_BinaryExpression(self, p_binexpr):
     left = p_binexpr.left.accept(self)
     operator = p_binexpr.operator
     if operator == "==":
         operator = "="
     elif operator == "!=":
         operator = "not="
     else:
         pass
     right = p_binexpr.right.accept(self)
     return clj.list([clj.ident(operator), left, right])
コード例 #2
0
ファイル: compiler.py プロジェクト: toymachine/misc
    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
コード例 #3
0
ファイル: compiler.py プロジェクト: toymachine/misc
 def visit_BindStatement(self, p_bindstmt):
     #only called at module level
     return clj.list([clj.ident('def'), clj.ident(p_bindstmt.name), p_bindstmt.expr.accept(self)])
コード例 #4
0
ファイル: compiler.py プロジェクト: toymachine/misc
 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)])
コード例 #5
0
ファイル: compiler.py プロジェクト: toymachine/misc
 def visit_SubscriptExpression(self, p_subscriptexpr):
     return clj.list([clj.ident("get"), p_subscriptexpr.expr.accept(self), p_subscriptexpr.indexExpr.accept(self)])
コード例 #6
0
ファイル: compiler.py プロジェクト: toymachine/misc
 def visit_IdentifierExpression(self, p_identexpr):
     return clj.ident(p_identexpr.identifier)
コード例 #7
0
ファイル: compiler.py プロジェクト: toymachine/misc
 def visit_DictLiteralExpression(self, p_literalexpr):
     l = [clj.ident("hash-map")]
     for key, val in p_literalexpr.pairs:
         l.append(key.accept(self))
         l.append(val.accept(self))
     return clj.list(l)
コード例 #8
0
ファイル: compiler.py プロジェクト: toymachine/misc
    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
コード例 #9
0
ファイル: compiler.py プロジェクト: toymachine/misc
    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
コード例 #10
0
ファイル: compiler.py プロジェクト: toymachine/misc
 def dummy_ident(self):
     self.dummy_id += 1
     return clj.ident('__d%d' % self.dummy_id)