+static bool ast_global_array_set(ast_value *self)
+{
+ size_t count = vec_size(self->initlist);
+ size_t i;
+
+ if (count > self->expression.count) {
+ compile_error(ast_ctx(self), "too many elements in initializer");
+ count = self->expression.count;
+ }
+ else if (count < self->expression.count) {
+ /* add this?
+ compile_warning(ast_ctx(self), "not all elements are initialized");
+ */
+ }
+
+ for (i = 0; i != count; ++i) {
+ switch (self->expression.next->vtype) {
+ case TYPE_FLOAT:
+ if (!ir_value_set_float(self->ir_values[i], self->initlist[i].vfloat))
+ return false;
+ break;
+ case TYPE_VECTOR:
+ if (!ir_value_set_vector(self->ir_values[i], self->initlist[i].vvec))
+ return false;
+ break;
+ case TYPE_STRING:
+ if (!ir_value_set_string(self->ir_values[i], self->initlist[i].vstring))
+ return false;
+ break;
+ case TYPE_ARRAY:
+ /* we don't support them in any other place yet either */
+ compile_error(ast_ctx(self), "TODO: nested arrays");
+ return false;
+ case TYPE_FUNCTION:
+ /* this requiers a bit more work - similar to the fields I suppose */
+ compile_error(ast_ctx(self), "global of type function not properly generated");
+ return false;
+ case TYPE_FIELD:
+ if (!self->initlist[i].vfield) {
+ compile_error(ast_ctx(self), "field constant without vfield set");
+ return false;
+ }
+ if (!self->initlist[i].vfield->ir_v) {
+ compile_error(ast_ctx(self), "field constant generated before its field");
+ return false;
+ }
+ if (!ir_value_set_field(self->ir_values[i], self->initlist[i].vfield->ir_v))
+ return false;
+ break;
+ default:
+ compile_error(ast_ctx(self), "TODO: global constant type %i", self->expression.vtype);
+ break;
+ }
+ }
+ return true;
+}
+