mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-03-22 18:51:24 +00:00
more fixes
This commit is contained in:
parent
1538e69f93
commit
d0ee56f25f
3 changed files with 37 additions and 22 deletions
17
fold.c
17
fold.c
|
@ -75,17 +75,17 @@ static GMQCC_INLINE vec3_t vec3_neg(vec3_t a) {
|
|||
|
||||
static GMQCC_INLINE vec3_t vec3_xor(vec3_t a, vec3_t b) {
|
||||
vec3_t out;
|
||||
out.x = (qcfloat_t)((qcint_t)a.x ^ (qcint_t)b.x);
|
||||
out.y = (qcfloat_t)((qcint_t)a.y ^ (qcint_t)b.y);
|
||||
out.z = (qcfloat_t)((qcint_t)a.z ^ (qcint_t)b.z);
|
||||
out.x = (qcfloat_t)(((qcint_t)a.x) ^ ((qcint_t)b.x));
|
||||
out.y = (qcfloat_t)(((qcint_t)a.y) ^ ((qcint_t)b.y));
|
||||
out.z = (qcfloat_t)(((qcint_t)a.z) ^ ((qcint_t)b.z));
|
||||
return out;
|
||||
}
|
||||
|
||||
static GMQCC_INLINE vec3_t vec3_xorvf(vec3_t a, qcfloat_t b) {
|
||||
vec3_t out;
|
||||
out.x = (qcfloat_t)((qcint_t)a.x ^ (qcint_t)b);
|
||||
out.y = (qcfloat_t)((qcint_t)a.y ^ (qcint_t)b);
|
||||
out.z = (qcfloat_t)((qcint_t)a.z ^ (qcint_t)b);
|
||||
out.x = (qcfloat_t)(((qcint_t)a.x) ^ ((qcint_t)b));
|
||||
out.y = (qcfloat_t)(((qcint_t)a.y) ^ ((qcint_t)b));
|
||||
out.z = (qcfloat_t)(((qcint_t)a.z) ^ ((qcint_t)b));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,8 @@ static GMQCC_INLINE bool vec3_pbool(vec3_t a) {
|
|||
}
|
||||
|
||||
static GMQCC_INLINE bool fold_can_1(const ast_value *val) {
|
||||
return (ast_istype((ast_expression*)val, ast_value) && val->hasvalue && val->cvq == CV_CONST && ((ast_expression*)val)->vtype != TYPE_FUNCTION);
|
||||
return (ast_istype(((ast_expression*)(val)), ast_value) && val->hasvalue && (val->cvq == CV_CONST) &&
|
||||
((ast_expression*)(val))->vtype != TYPE_FUNCTION);
|
||||
}
|
||||
|
||||
static GMQCC_INLINE bool fold_can_2(const ast_value *v1, const ast_value *v2) {
|
||||
|
@ -149,7 +150,7 @@ static GMQCC_INLINE bool fold_immediate_true(fold_t *fold, ast_value *v) {
|
|||
case TYPE_VECTOR:
|
||||
if (OPTS_FLAG(CORRECT_LOGIC))
|
||||
return vec3_pbool(v->constval.vvec);
|
||||
return !!v->constval.vvec.x;
|
||||
return !!(v->constval.vvec.x);
|
||||
case TYPE_STRING:
|
||||
if (!v->constval.vstring)
|
||||
return false;
|
||||
|
|
39
parser.c
39
parser.c
|
@ -504,7 +504,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
|||
|
||||
case opid1('+'):
|
||||
if (exprs[0]->vtype != exprs[1]->vtype ||
|
||||
(exprs[0]->vtype != TYPE_VECTOR && exprs[0]->vtype != TYPE_FLOAT) )
|
||||
(exprs[0]->vtype != TYPE_VECTOR && exprs[0]->vtype != TYPE_FLOAT) )
|
||||
{
|
||||
compile_error(ctx, "invalid types used in expression: cannot add type %s and %s",
|
||||
type_name[exprs[0]->vtype],
|
||||
|
@ -597,10 +597,19 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
|||
if (!(out = fold_op(parser->fold, op, exprs))) {
|
||||
if (exprs[0]->vtype == TYPE_FLOAT)
|
||||
out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F, exprs[0], exprs[1]);
|
||||
else if (exprs[0]->vtype == TYPE_VECTOR)
|
||||
out = (ast_expression*)ast_binary_new(ctx, INSTR_MUL_VF, exprs[0], out);
|
||||
else /* TODO stot */
|
||||
{
|
||||
else if (exprs[0]->vtype == TYPE_VECTOR) {
|
||||
out = (ast_expression*)ast_binary_new (
|
||||
ctx,
|
||||
INSTR_MUL_VF,
|
||||
exprs[0],
|
||||
(ast_expression*)ast_binary_new(
|
||||
ctx,
|
||||
INSTR_DIV_F,
|
||||
(ast_expression*)parser->fold->imm_float[1],
|
||||
exprs[1]
|
||||
)
|
||||
);
|
||||
} else {
|
||||
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 expression: cannot divide types %s and %s", ty1, ty2);
|
||||
|
@ -758,13 +767,13 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
|||
generated_op += 1; /* INSTR_OR */
|
||||
case opid2('&','&'):
|
||||
generated_op += INSTR_AND;
|
||||
if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) {
|
||||
ast_type_to_string(exprs[0], ty1, sizeof(ty1));
|
||||
ast_type_to_string(exprs[1], ty2, sizeof(ty2));
|
||||
compile_error(ctx, "invalid types for logical operation with -fperl-logic: %s and %s", ty1, ty2);
|
||||
return false;
|
||||
}
|
||||
if (!(out = fold_op(parser->fold, op, exprs))) {
|
||||
if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) {
|
||||
ast_type_to_string(exprs[0], ty1, sizeof(ty1));
|
||||
ast_type_to_string(exprs[1], ty2, sizeof(ty2));
|
||||
compile_error(ctx, "invalid types for logical operation with -fperl-logic: %s and %s", ty1, ty2);
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < 2; ++i) {
|
||||
if (OPTS_FLAG(CORRECT_LOGIC) && exprs[i]->vtype == TYPE_VECTOR) {
|
||||
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_V, exprs[i]);
|
||||
|
@ -816,7 +825,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
|||
compile_error(ctx, "invalid types used in exponentiation: %s and %s",
|
||||
ty1, ty2);
|
||||
return false;
|
||||
} else if (!(out = fold_op(parser->fold, op, exprs))) {
|
||||
}
|
||||
|
||||
if (!(out = fold_op(parser->fold, op, exprs))) {
|
||||
ast_call *gencall = ast_call_new(parser_ctx(parser), intrin_func(parser, "pow"));
|
||||
vec_push(gencall->params, exprs[0]);
|
||||
vec_push(gencall->params, exprs[1]);
|
||||
|
@ -832,7 +843,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
|||
ty1, ty2);
|
||||
|
||||
return false;
|
||||
} else if (!(out = fold_op(parser->fold, op, exprs))) {
|
||||
}
|
||||
|
||||
if (!(out = fold_op(parser->fold, op, exprs))) {
|
||||
ast_binary *eq = ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]);
|
||||
|
||||
eq->refs = AST_REF_NONE;
|
||||
|
|
3
parser.h
3
parser.h
|
@ -36,7 +36,8 @@ typedef struct {
|
|||
hash_table_t *imm_string_dotranslate; /* map<string, ast_value*> */
|
||||
} fold_t;
|
||||
|
||||
#define parser_ctx(p) ((p)->lex->tok.ctx)
|
||||
#define parser_ctx(p) ((p)->lex->tok.ctx)
|
||||
|
||||
typedef struct parser_s {
|
||||
lex_file *lex;
|
||||
int tok;
|
||||
|
|
Loading…
Reference in a new issue