static void ast_expression_init(ast_expression *self,
ast_expression_codegen *codegen)
{
- self->expression.codegen = codegen;
- self->expression.vtype = TYPE_VOID;
- self->expression.next = NULL;
- self->expression.outl = NULL;
- self->expression.outr = NULL;
+ self->expression.codegen = codegen;
+ self->expression.vtype = TYPE_VOID;
+ self->expression.next = NULL;
+ self->expression.outl = NULL;
+ self->expression.outr = NULL;
+ self->expression.variadic = false;
MEM_VECTOR_INIT(&self->expression, params);
}
}
fromex = &self->expression;
selfex = &cp->expression;
+ selfex->variadic = fromex->variadic;
for (i = 0; i < fromex->params_count; ++i) {
ast_value *v = ast_value_copy(fromex->params[i]);
if (!v || !ast_expression_common_params_add(selfex, v)) {
}
fromex = &other->expression;
selfex = &self->expression;
+ selfex->variadic = fromex->variadic;
for (i = 0; i < fromex->params_count; ++i) {
ast_value *v = ast_value_copy(fromex->params[i]);
if (!v || !ast_expression_common_params_add(selfex, v))
else
selfex->next = NULL;
+ selfex->variadic = fromex->variadic;
for (i = 0; i < fromex->params_count; ++i) {
ast_value *v = ast_value_copy(fromex->params[i]);
if (!v || !ast_expression_common_params_add(selfex, v)) {
return false;
if (a->expression.params_count != b->expression.params_count)
return false;
+ if (a->expression.variadic != b->expression.variadic)
+ return false;
if (a->expression.params_count) {
size_t i;
for (i = 0; i < a->expression.params_count; ++i) {
self->expression.vtype = t;
self->expression.next = NULL;
self->isconst = false;
+ self->uses = 0;
memset(&self->constval, 0, sizeof(self->constval));
self->ir_v = NULL;
if (owner->expression.vtype != TYPE_VECTOR &&
owner->expression.vtype != TYPE_FIELD) {
- asterror(ctx, "member-access on an invalid owner of type %s\n", type_name[owner->expression.vtype]);
+ asterror(ctx, "member-access on an invalid owner of type %s", type_name[owner->expression.vtype]);
mem_d(self);
return NULL;
}
* on all the globals.
*/
if (!self->ir_v) {
- asterror(ast_ctx(self), "ast_value used before generated (%s)\n", self->name);
+ asterror(ast_ctx(self), "ast_value used before generated (%s)", self->name);
return false;
}
*out = self->ir_v;
v = ir_builder_create_field(ir, self->name, self->expression.next->expression.vtype);
if (!v)
return false;
+ v->context = ast_ctx(self);
if (self->isconst) {
- asterror(ast_ctx(self), "TODO: constant field pointers with value\n");
+ asterror(ast_ctx(self), "TODO: constant field pointers with value");
goto error;
}
self->ir_v = v;
v = ir_builder_create_global(ir, self->name, self->expression.vtype);
if (!v) {
- asterror(ast_ctx(self), "ir_builder_create_global failed\n");
+ asterror(ast_ctx(self), "ir_builder_create_global failed");
return false;
}
+ v->context = ast_ctx(self);
if (self->isconst) {
switch (self->expression.vtype)
goto error;
break;
case TYPE_FUNCTION:
- asterror(ast_ctx(self), "global of type function not properly generated\n");
+ asterror(ast_ctx(self), "global of type function not properly generated");
goto error;
/* Cannot generate an IR value for a function,
* need a pointer pointing to a function rather.
*/
default:
- asterror(ast_ctx(self), "TODO: global constant type %i\n", self->expression.vtype);
+ asterror(ast_ctx(self), "TODO: global constant type %i", self->expression.vtype);
break;
}
}
v = ir_function_create_local(func, self->name, self->expression.vtype, param);
if (!v)
return false;
+ v->context = ast_ctx(self);
/* A constant local... hmmm...
* I suppose the IR will have to deal with this
goto error;
break;
default:
- asterror(ast_ctx(self), "TODO: global constant type %i\n", self->expression.vtype);
+ asterror(ast_ctx(self), "TODO: global constant type %i", self->expression.vtype);
break;
}
}
irf = self->ir_func;
if (!irf) {
- asterror(ast_ctx(self), "ast_function's related ast_value was not generated yet\n");
+ asterror(ast_ctx(self), "ast_function's related ast_value was not generated yet");
return false;
}
}
self->curblock = ir_function_create_block(irf, "entry");
- if (!self->curblock)
+ if (!self->curblock) {
+ asterror(ast_ctx(self), "failed to allocate entry block for `%s`", self->name);
return false;
+ }
for (i = 0; i < self->blocks_count; ++i) {
ast_expression_codegen *gen = self->blocks[i]->expression.codegen;
/* TODO: check return types */
if (!self->curblock->is_return)
{
+ return ir_block_create_return(self->curblock, NULL);
+ /* From now on the parser has to handle this situation */
+#if 0
if (!self->vtype->expression.next ||
self->vtype->expression.next->expression.vtype == TYPE_VOID)
{
asterror(ast_ctx(self), "function `%s` missing return value", self->name);
return false;
}
+#endif
}
return true;
}
/* generate locals */
for (i = 0; i < self->locals_count; ++i)
{
- if (!ast_local_codegen(self->locals[i], func->ir_func, false))
+ if (!ast_local_codegen(self->locals[i], func->ir_func, false)) {
+ if (opts_debug)
+ asterror(ast_ctx(self), "failed to generate local `%s`", self->locals[i]->name);
return false;
+ }
}
for (i = 0; i < self->exprs_count; ++i)
*/
(void)lvalue;
if (self->expression.outr) {
- asterror(ast_ctx(self), "internal error: ast_return cannot be reused, it bears no result!\n");
+ asterror(ast_ctx(self), "internal error: ast_return cannot be reused, it bears no result!");
return false;
}
self->expression.outr = (ir_value*)1;
ir_block *cond = func->curblock;
ir_block *ontrue;
ir_block *onfalse;
+ ir_block *ontrue_endblock;
+ ir_block *onfalse_endblock;
ir_block *merge;
/* We don't output any value, thus also don't care about r/lvalue */
(void)lvalue;
if (self->expression.outr) {
- asterror(ast_ctx(self), "internal error: ast_ifthen cannot be reused, it bears no result!\n");
+ asterror(ast_ctx(self), "internal error: ast_ifthen cannot be reused, it bears no result!");
return false;
}
self->expression.outr = (ir_value*)1;
cgen = self->on_true->expression.codegen;
if (!(*cgen)((ast_expression*)(self->on_true), func, false, &dummy))
return false;
+
+ /* we now need to work from the current endpoint */
+ ontrue_endblock = func->curblock;
} else
ontrue = NULL;
cgen = self->on_false->expression.codegen;
if (!(*cgen)((ast_expression*)(self->on_false), func, false, &dummy))
return false;
+
+ /* we now need to work from the current endpoint */
+ onfalse_endblock = func->curblock;
} else
onfalse = NULL;
return false;
/* add jumps ot the merge block */
- if (ontrue && !ir_block_create_jump(ontrue, merge))
+ if (ontrue && !ontrue_endblock->final && !ir_block_create_jump(ontrue_endblock, merge))
return false;
- if (onfalse && !ir_block_create_jump(onfalse, merge))
+ if (onfalse && !onfalse_endblock->final && !ir_block_create_jump(onfalse_endblock, merge))
return false;
/* we create the if here, that way all blocks are ordered :)
(void)out;
if (self->expression.outr) {
- asterror(ast_ctx(self), "internal error: ast_loop cannot be reused, it bears no result!\n");
+ asterror(ast_ctx(self), "internal error: ast_loop cannot be reused, it bears no result!");
return false;
}
self->expression.outr = (ir_value*)1;
else if (bpostcond) tmpblock = bpostcond;
else if (bprecond) tmpblock = bprecond;
else tmpblock = bout;
- if (!ir_block_create_jump(end_bbody, tmpblock))
+ if (!end_bbody->final && !ir_block_create_jump(end_bbody, tmpblock))
return false;
}