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);
}
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.
int op;
ast_expression *left;
ast_expression *right;
+ ast_binary_ref refs;
+
};
ast_binary* ast_binary_new(lex_ctx ctx,
int op,
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)
/* } */
+++ /dev/null
-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");
-}
+++ /dev/null
-I: perl-opts.qc
-D: test perl operators
-T: -execute
-C: -std=gmqcc
-M: -1
-M: 0
-M: 1