ast_value *imm_float_zero;
ast_value *imm_float_one;
+ ast_value *imm_float_neg_one;
+
ast_value *imm_vector_zero;
+
ast_value *nil;
ast_value *reserved_version;
return parser->imm_float_zero;
}
+static ast_value* parser_const_float_neg1(parser_t *parser) {
+ if (!parser->imm_float_neg_one)
+ parser->imm_float_neg_one = parser_const_float(parser, -1);
+ return parser->imm_float_neg_one;
+}
+
static ast_value* parser_const_float_1(parser_t *parser)
{
if (!parser->imm_float_one)
*/
static bool rotate_entfield_array_index_nodes(ast_expression **out)
{
- ast_array_index *index;
+ ast_array_index *index, *oldindex;
ast_entfield *entfield;
ast_value *field;
sub = index->index;
entity = entfield->entity;
- ast_delete(index);
+ oldindex = index;
index = ast_array_index_new(ctx, (ast_expression*)field, sub);
entfield = ast_entfield_new(ctx, entity, (ast_expression*)index);
*out = (ast_expression*)entfield;
+ oldindex->array = NULL;
+ oldindex->index = NULL;
+ ast_delete(oldindex);
+
return true;
}
return false;
}
}
- if (!ast_block_set_type(blocks[0], exprs[1]))
- return false;
+ ast_block_set_type(blocks[0], exprs[1]);
vec_push(sy->out, syblock(ctx, blocks[0]));
return true;
out = (ast_expression*)ast_ternary_new(ctx, exprs[0], exprs[1], exprs[2]);
break;
+ case opid3('<', '=', '>'): /* -1, 0, or 1 */
+ if (NotSameType(TYPE_FLOAT)) {
+ ast_type_to_string(exprs[0], ty1, sizeof(ty1));
+ ast_type_to_string(exprs[1], ty2, sizeof(ty2));
+ compile_error(ctx, "invalid types used in comparision: %s and %s",
+ ty1, ty2);
+
+ return false;
+ }
+
+ if (CanConstFold(exprs[0], exprs[1])) {
+ if (ConstF(0) < ConstF(1))
+ out = (ast_expression*)parser_const_float_neg1(parser);
+ else if (ConstF(0) == ConstF(1))
+ out = (ast_expression*)parser_const_float_0(parser);
+ 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*)eq,
+ /* out = 0 */
+ (ast_expression*)parser_const_float_0(parser),
+ /* } else { */
+ /* out = 1 */
+ (ast_expression*)parser_const_float_1(parser)
+ /* } */
+ )
+ /* } */
+ );
+
+ }
+ break;
+
case opid1('>'):
generated_op += 1; /* INSTR_GT */
case opid1('<'):
}
else
assignop = type_storep_instr[exprs[0]->expression.vtype];
- if (assignop == AINSTR_END || !ast_compare_type(field->expression.next, exprs[1]))
+ if (assignop == VINSTR_END || !ast_compare_type(field->expression.next, exprs[1]))
{
ast_type_to_string(field->expression.next, ty1, sizeof(ty1));
ast_type_to_string(exprs[1], ty2, sizeof(ty2));
assignop = type_store_instr[exprs[0]->expression.vtype];
}
- if (assignop == AINSTR_END) {
+ if (assignop == VINSTR_END) {
ast_type_to_string(exprs[0], ty1, sizeof(ty1));
ast_type_to_string(exprs[1], ty2, sizeof(ty2));
compile_error(ctx, "invalid types in assignment: cannot assign %s to %s", ty2, ty1);
asbinstore->keep_dest = true;
out = (ast_expression*)asbinstore;
break;
+
+ case opid2('~', 'P'):
+ if (exprs[0]->expression.vtype != TYPE_FLOAT) {
+ ast_type_to_string(exprs[0], ty1, sizeof(ty1));
+ compile_error(ast_ctx(exprs[0]), "invalid type for bit not: %s", ty1);
+ return false;
+ }
+
+ if(CanConstFold1(exprs[0]))
+ out = (ast_expression*)parser_const_float(parser, ~(qcint)ConstF(0));
+ else
+ out = (ast_expression*)ast_binary_new(ctx, INSTR_SUB_F, (ast_expression*)parser_const_float_neg1(parser), exprs[0]);
+ break;
}
#undef NotSameType
}
}
if (o == operator_count) {
- /* no operator found... must be the end of the statement */
- break;
+ compile_error(parser_ctx(parser), "unknown operator: %s", parser_tokval(parser));
+ goto onerr;
}
/* found an operator */
op = &operators[o];
ast_expression *functype = fld_think->expression.next;
thinkfunc = ast_value_new(parser_ctx(parser), parser_tokval(parser), functype->expression.vtype);
- if (!thinkfunc || !ast_type_adopt(thinkfunc, functype)) {
+ if (!thinkfunc) { /* || !ast_type_adopt(thinkfunc, functype)*/
ast_unref(framenum);
parseerror(parser, "failed to create implicit prototype for `%s`", parser_tokval(parser));
return false;
}
+ ast_type_adopt(thinkfunc, functype);
if (!parser_next(parser)) {
ast_unref(framenum);
}
}
+ if (var->hasvalue) {
+ parseerror(parser, "function `%s` declared with multiple bodies", var->name);
+ ast_block_delete(block);
+ goto enderr;
+ }
+
func = ast_function_new(ast_ctx(var), var->name, var);
if (!func) {
parseerror(parser, "failed to allocate function for `%s`", var->name);
}
else
{
- parseerror(parser, "unexpected token: %s", parser->lex->tok.value);
+ parseerror(parser, "unexpected token: `%s`", parser->lex->tok.value);
return false;
}
return true;