mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
shader: Refactoring
This commit is contained in:
parent
a0db26f234
commit
8833e46c7e
@ -393,24 +393,23 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
stmts = append(stmts, ss...)
|
stmts = append(stmts, ss...)
|
||||||
if len(exprs) == 0 {
|
|
||||||
if len(exprs) != len(outParams) {
|
|
||||||
cs.addError(stmt.Pos(), fmt.Sprintf("the number of returning variables must be %d but %d", len(outParams), len(stmt.Results)))
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(exprs) > 1 {
|
if len(exprs) > 1 {
|
||||||
if len(stmt.Results) > 1 || len(outParams) == 1 {
|
if len(stmt.Results) > 1 || len(outParams) == 1 {
|
||||||
cs.addError(r.Pos(), "single-value context and multiple-value context cannot be mixed")
|
cs.addError(r.Pos(), "single-value context and multiple-value context cannot be mixed")
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Is this logic really true?
|
|
||||||
if len(exprs) > 1 || len(outParams) > 1 {
|
if len(outParams) > 1 && len(stmt.Results) == 1 {
|
||||||
if len(exprs) != len(outParams) && len(stmt.Results) != len(outParams) {
|
if len(exprs) == 1 {
|
||||||
cs.addError(stmt.Pos(), fmt.Sprintf("the number of returning variables must be %d but %d", len(outParams), len(stmt.Results)))
|
cs.addError(stmt.Pos(), fmt.Sprintf("the number of returning variables must be %d but %d", len(outParams), len(stmt.Results)))
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
if len(exprs) > 1 && len(exprs) != len(outParams) {
|
||||||
|
cs.addError(stmt.Pos(), fmt.Sprintf("the number of returning variables must be %d but %d", len(outParams), len(exprs)))
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for j, t := range ts {
|
for j, t := range ts {
|
||||||
|
@ -283,3 +283,78 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
t.Errorf("error must be non-nil but was nil")
|
t.Errorf("error must be non-nil but was nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestShaderMultipleValueReturn(t *testing.T) {
|
||||||
|
if _, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
|
func Foo() (float, float) {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
|
return vec4(0)
|
||||||
|
}
|
||||||
|
`)); err == nil {
|
||||||
|
t.Errorf("error must be non-nil but was nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
|
func Foo() float {
|
||||||
|
return 0.0, 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
|
return vec4(0)
|
||||||
|
}
|
||||||
|
`)); err == nil {
|
||||||
|
t.Errorf("error must be non-nil but was nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
|
func Foo() (float, float, float) {
|
||||||
|
return 0.0, 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
|
return vec4(0)
|
||||||
|
}
|
||||||
|
`)); err == nil {
|
||||||
|
t.Errorf("error must be non-nil but was nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
|
func Foo() (float, float) {
|
||||||
|
return 0.0, 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
func Foo2() (float, float, float) {
|
||||||
|
return Foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
|
return vec4(0)
|
||||||
|
}
|
||||||
|
`)); err == nil {
|
||||||
|
t.Errorf("error must be non-nil but was nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := NewShader([]byte(`package main
|
||||||
|
|
||||||
|
func Foo() (float, float, float) {
|
||||||
|
return 0.0, 0.0, 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
func Foo2() (float, float, float) {
|
||||||
|
return Foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
|
return vec4(0.0)
|
||||||
|
}
|
||||||
|
`)); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user