v->cvq = self->cvq;
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) ||
- !ir_function_finalize(self->setter->constval.vfunc->ir_func))
- return false;
- }
- if (self->getter) {
- if (!ast_global_codegen(self->getter, func->owner, false) ||
- !ast_function_codegen(self->getter->constval.vfunc, func->owner) ||
- !ir_function_finalize(self->getter->constval.vfunc->ir_func))
- return false;
- }
+ if (!ast_generate_accessors(self, func->owner))
+ return false;
return true;
error: /* clean up */
return false;
}
+bool ast_generate_accessors(ast_value *asvalue, ir_builder *ir)
+{
+ if (asvalue->setter) {
+ if (!ast_global_codegen (asvalue->setter, ir, false) ||
+ !ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||
+ !ir_function_finalize(asvalue->setter->constval.vfunc->ir_func))
+ {
+ compile_error(ast_ctx(asvalue), "internal error: failed to generate setter for `%s`", asvalue->name);
+ return false;
+ }
+ }
+ if (asvalue->getter) {
+ if (!ast_global_codegen (asvalue->getter, ir, false) ||
+ !ast_function_codegen(asvalue->getter->constval.vfunc, ir) ||
+ !ir_function_finalize(asvalue->getter->constval.vfunc->ir_func))
+ {
+ compile_error(ast_ctx(asvalue), "internal error: failed to generate getter for `%s`", asvalue->name);
+ return false;
+ }
+ }
+ return true;
+}
+
bool ast_function_codegen(ast_function *self, ir_builder *ir)
{
ir_function *irf;
if (!ast_istype(parser->globals[i], ast_value))
continue;
asvalue = (ast_value*)(parser->globals[i]);
- if (asvalue->setter) {
- if (!ast_global_codegen(asvalue->setter, ir, false) ||
- !ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||
- !ir_function_finalize(asvalue->setter->constval.vfunc->ir_func))
- {
- printf("failed to generate setter for %s\n", asvalue->name);
- ir_builder_delete(ir);
- return false;
- }
- }
- if (asvalue->getter) {
- if (!ast_global_codegen(asvalue->getter, ir, false) ||
- !ast_function_codegen(asvalue->getter->constval.vfunc, ir) ||
- !ir_function_finalize(asvalue->getter->constval.vfunc->ir_func))
- {
- printf("failed to generate getter for %s\n", asvalue->name);
- ir_builder_delete(ir);
- return false;
- }
+ if (!ast_generate_accessors(asvalue, ir)) {
+ ir_builder_delete(ir);
+ return false;
}
}
for (i = 0; i < vec_size(parser->fields); ++i) {
continue;
if (asvalue->expression.vtype != TYPE_ARRAY)
continue;
- if (asvalue->setter) {
- if (!ast_global_codegen(asvalue->setter, ir, false) ||
- !ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||
- !ir_function_finalize(asvalue->setter->constval.vfunc->ir_func))
- {
- printf("failed to generate setter for %s\n", asvalue->name);
- ir_builder_delete(ir);
- return false;
- }
- }
- if (asvalue->getter) {
- if (!ast_global_codegen(asvalue->getter, ir, false) ||
- !ast_function_codegen(asvalue->getter->constval.vfunc, ir) ||
- !ir_function_finalize(asvalue->getter->constval.vfunc->ir_func))
- {
- printf("failed to generate getter for %s\n", asvalue->name);
- ir_builder_delete(ir);
- return false;
- }
+ if (!ast_generate_accessors(asvalue, ir)) {
+ ir_builder_delete(ir);
+ return false;
}
}
for (i = 0; i < vec_size(parser->functions); ++i) {