]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Introduce an ast_store rather than splitting ast_binary
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 26 Apr 2012 09:36:46 +0000 (11:36 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 26 Apr 2012 09:36:46 +0000 (11:36 +0200)
ast.c
ast.h

diff --git a/ast.c b/ast.c
index 9d55fed0e9f902ff5a3a3ea2399bb4c119766b7d..595dea16f2d4327f7f0ae8397a6d2c13937fded8 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -111,36 +111,7 @@ ast_binary* ast_binary_new(lex_ctx_t ctx, int op,
                            ast_value* left, ast_value* right)
 {
     ast_instantiate(ast_binary, ctx, ast_binary_delete);
-    switch (op) {
-    case INSTR_STORE_F:
-    case INSTR_STORE_V:
-    case INSTR_STORE_S:
-    case INSTR_STORE_ENT:
-    case INSTR_STORE_FLD:
-    case INSTR_STORE_FNC:
-    case INSTR_STOREP_F:
-    case INSTR_STOREP_V:
-    case INSTR_STOREP_S:
-    case INSTR_STOREP_ENT:
-    case INSTR_STOREP_FLD:
-    case INSTR_STOREP_FNC:
-#if 0
-    case INSTR_STORE_I:
-    case INSTR_STORE_IF:
-    case INSTR_STORE_FI:
-    case INSTR_STOREP_I:
-    case INSTR_STOREP_IF:
-    case INSTR_STOREP_FI:
-    case INSTR_STORE_P:
-    case INSTR_STOREP_P:
-    case INSTR_STOREP_C:
-#endif
-        ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_bin_store_codegen);
-        break;
-    default:
-        ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_binary_codegen);
-        break;
-    }
+    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_binary_codegen);
 
     self->op = op;
     self->left = left;
@@ -154,6 +125,24 @@ void ast_binary_delete(ast_binary *self)
     mem_d(self);
 }
 
+ast_store* ast_store_new(lex_ctx_t ctx, int op,
+                         ast_value *dest, ast_value *source)
+{
+    ast_instantiate(ast_store, ctx, ast_store_delete);
+    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_store_codegen);
+
+    self->op = op;
+    self->dest = dest;
+    self->source = source;
+
+    return self;
+}
+
+void ast_store_delete(ast_store *self)
+{
+    mem_d(self);
+}
+
 ast_block* ast_block_new(lex_ctx_t ctx)
 {
     ast_instantiate(ast_block, ctx, ast_block_delete);
@@ -221,7 +210,7 @@ bool ast_block_codegen(ast_block *self, ast_function *func, ir_value **out)
     return false;
 }
 
-bool ast_bin_store_codegen(ast_binary *self, ast_function *func, ir_value **out)
+bool ast_store_codegen(ast_store *self, ast_function *func, ir_value **out)
 {
     return false;
 }
diff --git a/ast.h b/ast.h
index 041bff7959749b747ca125838bd54f9783474b25..2eab19183352eb7f15bf064a6a3aa9f4211cfc93 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -37,6 +37,7 @@ typedef struct ast_value_s      ast_value;
 typedef struct ast_function_s   ast_function;
 typedef struct ast_block_s      ast_block;
 typedef struct ast_binary_s     ast_binary;
+typedef struct ast_store_s      ast_store;
 
 /* Node interface with common components
  */
@@ -46,6 +47,10 @@ typedef struct
     lex_ctx_t        context;
     /* I don't feel comfortable using keywords like 'delete' as names... */
     ast_node_delete *destroy;
+    /* keep: if a node contains this node, 'keep'
+     * prevents its dtor from destroying this node as well.
+     */
+    bool             keep;
 } ast_node_common;
 
 #define ast_delete(x) ( ( (ast_node*)(x) ) -> node.destroy )((ast_node*)(x))
@@ -125,11 +130,26 @@ void ast_binary_delete(ast_binary*);
 /* hmm, seperate functions?
 bool ast_block_codegen(ast_block*, ast_function*, ir_value**);
  */
-/* maybe for this one */
-bool ast_bin_store_codegen(ast_binary*, ast_function*, ir_value**);
-
 bool ast_binary_codegen(ast_binary*, ast_function*, ir_value**);
 
+/* Store
+ *
+ * Stores left<-right and returns left.
+ * Specialized binary expression node
+ */
+struct ast_store_s
+{
+    ast_expression_common expression;
+    int       op;
+    ast_value *dest;
+    ast_value *source;
+};
+ast_store* ast_store_new(lex_ctx_t ctx, int op,
+                         ast_value *d, ast_value *s);
+void ast_store_delete(ast_store*);
+
+bool ast_store_codegen(ast_store*, ast_function*, ir_value**);
+
 /* Blocks
  *
  */