shader: Bug fix: a binary expression for an int and a float did not work

This commit is contained in:
Hajime Hoshi 2020-06-20 18:10:23 +09:00
parent 5e0e12d290
commit 255da0367f
3 changed files with 8 additions and 8 deletions

View File

@ -855,18 +855,18 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
t = lhst t = lhst
} else if lhst.Main == shaderir.Float || lhst.Main == shaderir.Int { } else if lhst.Main == shaderir.Float || lhst.Main == shaderir.Int {
switch rhst.Main { switch rhst.Main {
case shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4: case shaderir.Float, shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4:
t = rhst t = rhst
default: default:
cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", e.X, e.Op, e.Y)) cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", lhst.String(), e.Op, rhst.String()))
return nil, nil, nil return nil, nil, nil
} }
} else if rhst.Main == shaderir.Float || rhst.Main == shaderir.Int { } else if rhst.Main == shaderir.Float || rhst.Main == shaderir.Int {
switch lhst.Main { switch lhst.Main {
case shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4: case shaderir.Float, shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4:
t = lhst t = lhst
default: default:
cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", e.X, e.Op, e.Y)) cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", lhst.String(), e.Op, rhst.String()))
return nil, nil, nil return nil, nil, nil
} }
} }

View File

@ -60,7 +60,7 @@ func (p *Program) structName(t *Type) string {
if t.Main != Struct { if t.Main != Struct {
panic("shaderir: the given type at structName must be a struct") panic("shaderir: the given type at structName must be a struct")
} }
s := t.serialize() s := t.String()
if n, ok := p.structNames[s]; ok { if n, ok := p.structNames[s]; ok {
return n return n
} }

View File

@ -43,7 +43,7 @@ func (t *Type) Equal(rhs *Type) bool {
return true return true
} }
func (t *Type) serialize() string { func (t *Type) String() string {
switch t.Main { switch t.Main {
case None: case None:
return "none" return "none"
@ -68,12 +68,12 @@ func (t *Type) serialize() string {
case Texture2D: case Texture2D:
return "sampler2D" return "sampler2D"
case Array: case Array:
return fmt.Sprintf("%s[%d]", t.Sub[0].serialize(), t.Length) return fmt.Sprintf("%s[%d]", t.Sub[0].String(), t.Length)
case Struct: case Struct:
str := "struct{" str := "struct{"
sub := make([]string, 0, len(t.Sub)) sub := make([]string, 0, len(t.Sub))
for _, st := range t.Sub { for _, st := range t.Sub {
sub = append(sub, st.serialize()) sub = append(sub, st.String())
} }
str += strings.Join(sub, ",") str += strings.Join(sub, ",")
str += "}" str += "}"