mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 01:42:05 +01:00
parent
7549f4fcd6
commit
5ddf1df423
@ -112,31 +112,24 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
// If either is typed, resolve the other type.
|
// If either is typed, resolve the other type.
|
||||||
// If both are untyped, keep them untyped.
|
// If both are untyped, keep them untyped.
|
||||||
if lhst.Main != shaderir.None || rhst.Main != shaderir.None {
|
if lhst.Main != shaderir.None || rhst.Main != shaderir.None {
|
||||||
// TODO: Remove ConstType (#2550)
|
|
||||||
if lhs[0].Const != nil {
|
if lhs[0].Const != nil {
|
||||||
switch lhs[0].Const.Kind() {
|
switch lhs[0].Const.Kind() {
|
||||||
case gconstant.Float:
|
case gconstant.Float:
|
||||||
lhst = shaderir.Type{Main: shaderir.Float}
|
lhst = shaderir.Type{Main: shaderir.Float}
|
||||||
lhs[0].ConstType = shaderir.ConstTypeFloat
|
|
||||||
case gconstant.Int:
|
case gconstant.Int:
|
||||||
lhst = shaderir.Type{Main: shaderir.Int}
|
lhst = shaderir.Type{Main: shaderir.Int}
|
||||||
lhs[0].ConstType = shaderir.ConstTypeInt
|
|
||||||
case gconstant.Bool:
|
case gconstant.Bool:
|
||||||
lhst = shaderir.Type{Main: shaderir.Bool}
|
lhst = shaderir.Type{Main: shaderir.Bool}
|
||||||
lhs[0].ConstType = shaderir.ConstTypeBool
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rhs[0].Const != nil {
|
if rhs[0].Const != nil {
|
||||||
switch rhs[0].Const.Kind() {
|
switch rhs[0].Const.Kind() {
|
||||||
case gconstant.Float:
|
case gconstant.Float:
|
||||||
rhst = shaderir.Type{Main: shaderir.Float}
|
rhst = shaderir.Type{Main: shaderir.Float}
|
||||||
rhs[0].ConstType = shaderir.ConstTypeFloat
|
|
||||||
case gconstant.Int:
|
case gconstant.Int:
|
||||||
rhst = shaderir.Type{Main: shaderir.Int}
|
rhst = shaderir.Type{Main: shaderir.Int}
|
||||||
rhs[0].ConstType = shaderir.ConstTypeInt
|
|
||||||
case gconstant.Bool:
|
case gconstant.Bool:
|
||||||
rhst = shaderir.Type{Main: shaderir.Bool}
|
rhst = shaderir.Type{Main: shaderir.Bool}
|
||||||
rhs[0].ConstType = shaderir.ConstTypeBool
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,9 +267,8 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
}
|
}
|
||||||
return []shaderir.Expr{
|
return []shaderir.Expr{
|
||||||
{
|
{
|
||||||
Type: shaderir.NumberExpr,
|
Type: shaderir.NumberExpr,
|
||||||
Const: gconstant.MakeInt64(int64(argts[0].Length)),
|
Const: gconstant.MakeInt64(int64(argts[0].Length)),
|
||||||
ConstType: shaderir.ConstTypeInt,
|
|
||||||
},
|
},
|
||||||
}, []shaderir.Type{{Main: shaderir.Int}}, stmts, true
|
}, []shaderir.Type{{Main: shaderir.Int}}, stmts, true
|
||||||
case shaderir.BoolF:
|
case shaderir.BoolF:
|
||||||
@ -287,9 +279,8 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
}
|
}
|
||||||
return []shaderir.Expr{
|
return []shaderir.Expr{
|
||||||
{
|
{
|
||||||
Type: shaderir.NumberExpr,
|
Type: shaderir.NumberExpr,
|
||||||
Const: args[0].Const,
|
Const: args[0].Const,
|
||||||
ConstType: shaderir.ConstTypeBool,
|
|
||||||
},
|
},
|
||||||
}, []shaderir.Type{{Main: shaderir.Bool}}, stmts, true
|
}, []shaderir.Type{{Main: shaderir.Bool}}, stmts, true
|
||||||
}
|
}
|
||||||
@ -304,9 +295,8 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
}
|
}
|
||||||
return []shaderir.Expr{
|
return []shaderir.Expr{
|
||||||
{
|
{
|
||||||
Type: shaderir.NumberExpr,
|
Type: shaderir.NumberExpr,
|
||||||
Const: v,
|
Const: v,
|
||||||
ConstType: shaderir.ConstTypeInt,
|
|
||||||
},
|
},
|
||||||
}, []shaderir.Type{{Main: shaderir.Int}}, stmts, true
|
}, []shaderir.Type{{Main: shaderir.Int}}, stmts, true
|
||||||
}
|
}
|
||||||
@ -319,9 +309,8 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
}
|
}
|
||||||
return []shaderir.Expr{
|
return []shaderir.Expr{
|
||||||
{
|
{
|
||||||
Type: shaderir.NumberExpr,
|
Type: shaderir.NumberExpr,
|
||||||
Const: v,
|
Const: v,
|
||||||
ConstType: shaderir.ConstTypeFloat,
|
|
||||||
},
|
},
|
||||||
}, []shaderir.Type{{Main: shaderir.Float}}, stmts, true
|
}, []shaderir.Type{{Main: shaderir.Float}}, stmts, true
|
||||||
}
|
}
|
||||||
@ -482,7 +471,6 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
// If the argument is a non-typed constant value, treat this as a float value (#1874).
|
// If the argument is a non-typed constant value, treat this as a float value (#1874).
|
||||||
if args[i].Const != nil && argts[i].Main == shaderir.None && gconstant.ToFloat(args[i].Const).Kind() != gconstant.Unknown {
|
if args[i].Const != nil && argts[i].Main == shaderir.None && gconstant.ToFloat(args[i].Const).Kind() != gconstant.Unknown {
|
||||||
args[i].Const = gconstant.ToFloat(args[i].Const)
|
args[i].Const = gconstant.ToFloat(args[i].Const)
|
||||||
args[i].ConstType = shaderir.ConstTypeFloat
|
|
||||||
argts[i] = shaderir.Type{Main: shaderir.Float}
|
argts[i] = shaderir.Type{Main: shaderir.Float}
|
||||||
}
|
}
|
||||||
if argts[i].Main != shaderir.Float && argts[i].Main != shaderir.Vec2 && argts[i].Main != shaderir.Vec3 && argts[i].Main != shaderir.Vec4 {
|
if argts[i].Main != shaderir.Float && argts[i].Main != shaderir.Vec2 && argts[i].Main != shaderir.Vec3 && argts[i].Main != shaderir.Vec4 {
|
||||||
@ -543,7 +531,6 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
// If the argument is a non-typed constant value, treat this as a float value (#1874).
|
// If the argument is a non-typed constant value, treat this as a float value (#1874).
|
||||||
if args[i].Const != nil && argts[i].Main == shaderir.None && gconstant.ToFloat(args[i].Const).Kind() != gconstant.Unknown {
|
if args[i].Const != nil && argts[i].Main == shaderir.None && gconstant.ToFloat(args[i].Const).Kind() != gconstant.Unknown {
|
||||||
args[i].Const = gconstant.ToFloat(args[i].Const)
|
args[i].Const = gconstant.ToFloat(args[i].Const)
|
||||||
args[i].ConstType = shaderir.ConstTypeFloat
|
|
||||||
argts[i] = shaderir.Type{Main: shaderir.Float}
|
argts[i] = shaderir.Type{Main: shaderir.Float}
|
||||||
}
|
}
|
||||||
if argts[i].Main != shaderir.Float && argts[i].Main != shaderir.Vec2 && argts[i].Main != shaderir.Vec3 && argts[i].Main != shaderir.Vec4 {
|
if argts[i].Main != shaderir.Float && argts[i].Main != shaderir.Vec2 && argts[i].Main != shaderir.Vec3 && argts[i].Main != shaderir.Vec4 {
|
||||||
@ -594,7 +581,6 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
// If the argument is a non-typed constant value, treat this as a float value (#1874).
|
// If the argument is a non-typed constant value, treat this as a float value (#1874).
|
||||||
if args[0].Const != nil && argts[0].Main == shaderir.None && gconstant.ToFloat(args[0].Const).Kind() != gconstant.Unknown {
|
if args[0].Const != nil && argts[0].Main == shaderir.None && gconstant.ToFloat(args[0].Const).Kind() != gconstant.Unknown {
|
||||||
args[0].Const = gconstant.ToFloat(args[0].Const)
|
args[0].Const = gconstant.ToFloat(args[0].Const)
|
||||||
args[0].ConstType = shaderir.ConstTypeFloat
|
|
||||||
argts[0] = shaderir.Type{Main: shaderir.Float}
|
argts[0] = shaderir.Type{Main: shaderir.Float}
|
||||||
}
|
}
|
||||||
switch callee.BuiltinFunc {
|
switch callee.BuiltinFunc {
|
||||||
@ -737,9 +723,8 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
if c, ok := block.findConstant(e.Name); ok {
|
if c, ok := block.findConstant(e.Name); ok {
|
||||||
return []shaderir.Expr{
|
return []shaderir.Expr{
|
||||||
{
|
{
|
||||||
Type: shaderir.NumberExpr,
|
Type: shaderir.NumberExpr,
|
||||||
Const: c.value,
|
Const: c.value,
|
||||||
ConstType: c.ctyp,
|
|
||||||
},
|
},
|
||||||
}, []shaderir.Type{c.typ}, nil, true
|
}, []shaderir.Type{c.typ}, nil, true
|
||||||
}
|
}
|
||||||
@ -928,9 +913,8 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
Index: idx,
|
Index: idx,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: shaderir.NumberExpr,
|
Type: shaderir.NumberExpr,
|
||||||
Const: gconstant.MakeInt64(int64(i)),
|
Const: gconstant.MakeInt64(int64(i)),
|
||||||
ConstType: shaderir.ConstTypeInt,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -966,7 +950,6 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
cs.addError(e.Pos(), fmt.Sprintf("constant %s truncated to integer", idx.Const.String()))
|
cs.addError(e.Pos(), fmt.Sprintf("constant %s truncated to integer", idx.Const.String()))
|
||||||
return nil, nil, nil, false
|
return nil, nil, nil, false
|
||||||
}
|
}
|
||||||
idx.ConstType = shaderir.ConstTypeInt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exprs, ts, ss, ok := cs.parseExpr(block, fname, e.X, markLocalVariableUsed)
|
exprs, ts, ss, ok := cs.parseExpr(block, fname, e.X, markLocalVariableUsed)
|
||||||
|
@ -37,7 +37,6 @@ type variable struct {
|
|||||||
type constant struct {
|
type constant struct {
|
||||||
name string
|
name string
|
||||||
typ shaderir.Type
|
typ shaderir.Type
|
||||||
ctyp shaderir.ConstType
|
|
||||||
value gconstant.Value
|
value gconstant.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,15 +549,6 @@ func (s *compileState) parseVariable(block *block, fname string, vs *ast.ValueSp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if es[0].Type == shaderir.NumberExpr {
|
|
||||||
switch t.Main {
|
|
||||||
case shaderir.Int:
|
|
||||||
es[0].ConstType = shaderir.ConstTypeInt
|
|
||||||
case shaderir.Float:
|
|
||||||
es[0].ConstType = shaderir.ConstTypeFloat
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, rt := range rts {
|
for i, rt := range rts {
|
||||||
if !canAssign(&t, &rt, es[i].Const) {
|
if !canAssign(&t, &rt, es[i].Const) {
|
||||||
s.addError(vs.Pos(), fmt.Sprintf("cannot use type %s as type %s in variable declaration", rt.String(), t.String()))
|
s.addError(vs.Pos(), fmt.Sprintf("cannot use type %s as type %s in variable declaration", rt.String(), t.String()))
|
||||||
@ -682,22 +672,17 @@ func (s *compileState) parseConstant(block *block, fname string, vs *ast.ValueSp
|
|||||||
}
|
}
|
||||||
|
|
||||||
c := es[0].Const
|
c := es[0].Const
|
||||||
constType := es[0].ConstType
|
|
||||||
switch t.Main {
|
switch t.Main {
|
||||||
case shaderir.Bool:
|
case shaderir.Bool:
|
||||||
constType = shaderir.ConstTypeBool
|
|
||||||
case shaderir.Int:
|
case shaderir.Int:
|
||||||
constType = shaderir.ConstTypeInt
|
|
||||||
c = gconstant.ToInt(c)
|
c = gconstant.ToInt(c)
|
||||||
case shaderir.Float:
|
case shaderir.Float:
|
||||||
constType = shaderir.ConstTypeFloat
|
|
||||||
c = gconstant.ToFloat(c)
|
c = gconstant.ToFloat(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
cs = append(cs, constant{
|
cs = append(cs, constant{
|
||||||
name: name,
|
name: name,
|
||||||
typ: t,
|
typ: t,
|
||||||
ctyp: constType,
|
|
||||||
value: c,
|
value: c,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ func (cs *compileState) forceToInt(node ast.Node, expr *shaderir.Expr) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
expr.Const = gconstant.ToInt(expr.Const)
|
expr.Const = gconstant.ToInt(expr.Const)
|
||||||
expr.ConstType = shaderir.ConstTypeInt
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +123,6 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
(rts[0].Main == shaderir.None || rts[0].Main == shaderir.Float) &&
|
(rts[0].Main == shaderir.None || rts[0].Main == shaderir.Float) &&
|
||||||
gconstant.ToFloat(rhs[0].Const).Kind() != gconstant.Unknown {
|
gconstant.ToFloat(rhs[0].Const).Kind() != gconstant.Unknown {
|
||||||
rhs[0].Const = gconstant.ToFloat(rhs[0].Const)
|
rhs[0].Const = gconstant.ToFloat(rhs[0].Const)
|
||||||
rhs[0].ConstType = shaderir.ConstTypeFloat
|
|
||||||
} else {
|
} else {
|
||||||
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: mismatched types %s and %s", lts[0].String(), rts[0].String()))
|
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: mismatched types %s and %s", lts[0].String(), rts[0].String()))
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -137,7 +135,6 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
gconstant.ToFloat(rhs[0].Const).Kind() != gconstant.Unknown)) {
|
gconstant.ToFloat(rhs[0].Const).Kind() != gconstant.Unknown)) {
|
||||||
if rhs[0].Const != nil {
|
if rhs[0].Const != nil {
|
||||||
rhs[0].Const = gconstant.ToFloat(rhs[0].Const)
|
rhs[0].Const = gconstant.ToFloat(rhs[0].Const)
|
||||||
rhs[0].ConstType = shaderir.ConstTypeFloat
|
|
||||||
}
|
}
|
||||||
} else if op == shaderir.MatrixMul && ((lts[0].Main == shaderir.Vec2 && rts[0].Main == shaderir.Mat2) ||
|
} else if op == shaderir.MatrixMul && ((lts[0].Main == shaderir.Vec2 && rts[0].Main == shaderir.Mat2) ||
|
||||||
(lts[0].Main == shaderir.Vec3 && rts[0].Main == shaderir.Mat3) ||
|
(lts[0].Main == shaderir.Vec3 && rts[0].Main == shaderir.Mat3) ||
|
||||||
@ -150,7 +147,6 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
gconstant.ToFloat(rhs[0].Const).Kind() != gconstant.Unknown)) {
|
gconstant.ToFloat(rhs[0].Const).Kind() != gconstant.Unknown)) {
|
||||||
if rhs[0].Const != nil {
|
if rhs[0].Const != nil {
|
||||||
rhs[0].Const = gconstant.ToFloat(rhs[0].Const)
|
rhs[0].Const = gconstant.ToFloat(rhs[0].Const)
|
||||||
rhs[0].ConstType = shaderir.ConstTypeFloat
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: mismatched types %s and %s", lts[0].String(), rts[0].String()))
|
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: mismatched types %s and %s", lts[0].String(), rts[0].String()))
|
||||||
@ -442,9 +438,8 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
Exprs: []shaderir.Expr{
|
Exprs: []shaderir.Expr{
|
||||||
exprs[0],
|
exprs[0],
|
||||||
{
|
{
|
||||||
Type: shaderir.NumberExpr,
|
Type: shaderir.NumberExpr,
|
||||||
Const: gconstant.MakeInt64(1),
|
Const: gconstant.MakeInt64(1),
|
||||||
ConstType: shaderir.ConstTypeInt,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -692,20 +687,6 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
|
|||||||
}
|
}
|
||||||
allblank = false
|
allblank = false
|
||||||
|
|
||||||
if r[0].Const != nil {
|
|
||||||
t, ok := block.findLocalVariableByIndex(l[0].Index)
|
|
||||||
if !ok {
|
|
||||||
cs.addError(pos, fmt.Sprintf("unexpected local variable index: %d", l[0].Index))
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
switch t.Main {
|
|
||||||
case shaderir.Int:
|
|
||||||
r[0].ConstType = shaderir.ConstTypeInt
|
|
||||||
case shaderir.Float:
|
|
||||||
r[0].ConstType = shaderir.ConstTypeFloat
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range lts {
|
for i := range lts {
|
||||||
if !canAssign(<s[i], &rts[i], r[i].Const) {
|
if !canAssign(<s[i], &rts[i], r[i].Const) {
|
||||||
cs.addError(pos, fmt.Sprintf("cannot use type %s as type %s in variable declaration", rts[i].String(), lts[i].String()))
|
cs.addError(pos, fmt.Sprintf("cannot use type %s as type %s in variable declaration", rts[i].String(), lts[i].String()))
|
||||||
|
@ -377,26 +377,17 @@ func (c *compileContext) function(p *shaderir.Program, f *shaderir.Func, prototy
|
|||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
func constantToNumberLiteral(t shaderir.ConstType, v constant.Value) string {
|
func constantToNumberLiteral(v constant.Value) string {
|
||||||
switch v.Kind() {
|
switch v.Kind() {
|
||||||
case constant.Bool:
|
case constant.Bool:
|
||||||
if t != shaderir.ConstTypeBool && t != shaderir.ConstTypeNone {
|
|
||||||
return fmt.Sprintf("!(unexpected const-type for bool: %d)", t)
|
|
||||||
}
|
|
||||||
if constant.BoolVal(v) {
|
if constant.BoolVal(v) {
|
||||||
return "true"
|
return "true"
|
||||||
}
|
}
|
||||||
return "false"
|
return "false"
|
||||||
case constant.Int:
|
case constant.Int:
|
||||||
if t != shaderir.ConstTypeInt && t != shaderir.ConstTypeNone {
|
|
||||||
return fmt.Sprintf("!(unexpected const-type for int: %d)", t)
|
|
||||||
}
|
|
||||||
x, _ := constant.Int64Val(v)
|
x, _ := constant.Int64Val(v)
|
||||||
return fmt.Sprintf("%d", x)
|
return fmt.Sprintf("%d", x)
|
||||||
case constant.Float:
|
case constant.Float:
|
||||||
if t != shaderir.ConstTypeFloat && t != shaderir.ConstTypeNone {
|
|
||||||
return fmt.Sprintf("!(unexpected const-type for float: %d)", t)
|
|
||||||
}
|
|
||||||
x, _ := constant.Float64Val(v)
|
x, _ := constant.Float64Val(v)
|
||||||
if i := math.Floor(x); i == x {
|
if i := math.Floor(x); i == x {
|
||||||
return fmt.Sprintf("%d.0", int64(i))
|
return fmt.Sprintf("%d.0", int64(i))
|
||||||
@ -477,7 +468,7 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
expr = func(e *shaderir.Expr) string {
|
expr = func(e *shaderir.Expr) string {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
case shaderir.NumberExpr:
|
case shaderir.NumberExpr:
|
||||||
return constantToNumberLiteral(e.ConstType, e.Const)
|
return constantToNumberLiteral(e.Const)
|
||||||
case shaderir.UniformVariable:
|
case shaderir.UniformVariable:
|
||||||
return fmt.Sprintf("U%d", e.Index)
|
return fmt.Sprintf("U%d", e.Index)
|
||||||
case shaderir.TextureVariable:
|
case shaderir.TextureVariable:
|
||||||
@ -564,14 +555,6 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
}
|
}
|
||||||
lines = append(lines, fmt.Sprintf("%s}", idt))
|
lines = append(lines, fmt.Sprintf("%s}", idt))
|
||||||
case shaderir.For:
|
case shaderir.For:
|
||||||
var ct shaderir.ConstType
|
|
||||||
switch s.ForVarType.Main {
|
|
||||||
case shaderir.Int:
|
|
||||||
ct = shaderir.ConstTypeInt
|
|
||||||
case shaderir.Float:
|
|
||||||
ct = shaderir.ConstTypeFloat
|
|
||||||
}
|
|
||||||
|
|
||||||
v := c.localVariableName(p, topBlock, s.ForVarIndex)
|
v := c.localVariableName(p, topBlock, s.ForVarIndex)
|
||||||
var delta string
|
var delta string
|
||||||
switch val, _ := constant.Float64Val(s.ForDelta); val {
|
switch val, _ := constant.Float64Val(s.ForDelta); val {
|
||||||
@ -584,10 +567,10 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
default:
|
default:
|
||||||
d := s.ForDelta
|
d := s.ForDelta
|
||||||
if val > 0 {
|
if val > 0 {
|
||||||
delta = fmt.Sprintf("%s += %s", v, constantToNumberLiteral(ct, d))
|
delta = fmt.Sprintf("%s += %s", v, constantToNumberLiteral(d))
|
||||||
} else {
|
} else {
|
||||||
d = constant.UnaryOp(token.SUB, d, 0)
|
d = constant.UnaryOp(token.SUB, d, 0)
|
||||||
delta = fmt.Sprintf("%s -= %s", v, constantToNumberLiteral(ct, d))
|
delta = fmt.Sprintf("%s -= %s", v, constantToNumberLiteral(d))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var op string
|
var op string
|
||||||
@ -599,8 +582,8 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := s.ForVarType
|
t := s.ForVarType
|
||||||
init := constantToNumberLiteral(ct, s.ForInit)
|
init := constantToNumberLiteral(s.ForInit)
|
||||||
end := constantToNumberLiteral(ct, s.ForEnd)
|
end := constantToNumberLiteral(s.ForEnd)
|
||||||
t0, t1 := typeString(&t)
|
t0, t1 := typeString(&t)
|
||||||
lines = append(lines, fmt.Sprintf("%sfor (%s %s%s = %s; %s %s %s; %s) {", idt, t0, v, t1, init, v, op, end, delta))
|
lines = append(lines, fmt.Sprintf("%sfor (%s %s%s = %s; %s %s %s; %s) {", idt, t0, v, t1, init, v, op, end, delta))
|
||||||
lines = append(lines, c.block(p, topBlock, s.Blocks[0], level+1)...)
|
lines = append(lines, c.block(p, topBlock, s.Blocks[0], level+1)...)
|
||||||
|
@ -310,26 +310,17 @@ func (c *compileContext) function(p *shaderir.Program, f *shaderir.Func, prototy
|
|||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
func constantToNumberLiteral(t shaderir.ConstType, v constant.Value) string {
|
func constantToNumberLiteral(v constant.Value) string {
|
||||||
switch v.Kind() {
|
switch v.Kind() {
|
||||||
case constant.Bool:
|
case constant.Bool:
|
||||||
if t != shaderir.ConstTypeBool && t != shaderir.ConstTypeNone {
|
|
||||||
return fmt.Sprintf("!(unexpected const-type for bool: %d)", t)
|
|
||||||
}
|
|
||||||
if constant.BoolVal(v) {
|
if constant.BoolVal(v) {
|
||||||
return "true"
|
return "true"
|
||||||
}
|
}
|
||||||
return "false"
|
return "false"
|
||||||
case constant.Int:
|
case constant.Int:
|
||||||
if t != shaderir.ConstTypeInt && t != shaderir.ConstTypeNone {
|
|
||||||
return fmt.Sprintf("!(unexpected const-type for int: %d)", t)
|
|
||||||
}
|
|
||||||
x, _ := constant.Int64Val(v)
|
x, _ := constant.Int64Val(v)
|
||||||
return fmt.Sprintf("%d", x)
|
return fmt.Sprintf("%d", x)
|
||||||
case constant.Float:
|
case constant.Float:
|
||||||
if t != shaderir.ConstTypeFloat && t != shaderir.ConstTypeNone {
|
|
||||||
return fmt.Sprintf("!(unexpected const-type for float: %d)", t)
|
|
||||||
}
|
|
||||||
x, _ := constant.Float64Val(v)
|
x, _ := constant.Float64Val(v)
|
||||||
if i := math.Floor(x); i == x {
|
if i := math.Floor(x); i == x {
|
||||||
return fmt.Sprintf("%d.0", int64(i))
|
return fmt.Sprintf("%d.0", int64(i))
|
||||||
@ -410,7 +401,7 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
expr = func(e *shaderir.Expr) string {
|
expr = func(e *shaderir.Expr) string {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
case shaderir.NumberExpr:
|
case shaderir.NumberExpr:
|
||||||
return constantToNumberLiteral(e.ConstType, e.Const)
|
return constantToNumberLiteral(e.Const)
|
||||||
case shaderir.UniformVariable:
|
case shaderir.UniformVariable:
|
||||||
return fmt.Sprintf("U%d", e.Index)
|
return fmt.Sprintf("U%d", e.Index)
|
||||||
case shaderir.TextureVariable:
|
case shaderir.TextureVariable:
|
||||||
@ -531,14 +522,6 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
}
|
}
|
||||||
lines = append(lines, fmt.Sprintf("%s}", idt))
|
lines = append(lines, fmt.Sprintf("%s}", idt))
|
||||||
case shaderir.For:
|
case shaderir.For:
|
||||||
var ct shaderir.ConstType
|
|
||||||
switch s.ForVarType.Main {
|
|
||||||
case shaderir.Int:
|
|
||||||
ct = shaderir.ConstTypeInt
|
|
||||||
case shaderir.Float:
|
|
||||||
ct = shaderir.ConstTypeFloat
|
|
||||||
}
|
|
||||||
|
|
||||||
v := c.localVariableName(p, topBlock, s.ForVarIndex)
|
v := c.localVariableName(p, topBlock, s.ForVarIndex)
|
||||||
var delta string
|
var delta string
|
||||||
switch val, _ := constant.Float64Val(s.ForDelta); val {
|
switch val, _ := constant.Float64Val(s.ForDelta); val {
|
||||||
@ -551,10 +534,10 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
default:
|
default:
|
||||||
d := s.ForDelta
|
d := s.ForDelta
|
||||||
if val > 0 {
|
if val > 0 {
|
||||||
delta = fmt.Sprintf("%s += %s", v, constantToNumberLiteral(ct, d))
|
delta = fmt.Sprintf("%s += %s", v, constantToNumberLiteral(d))
|
||||||
} else {
|
} else {
|
||||||
d = constant.UnaryOp(token.SUB, d, 0)
|
d = constant.UnaryOp(token.SUB, d, 0)
|
||||||
delta = fmt.Sprintf("%s -= %s", v, constantToNumberLiteral(ct, d))
|
delta = fmt.Sprintf("%s -= %s", v, constantToNumberLiteral(d))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var op string
|
var op string
|
||||||
@ -566,8 +549,8 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := s.ForVarType
|
t := s.ForVarType
|
||||||
init := constantToNumberLiteral(ct, s.ForInit)
|
init := constantToNumberLiteral(s.ForInit)
|
||||||
end := constantToNumberLiteral(ct, s.ForEnd)
|
end := constantToNumberLiteral(s.ForEnd)
|
||||||
t0, t1 := typeString(&t)
|
t0, t1 := typeString(&t)
|
||||||
lines = append(lines, fmt.Sprintf("%sfor (%s %s%s = %s; %s %s %s; %s) {", idt, t0, v, t1, init, v, op, end, delta))
|
lines = append(lines, fmt.Sprintf("%sfor (%s %s%s = %s; %s %s %s; %s) {", idt, t0, v, t1, init, v, op, end, delta))
|
||||||
lines = append(lines, c.block(p, topBlock, s.Blocks[0], level+1)...)
|
lines = append(lines, c.block(p, topBlock, s.Blocks[0], level+1)...)
|
||||||
|
@ -260,26 +260,17 @@ func (c *compileContext) function(p *shaderir.Program, f *shaderir.Func, prototy
|
|||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
func constantToNumberLiteral(t shaderir.ConstType, v constant.Value) string {
|
func constantToNumberLiteral(v constant.Value) string {
|
||||||
switch v.Kind() {
|
switch v.Kind() {
|
||||||
case constant.Bool:
|
case constant.Bool:
|
||||||
if t != shaderir.ConstTypeBool && t != shaderir.ConstTypeNone {
|
|
||||||
return fmt.Sprintf("!(unexpected const-type for bool: %d)", t)
|
|
||||||
}
|
|
||||||
if constant.BoolVal(v) {
|
if constant.BoolVal(v) {
|
||||||
return "true"
|
return "true"
|
||||||
}
|
}
|
||||||
return "false"
|
return "false"
|
||||||
case constant.Int:
|
case constant.Int:
|
||||||
if t != shaderir.ConstTypeInt && t != shaderir.ConstTypeNone {
|
|
||||||
return fmt.Sprintf("!(unexpected const-type for int: %d)", t)
|
|
||||||
}
|
|
||||||
x, _ := constant.Int64Val(v)
|
x, _ := constant.Int64Val(v)
|
||||||
return fmt.Sprintf("%d", x)
|
return fmt.Sprintf("%d", x)
|
||||||
case constant.Float:
|
case constant.Float:
|
||||||
if t != shaderir.ConstTypeFloat && t != shaderir.ConstTypeNone {
|
|
||||||
return fmt.Sprintf("!(unexpected const-type for float: %d)", t)
|
|
||||||
}
|
|
||||||
x, _ := constant.Float64Val(v)
|
x, _ := constant.Float64Val(v)
|
||||||
if i := math.Floor(x); i == x {
|
if i := math.Floor(x); i == x {
|
||||||
return fmt.Sprintf("%d.0", int64(i))
|
return fmt.Sprintf("%d.0", int64(i))
|
||||||
@ -352,7 +343,7 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
expr = func(e *shaderir.Expr) string {
|
expr = func(e *shaderir.Expr) string {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
case shaderir.NumberExpr:
|
case shaderir.NumberExpr:
|
||||||
return constantToNumberLiteral(e.ConstType, e.Const)
|
return constantToNumberLiteral(e.Const)
|
||||||
case shaderir.UniformVariable:
|
case shaderir.UniformVariable:
|
||||||
return fmt.Sprintf("U%d", e.Index)
|
return fmt.Sprintf("U%d", e.Index)
|
||||||
case shaderir.TextureVariable:
|
case shaderir.TextureVariable:
|
||||||
@ -456,14 +447,6 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
}
|
}
|
||||||
lines = append(lines, fmt.Sprintf("%s}", idt))
|
lines = append(lines, fmt.Sprintf("%s}", idt))
|
||||||
case shaderir.For:
|
case shaderir.For:
|
||||||
var ct shaderir.ConstType
|
|
||||||
switch s.ForVarType.Main {
|
|
||||||
case shaderir.Int:
|
|
||||||
ct = shaderir.ConstTypeInt
|
|
||||||
case shaderir.Float:
|
|
||||||
ct = shaderir.ConstTypeFloat
|
|
||||||
}
|
|
||||||
|
|
||||||
v := localVariableName(p, topBlock, s.ForVarIndex)
|
v := localVariableName(p, topBlock, s.ForVarIndex)
|
||||||
var delta string
|
var delta string
|
||||||
switch val, _ := constant.Float64Val(s.ForDelta); val {
|
switch val, _ := constant.Float64Val(s.ForDelta); val {
|
||||||
@ -476,10 +459,10 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
default:
|
default:
|
||||||
d := s.ForDelta
|
d := s.ForDelta
|
||||||
if val > 0 {
|
if val > 0 {
|
||||||
delta = fmt.Sprintf("%s += %s", v, constantToNumberLiteral(ct, d))
|
delta = fmt.Sprintf("%s += %s", v, constantToNumberLiteral(d))
|
||||||
} else {
|
} else {
|
||||||
d = constant.UnaryOp(token.SUB, d, 0)
|
d = constant.UnaryOp(token.SUB, d, 0)
|
||||||
delta = fmt.Sprintf("%s -= %s", v, constantToNumberLiteral(ct, d))
|
delta = fmt.Sprintf("%s -= %s", v, constantToNumberLiteral(d))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var op string
|
var op string
|
||||||
@ -491,8 +474,8 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := s.ForVarType
|
t := s.ForVarType
|
||||||
init := constantToNumberLiteral(ct, s.ForInit)
|
init := constantToNumberLiteral(s.ForInit)
|
||||||
end := constantToNumberLiteral(ct, s.ForEnd)
|
end := constantToNumberLiteral(s.ForEnd)
|
||||||
ts := typeString(&t, false)
|
ts := typeString(&t, false)
|
||||||
lines = append(lines, fmt.Sprintf("%sfor (%s %s = %s; %s %s %s; %s) {", idt, ts, v, init, v, op, end, delta))
|
lines = append(lines, fmt.Sprintf("%sfor (%s %s = %s; %s %s %s; %s) {", idt, ts, v, init, v, op, end, delta))
|
||||||
lines = append(lines, c.block(p, topBlock, s.Blocks[0], level+1)...)
|
lines = append(lines, c.block(p, topBlock, s.Blocks[0], level+1)...)
|
||||||
|
@ -101,16 +101,6 @@ const (
|
|||||||
Discard
|
Discard
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Remove ConstType (#2550)
|
|
||||||
type ConstType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
ConstTypeNone ConstType = iota
|
|
||||||
ConstTypeBool
|
|
||||||
ConstTypeInt
|
|
||||||
ConstTypeFloat
|
|
||||||
)
|
|
||||||
|
|
||||||
type Expr struct {
|
type Expr struct {
|
||||||
Type ExprType
|
Type ExprType
|
||||||
Exprs []Expr
|
Exprs []Expr
|
||||||
@ -119,9 +109,6 @@ type Expr struct {
|
|||||||
Swizzling string
|
Swizzling string
|
||||||
Index int
|
Index int
|
||||||
Op Op
|
Op Op
|
||||||
|
|
||||||
// TODO: Remove ConstType (#2550)
|
|
||||||
ConstType ConstType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExprType int
|
type ExprType int
|
||||||
|
Loading…
Reference in New Issue
Block a user