/* 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;
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);
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) ||
}
}
}
- 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) ||