shader: Bug fix: Some oeprators should be evaluated as bool

This commit is contained in:
Hajime Hoshi 2020-07-05 03:29:34 +09:00
parent fb63df48ae
commit f3651e23e4

View File

@ -91,8 +91,16 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
}, []shaderir.Type{t}, stmts, true
}
op, ok := shaderir.OpFromToken(e.Op)
if !ok {
cs.addError(e.Pos(), fmt.Sprintf("unexpected operator: %s", e.Op))
return nil, nil, nil, false
}
var t shaderir.Type
switch {
case op == shaderir.LessThanOp || op == shaderir.LessThanEqualOp || op == shaderir.GreaterThanOp || op == shaderir.GreaterThanEqualOp || op == shaderir.EqualOp || op == shaderir.NotEqualOp || op == shaderir.AndAnd || op == shaderir.OrOr:
t = shaderir.Type{Main: shaderir.Bool}
case lhst.Equal(&rhst):
t = lhst
case lhst.Main == shaderir.Float || lhst.Main == shaderir.Int:
@ -129,12 +137,6 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
return nil, nil, nil, false
}
op, ok := shaderir.OpFromToken(e.Op)
if !ok {
cs.addError(e.Pos(), fmt.Sprintf("unexpected operator: %s", e.Op))
return nil, nil, nil, false
}
return []shaderir.Expr{
{
Type: shaderir.Binary,