]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.h
Removed params from ast_function again. It really is superfluous to copy them, just...
[xonotic/gmqcc.git] / ast.h
diff --git a/ast.h b/ast.h
index d0ce67a02aba7846dd0ce31fb6049cdae7e2edc7..8ae190d2ff1fb70b700a758760c08a885ed876ae 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
  */
@@ -115,6 +116,8 @@ struct ast_value_s
      */
     MEM_VECTOR_MAKE(ast_value*, params);
 };
+MEM_VECTOR_PROTO(ast_value, ast_value*, params);
+
 ast_value* ast_value_new(lex_ctx ctx, const char *name, int qctype);
 /* This will NOT delete an underlying ast_function */
 void ast_value_delete(ast_value*);
@@ -122,7 +125,7 @@ void ast_value_delete(ast_value*);
 bool ast_value_set_name(ast_value*, const char *name);
 
 bool ast_value_codegen(ast_value*, ast_function*, bool lvalue, ir_value**);
-bool ast_local_codegen(ast_value *self, ir_function *func);
+bool ast_local_codegen(ast_value *self, ir_function *func, bool isparam);
 bool ast_global_codegen(ast_value *self, ir_builder *ir);
 
 /* Binary
@@ -284,6 +287,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
  *
  */
@@ -319,6 +345,8 @@ struct ast_function_s
     ast_value  *vtype;
     const char *name;
 
+    int builtin;
+
     ir_function *ir_func;
     ir_block    *curblock;
     ir_block    *breakblock;
@@ -332,6 +360,13 @@ struct ast_function_s
     char         labelbuf[64];
 
     MEM_VECTOR_MAKE(ast_block*, blocks);
+
+    /* contrary to the params in ast_value, these are the parameter variables
+     * which are to be used in expressions.
+     * The ast_value for the function contains only the parameter types used
+     * to generate ast_calls, and ast_call contains the parameter values
+     * used in that call.
+     */
 };
 ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype);
 /* This will NOT delete the underlying ast_value */