From 2a3e7c1cff95a06b85ca2860735433cc59da64f5 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Fri, 30 Nov 2012 21:11:12 +0100 Subject: [PATCH] field constants - revert globals generated after fields --- ast.c | 12 ++++++++++++ ast.h | 1 + parser.c | 20 +++++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/ast.c b/ast.c index d797fc1..5d824d0 100644 --- a/ast.c +++ b/ast.c @@ -1264,6 +1264,18 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) /* Cannot generate an IR value for a function, * need a pointer pointing to a function rather. */ + case TYPE_FIELD: + if (!self->constval.vfield) { + compile_error(ast_ctx(self), "field constant without vfield set"); + goto error; + } + if (!self->constval.vfield->ir_v) { + compile_error(ast_ctx(self), "field constant generated before its field"); + goto error; + } + if (!ir_value_set_field(v, self->constval.vfield->ir_v)) + goto error; + break; default: compile_error(ast_ctx(self), "TODO: global constant type %i", self->expression.vtype); break; diff --git a/ast.h b/ast.h index a7fd7b8..004243f 100644 --- a/ast.h +++ b/ast.h @@ -169,6 +169,7 @@ struct ast_value_s const char *vstring; int ventity; ast_function *vfunc; + ast_value *vfield; } constval; /* usecount for the parser */ diff --git a/parser.c b/parser.c index 87a1514..3e1bad9 100644 --- a/parser.c +++ b/parser.c @@ -4025,6 +4025,8 @@ skipvar: var->hasvalue = true; if (cval->expression.vtype == TYPE_STRING) var->constval.vstring = parser_strdup(cval->constval.vstring); + else if (cval->expression.vtype == TYPE_FIELD) + var->constval.vfield = cval; else memcpy(&var->constval, &cval->constval, sizeof(var->constval)); ast_unref(cval); @@ -4466,14 +4468,11 @@ bool parser_finish(const char *output) return false; } } - for (i = 0; i < vec_size(parser->fields); ++i) { + for (i = 0; i < vec_size(parser->globals); ++i) { ast_value *asvalue; - asvalue = (ast_value*)(parser->fields[i]->expression.next); - - if (!ast_istype((ast_expression*)asvalue, ast_value)) - continue; - if (asvalue->expression.vtype != TYPE_ARRAY) + if (!ast_istype(parser->globals[i], ast_value)) continue; + asvalue = (ast_value*)(parser->globals[i]); if (asvalue->setter) { if (!ast_global_codegen(asvalue->setter, ir, false) || !ast_function_codegen(asvalue->setter->constval.vfunc, ir) || @@ -4495,11 +4494,14 @@ bool parser_finish(const char *output) } } } - for (i = 0; i < vec_size(parser->globals); ++i) { + for (i = 0; i < vec_size(parser->fields); ++i) { ast_value *asvalue; - if (!ast_istype(parser->globals[i], ast_value)) + asvalue = (ast_value*)(parser->fields[i]->expression.next); + + if (!ast_istype((ast_expression*)asvalue, ast_value)) + continue; + if (asvalue->expression.vtype != TYPE_ARRAY) continue; - asvalue = (ast_value*)(parser->globals[i]); if (asvalue->setter) { if (!ast_global_codegen(asvalue->setter, ir, false) || !ast_function_codegen(asvalue->setter->constval.vfunc, ir) || -- 2.39.2