mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-22 11:21:39 +00:00
get-accessor calling in ast_array_index_codegen
This commit is contained in:
parent
1ab303c528
commit
30d87ee837
1 changed files with 37 additions and 3 deletions
40
ast.c
40
ast.c
|
@ -1520,8 +1520,20 @@ bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lva
|
||||||
ast_value *arr;
|
ast_value *arr;
|
||||||
ast_value *idx;
|
ast_value *idx;
|
||||||
|
|
||||||
|
if (!lvalue && self->expression.outr) {
|
||||||
|
*out = self->expression.outr;
|
||||||
|
}
|
||||||
|
if (lvalue && self->expression.outl) {
|
||||||
|
*out = self->expression.outl;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ast_istype(self->array, ast_value)) {
|
if (!ast_istype(self->array, ast_value)) {
|
||||||
asterror(ast_ctx(self), "array indexing this way is not supported");
|
asterror(ast_ctx(self), "array indexing this way is not supported");
|
||||||
|
/* note this would actually be pointer indexing because the left side is
|
||||||
|
* not an actual array but (hopefully) an indexable expression.
|
||||||
|
* Once we get integer arithmetic, and GADDRESS/GSTORE/GLOAD instruction
|
||||||
|
* support this path will be filled.
|
||||||
|
*/
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1531,10 +1543,32 @@ bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lva
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
/* Time to use accessor functions */
|
/* Time to use accessor functions */
|
||||||
/*
|
|
||||||
ast_expression_codegen *cgen;
|
ast_expression_codegen *cgen;
|
||||||
ir_value *iridx;
|
ir_value *iridx, *funval;
|
||||||
*/
|
ir_instr *call;
|
||||||
|
|
||||||
|
if (!arr->getter) {
|
||||||
|
asterror(ast_ctx(self), "value has no getter, don't know how to index it");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cgen = self->index->expression.codegen;
|
||||||
|
if (!(*cgen)((ast_expression*)(self->index), func, true, &iridx))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
cgen = arr->getter->expression.codegen;
|
||||||
|
if (!(*cgen)((ast_expression*)(arr->getter), func, true, &funval))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
call = ir_block_create_call(func->curblock, ast_function_label(func, "fetch"), funval);
|
||||||
|
if (!call)
|
||||||
|
return false;
|
||||||
|
if (!ir_call_param(call, iridx))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*out = ir_call_value(call);
|
||||||
|
self->expression.outr = *out;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue