]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
ast referencing
authorDale Weiler <killfieldengine@gmail.com>
Tue, 5 Feb 2013 17:14:56 +0000 (17:14 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 5 Feb 2013 17:14:56 +0000 (17:14 +0000)
ast.c
ast.h
parser.c
tests/perl-ops.qc [deleted file]
tests/perl-ops.tmpl [deleted file]

diff --git a/ast.c b/ast.c
index 4eb250fad19c360756aae26a362d5cc063bdbe3f..c68ba9f065eecca940f1ef92c9b46e0989095613 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -406,13 +406,17 @@ ast_binary* ast_binary_new(lex_ctx ctx, int op,
     else
         self->expression.vtype = left->expression.vtype;
 
+    /* references all */
+    self->refs = AST_REF_ALL;
+
     return self;
 }
 
 void ast_binary_delete(ast_binary *self)
 {
-    ast_unref(self->left);
-    ast_unref(self->right);
+    if (self->refs & AST_REF_LEFT)  ast_unref(self->left);
+    if (self->refs & AST_REF_RIGHT) ast_unref(self->right);
+
     ast_expression_delete((ast_expression*)self);
     mem_d(self);
 }
diff --git a/ast.h b/ast.h
index 18f02a8e259f34da73ca4ecebbf94bdd4b1dcb00..83c700a97938d696b1515ea83bb601a4f439e697 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -218,6 +218,13 @@ ast_expression* ast_type_copy(lex_ctx ctx, const ast_expression *ex);
 void ast_type_adopt_impl(ast_expression *self, const ast_expression *other);
 void ast_type_to_string(ast_expression *e, char *buf, size_t bufsize);
 
+typedef enum ast_binary_ref_s {
+    AST_REF_LEFT  = 1 << 1,
+    AST_REF_RIGHT = 1 << 2,
+    AST_REF_ALL   = (AST_REF_LEFT | AST_REF_RIGHT)
+} ast_binary_ref;
+
+
 /* Binary
  *
  * A value-returning binary expression.
@@ -229,6 +236,8 @@ struct ast_binary_s
     int             op;
     ast_expression *left;
     ast_expression *right;
+    ast_binary_ref  refs;
+    
 };
 ast_binary* ast_binary_new(lex_ctx    ctx,
                            int        op,
index 81bbbcbcba2cc8bd58e74eb16e436337bd7643b2..f589d63629361ddc6b48edd09d20299bb93227ef 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1085,23 +1085,21 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 else if (ConstF(0) > ConstF(1))
                     out = (ast_expression*)parser_const_float_1(parser);
             } else {
+                ast_binary *eq = ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]);
+
+                eq->refs = false; /* references nothing */
+
                     /* if (lt) { */
                 out = (ast_expression*)ast_ternary_new(ctx,
                         (ast_expression*)ast_binary_new(ctx, INSTR_LT, exprs[0], exprs[1]),
-
                         /* out = -1 */
                         (ast_expression*)parser_const_float_neg1(parser),
-
                     /* } else { */
                         /* if (eq) { */
-                        (ast_expression*)ast_ternary_new(ctx,
-                            (ast_expression*)ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]),
-
+                        (ast_expression*)ast_ternary_new(ctx, (ast_expression*)eq,
                             /* out = 0 */
                             (ast_expression*)parser_const_float_0(parser),
-
                         /* } else { */
-
                             /* out = 1 */
                             (ast_expression*)parser_const_float_1(parser)
                         /* } */
diff --git a/tests/perl-ops.qc b/tests/perl-ops.qc
deleted file mode 100644 (file)
index ee6631b..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-void main() {
-    /* so far only one perl operator is implemented */
-    float x = 100;
-    float y = 200;
-    float z = 300;
-
-    /* to ensure runtime */
-    x += 1;
-    y += 1;
-    z += 1;
-
-    float test_x = (x <=> x + 1); // -1 less than
-    float test_y = (x <=> x);     //  0 equal
-    float test_z = (x <=> x - 1); //  1 greater than
-
-    print(ftos(test_x), "\n");
-    print(ftos(test_y), "\n");
-    print(ftos(test_z), "\n");
-}
diff --git a/tests/perl-ops.tmpl b/tests/perl-ops.tmpl
deleted file mode 100644 (file)
index f3f1eb5..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-I: perl-opts.qc
-D: test perl operators
-T: -execute
-C: -std=gmqcc
-M: -1
-M: 0
-M: 1