From 375cfd24b379d3b84e364707422a12cd3cd42410 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Thu, 3 May 2012 21:57:13 +0200 Subject: [PATCH] ast_loop - codegen dummied --- ast.c | 36 ++++++++++++++++++++++++++++++++++++ ast.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/ast.c b/ast.c index 3e1738c..7a68ba3 100644 --- a/ast.c +++ b/ast.c @@ -273,6 +273,37 @@ void ast_ternary_delete(ast_ternary *self) mem_d(self); } +ast_loop* ast_loop_new(lex_ctx ctx, + ast_expression *initexpr, + ast_expression *precond, + ast_expression *postcond, + ast_expression *increment) +{ + ast_instantiate(ast_loop, ctx, ast_loop_delete); + ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_loop_codegen); + + self->initexpr = initexpr; + self->precond = precond; + self->postcond = postcond; + self->increment = increment; + + return self; +} + +void ast_loop_delete(ast_loop *self) +{ + if (self->initexpr) + ast_unref(self->initexpr); + if (self->precond) + ast_unref(self->precond); + if (self->postcond) + ast_unref(self->postcond); + if (self->increment) + ast_unref(self->increment); + ast_expression_delete((ast_expression*)self); + mem_d(self); +} + ast_store* ast_store_new(lex_ctx ctx, int op, ast_value *dest, ast_expression *source) { @@ -885,3 +916,8 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_ return true; } + +bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value **out) +{ + return false; +} diff --git a/ast.h b/ast.h index 5b8324a..bc24c53 100644 --- a/ast.h +++ b/ast.h @@ -39,6 +39,7 @@ typedef struct ast_store_s ast_store; typedef struct ast_entfield_s ast_entfield; typedef struct ast_ifthen_s ast_ifthen; typedef struct ast_ternary_s ast_ternary; +typedef struct ast_loop_s ast_loop; /* Node interface with common components */ @@ -241,6 +242,45 @@ void ast_ternary_delete(ast_ternary*); bool ast_ternary_codegen(ast_ternary*, ast_function*, bool lvalue, ir_value**); +/* A general loop node + * + * For convenience it contains 4 parts: + * -) (ini) = initializing expression + * -) (pre) = pre-loop condition + * -) (pst) = post-loop condition + * -) (inc) = "increment" expression + * The following is a psudo-representation of this loop + * note that '=>' bears the logical meaning of "implies". + * (a => b) equals (!a || b) + +{ini}; +while (has_pre => {pre}) +{ + {body}; + +continue: // a 'continue' will jump here + if (has_pst => {pst}) + break; + + {inc}; +} + */ +struct ast_loop_s +{ + ast_expression_common expression; + ast_expression *initexpr; + ast_expression *precond; + ast_expression *postcond; + ast_expression *increment; +}; +ast_loop* ast_loop_new(lex_ctx, ctx, + ast_expression *initexpr, + ast_expression *precond, + ast_expression *postcond, + ast_expression *increment); +void ast_loop_delete(ast_loop*); + +bool ast_loop_codegen(ast_loop*, ast_function*, bool lvalue, ir_value**); /* Blocks * -- 2.39.2