]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
ast_loop - codegen dummied
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 19:57:13 +0000 (21:57 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 19:57:13 +0000 (21:57 +0200)
ast.c
ast.h

diff --git a/ast.c b/ast.c
index 3e1738c73d00a14cda4418de137baca9b1d57538..7a68ba352bca72bfeb869d80c63740accf8c5a59 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -273,6 +273,37 @@ void ast_ternary_delete(ast_ternary *self)
     mem_d(self);
 }
 
+ast_loop* ast_loop_new(lex_ctx ctx,
+                       ast_expression *initexpr,
+                       ast_expression *precond,
+                       ast_expression *postcond,
+                       ast_expression *increment)
+{
+    ast_instantiate(ast_loop, ctx, ast_loop_delete);
+    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_loop_codegen);
+
+    self->initexpr  = initexpr;
+    self->precond   = precond;
+    self->postcond  = postcond;
+    self->increment = increment;
+
+    return self;
+}
+
+void ast_loop_delete(ast_loop *self)
+{
+    if (self->initexpr)
+        ast_unref(self->initexpr);
+    if (self->precond)
+        ast_unref(self->precond);
+    if (self->postcond)
+        ast_unref(self->postcond);
+    if (self->increment)
+        ast_unref(self->increment);
+    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)
 {
@@ -885,3 +916,8 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
 
     return true;
 }
+
+bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value **out)
+{
+    return false;
+}
diff --git a/ast.h b/ast.h
index 5b8324acf49cbba24119c02fd1dd380409b7ff52..bc24c53439cca6f09cf60dff17f57911b58531cd 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -39,6 +39,7 @@ typedef struct ast_store_s      ast_store;
 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;
 
 /* Node interface with common components
  */
@@ -241,6 +242,45 @@ void ast_ternary_delete(ast_ternary*);
 
 bool ast_ternary_codegen(ast_ternary*, ast_function*, bool lvalue, ir_value**);
 
+/* A general loop node
+ *
+ * For convenience it contains 4 parts:
+ * -) (ini) = initializing expression
+ * -) (pre) = pre-loop condition
+ * -) (pst) = post-loop condition
+ * -) (inc) = "increment" expression
+ * The following is a psudo-representation of this loop
+ * note that '=>' bears the logical meaning of "implies".
+ * (a => b) equals (!a || b)
+
+{ini};
+while (has_pre => {pre})
+{
+    {body};
+
+continue:      // a 'continue' will jump here
+    if (has_pst => {pst})
+        break;
+
+    {inc};
+}
+ */
+struct ast_loop_s
+{
+    ast_expression_common expression;
+    ast_expression *initexpr;
+    ast_expression *precond;
+    ast_expression *postcond;
+    ast_expression *increment;
+};
+ast_loop* ast_loop_new(lex_ctx, ctx,
+                       ast_expression *initexpr,
+                       ast_expression *precond,
+                       ast_expression *postcond,
+                       ast_expression *increment);
+void ast_loop_delete(ast_loop*);
+
+bool ast_loop_codegen(ast_loop*, ast_function*, bool lvalue, ir_value**);
 
 /* Blocks
  *