mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-23 20:33:05 +00:00
collect vector-member locals in ast_block->collect, like a garbage collection...
This commit is contained in:
parent
897bd5727e
commit
68e4a937f2
3 changed files with 24 additions and 6 deletions
4
ast.c
4
ast.c
|
@ -562,10 +562,14 @@ ast_block* ast_block_new(lex_ctx ctx)
|
||||||
}
|
}
|
||||||
MEM_VEC_FUNCTIONS(ast_block, ast_value*, locals)
|
MEM_VEC_FUNCTIONS(ast_block, ast_value*, locals)
|
||||||
MEM_VEC_FUNCTIONS(ast_block, ast_expression*, exprs)
|
MEM_VEC_FUNCTIONS(ast_block, ast_expression*, exprs)
|
||||||
|
MEM_VEC_FUNCTIONS(ast_block, ast_expression*, collect)
|
||||||
|
|
||||||
void ast_block_delete(ast_block *self)
|
void ast_block_delete(ast_block *self)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
for (i = 0; i < self->collect_count; ++i)
|
||||||
|
ast_unref(self->collect[i]);
|
||||||
|
MEM_VECTOR_CLEAR(self, collect);
|
||||||
for (i = 0; i < self->exprs_count; ++i)
|
for (i = 0; i < self->exprs_count; ++i)
|
||||||
ast_unref(self->exprs[i]);
|
ast_unref(self->exprs[i]);
|
||||||
MEM_VECTOR_CLEAR(self, exprs);
|
MEM_VECTOR_CLEAR(self, exprs);
|
||||||
|
|
2
ast.h
2
ast.h
|
@ -427,6 +427,7 @@ struct ast_block_s
|
||||||
|
|
||||||
MEM_VECTOR_MAKE(ast_value*, locals);
|
MEM_VECTOR_MAKE(ast_value*, locals);
|
||||||
MEM_VECTOR_MAKE(ast_expression*, exprs);
|
MEM_VECTOR_MAKE(ast_expression*, exprs);
|
||||||
|
MEM_VECTOR_MAKE(ast_expression*, collect);
|
||||||
};
|
};
|
||||||
ast_block* ast_block_new(lex_ctx ctx);
|
ast_block* ast_block_new(lex_ctx ctx);
|
||||||
void ast_block_delete(ast_block*);
|
void ast_block_delete(ast_block*);
|
||||||
|
@ -434,6 +435,7 @@ bool ast_block_set_type(ast_block*, ast_expression *from);
|
||||||
|
|
||||||
MEM_VECTOR_PROTO(ast_block, ast_value*, locals);
|
MEM_VECTOR_PROTO(ast_block, ast_value*, locals);
|
||||||
MEM_VECTOR_PROTO(ast_block, ast_expression*, exprs);
|
MEM_VECTOR_PROTO(ast_block, ast_expression*, exprs);
|
||||||
|
MEM_VECTOR_PROTO(ast_block, ast_expression*, collect);
|
||||||
|
|
||||||
bool ast_block_codegen(ast_block*, ast_function*, bool lvalue, ir_value**);
|
bool ast_block_codegen(ast_block*, ast_function*, bool lvalue, ir_value**);
|
||||||
|
|
||||||
|
|
14
parser.c
14
parser.c
|
@ -1888,6 +1888,18 @@ static bool parser_variable(parser_t *parser, ast_block *localblock)
|
||||||
(void)!parser_t_locals_add(parser, vx);
|
(void)!parser_t_locals_add(parser, vx);
|
||||||
(void)!parser_t_locals_add(parser, vy);
|
(void)!parser_t_locals_add(parser, vy);
|
||||||
(void)!parser_t_locals_add(parser, vz);
|
(void)!parser_t_locals_add(parser, vz);
|
||||||
|
if (!ast_block_locals_add(localblock, var) ||
|
||||||
|
!ast_block_collect_add(localblock, vx.var) ||
|
||||||
|
!ast_block_collect_add(localblock, vy.var) ||
|
||||||
|
!ast_block_collect_add(localblock, vz.var))
|
||||||
|
{
|
||||||
|
parser_pop_local(parser);
|
||||||
|
parser_pop_local(parser);
|
||||||
|
parser_pop_local(parser);
|
||||||
|
parser_pop_local(parser);
|
||||||
|
ast_value_delete(var);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1898,13 +1910,13 @@ static bool parser_variable(parser_t *parser, ast_block *localblock)
|
||||||
ast_value_delete(var);
|
ast_value_delete(var);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (localblock && !ast_block_locals_add(localblock, var))
|
if (localblock && !ast_block_locals_add(localblock, var))
|
||||||
{
|
{
|
||||||
parser_pop_local(parser);
|
parser_pop_local(parser);
|
||||||
ast_value_delete(var);
|
ast_value_delete(var);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!parser_next(parser)) {
|
if (!parser_next(parser)) {
|
||||||
ast_value_delete(var);
|
ast_value_delete(var);
|
||||||
|
|
Loading…
Reference in a new issue