mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
shader: Bug fix: Resolve types in a binary expression correctly
This commit is contained in:
parent
f36d6c02a9
commit
5e0e12d290
@ -833,23 +833,43 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
|
||||
|
||||
var stmts []shaderir.Stmt
|
||||
|
||||
// Prase RHS first for the order of the statements.
|
||||
rhs, t0, ss := cs.parseExpr(block, e.Y)
|
||||
if len(rhs) != 1 {
|
||||
cs.addError(e.Pos(), fmt.Sprintf("multiple-value context is not available at a binary operator: %s", e.Y))
|
||||
return nil, nil, nil
|
||||
}
|
||||
stmts = append(stmts, ss...)
|
||||
|
||||
lhs, t1, ss := cs.parseExpr(block, e.X)
|
||||
// Prase LHS first for the order of the statements.
|
||||
lhs, ts, ss := cs.parseExpr(block, e.X)
|
||||
if len(lhs) != 1 {
|
||||
cs.addError(e.Pos(), fmt.Sprintf("multiple-value context is not available at a binary operator: %s", e.X))
|
||||
return nil, nil, nil
|
||||
}
|
||||
stmts = append(stmts, ss...)
|
||||
lhst := ts[0]
|
||||
|
||||
// TODO: Check the compatibility of t0 and t1
|
||||
_ = t1
|
||||
rhs, ts, ss := cs.parseExpr(block, e.Y)
|
||||
if len(rhs) != 1 {
|
||||
cs.addError(e.Pos(), fmt.Sprintf("multiple-value context is not available at a binary operator: %s", e.Y))
|
||||
return nil, nil, nil
|
||||
}
|
||||
stmts = append(stmts, ss...)
|
||||
rhst := ts[0]
|
||||
|
||||
var t shaderir.Type
|
||||
if lhst.Equal(&rhst) {
|
||||
t = lhst
|
||||
} else if lhst.Main == shaderir.Float || lhst.Main == shaderir.Int {
|
||||
switch rhst.Main {
|
||||
case shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4:
|
||||
t = rhst
|
||||
default:
|
||||
cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", e.X, e.Op, e.Y))
|
||||
return nil, nil, nil
|
||||
}
|
||||
} else if rhst.Main == shaderir.Float || rhst.Main == shaderir.Int {
|
||||
switch lhst.Main {
|
||||
case shaderir.Vec2, shaderir.Vec3, shaderir.Vec4, shaderir.Mat2, shaderir.Mat3, shaderir.Mat4:
|
||||
t = lhst
|
||||
default:
|
||||
cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", e.X, e.Op, e.Y))
|
||||
return nil, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
return []shaderir.Expr{
|
||||
{
|
||||
@ -857,7 +877,7 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
|
||||
Op: op,
|
||||
Exprs: []shaderir.Expr{lhs[0], rhs[0]},
|
||||
},
|
||||
}, t0, stmts
|
||||
}, []shaderir.Type{t}, stmts
|
||||
case *ast.CallExpr:
|
||||
var (
|
||||
callee shaderir.Expr
|
||||
|
5
internal/shader/testdata/define2.expected.vs
vendored
5
internal/shader/testdata/define2.expected.vs
vendored
@ -2,8 +2,13 @@ void F0(out vec2 l0) {
|
||||
vec2 l1 = vec2(0);
|
||||
vec2 l2 = vec2(0);
|
||||
vec2 l3 = vec2(0);
|
||||
vec2 l4 = vec2(0);
|
||||
vec2 l5 = vec2(0);
|
||||
vec2 l6 = vec2(0);
|
||||
F1(l3);
|
||||
l2 = (1.0) * (l3);
|
||||
F1(l6);
|
||||
l5 = (l6) * (1.0);
|
||||
l0 = l2;
|
||||
return;
|
||||
}
|
||||
|
5
internal/shader/testdata/define2.go
vendored
5
internal/shader/testdata/define2.go
vendored
@ -1,8 +1,9 @@
|
||||
package main
|
||||
|
||||
func Foo() vec2 {
|
||||
x := 1 * Bar()
|
||||
return x
|
||||
x0 := 1 * Bar()
|
||||
x1 := Bar() * 1
|
||||
return x0
|
||||
}
|
||||
|
||||
func Bar() vec2 {
|
||||
|
Loading…
Reference in New Issue
Block a user