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
glslExpr = func(e *Expr) string {
switch e.Type {
case Numeric:
return fmt.Sprintf("%.9e", e.Num)
case IntExpr:
return fmt.Sprintf("%d", e.Int)
case FloatExpr:
return fmt.Sprintf("%.9e", e.Float)
case VarName:
switch e.Variable.Type {
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{
Type: Numeric,
Num: value,
Type: FloatExpr,
Float: value,
}
}
@ -291,7 +291,7 @@ varying vec3 V0;`,
binaryExpr(
Eq,
varNameExpr(Local, 0),
numericExpr(0),
floatExpr(0),
),
block(
nil,

View File

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