mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
shader: Add break/continue
This commit is contained in:
parent
c02213e900
commit
0e6f4fccc0
@ -391,6 +391,21 @@ func (cs *compileState) parseStmt(block *block, stmt ast.Stmt, inParams []variab
|
||||
Type: shaderir.Return,
|
||||
})
|
||||
|
||||
case *ast.BranchStmt:
|
||||
switch stmt.Tok {
|
||||
case token.BREAK:
|
||||
stmts = append(stmts, shaderir.Stmt{
|
||||
Type: shaderir.Break,
|
||||
})
|
||||
case token.CONTINUE:
|
||||
stmts = append(stmts, shaderir.Stmt{
|
||||
Type: shaderir.Continue,
|
||||
})
|
||||
default:
|
||||
cs.addError(stmt.Pos(), fmt.Sprintf("invalid token: %s", stmt.Tok))
|
||||
return nil, false
|
||||
}
|
||||
|
||||
case *ast.ExprStmt:
|
||||
exprs, _, ss, ok := cs.parseExpr(block, stmt.X)
|
||||
if !ok {
|
||||
|
20
internal/shader/testdata/for2.expected.vs
vendored
Normal file
20
internal/shader/testdata/for2.expected.vs
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
void F0(out vec2 l0) {
|
||||
vec2 l1 = vec2(0);
|
||||
vec2 l3 = vec2(0);
|
||||
l1 = vec2(0.0);
|
||||
for (int l2 = 0; l2 < 100; l2++) {
|
||||
(l1).x = ((l1).x) + (l2);
|
||||
if (((l1).x) >= (100.0)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
l3 = vec2(0.0);
|
||||
for (float l4 = 10.0; l4 >= 0.0; l4 -= 2.0) {
|
||||
if (((l3).x) < (100.0)) {
|
||||
continue;
|
||||
}
|
||||
(l3).x = ((l3).x) + (l4);
|
||||
}
|
||||
l0 = l1;
|
||||
return;
|
||||
}
|
19
internal/shader/testdata/for2.go
vendored
Normal file
19
internal/shader/testdata/for2.go
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
func Foo() vec2 {
|
||||
v := vec2(0)
|
||||
for i := 0; i < 100; i++ {
|
||||
v.x += i
|
||||
if v.x >= 100 {
|
||||
break
|
||||
}
|
||||
}
|
||||
v2 := vec2(0)
|
||||
for i := 10.0; i >= 0; i -= 2 {
|
||||
if v2.x < 100 {
|
||||
continue
|
||||
}
|
||||
v2.x += i
|
||||
}
|
||||
return v
|
||||
}
|
Loading…
Reference in New Issue
Block a user