ast_loop - codegen dummied

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-05-03 21:57:13 +02:00
parent 3e974a1a24
commit 375cfd24b3
2 changed files with 76 additions and 0 deletions

36
ast.c
View file

@ -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;
}

40
ast.h
View file

@ -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
*