From 281bd8657a08db0ec372459aed84d04d1df1f073 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 1 May 2012 15:08:54 +0200 Subject: [PATCH] ast_entfield node --- ast.c | 23 +++++++++++++++++++++++ ast.h | 27 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/ast.c b/ast.c index 3474dfc..0fe0362 100644 --- a/ast.c +++ b/ast.c @@ -132,6 +132,24 @@ void ast_binary_delete(ast_binary *self) mem_d(self); } +ast_entfield* ast_entfield_new(lex_ctx ctx, ast_expression *entity, ast_expression *field) +{ + ast_instantiate(ast_entfield, ctx, ast_entfield_delete); + ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_entfield_codegen); + + self->entity = entity; + self->field = field; + + return self; +} + +void ast_entfield_delete(ast_entfield *self) +{ + ast_unref(self->entity); + ast_unref(self->field); + mem_d(self); +} + ast_store* ast_store_new(lex_ctx ctx, int op, ast_value *dest, ast_expression *source) { @@ -316,3 +334,8 @@ bool ast_binary_codegen(ast_binary *self, ast_function *func, ir_value **out) { return false; } + +bool ast_entfield_codegen(ast_entfield *self, ast_function *func, ir_value **out) +{ + return false; +} diff --git a/ast.h b/ast.h index bcc04f1..cd73230 100644 --- a/ast.h +++ b/ast.h @@ -36,6 +36,7 @@ typedef struct ast_function_s ast_function; typedef struct ast_block_s ast_block; typedef struct ast_binary_s ast_binary; typedef struct ast_store_s ast_store; +typedef struct ast_entfield_s ast_entfield; /* Node interface with common components */ @@ -137,6 +138,32 @@ bool ast_block_codegen(ast_block*, ast_function*, ir_value**); */ bool ast_binary_codegen(ast_binary*, ast_function*, ir_value**); +/* Entity-field + * + * This must do 2 things: + * -) Provide a way to fetch an entity field value. (Rvalue) + * -) Provide a pointer to an entity field. (Lvalue) + * The problem: + * In original QC, there's only a STORE via pointer, but + * no LOAD via pointer. + * So we must know beforehand if we are going to read or assign + * the field. + * For this we will have to extend the codegen() functions with + * a flag saying whether or not we need an L or an R-value. + */ +struct ast_entfield_s +{ + ast_expression_common expression; + /* The entity can come from an expression of course. */ + ast_expression *entity; + /* As can the field, it just must result in a value of TYPE_FIELD */ + ast_expression *field; +}; +ast_entfield* ast_entfield_new(lex_ctx ctx, ast_expression *entity, ast_expression *field); +void ast_entfield_delete(ast_entfield*); + +bool ast_entfield_codegen(ast_entfield*, ast_function*, ir_value**); + /* Store * * Stores left<-right and returns left. -- 2.39.2