field constants - revert globals generated after fields

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-11-30 21:11:12 +01:00
parent 316298650e
commit 2a3e7c1cff
3 changed files with 24 additions and 9 deletions

12
ast.c
View file

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

1
ast.h
View file

@ -169,6 +169,7 @@ struct ast_value_s
const char *vstring;
int ventity;
ast_function *vfunc;
ast_value *vfield;
} constval;
/* usecount for the parser */

View file

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