mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
shader: Implement operators ++ and --
This commit is contained in:
parent
f95ca46c99
commit
e15ee77e8e
@ -17,6 +17,7 @@ package shader
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
gconstant "go/constant"
|
||||
"go/token"
|
||||
"strings"
|
||||
|
||||
@ -173,6 +174,37 @@ func (cs *compileState) parseStmt(block *block, stmt ast.Stmt, inParams []variab
|
||||
Exprs: exprs,
|
||||
Blocks: bs,
|
||||
})
|
||||
case *ast.IncDecStmt:
|
||||
exprs, _, ss, ok := cs.parseExpr(block, stmt.X)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
stmts = append(stmts, ss...)
|
||||
var op shaderir.Op
|
||||
switch stmt.Tok {
|
||||
case token.INC:
|
||||
op = shaderir.Add
|
||||
case token.DEC:
|
||||
op = shaderir.Sub
|
||||
}
|
||||
stmts = append(stmts, shaderir.Stmt{
|
||||
Type: shaderir.Assign,
|
||||
Exprs: []shaderir.Expr{
|
||||
exprs[0],
|
||||
{
|
||||
Type: shaderir.Binary,
|
||||
Op: op,
|
||||
Exprs: []shaderir.Expr{
|
||||
exprs[0],
|
||||
{
|
||||
Type: shaderir.NumberExpr,
|
||||
Const: gconstant.MakeInt64(1),
|
||||
ConstType: shaderir.ConstTypeInt,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
case *ast.ReturnStmt:
|
||||
for i, r := range stmt.Results {
|
||||
exprs, _, ss, ok := cs.parseExpr(block, r)
|
||||
|
10
internal/shader/testdata/inc.expected.vs
vendored
Normal file
10
internal/shader/testdata/inc.expected.vs
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
void F0(out vec2 l0) {
|
||||
int l1 = 0;
|
||||
int l2 = 0;
|
||||
l1 = 0;
|
||||
l1 = (l1) + (1);
|
||||
l2 = 1;
|
||||
l2 = (l2) - (1);
|
||||
l0 = vec2(l1, l2);
|
||||
return;
|
||||
}
|
9
internal/shader/testdata/inc.go
vendored
Normal file
9
internal/shader/testdata/inc.go
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
func Foo() vec2 {
|
||||
l0 := 0
|
||||
l0++
|
||||
l1 := 1
|
||||
l1--
|
||||
return vec2(l0, l1)
|
||||
}
|
Loading…
Reference in New Issue
Block a user