mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 12:00:38 +00:00
ast referencing
This commit is contained in:
parent
e2c424d607
commit
b3e87c3280
5 changed files with 20 additions and 35 deletions
8
ast.c
8
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);
|
||||
}
|
||||
|
|
9
ast.h
9
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,
|
||||
|
|
12
parser.c
12
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)
|
||||
/* } */
|
||||
|
|
|
@ -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");
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
I: perl-opts.qc
|
||||
D: test perl operators
|
||||
T: -execute
|
||||
C: -std=gmqcc
|
||||
M: -1
|
||||
M: 0
|
||||
M: 1
|
Loading…
Reference in a new issue