]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
ast_call node; codegen dummy
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 28 Jun 2012 14:15:51 +0000 (16:15 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 28 Jun 2012 14:15:51 +0000 (16:15 +0200)
ast.c
ast.h

diff --git a/ast.c b/ast.c
index 49446a111d7035085c90981018c91b02e48f5e06..409285d16b9b686286f3f455693b8a3a4ade50c0 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -308,6 +308,31 @@ void ast_loop_delete(ast_loop *self)
     mem_d(self);
 }
 
+ast_call* ast_call_new(lex_ctx ctx,
+                       ast_expression *funcexpr)
+{
+    ast_instantiate(ast_call, ctx, ast_call_delete);
+    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_call_codegen);
+
+    MEM_VECTOR_INIT(self, params);
+
+    return self;
+}
+
+void ast_call_delete(ast_call *self)
+{
+    size_t i;
+    for (i = 0; i < self->params_count; ++i)
+        ast_unref(self->params[i]);
+    MEM_VECTOR_CLEAR(self, params);
+
+    if (self->func)
+        ast_unref(self->func);
+
+    ast_expression_delete((ast_expression*)self);
+    mem_d(self);
+}
+
 ast_store* ast_store_new(lex_ctx ctx, int op,
                          ast_value *dest, ast_expression *source)
 {
@@ -1148,3 +1173,9 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
 
     return true;
 }
+
+bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value **out)
+{
+    /* TODO: call ir codegen */
+    return false;
+}
diff --git a/ast.h b/ast.h
index d0ce67a02aba7846dd0ce31fb6049cdae7e2edc7..f355716f70d04aeb39fa33f656b1d42217d2f3b6 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -40,6 +40,7 @@ typedef struct ast_entfield_s   ast_entfield;
 typedef struct ast_ifthen_s     ast_ifthen;
 typedef struct ast_ternary_s    ast_ternary;
 typedef struct ast_loop_s       ast_loop;
+typedef struct ast_call_s       ast_call;
 
 /* Node interface with common components
  */
@@ -284,6 +285,29 @@ void ast_loop_delete(ast_loop*);
 
 bool ast_loop_codegen(ast_loop*, ast_function*, bool lvalue, ir_value**);
 
+/* CALL node
+ *
+ * Contains an ast_expression as target, rather than an ast_function/value.
+ * Since it's how QC works, every ast_function has an ast_value
+ * associated anyway - in other words, the VM contains function
+ * pointers for every function anyway. Thus, this node will call
+ * expression.
+ * Additionally it contains a list of ast_expressions as parameters.
+ * Since calls can return values, an ast_call is also an ast_expression.
+ */
+struct ast_call_s
+{
+    ast_expression_common expression;
+    ast_expression *func;
+    MEM_VECTOR_MAKE(ast_expression*, params);
+};
+ast_call* ast_call_new(lex_ctx ctx,
+                       ast_expression *funcexpr);
+void ast_call_delete(ast_call*);
+bool ast_call_codegen(ast_call*, ast_function*, bool lvalue, ir_value**);
+
+MEM_VECTOR_PROTO(ast_call, ast_expression*, params);
+
 /* Blocks
  *
  */