From: Dale Weiler Date: Tue, 5 Feb 2013 17:14:56 +0000 (+0000) Subject: ast referencing X-Git-Tag: before-library~150 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b3e87c328009c3c5b1b700d600733906d7792f59;p=xonotic%2Fgmqcc.git ast referencing --- diff --git a/ast.c b/ast.c index 4eb250f..c68ba9f 100644 --- 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 18f02a8..83c700a 100644 --- 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, diff --git a/parser.c b/parser.c index 81bbbcb..f589d63 100644 --- 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 index ee6631b..0000000 --- a/tests/perl-ops.qc +++ /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 index f3f1eb5..0000000 --- a/tests/perl-ops.tmpl +++ /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