From: Wolfgang (Blub) Bumiller Date: Thu, 28 Jun 2012 14:15:51 +0000 (+0200) Subject: ast_call node; codegen dummy X-Git-Tag: 0.1-rc1~471 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e934e77cc56ee24162c7e7b6a4ccfc6ea02dbdcb;p=xonotic%2Fgmqcc.git ast_call node; codegen dummy --- diff --git a/ast.c b/ast.c index 49446a1..409285d 100644 --- a/ast.c +++ b/ast.c @@ -308,6 +308,31 @@ void ast_loop_delete(ast_loop *self) mem_d(self); } +ast_call* ast_call_new(lex_ctx ctx, + ast_expression *funcexpr) +{ + ast_instantiate(ast_call, ctx, ast_call_delete); + ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_call_codegen); + + MEM_VECTOR_INIT(self, params); + + return self; +} + +void ast_call_delete(ast_call *self) +{ + size_t i; + for (i = 0; i < self->params_count; ++i) + ast_unref(self->params[i]); + MEM_VECTOR_CLEAR(self, params); + + if (self->func) + ast_unref(self->func); + + 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) { @@ -1148,3 +1173,9 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value return true; } + +bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value **out) +{ + /* TODO: call ir codegen */ + return false; +} diff --git a/ast.h b/ast.h index d0ce67a..f355716 100644 --- a/ast.h +++ b/ast.h @@ -40,6 +40,7 @@ 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; +typedef struct ast_call_s ast_call; /* Node interface with common components */ @@ -284,6 +285,29 @@ void ast_loop_delete(ast_loop*); bool ast_loop_codegen(ast_loop*, ast_function*, bool lvalue, ir_value**); +/* CALL node + * + * Contains an ast_expression as target, rather than an ast_function/value. + * Since it's how QC works, every ast_function has an ast_value + * associated anyway - in other words, the VM contains function + * pointers for every function anyway. Thus, this node will call + * expression. + * Additionally it contains a list of ast_expressions as parameters. + * Since calls can return values, an ast_call is also an ast_expression. + */ +struct ast_call_s +{ + ast_expression_common expression; + ast_expression *func; + MEM_VECTOR_MAKE(ast_expression*, params); +}; +ast_call* ast_call_new(lex_ctx ctx, + ast_expression *funcexpr); +void ast_call_delete(ast_call*); +bool ast_call_codegen(ast_call*, ast_function*, bool lvalue, ir_value**); + +MEM_VECTOR_PROTO(ast_call, ast_expression*, params); + /* Blocks * */