]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
store_param storetype, parameter value list added to ast_function
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 21e43b3933ad188e425f7b496155001bb3382360..767dde92badaf54f15bc3e196d42ba38a2ba4270 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -316,8 +316,11 @@ ast_call* ast_call_new(lex_ctx ctx,
 
     MEM_VECTOR_INIT(self, params);
 
+    self->func = funcexpr;
+
     return self;
 }
+MEM_VEC_FUNCTIONS(ast_call, ast_expression*, params)
 
 void ast_call_delete(ast_call *self)
 {
@@ -433,6 +436,9 @@ void ast_function_delete(ast_function *self)
     for (i = 0; i < self->blocks_count; ++i)
         ast_delete(self->blocks[i]);
     MEM_VECTOR_CLEAR(self, blocks);
+    /* ast_delete, not unref, there must only have been references
+     * to the parameter values inside the blocks deleted above.
+     */
     for (i = 0; i < self->params_count; ++i)
         ast_delete(self->params[i]);
     MEM_VECTOR_CLEAR(self, params);
@@ -488,8 +494,10 @@ bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_valu
      * and the ast-user should take care of ast_global_codegen to be used
      * on all the globals.
      */
-    if (!self->ir_v)
+    if (!self->ir_v) {
+        printf("ast_value used before generated (%s)\n", self->name);
         return false;
+    }
     *out = self->ir_v;
     return true;
 }
@@ -504,6 +512,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir)
             return false;
 
         self->constval.vfunc->ir_func = func;
+        self->ir_v = func->value;
         /* The function is filled later on ast_function_codegen... */
         return true;
     }
@@ -608,9 +617,9 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
         return false;
     }
 
-    for (i = 0; i < self->params_count; ++i)
+    for (i = 0; i < self->vtype->params_count; ++i)
     {
-        if (!ir_function_params_add(irf, self->params[i]->expression.vtype))
+        if (!ir_function_params_add(irf, self->vtype->params[i]->expression.vtype))
             return false;
     }
 
@@ -634,7 +643,9 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
     {
         if (!self->vtype->expression.next ||
             self->vtype->expression.next->expression.vtype == TYPE_VOID)
+        {
             return ir_block_create_return(self->curblock, NULL);
+        }
         else
         {
             /* error("missing return"); */