@@ -2,8 +2,11 @@ package scalacl
22
33import org .scalamock .scalatest .MockFactory
44import org .scalatest .{ FlatSpecLike , Matchers }
5- import scalacl .impl .{ OpenCLCodeFlattening , CodeConversion }
6- import scalaxy .components .{ FlatCode , WithRuntimeUniverse }
5+
6+ import scala .reflect .runtime .{ currentMirror => cm , universe => ru }
7+ import scala .tools .reflect .ToolBox
8+ import scalacl .impl .{ Vectorization , CodeConversion , OpenCLCodeFlattening }
9+ import scalaxy .components .FlatCode
710
811trait BaseTest extends FlatSpecLike with Matchers with MockFactory {
912 def context [T ](f : Context => T ): T = {
@@ -14,30 +17,77 @@ trait BaseTest extends FlatSpecLike with Matchers with MockFactory {
1417 }
1518}
1619
17- trait RuntimeUniverseTest extends WithRuntimeUniverse {
20+ trait RuntimeUniverseTest {
21+ lazy val global = ru
22+ import global ._
23+
24+ def verbose = false
25+
1826 private var nextId = 0L
1927
2028 def fresh (s : String ) = synchronized {
2129 val v = nextId
2230 nextId += 1
2331 s + v
2432 }
33+
34+ def warning (pos : Position , msg : String ) =
35+ println(msg + " (" + pos + " )" )
36+
37+ def withSymbol [T <: Tree ](sym : Symbol , tpe : Type = NoType )(tree : T ): T = tree
38+
39+ def typed [T <: Tree ](tree : T ): T = {
40+ // if (tree.tpe == null && tree.tpe == NoType)
41+ // toolbox.typeCheck(tree.asInstanceOf[toolbox.u.Tree]).asInstanceOf[T]
42+ // else
43+ tree
44+ }
45+
46+ def inferImplicitValue (pt : Type ): Tree =
47+ toolbox.inferImplicitValue(pt.asInstanceOf [toolbox.u.Type ]).asInstanceOf [global.Tree ]
48+
49+ lazy val toolbox = cm.mkToolBox()
50+
51+ def typeCheck (x : Expr [_]): Tree =
52+ typeCheck(x.tree)
53+
54+ def typeCheck (tree : Tree , pt : Type = WildcardType ): Tree = {
55+ val ttree = tree.asInstanceOf [toolbox.u.Tree ]
56+ if (ttree.tpe != null && ttree.tpe != NoType )
57+ tree
58+ else {
59+ try {
60+ toolbox.typecheck(
61+ ttree,
62+ pt = pt.asInstanceOf [toolbox.u.Type ])
63+ } catch {
64+ case ex : Throwable =>
65+ throw new RuntimeException (s " Failed to typeCheck( $tree, $pt): $ex" , ex)
66+ }
67+ }.asInstanceOf [Tree ]
68+ }
69+
70+ def resetLocalAttrs (tree : Tree ): Tree = {
71+ toolbox.untypecheck(tree.asInstanceOf [toolbox.u.Tree ]).asInstanceOf [Tree ]
72+ }
73+
2574}
2675
2776trait CodeConversionTest extends CodeConversion with RuntimeUniverseTest {
2877 val global : reflect.api.Universe
78+
2979 import global ._
3080
3181 def convertExpression (block : Expr [Unit ], explicitParamDescs : Seq [ParamDesc ] = Seq ()) = {
3282 convertCode(typeCheck(block.tree, WildcardType ), explicitParamDescs)
3383 }
3484
85+ def flatStatement (statements : Seq [String ], values : Seq [String ]): FlatCode [String ] =
86+ FlatCode [String ](statements = statements, values = values)
87+
3588 def flatAndConvertExpression (x : Expr [_]): FlatCode [String ] = {
3689 flattenAndConvert(typeCheck(x))
3790 }
38-
39- def flatCode (statements : Seq [String ], values : Seq [String ]): FlatCode [String ] =
40- FlatCode [String ](statements = statements, values = values)
4191}
4292
4393trait CodeFlatteningTest extends OpenCLCodeFlattening with RuntimeUniverseTest {
@@ -67,3 +117,5 @@ trait CodeFlatteningTest extends OpenCLCodeFlattening with RuntimeUniverseTest {
67117 flatten(typeCheck(x.tree, WildcardType ), inputSymbols, owner)
68118 }
69119}
120+
121+ trait CodeVectorizationTest extends Vectorization with RuntimeUniverseTest
0 commit comments