shaderir: Allow integer literals

This commit is contained in:
Hajime Hoshi 2020-05-16 03:40:33 +09:00
parent 3cffe88334
commit 9f4985943c
3 changed files with 12 additions and 8 deletions

View File

@ -119,8 +119,10 @@ func (p *Program) glslBlock(b *Block, f *Func, level int, localVarIndex int) []s
var glslExpr func(e *Expr) string var glslExpr func(e *Expr) string
glslExpr = func(e *Expr) string { glslExpr = func(e *Expr) string {
switch e.Type { switch e.Type {
case Numeric: case IntExpr:
return fmt.Sprintf("%.9e", e.Num) return fmt.Sprintf("%d", e.Int)
case FloatExpr:
return fmt.Sprintf("%.9e", e.Float)
case VarName: case VarName:
switch e.Variable.Type { switch e.Variable.Type {
case Uniform: case Uniform:

View File

@ -59,10 +59,10 @@ func forStmt(init, end, delta int, block Block) Stmt {
} }
} }
func numericExpr(value float64) Expr { func floatExpr(value float32) Expr {
return Expr{ return Expr{
Type: Numeric, Type: FloatExpr,
Num: value, Float: value,
} }
} }
@ -291,7 +291,7 @@ varying vec3 V0;`,
binaryExpr( binaryExpr(
Eq, Eq,
varNameExpr(Local, 0), varNameExpr(Local, 0),
numericExpr(0), floatExpr(0),
), ),
block( block(
nil, nil,

View File

@ -66,7 +66,8 @@ type Expr struct {
Type ExprType Type ExprType
Exprs []Expr Exprs []Expr
Variable Variable Variable Variable
Num float64 Int int32
Float float32
Ident string Ident string
Op Op Op Op
} }
@ -74,7 +75,8 @@ type Expr struct {
type ExprType int type ExprType int
const ( const (
Numeric ExprType = iota IntExpr ExprType = iota
FloatExpr
VarName VarName
Ident Ident
Unary Unary