shader: Bug fix: Comparison with constants didn't work

This commit is contained in:
Hajime Hoshi 2020-07-05 17:33:03 +09:00
parent 3eaa7dd0e1
commit f4a72165e4
3 changed files with 23 additions and 4 deletions

View File

@ -78,11 +78,21 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
if op == token.QUO && lhs[0].Const.Kind() == gconstant.Int && rhs[0].Const.Kind() == gconstant.Int {
op = token.QUO_ASSIGN
}
v := gconstant.BinaryOp(lhs[0].Const, op, rhs[0].Const)
t := shaderir.Type{Main: shaderir.Int}
if v.Kind() == gconstant.Float {
t = shaderir.Type{Main: shaderir.Float}
var v gconstant.Value
var t shaderir.Type
switch op {
case token.EQL, token.NEQ, token.LSS, token.LEQ, token.GTR, token.GEQ:
v = gconstant.MakeBool(gconstant.Compare(lhs[0].Const, op, rhs[0].Const))
t = shaderir.Type{Main: shaderir.Bool}
default:
v = gconstant.BinaryOp(lhs[0].Const, op, rhs[0].Const)
if v.Kind() == gconstant.Float {
t = shaderir.Type{Main: shaderir.Float}
} else {
t = shaderir.Type{Main: shaderir.Int}
}
}
return []shaderir.Expr{
{
Type: shaderir.NumberExpr,

View File

@ -0,0 +1,4 @@
void F0(out bool l0) {
l0 = true;
return;
}

5
internal/shader/testdata/bool.go vendored Normal file
View File

@ -0,0 +1,5 @@
package main
func Foo() bool {
return 1.0 == 1.0
}