From 931fec91006b3bc1a72bce716ea8a109b2d6dedd Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 15 May 2020 03:33:07 +0900 Subject: [PATCH] shaderir: Refactoring --- internal/shaderir/ir_test.go | 119 ++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index dc6f0634b..b69bb10c6 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -20,6 +20,20 @@ import ( . "github.com/hajimehoshi/ebiten/internal/shaderir" ) +func block(localVars []Type, stmts ...Stmt) Block { + return Block{ + LocalVars: localVars, + Stmts: stmts, + } +} + +func blockStmt(block Block) Stmt { + return Stmt{ + Type: BlockStmt, + Blocks: []Block{block}, + } +} + func assignStmt(lhs Expr, rhs Expr) Stmt { return Stmt{ Type: Assign, @@ -164,12 +178,10 @@ varying vec3 V0;`, OutParams: []Type{ {Main: Float}, }, - Block: Block{ - LocalVars: []Type{ - {Main: Mat4}, - {Main: Mat4}, - }, - }, + Block: block([]Type{ + {Main: Mat4}, + {Main: Mat4}, + }), }, }, }, @@ -193,25 +205,20 @@ varying vec3 V0;`, OutParams: []Type{ {Main: Float}, }, - Block: Block{ - LocalVars: []Type{ + Block: block( + []Type{ {Main: Mat4}, {Main: Mat4}, }, - Stmts: []Stmt{ - { - Type: BlockStmt, - Blocks: []Block{ - { - LocalVars: []Type{ - {Main: Mat4}, - {Main: Mat4}, - }, - }, + blockStmt( + block( + []Type{ + {Main: Mat4}, + {Main: Mat4}, }, - }, - }, - }, + ), + ), + ), }, }, }, @@ -237,18 +244,17 @@ varying vec3 V0;`, OutParams: []Type{ {Main: Float}, }, - Block: Block{ - Stmts: []Stmt{ - assignStmt( - varNameExpr(Local, 2), - binaryExpr( - Add, - varNameExpr(Local, 0), - varNameExpr(Local, 1), - ), + Block: block( + nil, + assignStmt( + varNameExpr(Local, 2), + binaryExpr( + Add, + varNameExpr(Local, 0), + varNameExpr(Local, 1), ), - }, - }, + ), + ), }, }, }, @@ -269,33 +275,30 @@ varying vec3 V0;`, OutParams: []Type{ {Main: Float}, }, - Block: Block{ - Stmts: []Stmt{ - ifStmt( - binaryExpr( - Eq, - varNameExpr(Local, 0), - numericExpr(0), - ), - Block{ - Stmts: []Stmt{ - assignStmt( - varNameExpr(Local, 2), - varNameExpr(Local, 0), - ), - }, - }, - Block{ - Stmts: []Stmt{ - assignStmt( - varNameExpr(Local, 2), - varNameExpr(Local, 1), - ), - }, - }, + Block: block( + nil, + ifStmt( + binaryExpr( + Eq, + varNameExpr(Local, 0), + numericExpr(0), ), - }, - }, + block( + nil, + assignStmt( + varNameExpr(Local, 2), + varNameExpr(Local, 0), + ), + ), + block( + nil, + assignStmt( + varNameExpr(Local, 2), + varNameExpr(Local, 1), + ), + ), + ), + ), }, }, },