mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-17 09:02:25 +00:00
Handling vector constants now too
This commit is contained in:
parent
b88e25ed81
commit
79753d05bd
1 changed files with 34 additions and 0 deletions
34
parser.c
34
parser.c
|
@ -12,6 +12,7 @@ typedef struct {
|
|||
MEM_VECTOR_MAKE(ast_function*, functions);
|
||||
MEM_VECTOR_MAKE(ast_value*, imm_float);
|
||||
MEM_VECTOR_MAKE(ast_value*, imm_string);
|
||||
MEM_VECTOR_MAKE(ast_value*, imm_vector);
|
||||
|
||||
ast_function *function;
|
||||
MEM_VECTOR_MAKE(ast_value*, locals);
|
||||
|
@ -21,6 +22,7 @@ typedef struct {
|
|||
MEM_VEC_FUNCTIONS(parser_t, ast_value*, globals)
|
||||
MEM_VEC_FUNCTIONS(parser_t, ast_value*, imm_float)
|
||||
MEM_VEC_FUNCTIONS(parser_t, ast_value*, imm_string)
|
||||
MEM_VEC_FUNCTIONS(parser_t, ast_value*, imm_vector)
|
||||
MEM_VEC_FUNCTIONS(parser_t, ast_value*, locals)
|
||||
MEM_VEC_FUNCTIONS(parser_t, ast_function*, functions)
|
||||
|
||||
|
@ -97,6 +99,24 @@ ast_value* parser_const_string(parser_t *parser, const char *str)
|
|||
return out;
|
||||
}
|
||||
|
||||
ast_value* parser_const_vector(parser_t *parser, vector v)
|
||||
{
|
||||
size_t i;
|
||||
ast_value *out;
|
||||
for (i = 0; i < parser->imm_vector_count; ++i) {
|
||||
if (!memcmp(&parser->imm_vector[i]->constval.vvec, &v, sizeof(v)))
|
||||
return parser->imm_vector[i];
|
||||
}
|
||||
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_VECTOR);
|
||||
out->isconst = true;
|
||||
out->constval.vvec = v;
|
||||
if (!parser_t_imm_vector_add(parser, out)) {
|
||||
ast_value_delete(out);
|
||||
return NULL;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
ast_value* parser_find_global(parser_t *parser, const char *name)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -614,6 +634,15 @@ static ast_expression* parser_expression(parser_t *parser)
|
|||
goto onerr;
|
||||
}
|
||||
}
|
||||
else if (parser->tok == TOKEN_VECTORCONST) {
|
||||
ast_value *val = parser_const_vector(parser, parser_token(parser)->constval.v);
|
||||
if (!val)
|
||||
return false;
|
||||
if (!shunt_out_add(&sy, syexp(parser_ctx(parser), (ast_expression*)val))) {
|
||||
parseerror(parser, "out of memory");
|
||||
goto onerr;
|
||||
}
|
||||
}
|
||||
else if (parser->tok == '(') {
|
||||
nextwant = false; /* not expecting an operator next */
|
||||
if (!shunt_ops_add(&sy, syparen(parser_ctx(parser), 1, 0))) {
|
||||
|
@ -1085,6 +1114,11 @@ bool parser_compile(const char *filename)
|
|||
printf("failed to generate global %s\n", parser->imm_string[i]->name);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < parser->imm_vector_count; ++i) {
|
||||
if (!ast_global_codegen(parser->imm_vector[i], ir)) {
|
||||
printf("failed to generate global %s\n", parser->imm_vector[i]->name);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < parser->globals_count; ++i) {
|
||||
if (!ast_global_codegen(parser->globals[i], ir)) {
|
||||
printf("failed to generate global %s\n", parser->globals[i]->name);
|
||||
|
|
Loading…
Reference in a new issue