]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
Implemented [[accumulate]] attribute. This will hopefully be used by Xonotic to repla...
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index cef33bd73889ca3216d73d54740249fecf174c6f..cb4ad064979ad824b70ec33dde0df709819529c7 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1183,6 +1183,7 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
     if (!vtype) {
         compile_error(ast_ctx(self), "internal error: ast_function_new condition 0");
         goto cleanup;
+    } else if (vtype->hasvalue || vtype->expression.vtype != TYPE_FUNCTION) {
     } else if (vtype->hasvalue || vtype->expression.vtype != TYPE_FUNCTION) {
         compile_error(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)",
                  (int)!vtype,
@@ -1212,6 +1213,9 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
     self->fixedparams      = NULL;
     self->return_value     = NULL;
 
+    self->accumulate   = NULL;
+    self->accumulation = 0;
+
     return self;
 
 cleanup:
@@ -1792,6 +1796,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
     ir_value    *dummy;
     ast_expression         *ec;
     ast_expression_codegen *cgen;
+
     size_t    i;
 
     (void)ir;
@@ -1868,6 +1873,14 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
         }
     }
 
+    /* generate the call for any accumulation */
+    if (self->accumulate) {
+        ast_call *call = ast_call_new(ast_ctx(self), (ast_expression*)self->accumulate->vtype);
+        for (i = 0; i < vec_size(ec->params); i++)
+            vec_push(call->params, (ast_expression*)ec->params[i]);
+        vec_push(vec_last(self->blocks)->exprs, (ast_expression*)call);
+    }
+
     for (i = 0; i < vec_size(self->blocks); ++i) {
         cgen = self->blocks[i]->expression.codegen;
         if (!(*cgen)((ast_expression*)self->blocks[i], self, false, &dummy))