internal/shader: refactoring

This commit is contained in:
Hajime Hoshi 2023-09-12 03:27:30 +09:00
parent 73e4423fe7
commit 5e30e1ee1d
2 changed files with 5 additions and 10 deletions

View File

@ -155,16 +155,6 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
if lhst.Main != shaderir.None || rhst.Main != shaderir.None {
t = shaderir.Type{Main: shaderir.Bool}
}
case token.AND, token.OR, token.XOR, token.AND_NOT:
if lhs[0].Const.Kind() != gconstant.Int {
cs.addError(e.Pos(), fmt.Sprintf("operator %s not defined on %s (%s)", op, lhs[0].Const.String(), lhst.String()))
return nil, nil, nil, false
}
if rhs[0].Const.Kind() != gconstant.Int {
cs.addError(e.Pos(), fmt.Sprintf("operator %s not defined on %s (%s)", op, rhs[0].Const.String(), rhst.String()))
return nil, nil, nil, false
}
fallthrough
default:
v = gconstant.BinaryOp(lhs[0].Const, op, rhs[0].Const)
switch {

View File

@ -84,6 +84,11 @@ func AreValidTypesForBinaryOp(op Op, lhs, rhs *Expr, lhst, rhst Type) bool {
if op == ModOp {
return lhs.Const.Kind() == constant.Int && rhs.Const.Kind() == constant.Int
}
if op == And || op == Or || op == Xor {
return lhs.Const.Kind() == constant.Int && rhs.Const.Kind() == constant.Int
}
return true
}