]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
assignable return value now lives in ast_function, as globals can get overwritten...
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 50396538a32cba1d1a0e4f699bfd3c80d20a9afc..4af3e3cafbd894c7b3beda8e736c0f48aec743ff 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1104,6 +1104,7 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype)
     self->varargs          = NULL;
     self->argc             = NULL;
     self->fixedparams      = NULL;
+    self->return_value     = NULL;
 
     return self;
 }
@@ -1133,6 +1134,8 @@ void ast_function_delete(ast_function *self)
         ast_delete(self->argc);
     if (self->fixedparams)
         ast_unref(self->fixedparams);
+    if (self->return_value)
+        ast_unref(self->return_value);
     mem_d(self);
 }
 
@@ -1625,6 +1628,12 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
         return true;
     }
 
+    // have a local return value variable?
+    if (self->return_value) {
+        if (!ast_local_codegen(self->return_value, self->ir_func, false))
+            return false;
+    }
+
     if (!vec_size(self->blocks)) {
         compile_error(ast_ctx(self), "function `%s` has no body", self->name);
         return false;