mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-19 14:50:48 +00:00
Generating function-local arrays
This commit is contained in:
parent
a0b6008c2e
commit
bde2175779
1 changed files with 70 additions and 11 deletions
65
ast.c
65
ast.c
|
@ -968,6 +968,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
|
||||||
|
|
||||||
ast_expression_common *elemtype = &self->expression.next->expression;
|
ast_expression_common *elemtype = &self->expression.next->expression;
|
||||||
int vtype = elemtype->vtype;
|
int vtype = elemtype->vtype;
|
||||||
|
|
||||||
/* we are lame now - considering the way QC works we won't tolerate arrays > 1024 elements */
|
/* we are lame now - considering the way QC works we won't tolerate arrays > 1024 elements */
|
||||||
if (!self->expression.count || self->expression.count > opts_max_array_size) {
|
if (!self->expression.count || self->expression.count > opts_max_array_size) {
|
||||||
asterror(ast_ctx(self), "Invalid array of size %lu", (unsigned long)self->expression.count);
|
asterror(ast_ctx(self), "Invalid array of size %lu", (unsigned long)self->expression.count);
|
||||||
|
@ -1070,18 +1071,65 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->expression.vtype == TYPE_ARRAY)
|
if (self->expression.vtype == TYPE_ARRAY) {
|
||||||
{
|
size_t ai;
|
||||||
asterror(ast_ctx(self), "TODO: ast_local_codgen for TYPE_ARRAY");
|
char *name;
|
||||||
|
size_t namelen;
|
||||||
|
|
||||||
|
ast_expression_common *elemtype = &self->expression.next->expression;
|
||||||
|
int vtype = elemtype->vtype;
|
||||||
|
|
||||||
|
if (param) {
|
||||||
|
asterror(ast_ctx(self), "array-parameters are not supported");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* we are lame now - considering the way QC works we won't tolerate arrays > 1024 elements */
|
||||||
|
if (!self->expression.count || self->expression.count > opts_max_array_size) {
|
||||||
|
asterror(ast_ctx(self), "Invalid array of size %lu", (unsigned long)self->expression.count);
|
||||||
|
}
|
||||||
|
|
||||||
|
self->ir_values = (ir_value**)mem_a(sizeof(self->ir_values[0]) * self->expression.count);
|
||||||
|
if (!self->ir_values) {
|
||||||
|
asterror(ast_ctx(self), "failed to allocate array values");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = ir_function_create_local(func, self->name, vtype, param);
|
||||||
|
if (!v) {
|
||||||
|
asterror(ast_ctx(self), "ir_function_create_local failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (vtype == TYPE_FIELD)
|
||||||
|
v->fieldtype = elemtype->next->expression.vtype;
|
||||||
|
v->context = ast_ctx(self);
|
||||||
|
|
||||||
|
namelen = strlen(self->name);
|
||||||
|
name = (char*)mem_a(namelen + 16);
|
||||||
|
strcpy(name, self->name);
|
||||||
|
|
||||||
|
self->ir_values[0] = v;
|
||||||
|
for (ai = 1; ai < self->expression.count; ++ai) {
|
||||||
|
snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
|
||||||
|
self->ir_values[ai] = ir_function_create_local(func, name, vtype, param);
|
||||||
|
if (!self->ir_values[ai]) {
|
||||||
|
asterror(ast_ctx(self), "ir_builder_create_global failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (vtype == TYPE_FIELD)
|
||||||
|
self->ir_values[ai]->fieldtype = elemtype->next->expression.vtype;
|
||||||
|
self->ir_values[ai]->context = ast_ctx(self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
v = ir_function_create_local(func, self->name, self->expression.vtype, param);
|
v = ir_function_create_local(func, self->name, self->expression.vtype, param);
|
||||||
if (!v)
|
if (!v)
|
||||||
return false;
|
return false;
|
||||||
if (self->expression.vtype == TYPE_FIELD)
|
if (self->expression.vtype == TYPE_FIELD)
|
||||||
v->fieldtype = self->expression.next->expression.vtype;
|
v->fieldtype = self->expression.next->expression.vtype;
|
||||||
v->context = ast_ctx(self);
|
v->context = ast_ctx(self);
|
||||||
|
}
|
||||||
|
|
||||||
/* A constant local... hmmm...
|
/* A constant local... hmmm...
|
||||||
* I suppose the IR will have to deal with this
|
* I suppose the IR will have to deal with this
|
||||||
|
@ -1109,6 +1157,17 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
|
||||||
|
|
||||||
/* link us to the ir_value */
|
/* link us to the ir_value */
|
||||||
self->ir_v = v;
|
self->ir_v = v;
|
||||||
|
|
||||||
|
if (self->setter) {
|
||||||
|
if (!ast_global_codegen(self->setter, func->owner, false) ||
|
||||||
|
!ast_function_codegen(self->setter->constval.vfunc, func->owner))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (self->getter) {
|
||||||
|
if (!ast_global_codegen(self->getter, func->owner, false) ||
|
||||||
|
!ast_function_codegen(self->getter->constval.vfunc, func->owner))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error: /* clean up */
|
error: /* clean up */
|
||||||
|
|
Loading…
Reference in a new issue