From 7aba0a3e8c8223756da44911b3478f3dc3352603 Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Sun, 18 Dec 2016 15:26:17 -0500 Subject: [PATCH 01/10] flare lms-mod --- src/common/ArrayBufferOps.scala | 253 +++- src/common/ArrayOps.scala | 459 +++++-- src/common/Base.scala | 32 +- src/common/BooleanOps.scala | 182 ++- src/common/CastingOps.scala | 17 +- src/common/Compile.scala | 11 +- src/common/DSLBase.scala | 129 ++ src/common/DSLOps.scala | 17 +- src/common/DateOps.scala | 89 ++ src/common/DynamicRecord.scala | 397 +++++++ src/common/Equal.scala | 56 +- src/common/ExceptionOps.scala | 30 +- src/common/ExportGraph.scala | 2 +- src/common/ForwardTransformer.scala | 10 +- src/common/FractionalOps.scala | 30 +- src/common/FunctionBlocks.scala | 6 +- src/common/Functions.scala | 346 ++++-- src/common/GeneratorOps.scala | 297 +++++ src/common/GregorianCalendarOps.scala | 56 + src/common/HashCodeOps.scala | 38 + src/common/HashMapOps.scala | 270 ++++- src/common/IOOps.scala | 146 ++- src/common/IfThenElse.scala | 101 +- src/common/ImplicitOps.scala | 2 +- src/common/IterableOps.scala | 16 +- src/common/Iterator.scala | 58 + src/common/ListBuffer.scala | 96 ++ src/common/ListOps.scala | 97 +- src/common/LivenessOpt.scala | 15 +- src/common/LoopFusionOpt.scala | 4 +- src/common/Loops.scala | 15 +- src/common/MathOps.scala | 108 +- src/common/MiscOps.scala | 66 +- src/common/MultiMap.scala | 158 +++ src/common/NumericOps.scala | 9 +- src/common/ObjectOps.scala | 42 +- src/common/OrderingOps.scala | 205 ++-- src/common/Packages.scala | 85 +- src/common/PrimitiveOps.scala | 602 ++-------- src/common/RangeOps.scala | 90 +- src/common/SeqOps.scala | 2 +- src/common/SetOps.scala | 154 ++- src/common/SimpleDateFormatOps.scala | 58 + src/common/SimplifyTransform.scala | 153 ++- src/common/SplitEffects.scala | 7 +- src/common/StaticData.scala | 32 +- src/common/StringOps.scala | 212 ++-- src/common/Structs.scala | 447 +++++-- src/common/SynchronizedArrayBufferOps.scala | 4 +- src/common/TreeSet.scala | 126 ++ src/common/TupleOps.scala | 304 ++++- src/common/Unchecked.scala | 2 +- src/common/UninlinedFunctions.scala | 299 +++++ src/common/Variables.scala | 173 ++- src/common/While.scala | 100 +- src/internal/AccModel.scala | 62 - src/internal/BlockTraversal.scala | 3 +- src/internal/CCodegen.scala | 542 ++++++--- src/internal/CLikeCodegen.scala | 202 +--- src/internal/CodeMotion.scala | 13 +- src/internal/Config.scala | 18 +- src/internal/CppHostTransfer.scala | 301 ----- src/internal/CudaCodegen.scala | 212 +++- src/internal/CudaDeviceTransfer.scala | 134 --- src/internal/Effects.scala | 127 +- src/internal/Exceptions.scala | 2 +- src/internal/Expressions.scala | 191 ++- src/internal/ExtendedExpressions.scala | 53 + src/internal/FatCodegen.scala | 6 +- src/internal/FatExpressions.scala | 2 +- src/internal/FatScheduling.scala | 2 +- src/internal/FatTraversal.scala | 2 +- src/internal/GPUCodegen.scala | 605 +++++++--- src/internal/GenericCodegen.scala | 392 +++++- .../GraphVizDependencyGraphExport.scala | 214 ++++ src/internal/GraphVizExport.scala | 2 +- src/internal/OpenCLCodegen.scala | 235 +++- src/internal/OpenCLDeviceTransfer.scala | 95 -- src/internal/ScalaCodegen.scala | 57 +- src/internal/ScalaCompile.scala | 214 +++- src/internal/ScalaConciseCodegen.scala | 100 ++ src/internal/Scheduling.scala | 81 +- src/internal/SymMetaDataFixerTransform.scala | 88 ++ src/internal/Transforming.scala | 30 +- src/internal/Traversal.scala | 30 +- src/internal/Utils.scala | 17 +- src/util/ClosureCompare.scala | 2 +- src/util/GencodeCleaner.scala | 117 ++ src/util/GraphUtil.scala | 45 +- src/util/OverloadHack.scala | 207 +--- src/util/ReflectionUtil.scala | 30 + src/util/Timing.scala | 100 ++ ...t9-struct6.check => test1-constcse1.check} | 27 +- test-out/epfl/test10-effects1.check | 7 +- test-out/epfl/test10-effects2.check | 11 +- test-out/epfl/test10-effects3.check | 11 +- test-out/epfl/test10-effects4.check | 7 +- test-out/epfl/test10-misc1.check | 8 +- test-out/epfl/test10-misc2.check | 24 +- test-out/epfl/test10-misc3.check | 66 +- test-out/epfl/test10-misc4.check | 66 +- test-out/epfl/test10-misc5.check | 66 +- test-out/epfl/test10-transform1.check | 8 +- test-out/epfl/test10-transform2.check | 34 +- test-out/epfl/test10-transform3.check | 66 +- test-out/epfl/test10-transformrec3.check | 46 +- test-out/epfl/test10-worklist1.check | 18 +- test-out/epfl/test10-worklist2.check | 6 +- test-out/epfl/test10-worklist21.check | 14 +- test-out/epfl/test10-worklist22.check | 6 +- test-out/epfl/test10-worklist23.check | 14 +- test-out/epfl/test10-worklist3.check | 16 +- test-out/epfl/test11-hmm1.check | 17 +- test-out/epfl/test11-hmm2.check | 23 +- test-out/epfl/test11-stencil0.check | 7 +- test-out/epfl/test11-stencil1.check | 47 +- test-out/epfl/test11-stencil2a.check | 7 +- test-out/epfl/test11-stencil2b.check | 53 +- test-out/epfl/test11-stencil3a.check | 7 +- test-out/epfl/test11-stencil3b.check | 95 +- test-out/epfl/test12-array-seq-creation.check | 6 +- test-out/epfl/test12-map-flatmap-filter.check | 3 + test-out/epfl/test13-interpret2.check | 397 +++---- test-out/epfl/test13-interpret3.check | 104 +- test-out/epfl/test13-stable1.check | 12 +- test-out/epfl/test13-stable2.check | 30 +- test-out/epfl/test13-unstage1.check | 12 +- test-out/epfl/test14-cgen1.check | 15 +- test-out/epfl/test14-cgen2.check | 25 +- test-out/epfl/test14-cgen3.check | 37 +- test-out/epfl/test14-dataop1.check | 27 +- test-out/epfl/test14-dataop2.check | 70 +- test-out/epfl/test14-dataop3.check | 220 ---- test-out/epfl/test14-queries2.check | 36 +- test-out/epfl/test14-queries3.check | 26 +- test-out/epfl/test14-queries4.check | 30 +- test-out/epfl/test15-generator-array.check | 103 ++ test-out/epfl/test15-generator-simple.check | 374 ++++++ .../test15-tupled-generator-flatten.check | 27 + .../epfl/test15-tupled-generator-huge.check | 93 ++ .../epfl/test15-tupled-generator-simple.check | 36 + test-out/epfl/test16-DBMSOpt1.check | 2 + test-out/epfl/test16-DBMSOpt2.check | 69 ++ test-out/epfl/test2-fft3.check | 1 - test-out/epfl/test2-power.check | 1 - test-out/epfl/test2-sort1-dot.check | 303 ----- test-out/epfl/test2-sort1.check | 49 - test-out/epfl/test3-match1-dot.check | 4 +- test-out/epfl/test3-match1.check | 4 +- test-out/epfl/test3-match2-dot.check | 2 +- test-out/epfl/test3-match2.check | 2 +- test-out/epfl/test3-parse1-dot.check | 86 +- test-out/epfl/test3-parse1.check | 86 +- test-out/epfl/test3-parse2-dot.check | 56 +- test-out/epfl/test3-parse2.check | 56 +- test-out/epfl/test4-counter1.check | 9 +- test-out/epfl/test4-counter2.check | 97 +- test-out/epfl/test4-fac3.check | 2 +- test-out/epfl/test4-matchernew1.check | 45 +- test-out/epfl/test4-matchernew1b.check | 45 +- test-out/epfl/test4-matchernew2.check | 27 +- test-out/epfl/test4-matchernew2b.check | 27 +- test-out/epfl/test4-stream1.check | 59 +- test-out/epfl/test5-conditional.check | 25 +- test-out/epfl/test5-conditional.html.check | 12 +- test-out/epfl/test5-functions.check | 37 +- test-out/epfl/test5-functionsrecursive.check | 12 +- test-out/epfl/test5-funretfun.check | 4 +- test-out/epfl/test5-twoargsfun.check | 2 +- test-out/epfl/test6-vectors.check | 8 +- test-out/epfl/test7-codemotion1.check | 2 +- test-out/epfl/test7-codemotion2.check | 2 +- test-out/epfl/test7-codemotion3.check | 6 +- test-out/epfl/test7-codemotion4.check | 5 +- test-out/epfl/test7-codemotion5.check | 3 +- test-out/epfl/test7-codemotion6.check | 8 +- test-out/epfl/test7-fusion1.check | 5 +- test-out/epfl/test7-fusion2.check | 21 +- test-out/epfl/test7-fusion21.check | 9 +- test-out/epfl/test7-fusion22.check | 15 +- test-out/epfl/test7-fusion23.check | 45 +- test-out/epfl/test7-fusion24.check | 7 +- test-out/epfl/test7-fusion3.check | 5 +- test-out/epfl/test7-fusion4.check | 7 +- test-out/epfl/test7-lambdalift1.check | 2 +- test-out/epfl/test7-liveness1.check | 3 +- test-out/epfl/test7-liveness2.check | 3 +- test-out/epfl/test8-mutation1.check | 9 +- test-out/epfl/test8-mutation1b.check | 7 +- test-out/epfl/test8-mutation2.check | 11 +- test-out/epfl/test8-mutation3.check | 11 +- test-out/epfl/test8-mutation3b.check | 11 +- test-out/epfl/test8-mutation4.check | 11 +- test-out/epfl/test8-mutation4b.check | 13 +- test-out/epfl/test8-mutation4c.check | 7 +- test-out/epfl/test8-mutation5.check | 13 +- test-out/epfl/test8-mutation6.check | 15 +- test-out/epfl/test8-mutation7.check | 13 +- test-out/epfl/test8-speculative1.check | 6 +- test-out/epfl/test8-speculative1b.check | 4 +- test-out/epfl/test8-speculative1c.check | 8 +- test-out/epfl/test8-speculative1d.check | 8 +- test-out/epfl/test8-speculative3.check | 14 +- test-out/epfl/test8-speculative3b.check | 14 +- test-out/epfl/test8-speculative4.check | 6 +- test-out/epfl/test8-speculative5.check | 12 +- test-out/epfl/test8-speculative6.check | 114 -- test-out/epfl/test9-amb1a.check | 91 +- test-out/epfl/test9-amb1b.check | 43 +- test-out/epfl/test9-amb2a.check | 1025 ++++++++-------- test-out/epfl/test9-amb2b.check | 289 +++-- test-out/epfl/test9-cps1.check | 11 +- test-out/epfl/test9-cps2.check | 11 +- test-out/epfl/test9-csp1.check | 4 +- test-out/epfl/test9-csp2.check | 8 +- test-out/epfl/test9-struct1.check | 12 +- test-out/epfl/test9-struct2.check | 19 +- test-out/epfl/test9-struct2b.check | 25 +- test-out/epfl/test9-struct3.check | 9 +- test-out/epfl/test9-struct4.check | 11 +- test-out/epfl/test9-struct5.check | 19 - test-src/epfl/FileDiffSuite.scala | 5 +- test-src/epfl/test1-arith/Arith.scala | 2 +- test-src/epfl/test1-arith/Arrays.scala | 2 +- test-src/epfl/test1-arith/Relat.scala | 5 +- test-src/epfl/test1-arith/TestConstCSE.scala | 54 + test-src/epfl/test1-arith/TestNumeric.scala | 8 +- test-src/epfl/test1-arith/Trig.scala | 2 +- .../epfl/test10-transform/TestBackward.scala | 208 ---- .../epfl/test10-transform/TestEffect.scala | 290 ----- .../test10-transform/TestMiscTransform.scala | 618 ---------- .../epfl/test10-transform/TestTransform.scala | 160 --- .../test10-transform/TestTransformRec.scala | 142 --- test-src/epfl/test10-transform/TestWIP.scalax | 35 - .../TestWorklistTransform.scala | 216 ---- .../TestWorklistTransform2.scala | 173 --- test-src/epfl/test10-transform/Vectors.scala | 114 -- test-src/epfl/test11-shonan/TestHMM.scala | 149 --- test-src/epfl/test11-shonan/TestStencil.scala | 425 ------- .../test12-collections/TestArrayOps.scala | 33 - .../epfl/test12-collections/TestList.scala | 67 -- .../test13-dynamic-jit/TestInterpret.scala | 672 ----------- .../epfl/test13-dynamic-jit/TestStable.scala | 364 ------ test-src/epfl/test14-scratch/TestCGen.scala | 53 +- test-src/epfl/test14-scratch/TestDataOp.scala | 262 ---- .../epfl/test14-scratch/TestQueries.scala | 1056 ----------------- test-src/epfl/test2-fft/DisableOpts.scala | 2 +- test-src/epfl/test2-fft/TestFFT.scala | 11 +- test-src/epfl/test2-fft/TestPower.scala | 14 +- test-src/epfl/test2-fft/TestSort.scala | 35 +- test-src/epfl/test3-parsers/Effects.scala | 130 -- .../test3-parsers/ExtractorsGraphViz.scala | 71 -- test-src/epfl/test3-parsers/Functions.scala | 40 - test-src/epfl/test3-parsers/Matching.scala | 197 --- test-src/epfl/test3-parsers/Parsers.scala | 75 -- test-src/epfl/test3-parsers/TestMatch.scala | 92 -- test-src/epfl/test3-parsers/TestParsers.scala | 76 -- test-src/epfl/test4-functions/Automata.scala | 463 -------- test-src/epfl/test4-functions/FooBar.scala | 51 - test-src/epfl/test4-functions/Functions.scala | 210 ---- .../test4-functions/FunctionsGraphViz.scala | 48 - .../epfl/test4-functions/TestAckermann.scala | 71 -- test-src/epfl/test4-functions/TestFac.scala | 150 --- .../epfl/test4-functions/TestMatcher.scala | 76 -- .../epfl/test4-functions/TestMatcherNew.scala | 1033 ---------------- .../epfl/test4-functions/TestPatMat.scala | 80 -- test-src/epfl/test5-js/JSCompile.scala | 83 -- test-src/epfl/test5-js/TestConditional.scala | 130 -- test-src/epfl/test5-js/TestFunctions.scala | 297 ----- test-src/epfl/test6-layered/Test.scala | 239 ---- test-src/epfl/test7-analysis/Arrays.scala | 232 ---- .../epfl/test7-analysis/TestAnalysis.scala | 228 ---- .../epfl/test7-analysis/TestCodeMotion.scala | 252 ---- test-src/epfl/test7-analysis/TestDB.scalax | 114 -- test-src/epfl/test7-analysis/TestFusion.scala | 191 --- .../epfl/test7-analysis/TestFusion2.scala | 228 ---- .../epfl/test7-analysis/TestLambalift.scala | 134 --- .../epfl/test7-analysis/TestLiveness.scala | 150 --- .../epfl/test8-effects/TestMutation.scala | 361 ------ .../epfl/test8-effects/TestSpeculative.scala | 238 ---- .../epfl/test9-experimental/TestCPS.scala | 228 ---- .../test9-experimental/TestCrossStage.scala | 84 -- .../epfl/test9-experimental/TestStruct.scala | 303 ----- 283 files changed, 10762 insertions(+), 17642 deletions(-) create mode 100644 src/common/DSLBase.scala create mode 100644 src/common/DateOps.scala create mode 100644 src/common/DynamicRecord.scala create mode 100644 src/common/GeneratorOps.scala create mode 100644 src/common/GregorianCalendarOps.scala create mode 100644 src/common/HashCodeOps.scala create mode 100644 src/common/Iterator.scala create mode 100644 src/common/ListBuffer.scala create mode 100644 src/common/MultiMap.scala create mode 100644 src/common/SimpleDateFormatOps.scala create mode 100644 src/common/TreeSet.scala create mode 100644 src/common/UninlinedFunctions.scala delete mode 100644 src/internal/AccModel.scala delete mode 100644 src/internal/CppHostTransfer.scala delete mode 100644 src/internal/CudaDeviceTransfer.scala create mode 100644 src/internal/ExtendedExpressions.scala create mode 100644 src/internal/GraphVizDependencyGraphExport.scala delete mode 100644 src/internal/OpenCLDeviceTransfer.scala create mode 100644 src/internal/ScalaConciseCodegen.scala create mode 100644 src/internal/SymMetaDataFixerTransform.scala create mode 100644 src/util/GencodeCleaner.scala create mode 100644 src/util/ReflectionUtil.scala create mode 100644 src/util/Timing.scala rename test-out/epfl/{test9-struct6.check => test1-constcse1.check} (51%) delete mode 100644 test-out/epfl/test14-dataop3.check create mode 100644 test-out/epfl/test15-generator-array.check create mode 100644 test-out/epfl/test15-generator-simple.check create mode 100644 test-out/epfl/test15-tupled-generator-flatten.check create mode 100644 test-out/epfl/test15-tupled-generator-huge.check create mode 100644 test-out/epfl/test15-tupled-generator-simple.check create mode 100644 test-out/epfl/test16-DBMSOpt1.check create mode 100644 test-out/epfl/test16-DBMSOpt2.check delete mode 100644 test-out/epfl/test2-sort1-dot.check delete mode 100644 test-out/epfl/test2-sort1.check delete mode 100644 test-out/epfl/test8-speculative6.check delete mode 100644 test-out/epfl/test9-struct5.check create mode 100644 test-src/epfl/test1-arith/TestConstCSE.scala delete mode 100644 test-src/epfl/test10-transform/TestBackward.scala delete mode 100644 test-src/epfl/test10-transform/TestEffect.scala delete mode 100644 test-src/epfl/test10-transform/TestMiscTransform.scala delete mode 100644 test-src/epfl/test10-transform/TestTransform.scala delete mode 100644 test-src/epfl/test10-transform/TestTransformRec.scala delete mode 100644 test-src/epfl/test10-transform/TestWIP.scalax delete mode 100644 test-src/epfl/test10-transform/TestWorklistTransform.scala delete mode 100644 test-src/epfl/test10-transform/TestWorklistTransform2.scala delete mode 100644 test-src/epfl/test10-transform/Vectors.scala delete mode 100644 test-src/epfl/test11-shonan/TestHMM.scala delete mode 100644 test-src/epfl/test11-shonan/TestStencil.scala delete mode 100644 test-src/epfl/test12-collections/TestArrayOps.scala delete mode 100644 test-src/epfl/test12-collections/TestList.scala delete mode 100644 test-src/epfl/test13-dynamic-jit/TestInterpret.scala delete mode 100644 test-src/epfl/test13-dynamic-jit/TestStable.scala delete mode 100644 test-src/epfl/test14-scratch/TestDataOp.scala delete mode 100644 test-src/epfl/test14-scratch/TestQueries.scala delete mode 100644 test-src/epfl/test3-parsers/Effects.scala delete mode 100644 test-src/epfl/test3-parsers/ExtractorsGraphViz.scala delete mode 100644 test-src/epfl/test3-parsers/Functions.scala delete mode 100644 test-src/epfl/test3-parsers/Matching.scala delete mode 100644 test-src/epfl/test3-parsers/Parsers.scala delete mode 100644 test-src/epfl/test3-parsers/TestMatch.scala delete mode 100644 test-src/epfl/test3-parsers/TestParsers.scala delete mode 100644 test-src/epfl/test4-functions/Automata.scala delete mode 100644 test-src/epfl/test4-functions/FooBar.scala delete mode 100644 test-src/epfl/test4-functions/Functions.scala delete mode 100644 test-src/epfl/test4-functions/FunctionsGraphViz.scala delete mode 100644 test-src/epfl/test4-functions/TestAckermann.scala delete mode 100644 test-src/epfl/test4-functions/TestFac.scala delete mode 100644 test-src/epfl/test4-functions/TestMatcher.scala delete mode 100644 test-src/epfl/test4-functions/TestMatcherNew.scala delete mode 100644 test-src/epfl/test4-functions/TestPatMat.scala delete mode 100644 test-src/epfl/test5-js/JSCompile.scala delete mode 100644 test-src/epfl/test5-js/TestConditional.scala delete mode 100644 test-src/epfl/test5-js/TestFunctions.scala delete mode 100644 test-src/epfl/test6-layered/Test.scala delete mode 100644 test-src/epfl/test7-analysis/Arrays.scala delete mode 100644 test-src/epfl/test7-analysis/TestAnalysis.scala delete mode 100644 test-src/epfl/test7-analysis/TestCodeMotion.scala delete mode 100644 test-src/epfl/test7-analysis/TestDB.scalax delete mode 100644 test-src/epfl/test7-analysis/TestFusion.scala delete mode 100644 test-src/epfl/test7-analysis/TestFusion2.scala delete mode 100644 test-src/epfl/test7-analysis/TestLambalift.scala delete mode 100644 test-src/epfl/test7-analysis/TestLiveness.scala delete mode 100644 test-src/epfl/test8-effects/TestMutation.scala delete mode 100644 test-src/epfl/test8-effects/TestSpeculative.scala delete mode 100644 test-src/epfl/test9-experimental/TestCPS.scala delete mode 100644 test-src/epfl/test9-experimental/TestCrossStage.scala delete mode 100644 test-src/epfl/test9-experimental/TestStruct.scala diff --git a/src/common/ArrayBufferOps.scala b/src/common/ArrayBufferOps.scala index 55be988a..876db24f 100644 --- a/src/common/ArrayBufferOps.scala +++ b/src/common/ArrayBufferOps.scala @@ -1,31 +1,38 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter import scala.reflect.SourceContext import scala.collection.mutable.ArrayBuffer -import scala.lms.internal.GenericNestedCodegen +import scala.virtualization.lms.internal.GenericNestedCodegen import collection.mutable.ArrayBuffer import scala.reflect.SourceContext -trait ArrayBufferOps extends Base { +trait ArrayBufferOps extends Base with Variables { object ArrayBuffer { def apply[A:Manifest](xs: Rep[A]*) = arraybuffer_new(xs) } implicit def repToArrayBufferOps[A:Manifest](l: Rep[ArrayBuffer[A]]) = new ArrayBufferOpsCls(l) + implicit def varToArrayBufferOps[A:Manifest](l: Var[ArrayBuffer[A]]) = new ArrayBufferOpsCls(readVar(l)) class ArrayBufferOpsCls[A:Manifest](l: Rep[ArrayBuffer[A]]) { - def +=(e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l,e) + def apply(e: Rep[Int])(implicit pos: SourceContext) = arraybuffer_apply(l,e) + def append(e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l,e) + def -=(e: Rep[Int])(implicit pos: SourceContext) = arraybuffer_remove(l,e) def mkString(sep: Rep[String] = unit(""))(implicit pos: SourceContext) = arraybuffer_mkstring(l,sep) - def append(l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l,e) - def clear() = arraybuffer_clear(l) + def foreach(block: Rep[A] => Rep[Unit])(implicit pos: SourceContext) = arraybuffer_foreach(l, block) def toArray(implicit pos: SourceContext) = arraybuffer_toarray(l) def toSeq(implicit pos: SourceContext) = arraybuffer_toseq(l) + def size(implicit pos: SourceContext) = arraybuffer_size(l) + def clear(implicit pos: SourceContext) = arraybuffer_clear(l) + def indexWhere(f: Rep[A] => Rep[Boolean])(implicit pos: SourceContext) = arraybuffer_indexwhere(l,f) + def minBy[B:Manifest](f: Rep[A] => Rep[B])(implicit pos: SourceContext) = arraybuffer_minBy(l,f) + def foldLeft[B:Manifest](z: Rep[B])(f: (Rep[B], Rep[A]) => Rep[B]) = arraybuffer_foldLeft(l, z)(f) } - def infix_+=[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l, e) +// def infix_+=[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l, e) /* when mixed in with OptiML, one of these infix operations causes an NPE in the scala-virtualized compiler */ //TR: still the case? /* @@ -35,48 +42,134 @@ trait ArrayBufferOps extends Base { def infix_toArray[A:Manifest](l: Rep[ArrayBuffer[A]])(implicit pos: SourceContext) = arraybuffer_toarray(l) def infix_toSeq[A:Manifest](l: Rep[ArrayBuffer[A]])(implicit pos: SourceContext) = arraybuffer_toseq(l) */ - - def arraybuffer_mkstring[A:Manifest](l: Rep[ArrayBuffer[A]], sep: Rep[String])(implicit pos: SourceContext): Rep[String] - def arraybuffer_append[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext): Rep[Unit] def arraybuffer_new[A:Manifest](xs: Seq[Rep[A]])(implicit pos: SourceContext): Rep[ArrayBuffer[A]] - def arraybuffer_clear[A:Manifest](l: Rep[ArrayBuffer[A]]): Rep[Unit] + def arraybuffer_apply[A:Manifest](l: Rep[ArrayBuffer[A]], i: Rep[Int])(implicit pos: SourceContext): Rep[A] + def arraybuffer_append[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext): Rep[Unit] + def arraybuffer_remove[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[Int])(implicit pos: SourceContext): Rep[Unit] + def arraybuffer_mkstring[A:Manifest](l: Rep[ArrayBuffer[A]], sep: Rep[String])(implicit pos: SourceContext): Rep[String] + def arraybuffer_foreach[A:Manifest](x: Rep[ArrayBuffer[A]], block: Rep[A] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] def arraybuffer_toarray[A:Manifest](x: Rep[ArrayBuffer[A]])(implicit pos: SourceContext): Rep[Array[A]] def arraybuffer_toseq[A:Manifest](x: Rep[ArrayBuffer[A]])(implicit pos: SourceContext): Rep[Seq[A]] + def arraybuffer_size[A:Manifest](x: Rep[ArrayBuffer[A]])(implicit pos: SourceContext): Rep[Int] + def arraybuffer_clear[A:Manifest](x: Rep[ArrayBuffer[A]])(implicit pos: SourceContext): Rep[Unit] + def arraybuffer_indexwhere[A:Manifest](x: Rep[ArrayBuffer[A]], block: Rep[A] => Rep[Boolean])(implicit pos: SourceContext): Rep[Int] + def arraybuffer_minBy[A:Manifest,B:Manifest](x: Rep[ArrayBuffer[A]], f: Rep[A] => Rep[B])(implicit pos: SourceContext): Rep[A] + def arraybuffer_foldLeft[A:Manifest,B:Manifest](x: Rep[ArrayBuffer[A]], z: Rep[B])(f: (Rep[B], Rep[A]) => Rep[B]): Rep[B] } -trait ArrayBufferOpsExp extends ArrayBufferOps with EffectExp { +trait ArrayBufferOpsExp extends ArrayBufferOps with EffectExp with VariablesExp with FunctionsExp { case class ArrayBufferNew[A:Manifest](xs: Seq[Exp[A]]) extends Def[ArrayBuffer[A]] { val mA = manifest[A] } + case class ArrayBufferApply[A:Manifest](x: Exp[ArrayBuffer[A]], e: Exp[Int]) extends Def[A] { + val mA = manifest[A] + } + case class ArrayBufferAppend[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[A]) extends Def[Unit] { + val mA = manifest[A] + } + case class ArrayBufferRemove[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[Int]) extends Def[Unit] { + val mA = manifest[A] + } case class ArrayBufferMkString[A:Manifest](l: Exp[ArrayBuffer[A]], sep: Exp[String]) extends Def[String] - case class ArrayBufferAppend[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[A]) extends Def[Unit] - case class ArrayBufferClear[A:Manifest](l: Exp[ArrayBuffer[A]]) extends Def[Unit] + case class ArrayBufferForeach[A:Manifest](a: Exp[ArrayBuffer[A]], x: Sym[A], block: Block[Unit]) extends Def[Unit] case class ArrayBufferToArray[A:Manifest](x: Exp[ArrayBuffer[A]]) extends Def[Array[A]] case class ArrayBufferToSeq[A:Manifest](x: Exp[ArrayBuffer[A]]) extends Def[Seq[A]] + case class ArrayBufferSize[A:Manifest](x: Exp[ArrayBuffer[A]]) extends Def[Int] { + val mA = manifest[A] + } + case class ArrayBufferClear[A:Manifest](x: Exp[ArrayBuffer[A]]) extends Def[Unit] + case class ArrayBufferIndexWhere[A:Manifest](a: Exp[ArrayBuffer[A]], k: Sym[A], block: Block[Boolean]) extends Def[Int] { + val mA = manifest[A] + val idx = fresh[Int]; val elem = fresh[A] // Used in the c code generation + } + case class ArrayBufferMinBy[A:Manifest,B:Manifest](a: Exp[ArrayBuffer[A]], x: Sym[A], block: Block[B]) extends Def[A] { + val mA = manifest[A] + val mB = manifest[B] + val idx = fresh[Int]; val min = fresh[B] // Used in the c code generation + } + case class ArrayBufferFoldLeft[A:Manifest,B:Manifest](a: Exp[ArrayBuffer[A]], z: Exp[B], i: Sym[B], e: Sym[A], block: Block[B]) extends Def[B] { + val mA = manifest[A] + val mB = manifest[B] + val idx = fresh[Int] // Used in the c code generation + } def arraybuffer_new[A:Manifest](xs: Seq[Exp[A]])(implicit pos: SourceContext) = reflectMutable(ArrayBufferNew(xs)) - def arraybuffer_mkstring[A:Manifest](l: Exp[ArrayBuffer[A]], sep: Exp[String])(implicit pos: SourceContext) = ArrayBufferMkString(l, sep) + def arraybuffer_apply[A:Manifest](l: Rep[ArrayBuffer[A]], i: Rep[Int])(implicit pos: SourceContext) = ArrayBufferApply(l,i) def arraybuffer_append[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[A])(implicit pos: SourceContext) = reflectWrite(l)(ArrayBufferAppend(l, e)) - def arraybuffer_clear[A:Manifest](l: Exp[ArrayBuffer[A]]) = reflectWrite(l)(ArrayBufferClear(l)) + def arraybuffer_remove[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[Int])(implicit pos: SourceContext) = reflectWrite(l)(ArrayBufferRemove(l, e)) + def arraybuffer_mkstring[A:Manifest](l: Exp[ArrayBuffer[A]], sep: Exp[String])(implicit pos: SourceContext) = ArrayBufferMkString(l, sep) + def arraybuffer_foreach[A:Manifest](x: Exp[ArrayBuffer[A]], block: Rep[A] => Rep[Unit])(implicit pos: SourceContext) = { + val k = fresh[A] + val b = reifyEffects(block(k)) + reflectEffect(ArrayBufferForeach(x, k, b), summarizeEffects(b).star) + } def arraybuffer_toarray[A:Manifest](x: Exp[ArrayBuffer[A]])(implicit pos: SourceContext) = ArrayBufferToArray(x) def arraybuffer_toseq[A:Manifest](x: Exp[ArrayBuffer[A]])(implicit pos: SourceContext) = ArrayBufferToSeq(x) + def arraybuffer_size[A:Manifest](x: Exp[ArrayBuffer[A]])(implicit pos: SourceContext) = ArrayBufferSize(x) + def arraybuffer_clear[A:Manifest](x: Exp[ArrayBuffer[A]])(implicit pos: SourceContext) = ArrayBufferClear(x) + def arraybuffer_indexwhere[A:Manifest](x: Exp[ArrayBuffer[A]], block: Rep[A] => Rep[Boolean])(implicit pos: SourceContext) = { + val k = fresh[A] + val b = reifyEffects(block(k)) + reflectEffect(ArrayBufferIndexWhere(x, k, b), summarizeEffects(b).star) + } + def arraybuffer_minBy[A:Manifest,B:Manifest](x: Exp[ArrayBuffer[A]], f: Rep[A] => Rep[B])(implicit pos: SourceContext) = { + val k = fresh[A] + val b = reifyEffects(f(k)) + reflectEffect(ArrayBufferMinBy(x, k, b)(manifest[A],manifest[B]), summarizeEffects(b).star) + } + def arraybuffer_foldLeft[A:Manifest,B:Manifest](x: Exp[ArrayBuffer[A]], z: Exp[B])(f: (Exp[B], Exp[A]) => Exp[B]) = { + val e = fresh[A] + val i = fresh[B] + val b = reifyEffects(f(i,e)) + reflectEffect(ArrayBufferFoldLeft(x,z,i,e,b), summarizeEffects(b).star) + } ////////////// // mirroring - override def mirrorDef[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Def[A] = (e match { + /*override def mirrorDef[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Def[A] = (e match { case ArrayBufferMkString(l,r) => ArrayBufferMkString(f(l),f(r)) case ArrayBufferAppend(l,r) => ArrayBufferAppend(f(l),f(r)) case _ => super.mirrorDef(e,f) - }).asInstanceOf[Def[A]] // why?? + }).asInstanceOf[Def[A]] // why??*/ -/* override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case Reflect(ArrayBufferMkString(l,r), u, es) => reflectMirrored(Reflect(ArrayBufferMkString(f(l),f(r)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(ArrayBufferAppend(l,r), u, es) => reflectMirrored(Reflect(ArrayBufferAppend(f(l),f(r)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(a@ArrayBufferNew(b), u, es) => reflectMirrored(Reflect(ArrayBufferNew(f(b))(a.mA), mapOver(f,u), f(es))) + case Reflect(a@ArrayBufferAppend(ar,v), u, es) => reflectMirrored(Reflect(ArrayBufferAppend(f(ar),f(v))(a.mA), mapOver(f,u), f(es))) + case Reflect(a@ArrayBufferApply(ar,v), u, es) => reflectMirrored(Reflect(ArrayBufferApply(f(ar),f(v))(a.mA), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(a@ArrayBufferToArray(ar), u, es) => reflectMirrored(Reflect(ArrayBufferToArray(f(ar)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(a@ArrayBufferRemove(ar,v), u, es) => reflectMirrored(Reflect(ArrayBufferRemove(f(ar),f(v))(a.mA), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(a@ArrayBufferSize(ar), u, es) => reflectMirrored(Reflect(ArrayBufferSize(f(ar))(a.mA), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(a@ArrayBufferIndexWhere(m,k,v), u, es) => reflectMirrored(Reflect(ArrayBufferIndexWhere(f(m),k,f(v))(a.mA), mapOver(f,u), f(es))) + case Reflect(a@ArrayBufferMinBy(m,k,v), u, es) => + reflectMirrored(Reflect(ArrayBufferMinBy(f(m).asInstanceOf[Exp[scala.collection.mutable.ArrayBuffer[A]]],k,f(v))(a.mA.asInstanceOf[Manifest[A]],a.mB), mapOver(f,u), f(es))) + case Reflect(afl@ArrayBufferFoldLeft(a,z,i,e,b), u, es) => + reflectMirrored(Reflect(ArrayBufferFoldLeft(f(a),f(z),i,e,f(b))(afl.mA,afl.mB.asInstanceOf[Manifest[A]]), mapOver(f,u), f(es))) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] // why?? -*/ + + override def syms(e: Any): List[Sym[Any]] = e match { + case ArrayBufferForeach(m, k, v) => syms(m):::syms(v) + case ArrayBufferMinBy(m, k, v) => syms(m):::syms(v) + case ArrayBufferFoldLeft(m, z, i, e, v) => syms(m):::syms(v) + case _ => super.syms(e) + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case ArrayBufferForeach(m, k, v) => k :: effectSyms(v) + case ArrayBufferIndexWhere(m, k, v) => k :: effectSyms(m) ::: effectSyms(v) + case ArrayBufferMinBy(m, k, v) => k :: effectSyms(v) + case ArrayBufferFoldLeft(m, z, i, e, v) => i :: e :: effectSyms(v) + case _ => super.boundSyms(e) + } + + override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case ArrayBufferForeach(m, k, v) => freqNormal(m) ::: freqHot(v) + case ArrayBufferMinBy(m, k, v) => freqNormal(m) ::: freqHot(v) + case ArrayBufferFoldLeft(m, z, i, e, v) => freqNormal(m) ::: freqHot(v) + case _ => super.symsFreq(e) + } + } trait BaseGenArrayBufferOps extends GenericNestedCodegen { @@ -89,12 +182,37 @@ trait ScalaGenArrayBufferOps extends BaseGenArrayBufferOps with ScalaGenEffect { import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case a@ArrayBufferNew(xs) => emitValDef(sym, src"scala.collection.mutable.ArrayBuffer[${a.mA}](${(xs map {quote}).mkString(",")})") + case a@ArrayBufferApply(x, i) => emitValDef(sym, quote(x) + "(" + quote(i) + ")") + case a@ArrayBufferNew(xs) => + emitValDef(sym, "scala.collection.mutable.ArrayBuffer[" + remap(a.mA) + "](" + (xs map quote).mkString(",") + ")") case ArrayBufferMkString(l, sep) => emitValDef(sym, src"$l.mkString($sep)") case ArrayBufferAppend(l, e) => emitValDef(sym, src"$l += $e") - case ArrayBufferClear(l) => emitValDef(sym, src"$l.clear()") + case ArrayBufferForeach(l, e, b) => + emitValDef(sym, quote(l) + ".foreach(" + quote(e) + "=> {") + emitBlock(b) + emitBlockResult(b) + stream.println("})") + case ArrayBufferRemove(l, e) => emitValDef(sym, src"$l.remove($e)") case ArrayBufferToArray(x) => emitValDef(sym, src"$x.toArray") case ArrayBufferToSeq(x) => emitValDef(sym, src"$x.toSeq") + case ArrayBufferSize(x) => emitValDef(sym, src"$x.size") + case ArrayBufferClear(x) => emitValDef(sym, src"$x.clear") + case ArrayBufferIndexWhere(l, e, b) => + emitValDef(sym, quote(l) + ".indexWhere(" + quote(e) + "=> {") + emitBlock(b) + emitBlockResult(b) + stream.println("})") + case ArrayBufferMinBy(l, e, b) => + emitValDef(sym, quote(l) + ".minBy(" + quote(e) + "=> {") + emitBlock(b) + emitBlockResult(b) + stream.println("})") + case ArrayBufferFoldLeft(l, z, i, e, b) => + emitValDef(i, quote(z)) + emitValDef(sym, quote(l) + ".foldLeft(" + quote(i) + ")((" + quote(i) + "," + quote(e) + ") => {") + emitBlock(b) + emitBlockResult(b) + stream.println("})") case _ => super.emitNode(sym, rhs) } } @@ -103,8 +221,59 @@ trait CLikeGenArrayBufferOps extends BaseGenArrayBufferOps with CLikeGenBase { val IR: ArrayBufferOpsExp import IR._ + override def remap[A](m: Manifest[A]) = m match { + case s if s <:< manifest[ArrayBuffer[Any]] => "GArray*" + case _ => super.remap(m) + } + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { + case a@ArrayBufferNew(xs) => + emitValDef(sym, "g_array_new(NULL, TRUE, sizeof(" + remap(a.mA) + "))") + case a@ArrayBufferApply(x, i) => + emitValDef(sym, "g_array_index(" + quote(x) + "," + remap(a.mA) + ", " + quote(i) + ")") + case ArrayBufferAppend(l, e) => + emitValDef(sym, "g_array_append_val(" + quote(l) + "," + quote(e) + ")") + case ArrayBufferSize(x) => emitValDef(sym, quote(x) + "->len") + case iw@ArrayBufferIndexWhere(a, e, b) => + // TODO: Yannis: This could be done much better through lowering. Volunteers ? :-) + emitValDef(iw.idx, "0") + emitValDef(sym, "-1") + stream.println("for (;" + quote(iw.idx) + "<" + quote(a) + "->len;" + quote(iw.idx) + "+=1) {") + emitValDef(e, "g_array_index(" + quote(a) + "," + remap(iw.mA) + "," + quote(iw.idx) + ");") + emitBlock(b) + stream.println("if (" + quote(getBlockResult(b)) + " == true) {") + stream.println(quote(sym) + " = " + quote(iw.idx) + ";") + stream.println("break;") + stream.println("}") + stream.println("}") + case mb@ArrayBufferMinBy(a,e,b) => + // TODO: Yannis: This as well could be done much better through lowering. Volunteers ? :-) + // Set minimum to first element + emitValDef(e, "g_array_index(" + quote(a) + "," + remap(mb.mA) + ", 0);") + emitBlock(b) + emitValDef(mb.min, quote(getBlockResult(b))) + emitValDef(sym, quote(e)) + // Iterate rest elements and update min if necessary + emitValDef(mb.idx, "1") + stream.println("for (;" + quote(mb.idx) + "<" + quote(a) + "->len;" + quote(mb.idx) + "+=1) {") + emitValDef(e, "g_array_index(" + quote(a) + "," + remap(mb.mA) + "," + quote(mb.idx) + ");") + emitBlock(b) + stream.println("if (" + quote(getBlockResult(b)) + " < " + quote(mb.min) + ") {") + stream.println(quote(sym) + " = " + quote(e) + ";") + stream.println("}") + stream.println("}") + case afl@ArrayBufferFoldLeft(a,z,i,e,b) => + // TODO: Yannis: And finally the same goes here -- this could be done much better through lowering. Volunteers ? :-) + emitValDef(i, quote(z)) + emitValDef(afl.idx, "0") + stream.println("for (;" + quote(afl.idx) + "<" + quote(a) + "->len;" + quote(afl.idx) + "+=1) {") + emitValDef(e, "g_array_index(" + quote(a) + "," + remap(afl.mA) + "," + quote(afl.idx) + ");") + emitBlock(b) + stream.println(quote(i) + " = " + quote(getBlockResult(b)) + ";") + stream.println("}") + emitValDef(sym,quote(i)) + case abr@ArrayBufferRemove(a,idx) => stream.println("g_array_remove_index(" + quote(a) + "," + quote(idx) + ");") case _ => super.emitNode(sym, rhs) } } @@ -112,5 +281,39 @@ trait CLikeGenArrayBufferOps extends BaseGenArrayBufferOps with CLikeGenBase { trait CudaGenArrayBufferOps extends CudaGenEffect with CLikeGenArrayBufferOps trait OpenCLGenArrayBufferOps extends OpenCLGenEffect with CLikeGenArrayBufferOps -trait CGenArrayBufferOps extends CGenEffect with CLikeGenArrayBufferOps +trait CGenArrayBufferOps extends CGenEffect with CLikeGenArrayBufferOps { + val IR: ArrayBufferOpsExp + import IR._ + + override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { + case a@ArrayBufferNew(xs) => sym.atPhase(LIRLowering) { arraybuffer_new(xs)(a.mA,implicitly[SourceContext]).asInstanceOf[Exp[A]] } + case aba@ArrayBufferApply(a,e) => sym.atPhase(LIRLowering) { + val lar = LIRLowering(a) + arraybuffer_apply(lar,LIRLowering(e))(aba.mA,implicitly[SourceContext]).asInstanceOf[Exp[A]] + } + case abr@ArrayBufferRemove(a,idx) => sym.atPhase(LIRLowering) { + val lar = LIRLowering(a) + arraybuffer_remove(lar,LIRLowering(idx))(abr.mA,implicitly[SourceContext]).asInstanceOf[Exp[A]] + } + case iw@ArrayBufferIndexWhere(a,k,c) => + LIRTraversal(c) + sym.atPhase(LIRLowering) { + val lar = LIRLowering(a) + reflectEffect(ArrayBufferIndexWhere(lar,k,LIRLowering(c))(iw.mA)).asInstanceOf[Exp[A]] + } + case mb@ArrayBufferMinBy(a,k,c) => + LIRTraversal(c) + sym.atPhase(LIRLowering) { + val lar = LIRLowering(a).asInstanceOf[Exp[scala.collection.mutable.ArrayBuffer[A]]] + reflectEffect(ArrayBufferMinBy(lar,k,LIRLowering(c))(mb.mA.asInstanceOf[Manifest[A]],mb.mB)).asInstanceOf[Exp[A]] + } + case afl@ArrayBufferFoldLeft(a,z,i,e,b) => + LIRTraversal(b) + sym.atPhase(LIRLowering) { + val lar = LIRLowering(a).asInstanceOf[Exp[scala.collection.mutable.ArrayBuffer[Any]]] + reflectEffect(ArrayBufferFoldLeft(lar,LIRLowering(z),i,e,LIRLowering(b))(afl.mA,afl.mB.asInstanceOf[Manifest[A]])).asInstanceOf[Exp[A]] + } + case _ => super.lowerNode(sym,rhs) + } +} diff --git a/src/common/ArrayOps.scala b/src/common/ArrayOps.scala index 669ff26b..a9b5a2af 100644 --- a/src/common/ArrayOps.scala +++ b/src/common/ArrayOps.scala @@ -1,70 +1,97 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter import internal._ -import scala.reflect.SourceContext +import scala.reflect.{SourceContext, RefinedManifest} +import scala.collection.mutable.{HashMap,Set} trait ArrayOps extends Variables { + type Size = Long + // multiple definitions needed because implicits won't chain // not using infix here because apply doesn't work with infix methods implicit def varToArrayOps[T:Manifest](x: Var[Array[T]]) = new ArrayOpsCls(readVar(x)) implicit def repArrayToArrayOps[T:Manifest](a: Rep[Array[T]]) = new ArrayOpsCls(a) + implicit def repArrayAnyToArrayOps(a: Rep[Array[Any]]) = new ArrayOpsCls(a) implicit def arrayToArrayOps[T:Manifest](a: Array[T]) = new ArrayOpsCls(unit(a)) // substitution for "new Array[T](...)" // TODO: look into overriding __new for arrays object NewArray { - def apply[T:Manifest](n: Rep[Int]) = array_obj_new(n) + def apply[T:Manifest](n: Rep[Size], specializedType: Rep[String] = unit("")) = array_obj_new(n, specializedType) } object Array { - def apply[T:Manifest](xs: Rep[T]*) = array_obj_fromseq(xs) + def apply[T:Manifest](xs: T*) = array_obj_fromseq(xs) } class ArrayOpsCls[T:Manifest](a: Rep[Array[T]]){ - def apply(n: Rep[Int])(implicit pos: SourceContext) = array_apply(a, n) - def update(n: Rep[Int], y: Rep[T])(implicit pos: SourceContext) = array_update(a,n,y) + def apply(n: Rep[Size])(implicit pos: SourceContext) = array_apply(a, n) + def update(n: Rep[Size], y: Rep[T])(implicit pos: SourceContext) = array_update(a,n,y) def length(implicit pos: SourceContext) = array_length(a) def foreach(block: Rep[T] => Rep[Unit])(implicit pos: SourceContext) = array_foreach(a, block) + def filter(f: Rep[T] => Rep[Boolean]) = array_filter(a, f) + def groupBy[B: Manifest](f: Rep[T] => Rep[B]) = array_group_by(a,f) def sort(implicit pos: SourceContext) = array_sort(a) def map[B:Manifest](f: Rep[T] => Rep[B]) = array_map(a,f) def toSeq = array_toseq(a) - def slice(start:Rep[Int], end:Rep[Int]) = array_slice(a,start,end) - } - - def array_obj_new[T:Manifest](n: Rep[Int]): Rep[Array[T]] - def array_obj_fromseq[T:Manifest](xs: Seq[Rep[T]]): Rep[Array[T]] - def array_apply[T:Manifest](x: Rep[Array[T]], n: Rep[Int])(implicit pos: SourceContext): Rep[T] - def array_update[T:Manifest](x: Rep[Array[T]], n: Rep[Int], y: Rep[T])(implicit pos: SourceContext): Rep[Unit] - def array_unsafe_update[T:Manifest](x: Rep[Array[T]], n: Rep[Int], y: Rep[T])(implicit pos: SourceContext): Rep[Unit] - def array_length[T:Manifest](x: Rep[Array[T]])(implicit pos: SourceContext) : Rep[Int] + def sum = array_sum(a) + def zip[B: Manifest](a2: Rep[Array[B]]) = array_zip(a,a2) + def corresponds[B: Manifest](a2: Rep[Array[B]]) = array_corresponds(a,a2) + def mkString(del: String = "") = array_mkString(a,del) + def startsWith[B:Manifest](s2: Rep[Array[B]])(implicit pos: SourceContext) = array_startsWith[T,B](a,s2) + def endsWith[B:Manifest](s2: Rep[Array[B]])(implicit pos: SourceContext) = array_endsWith[T,B](a,s2) + def slice(from: Rep[Size], until: Rep[Size]) = array_slice[T](a, from, until) + def hash = array_hash(a) + def containsSlice(a2: Rep[Array[T]]) = array_containsSlice(a,a2) + def indexOfSlice(a2: Rep[Array[T]], idx: Rep[Size]) = array_indexOfSlice(a,a2, idx) + def compare(a2: Rep[Array[T]]) = array_compare(a,a2) + } + + def array_obj_new[T:Manifest](n: Rep[Size], specializedType: Rep[String] = unit("")): Rep[Array[T]] + def array_obj_fromseq[T:Manifest](xs: Seq[T]): Rep[Array[T]] + def array_apply[T:Manifest](x: Rep[Array[T]], n: Rep[Size])(implicit pos: SourceContext): Rep[T] + def array_update[T:Manifest](x: Rep[Array[T]], n: Rep[Size], y: Rep[T])(implicit pos: SourceContext): Rep[Unit] + def array_unsafe_update[T:Manifest](x: Rep[Array[T]], n: Rep[Size], y: Rep[T])(implicit pos: SourceContext): Rep[Unit] + def array_length[T:Manifest](x: Rep[Array[T]])(implicit pos: SourceContext) : Rep[Size] def array_foreach[T:Manifest](x: Rep[Array[T]], block: Rep[T] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] - def array_copy[T:Manifest](src: Rep[Array[T]], srcPos: Rep[Int], dest: Rep[Array[T]], destPos: Rep[Int], len: Rep[Int])(implicit pos: SourceContext): Rep[Unit] - def array_unsafe_copy[T:Manifest](src: Rep[Array[T]], srcPos: Rep[Int], dest: Rep[Array[T]], destPos: Rep[Int], len: Rep[Int])(implicit pos: SourceContext): Rep[Unit] + def array_filter[T : Manifest](l: Rep[Array[T]], f: Rep[T] => Rep[Boolean])(implicit pos: SourceContext): Rep[Array[T]] + def array_group_by[T : Manifest, B: Manifest](l: Rep[Array[T]], f: Rep[T] => Rep[B])(implicit pos: SourceContext): Rep[HashMap[B, Array[T]]] def array_sort[T:Manifest](x: Rep[Array[T]])(implicit pos: SourceContext): Rep[Array[T]] def array_map[A:Manifest,B:Manifest](a: Rep[Array[A]], f: Rep[A] => Rep[B]): Rep[Array[B]] def array_toseq[A:Manifest](a: Rep[Array[A]]): Rep[Seq[A]] - def array_slice[A:Manifest](a: Rep[Array[A]], start:Rep[Int], end:Rep[Int]): Rep[Array[A]] + def array_sum[A:Manifest](a: Rep[Array[A]]): Rep[A] + def array_zip[A:Manifest, B: Manifest](a: Rep[Array[A]], a2: Rep[Array[B]]): Rep[Array[(A,B)]] + def array_corresponds[A: Manifest, B: Manifest](a: Rep[Array[A]], a2: Rep[Array[B]]): Rep[Boolean] // limited support for corresponds (tests equality) + def array_mkString[A: Manifest](a: Rep[Array[A]], del: String = ""): Rep[String] + def array_startsWith[A:Manifest, B:Manifest](s1: Rep[Array[A]], s2: Rep[Array[B]])(implicit pos: SourceContext): Rep[Boolean] + def array_endsWith[A:Manifest, B:Manifest](s1: Rep[Array[A]], s2: Rep[Array[B]])(implicit pos: SourceContext): Rep[Boolean] + def array_slice[A: Manifest](a: Rep[Array[A]], from: Rep[Size], until: Rep[Size]): Rep[Array[A]] + def array_hash[A:Manifest](a: Rep[Array[A]]): Rep[Size] + def array_containsSlice[A:Manifest](s1: Rep[Array[A]], s2: Rep[Array[A]])(implicit pos: SourceContext): Rep[Boolean] + def array_indexOfSlice[A:Manifest](s1: Rep[Array[A]], s2: Rep[Array[A]], idx: Rep[Size])(implicit pos: SourceContext): Rep[Size] + def array_compare[A:Manifest](s1: Rep[Array[A]], s2: Rep[Array[A]])(implicit pos: SourceContext): Rep[Int] + def array_copy[T:Manifest](src: Rep[Array[T]], srcPos: Rep[Size], dest: Rep[Array[T]], destPos: Rep[Size], len: Rep[Size])(implicit pos: SourceContext): Rep[Unit] + def array_unsafe_copy[T:Manifest](src: Rep[Array[T]], srcPos: Rep[Size], dest: Rep[Array[T]], destPos: Rep[Size], len: Rep[Size])(implicit pos: SourceContext): Rep[Unit] } -trait ArrayOpsExp extends ArrayOps with EffectExp with VariablesExp { - case class ArrayNew[T:Manifest](n: Exp[Int]) extends Def[Array[T]] { +trait ArrayOpsExp extends ArrayOps with EffectExp with VariablesExp with StructExp with WhileExp with OrderingOps with PrimitiveOps with NumericOps { + case class ArrayNew[T:Manifest](n: Exp[Size], specializedType: Rep[String] = unit("")) extends Def[Array[T]] { val m = manifest[T] } - case class ArrayFromSeq[T:Manifest](xs: Seq[Exp[T]]) extends Def[Array[T]] { + case class ArrayFromSeq[T:Manifest](xs: Seq[T]) extends Def[Array[T]] { val m = manifest[T] } - case class ArrayApply[T:Manifest](a: Exp[Array[T]], n: Exp[Int]) extends Def[T] - case class ArrayUpdate[T:Manifest](a: Exp[Array[T]], n: Exp[Int], y: Exp[T]) extends Def[Unit] - case class ArrayLength[T:Manifest](a: Exp[Array[T]]) extends Def[Int] { + case class ArrayApply[T:Manifest](a: Exp[Array[T]], n: Exp[Size]) extends Def[T] + case class ArrayUpdate[T:Manifest](a: Exp[Array[T]], n: Exp[Size], y: Exp[T]) extends Def[Unit] + case class ArrayLength[T:Manifest](a: Exp[Array[T]]) extends Def[Size] { val m = manifest[T] } case class ArrayForeach[T](a: Exp[Array[T]], x: Sym[T], block: Block[Unit]) extends Def[Unit] - case class ArrayCopy[T:Manifest](src: Exp[Array[T]], srcPos: Exp[Int], dest: Exp[Array[T]], destPos: Exp[Int], len: Exp[Int]) extends Def[Unit] { - val m = manifest[T] - } + case class ArrayFilter[T : Manifest](l: Exp[Array[T]], x: Sym[T], block: Block[Boolean]) extends Def[Array[T]] + case class ArrayGroupBy[T: Manifest, B: Manifest](l: Exp[Array[T]], x: Sym[T], block: Block[B]) extends Def[HashMap[B, Array[T]]] case class ArraySort[T:Manifest](x: Exp[Array[T]]) extends Def[Array[T]] { val m = manifest[T] } @@ -72,21 +99,49 @@ trait ArrayOpsExp extends ArrayOps with EffectExp with VariablesExp { val array = NewArray[B](a.length) } case class ArrayToSeq[A:Manifest](x: Exp[Array[A]]) extends Def[Seq[A]] - case class ArraySlice[A:Manifest](a: Exp[Array[A]], s:Exp[Int], e:Exp[Int]) extends Def[Array[A]] - - def array_obj_new[T:Manifest](n: Exp[Int]) = reflectMutable(ArrayNew(n)) - def array_obj_fromseq[T:Manifest](xs: Seq[Exp[T]]) = /*reflectMutable(*/ ArrayFromSeq(xs) /*)*/ - def array_apply[T:Manifest](x: Exp[Array[T]], n: Exp[Int])(implicit pos: SourceContext): Exp[T] = ArrayApply(x, n) - def array_update[T:Manifest](x: Exp[Array[T]], n: Exp[Int], y: Exp[T])(implicit pos: SourceContext) = reflectWrite(x)(ArrayUpdate(x,n,y)) - def array_unsafe_update[T:Manifest](x: Rep[Array[T]], n: Rep[Int], y: Rep[T])(implicit pos: SourceContext) = ArrayUpdate(x,n,y) - def array_length[T:Manifest](a: Exp[Array[T]])(implicit pos: SourceContext) : Rep[Int] = ArrayLength(a) + case class ArraySum[A:Manifest](x: Exp[Array[A]]) extends Def[A] + case class ArrayZip[A:Manifest, B: Manifest](x: Exp[Array[A]], x2: Exp[Array[B]]) extends Def[Array[(A,B)]] + case class ArrayCorresponds[A:Manifest, B: Manifest](x: Exp[Array[A]], x2: Exp[Array[B]]) extends Def[Boolean] + case class ArrayMkString[A:Manifest](a: Exp[Array[A]], b: String = "") extends Def[String] + case class ArrayStartsWith[A:Manifest,B:Manifest](s1: Exp[Array[A]], s2: Exp[Array[B]]) extends Def[Boolean] + case class ArrayEndsWith[A:Manifest,B:Manifest](s1: Exp[Array[A]], s2: Exp[Array[B]]) extends Def[Boolean] + case class ArraySlice[A:Manifest](a: Exp[Array[A]], from: Exp[Size], until: Exp[Size]) extends Def[Array[A]] { + val m = manifest[A] + } + case class ArrayContainsSlice[A:Manifest](s1: Exp[Array[A]], s2: Exp[Array[A]]) extends Def[Boolean] + case class ArrayIndexOfSlice[A:Manifest](s1: Exp[Array[A]], s2: Exp[Array[A]], idx: Rep[Size]) extends Def[Size] { + val m = manifest[A] + } + case class ArrayCompare[A:Manifest](s1: Exp[Array[A]], s2: Exp[Array[A]]) extends Def[Int] { + val m = manifest[A] + } + case class ArrayHash[A:Manifest](a: Exp[Array[A]]) extends Def[Size] + case class ArrayCopy[T:Manifest](src: Exp[Array[T]], srcPos: Exp[Size], dest: Exp[Array[T]], destPos: Exp[Size], len: Exp[Size]) extends Def[Unit] { + val m = manifest[T] + } + + def array_obj_new[T:Manifest](n: Exp[Size], specializedType: Rep[String] = unit("")) = reflectMutable(ArrayNew(n, specializedType)) + def array_obj_fromseq[T:Manifest](xs: Seq[T]) = /*reflectMutable(*/ ArrayFromSeq(xs) /*)*/ + def array_apply[T:Manifest](x: Exp[Array[T]], n: Exp[Size])(implicit pos: SourceContext): Exp[T] = ArrayApply(x, n) + def array_update[T:Manifest](x: Exp[Array[T]], n: Exp[Size], y: Exp[T])(implicit pos: SourceContext) = reflectWrite(x)(ArrayUpdate(x,n,y)) + def array_unsafe_update[T:Manifest](x: Rep[Array[T]], n: Rep[Size], y: Rep[T])(implicit pos: SourceContext) = ArrayUpdate(x,n,y) + def array_length[T:Manifest](a: Exp[Array[T]])(implicit pos: SourceContext) : Rep[Size] = ArrayLength(a) def array_foreach[T:Manifest](a: Exp[Array[T]], block: Exp[T] => Exp[Unit])(implicit pos: SourceContext): Exp[Unit] = { val x = fresh[T] val b = reifyEffects(block(x)) reflectEffect(ArrayForeach(a, x, b), summarizeEffects(b).star) } - def array_copy[T:Manifest](src: Exp[Array[T]], srcPos: Exp[Int], dest: Exp[Array[T]], destPos: Exp[Int], len: Exp[Int])(implicit pos: SourceContext) = reflectWrite(dest)(ArrayCopy(src,srcPos,dest,destPos,len)) - def array_unsafe_copy[T:Manifest](src: Exp[Array[T]], srcPos: Exp[Int], dest: Exp[Array[T]], destPos: Exp[Int], len: Exp[Int])(implicit pos: SourceContext) = ArrayCopy(src,srcPos,dest,destPos,len) + def array_filter[T : Manifest](l: Exp[Array[T]], f: Exp[T] => Exp[Boolean])(implicit pos: SourceContext) = { + val a = fresh[T] + val b = reifyEffects(f(a)) + reflectEffect(ArrayFilter(l, a, b), summarizeEffects(b).star) + } + def array_group_by[T : Manifest, B: Manifest](l: Exp[Array[T]], f: Exp[T] => Exp[B])(implicit pos: SourceContext) = { + val a = fresh[T] + val b = reifyEffects(f(a)) + reflectEffect(ArrayGroupBy(l, a, b), summarizeEffects(b).star) + } + def array_sort[T:Manifest](x: Exp[Array[T]])(implicit pos: SourceContext) = ArraySort(x) def array_map[A:Manifest,B:Manifest](a: Exp[Array[A]], f: Exp[A] => Exp[B]) = { val x = fresh[A] @@ -94,8 +149,20 @@ trait ArrayOpsExp extends ArrayOps with EffectExp with VariablesExp { reflectEffect(ArrayMap(a, x, b), summarizeEffects(b)) } def array_toseq[A:Manifest](a: Exp[Array[A]]) = ArrayToSeq(a) - def array_slice[A:Manifest](a: Rep[Array[A]], start:Rep[Int], end:Rep[Int]) = ArraySlice(a,start,end) - + def array_sum[A:Manifest](a: Exp[Array[A]]) = reflectEffect(ArraySum(a)) + def array_zip[A:Manifest, B: Manifest](a: Exp[Array[A]], a2: Exp[Array[B]]) = reflectEffect(ArrayZip(a,a2)) + def array_corresponds[A: Manifest, B: Manifest](a: Rep[Array[A]], a2: Rep[Array[B]]) = reflectEffect(ArrayCorresponds(a,a2)) + def array_mkString[A: Manifest](a: Rep[Array[A]], del: String = "") = reflectEffect(ArrayMkString(a, del)) + def array_startsWith[A:Manifest,B:Manifest](s1: Exp[Array[A]], s2: Exp[Array[B]])(implicit pos: SourceContext) = ArrayStartsWith(s1,s2) + def array_endsWith[A:Manifest,B:Manifest](s1: Exp[Array[A]], s2: Exp[Array[B]])(implicit pos: SourceContext) = ArrayEndsWith(s1,s2) + def array_slice[A: Manifest](a: Exp[Array[A]], from: Exp[Size], until: Exp[Size]) = reflectEffect(ArraySlice[A](a,from,until)) + def array_hash[A:Manifest](a: Rep[Array[A]]) = reflectEffect(ArrayHash(a)) + def array_containsSlice[A:Manifest](s1: Exp[Array[A]], s2: Exp[Array[A]])(implicit pos: SourceContext) = ArrayContainsSlice(s1,s2) + def array_indexOfSlice[A:Manifest](s1: Exp[Array[A]], s2: Exp[Array[A]], idx: Exp[Size])(implicit pos: SourceContext) = ArrayIndexOfSlice(s1,s2,idx) + def array_compare[A:Manifest](s1: Exp[Array[A]], s2: Exp[Array[A]])(implicit pos: SourceContext)= ArrayCompare(s1,s2) + def array_copy[T:Manifest](src: Exp[Array[T]], srcPos: Exp[Size], dest: Exp[Array[T]], destPos: Exp[Size], len: Exp[Size])(implicit pos: SourceContext) = reflectWrite(dest)(ArrayCopy(src,srcPos,dest,destPos,len)) + def array_unsafe_copy[T:Manifest](src: Exp[Array[T]], srcPos: Exp[Size], dest: Exp[Array[T]], destPos: Exp[Size], len: Exp[Size])(implicit pos: SourceContext) = ArrayCopy(src,srcPos,dest,destPos,len) + ////////////// // mirroring @@ -104,30 +171,44 @@ trait ArrayOpsExp extends ArrayOps with EffectExp with VariablesExp { case ArrayLength(x) => array_length(f(x)) case e@ArraySort(x) => array_sort(f(x))(e.m,pos) case e@ArrayCopy(a,ap,d,dp,l) => toAtom(ArrayCopy(f(a),f(ap),f(d),f(dp),f(l))(e.m))(mtype(manifest[A]),pos) - case Reflect(e@ArrayNew(n), u, es) => reflectMirrored(Reflect(ArrayNew(f(n))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@ArrayLength(x), u, es) => reflectMirrored(Reflect(ArrayLength(f(x))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ArrayApply(l,r), u, es) => reflectMirrored(Reflect(ArrayApply(f(l),f(r))(mtype(manifest[A])), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@ArraySort(x), u, es) => reflectMirrored(Reflect(ArraySort(f(x))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ArrayUpdate(l,i,r), u, es) => reflectMirrored(Reflect(ArrayUpdate(f(l),f(i),f(r)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@ArrayCopy(a,ap,d,dp,l), u, es) => reflectMirrored(Reflect(ArrayCopy(f(a),f(ap),f(d),f(dp),f(l))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case ArrayCompare(a1, a2) => array_compare(f(a1), f(a2)) + case ArrayStartsWith(a1, a2) => array_startsWith(f(a1), f(a2)) + case ArrayEndsWith(a1, a2) => array_startsWith(f(a1), f(a2)) + case ArrayContainsSlice(a1, a2) => array_startsWith(f(a1), f(a2)) + case Reflect(e@ArraySlice(arr,idx1,idx2), u, es) => reflectMirrored(Reflect(ArraySlice(f(arr), f(idx1), f(idx2))(e.m), mapOver(f,u),f(es)))(mtype(manifest[A])) + case Reflect(e@ArrayIndexOfSlice(arr1,arr2,idx), u, es) => reflectMirrored(Reflect(ArrayIndexOfSlice(f(arr1), f(arr2), f(idx))(e.m), mapOver(f,u),f(es)))(mtype(manifest[A])) + case Reflect(e@ArrayNew(n, sType), u, es) => reflectMirrored(Reflect(ArrayNew(f(n), sType)(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@ArrayLength(x), u, es) => reflectMirrored(Reflect(ArrayLength(f(x))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(ArrayApply(l,r), u, es) => reflectMirrored(Reflect(ArrayApply(f(l),f(r))(mtype(manifest[A])), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@ArraySort(x), u, es) => reflectMirrored(Reflect(ArraySort(f(x))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(ArrayUpdate(l,i,r), u, es) => reflectMirrored(Reflect(ArrayUpdate(f(l),f(i),f(r)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@ArrayCopy(a,ap,d,dp,l), u, es) => reflectMirrored(Reflect(ArrayCopy(f(a),f(ap),f(d),f(dp),f(l))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] // why?? override def syms(e: Any): List[Sym[Any]] = e match { case ArrayForeach(a, x, body) => syms(a):::syms(body) case ArrayMap(a, x, body) => syms(a):::syms(body) + case ArrayFilter(a, x, body) => syms(a):::syms(body) + case ArrayGroupBy(a, x, body) => syms(a):::syms(body) + case ArraySlice(a,idx1,idx2) => syms(a) case _ => super.syms(e) } override def boundSyms(e: Any): List[Sym[Any]] = e match { case ArrayForeach(a, x, body) => x :: effectSyms(body) case ArrayMap(a, x, body) => x :: effectSyms(body) + case ArrayFilter(a, x, body) => x :: effectSyms(body) + case ArrayGroupBy(a, x, body) => x::effectSyms(body) + case ArraySlice(a,idx1,idx2) => effectSyms(a) case _ => super.boundSyms(e) } override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { case ArrayForeach(a, x, body) => freqNormal(a):::freqHot(body) case ArrayMap(a, x, body) => freqNormal(a):::freqHot(body) + case ArrayFilter(a, x, body) => freqNormal(a):::freqHot(body) + case ArrayGroupBy(a, x, body) => freqNormal(a):::freqHot(body) case _ => super.symsFreq(e) } @@ -135,22 +216,8 @@ trait ArrayOpsExp extends ArrayOps with EffectExp with VariablesExp { trait ArrayOpsExpOpt extends ArrayOpsExp { - /** - * @author Alen Stojanov (astojanov@inf.ethz.ch) - */ - override def array_length[T:Manifest](a: Exp[Array[T]])(implicit pos: SourceContext) : Rep[Int] = a match { - case Def(ArrayNew(n: Exp[Int])) => n - case Def(ArrayFromSeq(xs)) => Const(xs.size) - case Def(ArraySort(x)) => array_length(x) - case Def(ArrayMap(x, _, _)) => array_length(x) - case Def(Reflect(ArrayNew(n: Exp[Int]), _, _)) => n - case Def(Reflect(ArrayFromSeq(xs), _, _)) => Const(xs.size) - case Def(Reflect(ArraySort(x), _, _)) => array_length(x) - case Def(Reflect(ArrayMap(x, _, _), _, _)) => array_length(x) - case _ => super.array_length(a) - } - override def array_apply[T:Manifest](x: Exp[Array[T]], n: Exp[Int])(implicit pos: SourceContext): Exp[T] = { + override def array_apply[T:Manifest](x: Exp[Array[T]], n: Exp[Size])(implicit pos: SourceContext): Exp[T] = { if (context ne null) { // find the last modification of array x // if it is an assigment at index n, just return the last value assigned @@ -168,7 +235,7 @@ trait ArrayOpsExpOpt extends ArrayOpsExp { } } - override def array_update[T:Manifest](x: Exp[Array[T]], n: Exp[Int], y: Exp[T])(implicit pos: SourceContext) = { + override def array_update[T:Manifest](x: Exp[Array[T]], n: Exp[Size], y: Exp[T])(implicit pos: SourceContext) = { if (context ne null) { // find the last modification of array x // if it is an assigment at index n with the same value, just do nothing @@ -186,6 +253,8 @@ trait ArrayOpsExpOpt extends ArrayOpsExp { } } + + } @@ -204,7 +273,10 @@ trait ScalaGenArrayOps extends BaseGenArrayOps with ScalaGenBase { val ARRAY_LITERAL_MAX_SIZE = 1000 override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case a@ArrayNew(n) => emitValDef(sym, src"new Array[${remap(a.m)}]($n)") + case a@ArrayNew(n, sType) => { + val arrType = if (quote(sType) != "\"\"") quote(sType).replaceAll("\"","") else remap(a.m) + emitValDef(sym, src"new Array[$arrType]($n)") + } case e@ArrayFromSeq(xs) => { emitData(sym, xs) emitValDef(sym, @@ -220,49 +292,77 @@ trait ScalaGenArrayOps extends BaseGenArrayOps with ScalaGenBase { "{import scala.io.Source;(Source.fromFile(\"" + symDataPath(sym) + "\").getLines.map{Integer.parseInt(_)}).toArray}" } else { - "Array(" + (xs map quote).mkString(",") + ")" + src"Array($xs)" } ) } case ArrayApply(x,n) => emitValDef(sym, src"$x($n)") - case ArrayUpdate(x,n,y) => emitValDef(sym, src"$x($n) = $y") + case ArrayUpdate(x,n,y) => emitAssignment(sym, src"$x($n)", quote(y)) case ArrayLength(x) => emitValDef(sym, src"$x.length") - case ArrayForeach(a,x,block) => - gen"""val $sym = $a.foreach{ - |$x => + case ArrayForeach(a,x,block) => + stream.println(quote(a) + ".foreach{") + gen"""$x => |${nestedBlock(block)} |$block |}""" - case ArrayCopy(src,srcPos,dest,destPos,len) => emitValDef(sym, src"System.arraycopy($src,$srcPos,$dest,$destPos,$len)") - case a@ArraySort(x) => - gen"""val $sym = { - |val d = new Array[${remap(a.m)}]($x.length) - |System.arraycopy($x, 0, d, 0, $x.length) - |scala.util.Sorting.quickSort(d) - |d - |}""" - case n@ArrayMap(a,x,blk) => - gen"""// workaround for refinedManifest problem - |val $sym = { - |val out = ${n.array} - |val in = $a - |var i = 0 - |while (i < in.length) { - |val $x = in(i) - |${nestedBlock(blk)} - |out(i) = $blk - |i += 1 - |} - |out - |}""" - - // stream.println("val " + quote(sym) + " = " + quote(a) + ".map{") - // stream.println(quote(x) + " => ") - // emitBlock(blk) - // stream.println(quote(getBlockResult(blk))) - // stream.println("}") + case a@ArraySort(x) => + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + gen"""{ + |val d = new Array[${a.m}]($x.length) + |System.arraycopy($x, 0, d, 0, $x.length) + |scala.util.Sorting.quickSort(d) + |d + |}""" + } + emitValDef(sym, strWriter.toString) + case n@ArrayMap(a,x,blk) => + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + //stream.println("/* workaround for refinedManifest problem */") + gen"""{ + |val out = ${n.array} + |val in = $a + |var i = 0 + |while (i < in.length) { + |val $x = in(i) + |${nestedBlock(blk)} + |out(i) = $blk + |i += 1 + |} + |out + |}""" + } + emitValDef(sym, strWriter.toString) + case ArrayFilter(a,x,blk) => + emitValDef(sym, quote(a) + ".filter(" + quote(x) + "=> {") + emitBlock(blk) + emitBlockResult(blk) + stream.println("})") + case ArrayGroupBy(a,x,blk) => + emitValDef(sym, quote(a) + ".groupBy(" + quote(x) + "=> {") + emitBlock(blk) + emitBlockResult(blk) + stream.println("})") + case ArraySum(a) => emitValDef(sym, quote(a) + ".sum") case ArrayToSeq(a) => emitValDef(sym, src"$a.toSeq") - case ArraySlice(a,s,e) => emitValDef(sym, src"$a.slice($s,$e)") + case ArrayZip(a,a2) => emitValDef(sym, src"$a zip $a2") + case ArrayCorresponds(a,a2) => emitValDef(sym, src"$a.corresponds($a2){_==_}") + case ArrayMkString(a, del) => + if (del != "") + emitValDef(sym, src"$a.mkString($del)") + else + emitValDef(sym, src"$a.mkString") + case ArrayStartsWith(a,a2) => emitValDef(sym, src"$a.startsWith($a2)") + case ArrayEndsWith(a,a2) => emitValDef(sym, src"$a.endsWith($a2)") + case ArraySlice(a,from,until) => emitValDef(sym, src"$a.slice($from,$until)") + case ArrayHash(a) => emitValDef(sym, src"$a.foldLeft(0) { (cnt,x) => cnt + x.## }") + case ArrayContainsSlice(a,a2) => emitValDef(sym, src"$a.containsSlice($a2)") + case ArrayIndexOfSlice(a,a2,idx) => emitValDef(sym, src"$a.indexOfSlice($a2,$idx)") + case ArrayCompare(a,a2) => emitValDef(sym, "(" + quote(a) + ".zip(" + quote(a2) + ")).foldLeft(0){ (res, elem) => if (res == 0) elem._1 - elem._2 else res}") + case ArrayCopy(src,srcPos,dest,destPos,len) => emitValDef(sym, src"System.arraycopy($src,$srcPos,$dest,$destPos,$len)") case _ => super.emitNode(sym, rhs) } } @@ -273,10 +373,9 @@ trait CLikeGenArrayOps extends BaseGenArrayOps with CLikeGenBase { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { - case ArrayLength(x) => emitValDef(sym, src"sizeof($x)/sizeof(*$x)") // WARN: statically allocated elements only - case ArrayApply(x,n) => emitValDef(sym, src"$x[$n]") + case ArrayLength(x) => emitValDef(sym, src"$x.length") + case ArrayApply(x,n) => emitValDef(sym, src"$x.apply($n)") case ArrayUpdate(x,n,y) => stream.println(src"$x.update($n,$y);") - case ArraySlice(x,s,e) => val tp=remap(x.tp.typeArguments(0)); emitValDef(sym, src"({ size_t sz=sizeof("+tp+")*($e-$s); "+tp+"* r = ("+tp+"*)malloc(sz); memcpy(r,(("+tp+"*)$x)+$s,sz); r; })") case _ => super.emitNode(sym, rhs) } } @@ -284,17 +383,155 @@ trait CLikeGenArrayOps extends BaseGenArrayOps with CLikeGenBase { trait CudaGenArrayOps extends CudaGenBase with CLikeGenArrayOps trait OpenCLGenArrayOps extends OpenCLGenBase with CLikeGenArrayOps -trait CGenArrayOps extends CGenBase with BaseGenArrayOps { - val IR: ArrayOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { - rhs match { - case ArrayLength(x) => emitValDef(sym, quote(x) + "->length") - case ArrayApply(x,n) => emitValDef(sym, quote(x) + "->apply(" + quote(n) + ")") - case ArrayUpdate(x,n,y) => stream.println(quote(x) + "->update(" + quote(n) + "," + quote(y) + ");") - case _ => super.emitNode(sym, rhs) - } +trait CGenArrayOps extends CGenEffect with CGenStruct { + val IR: ArrayOpsExp + import IR._ + +/* + + override def remapManifest[T:Manifest](sym: Sym[T]): Manifest[_] = { + if (sym.tp.erasure.isArray) manifest[LoweredArray[T]] + else super.remapManifest(sym) + } + + override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { + case a@ArrayNew(n, sType) => { + sym.atPhase(LIRLowering) { + reflectEffect(SimpleStruct[LoweredArray[T]](ClassTag(structName(manifest[T])), Seq( + "array" -> reflectEffect(rhs), + "length" -> n + ))).asInstanceOf[Exp[T]] + } + } + case ArrayApply(a, n) => { + sym.atPhase(LIRLowering) { + val ar = field[Array[T]](LIRLowering(a), "array") + reflectEffect(ArrayApply(ar, LIRLowering(n))).asInstanceOf[Exp[T]] + } + } + case ArrayFilter(a,x,blk) => { + /* Not yet implemented, not needed so far (we take advantage of the final + '\0' character for array of bytes for all operations of importance) */ + sym.atPhase(LIRLowering) { + LIRLowering(a).asInstanceOf[Exp[T]] + } + } + case ArrayUpdate(a, n, y) => { + sym.atPhase(LIRLowering) { + val ar = field[Array[Any]](LIRLowering(a), "array") + reflectEffect(ArrayUpdate(ar, LIRLowering(n), LIRLowering(y))).asInstanceOf[Exp[T]] + } + } + case ar@ArrayLength(a) => + sym.atPhase(LIRLowering) { + field(LIRLowering(a),"length").asInstanceOf[Exp[T]] + } + case ArrayHash(a) => + sym.atPhase(LIRLowering) { + if (a.tp != manifest[Array[Byte]]) throw new Exception("Unknown manifest " + a.tp + " when lowering ArrayHash.") + val arr = field[Array[Byte]](LIRLowering(a),"array") + val arrlen = field(LIRLowering(a),"length").asInstanceOf[Rep[Int]] + var i = var_new[Int](unit(0)) + var h = var_new[Int](unit(0)) + __whileDo(i < arrlen && arr(i) != unit('\0'), { + h += arr(i) + i+=1 + }) + readVar(h).asInstanceOf[Exp[T]] + } + case ArrayCorresponds(a1,a2) => + sym.atPhase(LIRLowering) { + if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[Array[Byte]]) { + val arr2 = field[Array[Byte]](LIRLowering(a2),"array") + __equal(LIRLowering(a1),arr2).asInstanceOf[Exp[T]] + } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayCorresponds.") + } + case ArrayCompare(a1,a2) => + sym.atPhase(LIRLowering) { + if (a1.tp == manifest[Array[Byte]] && (a2.tp == manifest[Array[Byte]] || a2.tp.typeArguments(0) == manifest[Array[Byte]])) { + val arr1 = field[Array[Byte]](LIRLowering(a1),"array") + val arr2 = field[Array[Byte]](LIRLowering(a2),"array") + string_compareTo(arr1.asInstanceOf[Exp[String]],arr2.asInstanceOf[Exp[String]]).asInstanceOf[Exp[T]] + } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayCompare.") + } + case ArrayStartsWith(a1,a2) => + sym.atPhase(LIRLowering) { + if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[java.lang.String]) { + val arr1 = field[Array[Byte]](LIRLowering(a1),"array") + string_startswith(arr1.asInstanceOf[Exp[String]],a2.asInstanceOf[Exp[String]]).asInstanceOf[Exp[T]] + } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayStartsWith.") + } + case ArrayEndsWith(a1,a2) => + sym.atPhase(LIRLowering) { + if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[java.lang.String]) { + val arr1 = field[Array[Byte]](LIRLowering(a1),"array") + string_endswith(arr1.asInstanceOf[Exp[String]],a2.asInstanceOf[Exp[String]]).asInstanceOf[Exp[T]] + } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayEndsWith.") + } + case ArrayContainsSlice(a1,a2) => + sym.atPhase(LIRLowering) { + if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[java.lang.String]) { + val arr1 = field[Array[Byte]](LIRLowering(a1),"array") + string_containsSlice(arr1.asInstanceOf[Exp[String]],a2.asInstanceOf[Exp[String]]).asInstanceOf[Exp[T]] + } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayContainsSlice.") + } + case ArrayIndexOfSlice(a1,a2,idx) => + sym.atPhase(LIRLowering) { + if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[java.lang.String]) { + val arr1 = field[Array[Byte]](LIRLowering(a1),"array") + string_indexOfSlice(arr1.asInstanceOf[Exp[String]],LIRLowering(a2).asInstanceOf[Exp[String]],LIRLowering(idx)).asInstanceOf[Exp[T]] + } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayIndexOfSlice.") + } + case as@ArraySlice(arr,idx1,idx2) => + sym.atPhase(LIRLowering) { + val len = LIRLowering(idx2) - LIRLowering(idx1) + 1 + // Initialize new array + val newarr = reflectEffect(SimpleStruct[LoweredArray[T]](ClassTag(structName(manifest[T])), Seq( + "array" -> array_obj_new(len)(as.m), + "length" -> len + ))) + // Perform the copy + // TODO: FIX THE TYPE OF THIS ARRAY -- IT CAN BE ANY, BUT DOES IT AFFECT ANYTHING? + val arr1 = field[Array[Byte]](newarr,"array") + val arr2 = field[Array[Byte]](LIRLowering(arr),"array") + array_copy(arr2.asInstanceOf[Exp[Array[Any]]],unit(0),arr1.asInstanceOf[Exp[Array[Any]]],unit(0),len-unit(1)) + newarr.asInstanceOf[Exp[T]] + } + case _ => super.lowerNode(sym, rhs) } -} +*/ + + + abstract class LoweredArray[T:Manifest] + + override def remap[A](m: Manifest[A]) = m match { + case s if m <:< manifest[LoweredArray[Any]] => "struct " + structName(m.typeArguments.head) + "*" + case s if m.erasure.isArray => remap(m.typeArguments.head) + "*" + case _ => super.remap(m) + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case a@ArrayNew(n, sType) => { + val arrType = if (quote(sType) != "\"\"") quote(sType) else remap(a.m) + stream.println(arrType + "* " + quote(sym) + " = " + getMemoryAllocString(quote(n), arrType)) + } + case ArrayForeach(a,x,blk) => { + stream.println("{") + stream.println("int i = 0;") + stream.println("for ( i = 0 ; i < " + quote(findInitSymbol(a)) + "Size; i += 1) {") + emitBlock(blk) + emitBlockResult(blk) + stream.println("}") + stream.println("};") + } + case ArrayApply(x,n) => emitValDef(sym, quote(x) + "[" + quote(n) + "]") + case ArrayUpdate(x,n,y) => stream.println(quote(x) + "[" + quote(n) + "] = " + quote(y) + ";") + case ArrayCopy(src,s1,dest,s2,len) => + stream.println("memcpy(" + quote(dest) + "," + quote(src) + "," + quote(len) + ");") + stream.println(quote(dest) + "[" + quote(len) + "] = '\\0';") + case _ => super.emitNode(sym, rhs) + } + } +} diff --git a/src/common/Base.scala b/src/common/Base.scala index f389beb9..c7970497 100644 --- a/src/common/Base.scala +++ b/src/common/Base.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import internal._ @@ -17,12 +17,12 @@ trait LiftAll extends Base { * * @since 0.1 */ -trait Base extends EmbeddedControls { +trait Base extends EmbeddedControls with LoweringTransform { type API <: Base type Rep[+T] - protected def unit[T:Manifest](x: T): Rep[T] + def unit[T:Manifest](x: T): Rep[T] // always lift Unit and Null (for now) implicit def unitToRepUnit(x: Unit) = unit(x) @@ -37,11 +37,20 @@ trait Base extends EmbeddedControls { trait BaseExp extends Base with Expressions with Blocks with Transforming { type Rep[+T] = Exp[T] - protected def unit[T:Manifest](x: T) = Const(x) + def unit[T:Manifest](x: T) = Const(x) } -trait BlockExp extends BaseExp with Blocks +trait BlockExp extends BaseExp +/* +trait BlockExp extends BaseExp with Blocks { + + implicit object CanTransformBlock extends CanTransform[Block] { + def transform[A](x: Block[A], t: Transformer): Block[A] = Block(t(x.res)) + } + +} +*/ trait EffectExp extends BaseExp with Effects { @@ -57,8 +66,17 @@ trait EffectExp extends BaseExp with Effects { } override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = e match { +/* + case Reflect(x, u, es) => + reifyEffects { + context = f(es) + mirror(x) + } + +*/ +// case Reflect(Print(x), u, es) => Reflect(Print(f(x)), es map (e => f(e))) case Reflect(x, u, es) => reflectMirrored(mirrorDef(e,f).asInstanceOf[Reflect[A]]) - case Reify(x, u, es) => Reify(f(x), mapOver(f,u), f(es)) + case Reify(x, u, es) => Reify(f(x), mapOver(f,u), f(es)) //TODO: u case _ => super.mirror(e,f) } @@ -67,7 +85,7 @@ trait EffectExp extends BaseExp with Effects { trait BaseFatExp extends BaseExp with FatExpressions with FatTransforming -// The traits below provide an interface to codegen so that clients do +// The traits below provide an interface to codegen so that client do // not need to depend on internal._ trait ScalaGenBase extends ScalaCodegen diff --git a/src/common/BooleanOps.scala b/src/common/BooleanOps.scala index 75128bc3..061b2665 100644 --- a/src/common/BooleanOps.scala +++ b/src/common/BooleanOps.scala @@ -1,8 +1,9 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter import scala.reflect.SourceContext +import scala.virtualization.lms.internal._ trait LiftBoolean { this: Base => @@ -10,96 +11,167 @@ trait LiftBoolean { implicit def boolToBoolRep(b: Boolean) = unit(b) } -trait BooleanOps extends Variables { +trait BooleanOps extends Variables with Expressions { def infix_unary_!(x: Rep[Boolean])(implicit pos: SourceContext) = boolean_negate(x) - def infix_&&(lhs: Rep[Boolean], rhs: =>Rep[Boolean])(implicit pos: SourceContext) = boolean_and(lhs,rhs) - def infix_||(lhs: Rep[Boolean], rhs: =>Rep[Boolean])(implicit pos: SourceContext) = boolean_or(lhs,rhs) - - // TODO: short-circuit by default + def infix_&&(lhs: Rep[Boolean], rhs: => Rep[Boolean])(implicit pos: SourceContext) = boolean_and(lhs,rhs) + def infix_&&(lhs: Boolean, rhs: => Rep[Boolean])(implicit pos: SourceContext): Exp[Boolean] = { + if (lhs == true) rhs.asInstanceOf[Exp[Boolean]] + else Const(false) + } + def infix_||(lhs: Rep[Boolean], rhs: => Rep[Boolean])(implicit pos: SourceContext) = boolean_or(lhs,rhs) + def infix_||(lhs: Boolean, rhs: => Rep[Boolean])(implicit pos: SourceContext): Exp[Boolean] = { + if (lhs == true) Const(true) + else rhs.asInstanceOf[Exp[Boolean]] + } def boolean_negate(lhs: Rep[Boolean])(implicit pos: SourceContext): Rep[Boolean] - def boolean_and(lhs: Rep[Boolean], rhs: Rep[Boolean])(implicit pos: SourceContext): Rep[Boolean] - def boolean_or(lhs: Rep[Boolean], rhs: Rep[Boolean])(implicit pos: SourceContext): Rep[Boolean] + def boolean_and(lhs: Rep[Boolean], rhs: => Rep[Boolean])(implicit pos: SourceContext): Rep[Boolean] + def boolean_or(lhs: Rep[Boolean], rhs: => Rep[Boolean])(implicit pos: SourceContext): Rep[Boolean] } -trait BooleanOpsExp extends BooleanOps with EffectExp { +trait BooleanOpsExp extends BooleanOps with BaseExp with EffectExp { case class BooleanNegate(lhs: Exp[Boolean]) extends Def[Boolean] - case class BooleanAnd(lhs: Exp[Boolean], rhs: Exp[Boolean]) extends Def[Boolean] - case class BooleanOr(lhs: Exp[Boolean], rhs: Exp[Boolean]) extends Def[Boolean] + case class BooleanAnd(lhs: Exp[Boolean], rhs: Block[Boolean]) extends Def[Boolean] { + val c = fresh[Boolean] // used in c code generation + } + case class BooleanOr(lhs: Exp[Boolean], rhs: Block[Boolean]) extends Def[Boolean] { + val c = fresh[Boolean] // used in c code generation + } def boolean_negate(lhs: Exp[Boolean])(implicit pos: SourceContext) : Exp[Boolean] = BooleanNegate(lhs) - def boolean_and(lhs: Exp[Boolean], rhs: Exp[Boolean])(implicit pos: SourceContext) : Exp[Boolean] = BooleanAnd(lhs,rhs) - def boolean_or(lhs: Exp[Boolean], rhs: Exp[Boolean])(implicit pos: SourceContext) : Exp[Boolean] = BooleanOr(lhs,rhs) + def boolean_and(lhs: Exp[Boolean], frhs: => Exp[Boolean])(implicit pos: SourceContext) : Exp[Boolean] = { + lhs match { + case x@Const(false) => x + case x@Const(true) => frhs + case _ => { + val rhs = reifyEffects(frhs) + BooleanAnd(lhs,rhs) + } + } + } + def boolean_or(lhs: Exp[Boolean], frhs: => Exp[Boolean])(implicit pos: SourceContext) : Exp[Boolean] = { + lhs match { + case x@Const(true) => x + case x@Const(false) => frhs + case _ => { + val rhs = reifyEffects(frhs) + BooleanOr(lhs,rhs) + } + } + } override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { case BooleanNegate(x) => boolean_negate(f(x)) - case BooleanAnd(x,y) => boolean_and(f(x),f(y)) - case BooleanOr(x,y) => boolean_or(f(x),f(y)) - - case Reflect(BooleanNegate(x), u, es) => reflectMirrored(Reflect(BooleanNegate(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(BooleanAnd(x,y), u, es) => reflectMirrored(Reflect(BooleanAnd(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(BooleanOr(x,y), u, es) => reflectMirrored(Reflect(BooleanOr(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case BooleanAnd(x,y) => toAtom(BooleanAnd(f(x),f(y))) + case BooleanOr(x,y) => toAtom(BooleanOr(f(x),f(y))) case _ => super.mirror(e, f) }).asInstanceOf[Exp[A]] // why?? -} + + override def syms(e: Any): List[Sym[Any]] = e match { + case BooleanAnd(lhs,rhs) => syms(lhs):::syms(rhs) + case BooleanOr(lhs,rhs) => syms(lhs):::syms(rhs) + case _ => super.syms(e) + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case BooleanAnd(lhs,rhs) => effectSyms(lhs) ::: effectSyms(rhs) + case BooleanOr(lhs,rhs) => effectSyms(lhs) ::: effectSyms(rhs) + case _ => super.boundSyms(e) + } + override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case BooleanAnd(a, x) => freqHot(a):::freqCold(x) + case BooleanOr(a, x) => freqHot(a):::freqCold(x) + case _ => super.symsFreq(e) + } -/** - * @author Alen Stojanov (astojanov@inf.ethz.ch) - */ -trait BooleanOpsExpOpt extends BooleanOpsExp { +} + +trait BooleanOpsExpOpt extends BooleanOpsExp { override def boolean_negate(lhs: Exp[Boolean])(implicit pos: SourceContext) = lhs match { case Def(BooleanNegate(x)) => x - case Const(a) => Const(!a) case _ => super.boolean_negate(lhs) } - - override def boolean_and(lhs: Exp[Boolean], rhs: Exp[Boolean])(implicit pos: SourceContext) : Exp[Boolean] = { - (lhs, rhs) match { - case (Const(false), _) => Const(false) - case (_, Const(false)) => Const(false) - case (Const(true), x) => x - case (x, Const(true)) => x - case _ => super.boolean_and(lhs, rhs) - } - } - - override def boolean_or(lhs: Exp[Boolean], rhs: Exp[Boolean])(implicit pos: SourceContext) : Exp[Boolean] = { - (lhs, rhs) match { - case (Const(false), x) => x - case (x, Const(false)) => x - case (Const(true), _) => Const(true) - case (_, Const(true)) => Const(true) - case _ => super.boolean_or(lhs, rhs) - } - } } -trait ScalaGenBooleanOps extends ScalaGenBase { +trait ScalaGenBooleanOps extends ScalaGenBase with GenericNestedCodegen { val IR: BooleanOpsExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case BooleanNegate(b) => emitValDef(sym, src"!$b") - case BooleanAnd(lhs,rhs) => emitValDef(sym, src"$lhs && $rhs") - case BooleanOr(lhs,rhs) => emitValDef(sym, src"$lhs || $rhs") + case BooleanAnd(lhs,rhs) => + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + gen"""if ($lhs == true) { + |${nestedBlock(rhs)} + |$rhs + |} else false""" + } + emitValDef(sym, strWriter.toString) + case BooleanOr(lhs,rhs) => + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + gen"""if ($lhs == false) { + |${nestedBlock(rhs)} + |$rhs + |} else true""" + } + emitValDef(sym, strWriter.toString) case _ => super.emitNode(sym,rhs) } } -trait CLikeGenBooleanOps extends CLikeGenBase { +trait CLikeGenBooleanOps extends CLikeGenBase with GenericNestedCodegen { val IR: BooleanOpsExp import IR._ - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case BooleanNegate(b) => emitValDef(sym, src"!$b") - case BooleanAnd(lhs,rhs) => emitValDef(sym, src"$lhs && $rhs") - case BooleanOr(lhs,rhs) => emitValDef(sym, src"$lhs || $rhs") - case _ => super.emitNode(sym,rhs) + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case BooleanNegate(b) => emitValDef(sym, src"!$b") + case b@BooleanAnd(lhs,rhs) => { + emitValDef(b.c, quote(lhs)) + stream.println("if (" + quote(lhs) + ") {") + emitBlock(rhs) + stream.println(quote(b.c) + " = " + quote(getBlockResult(rhs)) + ";") + stream.println("}") + emitValDef(sym, quote(b.c)) + } + case b@BooleanOr(lhs,rhs) => { + emitValDef(b.c, quote(lhs)) + stream.println("if (" + quote(lhs) + " == false) {") + emitBlock(rhs) + stream.println(quote(b.c) + " = " + quote(getBlockResult(rhs)) + ";") + stream.println("}") + emitValDef(sym, quote(b.c)) + } + case _ => super.emitNode(sym,rhs) + } } } trait CudaGenBooleanOps extends CudaGenBase with CLikeGenBooleanOps trait OpenCLGenBooleanOps extends OpenCLGenBase with CLikeGenBooleanOps -trait CGenBooleanOps extends CGenBase with CLikeGenBooleanOps +trait CGenBooleanOps extends CGenBase with CLikeGenBooleanOps { + val IR: BooleanOpsExp + import IR._ + + override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { + case BooleanAnd(lhs,rhs) => { + LIRTraversal(rhs) + sym.atPhase(LIRLowering) { + reflectEffect(BooleanAnd(LIRLowering(lhs),LIRLowering(rhs))).asInstanceOf[Exp[A]] + } + } + case BooleanOr(lhs,rhs) => { + LIRTraversal(rhs) + sym.atPhase(LIRLowering) { + reflectEffect(BooleanOr(LIRLowering(lhs),LIRLowering(rhs))).asInstanceOf[Exp[A]] + } + } + case _ => super.lowerNode(sym,rhs) + } +} diff --git a/src/common/CastingOps.scala b/src/common/CastingOps.scala index 58d3edfe..61bf6c99 100644 --- a/src/common/CastingOps.scala +++ b/src/common/CastingOps.scala @@ -1,8 +1,8 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.util.OverloadHack +import scala.virtualization.lms.util.OverloadHack import scala.reflect.SourceContext trait CastingOps extends Variables with OverloadHack { @@ -18,21 +18,20 @@ trait CastingOps extends Variables with OverloadHack { } def rep_isinstanceof[A,B](lhs: Rep[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Rep[Boolean] - def rep_asinstanceof[A,B:Manifest](lhs: Rep[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Rep[B] + def rep_asinstanceof[A,B](lhs: Rep[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Rep[B] } -trait CastingOpsExp extends CastingOps with BaseExp with EffectExp { +trait CastingOpsExp extends CastingOps with BaseExp { this: ImplicitOps => case class RepIsInstanceOf[A,B](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B]) extends Def[Boolean] - case class RepAsInstanceOf[A,B:Manifest](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B]) extends Def[B] + case class RepAsInstanceOf[A,B](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B]) extends Def[B] def rep_isinstanceof[A,B](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) = RepIsInstanceOf(lhs,mA,mB) - def rep_asinstanceof[A,B:Manifest](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Exp[B] = toAtom(RepAsInstanceOf(lhs,mA,mB))(mB,pos) + def rep_asinstanceof[A,B](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Exp[B] = toAtom(RepAsInstanceOf(lhs,mA,mB))(mB,pos) override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case RepAsInstanceOf(lhs, mA, mB) => rep_asinstanceof(f(lhs),mA,mB)(mtype(mB),pos) - case Reflect(e@RepAsInstanceOf(lhs, mA, mB), u, es) => reflectMirrored(Reflect(RepAsInstanceOf(f(lhs),mA,mB)(mtype(mB)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case RepAsInstanceOf(lhs, mA, mB) => rep_asinstanceof(f(lhs), mA,mB) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] } @@ -55,7 +54,7 @@ trait CLikeGenCastingOps extends CLikeGenBase { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { //case RepIsInstanceOf(x,mA,mB) => //TODO: How? - case RepAsInstanceOf(x,mA,mB) => emitValDef(sym, "(%s) %s".format(remapWithRef(mB),quote(x))) + case RepAsInstanceOf(x,mA,mB) => emitValDef(sym, src"($mB) $x") case _ => super.emitNode(sym, rhs) } } diff --git a/src/common/Compile.scala b/src/common/Compile.scala index 879d8344..87ce734d 100644 --- a/src/common/Compile.scala +++ b/src/common/Compile.scala @@ -1,14 +1,15 @@ -package scala.lms +package scala.virtualization.lms package common import internal.ScalaCompile trait Compile extends Base { - def compile[A,B](f: Rep[A] => Rep[B])(implicit mA: Manifest[A], mB: Manifest[B]): A=>B + def compile1[A,B](f: Rep[A] => Rep[B])(implicit mA: Manifest[A], mB: Manifest[B]): A=>B + // Needed for backwards compatibility of tests after renaming compile to + // compile1 for a unified naming scheme + def compile[A,B](f: Rep[A] => Rep[B])(implicit mA: Manifest[A], mB: Manifest[B]) = compile1[A,B](f) } -trait CompileScala extends Compile with BaseExp with ScalaCompile { - -} +trait CompileScala extends Compile with BaseExp with ScalaCompile diff --git a/src/common/DSLBase.scala b/src/common/DSLBase.scala new file mode 100644 index 00000000..072f5468 --- /dev/null +++ b/src/common/DSLBase.scala @@ -0,0 +1,129 @@ +package scala.virtualization.lms +package common + +trait DSLBase extends BaseExp with UncheckedOps { + // keep track of top level functions + abstract class TopLevel(n: String) { + val name = n; + } + + val rec = new scala.collection.mutable.HashMap[String, TopLevel] + + case class TopLevel1 [A1, B](n: String, mA1: Manifest[A1], mB: Manifest[B], f: (Rep[A1]) => Rep[B]) extends TopLevel(n) + case class TopLevel2 [A1, A2, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mB: Manifest[B], f: (Rep[A1], Rep[A2]) => Rep[B]) extends TopLevel(n) + case class TopLevel3 [A1, A2, A3, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3]) => Rep[B]) extends TopLevel(n) + case class TopLevel4 [A1, A2, A3, A4, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4]) => Rep[B]) extends TopLevel(n) + case class TopLevel5 [A1, A2, A3, A4, A5, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5]) => Rep[B]) extends TopLevel(n) + case class TopLevel6 [A1, A2, A3, A4, A5, A6, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6]) => Rep[B]) extends TopLevel(n) + case class TopLevel7 [A1, A2, A3, A4, A5, A6, A7, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7]) => Rep[B]) extends TopLevel(n) + case class TopLevel8 [A1, A2, A3, A4, A5, A6, A7, A8, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8]) => Rep[B]) extends TopLevel(n) + case class TopLevel9 [A1, A2, A3, A4, A5, A6, A7, A8, A9, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9]) => Rep[B]) extends TopLevel(n) + case class TopLevel10 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10]) => Rep[B]) extends TopLevel(n) + case class TopLevel11 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11]) => Rep[B]) extends TopLevel(n) + case class TopLevel12 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mA12: Manifest[A12], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12]) => Rep[B]) extends TopLevel(n) + case class TopLevel13 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mA12: Manifest[A12], mA13: Manifest[A13], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13]) => Rep[B]) extends TopLevel(n) + case class TopLevel14 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mA12: Manifest[A12], mA13: Manifest[A13], mA14: Manifest[A14], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14]) => Rep[B]) extends TopLevel(n) + case class TopLevel15 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mA12: Manifest[A12], mA13: Manifest[A13], mA14: Manifest[A14], mA15: Manifest[A15], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15]) => Rep[B]) extends TopLevel(n) + case class TopLevel16 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mA12: Manifest[A12], mA13: Manifest[A13], mA14: Manifest[A14], mA15: Manifest[A15], mA16: Manifest[A16], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16]) => Rep[B]) extends TopLevel(n) + case class TopLevel17 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mA12: Manifest[A12], mA13: Manifest[A13], mA14: Manifest[A14], mA15: Manifest[A15], mA16: Manifest[A16], mA17: Manifest[A17], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16], Rep[A17]) => Rep[B]) extends TopLevel(n) + case class TopLevel18 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mA12: Manifest[A12], mA13: Manifest[A13], mA14: Manifest[A14], mA15: Manifest[A15], mA16: Manifest[A16], mA17: Manifest[A17], mA18: Manifest[A18], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16], Rep[A17], Rep[A18]) => Rep[B]) extends TopLevel(n) + case class TopLevel19 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, B](n: String, mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mA12: Manifest[A12], mA13: Manifest[A13], mA14: Manifest[A14], mA15: Manifest[A15], mA16: Manifest[A16], mA17: Manifest[A17], mA18: Manifest[A18], mA19: Manifest[A19], mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16], Rep[A17], Rep[A18], Rep[A19]) => Rep[B]) extends TopLevel(n) + + //case class TopLevel14_16 [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27, A28, A29, A30, B](n: String, (mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mA6: Manifest[A6], mA7: Manifest[A7], mA8: Manifest[A8], mA9: Manifest[A9], mA10: Manifest[A10], mA11: Manifest[A11], mA12: Manifest[A12], mA13: Manifest[A13], mA14: Manifest[A14]), (mA15: Manifest[A15], mA16: Manifest[A16], mA17: Manifest[A17], mA18: Manifest[A18], mA19: Manifest[A19], mA20: Manifest[A20], mA21: Manifest[A21], mA22: Manifest[A22], mA23: Manifest[A23], mA24: Manifest[A24], mA25: Manifest[A25], mA26: Manifest[A26], mA27: Manifest[A27], mA28: Manifest[A28], mA29: Manifest[A29], mA30: Manifest[A30]), mB: Manifest[B], f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14])(Rep[A15], Rep[A16], Rep[A17], Rep[A18], Rep[A19], Rep[A20], Rep[A21], Rep[A22], Rep[A23], Rep[A24], Rep[A25], Rep[A26], Rep[A27], Rep[A28], Rep[A29], Rep[A30]) => Rep[B]) extends TopLevel(n) + + def toplevel1[A1: Manifest, B: Manifest](name: String)(f: (Rep[A1]) => Rep[B]): (Rep[A1]) => Rep[B] = { + val g = (x1: Rep[A1]) => unchecked[B](name, "(", x1, ")") + rec.getOrElseUpdate(name, TopLevel1(name, manifest[A1], manifest[B], f)) + g + } + def toplevel2[A1: Manifest, A2: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2]) => Rep[B]): (Rep[A1], Rep[A2]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2]) => unchecked[B](name, "(", x1, ",", x2, ")") + rec.getOrElseUpdate(name, TopLevel2(name, manifest[A1], manifest[A2], manifest[B], f)) + g + } + def toplevel3[A1: Manifest, A2: Manifest, A3: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ")") + rec.getOrElseUpdate(name, TopLevel3(name, manifest[A1], manifest[A2], manifest[A3], manifest[B], f)) + g + } + def toplevel4[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ")") + rec.getOrElseUpdate(name, TopLevel4(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[B], f)) + g + } + def toplevel5[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ")") + rec.getOrElseUpdate(name, TopLevel5(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[B], f)) + g + } + def toplevel6[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ")") + rec.getOrElseUpdate(name, TopLevel6(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[B], f)) + g + } + def toplevel7[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ")") + rec.getOrElseUpdate(name, TopLevel7(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[B], f)) + g + } + def toplevel8[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ")") + rec.getOrElseUpdate(name, TopLevel8(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[B], f)) + g + } + def toplevel9[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ")") + rec.getOrElseUpdate(name, TopLevel9(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[B], f)) + g + } + def toplevel10[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ")") + rec.getOrElseUpdate(name, TopLevel10(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[B], f)) + g + } + def toplevel11[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, A11: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10], x11: Rep[A11]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ",", x11, ")") + rec.getOrElseUpdate(name, TopLevel11(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[A11], manifest[B], f)) + g + } + def toplevel12[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, A11: Manifest, A12: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10], x11: Rep[A11], x12: Rep[A12]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ",", x11, ",", x12, ")") + rec.getOrElseUpdate(name, TopLevel12(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[A11], manifest[A12], manifest[B], f)) + g + } + def toplevel13[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, A11: Manifest, A12: Manifest, A13: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10], x11: Rep[A11], x12: Rep[A12], x13: Rep[A13]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ",", x11, ",", x12, ",", x13, ")") + rec.getOrElseUpdate(name, TopLevel13(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[A11], manifest[A12], manifest[A13], manifest[B], f)) + g + } + def toplevel14[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, A11: Manifest, A12: Manifest, A13: Manifest, A14: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10], x11: Rep[A11], x12: Rep[A12], x13: Rep[A13], x14: Rep[A14]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ",", x11, ",", x12, ",", x13, ",", x14, ")") + rec.getOrElseUpdate(name, TopLevel14(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[A11], manifest[A12], manifest[A13], manifest[A14], manifest[B], f)) + g + } + def toplevel15[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, A11: Manifest, A12: Manifest, A13: Manifest, A14: Manifest, A15: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10], x11: Rep[A11], x12: Rep[A12], x13: Rep[A13], x14: Rep[A14], x15: Rep[A15]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ",", x11, ",", x12, ",", x13, ",", x14, ",", x15, ")") + rec.getOrElseUpdate(name, TopLevel15(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[A11], manifest[A12], manifest[A13], manifest[A14], manifest[A15], manifest[B], f)) + g + } + def toplevel16[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, A11: Manifest, A12: Manifest, A13: Manifest, A14: Manifest, A15: Manifest, A16: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10], x11: Rep[A11], x12: Rep[A12], x13: Rep[A13], x14: Rep[A14], x15: Rep[A15], x16: Rep[A16]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ",", x11, ",", x12, ",", x13, ",", x14, ",", x15, ",", x16, ")") + rec.getOrElseUpdate(name, TopLevel16(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[A11], manifest[A12], manifest[A13], manifest[A14], manifest[A15], manifest[A16], manifest[B], f)) + g + } + def toplevel17[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, A11: Manifest, A12: Manifest, A13: Manifest, A14: Manifest, A15: Manifest, A16: Manifest, A17: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16], Rep[A17]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16], Rep[A17]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10], x11: Rep[A11], x12: Rep[A12], x13: Rep[A13], x14: Rep[A14], x15: Rep[A15], x16: Rep[A16], x17: Rep[A17]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ",", x11, ",", x12, ",", x13, ",", x14, ",", x15, ",", x16, ",", x17, ")") + rec.getOrElseUpdate(name, TopLevel17(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[A11], manifest[A12], manifest[A13], manifest[A14], manifest[A15], manifest[A16], manifest[A17], manifest[B], f)) + g + } + def toplevel18[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, A11: Manifest, A12: Manifest, A13: Manifest, A14: Manifest, A15: Manifest, A16: Manifest, A17: Manifest, A18: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16], Rep[A17], Rep[A18]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16], Rep[A17], Rep[A18]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10], x11: Rep[A11], x12: Rep[A12], x13: Rep[A13], x14: Rep[A14], x15: Rep[A15], x16: Rep[A16], x17: Rep[A17], x18: Rep[A18]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ",", x11, ",", x12, ",", x13, ",", x14, ",", x15, ",", x16, ",", x17, ",", x18, ")") + rec.getOrElseUpdate(name, TopLevel18(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[A11], manifest[A12], manifest[A13], manifest[A14], manifest[A15], manifest[A16], manifest[A17], manifest[A18], manifest[B], f)) + g + } + def toplevel19[A1: Manifest, A2: Manifest, A3: Manifest, A4: Manifest, A5: Manifest, A6: Manifest, A7: Manifest, A8: Manifest, A9: Manifest, A10: Manifest, A11: Manifest, A12: Manifest, A13: Manifest, A14: Manifest, A15: Manifest, A16: Manifest, A17: Manifest, A18: Manifest, A19: Manifest, B: Manifest](name: String)(f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16], Rep[A17], Rep[A18], Rep[A19]) => Rep[B]): (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5], Rep[A6], Rep[A7], Rep[A8], Rep[A9], Rep[A10], Rep[A11], Rep[A12], Rep[A13], Rep[A14], Rep[A15], Rep[A16], Rep[A17], Rep[A18], Rep[A19]) => Rep[B] = { + val g = (x1: Rep[A1], x2: Rep[A2], x3: Rep[A3], x4: Rep[A4], x5: Rep[A5], x6: Rep[A6], x7: Rep[A7], x8: Rep[A8], x9: Rep[A9], x10: Rep[A10], x11: Rep[A11], x12: Rep[A12], x13: Rep[A13], x14: Rep[A14], x15: Rep[A15], x16: Rep[A16], x17: Rep[A17], x18: Rep[A18], x19: Rep[A19]) => unchecked[B](name, "(", x1, ",", x2, ",", x3, ",", x4, ",", x5, ",", x6, ",", x7, ",", x8, ",", x9, ",", x10, ",", x11, ",", x12, ",", x13, ",", x14, ",", x15, ",", x16, ",", x17, ",", x18, ",", x19, ")") + rec.getOrElseUpdate(name, TopLevel19(name, manifest[A1], manifest[A2], manifest[A3], manifest[A4], manifest[A5], manifest[A6], manifest[A7], manifest[A8], manifest[A9], manifest[A10], manifest[A11], manifest[A12], manifest[A13], manifest[A14], manifest[A15], manifest[A16], manifest[A17], manifest[A18], manifest[A19], manifest[B], f)) + g + } +} \ No newline at end of file diff --git a/src/common/DSLOps.scala b/src/common/DSLOps.scala index 254674cb..e60a74a0 100644 --- a/src/common/DSLOps.scala +++ b/src/common/DSLOps.scala @@ -1,9 +1,9 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException} +import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException} //TODO: is this used at all? should it be merge with DeliteOps? @@ -27,10 +27,15 @@ trait ScalaGenDSLOps extends ScalaGenEffect with BaseGenDSLOps { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case op: DSLOp[_] => val b = op.representation - gen"""val $sym = { - |${nestedBlock(b)} - |$b - |}""" + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + gen"""{ + |${nestedBlock(b)} + |$b + |}""" + } + emitValDef(sym, strWriter.toString) case _ => super.emitNode(sym, rhs) } diff --git a/src/common/DateOps.scala b/src/common/DateOps.scala new file mode 100644 index 00000000..0283656f --- /dev/null +++ b/src/common/DateOps.scala @@ -0,0 +1,89 @@ +package scala.virtualization.lms +package common + +import scala.virtualization.lms.common._ +import scala.virtualization.lms.internal.CNestedCodegen +import scala.reflect.SourceContext +import java.util.Date + +/** + * Lifter Classes for Date + */ +trait DateOps extends Base { + + class DateOpsCls(x: Rep[Date]) { + def getTime(): Rep[Long] = dtGetTime(x) + def getYear(): Rep[Long] = dtGetYear(x) + } + + implicit def date2DateOpsCls(x: Rep[Date]): DateOpsCls = new DateOpsCls(x) + def newDate(): Rep[Date] + def newDate(x: Rep[Long]): Rep[Date] + def dtGetTime(x: Rep[Date]): Rep[Long] + def dtGetYear(x: Rep[Date]): Rep[Long] + def getDateAsString(x: Rep[Long]): Rep[String] +} + +trait DateExp extends DateOps with BaseExp { + + case class DtGetTime(x: Exp[Date]) extends Def[Long] + case class DtGetYear(x: Exp[Date]) extends Def[Long] + case class NewDate(x: Exp[Long]) extends Def[Date] + case class GetDateAsString(x: Exp[Long]) extends Def[String] + + def newDate(): Exp[Date] = NewDate(null) + def newDate(x: Rep[Long]): Exp[Date] = NewDate(x) + def dtGetTime(x: Exp[Date]): Exp[Long] = DtGetTime(x) + def dtGetYear(x: Exp[Date]): Exp[Long] = DtGetYear(x) + def getDateAsString(x: Rep[Long]) = GetDateAsString(x) + + ////////////// + // mirroring + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case NewDate(x) => newDate(x) + case DtGetTime(x) => dtGetTime(f(x)) + case DtGetYear(x) => dtGetYear(f(x)) + case GetDateAsString(x) => getDateAsString(f(x)) + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] // why?? +} + +trait DateExpOpt extends DateExp { + override def dtGetTime(x: Exp[Date]): Exp[Long] = x match { + case Const(x) => unit(x.getTime) + case _ => super.dtGetTime(x) + } +} + +trait ScalaGenDate extends ScalaGenBase { + val IR: DateExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case NewDate(x) => emitValDef(sym, "new java.util.Date(" + { if (x!=null) quote(x) } + ")") + case DtGetTime(x) => emitValDef(sym, quote(x) + ".getTime()"); + case DtGetYear(x) => emitValDef(sym, quote(x) + ".getYear() + 1900"); + case GetDateAsString(x) => emitValDef(sym, "new java.util.Date(" + { if (x!=null) quote(x) } + ").toString") + case _ => super.emitNode(sym, rhs) + } +} + +trait CGenDate extends CGenBase with CNestedCodegen { + val IR: DateExp + import IR._ + + override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { + case NewDate(x) => sym.atPhase(LIRLowering) { LIRLowering(x).asInstanceOf[Exp[T]] } + case _ => super.lowerNode(sym,rhs) + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case NewDate(x) => stream.println("long " + quote(sym) + " = " + quote(x) + "; // date") + case DtGetYear(x) => + emitValDef(sym, quote(x) + "/10000") + case gd@GetDateAsString(x) => + emitValDef(sym, getMemoryAllocString("9", "char")) + stream.println("snprintf(" + quote(sym) + ", 9, \"%lu\", " + quote(x) + ");") + case _ => super.emitNode(sym, rhs) + } +} diff --git a/src/common/DynamicRecord.scala b/src/common/DynamicRecord.scala new file mode 100644 index 00000000..83adbee6 --- /dev/null +++ b/src/common/DynamicRecord.scala @@ -0,0 +1,397 @@ +/*package scala.virtualization.lms +package common + +import java.io._ +import reflect.ClassManifest +import scala.collection.mutable.HashMap +import scala.virtualization.lms.internal._ +import scala.virtualization.lms.util._ +import scala.reflect.SourceContext + +object DynamicRecordsMap extends Serializable { + // We want to be able to call the scala compiler without generating code + var mapInitialized: Boolean = false; + var dataPath: String = null; + var registeredDynamicRecords: HashMap[String, List[(String, Class[_])]] = null + + // Helpers for printing information + def getNames(recname: String) = { + registeredDynamicRecords(recname).map(x => x._1).mkString("|") + } + + def initialize(rootFolder: String) = { + if (mapInitialized) + throw new RuntimeException("DynamicRecordsMap already initialized"); + mapInitialized = true + dataPath = rootFolder + registeredDynamicRecords = new HashMap[String, List[(String, Class[_])]] + } + +} + +object DynamicRecordEffectsMap { + val effectsMap = new collection.mutable.HashMap[(String,String), Any]() +} + +trait DynamicRecord extends Base with Serializable with VariablesExp { + + object NewDynamicRecord { + def apply[T:Manifest](n: String, reuse: Boolean = false) = newDynamicRecord(n, reuse) + } + + class DynamicRecordOps(x: Rep[DynamicRecord]) { + def get(field: Rep[Any]) = dynamicRecordGet(x, field) + def set(field: Rep[Any], value: Rep[Any]) = dynamicRecordSet(x, field, value) + def foreach(f: Rep[DynamicRecord] => Rep[Unit]) = dynamicRecordForEach(x,f) + } + implicit def varDynamicType2dynamicRecordOps(x: Var[DynamicRecord]) = new DynamicRecordOps(readVar(x)) + implicit def varDynamicType2dynamicRecord(x: Var[DynamicRecord]) = readVar(x) + implicit def dynamicRecord2dynamicRecordOps(x: Rep[DynamicRecord]) = new DynamicRecordOps(x) + implicit def dynamicRecord2RepdynamicRecordOps(x: DynamicRecord) = new DynamicRecordOps(unit(x)) + + def newDynamicRecord(name: String, reuse: Boolean = false): Rep[DynamicRecord] + def dynamicRecordGet(x: Rep[DynamicRecord], field: Rep[Any]): Rep[Any] + def dynamicRecordSet(x: Rep[DynamicRecord], field: Rep[Any], value: Rep[Any]): Rep[Unit] + def dynamicRecordForEach(x: Rep[DynamicRecord], f: Rep[DynamicRecord] => Rep[Unit]): Rep[Unit] + val NullDynamicRecord = unit(null).asInstanceOf[Rep[DynamicRecord]] +} + +trait DynamicRecordExp extends DynamicRecord with BaseExp with EffectExp { + case class NewDynamicRecordObj(n: String) extends Def[DynamicRecord] + case class DynamicRecordGet(x: Rep[DynamicRecord], field: Rep[Any]) extends Def[Any] + case class DynamicRecordSet(x: Rep[DynamicRecord], field: Rep[Any], value: Rep[Any]) extends Def[Unit] + case class DynamicRecordForEach(l: Rep[DynamicRecord], x: Sym[DynamicRecord], block: Block[Unit]) extends Def[Unit] + + def newDynamicRecord(name: String, reuse: Boolean = false) = + if (reuse) NewDynamicRecordObj(name) else reflectMutable(NewDynamicRecordObj(name)) + + def dynamicRecordGet(x: Rep[DynamicRecord], field: Rep[Any]) = { + val key = (x.toString, field.toString) + DynamicRecordEffectsMap.effectsMap.get(key) match { + case Some(e) => e.asInstanceOf[Sym[_]] + case None => { + val rE = reflectWrite(x)(DynamicRecordGet(x, field)) + DynamicRecordEffectsMap.effectsMap += key -> rE + rE + } + } + } + + def dynamicRecordSet(x: Rep[DynamicRecord], field: Rep[Any], value: Rep[Any]) = { + val key = (x.toString, field.toString) + // Forces new gets that follow to re-read the entry. + val e = DynamicRecordEffectsMap.effectsMap.remove(key) + reflectEffect(DynamicRecordSet(x,field,value)) + } + + def dynamicRecordForEach(x: Rep[DynamicRecord], f: Exp[DynamicRecord] => Exp[Unit])={ + val a = fresh[DynamicRecord] + val b = reifyEffects(f(a)) + reflectEffect(DynamicRecordForEach(x, a, b), summarizeEffects(b).star) + } + + override def syms(e: Any): List[Sym[Any]] = e match { + case DynamicRecordForEach(a, x, body) => syms(a):::syms(body) + case _ => super.syms(e) + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case DynamicRecordForEach(a, x, body) => x :: effectSyms(body) + case _ => super.boundSyms(e) + } + + override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case DynamicRecordForEach(a, x, body) => freqNormal(a):::freqHot(body) + case _ => super.symsFreq(e) + } +} + +trait ScalaGenDynamicRecord extends ScalaGenBase with GenericNestedCodegen { + val IR: DynamicRecordExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case NewDynamicRecordObj(x) => emitValDef(sym, "new " + x + "()") + case DynamicRecordGet(x, field) => emitValDef(sym, quote(x) + "." + quote(field).replaceAll("\"","")) + case DynamicRecordSet(x, field, value) => + stream.println(quote(x) + "." + quote(field).replaceAll("\"","") + " = " + quote(value)) + case DynamicRecordForEach(x, init, block) => + stream.println("val x" + sym.toString.replace("Sym(","").replace(")","") + " = {") + stream.println("\tvar " + quote(init) + "=" + quote(x)) + stream.println("\twhile (" + quote(init) + " != null) {") + emitBlock(block) + stream.println("\t\t" + quote(init) + "=" + quote(init) + ".next") + stream.println("\t}") + stream.println("}") + + case _ => super.emitNode(sym, rhs) + } + } + + override def emitDataStructures(out: PrintWriter) { + DynamicRecordsMap.registeredDynamicRecords.foreach( + rec => writeRecord(out, rec._1, rec._2) + ) + //DynamicRecordsMap.registeredDynamicRecords.clear + } + + def writeRecord(out: PrintWriter, className: String, attrs: List[(String, Class[_])]) { + out.print("class " + className + " extends Serializable" +" {\n") + for ((p1,p2) <- attrs) { + val str = { + if (ClassManifest.fromClass(p2) == classManifest[Array[Byte]]) + "Array[Byte]" + else + p2.toString.replaceAll("class ","").replaceAll("int", "scala.Int").replaceAll("double","scala.Double").replaceAll("char", "Char").replaceAll("long", "scala.Long") + } + out.print("private[this] final var _" + p1 + ": " + str + " = null.asInstanceOf[" + str + "];\n") + out.println("@inline final def " + p1 + " = _" + p1) + out.println("@inline final def " + p1 + "_=(x:" + str + ") = _" + p1 + " = x ") + } + out.println("@transient var next: " + className + " = null ") + // Custom toString function + out.print("override def toString() = {\n\"\"+") + out.print( (for ((p1,p2) <- attrs) yield + if (ClassManifest.fromClass(p2) == classManifest[Array[Byte]]) "new String(" + p1 + ")" + else if (p1.contains("DATE")) "{new java.util.Date(" + p1 + ")}" + else p1 + ).mkString("+\"|\"+") ) + out.print("}\n"); + // Custom serialization/deserialization routines + out.println("@throws(classOf[java.io.IOException])") + out.println("private def writeObject(out: java.io.ObjectOutputStream): Unit = {") + for ((p1,p2) <- attrs) { + ClassManifest.fromClass(p2) match { + case m if m <:< classManifest[scala.Int] => out.println("out.writeInt(" + p1 + ")") + case m if m <:< classManifest[scala.Double] => out.println("out.writeDouble(" + p1 + ")") + case m if m <:< classManifest[scala.Char] => out.println("out.writeChar(" + p1 + ")") + case m if m <:< classManifest[scala.Long] => out.println("out.writeLong(" + p1 + ")") + case m if m <:< classManifest[java.lang.String] => out.println("out.writeUTF(" + p1 + ")") + case m if m == classManifest[Array[Byte]] => { + out.println("out.writeInt(" + p1 +".length)") + out.println("out.write(" + p1 + ")") + } + case _ => out.println("out.writeObject(" + p1 + ")") + } + } + out.println("}") + out.println("@throws(classOf[java.io.IOException])") + out.println("private def readObject(in: java.io.ObjectInputStream): Unit = {") + out.println("var length: Int = 0"); + for ((p1,p2) <- attrs) { + ClassManifest.fromClass(p2) match { + case m if m <:< classManifest[scala.Int] => out.println(p1 + " = in.readInt()") + case m if m <:< classManifest[scala.Double] => out.println(p1 + " = in.readDouble()") + case m if m <:< classManifest[scala.Char] => out.println(p1 + " = in.readChar()") + case m if m <:< classManifest[scala.Long] => out.println(p1 + " = in.readLong()") + case m if m <:< classManifest[java.lang.String] => out.println(p1 + " = in.readUTF()") + case m if m == classManifest[Array[Byte]] => { + out.println(p1 + " = new Array[Byte](in.readInt())") + out.println("in.read(" + p1 + ", 0, " + p1 + ".length)") + } + case _ => out.println(p1 + " = in.readObject().asInstanceOf[" + p2.toString.replaceAll("class ","") + "]") + } + } + out.println("}") + out.println("}") // End of class + out.flush + } + + def newDynamicRecordType(name: String, attrs: List[(String, Class[_])]) { + if (DynamicRecordsMap.registeredDynamicRecords.get(name) == None) { + // Register for first use + DynamicRecordsMap.registeredDynamicRecords += (name -> attrs) + // Write to file (for persistence) + val filename = DynamicRecordsMap.dataPath + name + ".scala" + val writer = new PrintWriter(new java.io.File(filename)) + writeRecord(writer, name, attrs) + writer.close() + } + } + +} + +trait CGenDynamicRecord extends CGenBase with GenericNestedCodegen { + val IR: DynamicRecordExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case NewDynamicRecordObj(x) => allocStruct(sym, x, stream) + case DynamicRecordGet(x, field) => emitValDef(sym, quote(x) + "->" + quote(field).replaceAll("\"","")) + case DynamicRecordSet(x, field, value) => + stream.println(quote(x) + "->" + quote(field).replaceAll("\"","") + " = " + quote(value) + ";") + case DynamicRecordForEach(x, init, block) => + stream.println("val x" + sym.toString.replace("Sym(","").replace(")","") + " = {") + stream.println("\tvar " + quote(init) + "=" + quote(x)) + stream.println("\twhile (" + quote(init) + " != null) {") + emitBlock(block) + stream.println("\t\t" + quote(init) + "=" + quote(init) + ".next") + stream.println("\t}") + stream.println("}") + case _ => super.emitNode(sym, rhs) + } + } + + override def emitDataStructures(out: PrintWriter) { + DynamicRecordsMap.registeredDynamicRecords.foreach( + rec => writeRecord(out, rec._1, rec._2) + ) + //DynamicRecordsMap.registeredDynamicRecords.clear + } + + def writeRecord(out: PrintWriter, className: String, attrs: List[(String, Class[_])]) { + out.print("struct " + className + " {\n") + for ((p1,p2) <- attrs) out.print(remapInternal(scala.reflect.ClassManifestFactory.fromClass(p2).toString) + " " + p1 + ";\n") + out.println("struct " + className + "* next;") + out.print("};\n") + out.flush + } + + def newDynamicRecordType(name: String, attrs: List[(String, Class[_])]) { + if (DynamicRecordsMap.registeredDynamicRecords.get(name) == None) { + // Register for first use + DynamicRecordsMap.registeredDynamicRecords += (name -> attrs) + val filename = DynamicRecordsMap.dataPath + name + ".c" + val writer = new PrintWriter(new java.io.File(filename)) + writeRecord(writer, name, attrs) + } + } +} + +// HASHMAP +trait DynamicRecordHashMap extends Base with HashMapOps with Variables { + implicit def dRecHashMapToRepHashMapOps[K:Manifest,V:Manifest](m: HashMap[K,V]) = new dynamicRecordHashMapOpsCls[K,V](unit(m)) + implicit def dRecrepHashMapToHashMapOps[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) = new dynamicRecordHashMapOpsCls[K,V](m) + implicit def dRecvarrepHashMapToHashMapOps[K:Manifest,V:Manifest](m: Var[HashMap[K,V]]) = new dynamicRecordHashMapOpsCls[K,V](readVar(m)) + + class dynamicRecordHashMapOpsCls[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) { + def apply(k: Rep[K])(implicit pos: SourceContext) = hashmap_apply(m, k) + def size(implicit pos: SourceContext) = hashmap_size(m) + def removeHead(implicit pos:SourceContext) = hashmap_removehead(m) + def getOrElseUpdate(k: Rep[K], v: => Rep[V], h: Rep[DynamicRecord] => Rep[Int] = null, e: (Rep[DynamicRecord],Rep[DynamicRecord])=>Rep[Boolean]=null)(implicit pos: SourceContext) = hashmap_getorelseupdate[K,V](m,k,v,h,e) + def mkString(delimiter: Rep[String]) = hashmap_mkString(m, delimiter) + } + + override def hashmap_new[K:Manifest,V:Manifest](specializedKey: String = "", specializedValue: String = "")(implicit pos: SourceContext) : Rep[HashMap[K,V]] + override def hashmap_apply[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K])(implicit pos: SourceContext): Rep[V] + override def hashmap_size[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Int] + override def hashmap_removehead[K: Manifest, V: Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[(K,V)] + def hashmap_getorelseupdate[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: => Rep[V], h: Rep[DynamicRecord] => Rep[Int] = null, e: (Rep[DynamicRecord],Rep[DynamicRecord])=>Rep[Boolean] = null)(implicit pos: SourceContext): Rep[V] + override def hashmap_mkString[K: Manifest, V: Manifest](m: Rep[HashMap[K,V]], v: Rep[String])(implicit pos: SourceContext): Rep[String] +} + +trait DynamicRecordHashMapExp extends DynamicRecordHashMap with EffectExp with HashMapOpsExp with DynamicRecordExp { + abstract class DynamicRecordHashMapDef[K:Manifest,V:Manifest,R:Manifest] extends Def[R] { + val mK = manifest[K] + val mV = manifest[V] + } + case class DynamicRecordHashMapNew[K:Manifest,V:Manifest](specializedKey: String = "", specializedValue: String ="") extends DynamicRecordHashMapDef[K,V,HashMap[K,V]] + case class DynamicRecordHashMapApply[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K]) extends DynamicRecordHashMapDef[K,V,V] + case class DynamicRecordHashMapSize[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends DynamicRecordHashMapDef[K,V,Int] + case class DynamicRecordHashMapRemoveHead[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends DynamicRecordHashMapDef[K,V,(K,V)] + case class DynamicRecordHashMapGetOrElseUpdate[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], v: Block[V], h: Block[Int], e: Block[Boolean], d: Sym[DynamicRecord]) extends DynamicRecordHashMapDef[K,V,V] + case class DynamicRecordHashMapMkString[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], v:Rep[String]) extends DynamicRecordHashMapDef[K,V,String] + + override def hashmap_new[K:Manifest,V:Manifest](specializedKey: String = "", specializedValue: String = "")(implicit pos: SourceContext) = reflectMutable(DynamicRecordHashMapNew[K,V](specializedKey, specializedValue)) + override def hashmap_apply[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K])(implicit pos: SourceContext) = DynamicRecordHashMapApply(m,k) + override def hashmap_size[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = DynamicRecordHashMapSize(m) + override def hashmap_removehead[K: Manifest, V: Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = reflectWrite(m)(DynamicRecordHashMapRemoveHead(m)) + def hashmap_getorelseupdate[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: => Exp[V], h: Exp[DynamicRecord] => Exp[Int] = null, e: (Exp[DynamicRecord],Exp[DynamicRecord])=>Exp[Boolean] = null)(implicit pos: SourceContext) = { + val b = reifyEffects(v) + val f = reifyEffects(h(k.asInstanceOf[Rep[DynamicRecord]])) + val ff = fresh[DynamicRecord] + val g = reifyEffects(e(k.asInstanceOf[Rep[DynamicRecord]],ff)) + reflectWrite(m)(DynamicRecordHashMapGetOrElseUpdate(m,k,b,f,g,ff)) + } + override def hashmap_mkString[K: Manifest, V: Manifest](m: Rep[HashMap[K,V]], v: Rep[String])(implicit pos: SourceContext) = reflectEffect(DynamicRecordHashMapMkString(m, v)) + + //override def syms(p: Any): List[Sym[Any]] = p match { + // case HashMapGetOrElseUpdate(m, k, v,h,e) => syms(m):::syms(v) + // case _ => super.syms(p) + //} + + override def boundSyms(p: Any): List[Sym[Any]] = p match { + case DynamicRecordHashMapGetOrElseUpdate(m, k, v,h,e,d) => effectSyms(h) ::: effectSyms(v) ::: effectSyms(e) + case _ => super.boundSyms(p) + } + + //override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + // case HashMapGetOrElseUpdate(m, k, v,h,e) => freqNormal(m) ::: freqHot(v) + // case _ => super.symsFreq(e) + //} +} + +trait ScalaGenDynamicRecordHashMap extends ScalaGenBase with GenericNestedCodegen with ScalaGenEffect { + val IR: DynamicRecordHashMapExp + import IR._ + + def quoteSizeSymbol(m: Exp[_]): String = { + val sizeSymbol = findInitSymbol(m) + "__" + quote(sizeSymbol) + "Size" + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case m@DynamicRecordHashMapNew(spkey, spvalue) => { + val key = if (spkey != "") spkey else remap(m.mK) + val value = if (spvalue != "") spvalue else remap(m.mV) + stream.println("var " + quote(sym) + " = new Array[" + value + "](16)") + stream.println("var __" + quote(sym) + "Size = 0") + } + case DynamicRecordHashMapSize(m) => emitValDef(sym, quoteSizeSymbol(m)) + case DynamicRecordHashMapRemoveHead(m) => { + stream.println("val " + quote(sym) + "= {") + stream.println("var __idx = 0") + stream.println("var __elem = " + quote(m) + "(__idx)") + stream.println("while (__elem == null && __idx < " + quote(m) + ".length) {") + stream.println("__idx = __idx + 1") + stream.println("__elem = " + quote(m) + "(__idx)") + stream.println("}") + stream.println(quote(m) + "(__idx) = __elem.next") + stream.println(quoteSizeSymbol(m) + " -= 1") + stream.println("(__elem, __elem)") + stream.println("}") + } + case DynamicRecordHashMapGetOrElseUpdate(m,k,v,h,e,d) => { + stream.println("val ones = " + quote(m) + ".length - 1") + stream.println("var bc = ones") + stream.println("bc = bc - ((bc >>> 1) & 0x55555555);") + stream.println("bc = (bc & 0x33333333) + ((bc >>> 2) & 0x33333333);") + stream.println("bc = (bc + (bc >>> 4)) & 0x0f0f0f0f;") + stream.println("bc = bc + (bc >>> 8);") + stream.println("bc = bc + (bc >>> 16);") + stream.println("bc = bc & 0x3f;") + emitBlock(h) + stream.println("var hc = " + quote(getBlockResult(h)) + " * 0x9e3775cd") + stream.println("hc = ((hc >>> 24) ) |") + stream.println(" ((hc >> 8) & 0xFF00) |") + stream.println(" ((hc << 8) & 0xFF0000) |") + stream.println(" ((hc << 24));") + stream.println("hc = hc * 0x9e3775cd") + stream.println("val rotation = bc % 32") + stream.println("val improved = (hc >>> rotation) | (hc << (32 - rotation))") + stream.println("val h = (improved >> (32 - bc)) & ones") + stream.println("var e = " + quote(m) + "(h)") + stream.println("while (e != null && !{") + val savedStream = stream + val newSource = new StringWriter() + stream = new PrintWriter(newSource) + emitBlock(e) + stream = savedStream + val outStream = newSource.toString.replaceAll(quote(d), "e") + stream.println(outStream) + emitBlockResult(e) + stream.println("}) e = e.next") + stream.println("var " + quote(sym) + " = e") + stream.println("if (e eq null) {") + emitBlock(v) + stream.println(quote(sym) + " = " + quote(getBlockResult(v))) + stream.println(quote(sym) + ".next = " + quote(m) + "(h)") + stream.println(quote(m) + "(h) = " + quote(sym)) + stream.println(quoteSizeSymbol(m) + " = " + quoteSizeSymbol(m) + " + 1") + stream.println("}") + } + case _ => super.emitNode(sym, rhs) + } +}*/ diff --git a/src/common/Equal.scala b/src/common/Equal.scala index 15b2407f..0a90d250 100644 --- a/src/common/Equal.scala +++ b/src/common/Equal.scala @@ -1,9 +1,10 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.util.OverloadHack +import scala.virtualization.lms.util.OverloadHack import scala.reflect.SourceContext +import scala.virtualization.lms.internal.CNestedCodegen trait LiftEquals extends Base { this: Equal => @@ -63,7 +64,7 @@ trait EqualExpBridge extends BaseExp { trait EqualExp extends Equal with EqualExpBridge with VariablesExp -trait EqualExpBridgeOpt extends EqualExpBridge { +trait EqualExpBridgeOpt extends EqualExp { override def equals[A:Manifest,B:Manifest](a: Rep[A], b: Rep[B])(implicit pos: SourceContext): Rep[Boolean] = if (a == b) Const(true) else (a,b) match { case (Const(a),Const(b)) => Const(a == b) case _ => super.equals(a,b) @@ -79,26 +80,41 @@ trait EqualExpOpt extends EqualExp with EqualExpBridgeOpt trait ScalaGenEqual extends ScalaGenBase { - val IR: EqualExpBridge + val IR: EqualExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Equal(a,b) => emitValDef(sym, src"$a == $b") - case NotEqual(a,b) => emitValDef(sym, src"$a != $b") + case Equal(a,b) => + if (a.tp == manifest[Array[Byte]] || b.tp == manifest[Array[Byte]]) + emitValDef(sym, src"java.util.Arrays.equals($a,$b)") + else emitValDef(sym, src"$a == $b") + case NotEqual(a,b) => + if (a.tp == manifest[Array[Byte]] || b.tp == manifest[Array[Byte]]) + emitValDef(sym, src"!java.util.Arrays.equals($a,$b)") + else emitValDef(sym, src"$a != $b") case _ => super.emitNode(sym, rhs) } } trait CLikeGenEqual extends CLikeGenBase { - val IR: EqualExpBridge + val IR: EqualExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { case Equal(a,b) => - emitValDef(sym, src"$a == $b") + if (b.tp == manifest[Array[Byte]] || b.tp == manifest[String]) + // Hm... is this generic enough? it implicitly introduces a "lowering" for accessing + // the array field of the implicitly lowered array. + // TR: disabled! + //emitValDef(sym, "strcmp(" + quote(a) + "->array," + quote(b) + ") == 0;") + emitValDef(sym, "tpch_strcmp(" + quote(a) + "," + quote(b) + ") == 0;") + else emitValDef(sym, src"$a == $b") case NotEqual(a,b) => - emitValDef(sym, src"$a != $b") + if (b.tp == manifest[Array[Byte]] || b.tp == manifest[String]) + //emitValDef(sym, "strcmp(" + quote(a) + "->array," + quote(b) + ") != 0;") + emitValDef(sym, "tpch_strcmp(" + quote(a) + "," + quote(b) + ") != 0;") + else emitValDef(sym, src"$a != $b") case _ => super.emitNode(sym, rhs) } } @@ -106,22 +122,14 @@ trait CLikeGenEqual extends CLikeGenBase { trait CudaGenEqual extends CudaGenBase with CLikeGenEqual trait OpenCLGenEqual extends OpenCLGenBase with CLikeGenEqual - -trait CGenEqual extends CGenBase with CLikeGenEqual { - val IR: EqualExpBridge +trait CGenEqual extends CGenBase with CLikeGenEqual with CNestedCodegen { + val IR: EqualExp import IR._ - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { - rhs match { - case Equal(a,b) if(remap(a.tp) == "string" && remap(b.tp) == "string") => - emitValDef(sym, quote(a) + ".compare(" + quote(b) + ") == 0") - case Equal(a,b) if (!isPrimitiveType(a.tp) && !isPrimitiveType(b.tp) && (remap(a.tp) == remap(b.tp))) => - emitValDef(sym, quote(a) + "->equals(" + quote(b) + ")") - case NotEqual(a,b) if(remap(a.tp) == "string" && remap(b.tp) == "string") => - emitValDef(sym, quote(a) + ".compare(" + quote(b) + ") != 0") - case NotEqual(a,b) if (!isPrimitiveType(a.tp) && !isPrimitiveType(b.tp) && (remap(a.tp) == remap(b.tp))) => - emitValDef(sym, "!" + quote(a) + "->equals(" + quote(b) + ")") - case _ => super.emitNode(sym, rhs) - } + override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { + case Equal(lhs,rhs) => sym.atPhase(LIRLowering) { + reflectEffect(Equal(LIRLowering(lhs),LIRLowering(rhs))).asInstanceOf[Exp[A]] + } + case _ => super.lowerNode(sym,rhs) } } diff --git a/src/common/ExceptionOps.scala b/src/common/ExceptionOps.scala index f67e0231..e4f094d3 100644 --- a/src/common/ExceptionOps.scala +++ b/src/common/ExceptionOps.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter @@ -20,7 +20,7 @@ trait ExceptionOpsExp extends ExceptionOps with EffectExp { def throw_exception(m: Exp[String]) = reflectEffect(ThrowException(m), Global()) override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case Reflect(ThrowException(s), u, es) => reflectMirrored(Reflect(ThrowException(f(s)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(ThrowException(s), u, es) => reflectMirrored(Reflect(ThrowException(f(s)), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] } @@ -35,29 +35,3 @@ trait ScalaGenExceptionOps extends ScalaGenBase { } } -trait CLikeGenExceptionOps extends CLikeGenBase { - val IR: ExceptionOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ThrowException(m) => - stream.println("printf(" + quote(m) + ".c_str());") - stream.println("assert(false);") - case _ => super.emitNode(sym, rhs) - } -} - -trait CGenExceptionOps extends CGenBase with CLikeGenExceptionOps -trait CudaGenExceptionOps extends CudaGenBase with CLikeGenExceptionOps { - val IR: ExceptionOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ThrowException(m) => - stream.println("printf(" + quote(m) + ");") - stream.println("assert(false);") - case _ => super.emitNode(sym, rhs) - } -} -//OpenCL does not support printf within a kernel -//trait OpenCLGenExceptionOps extends OpenCLGenBase with CLikeGenExceptionOps diff --git a/src/common/ExportGraph.scala b/src/common/ExportGraph.scala index f82516dc..92eef6c1 100644 --- a/src/common/ExportGraph.scala +++ b/src/common/ExportGraph.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import internal.GraphVizExport diff --git a/src/common/ForwardTransformer.scala b/src/common/ForwardTransformer.scala index 3485de86..2d473ac1 100644 --- a/src/common/ForwardTransformer.scala +++ b/src/common/ForwardTransformer.scala @@ -1,11 +1,12 @@ -package scala.lms +package scala.virtualization.lms package common import scala.collection.{immutable,mutable} import scala.reflect.SourceContext +import scala.virtualization.lms.internal.{Effects, FatTransforming, AbstractSubstTransformer, FatBlockTraversal} trait ForwardTransformer extends internal.AbstractSubstTransformer with internal.FatBlockTraversal { self => - val IR: BaseFatExp with EffectExp //LoopsFatExp with IfThenElseFatExp + val IR: FatTransforming with Effects //LoopsFatExp with IfThenElseFatExp import IR._ def transformBlock[A:Manifest](block: Block[A]): Block[A] = { @@ -31,7 +32,8 @@ trait ForwardTransformer extends internal.AbstractSubstTransformer with internal // // but we'd rather have x15 = x9 + x14 override def apply[A](x: Exp[A]): Exp[A] = subst.get(x) match { - case Some(y) => y.asInstanceOf[Exp[A]] case _ => x + case Some(y) => y.asInstanceOf[Exp[A]] + case _ => x } override def reflectBlock[A](block: Block[A]): Exp[A] = { @@ -134,7 +136,6 @@ trait RecursiveTransformer extends ForwardTransformer { self => trait WorklistTransformer extends ForwardTransformer { // need backward version, too? - val IR: LoopsFatExp with IfThenElseFatExp import IR._ var curSubst: Map[Sym[Any],() => Exp[Any]] = Map.empty var nextSubst: Map[Sym[Any],() => Exp[Any]] = Map.empty @@ -168,5 +169,4 @@ trait WorklistTransformer extends ForwardTransformer { // need backward version, super.transformStm(stm) } } - } diff --git a/src/common/FractionalOps.scala b/src/common/FractionalOps.scala index e7ea08f3..96c1bef5 100644 --- a/src/common/FractionalOps.scala +++ b/src/common/FractionalOps.scala @@ -1,8 +1,9 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter import scala.reflect.SourceContext +import scala.virtualization.lms.internal.GenericNestedCodegen trait FractionalOps extends ImplicitOps { def infix_/[A,T](lhs: Rep[T], rhs: Rep[A])(implicit c: A => T, f: Fractional[T], mA: Manifest[A], mT: Manifest[T], pos: SourceContext) = fractional_divide(lhs,implicit_convert[A,T](rhs)) @@ -10,17 +11,21 @@ trait FractionalOps extends ImplicitOps { def fractional_divide[T:Fractional:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] } -trait FractionalOpsExp extends FractionalOps with ImplicitOpsExp with EffectExp { +trait FractionalOpsExp extends FractionalOps with ImplicitOpsExp { - case class FractionalDivide[T](lhs: Exp[T], rhs: Exp[T])(implicit val f: Fractional[T], val mT: Manifest[T]) extends Def[T] + case class FractionalDivide[T:Fractional:Manifest](lhs: Exp[T], rhs: Exp[T]) extends Def[T] { + val mT = manifest[T] + val fr = implicitly[Fractional[T]] + } def fractional_divide[T:Fractional:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext) : Rep[T] = FractionalDivide(lhs, rhs) - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case e@FractionalDivide(a,b) => fractional_divide(f(a),f(b))(e.f.asInstanceOf[Fractional[A]],mtype(e.mT),pos) - case Reflect(e@FractionalDivide(a,b), u, es) => reflectMirrored(Reflect(FractionalDivide(f(a),f(b))(e.f.asInstanceOf[Fractional[A]],mtype(e.mT)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case _ => super.mirror(e,f) - }).asInstanceOf[Exp[A]] + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { + e match { + case fd@FractionalDivide(lhs, rhs) => FractionalDivide(f(lhs),f(rhs))(fd.fr.asInstanceOf[Fractional[A]],manifest[A]) + case _ => super.mirror(e,f) + } + } } trait ScalaGenFractionalOps extends ScalaGenBase { @@ -48,4 +53,11 @@ trait CLikeGenFractionalOps extends CLikeGenBase { trait CudaGenFractionalOps extends CudaGenBase with CLikeGenFractionalOps trait OpenCLGenFractionalOps extends OpenCLGenBase with CLikeGenFractionalOps -trait CGenFractionalOps extends CGenBase with CLikeGenFractionalOps +trait CGenFractionalOps extends CGenBase with CLikeGenFractionalOps with GenericNestedCodegen { + val IR: FractionalOpsExp + import IR._ + override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { + case fd@FractionalDivide(a,b) => fractional_divide(LIRLowering(a), LIRLowering(b))(fd.fr.asInstanceOf[Fractional[A]],manifest[A],implicitly[SourceContext]) + case _ => super.lowerNode(sym,rhs) + } +} diff --git a/src/common/FunctionBlocks.scala b/src/common/FunctionBlocks.scala index 98cf0855..93159e6a 100644 --- a/src/common/FunctionBlocks.scala +++ b/src/common/FunctionBlocks.scala @@ -1,10 +1,10 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.lms.internal.{Blocks, Effects, AbstractTransformer} -import scala.lms.util.OverloadHack +import scala.virtualization.lms.internal.{Blocks, Effects, AbstractTransformer} +import scala.virtualization.lms.util.OverloadHack /* * This trait allows functions to be stored as case class parameters in a way that works correctly diff --git a/src/common/Functions.scala b/src/common/Functions.scala index f956571d..d309ca15 100644 --- a/src/common/Functions.scala +++ b/src/common/Functions.scala @@ -1,15 +1,15 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException} -import scala.lms.util.ClosureCompare +import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException, CNestedCodegen} +import scala.virtualization.lms.util.ClosureCompare import scala.reflect.SourceContext trait Functions extends Base { - + def doLambda[A:Manifest,B:Manifest](fun: Rep[A] => Rep[B])(implicit pos: SourceContext): Rep[A => B] implicit def fun[A:Manifest,B:Manifest](f: Rep[A] => Rep[B]): Rep[A=>B] = doLambda(f) @@ -20,6 +20,10 @@ trait Functions extends Base { } def doApply[A:Manifest,B:Manifest](fun: Rep[A => B], arg: Rep[A])(implicit pos: SourceContext): Rep[B] + def uninlinedFunc0[B:Manifest](f: Function0[Rep[B]]): Rep[Unit=>B] + def uninlinedFunc1[A:Manifest,B:Manifest](f: Function1[Rep[A],Rep[B]]): Rep[A=>B] + def uninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](f: Function2[Rep[A1],Rep[A2],Rep[B]]): Rep[(A1,A2)=>B] + def uninlinedFunc3[A1:Manifest,A2:Manifest,A3:Manifest,B:Manifest](f: Function3[Rep[A1],Rep[A2],Rep[A3],Rep[B]]): Rep[(A1,A2,A3)=>B] } trait TupledFunctions extends Functions with TupleOps { @@ -34,6 +38,9 @@ trait TupledFunctions extends Functions with TupleOps { implicit def fun[A1:Manifest,A2:Manifest,A3:Manifest,A4:Manifest,A5:Manifest,B:Manifest](f: (Rep[A1], Rep[A2], Rep[A3], Rep[A4], Rep[A5]) => Rep[B]): Rep[((A1,A2,A3,A4,A5))=>B] = fun((t: Rep[(A1,A2,A3,A4,A5)]) => f(tuple5_get1(t), tuple5_get2(t), tuple5_get3(t), tuple5_get4(t), tuple5_get5(t))) + class LambdaOps0[B:Manifest](f: Rep[Unit => B]) { + def apply() = doApply(f,unit()) + } class LambdaOps2[A1:Manifest,A2:Manifest,B:Manifest](f: Rep[((A1,A2)) => B]) { def apply(x1: Rep[A1], x2: Rep[A2]) = doApply(f,(x1, x2)) def apply(x: Rep[(A1,A2)]): Rep[B] = doApply(f,x) @@ -52,6 +59,8 @@ trait TupledFunctions extends Functions with TupleOps { } implicit def toLambdaOpsAny[B:Manifest](fun: Rep[Any => B]) = toLambdaOps(fun) + implicit def toLambdaOps0[B:Manifest](fun: Rep[Unit => B]) = + new LambdaOps0(fun) implicit def toLambdaOps2[A1:Manifest,A2:Manifest,B:Manifest](fun: Rep[((A1,A2)) => B]) = new LambdaOps2(fun) implicit def toLambdaOps3[A1:Manifest,A2:Manifest,A3:Manifest,B:Manifest](fun: Rep[((A1,A2,A3)) => B]) = @@ -64,7 +73,29 @@ trait TupledFunctions extends Functions with TupleOps { trait FunctionsExp extends Functions with EffectExp { case class Lambda[A:Manifest,B:Manifest](f: Exp[A] => Exp[B], x: Exp[A], y: Block[B]) extends Def[A => B] { val mA = manifest[A]; val mB = manifest[B] } - case class Apply[A:Manifest,B:Manifest](f: Exp[A => B], arg: Exp[A]) extends Def[B] { val mA = manifest[A]; val mB = manifest[B] } + case class Apply[A:Manifest,B:Manifest](f: Exp[A => B], arg: Exp[A]) extends Def[B] { + val mA = manifest[A] + val mB = manifest[B] + } + case class UninlinedFunc0[B:Manifest](b: Block[B]) extends Def[Unit => B] { + val mB = manifest[B] + } + case class UninlinedFunc1[A:Manifest,B:Manifest](s:Sym[A], b: Block[B]) extends Def[A => B] { + val mA = manifest[A] + val mB = manifest[B] + } + case class UninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](s1:Sym[A1], s2:Sym[A2], b: Block[B]) extends Def[(A1,A2) => B] { + val mA1 = manifest[A1] + val mA2 = manifest[A2] + val mB = manifest[B] + } + case class UninlinedFunc3[A1:Manifest,A2:Manifest,A3:Manifest,B:Manifest](s1:Sym[A1], s2:Sym[A2], s3:Sym[A3], b: Block[B]) extends Def[(A1,A2,A3) => B] { + val mA1 = manifest[A1] + val mA2 = manifest[A2] + val mA3 = manifest[A3] + val mB = manifest[B] + } + // unboxedFresh and unbox are hooks that can be overridden to // implement multiple-arity functions with tuples. These two methods @@ -98,10 +129,60 @@ trait FunctionsExp extends Functions with EffectExp { } } + /* BEGINNING UNINLINED FUNCTIONS */ + val functionList0 = new scala.collection.mutable.HashMap[Sym[Any],Block[Any]]() + val functionList1 = new scala.collection.mutable.HashMap[Sym[Any],(Sym[Any],Block[Any])]() + val functionList2 = new scala.collection.mutable.HashMap[Sym[Any],(Sym[Any],Sym[Any],Block[Any])]() + val functionList3 = new scala.collection.mutable.HashMap[Sym[Any],(Sym[Any],Sym[Any],Sym[Any],Block[Any])]() + def uninlinedFunc0[B:Manifest](f: Function0[Rep[B]]) = { + val b = reifyEffects(f()) + uninlinedFunc0(b) + } + def uninlinedFunc0[B:Manifest](b: Block[B]) = { + val l = reflectEffect(UninlinedFunc0(b), Pure()) + functionList0 += (l.asInstanceOf[Sym[Any]] -> b) + l + } + + def uninlinedFunc1[A:Manifest,B:Manifest](f: Function1[Rep[A],Rep[B]]) = { + val s = fresh[A] + val b = reifyEffects(f(s)) + uninlinedFunc1(s,b) + } + def uninlinedFunc1[A:Manifest,B:Manifest](s: Sym[A], b: Block[B]) = { + val l = reflectEffect(UninlinedFunc1(s,b), Pure()) + functionList1 += (l.asInstanceOf[Sym[Any]] -> (s,b)) + l + } + + def uninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](f: Function2[Rep[A1],Rep[A2],Rep[B]]) = { + val s1 = fresh[A1] + val s2 = fresh[A2] + val b = reifyEffects(f(s1,s2)) + uninlinedFunc2(s1,s2,b) + } + def uninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](s1: Sym[A1], s2: Sym[A2], b: Block[B]) = { + val l = reflectEffect(UninlinedFunc2(s1,s2,b), Pure()) + functionList2 += (l.asInstanceOf[Sym[Any]] -> (s1,s2,b)) + l + } + + def uninlinedFunc3[A1:Manifest,A2:Manifest,A3:Manifest,B:Manifest](f: Function3[Rep[A1],Rep[A2],Rep[A3],Rep[B]]) = { + val s1 = fresh[A1] + val s2 = fresh[A2] + val s3 = fresh[A3] + val b = reifyEffects(f(s1,s2,s3)) + uninlinedFunc3(s1,s2,s3,b) + } + def uninlinedFunc3[A1:Manifest,A2:Manifest,A3:Manifest,B:Manifest](s1: Sym[A1], s2: Sym[A2], s3: Sym[A3], b: Block[B]) = { + val l = reflectEffect(UninlinedFunc3(s1,s2,s3,b), Pure()) + functionList3 += (l.asInstanceOf[Sym[Any]] -> (s1,s2,s3,b)) + l + } + /* END OF UNINLINED FUNCTIONS */ + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { case e@Lambda(g,x,y) => toAtom(Lambda(f(g),f(x),f(y))(e.mA,e.mB))(mtype(manifest[A]),implicitly[SourceContext]) - case e@Apply(g,arg) => doApply(f(g), f(arg))(e.mA,mtype(e.mB),implicitly[SourceContext]) - case Reflect(e@Apply(g,arg), u, es) => reflectMirrored(Reflect(Apply(f(g),f(arg))(e.mA,mtype(e.mB)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] // why?? @@ -109,8 +190,12 @@ trait FunctionsExp extends Functions with EffectExp { case Lambda(f, x, y) => syms(y) case _ => super.syms(e) } - + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case UninlinedFunc0(f) => effectSyms(f) + case UninlinedFunc1(s,f) => s :: effectSyms(f) + case UninlinedFunc2(s1,s2,f) => s1 :: s2 :: effectSyms(f) + case UninlinedFunc3(s1,s2,s3,f) => s1 :: s2 :: s3 :: effectSyms(f) case Lambda(f, x, y) => syms(x) ::: effectSyms(y) case _ => super.boundSyms(e) } @@ -188,6 +273,22 @@ trait TupledFunctionsExp extends TupledFunctions with FunctionsExp with TupleOps } } + override def aliasSyms(e: Any): List[Sym[Any]] = e match { + case UninlinedFunc0(f) => effectSyms(f) + case UninlinedFunc1(s,f) => s :: effectSyms(f) + case UninlinedFunc2(s1,s2,f) => s1 :: s2 :: effectSyms(f) + case UninlinedFunc3(s1,s2,s3,f) => s1 :: s2 :: s3 :: effectSyms(f) + case _ => super.aliasSyms(e) + } + + override def containSyms(e: Any): List[Sym[Any]] = e match { + case UninlinedFunc0(f) => effectSyms(f) + case UninlinedFunc1(s,f) => s :: effectSyms(f) + case UninlinedFunc2(s1,s2,f) => s1 :: s2 :: effectSyms(f) + case UninlinedFunc3(s1,s2,s3,f) => s1 :: s2 :: s3 :: effectSyms(f) + case _ => super.containSyms(e) + } + override def boundSyms(e: Any): List[Sym[Any]] = e match { case Lambda(f, UnboxedTuple(xs), y) => xs.flatMap(syms) ::: effectSyms(y) case _ => super.boundSyms(e) @@ -223,11 +324,24 @@ trait GenericGenUnboxedTupleAccess extends GenericNestedCodegen { import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case FieldApply(UnboxedTuple(vars), "_1") => emitValDef(sym, quote(vars(0))) - case FieldApply(UnboxedTuple(vars), "_2") => emitValDef(sym, quote(vars(1))) - case FieldApply(UnboxedTuple(vars), "_3") => emitValDef(sym, quote(vars(2))) - case FieldApply(UnboxedTuple(vars), "_4") => emitValDef(sym, quote(vars(3))) - case FieldApply(UnboxedTuple(vars), "_5") => emitValDef(sym, quote(vars(4))) + case Tuple2Access1(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(0))) + case Tuple2Access2(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(1))) + + case Tuple3Access1(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(0))) + case Tuple3Access2(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(1))) + case Tuple3Access3(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(2))) + + case Tuple4Access1(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(0))) + case Tuple4Access2(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(1))) + case Tuple4Access3(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(2))) + case Tuple4Access4(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(3))) + + case Tuple5Access1(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(0))) + case Tuple5Access2(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(1))) + case Tuple5Access3(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(2))) + case Tuple5Access4(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(3))) + case Tuple5Access5(UnboxedTuple(vars)) => emitValDef(sym, quote(vars(4))) + case _ => super.emitNode(sym, rhs) } } @@ -243,16 +357,33 @@ trait ScalaGenFunctions extends ScalaGenEffect with BaseGenFunctions { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case e@Lambda(fun, x, y) => - emitValDef(sym, "{" + quote(x) + ": (" + remap(x.tp) + ") => ") + emitValDef(sym, "{" + quote(x, true) + ": (" + x.tp + ") => ") emitBlock(y) - stream.println(quote(getBlockResult(y)) + ": " + remap(y.tp)) + if (y.tp != manifest[Unit]) stream.println(quote(getBlockResult(y)) + ": " + y.tp) stream.println("}") + case UninlinedFunc0(b) => /* Handled in emitFunctions */ {} + case UninlinedFunc1(s,b) => /* Handled in emitFunctions */ {} + case UninlinedFunc2(s1,s2,b) => /* Handled in emitFunctions */ {} + case UninlinedFunc3(s1,s2,s3,b) => /* Handled in emitFunctions */ {} case Apply(fun, arg) => - emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") + arg match { + case Const(()) => emitValDef(sym, quote(fun) + "()") + case _ => emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") + } case _ => super.emitNode(sym, rhs) } + + override def emitFunctions() = { + functionList0.foreach(func => { + stream.println("def " + quote(func._1) + "() = {") + emitBlock(func._2) + emitBlockResult(func._2) + stream.println("}") + }) + functionList0.clear + } } trait ScalaGenTupledFunctions extends ScalaGenFunctions with GenericGenUnboxedTupleAccess { @@ -266,28 +397,26 @@ trait ScalaGenTupledFunctions extends ScalaGenFunctions with GenericGenUnboxedTu override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case Lambda(fun, UnboxedTuple(xs), y) => - emitValDef(sym, "{" + xs.map(s=>quote(s)+":"+remap(s.tp)).mkString("(",",",")") + " => ") + emitValDef(sym, "{" + xs.map(s=>quote(s, true)+":"+remap(s.tp)).mkString("(",",",")") + " => ") emitBlock(y) - stream.println(quote(getBlockResult(y)) + ": " + remap(y.tp)) + var ytp = remap(y.tp).toString; + if (ytp != manifest[Unit]) stream.println(quote(getBlockResult(y)) + ": " + ytp ) stream.println("}") - case Apply(fun, UnboxedTuple(args)) => emitValDef(sym, quote(fun) + args.map(quote).mkString("(", ",", ")")) - case _ => super.emitNode(sym,rhs) } - - def unwrapTupleStr[A](m: Manifest[A]): Array[String] = { - val s = m.toString + + def unwrapTupleStr(s: String): Array[String] = { if (s.startsWith("scala.Tuple")) s.slice(s.indexOf("[")+1,s.length-1).filter(c => c != ' ').split(",") - else Array(remap(m)) - } - - override def remap[A](m: Manifest[A]): String = m.toString match { + else scala.Array(s) + } + + override def remap[A](m: Manifest[A]): String = m.toString match { case f if f.startsWith("scala.Function") => val targs = m.typeArguments.dropRight(1) val res = remap(m.typeArguments.last) - val targsUnboxed = targs.flatMap(t => unwrapTupleStr(t)) + val targsUnboxed = targs.flatMap(t => unwrapTupleStr(remap(t))) val sep = if (targsUnboxed.length > 0) "," else "" "scala.Function" + (targsUnboxed.length) + "[" + targsUnboxed.mkString(",") + sep + res + "]" @@ -302,11 +431,10 @@ trait CudaGenFunctions extends CudaGenEffect with BaseGenFunctions { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { case e@Lambda(fun, x, y) => - throw new GenerationFailedException("CudaGenFunctions: Lambda is not supported yet") // The version for inlined device function - //stream.println(addTab() + "%s %s = %s;".format(remap(x.tp), quote(x), quote(sym)+"_1")) - //emitBlock(y) - //stream.println(addTab() + "%s %s = %s;".format(remap(y.tp), quote(sym), quote(getBlockResult(y)))) + stream.println(addTab() + "%s %s = %s;".format(remap(x.tp), quote(x), quote(sym)+"_1")) + emitBlock(y) + stream.println(addTab() + "%s %s = %s;".format(remap(y.tp), quote(sym), quote(getBlockResult(y)))) // The version for separate device function /* @@ -318,6 +446,7 @@ trait CudaGenFunctions extends CudaGenEffect with BaseGenFunctions { stream.println("return %s;".format(quote(getBlockResult(y)))) stream.println("}") */ + case Apply(fun, arg) => emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") @@ -342,68 +471,139 @@ trait OpenCLGenFunctions extends OpenCLGenEffect with BaseGenFunctions { } } -trait CGenFunctions extends CGenEffect with BaseGenFunctions { +trait CGenFunctions extends CNestedCodegen with CGenEffect with BaseGenFunctions { val IR: FunctionsExp import IR._ - // Case for functions with a single argument (therefore, not tupled) + override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { + case UninlinedFunc0(f) => { + LIRTraversal(f) + sym.atPhase(LIRLowering) { + functionList0 -= sym + functionList0 += (sym -> LIRLowering(f)) + sym + } + } + case UninlinedFunc1(s,f) => { + LIRTraversal(f) + sym.atPhase(LIRLowering) { + functionList1 -= sym + functionList1 += (sym -> (s,LIRLowering(f))) + sym + } + } + case UninlinedFunc2(s1,s2,f) => { + LIRTraversal(f) + sym.atPhase(LIRLowering) { + functionList2 -= sym + functionList2 += (sym -> (s1,s2,LIRLowering(f))) + sym + } + } + case UninlinedFunc3(s1,s2,s3,f) => { + LIRTraversal(f) + sym.atPhase(LIRLowering) { + functionList3 -= sym + functionList3 += (sym -> (s1,s2,s3,LIRLowering(f))) + sym + } + } + case a@Apply(fun, arg) => + sym.atPhase(LIRLowering) { + val funSym = fun.asInstanceOf[Sym[_]] + val rM = (fun match { + case s if functionList0.contains(funSym) => getBlockResult(functionList0(funSym)).tp + case _ => a.mB + }).asInstanceOf[Manifest[T]] + doApply(fun, arg)(a.mA, rM, implicitly[SourceContext]).asInstanceOf[Exp[T]] + } + case _ => super.lowerNode(sym, rhs) + } + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case e@Lambda(fun, x, y) => - val retType = remap(getBlockResult(y).tp) - val retTp = if (cppExplicitFunRet == "true") "function<"+retType+"("+remap(x.tp)+")>" else "auto" - stream.println(retTp+" "+quote(sym)+ - " = [&]("+remap(x.tp)+" "+quote(x)+") {") + stream.println(remap(y.tp)+" "+quote(sym)+"("+remap(x.tp)+" "+quote(x)+") {") emitBlock(y) val z = getBlockResult(y) - if (retType != "void") + if (remap(z.tp) != "void") stream.println("return " + quote(z) + ";") - stream.println("};") - case Apply(fun, arg) => - emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") + stream.println("}") + case UninlinedFunc0(b) => /* Handled in emitFunctions */ {} + case UninlinedFunc1(s,b) => /* Handled in emitFunctions */ {} + case UninlinedFunc2(s1,s2,b) => /* Handled in emitFunctions */ {} + case UninlinedFunc3(s1,s2,s3,b) => /* Handled in emitFunctions */ {} + case a@Apply(fun, arg) => + arg match { + case Const(x) => x match { + case t: scala.Tuple2[Exp[_],Exp[_]] => + emitValDef(sym, quote(fun) + "(" + quote(t._1) + "," + quote(t._2) + ")") + case () => emitValDef(sym, quote(fun) + "()") + case _ => emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") + } + case _ => emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") + } case _ => super.emitNode(sym, rhs) } - + override def emitFunctions() = { + // Output prototypes to resolve dependencies + functionList0.foreach(f=>stream.println(remap(getBlockResult(f._2).tp) + " " + quote(f._1) + "();")) + functionList1.foreach(f=>stream.println(remap(getBlockResult(f._2._2).tp) + " " + quote(f._1) + "(" + remap(f._2._1.tp) + " " + quote(f._2._1) + ");")) + functionList2.foreach(f=>stream.println(remap(getBlockResult(f._2._3).tp) + " " + quote(f._1) + "(" + remap(f._2._1.tp) + " " + quote(f._2._1) + ", " + remap(f._2._2.tp) + " " + quote(f._2._2) +");\n")) + functionList3.foreach(f=>stream.println(remap(getBlockResult(f._2._4).tp) + " " + quote(f._1) + "(" + remap(f._2._1.tp) + " " + quote(f._2._1) + ", " + remap(f._2._2.tp) + " " + quote(f._2._2) + ", " + remap(f._2._3.tp) + " " + quote(f._2._3) + ");\n")) + // Output actual functions + functionList0.foreach(func => { + stream.println(remap(getBlockResult(func._2).tp) + " " + quote(func._1) + "() {") + emitBlock(func._2) + stream.println("return " + quote(getBlockResult(func._2)) + ";") + stream.println("}\n") + }) + functionList1.foreach(func => { + stream.print(remap(getBlockResult(func._2._2).tp) + " " + quote(func._1) + "(") + stream.print(remap(func._2._1.tp) + " " + quote(func._2._1)) + stream.println(") {") + emitBlock(func._2._2) + stream.println("return " + quote(getBlockResult(func._2._2)) + ";") + stream.println("}\n") + }) + functionList2.foreach(func => { + stream.print(remap(getBlockResult(func._2._3).tp) + " " + quote(func._1) + "(") + stream.print(remap(func._2._1.tp) + " " + quote(func._2._1) + ", ") + stream.print(remap(func._2._2.tp) + " " + quote(func._2._2)) + stream.println(") {") + emitBlock(func._2._3) + stream.println("return " + quote(getBlockResult(func._2._3)) + ";") + stream.println("}\n") + }) + functionList3.foreach(func => { + stream.print(remap(getBlockResult(func._2._4).tp) + " " + quote(func._1) + "(") + stream.print(remap(func._2._1.tp) + " " + quote(func._2._1) + ", ") + stream.print(remap(func._2._2.tp) + " " + quote(func._2._2) + ", ") + stream.print(remap(func._2._3.tp) + " " + quote(func._2._3)) + stream.println(") {") + emitBlock(func._2._4) + stream.println("return " + quote(getBlockResult(func._2._4)) + ";") + stream.println("}\n") + }) + functionList0.clear + functionList1.clear + functionList2.clear + functionList3.clear + } } trait CGenTupledFunctions extends CGenFunctions with GenericGenUnboxedTupleAccess { val IR: TupledFunctionsExp import IR._ - - /*override def quote(x: Exp[Any]) : String = x match { - case UnboxedTuple(t) => t.map(quote).mkString("((", ",", "))") - case _ => super.quote(x) - }*/ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case Lambda(fun, UnboxedTuple(xs), y) => - val retType = remap(getBlockResult(y).tp) - val retTp = if (cppExplicitFunRet == "true") "function<"+retType+"("+xs.map(s=>remap(s.tp)).mkString(",")+")>" else "auto" - stream.println(retTp+" "+quote(sym)+ - " = [&]("+xs.map(s=>remap(s.tp)+" "+quote(s)).mkString(",")+") {") + stream.println(remap(y.tp)+" "+quote(sym)+"("+xs.map(s=>remap(s.tp)+" "+quote(s)).mkString(",")+") {") emitBlock(y) val z = getBlockResult(y) - if (retType != "void") + if (remap(z.tp) != "void") stream.println("return " + quote(z) + ";") - stream.println("};") - case Apply(fun, UnboxedTuple(args)) => + stream.println("}") + case a@Apply(fun, UnboxedTuple(args)) => emitValDef(sym, quote(fun) + args.map(quote).mkString("(", ",", ")")) case _ => super.emitNode(sym,rhs) } - - /*def unwrapTupleStr(s: String): Array[String] = { - if (s.startsWith("scala.Tuple")) s.slice(s.indexOf("[")+1,s.length-1).filter(c => c != ' ').split(",") - else Array(s) - }*/ - - /*override def remap[A](m: Manifest[A]): String = m.toString match { - case f if f.startsWith("scala.Function") => - val targs = m.typeArguments.dropRight(1) - val res = remap(m.typeArguments.last) - val targsUnboxed = targs.flatMap(t => unwrapTupleStr(remap(t))) - val sep = if (targsUnboxed.length > 0) "," else "" - "scala.Function" + (targsUnboxed.length) + "[" + targsUnboxed.mkString(",") + sep + res + "]" - - case _ => super.remap(m) - }*/ } diff --git a/src/common/GeneratorOps.scala b/src/common/GeneratorOps.scala new file mode 100644 index 00000000..23a6ae3d --- /dev/null +++ b/src/common/GeneratorOps.scala @@ -0,0 +1,297 @@ +package scala.virtualization.lms +package common + +import java.io.PrintWriter +import scala.virtualization.lms.common._ +import scala.collection.mutable +import scala.collection.mutable.Set +import scala.reflect.SourceContext +import scala.collection.mutable.Map + +trait MapOps extends Base { + type MapType[K,V] + + def newMapType[K: Manifest, V: Manifest](): Rep[MapType[K, V]] + def lookupOrDefault[K, V: Manifest](x: Rep[MapType[K, V]], key: Rep[K], defaultVal: Rep[V]): Rep[V] + def updateValue[K, V](x: Rep[MapType[K, V]], key: Rep[K], value: Rep[V]): Rep[Unit] +} + +trait GeneratorOps extends Base with Variables with LiftVariables with IfThenElse with Equal with TupleOps with ListOps with MapOps with ObjectOps with StringOps with HashMapOps with ListBuffer with HashMultiMapOps with SetOps with LiftNumeric with NumericOps with ArrayOps { + def materializeGenerator[T:Manifest,U:Manifest](gen: Generator[U]): Rep[T] + def dematerializeGenerator[T:Manifest,U:Manifest](genCon: Rep[T]): Generator[U] + + def materializeTupleGenerator[T:Manifest,U:Manifest,V:Manifest](gen: TupleGenerator[U,V]): Rep[T] + def dematerializeTupleGenerator[T:Manifest,U:Manifest,V:Manifest](genCon: Rep[T]): TupleGenerator[U,V] + + implicit def generatorToRep[T:Manifest](gen: Generator[T]): Rep[T] = materializeGenerator[T,T](gen) + //TODO - This implicite should be defined for every collection type + //implicit def repToGenerator[T:Manifest,U:Manifest](genCon: Rep[T]): Generator[U] = dematerializeGenerator[T,U](genCon) + + implicit def tupledGeneratorToRep[K:Manifest, V:Manifest](gen: TupleGenerator[K,V]): Rep[(K,V)] = materializeTupleGenerator[(K,V),K,V](gen) + //TODO - This implicite should be defined for every collection type + //implicit def repToGenerator[T:Manifest,U:Manifest](genCon: Rep[T]): Generator[U] = dematerializeGenerator[T,U](genCon) + + abstract class TupleGenerator[K:Manifest, V:Manifest] extends ((Rep[(K,V)] => Rep[Unit]) => Rep[Unit]) with Serializable /*extends Generator[(K,V)]*/ { self => + + /*override*/ def map[K2:Manifest, V2:Manifest](g: Rep[(K,V)] => Rep[(K2,V2)]) = new TupleGenerator[K2,V2] { + def apply(f: Rep[(K2,V2)] => Rep[Unit]) = self.apply { + x:Rep[(K,V)] => f(g(x)) + } + } + + /*override*/ def filter(p: Rep[(K,V)] => Rep[Boolean]) = new TupleGenerator[K,V] { + def apply(f: Rep[(K,V)] => Rep[Unit]) = self.apply { + x:Rep[(K,V)] => if(p(x)) f(x) + } + } + + /*override*/ def ++(that: TupleGenerator[K,V]) = new TupleGenerator[K,V] { + def apply(f: Rep[(K,V)] => Rep[Unit]) = { + self.apply(f) + that.apply(f) + } + } + + /*override*/ def flatMap[K2:Manifest, V2:Manifest](g: Rep[(K,V)] => TupleGenerator[K2,V2]) = new TupleGenerator[K2,V2] { + def apply(f: Rep[(K2,V2)] => Rep[Unit]) = self.apply { x:Rep[(K,V)] => + val tmp : TupleGenerator[K2,V2] = g(x) + tmp(f) + } + } + + /*override*/ def reduce(h:(Rep[(K,V)],Rep[(K,V)])=>Rep[(K,V)], z:Rep[(K,V)]) = new TupleGenerator[K,V] { + def apply(f: Rep[(K,V)] => Rep[Unit]) = { + var best = z; + self.apply { x:Rep[(K,V)] => if (best==z) best=x; else best=h(best,x) } + if (best!=z) f(best) + } + } + + /*override*/ def flatten[K2:Manifest, V2:Manifest] = flatMap[K2,V2] { + x:Rep[(K,V)] => dematerializeTupleGenerator[(K,V),K2,V2](x) + } + + /*override*/ def fold[Y:Manifest](init: Rep[Y], g: Rep[(K,V)] => (Rep[Y] => Rep[Y])): Rep[Y] = { + var res = init + self.apply { + x:Rep[(K,V)] => res = g(x)(res) + } + res + } + + /*override*/ def foldLong(init: Rep[Long], g: Rep[(K,V)] => (Rep[Long] => Rep[Long])): Rep[Long] = { + var res = init + self.apply { + x:Rep[(K,V)] => res = g(x)(res) + } + res + } + + /*override*/ def foreach(g: Rep[(K,V)] => Rep[Unit]) = self.apply { + x:Rep[(K,V)] => g(x) + } + + /*override*/ def toList: Rep[List[(K,V)]] = { + var resList = List[(K,V)]() + self.apply { + x:Rep[(K,V)] => resList = x :: resList + } + resList + } + + def groupByAggregate[K2:Manifest, V2:Manifest](init: Rep[V2], group: Rep[(K, V)] => Rep[K2], + fn: Rep[(K, V)] => (Rep[V2] => Rep[V2])): Rep[MapType[K2, V2]] = { + val grps = newMapType[K2,V2]() + self.apply { + x:Rep[(K,V)] => { + val key: Rep[K2] = group(x) + val value = fn(x)(lookupOrDefault(grps,key,init)) + updateValue(grps,key,value) + } + } + grps + } + + def groupByMultipleAggregates[K2:Manifest, V2:Manifest](newMapFun: () => Rep[scala.collection.mutable.HashMap[K2, Array[V2]]], numAggs: Rep[Long], group: Rep[(K, V)] => Rep[K2], fn: (Rep[V], Rep[V2]) => Rep[V2]*): Rep[scala.collection.mutable.HashMap[K2, Array[V2]]] = { + val grps = newMapFun()//HashMap[K2,Array[V2]]() + self.apply { + x:Rep[(K,V)] => { + val key: Rep[K2] = group(x) + val aggs = grps.getOrElseUpdate(key, NewArray[V2](numAggs))//fn.length))// lookupOrDefault[K2,Array[V2]](grps,key,init)) + fn.foldLeft(0L) { (cnt,aggfn) => { + val value = aggfn(x._2,aggs(cnt)) + aggs(cnt) = value + cnt+1 + } } + unit() + } + } + grps + } + + def mkString(delimiter: Rep[String] = unit("")): Rep[String] = { + var res = string_new(unit("")) + self.apply { + x:Rep[(K,V)] => res = res + infix_ToString(x)//.ToString + if (delimiter != unit("")) res = res + delimiter + } + res + } + + + /*def slice[K2: Manifest](kp: Rep[K2], idx: Rep[List[Int]]): TupleGenerator[K, V] = { + self.filter{ + kv:Rep[(K,V)] => { + val k = kv._1.asInstanceOf[Rep[(K2,_)]] + kp == tuple2_get1(k) + } + } + }*/ + } + + // Generator[T] === (T => Unit) => Unit + abstract class Generator[T:Manifest] extends ((Rep[T] => Rep[Unit]) => Rep[Unit]) with Serializable { self => + + //Rep[T => U] != Rep[T] => Rep[U] + def map[U:Manifest](g: Rep[T] => Rep[U]) = new Generator[U] { + def apply(f: Rep[U] => Rep[Unit]) = self.apply { + x:Rep[T] => f(g(x)) + } + } + + def filter(p: Rep[T] => Rep[Boolean]) = new Generator[T] { + def apply(f: Rep[T] => Rep[Unit]) = self.apply { + x:Rep[T] => if(p(x)) f(x) + } + } + + def ++(that: Generator[T]) = new Generator[T] { + def apply(f: Rep[T] => Rep[Unit]) = { + self.apply(f) + that.apply(f) + } + } + + def flatMap[U:Manifest](g: Rep[T] => Generator[U]) = new Generator[U]{ + def apply(f: Rep[U] => Rep[Unit]) = self.apply{ x:Rep[T] => + val tmp : Generator[U] = g(x) + tmp(f) + } + } + + def reduce(h:(Rep[T],Rep[T])=>Rep[T], z:Rep[T]) = new Generator[T] { + def apply(f: Rep[T] => Rep[Unit]) = { + var best = z; + self.apply { x:Rep[T] => if (best==z) best=x; else best=h(best,x) } + if (best!=z) f(best) + } + } + + def flatten[U:Manifest] = flatMap[U] { + x:Rep[T] => dematerializeGenerator[T,U](x) + } + + def fold[Y:Manifest](init: Rep[Y], g: Rep[T] => (Rep[Y] => Rep[Y])): Rep[Y] = { + var res = init + self.apply { + x:Rep[T] => res = g(x)(res) + } + res + } + + def sum(implicit num: Numeric[T]): Rep[T] = { + var res = unit(num.zero) + self.apply { + x:Rep[T] => res = numeric_plus(x, readVar(res)) + } + readVar(res) + } + + + def foldLong(init: Rep[Long], g: Rep[T] => (Rep[Long] => Rep[Long])): Rep[Long] = { + var res = init + self.apply { + x:Rep[T] => res = g(x)(res) + } + res + } + + def foreach(g: Rep[T] => Rep[Unit]) = self.apply { + x:Rep[T] => g(x) + } + + def toList: Rep[List[T]] = { + var resList = List[T]() + self.apply { + x:Rep[T] => resList = x :: resList + } + resList + } + + } + + case class EmptyGen[T:Manifest]() extends Generator[T]{ + def apply(f: Rep[T] => Rep[Unit]) = {} + } + + def emptyGen[A:Manifest](): Generator[A] = EmptyGen[A] + + def elGen[A:Manifest](a: Rep[A]): Generator[A] = new Generator[A]{ + def apply(f: Rep[A] => Rep[Unit]) = { + f(a) + } + } + + def cond[A:Manifest](cond: Rep[Boolean], a: Generator[A], b: Generator[A]) = new Generator[A]{ + def apply(f: Rep[A] => Rep[Unit]) = { + if(cond) a(f) else b(f) + } + } +} + +trait GeneratorOpsExp extends GeneratorOps with EffectExp with VariablesExp with IfThenElseExp with EqualExp with TupleOpsExp with ListOpsExp with ObjectOpsExp with StringOpsExp with HashMapOpsExp with ListBufferExp with HashMultiMapOpsExp with SetOpsExp with ArrayOpsExp { + + case class GeneratorContainer[T: Manifest,U:Manifest](gen: Generator[U]) extends Def[T] + case class TupleGeneratorContainer[T: Manifest,U:Manifest,V:Manifest](gen: TupleGenerator[U,V]) extends Def[T] + + def materializeGenerator[T:Manifest,U:Manifest](gen: Generator[U]): Rep[T] = GeneratorContainer[T,U](gen) + def dematerializeGenerator[T:Manifest,U:Manifest](genCon: Rep[T]): Generator[U] = { + findDefinition(genCon.asInstanceOf[Sym[T]]).get.rhs match { + case Reflect(ReadVar(x), _, _) => x.asInstanceOf[GeneratorContainer[T,U]].gen + case x => x.asInstanceOf[GeneratorContainer[T,U]].gen + } + } + def materializeTupleGenerator[T:Manifest,U:Manifest,V:Manifest](gen: TupleGenerator[U,V]): Rep[T] = TupleGeneratorContainer[T,U,V](gen) + def dematerializeTupleGenerator[T:Manifest,U:Manifest,V:Manifest](genCon: Rep[T]): TupleGenerator[U,V] = { + findDefinition(genCon.asInstanceOf[Sym[T]]).get.rhs match { + case Reflect(ReadVar(x), _, _) => x.asInstanceOf[TupleGeneratorContainer[T,U,V]].gen + case x => x.asInstanceOf[TupleGeneratorContainer[T,U,V]].gen + } + } +} + +trait ScalaGenGeneratorOps extends ScalaGenVariables + with ScalaGenIfThenElse with ScalaGenEqual with ScalaGenListOps with ScalaGenTupleOps { + val IR: GeneratorOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + // currently, we shoud explicitly call toList method on a generator, in order to convert it again to list + + case TupleGeneratorContainer(gen) => val genList = gen.toList; emitNode(sym, Def.unapply(genList).get) + case GeneratorContainer(gen) => + case _ => super.emitNode(sym, rhs) + } + +} + +trait CGenGeneratorOps extends CGenVariables + with CGenIfThenElse with CLikeGenEqual with CLikeGenListOps { + val IR: GeneratorOpsExp + import IR._ + + /*override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case _ => super.emitNode(sym, rhs) + }*/ + +} diff --git a/src/common/GregorianCalendarOps.scala b/src/common/GregorianCalendarOps.scala new file mode 100644 index 00000000..30797b93 --- /dev/null +++ b/src/common/GregorianCalendarOps.scala @@ -0,0 +1,56 @@ +package scala.virtualization.lms +package common + +import scala.virtualization.lms.common._ +import scala.reflect.SourceContext +import java.util.Date +import java.util.GregorianCalendar + +/** + * Lifter Classes for GregorianCalendar + */ +trait GregorianCalendarOps extends Base { + + class GregorianCalendarOpsCls(x: Rep[GregorianCalendar]) { + def getTime(): Rep[Date] = gcGetTime(x) + } + + implicit def date2GregorianCalendarOpsCls(x: Rep[GregorianCalendar]): GregorianCalendarOpsCls = new GregorianCalendarOpsCls(x) + def newGregorianCalendar(y: Rep[Int], m: Rep[Int], d: Rep[Int]): Rep[GregorianCalendar] + def gcGetTime(x: Rep[GregorianCalendar]): Rep[Date] +} + +trait GregorianCalendarExp extends GregorianCalendarOps with BaseExp { + + case class NewGregorianCalendar(y: Exp[Int], m: Exp[Int], d: Exp[Int]) extends Def[GregorianCalendar] + case class GcGetTime(x: Exp[GregorianCalendar]) extends Def[Date] + + def newGregorianCalendar(y: Exp[Int], m: Exp[Int], d: Exp[Int]): Exp[GregorianCalendar] = NewGregorianCalendar(y, m, d) + def gcGetTime(x: Exp[GregorianCalendar]): Exp[Date] = GcGetTime(x) + + ////////////// + // mirroring + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case NewGregorianCalendar(y,m,d) => newGregorianCalendar(f(y),f(m),f(d)) + case GcGetTime(x) => gcGetTime(f(x)) + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] // why?? +} + +trait GregorianCalendarExpOpt extends GregorianCalendarExp { + override def gcGetTime(x: Exp[GregorianCalendar]): Exp[Date] = x match { + case Const(x) => unit(x.getTime) + case _ => super.gcGetTime(x) + } +} + +trait ScalaGenGregorianCalendar extends ScalaGenBase { + val IR: GregorianCalendarExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case NewGregorianCalendar(y, m, d) => emitValDef(sym, "new GregorianCalendar(" + quote(y) + ", " + quote(m) + ", " + quote(d) + ")") + case GcGetTime(x) => emitValDef(sym, quote(x) + ".getTime()"); + case _ => super.emitNode(sym, rhs) + } +} \ No newline at end of file diff --git a/src/common/HashCodeOps.scala b/src/common/HashCodeOps.scala new file mode 100644 index 00000000..46df8b91 --- /dev/null +++ b/src/common/HashCodeOps.scala @@ -0,0 +1,38 @@ +package scala.virtualization.lms +package common + +import scala.virtualization.lms.util._ +import scala.virtualization.lms.internal._ + +trait HashCodeOps extends Base { + def __hashCode(x: Rep[Any]): Rep[Int] +} + +trait HashCodeOpsExp extends BaseExp with EffectExp { + case class HashCode(x: Rep[Any]) extends Def[Int] + def __hashCode(x: Rep[Any]) = reflectEffect(HashCode(x)) +} + +trait ScalaGenHashCodeOps extends ScalaGenBase { + val IR: HashCodeOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case HashCode(x) => emitValDef(sym, quote(x) + ".hashCode") + case _ => super.emitNode(sym, rhs) + } + } +} + +trait CGenHashCodeOps extends CGenBase { + val IR: HashCodeOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case HashCode(x) => emitValDef(sym, "(int)" + quote(x)) + case _ => super.emitNode(sym, rhs) + } + } +} diff --git a/src/common/HashMapOps.scala b/src/common/HashMapOps.scala index a0db7999..ff6396cd 100644 --- a/src/common/HashMapOps.scala +++ b/src/common/HashMapOps.scala @@ -1,18 +1,22 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal._ -import scala.collection.mutable.Set -import java.util.HashMap +import java.io.StringWriter +import scala.virtualization.lms.internal._ +import scala.collection.mutable.{HashMap,Set} import scala.reflect.SourceContext -trait HashMapOps extends Base { +trait HashMapOps extends Base with Variables with TupleOps { object HashMap { def apply[K:Manifest,V:Manifest]()(implicit pos: SourceContext) = hashmap_new[K,V]() + def apply[K:Manifest,V:Manifest](hash: Rep[K] => Rep[Int], equals: (Rep[K],Rep[K])=>Rep[Boolean])(implicit pos: SourceContext) = + hashmap_new[K,V](hash, equals) } - - implicit def repHashMapToHashMapOps[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) = new hashmapOpsCls(m) + + implicit def HashMapToRepHashMapOps[K:Manifest,V:Manifest](m: HashMap[K,V]) = new hashmapOpsCls[K,V](unit(m)) + implicit def repHashMapToHashMapOps[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) = new hashmapOpsCls[K,V](m) + implicit def varrepHashMapToHashMapOps[K:Manifest,V:Manifest](m: Var[HashMap[K,V]]) = new hashmapOpsCls[K,V](readVar(m)) class hashmapOpsCls[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) { def apply(k: Rep[K])(implicit pos: SourceContext) = hashmap_apply(m, k) @@ -20,67 +24,152 @@ trait HashMapOps extends Base { def contains(k: Rep[K])(implicit pos: SourceContext) = hashmap_contains(m, k) def size(implicit pos: SourceContext) = hashmap_size(m) def values(implicit pos: SourceContext) = hashmap_values(m) + def map[B:Manifest](f: Rep[(K,V)] => Rep[B]) = hashmap_map(m,f) + def foreach(block: Rep[(K,V)] => Rep[Unit])(implicit pos: SourceContext) = hashmap_foreach(m, block) def clear()(implicit pos: SourceContext) = hashmap_clear(m) def keySet(implicit pos: SourceContext) = hashmap_keyset(m) def keys(implicit pos: SourceContext) = hashmap_keys(m) + def head(implicit pos: SourceContext) = hashmap_head(m) + def removeHead(implicit pos:SourceContext) = hashmap_removehead(m) + def getOrElseUpdate(k: Rep[K], v: => Rep[V])(implicit pos: SourceContext) = hashmap_getorelseupdate[K,V](m,k,v) + def remove(v: Rep[K])(implicit pos:SourceContext) = hashmap_remove[K,V](m,v) + def mkString(delimiter: Rep[String]) = hashmap_mkString(m, delimiter) } - def hashmap_new[K:Manifest,V:Manifest]()(implicit pos: SourceContext) : Rep[HashMap[K,V]] + def hashmap_new[K:Manifest,V:Manifest]() : Rep[HashMap[K,V]] + def hashmap_new[K:Manifest,V:Manifest](hash: Rep[K] => Rep[Int], equals: (Rep[K],Rep[K])=>Rep[Boolean]) : Rep[HashMap[K,V]] def hashmap_apply[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K])(implicit pos: SourceContext): Rep[V] def hashmap_update[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext): Rep[Unit] def hashmap_unsafe_update[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext): Rep[Unit] def hashmap_contains[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], i: Rep[K])(implicit pos: SourceContext): Rep[Boolean] def hashmap_size[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Int] def hashmap_values[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Iterable[V]] + def hashmap_map[K:Manifest,V:Manifest,B:Manifest](m: Rep[HashMap[K,V]], f: Rep[(K,V)]=>Rep[B]): Rep[HashMap[K,B]] + def hashmap_foreach[K:Manifest,V:Manifest](x: Rep[HashMap[K,V]], block: Rep[(K,V)] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] def hashmap_clear[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Unit] def hashmap_keyset[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Set[K]] def hashmap_keys[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Iterable[K]] + def hashmap_head[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[(K,V)] + def hashmap_removehead[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[(K,V)] + def hashmap_remove[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], v: Rep[K])(implicit pos: SourceContext): Rep[V] + def hashmap_getorelseupdate[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: => Rep[V])(implicit pos: SourceContext): Rep[V] + def hashmap_mkString[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], v: Rep[String])(implicit pos: SourceContext): Rep[String] } -trait HashMapOpsExp extends HashMapOps with EffectExp { +trait HashMapOpsExp extends HashMapOps with EffectExp with TupleOpsExp with FunctionsExp with ArrayOps with IfThenElseExp with EqualExp { abstract class HashMapDef[K:Manifest,V:Manifest,R:Manifest] extends Def[R] { val mK = manifest[K] val mV = manifest[V] } case class HashMapNew[K:Manifest,V:Manifest]() extends HashMapDef[K,V,HashMap[K,V]] + case class HashMapExtendedNew[K:Manifest,V:Manifest](k: Sym[K], hf:Block[Int], v1: Sym[K], v2: Sym[K], ef: Block[Boolean]) extends HashMapDef[K,V,HashMap[K,V]] case class HashMapApply[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K]) extends HashMapDef[K,V,V] case class HashMapUpdate[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], v: Exp[V]) extends HashMapDef[K,V,Unit] case class HashMapContains[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], i: Exp[K]) extends HashMapDef[K,V,Boolean] case class HashMapSize[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Int] case class HashMapValues[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Iterable[V]] + case class HashMapMap[K:Manifest,V:Manifest,B:Manifest](m: Exp[HashMap[K,V]], s: Sym[(K,V)], v:Block[B]) extends HashMapDef[K,V,HashMap[K,B]] + case class HashMapForeach[K:Manifest, V:Manifest](a: Exp[HashMap[K,V]], x: Sym[(K,V)], block: Block[Unit]) extends Def[Unit] case class HashMapClear[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Unit] case class HashMapKeySet[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Set[K]] case class HashMapKeys[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Iterable[K]] + case class HashMapHead[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,(K,V)] + case class HashMapRemoveHead[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], s: Sym[V]) extends HashMapDef[K,V,(K,V)] + // We assume that the element to be removed exists for sure for simplicitly + case class HashMapRemove[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], v:Rep[K]) extends HashMapDef[K,V,V] { + val ccc = manifest[V] + } + case class HashMapGetOrElseUpdate[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], vl: Block[V]) extends HashMapDef[K,V,V] with IfThenElseExp + case class HashMapMkString[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], v:Rep[String]) extends HashMapDef[K,V,String] - def hashmap_new[K:Manifest,V:Manifest]()(implicit pos: SourceContext) = reflectMutable(HashMapNew[K,V]()) + def hashmap_new[K:Manifest,V:Manifest]() = reflectMutable(HashMapNew[K,V]()) + def hashmap_new[K:Manifest,V:Manifest](hash: Exp[K] => Exp[Int], equals: (Exp[K],Exp[K])=>Exp[Boolean]) = { + val k = fresh[K] + val v1 = fresh[K] + val v2 = fresh[K] + val hf = reifyEffects(hash(k)) + val ef = reifyEffects(equals(v1,v2)) + reflectMutable(HashMapExtendedNew[K,V](k,hf,v1,v2,ef)) + } def hashmap_apply[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K])(implicit pos: SourceContext) = HashMapApply(m,k) def hashmap_update[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], v: Exp[V])(implicit pos: SourceContext) = reflectWrite(m)(HashMapUpdate(m,k,v)) def hashmap_unsafe_update[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], v: Exp[V])(implicit pos: SourceContext) = reflectEffect(HashMapUpdate(m,k,v)) def hashmap_contains[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], i: Exp[K])(implicit pos: SourceContext) = HashMapContains(m, i) - def hashmap_size[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = HashMapSize(m) + def hashmap_size[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = reflectEffect(HashMapSize(m)) def hashmap_values[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = HashMapValues(m) + def hashmap_map[K:Manifest,V:Manifest,B:Manifest](m: Rep[HashMap[K,V]], f: Rep[(K,V)]=>Rep[B]) = { + val a = fresh[Tuple2[K,V]] + val b = reifyEffects(f(a)) + reflectEffect(HashMapMap(m, a, b))//, summarizeEffects(b).star) + } + def hashmap_foreach[K:Manifest,V:Manifest](x: Rep[HashMap[K,V]], block: Rep[(K,V)] => Rep[Unit])(implicit pos: SourceContext) = { + val k = fresh[(K,V)] + val b = reifyEffects(block(k)) + reflectEffect(HashMapForeach(x, k, b), summarizeEffects(b).star) + } + def hashmap_clear[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = reflectWrite(m)(HashMapClear(m)) - def hashmap_keyset[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = HashMapKeySet(m) + def hashmap_keyset[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = reflectEffect(HashMapKeySet(m)) def hashmap_keys[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = HashMapKeys(m) + def hashmap_head[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = { + reflectEffect(HashMapHead(m)) + } + def hashmap_removehead[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = { + val s = fresh[V] + reflectEffect(HashMapRemoveHead(m,s)) + } + def hashmap_remove[K:Manifest, V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K])(implicit pos: SourceContext) = reflectEffect(HashMapRemove[K,V](m,k)) + def hashmap_getorelseupdate[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Exp[K], v: => Exp[V])(implicit pos: SourceContext) = { + val b = reifyEffects(v) + reflectEffect(HashMapGetOrElseUpdate[K,V](m,k,b), summarizeEffects(b).star) + } + def hashmap_mkString[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], v: Rep[String])(implicit pos: SourceContext) = reflectEffect(HashMapMkString(m, v)) override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { (e match { case e@HashMapApply(m,k) => hashmap_apply(f(m),f(k))(e.mK,e.mV,pos) + case e@HashMapRemove(m,k) => hashmap_remove(f(m),f(k))(e.mK,e.mV,pos) case e@HashMapKeys(m) => hashmap_keys(f(m))(e.mK,e.mV,pos) + case e@HashMapKeySet(m) => hashmap_keyset(f(m))(e.mK,e.mV,pos) case e@HashMapValues(m) => hashmap_values(f(m))(e.mK,e.mV,pos) case e@HashMapContains(m,k) => hashmap_contains(f(m),f(k))(e.mK,e.mV,pos) - case e@HashMapSize(m) => hashmap_size(f(m))(e.mK,e.mV,pos) - case Reflect(e@HashMapApply(m,k), u, es) => reflectMirrored(Reflect(HashMapApply(f(m),f(k))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@HashMapKeys(m), u, es) => reflectMirrored(Reflect(HashMapKeys(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@HashMapValues(m), u, es) => reflectMirrored(Reflect(HashMapValues(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@HashMapContains(m,k), u, es) => reflectMirrored(Reflect(HashMapContains(f(m),f(k))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@HashMapSize(m), u, es) => reflectMirrored(Reflect(HashMapSize(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@HashMapNew(), u, es) => reflectMirrored(Reflect(HashMapNew()(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@HashMapUpdate(m,k,v), u, es) => reflectMirrored(Reflect(HashMapUpdate(f(m),f(k),f(v))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@HashMapApply(m,k), u, es) => reflectMirrored(Reflect(HashMapApply(f(m),f(k))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@HashMapKeys(m), u, es) => reflectMirrored(Reflect(HashMapKeys(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@HashMapKeySet(m), u, es) => reflectMirrored(Reflect(HashMapKeySet(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@HashMapValues(m), u, es) => reflectMirrored(Reflect(HashMapValues(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@HashMapSize(m), u, es) => reflectMirrored(Reflect(HashMapSize(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@HashMapRemove(m,el), u, es) => reflectMirrored(Reflect(HashMapRemove(f(m),f(el))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@HashMapContains(m,k), u, es) => reflectMirrored(Reflect(HashMapContains(f(m),f(k))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@HashMapNew(), u, es) => reflectMirrored(Reflect(HashMapNew()(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@HashMapUpdate(m,k,v), u, es) => reflectMirrored(Reflect(HashMapUpdate(f(m),f(k),f(v))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) +// case Reflect(HashMapExtendedNew(k,hf,v1,v2,ef), u, es) => reflectMirrored(Reflect(HashMapExtendedNew(k,f(hf),v1,v2,f(ef)), mapOver(f,u), f(es))) +// case Reflect(HashMapGetOrElseUpdate(m,k,v), u, es) => reflectMirrored(Reflect(HashMapGetOrElseUpdate(f(m).asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],f(k),f(v)), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] // why?? } + override def syms(e: Any): List[Sym[Any]] = e match { + case HashMapMap(m, k, v) => syms(m):::syms(v) + case HashMapForeach(m, k, v) => syms(m):::syms(v) + case HashMapExtendedNew(k,hf,v1,v2,ef) => syms(k):::syms(hf):::syms(v1):::syms(v2):::syms(ef) + case _ => super.syms(e) + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case HashMapGetOrElseUpdate(m, k, v) => effectSyms(k) ::: effectSyms(m) ::: effectSyms(v) + case HashMapMap(m, k, v) => k :: effectSyms(v) + case HashMapForeach(m, k, v) => k :: effectSyms(v) + case HashMapUpdate(m,k,v) => effectSyms(k) ::: effectSyms(m) ::: effectSyms(v) + case HashMapExtendedNew(k,hf,v1,v2,ef) => k :: v1 :: v2 :: effectSyms(hf) ::: effectSyms(ef) + case _ => super.boundSyms(e) + } + + override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case HashMapMap(m, k, v) => freqNormal(m) ::: freqHot(v) + case HashMapForeach(m, k, v) => freqNormal(m) ::: freqHot(v) + case _ => super.symsFreq(e) + } + } trait BaseGenHashMapOps extends GenericNestedCodegen { @@ -93,43 +182,142 @@ trait ScalaGenHashMapOps extends BaseGenHashMapOps with ScalaGenEffect { val IR: HashMapOpsExp import IR._ - // TODO: have two versions for generating Scala/Java versions - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case m@HashMapNew() => emitValDef(sym, "new java.util.HashMap[" + remap(m.mK) + "," + remap(m.mV) + "]()") - case HashMapApply(m,k) => emitValDef(sym, quote(m) + ".get(" + quote(k) + ")") - case HashMapUpdate(m,k,v) => emitValDef(sym, quote(m) + ".put(" + quote(k) + ", " + quote(v) + ")") - case HashMapContains(m,i) => emitValDef(sym, quote(m) + ".containsKey(" + quote(i) + ")") - case HashMapSize(m) => emitValDef(sym, quote(m) + ".size") - case HashMapValues(m) => emitValDef(sym, "scala.collection.JavaConverters.collectionAsScalaIterableConverter("+quote(m)+".values).asScala") - case HashMapClear(m) => emitValDef(sym, quote(m) + ".clear()") - case HashMapKeySet(m) => emitValDef(sym, "scala.collection.JavaConverters.asScalaSetConverter("+quote(m)+".keySet).asScala") - case HashMapKeys(m) => emitValDef(sym, "scala.collection.JavaConverters.asScalaSetConverter("+quote(m)+".keySet).asScala.toIterable") - case _ => super.emitNode(sym, rhs) - } -/* - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case m@HashMapNew() => emitValDef(sym, src"collection.mutable.HashMap[${m.mK},${m.mV}]()") + case m@HashMapNew() => emitValDef(sym, src"new scala.collection.mutable.HashMap[${m.mK},${m.mV}]()") + case m@HashMapExtendedNew(k,hf,v1,v2,ef) => + emitValDef(sym, src"new scala.collection.mutable.HashMap[${m.mK},${m.mV}]() {") + stream.println("override def elemHashCode(" + quote(k) + ": " + remap(m.mK) + ") = {") + emitBlock(hf) + emitBlockResult(hf) + stream.println("}") + stream.println("override def elemEquals(" + quote(v1) + ": " + remap(m.mK) + ", " + quote(v2) + ": " + remap(m.mK) + ") = {") + emitBlock(ef) + emitBlockResult(ef) + stream.println("}") + stream.println("}") case HashMapApply(m,k) => emitValDef(sym, src"$m($k)") case HashMapUpdate(m,k,v) => emitValDef(sym, src"$m($k) = $v") case HashMapContains(m,i) => emitValDef(sym, src"$m.contains($i)") case HashMapSize(m) => emitValDef(sym, src"$m.size") case HashMapValues(m) => emitValDef(sym, src"$m.values") case HashMapClear(m) => emitValDef(sym, src"$m.clear()") - case HashMapKeySet(m) => emitValDef(sym, src"$m.keySet") + case HashMapKeySet(m) => emitValDef(sym, src"collection.mutable.Set($m.keySet.toSeq:_*)") case HashMapKeys(m) => emitValDef(sym, src"$m.keys") + case HashMapHead(m) => emitValDef(sym, src"$m.head") + case HashMapRemoveHead(m,s) => { + emitValDef(s, src"$m.head") + gen"$m -= $s._1" + emitValDef(sym, quote(s)) + } + // We assume that the element to be removed exists for sure for simplicitly + case HashMapRemove(m,k) => emitValDef(sym, src"$m.remove($k).get") + case HashMapMap(m,k,v) => { + emitValDef(sym, quote(m) + ".map(" + quote(k) + "=> {") + emitBlock(v) + emitBlockResult(v) + stream.println("})") + } + case HashMapForeach(m,k,v) => { + emitValDef(sym, quote(m) + ".foreach(" + quote(k) + "=> {") + emitBlock(v) + emitBlockResult(v) + stream.println("})") + } + case HashMapGetOrElseUpdate(m,k,v) => { + emitValDef(sym, quote(m) + ".getOrElseUpdate(" + quote(k) + ",{") + emitBlock(v) + emitBlockResult(v) + stream.println("})") + } + case HashMapMkString(m,k) => emitValDef(sym, src"$m.mkString($k)") case _ => super.emitNode(sym, rhs) } -*/ } trait CLikeGenHashMapOps extends BaseGenHashMapOps with CLikeCodegen { val IR: HashMapOpsExp import IR._ -// override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { -// case _ => super.emitNode(sym, rhs) -// } + override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { + case m@HashMapExtendedNew(k,hf,v1,v2,ef) => + LIRTraversal(hf) + LIRTraversal(ef) + sym.atPhase(LIRLowering) { + val lhf = LIRLowering(hf) + val lef = LIRLowering(ef) + val nvt = remapManifest(fresh(m.mV)) + val lkM = remapManifest(fresh(m.mK))(m.mK) + k.tp = lkM + v1.tp = lkM + v2.tp = lkM + reflectMutable(HashMapExtendedNew(k,lhf,v1,v2,lef)(m.mK,nvt)).asInstanceOf[Exp[A]] + } + case ma@HashMapApply(m,k) => + sym.atPhase(LIRLowering) { + reflectEffect(HashMapApply(LIRLowering(m).asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],LIRLowering(k))).asInstanceOf[Exp[A]] + } + case gu@HashMapGetOrElseUpdate(m,k,v) => + LIRTraversal(v) + sym.atPhase(LIRLowering) { + val vb = LIRLowering(v) + val hm = LIRLowering(m) + val nvt = remapManifest(fresh(vb.tp)) + val c = hashmap_apply(hm.asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],LIRLowering(k))(gu.mK,nvt.asInstanceOf[Manifest[A]],implicitly[SourceContext]) + val cc = reflectEffect(IfThenElse ((c == unit(null)), vb, Block(c))) + __ifThenElse ((cc != c), hashmap_update(hm.asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],LIRLowering(k),cc), ()) + cc.asInstanceOf[Exp[A]] + } + case ks@HashMapKeySet(m) => sym.atPhase(LIRLowering) { + hashmap_keyset(LIRLowering(m))(remapManifest(fresh(ks.mK))(ks.mK).asInstanceOf[Manifest[Any]],ks.mV,implicitly[SourceContext]).asInstanceOf[Exp[A]] + } + case r@HashMapRemove(m,k) => { + sym.atPhase(LIRLowering) { + val hm = LIRLowering(m) + val nvt = remapManifest(fresh(r.ccc))(r.ccc) + val c = hashmap_apply(hm.asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],LIRLowering(k))(r.mK,nvt.asInstanceOf[Manifest[A]],implicitly[SourceContext]) + hashmap_remove(hm.asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]], LIRLowering(k)) + c.asInstanceOf[Exp[A]] + } + } + case _ => super.lowerNode(sym,rhs) + } + + override def remap[A](m: Manifest[A]) = m match { + case s if m <:< manifest[scala.collection.mutable.HashMap[Any,Any]] => "GHashTable *" + case _ => super.remap(m) + } + + def remapKeyIfPrimitive(k: Exp[Any]) = k.tp match { + case s if s == manifest[Int] || s == manifest[Double] || s == manifest[Long] => "GINT_TO_POINTER(" + quote(k) + ")" + case _ => quote(k) + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case m@HashMapNew() => { + m.mK match { + case s if s == manifest[java.lang.String] => + emitValDef(sym, "g_hash_table_new(g_str_hash, g_str_equal)") + case s if s == manifest[Int] || s == manifest[Double] || s == manifest[Long] => + emitValDef(sym, "g_hash_table_new(g_direct_hash, g_direct_equal)") + case _ => throw new Exception("Unknown primitive type " + m.mK + " for CCodegen of HashMapNew.") + } + } + case m@HashMapExtendedNew(k,hf,v1,v2,ef) => { + val uhf = uninlinedFunc1(k,hf) + val uef = uninlinedFunc2(v1,v2,ef) + emitValDef(sym, "g_hash_table_new((GHashFunc)" + quote(uhf) + ",(GEqualFunc)" + quote(uef) + ")") + } + case HashMapSize(m) => emitValDef(sym, "g_hash_table_size(" + quote(m) + ");") + case HashMapApply(m,k) => emitValDef(sym, "g_hash_table_lookup(" + quote(m) + "," + remapKeyIfPrimitive(k) + ");"); + case HashMapUpdate(m,k,v) => stream.println("g_hash_table_insert(" + quote(m) + "," + remapKeyIfPrimitive(k) + "," + quote(v) + ");"); + case HashMapKeySet(m) => emitValDef(sym, "g_hash_table_get_keys(" + quote(m) + ")") + case HashMapRemove(m,k) => + emitValDef(sym, "g_hash_table_lookup(" + quote(m) + "," + remapKeyIfPrimitive(k) + ");"); + stream.println("g_hash_table_remove(" + quote(m) + "," + remapKeyIfPrimitive(k) + ");"); + case HashMapClear(m) => stream.println("g_hash_table_remove_all(" + quote(m) + ");") + case HashMapContains(m,k) => emitValDef(sym, "g_hash_table_lookup(" + quote(m) + "," + remapKeyIfPrimitive(k) + ") != NULL") + case _ => super.emitNode(sym, rhs) + } } trait CudaGenHashMapOps extends CudaGenEffect with CLikeGenHashMapOps diff --git a/src/common/IOOps.scala b/src/common/IOOps.scala index 62f9e076..bebbbbaf 100644 --- a/src/common/IOOps.scala +++ b/src/common/IOOps.scala @@ -1,8 +1,8 @@ -package scala.lms +package scala.virtualization.lms package common -import java.io.{File, FileReader, FileWriter, BufferedReader, BufferedWriter, PrintWriter} -import scala.lms.internal.{GenerationFailedException} +import java.io.{File, FileReader, FileWriter, BufferedReader, BufferedWriter, PrintWriter, FileOutputStream, ObjectOutputStream, FileInputStream, ObjectInputStream} +import scala.virtualization.lms.internal.{GenerationFailedException, GenericNestedCodegen} import util.OverloadHack import scala.reflect.SourceContext @@ -19,11 +19,13 @@ trait IOOps extends Variables with OverloadHack { def infix_getCanonicalFile(f: Rep[File])(implicit pos: SourceContext) = file_getcanonicalfile(f) def infix_getPath(f: Rep[File])(implicit pos: SourceContext) = file_getpath(f) def infix_listFiles(f: Rep[File])(implicit pos: SourceContext) = file_listfiles(f) + def infix_close(f: Rep[File])(implicit pos: SourceContext, o: Overloaded1) = file_close(f) // Only for the C code gen def obj_file_apply(dir: Rep[String])(implicit pos: SourceContext): Rep[File] def file_getcanonicalfile(f: Rep[File])(implicit pos: SourceContext): Rep[File] def file_getpath(f: Rep[File])(implicit pos: SourceContext): Rep[String] def file_listfiles(f: Rep[File])(implicit pos: SourceContext): Rep[Array[File]] + def file_close(f: Rep[File])(implicit pos: SourceContext): Rep[Unit] // Only for the C code gen /** * BufferedReader @@ -32,7 +34,7 @@ trait IOOps extends Variables with OverloadHack { def apply(f: Rep[FileReader])(implicit pos: SourceContext) = obj_br_apply(f) } def infix_readLine(b: Rep[BufferedReader])(implicit pos: SourceContext) = br_readline(b) - def infix_close(b: Rep[BufferedReader])(implicit pos: SourceContext) = br_close(b) + def infix_close(b: Rep[BufferedReader])(implicit pos: SourceContext, o: Overloaded2) = br_close(b) def obj_br_apply(f: Rep[FileReader])(implicit pos: SourceContext): Rep[BufferedReader] def br_readline(b: Rep[BufferedReader])(implicit pos: SourceContext): Rep[String] @@ -67,6 +69,58 @@ trait IOOps extends Variables with OverloadHack { def apply(s: Rep[String])(implicit pos: SourceContext) = obj_fw_apply(s) } def obj_fw_apply(s: Rep[String])(implicit pos: SourceContext): Rep[FileWriter] + + /** + * ObjectOutputStream + */ + object FileInputStream { + def apply(s: Rep[String])(implicit pos: SourceContext) = obj_fis_apply(s) + } + class FileInputStreamOps(x: Rep[FileInputStream]) { + def available()(implicit pos: SourceContext) = obj_fis_available(x) + } + implicit def fisToFisOps(x: Rep[FileInputStream]) = new FileInputStreamOps(x) + def obj_fis_apply(s: Rep[String]): Rep[FileInputStream] + def obj_fis_available(s: Rep[FileInputStream]): Rep[Int] + + object ObjectInputStream { + def apply(s: Rep[FileInputStream])(implicit pos: SourceContext) = obj_ois_apply(s) + } + class ObjectInputStreamOps(x: Rep[ObjectInputStream]) { + def readObject(dynamicType: String = null)(implicit pos: SourceContext) = obj_ois_readObject(x, dynamicType) + def close()(implicit pos: SourceContext) = obj_ois_close(x) + } + implicit def oisTooisOps(x: Rep[ObjectInputStream]) = new ObjectInputStreamOps(x) + def obj_ois_apply(s: Rep[FileInputStream]): Rep[ObjectInputStream] + def obj_ois_close(s: Rep[ObjectInputStream]): Rep[Unit] + def obj_ois_readObject(x: Rep[ObjectInputStream], dynamicType: String = null): Rep[Object] + + object ObjectOutputStream { + def apply(s: Rep[FileOutputStream])(implicit pos: SourceContext) = obj_oos_apply(s, unit(false)) + def apply(s: Rep[FileOutputStream], x: Rep[Boolean])(implicit pos: SourceContext) = obj_oos_apply(s, x) + } + class ObjectOutputStreamOps(x: Rep[ObjectOutputStream]) { + def writeObject(elem: Rep[Any])(implicit pos: SourceContext) = obj_oos_writeObject(x,elem) + def close()(implicit pos: SourceContext) = obj_oos_close(x) + } + implicit def oosToOoosOps(x: Rep[ObjectOutputStream]) = new ObjectOutputStreamOps(x) + def obj_oos_apply(s: Rep[FileOutputStream], x: Rep[Boolean])(implicit pos: SourceContext): Rep[ObjectOutputStream] + def obj_oos_writeObject(s: Rep[ObjectOutputStream], elem: Rep[Any])(implicit pos: SourceContext): Rep[Unit] + def obj_oos_close(s: Rep[ObjectOutputStream])(implicit pos: SourceContext): Rep[Unit] + + /** + * FileWriter + */ + object FileOutputStream { + def apply(s: Rep[File])(implicit pos: SourceContext) = obj_fos_apply(s) + } + def obj_fos_apply(s: Rep[File])(implicit pos: SourceContext): Rep[FileOutputStream] + + object FileLineCount { + def apply(s: Rep[String])(implicit pos: SourceContext) = file_line_count(s) + } + def file_line_count(s: Rep[String])(implicit pos: SourceContext): Rep[Int] + } trait IOOpsExp extends IOOps with DSLOpsExp { @@ -74,42 +128,66 @@ trait IOOpsExp extends IOOps with DSLOpsExp { case class FileGetCanonicalFile(f: Exp[File]) extends Def[File] case class FileGetPath(f: Exp[File]) extends Def[String] case class FileListFiles(f: Exp[File]) extends Def[Array[File]] + case class FileClose(f: Exp[File]) extends Def[Unit] // Only for the C code gen case class ObjBrApply(f: Exp[FileReader]) extends Def[BufferedReader] case class ObjBwApply(f: Exp[FileWriter]) extends Def[BufferedWriter] case class ObjFrApply(s: Exp[String]) extends Def[FileReader] case class ObjFwApply(s: Exp[String]) extends Def[FileWriter] + case class ObjOosApply(s: Exp[FileOutputStream], x: Rep[Boolean]) extends Def[ObjectOutputStream] + case class ObjOosWriteObject(s: Exp[ObjectOutputStream], elem: Exp[Any]) extends Def[Unit] + case class ObjOosClose(s: Exp[ObjectOutputStream]) extends Def[Unit] + case class ObjFosApply(s: Exp[File]) extends Def[FileOutputStream] + case class ObjFisApply(s: Exp[String]) extends Def[FileInputStream] + case class ObjOisApply(s: Exp[FileInputStream]) extends Def[ObjectInputStream] + case class ObjOisClose(s: Exp[ObjectInputStream]) extends Def[Unit] + case class ObjOisAvailable(s: Exp[FileInputStream]) extends Def[Int] + case class ObjOisReadObject(s: Exp[ObjectInputStream], dynamicType: String = null) extends Def[Object] case class BwWrite(b: Exp[BufferedWriter], s: Rep[String]) extends Def[Unit] case class BwClose(b: Exp[BufferedWriter]) extends Def[Unit] case class BrReadline(b: Exp[BufferedReader]) extends Def[String] case class BrClose(b: Exp[BufferedReader]) extends Def[Unit] + case class CountFileLines(b: Exp[String]) extends Def[Int] { + val f = fresh[java.io.File] // used in c code gen + } def obj_file_apply(dir: Exp[String])(implicit pos: SourceContext): Exp[File] = reflectEffect(ObjFileApply(dir)) def file_getcanonicalfile(f: Exp[File])(implicit pos: SourceContext) = FileGetCanonicalFile(f) def file_getpath(f: Exp[File])(implicit pos: SourceContext) = FileGetPath(f) def file_listfiles(f: Exp[File])(implicit pos: SourceContext) = FileListFiles(f) + def file_close(f: Exp[File])(implicit pos: SourceContext) = FileClose(f) // Only for the C code gen def obj_br_apply(f: Exp[FileReader])(implicit pos: SourceContext): Exp[BufferedReader] = reflectEffect(ObjBrApply(f)) def obj_bw_apply(f: Exp[FileWriter])(implicit pos: SourceContext): Exp[BufferedWriter] = reflectEffect(ObjBwApply(f)) def obj_fr_apply(s: Exp[String])(implicit pos: SourceContext): Exp[FileReader] = reflectEffect(ObjFrApply(s)) def obj_fw_apply(s: Exp[String])(implicit pos: SourceContext): Exp[FileWriter] = reflectEffect(ObjFwApply(s)) + def obj_oos_apply(s: Exp[FileOutputStream], x: Rep[Boolean])(implicit pos: SourceContext): Exp[ObjectOutputStream] = reflectEffect(ObjOosApply(s,x)) + def obj_oos_writeObject(s: Exp[ObjectOutputStream], elem: Exp[Any])(implicit pos: SourceContext): Exp[Unit] = reflectEffect(ObjOosWriteObject(s, elem)) + def obj_oos_close(s: Exp[ObjectOutputStream])(implicit pos: SourceContext): Exp[Unit] = reflectEffect(ObjOosClose(s)) + def obj_fos_apply(s: Exp[File])(implicit pos: SourceContext): Exp[FileOutputStream] = reflectEffect(ObjFosApply(s)) + def obj_fis_apply(s: Rep[String]) = reflectEffect(ObjFisApply(s)) + def obj_ois_apply(s: Rep[FileInputStream]) = reflectEffect(ObjOisApply(s)) + def obj_ois_close(s: Rep[ObjectInputStream]) = reflectEffect(ObjOisClose(s)) + def obj_fis_available(s: Rep[FileInputStream]) = reflectEffect(ObjOisAvailable(s)) + def obj_ois_readObject(x: Rep[ObjectInputStream], dynamicType: String = null) = reflectEffect(ObjOisReadObject(x, dynamicType)) def bw_write(b: Exp[BufferedWriter], s: Exp[String])(implicit pos: SourceContext) = reflectEffect(BwWrite(b,s)) def bw_close(b: Exp[BufferedWriter])(implicit pos: SourceContext) = reflectEffect(BwClose(b)) def br_readline(b: Exp[BufferedReader])(implicit pos: SourceContext) : Exp[String] = reflectEffect(BrReadline(b)) def br_close(b: Exp[BufferedReader])(implicit pos: SourceContext) : Exp[Unit] = reflectEffect(BrClose(b)) + def file_line_count(s: Rep[String])(implicit pos: SourceContext) = reflectEffect(CountFileLines(s)) override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = ({ e match { - case Reflect(ObjFrApply(s), u, es) => reflectMirrored(Reflect(ObjFrApply(f(s)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjBrApply(x), u, es) => reflectMirrored(Reflect(ObjBrApply(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjFwApply(s), u, es) => reflectMirrored(Reflect(ObjFwApply(f(s)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjBwApply(x), u, es) => reflectMirrored(Reflect(ObjBwApply(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(BrReadline(b), u, es) => reflectMirrored(Reflect(BrReadline(f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(BwWrite(b,s), u, es) => reflectMirrored(Reflect(BwWrite(f(b),f(s)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(BrClose(b), u, es) => reflectMirrored(Reflect(BrClose(f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(BwClose(b), u, es) => reflectMirrored(Reflect(BwClose(f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(ObjFrApply(s), u, es) => obj_fr_apply(f(s)) + case Reflect(ObjBrApply(x), u, es) => obj_br_apply(f(x)) + case Reflect(ObjFwApply(s), u, es) => obj_fw_apply(f(s)) + case Reflect(ObjBwApply(x), u, es) => obj_bw_apply(f(x)) + case Reflect(BrReadline(b), u, es) => br_readline(f(b)) + case Reflect(BwWrite(b,s), u, es) => bw_write(f(b),f(s)) + case Reflect(BrClose(b), u, es) => br_close(f(b)) + case Reflect(BwClose(b), u, es) => bw_close(f(b)) case _ => super.mirror(e,f) } }).asInstanceOf[Exp[A]] @@ -124,32 +202,68 @@ trait ScalaGenIOOps extends ScalaGenBase { case FileGetCanonicalFile(f) => emitValDef(sym, src"$f.getCanonicalFile()") case FileGetPath(f) => emitValDef(sym, src"$f.getPath()") case FileListFiles(f) => emitValDef(sym, src"$f.listFiles()") + case FileClose(f) => throw new GenerationFailedException("File.close is not defined for Scala Generation, only for C! Maybe you meant to close the BufferedStreams instead.") case ObjBrApply(f) => emitValDef(sym, src"new java.io.BufferedReader($f)") case ObjBwApply(f) => emitValDef(sym, src"new java.io.BufferedWriter($f)") case ObjFrApply(s) => emitValDef(sym, src"new java.io.FileReader($s)") case ObjFwApply(s) => emitValDef(sym, src"new java.io.FileWriter($s)") + case ObjOosApply(s,x) => + if (x == Const(true)) { + emitValDef(sym, src"new java.io.ObjectOutputStream($s){") + gen"""override protected def writeStreamHeader() { + |reset(); + |} + |}""" + } else emitValDef(sym, src"new java.io.ObjectOutputStream($s)") + case ObjOosWriteObject(s, elem) => gen"$s.writeObject($elem)" + case ObjOosClose(s) => gen"$s.close" + case ObjFosApply(s) => emitValDef(sym, src"new java.io.FileOutputStream($s,true)") + case ObjFisApply(s) => emitValDef(sym, src"new java.io.FileInputStream($s)") + case ObjOisApply(s) => emitValDef(sym, src"new java.io.ObjectInputStream($s)") + case ObjOisClose(s) => emitValDef(sym, src"$s.close") + case ObjOisAvailable(s) => emitValDef(sym, src"$s.available") + case ObjOisReadObject(s, dtype) => { + if (dtype == null) emitValDef(sym, src"$s.readObject") + else emitValDef(sym, src"$s.readObject.asInstanceOf[$dtype]") + } case BwWrite(b,s) => emitValDef(sym, src"$b.write($s)") case BwClose(b) => emitValDef(sym, src"$b.close()") case BrReadline(b) => emitValDef(sym, src"$b.readLine()") case BrClose(b) => emitValDef(sym, src"$b.close()") + case CountFileLines(b) => emitValDef(sym, "{import scala.sys.process._; Integer.parseInt(((\"wc -l \" +" + quote(b) + ") #| \"awk {print($1)}\" !!).replaceAll(\"\\\\s+$\", \"\"))}") case _ => super.emitNode(sym, rhs) } } -trait CLikeGenIOOps extends CLikeGenBase { +trait CLikeGenIOOps extends CLikeGenBase with GenericNestedCodegen { val IR: IOOpsExp import IR._ + override def remap[A](m: Manifest[A]) = { + m match { + case s if s == manifest[File] => "FILE*" + case _ => super.remap(m) + } + } + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ObjFileApply(dir) => emitValDef(sym, "fopen(" + quote(dir) + ", \"rw\")") + case ObjOosApply(s,x) => quote(s) + case ObjFosApply(s) => quote(s) + case FileClose(s) => stream.println("fclose(" + quote(s) + ")") case ObjBrApply(f) => throw new GenerationFailedException("CLikeGenIOOps: Java IO operations are not supported") case ObjFrApply(s) => throw new GenerationFailedException("CLikeGenIOOps: Java IO operations are not supported") case BrReadline(b) => throw new GenerationFailedException("CLikeGenIOOps: Java IO operations are not supported") case BrClose(b) => throw new GenerationFailedException("CLikeGenIOOps: Java IO operations are not supported") + case c@CountFileLines(b) => { + emitValDef(c.f, "popen(\"wc -l " + quote(b).replace("\"","") + "\",\"r\");") + stream.println("int " + quote(sym) + " = 0;") + stream.println("fscanf(" + quote(c.f) + ",\"%d\", &" + quote(sym) + ");") + stream.println("pclose(" + quote(c.f) + ");") + } case _ => super.emitNode(sym, rhs) } } trait CudaGenIOOps extends CudaGenBase with CLikeGenIOOps trait OpenCLGenIOOps extends OpenCLGenBase with CLikeGenIOOps -trait CGenIOOps extends CGenBase with CLikeGenIOOps - - +trait CGenIOOps extends CGenBase with CLikeGenIOOps diff --git a/src/common/IfThenElse.scala b/src/common/IfThenElse.scala index c691c9cf..6aa74c75 100644 --- a/src/common/IfThenElse.scala +++ b/src/common/IfThenElse.scala @@ -1,9 +1,9 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.lms.internal.{GenericNestedCodegen, GenericFatCodegen, GenerationFailedException} +import scala.virtualization.lms.internal.{GenericNestedCodegen, GenericFatCodegen, GenerationFailedException} trait IfThenElse extends Base { def __ifThenElse[T:Manifest](cond: Rep[Boolean], thenp: => Rep[T], elsep: => Rep[T])(implicit pos: SourceContext): Rep[T] @@ -40,7 +40,7 @@ trait IfThenElseExp extends IfThenElse with EffectExp { val a = reifyEffectsHere(thenp) val b = reifyEffectsHere(elsep) - ifThenElse(cond,a,b) + ifThenElse[T](cond,a,b) } def ifThenElse[T:Manifest](cond: Rep[Boolean], thenp: Block[T], elsep: Block[T])(implicit pos: SourceContext) = { @@ -54,7 +54,7 @@ trait IfThenElseExp extends IfThenElse with EffectExp { // (see TestMutation, for now sticking to old behavior) ////reflectEffect(IfThenElse(cond,thenp,elsep), ae orElse be) - reflectEffectInternal(IfThenElse(cond,thenp,elsep), ae orElse be) + reflectEffectInternal(IfThenElse[T](cond,thenp,elsep), ae orElse be) } override def mirrorDef[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Def[A] = e match { @@ -67,7 +67,7 @@ trait IfThenElseExp extends IfThenElse with EffectExp { if (f.hasContext) __ifThenElse(f(c),f.reflectBlock(a),f.reflectBlock(b)) else - reflectMirrored(Reflect(IfThenElse(f(c),f(a),f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + reflectMirrored(Reflect(IfThenElse(f(c),f(a),f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) case IfThenElse(c,a,b) => if (f.hasContext) __ifThenElse(f(c),f.reflectBlock(a),f.reflectBlock(b)) @@ -200,6 +200,12 @@ trait IfThenElseExpOpt extends IfThenElseExp { this: BooleanOpsExp with EqualExp } } + + + + + + trait BaseGenIfThenElse extends GenericNestedCodegen { val IR: IfThenElseExp import IR._ @@ -229,13 +235,18 @@ trait ScalaGenIfThenElse extends ScalaGenEffect with BaseGenIfThenElse { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case IfThenElse(c,a,b) => - stream.println("val " + quote(sym) + " = if (" + quote(c) + ") {") - emitBlock(a) - stream.println(quote(getBlockResult(a))) - stream.println("} else {") - emitBlock(b) - stream.println(quote(getBlockResult(b))) - stream.println("}") + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + stream.println("if (" + quote(c) + ") {") + emitBlock(a) + emitBlockResult(a) + stream.println("} else {") + emitBlock(b) + emitBlockResult(b) + stream.print("}") + } + emitValDef(sym, strWriter.toString) case _ => super.emitNode(sym, rhs) } } @@ -245,7 +256,7 @@ trait ScalaGenIfThenElseFat extends ScalaGenIfThenElse with ScalaGenFat with Bas override def emitFatNode(symList: List[Sym[Any]], rhs: FatDef) = rhs match { case SimpleFatIfThenElse(c,as,bs) => - def quoteList[T](xs: List[Exp[T]]) = if (xs.length > 1) xs.map(quote).mkString("(",",",")") else xs.map(quote).mkString(",") + def quoteList[T](xs: List[Exp[T]]) = if (xs.length > 1) xs.map(x => quote(x, true)).mkString("(",",",")") else xs.map(x => quote(x,true)).mkString(",") if (symList.length > 1) stream.println("// TODO: use vars instead of tuples to return multiple values") stream.println("val " + quoteList(symList) + " = if (" + quote(c) + ") {") emitFatBlock(as) @@ -372,40 +383,40 @@ trait OpenCLGenIfThenElseFat extends OpenCLGenIfThenElse with OpenCLGenFat with trait CGenIfThenElse extends CGenEffect with BaseGenIfThenElse { import IR._ + override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { + case IfThenElse(c,a,b) => { + LIRTraversal(a) + LIRTraversal(b) + sym.atPhase(LIRLowering) { + val tc = LIRLowering(c) + val ta = LIRLowering(a) + val tb = LIRLowering(b) + reflectEffect(IfThenElse(tc, ta, tb)(tb.tp.asInstanceOf[Manifest[T]])).asInstanceOf[Exp[T]] + } + } + case _ => super.lowerNode(sym, rhs) + } + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { case IfThenElse(c,a,b) => - //TODO: using if-else does not work - remap(sym.tp) match { - case "void" => + //TODO: using if-else does noIIIt work + isVoidType(sym.tp) match { + case true => stream.println("if (" + quote(c) + ") {") emitBlock(a) stream.println("} else {") emitBlock(b) stream.println("}") - case _ => - if (cppIfElseAutoRet == "true") { - val ten = quote(sym) + "True" - val fen = quote(sym) + "False" - def emitCondFun[T: Manifest](fname: String, block: Block[T]) { - stream.println("auto " + fname + " = [&]() {"); - emitBlock(block) - stream.println("return " + quote(getBlockResult(block)) + ";") - stream.println("};") - } - emitCondFun(ten, a) - emitCondFun(fen, b) - stream.println("auto " + quote(sym) + " = " + quote(c) + " ? " + ten + "() : " + fen + "();") - } else { - stream.println("%s %s;".format(remap(sym.tp),quote(sym))) - stream.println("if (" + quote(c) + ") {") - emitBlock(a) - stream.println("%s = %s;".format(quote(sym),quote(getBlockResult(a)))) - stream.println("} else {") - emitBlock(b) - stream.println("%s = %s;".format(quote(sym),quote(getBlockResult(b)))) - stream.println("}") - } + case false => + stream.println("%s %s;".format(remap(getBlockResult(a).tp),quote(sym))) + stream.println("if (" + quote(c) + ") {") + emitBlock(a) + stream.println("%s = %s;".format(quote(sym),quote(getBlockResult(a)))) + stream.println("} else {") + emitBlock(b) + stream.println("%s = %s;".format(quote(sym),quote(getBlockResult(b)))) + stream.println("}") } /* val booll = remap(sym.tp).equals("void") @@ -436,7 +447,17 @@ trait CGenIfThenElseFat extends CGenIfThenElse with CGenFat with BaseGenIfThenEl import IR._ override def emitFatNode(symList: List[Sym[Any]], rhs: FatDef) = rhs match { - case SimpleFatIfThenElse(c,a,b) => sys.error("TODO: implement fat if C codegen") + case SimpleFatIfThenElse(c,as,bs) => + def quoteList[T](xs: List[Exp[T]]) = if (xs.length > 1) xs.map(x => quote(x, true)).mkString("(",",",")").replace("()","") else xs.map(x => quote(x,true)).mkString(",").replace("()","") + if (symList.length > 1) stream.println("// TODO: use vars instead of tuples to return multiple values") + stream.println("if (" + quote(c) + ") {") + emitFatBlock(as) + stream.println(quoteList(as.map(getBlockResult))) + stream.println("} else {") + emitFatBlock(bs) + stream.println(quoteList(bs.map(getBlockResult))) + stream.println("}") + case _ => super.emitFatNode(symList, rhs) } } diff --git a/src/common/ImplicitOps.scala b/src/common/ImplicitOps.scala index 37372160..da88a99b 100644 --- a/src/common/ImplicitOps.scala +++ b/src/common/ImplicitOps.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter diff --git a/src/common/IterableOps.scala b/src/common/IterableOps.scala index 57d44740..296b32cc 100644 --- a/src/common/IterableOps.scala +++ b/src/common/IterableOps.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter @@ -39,8 +39,8 @@ trait IterableOpsExp extends IterableOps with EffectExp with VariablesExp { override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { (e match { case e@IterableToArray(x) => iterable_toarray(f(x))(e.m,pos) - case Reflect(e@IterableForeach(x,y,b), u, es) => reflectMirrored(Reflect(IterableForeach(f(x),f(y).asInstanceOf[Sym[_]],f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@IterableToArray(x), u, es) => reflectMirrored(Reflect(IterableToArray(f(x))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@IterableForeach(x,y,b), u, es) => reflectMirrored(Reflect(IterableForeach(f(x),f(y).asInstanceOf[Sym[_]],f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@IterableToArray(x), u, es) => reflectMirrored(Reflect(IterableToArray(f(x))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] // why?? } @@ -73,11 +73,11 @@ trait ScalaGenIterableOps extends BaseGenIterableOps with ScalaGenBase { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case IterableForeach(a,x,block) => - gen"""val $sym=$a.foreach{ - |$x => - |${nestedBlock(block)} - |$block - |}""" + gen"""$a.foreach{ + |$x => + |${nestedBlock(block)} + |$block + |}""" case IterableToArray(a) => emitValDef(sym, src"$a.toArray") case _ => super.emitNode(sym, rhs) } diff --git a/src/common/Iterator.scala b/src/common/Iterator.scala new file mode 100644 index 00000000..fbd00297 --- /dev/null +++ b/src/common/Iterator.scala @@ -0,0 +1,58 @@ +package scala.virtualization.lms.common + +import scala.virtualization.lms.internal._ + +trait Iterator extends Base with Variables { + class IteratorOps[A: Manifest](x: Rep[scala.Iterator[A]]) { + def hasNext() = iteratorHasNext(x) + def next() = iteratorNext(x) + def isEmpty() = iteratorIsEmpty(x) + def size() = iteratorSize(x) // Usefull for debugging but consumes all elements + def head() = iteratorHead(x) + } + + implicit def Iter2IteratorOps[A: Manifest](x: Rep[scala.Iterator[A]]) = new IteratorOps[A](x) + implicit def varIterToIteratorOps[A: Manifest](x: Var[scala.Iterator[A]]) = new IteratorOps[A](readVar(x)) + implicit def BufIter2IteratorOps[A: Manifest](x: Rep[scala.BufferedIterator[A]]) = new IteratorOps[A](x) + implicit def varBufIterToIteratorOps[A: Manifest](x: Var[scala.BufferedIterator[A]]) = new IteratorOps[A](readVar(x)) + + def iteratorHasNext[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[Boolean] + def iteratorNext[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[A] + def iteratorIsEmpty[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[Boolean] + def iteratorSize[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[Int] + def iteratorHead[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[A] +} + +trait IteratorExp extends Iterator with BaseExp with Effects /*with VariablesExp*/ { + case class IteratorHasNext[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[Boolean] + case class IteratorNext[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[A] + case class IteratorIsEmpty[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[Boolean] + case class IteratorSize[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[Int] + case class IteratorHead[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[A] + + def iteratorHasNext[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorHasNext[A](x)) + def iteratorNext[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorNext[A](x)) + def iteratorIsEmpty[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorIsEmpty[A](x)) + def iteratorSize[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorSize[A](x)) + def iteratorHead[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorHead[A](x)) +} + +trait ScalaGenIterator extends ScalaGenBase { + val IR: IteratorExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case IteratorHasNext(x) => + emitValDef(sym, quote(x) + ".hasNext") + case IteratorNext(x) => + emitValDef(sym, quote(x) + ".next") + case IteratorIsEmpty(x) => + emitValDef(sym, quote(x) + ".isEmpty") + case IteratorSize(x) => + emitValDef(sym, quote(x) + ".length") + // Note that this will throw an error at runtime if x is Iterator instead of BufferedIterator + case IteratorHead(x) => + emitValDef(sym, quote(x) + ".head") + case _ => super.emitNode(sym, rhs) + } +} diff --git a/src/common/ListBuffer.scala b/src/common/ListBuffer.scala new file mode 100644 index 00000000..520f3cb0 --- /dev/null +++ b/src/common/ListBuffer.scala @@ -0,0 +1,96 @@ +package scala.virtualization.lms.common + +import scala.collection.mutable +import scala.virtualization.lms.internal._ + +trait ListBuffer extends Base with Expressions with Variables { + class ListBufferOps[A:Manifest](x: Rep[mutable.ListBuffer[A]]) { + def +=(v: Rep[Any]) = listBufferAdd(x, v) + def remove(v: Rep[Int]) = listBufferRemove(x, v) + def size() = listBufferSize(x) + def head() = listBufferHead(x) + def mkString(v: Rep[String]) = listBufferMkString(x,v) + def foreach[B: Manifest](f: Rep[A] => Rep[B]) = listBufferforeach[A,B](x, f) + } + + implicit def listBuffer2listBufferOps[A:Manifest](x: Rep[mutable.ListBuffer[A]]) = new ListBufferOps(x) + implicit def varlistBuffer2listBufferOps[A:Manifest](x: Var[mutable.ListBuffer[A]]) = new ListBufferOps(readVar(x)) + + def newListBuffer[A:Manifest](): Rep[mutable.ListBuffer[A]] + def listBufferAdd[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Any]): Rep[Unit] + def listBufferRemove[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Int]): Rep[A] + def listBufferSize[A:Manifest](x: Rep[mutable.ListBuffer[A]]): Rep[Int] + def listBufferHead[A:Manifest](x: Rep[mutable.ListBuffer[A]]): Rep[Any] + def listBufferMkString[A:Manifest](x: Rep[mutable.ListBuffer[A]], y: Rep[String]): Rep[String] + def listBufferforeach[A:Manifest, B:Manifest](x: Rep[mutable.ListBuffer[A]], f: Rep[A] => Rep[B]): Rep[Unit] +} + +trait ListBufferExp extends ListBuffer with BaseExp with EffectExp with Effects { + case class ListBufferAdd[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Any]) extends Def[Unit] + case class ListBufferRemove[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Int]) extends Def[A] + case class ListBufferSize[A:Manifest](x: Rep[mutable.ListBuffer[A]]) extends Def[Int] + case class ListBufferHead[A:Manifest](x: Rep[mutable.ListBuffer[A]]) extends Def[Any] + case class NewListBuffer[A:Manifest]() extends Def[mutable.ListBuffer[A]] { + val m = manifest[A] + } + case class ListmkString[A:Manifest](x: Rep[mutable.ListBuffer[A]], y: Rep[String]) extends Def[String] + case class ListBufferForeach[A:Manifest, B:Manifest](l: Exp[mutable.ListBuffer[A]], x: Sym[A], block: Block[B]) extends Def[Unit] + + def newListBuffer[A:Manifest]() = reflectEffect(NewListBuffer[A]()) + def listBufferAdd[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Any]): Rep[Unit] = reflectEffect(ListBufferAdd(x,v)) + def listBufferRemove[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Int]): Rep[A] = reflectEffect(ListBufferRemove(x,v)) + def listBufferSize[A:Manifest](x: Rep[mutable.ListBuffer[A]]) = reflectEffect(ListBufferSize(x)) + def listBufferHead[A:Manifest](x: Rep[mutable.ListBuffer[A]]) = reflectEffect(ListBufferHead(x)) + def listBufferMkString[A:Manifest](x: Rep[mutable.ListBuffer[A]], y: Rep[String]) = ListmkString(x,y) + def listBufferforeach[A:Manifest, B:Manifest](x: Rep[mutable.ListBuffer[A]], f: Rep[A] => Rep[B]) = { + val a = fresh[A] + val b = reifyEffects(f(a)) + reflectEffect(ListBufferForeach(x, a, b), summarizeEffects(b).star) + } + + override def syms(e: Any): List[Sym[Any]] = e match { + case ListBufferForeach(a, x, body) => syms(a):::syms(body) + case _ => super.syms(e) + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case ListBufferForeach(a, x, body) => x :: effectSyms(body) + case _ => super.boundSyms(e) + } + + override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case ListBufferForeach(a, x, body) => freqNormal(a):::freqHot(body) + case _ => super.symsFreq(e) + } +} + +trait ScalaGenListBuffer extends ScalaGenBase with ScalaNestedCodegen { + val IR: ListBufferExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case l@NewListBuffer() => + emitValDef(sym, "new scala.collection.mutable.ListBuffer[" + remap(l.m) + "]") + case ListBufferAdd(x,v) => emitValDef(sym, quote(x) + " += " + quote(v)) + case ListBufferRemove(x,v) => emitValDef(sym, quote(x) + ".remove(" + quote(v) + ")") + case ListBufferSize(x) => emitValDef(sym, quote(x) + ".size") + case ListBufferHead(x) => emitValDef(sym, quote(x) + ".head") + case ListmkString(x,v) => emitValDef(sym, quote(x) + ".mkString(" + quote(v) + ")") + case ListBufferForeach(l,x,blk) => { + stream.println("val " + quote(sym) + " = " + quote(l) + ".foreach { "+ quote(x) + " => ") + emitBlock(blk) + stream.println(quote(getBlockResult(blk))) + stream.println("}") + } + case _ => super.emitNode(sym, rhs) + } +} + +trait CGenListBuffer extends CGenBase with CNestedCodegen { + val IR: ListBufferExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case _ => super.emitNode(sym, rhs) + } +} diff --git a/src/common/ListOps.scala b/src/common/ListOps.scala index d251d1bd..e3ab5d61 100644 --- a/src/common/ListOps.scala +++ b/src/common/ListOps.scala @@ -1,8 +1,8 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal.GenericNestedCodegen +import scala.virtualization.lms.internal.GenericNestedCodegen import scala.reflect.SourceContext trait ListOps extends Variables { @@ -10,6 +10,10 @@ trait ListOps extends Variables { object List { def apply[A:Manifest](xs: Rep[A]*)(implicit pos: SourceContext) = list_new(xs) } + + object NewList { + def apply[A:Manifest](xs: Rep[A]*)(implicit pos: SourceContext) = list_new(xs) + } implicit def varToListOps[T:Manifest](x: Var[List[T]]) = new ListOpsCls(readVar(x)) // FIXME: dep on var is not nice implicit def repToListOps[T:Manifest](a: Rep[List[T]]) = new ListOpsCls(a) @@ -17,23 +21,25 @@ trait ListOps extends Variables { class ListOpsCls[A:Manifest](l: Rep[List[A]]) { def map[B:Manifest](f: Rep[A] => Rep[B]) = list_map(l,f) + def foreach(f: Rep[A] => Rep[Unit]) = list_foreach(l,f) def flatMap[B : Manifest](f: Rep[A] => Rep[List[B]]) = list_flatMap(l,f) def filter(f: Rep[A] => Rep[Boolean]) = list_filter(l, f) def sortBy[B:Manifest:Ordering](f: Rep[A] => Rep[B]) = list_sortby(l,f) def ::(e: Rep[A]) = list_prepend(l,e) def ++ (l2: Rep[List[A]]) = list_concat(l, l2) def mkString = list_mkString(l) - def mkString(s:Rep[String]) = list_mkString2(l,s) def head = list_head(l) def tail = list_tail(l) def isEmpty = list_isEmpty(l) def toArray = list_toarray(l) def toSeq = list_toseq(l) + def contains(e: Rep[A]) = list_contains(l,e) } def list_new[A:Manifest](xs: Seq[Rep[A]])(implicit pos: SourceContext): Rep[List[A]] def list_fromseq[A:Manifest](xs: Rep[Seq[A]])(implicit pos: SourceContext): Rep[List[A]] def list_map[A:Manifest,B:Manifest](l: Rep[List[A]], f: Rep[A] => Rep[B])(implicit pos: SourceContext): Rep[List[B]] + def list_foreach[A:Manifest](l: Rep[List[A]], f: Rep[A] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] def list_flatMap[A : Manifest, B : Manifest](xs: Rep[List[A]], f: Rep[A] => Rep[List[B]])(implicit pos: SourceContext): Rep[List[B]] def list_filter[A : Manifest](l: Rep[List[A]], f: Rep[A] => Rep[Boolean])(implicit pos: SourceContext): Rep[List[A]] def list_sortby[A:Manifest,B:Manifest:Ordering](l: Rep[List[A]], f: Rep[A] => Rep[B])(implicit pos: SourceContext): Rep[List[A]] @@ -43,16 +49,19 @@ trait ListOps extends Variables { def list_concat[A:Manifest](xs: Rep[List[A]], ys: Rep[List[A]])(implicit pos: SourceContext): Rep[List[A]] def list_cons[A:Manifest](x: Rep[A], xs: Rep[List[A]])(implicit pos: SourceContext): Rep[List[A]] // FIXME remove? def list_mkString[A : Manifest](xs: Rep[List[A]])(implicit pos: SourceContext): Rep[String] - def list_mkString2[A : Manifest](xs: Rep[List[A]], sep:Rep[String])(implicit pos: SourceContext): Rep[String] def list_head[A:Manifest](xs: Rep[List[A]])(implicit pos: SourceContext): Rep[A] def list_tail[A:Manifest](xs: Rep[List[A]])(implicit pos: SourceContext): Rep[List[A]] def list_isEmpty[A:Manifest](xs: Rep[List[A]])(implicit pos: SourceContext): Rep[Boolean] + def list_contains[A:Manifest](xs: Rep[List[A]], e: Rep[A])(implicit pos: SourceContext): Rep[Boolean] } trait ListOpsExp extends ListOps with EffectExp with VariablesExp { - case class ListNew[A:Manifest](xs: Seq[Rep[A]]) extends Def[List[A]] + case class ListNew[A:Manifest](xs: Seq[Rep[A]]) extends Def[List[A]] { + val m = manifest[A] + } case class ListFromSeq[A:Manifest](xs: Rep[Seq[A]]) extends Def[List[A]] case class ListMap[A:Manifest,B:Manifest](l: Exp[List[A]], x: Sym[A], block: Block[B]) extends Def[List[B]] + case class ListForeach[A:Manifest](l: Exp[List[A]], x: Sym[A], block: Block[Unit]) extends Def[Unit] case class ListFlatMap[A:Manifest, B:Manifest](l: Exp[List[A]], x: Sym[A], block: Block[List[B]]) extends Def[List[B]] case class ListFilter[A : Manifest](l: Exp[List[A]], x: Sym[A], block: Block[Boolean]) extends Def[List[A]] case class ListSortBy[A:Manifest,B:Manifest:Ordering](l: Exp[List[A]], x: Sym[A], block: Block[B]) extends Def[List[A]] @@ -62,10 +71,10 @@ trait ListOpsExp extends ListOps with EffectExp with VariablesExp { case class ListConcat[A:Manifest](xs: Rep[List[A]], ys: Rep[List[A]]) extends Def[List[A]] case class ListCons[A:Manifest](x: Rep[A], xs: Rep[List[A]]) extends Def[List[A]] case class ListMkString[A:Manifest](l: Exp[List[A]]) extends Def[String] - case class ListMkString2[A:Manifest](l: Exp[List[A]], s: Exp[String]) extends Def[String] case class ListHead[A:Manifest](xs: Rep[List[A]]) extends Def[A] case class ListTail[A:Manifest](xs: Rep[List[A]]) extends Def[List[A]] case class ListIsEmpty[A:Manifest](xs: Rep[List[A]]) extends Def[Boolean] + case class ListContains[A:Manifest](xs: Rep[List[A]], e: Rep[A]) extends Def[Boolean] def list_new[A:Manifest](xs: Seq[Rep[A]])(implicit pos: SourceContext) = ListNew(xs) def list_fromseq[A:Manifest](xs: Rep[Seq[A]])(implicit pos: SourceContext) = ListFromSeq(xs) @@ -74,6 +83,11 @@ trait ListOpsExp extends ListOps with EffectExp with VariablesExp { val b = reifyEffects(f(a)) reflectEffect(ListMap(l, a, b), summarizeEffects(b).star) } + def list_foreach[A:Manifest](l: Exp[List[A]], f: Exp[A] => Exp[Unit])(implicit pos: SourceContext) = { + val a = fresh[A] + val b = reifyEffects(f(a)) + reflectEffect(ListForeach(l, a, b), summarizeEffects(b).star) + } def list_flatMap[A:Manifest, B:Manifest](l: Exp[List[A]], f: Exp[A] => Exp[List[B]])(implicit pos: SourceContext) = { val a = fresh[A] val b = reifyEffects(f(a)) @@ -95,10 +109,10 @@ trait ListOpsExp extends ListOps with EffectExp with VariablesExp { def list_concat[A:Manifest](xs: Rep[List[A]], ys: Rep[List[A]])(implicit pos: SourceContext) = ListConcat(xs,ys) def list_cons[A:Manifest](x: Rep[A], xs: Rep[List[A]])(implicit pos: SourceContext) = ListCons(x,xs) def list_mkString[A:Manifest](l: Exp[List[A]])(implicit pos: SourceContext) = ListMkString(l) - def list_mkString2[A:Manifest](l: Rep[List[A]], sep:Rep[String])(implicit pos: SourceContext) = ListMkString2(l,sep) def list_head[A:Manifest](xs: Rep[List[A]])(implicit pos: SourceContext) = ListHead(xs) def list_tail[A:Manifest](xs: Rep[List[A]])(implicit pos: SourceContext) = ListTail(xs) def list_isEmpty[A:Manifest](xs: Rep[List[A]])(implicit pos: SourceContext) = ListIsEmpty(xs) + def list_contains[A:Manifest](xs: Rep[List[A]], e: Rep[A])(implicit pos: SourceContext) = ListContains(xs,e) override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { (e match { @@ -109,6 +123,7 @@ trait ListOpsExp extends ListOps with EffectExp with VariablesExp { override def syms(e: Any): List[Sym[Any]] = e match { case ListMap(a, x, body) => syms(a):::syms(body) + case ListForeach(a, x, body) => syms(a):::syms(body) case ListFlatMap(a, _, body) => syms(a) ::: syms(body) case ListFilter(a, _, body) => syms(a) ::: syms(body) case ListSortBy(a, x, body) => syms(a):::syms(body) @@ -117,6 +132,7 @@ trait ListOpsExp extends ListOps with EffectExp with VariablesExp { override def boundSyms(e: Any): List[Sym[Any]] = e match { case ListMap(a, x, body) => x :: effectSyms(body) + case ListForeach(a, x, body) => x :: effectSyms(body) case ListFlatMap(_, x, body) => x :: effectSyms(body) case ListFilter(_, x, body) => x :: effectSyms(body) case ListSortBy(a, x, body) => x :: effectSyms(body) @@ -125,6 +141,7 @@ trait ListOpsExp extends ListOps with EffectExp with VariablesExp { override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { case ListMap(a, x, body) => freqNormal(a):::freqHot(body) + case ListForeach(a, x, body) => freqNormal(a):::freqHot(body) case ListFlatMap(a, _, body) => freqNormal(a) ::: freqHot(body) case ListFilter(a, _, body) => freqNormal(a) ::: freqHot(body) case ListSortBy(a, x, body) => freqNormal(a):::freqHot(body) @@ -152,7 +169,7 @@ trait ScalaGenListOps extends BaseGenListOps with ScalaGenEffect { import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ListNew(xs) => emitValDef(sym, src"List(${(xs map {quote}).mkString(",")})") + case l@ListNew(xs) => emitValDef(sym, src"List[${l.m}](${(xs map {quote}).mkString(",")})") case ListConcat(xs,ys) => emitValDef(sym, src"$xs ::: $ys") case ListCons(x, xs) => emitValDef(sym, src"$x :: $xs") case ListHead(xs) => emitValDef(sym, src"$xs.head") @@ -160,30 +177,58 @@ trait ScalaGenListOps extends BaseGenListOps with ScalaGenEffect { case ListIsEmpty(xs) => emitValDef(sym, src"$xs.isEmpty") case ListFromSeq(xs) => emitValDef(sym, src"List($xs: _*)") case ListMkString(xs) => emitValDef(sym, src"$xs.mkString") - case ListMkString2(xs,s) => emitValDef(sym, src"$xs.mkString($s)") case ListMap(l,x,blk) => - gen"""val $sym = $l.map { $x => - |${nestedBlock(blk)} - |$blk - |}""" - case ListFlatMap(l, x, b) => - gen"""val $sym = $l.flatMap { $x => - |${nestedBlock(b)} - |$b - |}""" - case ListFilter(l, x, b) => - gen"""val $sym = $l.filter { $x => - |${nestedBlock(b)} - |$b - |}""" - case ListSortBy(l,x,blk) => - gen"""val $sym = $l.sortBy { $x => + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + gen"""$l.map { $x => + |${nestedBlock(blk)} + |$blk + |}""" + } + emitValDef(sym, strWriter.toString) + case ListForeach(l,x,blk) => { + gen"""$l.foreach { $x => |${nestedBlock(blk)} - |$blk |}""" + } + case ListFlatMap(l, x, b) => { + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + gen"""$l.flatMap { $x => + |${nestedBlock(b)} + |$b + |}""" + } + emitValDef(sym, strWriter.toString) + } + case ListFilter(l, x, b) => { + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + gen"""$l.filter { $x => + |${nestedBlock(b)} + |$b + |}""" + } + emitValDef(sym, strWriter.toString) + } + case ListSortBy(l,x,blk) => { + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + gen"""$l.sortBy { $x => + |${nestedBlock(blk)} + |$blk + |}""" + } + emitValDef(sym, strWriter.toString) + } case ListPrepend(l,e) => emitValDef(sym, src"$e :: $l") case ListToArray(l) => emitValDef(sym, src"$l.toArray") case ListToSeq(l) => emitValDef(sym, src"$l.toSeq") + case ListContains(l, e) => emitValDef(sym, src"$l.contains($e)") case _ => super.emitNode(sym, rhs) } } diff --git a/src/common/LivenessOpt.scala b/src/common/LivenessOpt.scala index d966d61e..fffdcb5c 100644 --- a/src/common/LivenessOpt.scala +++ b/src/common/LivenessOpt.scala @@ -1,8 +1,8 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal.NestedBlockTraversal +import scala.virtualization.lms.internal.NestedBlockTraversal import scala.collection.mutable @@ -62,8 +62,6 @@ trait DefUseAnalysis extends NestedBlockTraversal { val saveDefUseMap = defUseMap defUseMap - printlog("gathering def-use info for block " + result) - var pairs = List[(Exp[Any],Exp[Any])]() for (TP(sym, rhs) <- innerScope) { @@ -72,12 +70,9 @@ trait DefUseAnalysis extends NestedBlockTraversal { } } - if (saveDefUseMap ne null) { - defUseMap = pairs.groupBy(_._1).map(p => (p._1, p._2.map(_._2).toSet)) - for ((k,vs) <- saveDefUseMap) { - defUseMap += (k -> (saveDefUseMap(k) ++ defUseMap.getOrElse(k, Set()))) - } - } else + if (saveDefUseMap ne null) + defUseMap = pairs.groupBy(_._1).map(p => (p._1, saveDefUseMap.getOrElse(p._1, Set()) ++ p._2.map(_._2))) + else defUseMap = pairs.groupBy(_._1).map(p => (p._1, p._2.map(_._2).toSet)) body diff --git a/src/common/LoopFusionOpt.scala b/src/common/LoopFusionOpt.scala index cb2087df..c7134767 100644 --- a/src/common/LoopFusionOpt.scala +++ b/src/common/LoopFusionOpt.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import internal.CodeMotion @@ -405,7 +405,7 @@ trait LoopFusionCore extends internal.FatScheduling with CodeMotion with Simplif val fusedNeg = preNeg flatMap { s1 => postNeg map { s2 => (s1,s2) } } WtableNeg = (fusedNeg ++ WtableNeg).distinct - case None => partitionsOut = b::partitionsOut + case _ => partitionsOut = b::partitionsOut } } diff --git a/src/common/Loops.scala b/src/common/Loops.scala index 4f1b83b4..9eddaabe 100644 --- a/src/common/Loops.scala +++ b/src/common/Loops.scala @@ -1,9 +1,10 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.lms.internal.{FatBlockTraversal,GenericNestedCodegen,GenericFatCodegen} +import scala.virtualization.lms.internal.{FatBlockTraversal,GenericNestedCodegen,GenericFatCodegen} +import scala.reflect.SourceContext trait Loops extends Base { // no surface constructs for now @@ -16,10 +17,10 @@ trait LoopsExp extends Loops with BaseExp with EffectExp { val v: Sym[Int] val body: Def[A] } - + case class SimpleLoop[A](val size: Exp[Int], val v: Sym[Int], val body: Def[A]) extends AbstractLoop[A] - def simpleLoop[A:Manifest](size: Exp[Int], v: Sym[Int], body: Def[A])(implicit pos: SourceContext): Exp[A] = SimpleLoop(size, v, body) + def simpleLoop[A:Manifest](size: Exp[Int], v: Sym[Int], body: Def[A]): Exp[A] = SimpleLoop(size, v, body) override def syms(e: Any): List[Sym[Any]] = e match { @@ -48,7 +49,6 @@ trait LoopsExp extends Loops with BaseExp with EffectExp { override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { case SimpleLoop(s,v,body: Def[A]) => simpleLoop(f(s),f(v).asInstanceOf[Sym[Int]],mirrorFatDef(body,f)) - case Reflect(SimpleLoop(s,v,body: Def[A]), u, es) if u == Control() => reflectMirrored(Reflect(SimpleLoop(f(s),f(v).asInstanceOf[Sym[Int]],mirrorFatDef(body,f)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] // why?? @@ -176,9 +176,6 @@ trait ScalaGenLoopsFat extends ScalaGenLoops with ScalaGenFat with BaseGenLoopsF trait CLikeGenLoops extends CLikeGenBase with BaseGenLoops trait CLikeGenLoopsFat extends CLikeGenLoops with CLikeGenFat with BaseGenLoopsFat -trait CGenLoops extends CGenBase with CLikeGenLoops -trait CGenLoopsFat extends CGenLoops with CGenFat with CLikeGenLoopsFat - trait GPUGenLoops extends GPUGenBase with CLikeGenLoops trait GPUGenLoopsFat extends GPUGenLoops with GPUGenFat with CLikeGenLoopsFat @@ -186,4 +183,4 @@ trait CudaGenLoops extends CudaGenBase with GPUGenLoops trait CudaGenLoopsFat extends CudaGenLoops with CudaGenFat with GPUGenLoopsFat trait OpenCLGenLoops extends OpenCLGenBase with GPUGenLoops -trait OpenCLGenLoopsFat extends OpenCLGenLoops with OpenCLGenFat with GPUGenLoopsFat +trait OpenCLGenLoopsFat extends OpenCLGenLoops with OpenCLGenFat with GPUGenLoopsFat \ No newline at end of file diff --git a/src/common/MathOps.scala b/src/common/MathOps.scala index 580ca10e..fe53e007 100755 --- a/src/common/MathOps.scala +++ b/src/common/MathOps.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter @@ -12,23 +12,17 @@ trait MathOps extends Base { def floor(x: Rep[Double])(implicit pos: SourceContext) = math_floor(x) def exp(x: Rep[Double])(implicit pos: SourceContext) = math_exp(x) def log(x: Rep[Double])(implicit pos: SourceContext) = math_log(x) - def log10(x: Rep[Double])(implicit ctx: SourceContext) = math_log10(x) def sqrt(x: Rep[Double])(implicit pos: SourceContext) = math_sqrt(x) def sin(x: Rep[Double])(implicit pos: SourceContext) = math_sin(x) - def sinh(x: Rep[Double])(implicit ctx: SourceContext) = math_sinh(x) - def asin(x: Rep[Double])(implicit ctx: SourceContext) = math_asin(x) def cos(x: Rep[Double])(implicit pos: SourceContext) = math_cos(x) - def cosh(x: Rep[Double])(implicit ctx: SourceContext) = math_cosh(x) def acos(x: Rep[Double])(implicit pos: SourceContext) = math_acos(x) - def tan(x: Rep[Double])(implicit ctx: SourceContext) = math_tan(x) - def tanh(x: Rep[Double])(implicit ctx: SourceContext) = math_tanh(x) def atan(x: Rep[Double])(implicit pos: SourceContext) = math_atan(x) def atan2(x: Rep[Double], y: Rep[Double])(implicit pos: SourceContext) = math_atan2(x,y) def pow(x: Rep[Double], y: Rep[Double])(implicit pos: SourceContext) = math_pow(x,y) def abs[A:Manifest:Numeric](x: Rep[A])(implicit pos: SourceContext) = math_abs(x) def max[A:Manifest:Numeric](x: Rep[A], y: Rep[A])(implicit pos: SourceContext) = math_max(x,y) def min[A:Manifest:Numeric](x: Rep[A], y: Rep[A])(implicit pos: SourceContext) = math_min(x,y) - def Pi(implicit pos: SourceContext) = 3.141592653589793238462643383279502884197169 + def Pi(implicit pos: SourceContext) = math_pi def E(implicit pos: SourceContext) = math_e } @@ -36,16 +30,10 @@ trait MathOps extends Base { def math_floor(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_exp(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_log(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] - def math_log10(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] def math_sqrt(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_sin(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] - def math_sinh(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] - def math_asin(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] def math_cos(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] - def math_cosh(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] def math_acos(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] - def math_tan(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] - def math_tanh(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] def math_atan(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_atan2(x: Rep[Double], y: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_pow(x: Rep[Double], y: Rep[Double])(implicit pos: SourceContext): Rep[Double] @@ -61,16 +49,10 @@ trait MathOpsExp extends MathOps with EffectExp { case class MathFloor(x: Exp[Double]) extends Def[Double] case class MathExp(x: Exp[Double]) extends Def[Double] case class MathLog(x: Exp[Double]) extends Def[Double] - case class MathLog10(x: Exp[Double]) extends Def[Double] case class MathSqrt(x: Exp[Double]) extends Def[Double] case class MathSin(x: Exp[Double]) extends Def[Double] - case class MathSinh(x: Exp[Double]) extends Def[Double] - case class MathAsin(x: Exp[Double]) extends Def[Double] case class MathCos(x: Exp[Double]) extends Def[Double] - case class MathCosh(x: Exp[Double]) extends Def[Double] case class MathAcos(x: Exp[Double]) extends Def[Double] - case class MathTan(x: Exp[Double]) extends Def[Double] - case class MathTanh(x: Exp[Double]) extends Def[Double] case class MathAtan(x: Exp[Double]) extends Def[Double] case class MathAtan2(x: Exp[Double], y: Exp[Double]) extends Def[Double] case class MathPow(x: Exp[Double], y: Exp[Double]) extends Def[Double] @@ -84,16 +66,10 @@ trait MathOpsExp extends MathOps with EffectExp { def math_floor(x: Exp[Double])(implicit pos: SourceContext) = MathFloor(x) def math_exp(x: Exp[Double])(implicit pos: SourceContext) = MathExp(x) def math_log(x: Exp[Double])(implicit pos: SourceContext) = MathLog(x) - def math_log10(x: Exp[Double])(implicit ctx: SourceContext) = MathLog10(x) def math_sqrt(x: Exp[Double])(implicit pos: SourceContext) = MathSqrt(x) def math_sin(x: Exp[Double])(implicit pos: SourceContext) = MathSin(x) - def math_sinh(x: Exp[Double])(implicit ctx: SourceContext) = MathSinh(x) - def math_asin(x: Exp[Double])(implicit ctx: SourceContext) = MathAsin(x) def math_cos(x: Exp[Double])(implicit pos: SourceContext) = MathCos(x) - def math_cosh(x: Exp[Double])(implicit ctx: SourceContext) = MathCosh(x) def math_acos(x: Exp[Double])(implicit pos: SourceContext) = MathAcos(x) - def math_tan(x: Exp[Double])(implicit ctx: SourceContext) = MathTan(x) - def math_tanh(x: Exp[Double])(implicit ctx: SourceContext) = MathTanh(x) def math_atan(x: Exp[Double])(implicit pos: SourceContext) = MathAtan(x) def math_atan2(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = MathAtan2(x,y) def math_pow(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = MathPow(x,y) @@ -101,7 +77,7 @@ trait MathOpsExp extends MathOps with EffectExp { def math_max[A:Manifest:Numeric](x: Exp[A], y: Exp[A])(implicit pos: SourceContext) = MathMax(x, y) def math_min[A:Manifest:Numeric](x: Exp[A], y: Exp[A])(implicit pos: SourceContext) = MathMin(x, y) def math_pi(implicit pos: SourceContext) = MathPi() - def math_e(implicit pos: SourceContext) = MathE() + def math_e(implicit pos: SourceContext) = MathE() override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = ({ implicit var a: Numeric[A] = null // hack!! need to store it in Def instances?? @@ -119,32 +95,20 @@ trait MathOpsExp extends MathOps with EffectExp { case MathAtan2(x,y) => math_atan2(f(x),f(y)) case MathMin(x,y) => math_min(f(x),f(y)) case MathMax(x,y) => math_max(f(x),f(y)) - case MathLog10(x) => math_log10(f(x)) - case MathSinh(x) => math_sinh(f(x)) - case MathAsin(x) => math_asin(f(x)) - case MathCosh(x) => math_cosh(f(x)) - case MathTan(x) => math_tan(f(x)) - case MathTanh(x) => math_tanh(f(x)) - case Reflect(MathCeil(x), u, es) => reflectMirrored(Reflect(MathCeil(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathFloor(x), u, es) => reflectMirrored(Reflect(MathFloor(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathExp(x), u, es) => reflectMirrored(Reflect(MathExp(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathPow(x,y), u, es) => reflectMirrored(Reflect(MathPow(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathAbs(x), u, es) => reflectMirrored(Reflect(MathAbs(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathSin(x), u, es) => reflectMirrored(Reflect(MathSin(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathCos(x), u, es) => reflectMirrored(Reflect(MathCos(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathAcos(x), u, es) => reflectMirrored(Reflect(MathAcos(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathLog(x), u, es) => reflectMirrored(Reflect(MathLog(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathSqrt(x), u, es) => reflectMirrored(Reflect(MathSqrt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathAtan2(x,y), u, es) => reflectMirrored(Reflect(MathAtan2(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathMin(x,y), u, es) => reflectMirrored(Reflect(MathMin(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathMax(x,y), u, es) => reflectMirrored(Reflect(MathMax(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathLog10(x), u, es) => reflectMirrored(Reflect(MathLog10(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathSinh(x), u, es) => reflectMirrored(Reflect(MathSinh(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathAsin(x), u, es) => reflectMirrored(Reflect(MathAsin(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathCosh(x), u, es) => reflectMirrored(Reflect(MathCosh(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathTan(x), u, es) => reflectMirrored(Reflect(MathTan(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(MathTanh(x), u, es) => reflectMirrored(Reflect(MathTanh(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathCeil(x), u, es) => reflectMirrored(Reflect(MathCeil(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathFloor(x), u, es) => reflectMirrored(Reflect(MathFloor(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathExp(x), u, es) => reflectMirrored(Reflect(MathExp(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathPow(x,y), u, es) => reflectMirrored(Reflect(MathPow(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathAbs(x), u, es) => reflectMirrored(Reflect(MathAbs(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathSin(x), u, es) => reflectMirrored(Reflect(MathSin(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathCos(x), u, es) => reflectMirrored(Reflect(MathCos(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathAcos(x), u, es) => reflectMirrored(Reflect(MathAcos(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathLog(x), u, es) => reflectMirrored(Reflect(MathLog(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathSqrt(x), u, es) => reflectMirrored(Reflect(MathSqrt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathAtan2(x,y), u, es) => reflectMirrored(Reflect(MathAtan2(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathMin(x,y), u, es) => reflectMirrored(Reflect(MathMin(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathMax(x,y), u, es) => reflectMirrored(Reflect(MathMax(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) } @@ -162,21 +126,15 @@ trait ScalaGenMathOps extends BaseGenMathOps with ScalaGenEffect { val IR: MathOpsExp import IR._ - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { // TODO: use java.lang.Math etc... case MathCeil(x) => emitValDef(sym, src"java.lang.Math.ceil($x)") case MathFloor(x) => emitValDef(sym, src"java.lang.Math.floor($x)") case MathExp(x) => emitValDef(sym, src"java.lang.Math.exp($x)") case MathLog(x) => emitValDef(sym, src"java.lang.Math.log($x)") - case MathLog10(x) => emitValDef(sym, src"java.lang.Math.log10($x)") case MathSqrt(x) => emitValDef(sym, src"java.lang.Math.sqrt($x)") case MathSin(x) => emitValDef(sym, src"java.lang.Math.sin($x)") - case MathSinh(x) => emitValDef(sym, "java.lang.Math.sinh($x)") - case MathAsin(x) => emitValDef(sym, "java.lang.Math.asin($x)") case MathCos(x) => emitValDef(sym, src"java.lang.Math.cos($x)") - case MathCosh(x) => emitValDef(sym, "java.lang.Math.cosh($x)") case MathAcos(x) => emitValDef(sym, src"java.lang.Math.acos($x)") - case MathTan(x) => emitValDef(sym, "java.lang.Math.tan($x)") - case MathTanh(x) => emitValDef(sym, "java.lang.Math.tanh($x)") case MathAtan(x) => emitValDef(sym, src"java.lang.Math.atan($x)") case MathAtan2(x,y) => emitValDef(sym, src"java.lang.Math.atan2($x, $y)") case MathPow(x,y) => emitValDef(sym, src"java.lang.Math.pow($x,$y)") @@ -184,7 +142,7 @@ trait ScalaGenMathOps extends BaseGenMathOps with ScalaGenEffect { case MathMax(x,y) => emitValDef(sym, src"java.lang.Math.max($x, $y)") case MathMin(x,y) => emitValDef(sym, src"java.lang.Math.min($x, $y)") case MathPi() => emitValDef(sym, "java.lang.Math.PI") - case MathE() => emitValDef(sym, "java.lang.Math.E") + case MathE() => emitValDef(sym, "java.lang.Math.E") case _ => super.emitNode(sym, rhs) } } @@ -215,7 +173,9 @@ trait ScalaGenMathOpsApacheCommons extends ScalaGenMathOps { } -trait CLikeGenMathOps extends BaseGenMathOps with CLikeGenEffect { + + +trait CudaGenMathOps extends BaseGenMathOps with CudaGenEffect { val IR: MathOpsExp import IR._ @@ -238,42 +198,36 @@ trait CLikeGenMathOps extends BaseGenMathOps with CLikeGenEffect { case MathMin(x,y) if(remap(sym.tp))=="float" => emitValDef(sym, src"fmin($x, $y)") case MathMin(x,y) if(remap(sym.tp))=="double" => emitValDef(sym, src"fmin($x, $y)") case MathMin(x,y) if(remap(sym.tp))=="int" => emitValDef(sym, src"min($x, $y)") - case _ => super.emitNode(sym, rhs) - } -} - - -trait CudaGenMathOps extends CLikeGenMathOps with CudaGenEffect { - val IR: MathOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case MathPi() => emitValDef(sym, "CUDART_PI_F") case MathE() => emitValDef(sym, "2.7182818284f") case _ => super.emitNode(sym, rhs) } } -trait OpenCLGenMathOps extends CLikeGenMathOps with OpenCLGenEffect { +trait OpenCLGenMathOps extends BaseGenMathOps with OpenCLGenEffect { val IR: MathOpsExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case MathPi() => emitValDef(sym, "M_PI") - case MathE() => emitValDef(sym, "M_E") + case MathCeil(x) => emitValDef(sym, src"ceil($x)") + case MathFloor(x) => emitValDef(sym, src"floor($x)") + case MathExp(x) => emitValDef(sym, src"exp($x)") + case MathLog(x) => emitValDef(sym, src"log($x)") + case MathSqrt(x) => emitValDef(sym, src"sqrt($x)") + case MathAbs(x) => emitValDef(sym, src"abs($x)") case MathMax(x,y) => emitValDef(sym, src"max($x, $y)") case MathMin(x,y) => emitValDef(sym, src"min($x, $y)") case _ => super.emitNode(sym, rhs) } } -trait CGenMathOps extends CLikeGenMathOps with CGenEffect { +trait CGenMathOps extends BaseGenMathOps with CGenEffect { val IR: MathOpsExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case MathPi() => emitValDef(sym, "M_PI") - case MathE() => emitValDef(sym, "M_E") + case MathSin(x) if(remap(sym.tp)=="double") => emitValDef(sym, src"sin($x)") + case MathPi() if(remap(sym.tp)=="double") => emitValDef(sym, "M_PI") case _ => super.emitNode(sym, rhs) } diff --git a/src/common/MiscOps.scala b/src/common/MiscOps.scala index 5deca961..25c87af1 100644 --- a/src/common/MiscOps.scala +++ b/src/common/MiscOps.scala @@ -1,8 +1,8 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal._ +import scala.virtualization.lms.internal._ import scala.reflect.SourceContext trait MiscOps extends Base { @@ -36,6 +36,7 @@ trait MiscOpsExp extends MiscOps with EffectExp { def print(x: Exp[Any])(implicit pos: SourceContext) = reflectEffect(Print(x)) // TODO: simple effect def println(x: Exp[Any])(implicit pos: SourceContext) = reflectEffect(PrintLn(x)) // TODO: simple effect def printf(f: String, x: Rep[Any]*)(implicit pos: SourceContext): Rep[Unit] = reflectEffect(PrintF(f, x.toList)) + def printf(f: String, x: List[Rep[Any]])(implicit pos: SourceContext): Rep[Unit] = reflectEffect(PrintF(f, x)) def exit(s: Exp[Int])(implicit pos: SourceContext) = reflectEffect(Exit(s)) def error(s: Exp[String])(implicit pos: SourceContext) = reflectEffect(Error(s)) def returnL(x: Exp[Any])(implicit pos: SourceContext) = { @@ -45,12 +46,12 @@ trait MiscOpsExp extends MiscOps with EffectExp { } override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case Reflect(Error(x), u, es) => reflectMirrored(Reflect(Error(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(Print(x), u, es) => reflectMirrored(Reflect(Print(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(PrintLn(x), u, es) => reflectMirrored(Reflect(PrintLn(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(PrintF(fm,x), u, es) => reflectMirrored(Reflect(PrintF(fm,f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(Exit(x), u, es) => reflectMirrored(Reflect(Exit(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(Return(x), u, es) => reflectMirrored(Reflect(Return(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(Error(x), u, es) => reflectMirrored(Reflect(Error(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(Print(x), u, es) => reflectMirrored(Reflect(Print(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(PrintLn(x), u, es) => reflectMirrored(Reflect(PrintLn(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(PrintF(fm,x), u, es) => reflectMirrored(Reflect(PrintF(fm,f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(Exit(x), u, es) => reflectMirrored(Reflect(Exit(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(Return(x), u, es) => reflectMirrored(Reflect(Return(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] } @@ -60,46 +61,35 @@ trait ScalaGenMiscOps extends ScalaGenEffect { import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case PrintF(f,xs) => emitValDef(sym, src"printf(${f::xs})") - case PrintLn(s) => emitValDef(sym, src"println($s)") - case Print(s) => emitValDef(sym, src"print($s)") - case Exit(a) => emitValDef(sym, src"exit($a)") - case Return(x) => emitValDef(sym, src"return $x") - case Error(s) => emitValDef(sym, src"error($s)") + case PrintF(f,xs) => + stream.print("printf(\"\"\"" + f.replace("\\n","\n") + "\"\"\"") + if (xs.size != 0) stream.print(xs.map(x => quote(x)).mkString(",",",","")) + stream.println(")") + case PrintLn(s) => gen"println($s)" + case Print(s) => gen"print($s)" + case Exit(a) => gen"exit($a)" + case Return(x) => gen"return $x" + case Error(s) => gen"error($s)" case _ => super.emitNode(sym, rhs) } } -trait CGenMiscOps extends CGenEffect { +trait CGenMiscOps extends CGenEffect with GenericNestedCodegen { val IR: MiscOpsExp import IR._ - - def format(s: Exp[Any]): String = { - remap(s.tp) match { - case "uint16_t" => "%c" - case "bool" | "int8_t" | "int16_t" | "int32_t" => "%d" - case "int64_t" => "%ld" - case "float" | "double" => "%f" - case "string" => "%s" - case _ => throw new GenerationFailedException("CGenMiscOps: cannot print type " + remap(s.tp)) - } - } - - def quoteRawString(s: Exp[Any]): String = { - remap(s.tp) match { - case "string" => quote(s) + ".c_str()" - case _ => quote(s) - } + +/* override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { + //TR case PrintLn(x) => sym.atPhase(LIRLowering) { println(LIRLowering(x)).asInstanceOf[Exp[A]] } + case _ => super.lowerNode(sym, rhs) } +*/ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case PrintF(f,x) => stream.println("printf(" + ((Const(f:String)::x).map(quoteRawString)).mkString(",") + ");") - case PrintLn(s) => stream.println("printf(\"" + format(s) + "\\n\"," + quoteRawString(s) + ");") - case Print(s) => stream.println("printf(\"" + format(s) + "\"," + quoteRawString(s) + ");") - case Exit(a) => stream.println("exit(" + quote(a) + ");") - case Return(x) => stream.println("return " + quote(x) + ";") - case Error(s) => stream.println("error(-1,0,\"%s\"," + quote(s) + ");") + case PrintF(f,xs) => gen"printf(${Const(f:String)::xs});" + case PrintLn(s) => gen"""printf("%s\n",$s);""" + case Print(s) => gen"""printf("%s",$s);""" + case Exit(a) => gen"exit($a);" case _ => super.emitNode(sym, rhs) } } diff --git a/src/common/MultiMap.scala b/src/common/MultiMap.scala new file mode 100644 index 00000000..67ff6174 --- /dev/null +++ b/src/common/MultiMap.scala @@ -0,0 +1,158 @@ +package scala.virtualization.lms +package common + +import java.io.PrintWriter +import scala.virtualization.lms.internal._ +import scala.collection.mutable.{HashMap,Set} +import scala.reflect.SourceContext + +trait HashMultiMapOps extends Base with Variables { + object HashMultiMap { + def apply[K:Manifest,V:Manifest](size: Long = 0, specializedKey: String = "", specializedValue:String = "")(implicit pos: SourceContext) = hashmultimap_new[K,V](size, specializedKey, specializedValue) + } + + implicit def HashMultiMapToRepHashMapOps[K:Manifest,V:Manifest](m: HashMap[K,Set[V]]) = new hashMultiMapOpsCls(unit(m)) + implicit def repHashMultiMapToHashMapOps[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]]) = new hashMultiMapOpsCls(m) + implicit def varrepHashMultiMapToHashMapOps[K:Manifest,V:Manifest](m: Var[HashMap[K,Set[V]]]) = new hashMultiMapOpsCls(readVar(m)) + + class hashMultiMapOpsCls[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]]) { + def apply(k: Rep[K])(implicit pos: SourceContext) = hashmultimap_apply(m, k) + def update(k: Rep[K], v: Rep[V])(implicit pos: SourceContext) = hashmultimap_update(m,k,v) + def contains(k: Rep[K])(implicit pos: SourceContext) = hashmultimap_contains(m, k) + def foreach(block: Rep[(K,Set[V])] => Rep[Unit])(implicit pos: SourceContext) = hashmultimap_foreach(m, block) + def mkString(delimiter: Rep[String]) = hashmultimap_mkString(m, delimiter) + def getOrElseEmpty(k: Rep[K])(implicit pos: SourceContext) = hashmultimap_getorelseempty(m,k) + def remove(k: Rep[K], v: Rep[V])(implicit pos: SourceContext) = hashmultimap_remove(m,k,v) + } + + def hashmultimap_new[K:Manifest,V:Manifest](size: Long = 0, specializedKey: String = "", specializedValue: String = "")(implicit pos: SourceContext) : Rep[HashMap[K,Set[V]]] + def hashmultimap_apply[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K])(implicit pos: SourceContext): Rep[Set[V]] + def hashmultimap_update[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext): Rep[Unit] + def hashmultimap_contains[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], i: Rep[K])(implicit pos: SourceContext): Rep[Boolean] + def hashmultimap_foreach[K:Manifest,V:Manifest](x: Rep[HashMap[K,Set[V]]], block: Rep[(K,Set[V])] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] + def hashmultimap_mkString[K: Manifest, V: Manifest](m: Rep[HashMap[K,Set[V]]], v: Rep[String])(implicit pos: SourceContext): Rep[String] + def hashmultimap_getorelseempty[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K])(implicit pos: SourceContext): Rep[Set[V]] + def hashmultimap_remove[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext): Rep[Unit] +} + +trait HashMultiMapOpsExp extends HashMultiMapOps with EffectExp { + abstract class HashMultiMapDef[K:Manifest,V:Manifest,R:Manifest] extends Def[R] { + val mK = manifest[K] + val mV = manifest[V] + } + case class HashMultiMapNew[K:Manifest,V:Manifest](size: Long = 0, specializedKey: String = "", specializedValue: String ="") extends HashMultiMapDef[K,Set[V],HashMap[K,Set[V]]] + case class HashMultiMapApply[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K]) extends HashMultiMapDef[K,V,Set[V]] + case class HashMultiMapUpdate[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K], v: Exp[V]) extends HashMultiMapDef[K,V,Unit] + case class HashMultiMapContains[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], i: Exp[K]) extends HashMultiMapDef[K,V,Boolean] + case class HashMultiMapForeach[K:Manifest, V:Manifest](a: Exp[HashMap[K,Set[V]]], x: Sym[(K,Set[V])], block: Block[Unit]) extends Def[Unit] + case class HashMultiMapMkString[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], v:Rep[String]) extends HashMultiMapDef[K,V,String] + case class HashMultiMapGetOrElseEmpty[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K]) extends HashMultiMapDef[K,V,Set[V]] + case class HashMultiMapRemove[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K], v: Exp[V]) extends HashMultiMapDef[K,V,Unit] + + def hashmultimap_new[K:Manifest,V:Manifest](size: Long = 0, specializedKey: String = "", specializedValue: String = "")(implicit pos: SourceContext) = reflectEffect(HashMultiMapNew[K,V](size, specializedKey, specializedValue)) + def hashmultimap_apply[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K])(implicit pos: SourceContext) = reflectEffect(HashMultiMapApply[K,V](m,k)) + def hashmultimap_update[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K], v: Exp[V])(implicit pos: SourceContext) = reflectEffect(HashMultiMapUpdate[K,V](m,k,v)) + def hashmultimap_contains[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], i: Exp[K])(implicit pos: SourceContext) = HashMultiMapContains(m, i) + def hashmultimap_foreach[K:Manifest,V:Manifest](x: Rep[HashMap[K,Set[V]]], block: Rep[(K,Set[V])] => Rep[Unit])(implicit pos: SourceContext) = { + val k = fresh[(K,Set[V])] + val b = reifyEffects(block(k)) + reflectEffect(HashMultiMapForeach(x, k, b), summarizeEffects(b).star) + } + def hashmultimap_mkString[K: Manifest, V: Manifest](m: Rep[HashMap[K,Set[V]]], v: Rep[String])(implicit pos: SourceContext) = reflectEffect(HashMultiMapMkString(m, v)) + def hashmultimap_getorelseempty[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K])(implicit pos: SourceContext) = reflectEffect(HashMultiMapGetOrElseEmpty(m,k)) + def hashmultimap_remove[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext) = reflectEffect(HashMultiMapRemove(m,k,v)) + + override def syms(e: Any): List[Sym[Any]] = e match { + case HashMultiMapForeach(a, x, body) => syms(a):::syms(body) + case _ => super.syms(e) + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case HashMultiMapForeach(a, x, body) => x :: effectSyms(body) + case _ => super.boundSyms(e) + } + + override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case HashMultiMapForeach(a, x, body) => freqNormal(a):::freqHot(body) + case _ => super.symsFreq(e) + } + + +} + +trait ScalaGenHashMultiMap extends GenericNestedCodegen with ScalaGenEffect { + val IR: HashMultiMapOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case m@HashMultiMapNew(size, spkey, spvalue) => { + val key = if (spkey != "") spkey else remap(m.mK) + val value = if (spvalue != "") spvalue else remap(m.mV) + emitValDef(sym, "new collection.mutable.HashMap[" + key + ", " + value + "]() with scala.collection.mutable.MultiMap[" + key + "," + value.replace("scala.collection.mutable.Set[","").replace("]","") + "]") + } + case HashMultiMapApply(m,k) => emitValDef(sym, quote(m) + "(" + quote(k) + ")") + case HashMultiMapGetOrElseEmpty(m,k) => emitValDef(sym, quote(m) + ".getOrElse(" + quote(k) + ", scala.collection.mutable.Set.empty)") + case HashMultiMapUpdate(m,k,v) => emitValDef(sym, quote(m) + ".addBinding(" + quote(k) + "," + quote(v) + ")") + case HashMultiMapContains(m,i) => emitValDef(sym, quote(m) + ".contains(" + quote(i) + ")") + case HashMultiMapForeach(m,k,v) => emitValDef(sym, quote(m) + ".foreach(" + quote(k) + "=>{") + emitBlock(v) + emitBlockResult(v) + stream.println("})") + case HashMultiMapMkString(m,k) => emitValDef(sym, quote(m) + ".mkString(" + quote(k) + ")") + case HashMultiMapRemove(m,k,v) => emitValDef(sym, quote(m) + "(" + quote(k) + ").remove(" + quote(v) +")") + case _ => super.emitNode(sym, rhs) + } +} + +trait ScalaGenHashMultiMapOpt extends GenericNestedCodegen with ScalaGenEffect { + val IR: HashMultiMapOpsExp + import IR._ + + def emitKeyModulo[K: Manifest, V: Manifest](m: Rep[HashMap[K, Set[V]]], k: Rep[K]) = { + quote(k) + "%" + quote(m) + ".length" + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case m@HashMultiMapNew(size, spkey, spvalue) => { + // Sanity check + //if (m.mV != manifest[Set[scala.virtualization.lms.common.DynamicRecord]]) + // throw new RuntimeException("ScalaGenHashMultiMapOpt can only be used with sets of DynamicRecords (you provided " + remap(m.mV)) + val value = if (spvalue != "") spvalue else remap(m.mV) + emitValDef(sym, "new Array[" + value + "](" + size + ")") + } + case HashMultiMapApply(m,k) => { + stream.println("val " + quote(sym) + " = " + quote(m) + "(" + emitKeyModulo(m,k) + ")") + } + case HashMultiMapUpdate(m,k,v) => { + stream.println("\nval x" + sym.toString.replace("Sym(","").replace(")","") + " = {") + stream.println("\tval __elem = " + quote(m) + "(" + emitKeyModulo(m,k) + ")") + stream.println("\tif (__elem == null) " + quote(m) + "(" + emitKeyModulo(m,k) + ") = " + quote(v)) + stream.println("\telse {") + stream.println("\t\t" + quote(v) + ".next = __elem") + stream.println("\t\t" + quote(m) + "(" + emitKeyModulo(m,k) + ") = " + quote(v)) + stream.println("\t}") + stream.println("}") + } + case HashMultiMapContains(m,k) => { + stream.println("val " + quote(sym) + " = " + quote(m) + "(" + emitKeyModulo(m,k) + ") != null") + } + case HashMultiMapGetOrElseEmpty(m,k) => + // Note: here you get back a null if you have no elements ("the else") but we handle + // this case in the for-each function in the dynamic record (which should be used to + // iterate over the values in a way similar to the normal multimap) + stream.println("val " + quote(sym) + " = " + quote(m) + "(" + emitKeyModulo(m,k) + ")") + case HashMultiMapMkString(m,k) => emitValDef(sym, quote(m) + ".mkString(" + emitKeyModulo(m,k) + ")") + case HashMultiMapRemove(m,k,v) => { + stream.println("\tvar __elem = " + quote(m) + "(" + emitKeyModulo(m,k) + ")") + stream.println("\tvar __prevelem = __elem; __prevelem = null;") + stream.println("\twhile ((__elem != null) && (__elem.equals(" + quote(v) + ") == false)) {") + stream.println("\t\t__prevelem = __elem") + stream.println("\t\t__elem = __elem.next") + stream.println("}") + stream.println("\tif (__elem == null) throw new RuntimeException(\"Element to be removed not found\")") + stream.println("\telse if (__prevelem != null) __prevelem.next = __elem.next") + stream.println("\telse " + quote(m) + "(" + emitKeyModulo(m,k) + ") = __elem.next") + } + case _ => super.emitNode(sym, rhs) + } +} diff --git a/src/common/NumericOps.scala b/src/common/NumericOps.scala index f5e33575..80a109a3 100644 --- a/src/common/NumericOps.scala +++ b/src/common/NumericOps.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter @@ -11,7 +11,6 @@ trait LiftNumeric { } trait NumericOps extends Variables { - this: PrimitiveOps => // workaround for infix not working with manifests implicit def numericToNumericOps[T:Numeric:Manifest](n: T) = new NumericOpsCls(unit(n)) @@ -26,6 +25,9 @@ trait NumericOps extends Variables { def /(rhs: Rep[T])(implicit pos: SourceContext) = numeric_divide(lhs,rhs) } + //def infix_+[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T]) = numeric_plus(lhs,rhs) + //def infix_-[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T]) = numeric_minus(lhs,rhs) + //def infix_*[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T]) = numeric_times(lhs,rhs) def numeric_plus[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] def numeric_minus[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] def numeric_times[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] @@ -36,8 +38,6 @@ trait NumericOps extends Variables { } trait NumericOpsExp extends NumericOps with VariablesExp with BaseFatExp { - this: PrimitiveOpsExp => - abstract class DefMN[A:Manifest:Numeric] extends Def[A] { def mev = manifest[A] def aev = implicitly[Numeric[A]] @@ -65,7 +65,6 @@ trait NumericOpsExp extends NumericOps with VariablesExp with BaseFatExp { trait NumericOpsExpOpt extends NumericOpsExp { - this: PrimitiveOpsExp => override def numeric_plus[T:Numeric:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Exp[T] = (lhs,rhs) match { case (Const(x), Const(y)) => Const(implicitly[Numeric[T]].plus(x,y)) diff --git a/src/common/ObjectOps.scala b/src/common/ObjectOps.scala index 8b9355f4..c306d58e 100644 --- a/src/common/ObjectOps.scala +++ b/src/common/ObjectOps.scala @@ -1,24 +1,29 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.util.OverloadHack -import scala.lms.internal.{GenerationFailedException} +import scala.virtualization.lms.util.OverloadHack +import scala.virtualization.lms.internal.{GenerationFailedException} import scala.reflect.SourceContext trait ObjectOps extends Variables with OverloadHack { - def infix_toString(lhs: Rep[Any])(implicit pos: SourceContext) = object_tostring(lhs) + //def infix_toString(lhs: Rep[Any])(implicit pos: SourceContext) = object_tostring(lhs) def infix_ToString(lhs: Rep[Any])(implicit pos: SourceContext) = object_tostring(lhs) + //def infix_hashCode(lhs: Rep[Any])(implicit pos: SourceContext) = object_hashcode(lhs) + //def infix_##(lhs: Rep[Any])(implicit pos: SourceContext) = object_hashcode(lhs) + def infix_HashCode(lhs: Rep[Any])(implicit pos: SourceContext) = object_hashcode(lhs) def infix_unsafeImmutable[A:Manifest](lhs: Rep[A])(implicit pos: SourceContext) = object_unsafe_immutable(lhs) def infix_unsafeMutable[A:Manifest](lhs: Rep[A])(implicit pos: SourceContext) = object_unsafe_mutable(lhs) def object_tostring(lhs: Rep[Any])(implicit pos: SourceContext): Rep[String] + def object_hashcode(lhs: Rep[Any])(implicit pos: SourceContext): Rep[Int] def object_unsafe_immutable[A:Manifest](lhs: Rep[A])(implicit pos: SourceContext): Rep[A] def object_unsafe_mutable[A:Manifest](lhs: Rep[A])(implicit pos: SourceContext): Rep[A] } trait ObjectOpsExp extends ObjectOps with VariablesExp { case class ObjectToString(o: Exp[Any]) extends Def[String] + case class ObjectHashCode(o: Exp[Any]) extends Def[Int] case class ObjectUnsafeImmutable[A:Manifest](o: Exp[A]) extends Def[A] { val m = manifest[A] } @@ -27,6 +32,7 @@ trait ObjectOpsExp extends ObjectOps with VariablesExp { } def object_tostring(lhs: Exp[Any])(implicit pos: SourceContext) = ObjectToString(lhs) + def object_hashcode(lhs: Exp[Any])(implicit pos: SourceContext) = ObjectHashCode(lhs) def object_unsafe_immutable[A:Manifest](lhs: Exp[A])(implicit pos: SourceContext) = lhs match { // INVESTIGATE: there was an issue where Const(0).unsafeImmutable == Const(0.0). How is this possible? CSE with primitive widening? case c@Const(x) => c @@ -40,8 +46,9 @@ trait ObjectOpsExp extends ObjectOps with VariablesExp { override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { case e@ObjectUnsafeImmutable(a) => object_unsafe_immutable(f(a))(mtype(e.m),pos) case e@ObjectToString(a) => object_tostring(f(a)) - case Reflect(e@ObjectUnsafeImmutable(a), u, es) => reflectMirrored(Reflect(ObjectUnsafeImmutable(f(a))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@ObjectUnsafeMutable(a), u, es) => reflectMirrored(Reflect(ObjectUnsafeMutable(f(a))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case e@ObjectHashCode(a) => object_hashcode(f(a)) + case Reflect(e@ObjectUnsafeImmutable(a), u, es) => reflectMirrored(Reflect(ObjectUnsafeImmutable(f(a))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@ObjectUnsafeMutable(a), u, es) => reflectMirrored(Reflect(ObjectUnsafeMutable(f(a))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] @@ -79,36 +86,23 @@ trait ObjectOpsExpOpt extends ObjectOpsExp { trait ScalaGenObjectOps extends ScalaGenBase { val IR: ObjectOpsExp import IR._ - + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case ObjectToString(lhs) => emitValDef(sym, src"($lhs).toString()") + case ObjectHashCode(lhs) => emitValDef(sym, src"($lhs).##") case ObjectUnsafeImmutable(x) => emitValDef(sym, src"$x// unsafe immutable") case ObjectUnsafeMutable(x) => emitValDef(sym, src"$x// unsafe mutable") case _ => super.emitNode(sym, rhs) } } -trait GPUGenObjectOps extends GPUGenBase { - val IR: ObjectOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ObjectUnsafeImmutable(x) => - emitValDef(sym, quote(x) + "; // unsafe immutable") - emitPtrDef(sym, x) - case ObjectUnsafeMutable(x) => - emitValDef(sym, quote(x) + "; // unsafe mutable") - emitPtrDef(sym, x) - case _ => super.emitNode(sym, rhs) - } -} - trait CLikeGenObjectOps extends CLikeGenBase { val IR: ObjectOpsExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ObjectToString(x) => emitValDef(sym, src"($x).toString()") + case ObjectToString(lhs) => emitValDef(sym, src"($lhs).toString()") + case ObjectHashCode(lhs) => emitValDef(sym, src"($lhs).##") case ObjectUnsafeImmutable(x) => emitValDef(sym, src"$x; // unsafe immutable") case ObjectUnsafeMutable(x) => emitValDef(sym, src"$x; // unsafe mutable") case _ => super.emitNode(sym, rhs) @@ -117,4 +111,4 @@ trait CLikeGenObjectOps extends CLikeGenBase { trait CudaGenObjectOps extends CudaGenBase with CLikeGenObjectOps trait OpenCLGenObjectOps extends OpenCLGenBase with CLikeGenObjectOps -trait CGenObjectOps extends CGenBase with CLikeGenObjectOps +trait CGenObjectOps extends CGenBase with CLikeGenObjectOps diff --git a/src/common/OrderingOps.scala b/src/common/OrderingOps.scala index b7e99694..7829dedd 100644 --- a/src/common/OrderingOps.scala +++ b/src/common/OrderingOps.scala @@ -1,8 +1,8 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.util.OverloadHack +import scala.virtualization.lms.util.OverloadHack import scala.reflect.SourceContext trait OrderingOps extends Base with Variables with OverloadHack { @@ -10,35 +10,52 @@ trait OrderingOps extends Base with Variables with OverloadHack { implicit def orderingToOrderingOps[T:Ordering:Manifest](n: T) = new OrderingOpsCls(unit(n)) implicit def repOrderingToOrderingOps[T:Ordering:Manifest](n: Rep[T]) = new OrderingOpsCls(n) implicit def varOrderingToOrderingOps[T:Ordering:Manifest](n: Var[T]) = new OrderingOpsCls(readVar(n)) + implicit val x: Ordering[Array[Byte]] = null + implicit val y: Ordering[Rep[Array[Byte]]] = null class OrderingOpsCls[T:Ordering:Manifest](lhs: Rep[T]){ - def < (rhs: Rep[T])(implicit pos: SourceContext) = ordering_lt(lhs, rhs) - def <= (rhs: Rep[T])(implicit pos: SourceContext) = ordering_lteq(lhs, rhs) - def > (rhs: Rep[T])(implicit pos: SourceContext) = ordering_gt(lhs, rhs) - def >= (rhs: Rep[T])(implicit pos: SourceContext) = ordering_gteq(lhs, rhs) - def equiv (rhs: Rep[T])(implicit pos: SourceContext) = ordering_equiv(lhs, rhs) - def max (rhs: Rep[T])(implicit pos: SourceContext) = ordering_max(lhs, rhs) - def min (rhs: Rep[T])(implicit pos: SourceContext) = ordering_min(lhs, rhs) - def compare (rhs: Rep[T])(implicit pos: SourceContext) = ordering_compare(lhs, rhs) - - def < [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_lt(lhs, c(rhs)) - def <= [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_lteq(lhs, c(rhs)) - def > [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_gt(lhs, c(rhs)) - def >= [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_gteq(lhs, c(rhs)) - def equiv [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_equiv(lhs, c(rhs)) - def max [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_max(lhs, c(rhs)) - def min [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_min(lhs, c(rhs)) - def compare [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_compare(lhs, c(rhs)) + def <(rhs: Rep[T])(implicit pos: SourceContext) = ordering_lt[T](lhs, rhs) + def <=(rhs: Rep[T])(implicit pos: SourceContext) = ordering_lteq[T](lhs, rhs) + def >(rhs: Rep[T])(implicit pos: SourceContext) = ordering_gt[T](lhs, rhs) + def >=(rhs: Rep[T])(implicit pos: SourceContext) = ordering_gteq[T](lhs, rhs) + def equiv(rhs: Rep[T])(implicit pos: SourceContext) = ordering_equiv[T](lhs, rhs) + def max(rhs: Rep[T])(implicit pos: SourceContext) = ordering_max[T](lhs, rhs) + def min(rhs: Rep[T])(implicit pos: SourceContext) = ordering_min[T](lhs, rhs) + + def <[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_lt[T](lhs, c(rhs)) + def <=[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_lteq[T](lhs, c(rhs)) + def >[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_gt[T](lhs, c(rhs)) + def >=[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_gteq[T](lhs, c(rhs)) + def equiv[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_equiv[T](lhs, c(rhs)) + def max[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_max[T](lhs, c(rhs)) + def min[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_min[T](lhs, c(rhs)) + + // We need these methods, e.g. when we are comparing a Double (on rhs) with a Long (on lhs) + // But, they will not solve the problem, because it will happen again other way around! + // def <[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_lt[B](c(lhs), rhs) + // def <=[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_lteq[B](c(lhs), rhs) + // def >[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_gt[B](c(lhs), rhs) + // def >=[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_gteq[B](c(lhs), rhs) + // def equiv[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_equiv[B](c(lhs), rhs) + // def max[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_max[B](c(lhs), rhs) + // def min[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_min[B](c(lhs), rhs) } - def ordering_lt [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_lteq [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_gt [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_gteq [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_equiv [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_max [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] - def ordering_min [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] - def ordering_compare [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Int] +// def infix_<[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_lt(lhs,c(rhs)) +// def infix_<=[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_lteq(lhs,c(rhs)) +// def infix_>[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_gt(lhs,c(rhs)) +// def infix_>=[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_gteq(lhs,c(rhs)) +// def infix_equiv[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_equiv(lhs,c(rhs)) +// def infix_max[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_max(lhs,c(rhs)) +// def infix_min[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_min(lhs,c(rhs)) + + def ordering_lt[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_lteq[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_gt[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_gteq[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_equiv[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_max[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] + def ordering_min[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] } @@ -47,124 +64,48 @@ trait OrderingOpsExp extends OrderingOps with VariablesExp { def mev = manifest[T] def aev = implicitly[Ordering[T]] } - case class OrderingLT [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingLTEQ [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingGT [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingGTEQ [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingEquiv [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingMax [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,T] - case class OrderingMin [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,T] - case class OrderingCompare [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Int] - - def ordering_lt [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingLT(lhs,rhs) - def ordering_lteq [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingLTEQ(lhs,rhs) - def ordering_gt [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingGT(lhs,rhs) - def ordering_gteq [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingGTEQ(lhs,rhs) - def ordering_equiv [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingEquiv(lhs,rhs) - def ordering_max [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = OrderingMax(lhs,rhs) - def ordering_min [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = OrderingMin(lhs,rhs) - def ordering_compare[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Int] = OrderingCompare(lhs,rhs) - - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case e@OrderingLT(a,b) => ordering_lt(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingLTEQ(a,b) => ordering_lteq(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingGT(a,b) => ordering_gt(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingGTEQ(a,b) => ordering_gteq(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingEquiv(a,b) => ordering_equiv(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingMax(a,b) => ordering_max(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev),pos) - case e@OrderingMin(a,b) => ordering_min(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev),pos) - case e@OrderingCompare(a,b) => ordering_compare(f(a),f(b))(e.aev,e.mev,pos) - case Reflect(e@OrderingLT(a,b), u, es) => reflectMirrored(Reflect(OrderingLT(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@OrderingLTEQ(a,b), u, es) => reflectMirrored(Reflect(OrderingLTEQ(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@OrderingGT(a,b), u, es) => reflectMirrored(Reflect(OrderingGT(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@OrderingGTEQ(a,b), u, es) => reflectMirrored(Reflect(OrderingGTEQ(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@OrderingEquiv(a,b), u, es) => reflectMirrored(Reflect(OrderingEquiv(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@OrderingMax(a,b), u, es) => reflectMirrored(Reflect(OrderingMax(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@OrderingMin(a,b), u, es) => reflectMirrored(Reflect(OrderingMin(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(e@OrderingCompare(a,b), u, es) => reflectMirrored(Reflect(OrderingCompare(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case class OrderingLT[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingLTEQ[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingGT[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingGTEQ[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingEquiv[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingMax[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,T] + case class OrderingMin[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,T] + + def ordering_lt[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingLT(lhs,rhs) + def ordering_lteq[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingLTEQ(lhs,rhs) + def ordering_gt[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingGT(lhs,rhs) + def ordering_gteq[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingGTEQ(lhs,rhs) + def ordering_equiv[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingEquiv(lhs,rhs) + def ordering_max[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = OrderingMax(lhs,rhs) + def ordering_min[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = OrderingMin(lhs,rhs) + + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { + (e match { + case e@OrderingLT(a,b) => ordering_lt(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingLTEQ(a,b) => ordering_lteq(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingGT(a,b) => ordering_gt(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingGTEQ(a,b) => ordering_gteq(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingEquiv(a,b) => ordering_equiv(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingMax(a,b) => ordering_max(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev),pos) + case e@OrderingMin(a,b) => ordering_min(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev),pos) case _ => super.mirror(e, f) - }).asInstanceOf[Exp[A]] -} - -/** - * @author Alen Stojanov (astojanov@inf.ethz.ch) - */ -trait OrderingOpsExpOpt extends OrderingOpsExp { - - override def ordering_lt[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { - case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].lt(a, b)) - case (a, b) if a.equals(b) => Const(false) - case _ => super.ordering_lt(lhs, rhs) - } - - override def ordering_lteq[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { - case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].lteq(a, b)) - case (a, b) if a.equals(b) => Const(true) - case _ => super.ordering_lteq(lhs, rhs) - } - - override def ordering_gt[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { - case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].gt(a, b)) - case (a, b) if a.equals(b) => Const(false) - case _ => super.ordering_gt(lhs, rhs) - } - - override def ordering_gteq[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { - case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].gteq(a, b)) - case (a, b) if a.equals(b) => Const(true) - case _ => super.ordering_gteq(lhs, rhs) - } - - override def ordering_equiv[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { - case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].equiv(a, b)) - case (a, b) if a.equals(b) => Const(true) - case _ => super.ordering_equiv(lhs, rhs) - } - - override def ordering_max[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = (lhs, rhs) match { - case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].max(a, b)) - case (a, b) if a.equals(b) => a - case _ => super.ordering_max(lhs, rhs) - } - - override def ordering_min[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = (lhs, rhs) match { - case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].min(a, b)) - case (a, b) if a.equals(b) => a - case _ => super.ordering_min(lhs, rhs) + }).asInstanceOf[Exp[A]] } - - override def ordering_compare[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Int] = (lhs, rhs) match { - case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].compare(a, b)) - case (a, b) if a.equals(b) => Const[Int](0) - case _ => super.ordering_compare(lhs, rhs) - } - } - trait ScalaGenOrderingOps extends ScalaGenBase { val IR: OrderingOpsExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case OrderingLT(a,b) => emitValDef(sym, src"$a < $b") + case lt@OrderingLT(a,b) => emitValDef(sym, src"$a < $b") case OrderingLTEQ(a,b) => emitValDef(sym, src"$a <= $b") case OrderingGT(a,b) => emitValDef(sym, src"$a > $b") case OrderingGTEQ(a,b) => emitValDef(sym, src"$a >= $b") case OrderingEquiv(a,b) => emitValDef(sym, src"$a equiv $b") case OrderingMax(a,b) => emitValDef(sym, src"$a max $b") case OrderingMin(a,b) => emitValDef(sym, src"$a min $b") - case c@OrderingCompare(a,b) => c.mev match { - case m if m == Manifest.Int => emitValDef(sym, "java.lang.Integer.compare("+quote(a)+","+quote(b)+")") - case m if m == Manifest.Long => emitValDef(sym, "java.lang.Long.compare("+quote(a)+","+quote(b)+")") - case m if m == Manifest.Double => emitValDef(sym, "java.lang.Double.compare("+quote(a)+","+quote(b)+")") - case m if m == Manifest.Float => emitValDef(sym, "java.lang.Float.compare("+quote(a)+","+quote(b)+")") - case m if m == Manifest.Boolean => emitValDef(sym, "java.lang.Boolean.compare("+quote(a)+","+quote(b)+")") - case m if m == Manifest.Byte => emitValDef(sym, "java.lang.Byte.compare("+quote(a)+","+quote(b)+")") - case m if m == Manifest.Char => emitValDef(sym, "java.lang.Character.compare("+quote(a)+","+quote(b)+")") - case m if m == Manifest.Short => emitValDef(sym, "java.lang.Short.compare("+quote(a)+","+quote(b)+")") - case _ => emitValDef(sym, quote(a) + " compare " + quote(b)) - } case _ => super.emitNode(sym, rhs) } } @@ -176,7 +117,7 @@ trait CLikeGenOrderingOps extends CLikeGenBase { // TODO: Add MIN/MAX macro needs to C-like header file override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { - case OrderingLT(a,b) => + case lt@OrderingLT(a,b) => emitValDef(sym, src"$a < $b") case OrderingLTEQ(a,b) => emitValDef(sym, src"$a <= $b") @@ -187,10 +128,8 @@ trait CLikeGenOrderingOps extends CLikeGenBase { case OrderingEquiv(a,b) => emitValDef(sym, src"$a == $b") case OrderingMax(a,b) => - //emitValDef(sym, quote(a) + ">" + quote(b) + "?" + quote(a) + ":" + quote(b)) emitValDef(sym, src"MAX($a, $b)") case OrderingMin(a,b) => - //emitValDef(sym, quote(a) + "<" + quote(b) + "?" + quote(a) + ":" + quote(b)) emitValDef(sym, src"MIN($a, $b)") case _ => super.emitNode(sym, rhs) } diff --git a/src/common/Packages.scala b/src/common/Packages.scala index 0786eb9d..5ec6d417 100644 --- a/src/common/Packages.scala +++ b/src/common/Packages.scala @@ -1,7 +1,7 @@ -package scala.lms +package scala.virtualization.lms package common -import scala.lms.common._ +import scala.virtualization.lms.common._ /** * IR: this is the front-end that defines what operations are available in user applications. Backends can share @@ -13,60 +13,65 @@ trait LiftScala extends LiftAll with LiftVariables with LiftEquals { } trait ScalaOpsPkg extends Base - with ImplicitOps with NumericOps with FractionalOps with OrderingOps with StringOps - with RangeOps with IOOps with ArrayOps with BooleanOps with PrimitiveOps with MiscOps - with Equal with IfThenElse with Variables with While with TupleOps with ListOps - with SeqOps with MathOps with CastingOps with SetOps with ObjectOps with ArrayBufferOps + with Structs with ImplicitOps with NumericOps with FractionalOps with OrderingOps + with StringOps with RangeOps with IOOps with ArrayOps with BooleanOps + with PrimitiveOps with MiscOps with Functions with Equal with IfThenElse + with Variables with While with TupleOps with ListOps with SeqOps with MathOps + with CastingOps with SetOps with ObjectOps with ArrayBufferOps + with DateOps with GregorianCalendarOps with SimpleDateFormatOps with UncheckedOps -trait ScalaOpsPkgExp extends ScalaOpsPkg - with ImplicitOpsExp with NumericOpsExp with FractionalOpsExp with OrderingOpsExp with StringOpsExp - with RangeOpsExp with IOOpsExp with ArrayOpsExp with BooleanOpsExp with PrimitiveOpsExp with MiscOpsExp - with FunctionsExp with EqualExp with IfThenElseExp with VariablesExp with WhileExp with TupleOpsExp with ListOpsExp - with SeqOpsExp with DSLOpsExp with MathOpsExp with CastingOpsExp with SetOpsExp with ObjectOpsExp with ArrayBufferOpsExp +trait ScalaOpsPkgExp extends ScalaOpsPkg + with StructExp with ImplicitOpsExp with NumericOpsExp with FractionalOpsExp with OrderingOpsExp + with StringOpsExp with RangeOpsExp with IOOpsExp with ArrayOpsExp with BooleanOpsExp + with PrimitiveOpsExp with MiscOpsExp with FunctionsExp with EqualExp with IfThenElseExp + with VariablesExp with WhileExp with TupleOpsExp with ListOpsExp with SeqOpsExp with MathOpsExp + with CastingOpsExp with SetOpsExp with ObjectOpsExp with ArrayBufferOpsExp + with DateExp with GregorianCalendarExp with SimpleDateFormatExp with UncheckedOpsExp +trait ScalaOpsPkgExpOpt extends ScalaOpsPkgExp + with StructExpOptCommon with NumericOpsExpOpt + with ArrayOpsExpOpt with ListOpsExpOpt + with EqualExpOpt with IfThenElseExpOpt with VariablesExpOpt with WhileExpOpt + with DateExpOpt with GregorianCalendarExpOpt with SimpleDateFormatExpOpt with ObjectOpsExpOpt -/** - * Code gen: each target must define a code generator package. - */ - - -///////// -// Scala +/** Code gen: each target must define a code generator package. */ trait ScalaCodeGenPkg extends ScalaGenImplicitOps with ScalaGenNumericOps with ScalaGenFractionalOps with ScalaGenOrderingOps with ScalaGenStringOps with ScalaGenRangeOps with ScalaGenIOOps with ScalaGenArrayOps with ScalaGenBooleanOps with ScalaGenPrimitiveOps with ScalaGenMiscOps with ScalaGenFunctions with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenVariables with ScalaGenWhile with ScalaGenTupleOps with ScalaGenListOps with ScalaGenSeqOps with ScalaGenDSLOps with ScalaGenMathOps with ScalaGenCastingOps with ScalaGenSetOps - with ScalaGenObjectOps with ScalaGenArrayBufferOps + with ScalaGenObjectOps with ScalaGenArrayBufferOps with ScalaGenDate with ScalaGenGregorianCalendar + with ScalaGenSimpleDateFormat with ScalaGenUncheckedOps { val IR: ScalaOpsPkgExp } ///// // C -trait CCodeGenPkg extends CGenImplicitOps with CGenNumericOps with CGenFractionalOps with CGenOrderingOps - with CGenStringOps with CGenRangeOps with CGenIOOps with CGenArrayOps with CGenBooleanOps +trait COpsPkg extends ScalaOpsPkg +trait COpsPkgExp extends ScalaOpsPkgExp +trait CCodeGenPkg extends CGenDSLOps with CGenImplicitOps with CGenNumericOps with CGenFractionalOps with CGenOrderingOps + with CGenStringOps /*with CGenRangeOps*/ with CGenIOOps with CGenArrayOps with CGenBooleanOps with CGenPrimitiveOps with CGenMiscOps with CGenFunctions with CGenEqual with CGenIfThenElse - with CGenVariables with CGenWhile with CGenTupleOps with CGenListOps - with CGenSeqOps with CGenDSLOps with CGenMathOps with CGenCastingOps with CGenSetOps - with CGenObjectOps with CGenArrayBufferOps - { val IR: ScalaOpsPkgExp } + with CGenVariables with CGenWhile + with CGenMathOps with CGenCastingOps with CGenSetOps with CGenArrayBufferOps with CGenUncheckedOps + { val IR: COpsPkgExp } /////// // Cuda -trait CudaCodeGenPkg extends CudaGenImplicitOps with CudaGenNumericOps with CudaGenFractionalOps with CudaGenOrderingOps - with CudaGenStringOps with CudaGenRangeOps with CudaGenIOOps with CudaGenArrayOps with CudaGenBooleanOps - with CudaGenPrimitiveOps with CudaGenMiscOps with CudaGenFunctions with CudaGenEqual with CudaGenIfThenElse - with CudaGenVariables with CudaGenWhile with CudaGenTupleOps with CudaGenListOps - with CudaGenSeqOps with CudaGenDSLOps with CudaGenMathOps with CudaGenCastingOps with CudaGenSetOps - with CudaGenObjectOps with CudaGenArrayBufferOps +// CudaGenDSLOps will be used after all the basic generators are passed +trait CudaCodeGenPkg extends CudaGenDSLOps with CudaGenImplicitOps with CudaGenNumericOps with CudaGenFractionalOps with CudaGenOrderingOps + with CudaGenStringOps /*with CudaGenRangeOps*/ with CudaGenIOOps with CudaGenArrayOps with CudaGenBooleanOps + with CudaGenPrimitiveOps with CudaGenMiscOps /*with CudaGenFunctions*/ with CudaGenEqual with CudaGenIfThenElse + with CudaGenVariables with CudaGenWhile + with CudaGenMathOps with CudaGenCastingOps with CudaGenSetOps with CudaGenArrayBufferOps { val IR: ScalaOpsPkgExp } -///////// -// OpenCL -trait OpenCLCodeGenPkg extends OpenCLGenImplicitOps with OpenCLGenNumericOps with OpenCLGenFractionalOps with OpenCLGenOrderingOps - with OpenCLGenStringOps with OpenCLGenRangeOps with OpenCLGenIOOps with OpenCLGenArrayOps with OpenCLGenBooleanOps - with OpenCLGenPrimitiveOps with OpenCLGenMiscOps with OpenCLGenFunctions with OpenCLGenEqual with OpenCLGenIfThenElse - with OpenCLGenVariables with OpenCLGenWhile with OpenCLGenTupleOps with OpenCLGenListOps - with OpenCLGenSeqOps with OpenCLGenDSLOps with OpenCLGenMathOps with OpenCLGenCastingOps with OpenCLGenSetOps - with OpenCLGenObjectOps with OpenCLGenArrayBufferOps - { val IR: ScalaOpsPkgExp } \ No newline at end of file +//trait CudaCodeGenPkg extends CudaGenNumericOps with CudaGenRangeOps with CudaGenFractionalOps +// with CudaGenMiscOps with CudaGenFunctions with CudaGenVariables with CudaGenDSLOps with CudaGenImplicitOps { val IR: ScalaOpsPkgExp } + +trait OpenCLCodeGenPkg extends OpenCLGenDSLOps with OpenCLGenImplicitOps with OpenCLGenNumericOps with OpenCLGenFractionalOps with OpenCLGenOrderingOps + with OpenCLGenStringOps /*with OpenCLGenRangeOps*/ with OpenCLGenIOOps with OpenCLGenArrayOps with OpenCLGenBooleanOps + with OpenCLGenPrimitiveOps with OpenCLGenMiscOps /*with OpenCLGenFunctions*/ with OpenCLGenEqual with OpenCLGenIfThenElse + with OpenCLGenVariables with OpenCLGenWhile + with OpenCLGenMathOps with OpenCLGenCastingOps with OpenCLGenSetOps with OpenCLGenArrayBufferOps + { val IR: ScalaOpsPkgExp } diff --git a/src/common/PrimitiveOps.scala b/src/common/PrimitiveOps.scala index 710a6280..9e65f24a 100644 --- a/src/common/PrimitiveOps.scala +++ b/src/common/PrimitiveOps.scala @@ -1,15 +1,16 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.util.OverloadHack +import scala.virtualization.lms.util.OverloadHack import scala.reflect.SourceContext trait LiftPrimitives { this: PrimitiveOps => implicit def intToRepInt(x: Int) = unit(x) + implicit def longToRepLong(x: Long) = unit(x) implicit def floatToRepFloat(x: Float) = unit(x) implicit def doubleToRepDouble(x: Double) = unit(x) @@ -31,133 +32,16 @@ trait PrimitiveOps extends Variables with OverloadHack { /** * Primitive conversions */ - implicit def repIntToRepDouble(x: Rep[Int]): Rep[Double] = x.toDouble - implicit def repIntToRepFloat(x: Rep[Int]): Rep[Float] = x.toFloat - implicit def repFloatToRepDouble(x: Rep[Float]): Rep[Double] = x.toDouble - - - /** - * Enumerate all combinations of primitive math. - * Avoids certain fragile behavior, including compiler crashes and some erroneous or inaccessible type errors. - */ - def infix_-(lhs: Int, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Int] = int_minus(unit(lhs), rhs) - def infix_-(lhs: Int, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_minus(unit(lhs), rhs) - def infix_-(lhs: Int, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_minus(unit(lhs), rhs) - def infix_-(lhs: Float, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Float] = float_minus(unit(lhs),rhs) - def infix_-(lhs: Float, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_minus(unit(lhs), rhs) - def infix_-(lhs: Float, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_minus(unit(lhs), rhs) - def infix_-(lhs: Double, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Double] = double_minus(unit(lhs),rhs) - def infix_-(lhs: Double, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Double] = double_minus(unit(lhs),rhs) - def infix_-(lhs: Double, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_minus(unit(lhs),rhs) - def infix_-(lhs: Rep[Int], rhs: Int)(implicit ctx: SourceContext): Rep[Int] = int_minus(lhs, unit(rhs)) - def infix_-(lhs: Rep[Int], rhs: Double)(implicit ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) - def infix_-(lhs: Rep[Int], rhs: Float)(implicit ctx: SourceContext): Rep[Float] = float_minus(lhs, unit(rhs)) - def infix_-(lhs: Rep[Float], rhs: Int)(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_minus(lhs, unit(rhs)) - def infix_-(lhs: Rep[Float], rhs: Float)(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_minus(lhs, unit(rhs)) - def infix_-(lhs: Rep[Float], rhs: Double)(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) - def infix_-(lhs: Rep[Double], rhs: Int)(implicit o: Overloaded4, ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) - def infix_-(lhs: Rep[Double], rhs: Float)(implicit o: Overloaded5, ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) - def infix_-(lhs: Rep[Double], rhs: Double)(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) - def infix_-(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, ctx: SourceContext): Rep[Int] = int_minus(lhs, rhs) - def infix_-(lhs: Rep[Int], rhs: Rep[Float])(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_minus(repIntToRepFloat(lhs), rhs) - def infix_-(lhs: Rep[Int], rhs: Rep[Double])(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_minus(repIntToRepDouble(lhs), rhs) - def infix_-(lhs: Rep[Float], rhs: Rep[Int])(implicit o: Overloaded4, ctx: SourceContext): Rep[Float] = float_minus(lhs,repIntToRepFloat(rhs)) - def infix_-(lhs: Rep[Float], rhs: Rep[Float])(implicit o: Overloaded5, ctx: SourceContext): Rep[Float] = float_minus(lhs, rhs) - def infix_-(lhs: Rep[Float], rhs: Rep[Double])(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_minus(repFloatToRepDouble(lhs), rhs) - def infix_-(lhs: Rep[Double], rhs: Rep[Int])(implicit o: Overloaded7, ctx: SourceContext): Rep[Double] = double_minus(lhs,repIntToRepDouble(rhs)) - def infix_-(lhs: Rep[Double], rhs: Rep[Float])(implicit o: Overloaded8, ctx: SourceContext): Rep[Double] = double_minus(lhs,repFloatToRepDouble(rhs)) - def infix_-(lhs: Rep[Double], rhs: Rep[Double])(implicit o: Overloaded9, ctx: SourceContext): Rep[Double] = double_minus(lhs,rhs) - - def infix_+(lhs: Int, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Int] = int_plus(unit(lhs), rhs) - def infix_+(lhs: Int, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_plus(unit(lhs), rhs) - def infix_+(lhs: Int, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_plus(unit(lhs), rhs) - def infix_+(lhs: Float, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Float] = float_plus(unit(lhs),rhs) - def infix_+(lhs: Float, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_plus(unit(lhs), rhs) - def infix_+(lhs: Float, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_plus(unit(lhs), rhs) - def infix_+(lhs: Double, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Double] = double_plus(unit(lhs),rhs) - def infix_+(lhs: Double, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Double] = double_plus(unit(lhs),rhs) - def infix_+(lhs: Double, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_plus(unit(lhs),rhs) - def infix_+(lhs: Rep[Int], rhs: Int)(implicit ctx: SourceContext): Rep[Int] = int_plus(lhs, unit(rhs)) - def infix_+(lhs: Rep[Int], rhs: Double)(implicit ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) - def infix_+(lhs: Rep[Int], rhs: Float)(implicit ctx: SourceContext): Rep[Float] = float_plus(lhs, unit(rhs)) - def infix_+(lhs: Rep[Float], rhs: Int)(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_plus(lhs, unit(rhs)) - def infix_+(lhs: Rep[Float], rhs: Float)(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_plus(lhs, unit(rhs)) - def infix_+(lhs: Rep[Float], rhs: Double)(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) - def infix_+(lhs: Rep[Double], rhs: Int)(implicit o: Overloaded4, ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) - def infix_+(lhs: Rep[Double], rhs: Float)(implicit o: Overloaded5, ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) - def infix_+(lhs: Rep[Double], rhs: Double)(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) - def infix_+(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded15, ctx: SourceContext): Rep[Int] = int_plus(lhs, rhs) - def infix_+(lhs: Rep[Int], rhs: Rep[Float])(implicit o: Overloaded16, ctx: SourceContext): Rep[Float] = float_plus(repIntToRepFloat(lhs), rhs) - def infix_+(lhs: Rep[Int], rhs: Rep[Double])(implicit o: Overloaded17, ctx: SourceContext): Rep[Double] = double_plus(repIntToRepDouble(lhs), rhs) - def infix_+(lhs: Rep[Float], rhs: Rep[Int])(implicit o: Overloaded18, ctx: SourceContext): Rep[Float] = float_plus(lhs,repIntToRepFloat(rhs)) - def infix_+(lhs: Rep[Float], rhs: Rep[Float])(implicit o: Overloaded19, ctx: SourceContext): Rep[Float] = float_plus(lhs, rhs) - def infix_+(lhs: Rep[Float], rhs: Rep[Double])(implicit o: Overloaded20, ctx: SourceContext): Rep[Double] = double_plus(repFloatToRepDouble(lhs), rhs) - def infix_+(lhs: Rep[Double], rhs: Rep[Int])(implicit o: Overloaded21, ctx: SourceContext): Rep[Double] = double_plus(lhs,repIntToRepDouble(rhs)) - def infix_+(lhs: Rep[Double], rhs: Rep[Float])(implicit o: Overloaded22, ctx: SourceContext): Rep[Double] = double_plus(lhs,repFloatToRepDouble(rhs)) - def infix_+(lhs: Rep[Double], rhs: Rep[Double])(implicit o: Overloaded23, ctx: SourceContext): Rep[Double] = double_plus(lhs,rhs) - - def infix_*(lhs: Int, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Int] = int_times(unit(lhs), rhs) - def infix_*(lhs: Int, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_times(unit(lhs), rhs) - def infix_*(lhs: Int, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_times(unit(lhs), rhs) - def infix_*(lhs: Float, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Float] = float_times(unit(lhs),rhs) - def infix_*(lhs: Float, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_times(unit(lhs), rhs) - def infix_*(lhs: Float, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_times(unit(lhs), rhs) - def infix_*(lhs: Double, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Double] = double_times(unit(lhs),rhs) - def infix_*(lhs: Double, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Double] = double_times(unit(lhs),rhs) - def infix_*(lhs: Double, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_times(unit(lhs),rhs) - def infix_*(lhs: Rep[Int], rhs: Int)(implicit ctx: SourceContext): Rep[Int] = int_times(lhs, unit(rhs)) - def infix_*(lhs: Rep[Int], rhs: Double)(implicit ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) - def infix_*(lhs: Rep[Int], rhs: Float)(implicit ctx: SourceContext): Rep[Float] = float_times(lhs, unit(rhs)) - def infix_*(lhs: Rep[Float], rhs: Int)(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_times(lhs, unit(rhs)) - def infix_*(lhs: Rep[Float], rhs: Float)(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_times(lhs, unit(rhs)) - def infix_*(lhs: Rep[Float], rhs: Double)(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) - def infix_*(lhs: Rep[Double], rhs: Int)(implicit o: Overloaded4, ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) - def infix_*(lhs: Rep[Double], rhs: Float)(implicit o: Overloaded5, ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) - def infix_*(lhs: Rep[Double], rhs: Double)(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) - def infix_*(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, ctx: SourceContext): Rep[Int] = int_times(lhs, rhs) - def infix_*(lhs: Rep[Int], rhs: Rep[Float])(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_times(repIntToRepFloat(lhs), rhs) - def infix_*(lhs: Rep[Int], rhs: Rep[Double])(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_times(repIntToRepDouble(lhs), rhs) - def infix_*(lhs: Rep[Float], rhs: Rep[Int])(implicit o: Overloaded4, ctx: SourceContext): Rep[Float] = float_times(lhs,repIntToRepFloat(rhs)) - def infix_*(lhs: Rep[Float], rhs: Rep[Float])(implicit o: Overloaded5, ctx: SourceContext): Rep[Float] = float_times(lhs, rhs) - def infix_*(lhs: Rep[Float], rhs: Rep[Double])(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_times(repFloatToRepDouble(lhs), rhs) - def infix_*(lhs: Rep[Double], rhs: Rep[Int])(implicit o: Overloaded7, ctx: SourceContext): Rep[Double] = double_times(lhs,repIntToRepDouble(rhs)) - def infix_*(lhs: Rep[Double], rhs: Rep[Float])(implicit o: Overloaded8, ctx: SourceContext): Rep[Double] = double_times(lhs,repFloatToRepDouble(rhs)) - def infix_*(lhs: Rep[Double], rhs: Rep[Double])(implicit o: Overloaded9, ctx: SourceContext): Rep[Double] = double_times(lhs,rhs) - - def infix_/(lhs: Int, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Int] = int_divide(unit(lhs), rhs) - def infix_/(lhs: Int, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_divide(unit(lhs), rhs) - def infix_/(lhs: Int, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_divide(unit(lhs), rhs) - def infix_/(lhs: Float, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Float] = float_divide(unit(lhs),rhs) - def infix_/(lhs: Float, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_divide(unit(lhs), rhs) - def infix_/(lhs: Float, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_divide(unit(lhs), rhs) - def infix_/(lhs: Double, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Double] = double_divide(unit(lhs),rhs) - def infix_/(lhs: Double, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Double] = double_divide(unit(lhs),rhs) - def infix_/(lhs: Double, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_divide(unit(lhs),rhs) - def infix_/(lhs: Rep[Int], rhs: Int)(implicit ctx: SourceContext): Rep[Int] = int_divide(lhs, unit(rhs)) - def infix_/(lhs: Rep[Int], rhs: Double)(implicit ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) - def infix_/(lhs: Rep[Int], rhs: Float)(implicit ctx: SourceContext): Rep[Float] = float_divide(lhs, unit(rhs)) - def infix_/(lhs: Rep[Float], rhs: Int)(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_divide(lhs, unit(rhs)) - def infix_/(lhs: Rep[Float], rhs: Float)(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_divide(lhs, unit(rhs)) - def infix_/(lhs: Rep[Float], rhs: Double)(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) - def infix_/(lhs: Rep[Double], rhs: Int)(implicit o: Overloaded4, ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) - def infix_/(lhs: Rep[Double], rhs: Float)(implicit o: Overloaded5, ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) - def infix_/(lhs: Rep[Double], rhs: Double)(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) - def infix_/(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, ctx: SourceContext): Rep[Int] = int_divide(lhs, rhs) - def infix_/(lhs: Rep[Int], rhs: Rep[Float])(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_divide(repIntToRepFloat(lhs), rhs) - def infix_/(lhs: Rep[Int], rhs: Rep[Double])(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_divide(repIntToRepDouble(lhs), rhs) - def infix_/(lhs: Rep[Float], rhs: Rep[Int])(implicit o: Overloaded4, ctx: SourceContext): Rep[Float] = float_divide(lhs,repIntToRepFloat(rhs)) - def infix_/(lhs: Rep[Float], rhs: Rep[Float])(implicit o: Overloaded5, ctx: SourceContext): Rep[Float] = float_divide(lhs, rhs) - def infix_/(lhs: Rep[Float], rhs: Rep[Double])(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_divide(repFloatToRepDouble(lhs), rhs) - def infix_/(lhs: Rep[Double], rhs: Rep[Int])(implicit o: Overloaded7, ctx: SourceContext): Rep[Double] = double_divide(lhs,repIntToRepDouble(rhs)) - def infix_/(lhs: Rep[Double], rhs: Rep[Float])(implicit o: Overloaded8, ctx: SourceContext): Rep[Double] = double_divide(lhs,repFloatToRepDouble(rhs)) - def infix_/(lhs: Rep[Double], rhs: Rep[Double])(implicit o: Overloaded9, ctx: SourceContext): Rep[Double] = double_divide(lhs,rhs) + implicit def repIntToRepDouble(x: Rep[Int]): Rep[Double] = implicit_convert[Int,Double](x) + implicit def repIntToRepFloat(x: Rep[Int]): Rep[Float] = implicit_convert[Int,Float](x) + implicit def repFloatToRepDouble(x: Rep[Float]): Rep[Double] = implicit_convert[Float,Double](x) /** * Double */ - implicit def doubleToDoubleOps(n: Double): DoubleOpsCls = new DoubleOpsCls(unit(n)) - implicit def repDoubleToDoubleOps(n: Rep[Double]): DoubleOpsCls = new DoubleOpsCls(n) - implicit def varDoubleToDoubleOps(n: Var[Double]): DoubleOpsCls = new DoubleOpsCls(readVar(n)) + implicit def doubleToDoubleOps(n: Double) = new DoubleOpsCls(unit(n)) + implicit def repDoubleToDoubleOps(n: Rep[Double]) = new DoubleOpsCls(n) + implicit def varDoubleToDoubleOps(n: Var[Double]) = new DoubleOpsCls(readVar(n)) object Double { def parseDouble(s: Rep[String])(implicit pos: SourceContext) = obj_double_parse_double(s) @@ -169,8 +53,6 @@ trait PrimitiveOps extends Variables with OverloadHack { class DoubleOpsCls(lhs: Rep[Double]){ def floatValue()(implicit pos: SourceContext) = double_float_value(lhs) - def toInt(implicit pos: SourceContext) = double_to_int(lhs) - def toFloat(implicit pos: SourceContext) = double_to_float(lhs) } def obj_double_parse_double(s: Rep[String])(implicit pos: SourceContext): Rep[Double] @@ -179,34 +61,11 @@ trait PrimitiveOps extends Variables with OverloadHack { def obj_double_min_value(implicit pos: SourceContext): Rep[Double] def obj_double_max_value(implicit pos: SourceContext): Rep[Double] def double_float_value(lhs: Rep[Double])(implicit pos: SourceContext): Rep[Float] - def double_plus(lhs: Rep[Double], rhs: Rep[Double])(implicit pos: SourceContext): Rep[Double] - def double_minus(lhs: Rep[Double], rhs: Rep[Double])(implicit pos: SourceContext): Rep[Double] - def double_times(lhs: Rep[Double], rhs: Rep[Double])(implicit pos: SourceContext): Rep[Double] - def double_divide(lhs: Rep[Double], rhs: Rep[Double])(implicit pos: SourceContext): Rep[Double] - def double_to_int(lhs: Rep[Double])(implicit pos: SourceContext): Rep[Int] - def double_to_float(lhs: Rep[Double])(implicit pos: SourceContext): Rep[Float] - - /** - * Float - */ - object Float { - def parseFloat(s: Rep[String])(implicit pos: SourceContext) = obj_float_parse_float(s) - } - def infix_toInt(lhs: Rep[Float])(implicit o: Overloaded1, pos: SourceContext): Rep[Int] = float_to_int(lhs) - def infix_toDouble(lhs: Rep[Float])(implicit o: Overloaded1, pos: SourceContext): Rep[Double] = float_to_double(lhs) - - def obj_float_parse_float(s: Rep[String])(implicit pos: SourceContext): Rep[Float] - def float_plus(lhs: Rep[Float], rhs: Rep[Float])(implicit pos: SourceContext): Rep[Float] - def float_minus(lhs: Rep[Float], rhs: Rep[Float])(implicit pos: SourceContext): Rep[Float] - def float_times(lhs: Rep[Float], rhs: Rep[Float])(implicit pos: SourceContext): Rep[Float] - def float_divide(lhs: Rep[Float], rhs: Rep[Float])(implicit pos: SourceContext): Rep[Float] - def float_to_int(lhs: Rep[Float])(implicit pos: SourceContext): Rep[Int] - def float_to_double(lhs: Rep[Float])(implicit pos: SourceContext): Rep[Double] - /** * Int */ + object Integer { def parseInt(s: Rep[String])(implicit pos: SourceContext) = obj_integer_parse_int(s) } @@ -216,9 +75,9 @@ trait PrimitiveOps extends Variables with OverloadHack { def MinValue(implicit pos: SourceContext) = obj_int_min_value } - implicit def intToIntOps(n: Int): IntOpsCls = new IntOpsCls(unit(n)) - implicit def repIntToIntOps(n: Rep[Int]): IntOpsCls = new IntOpsCls(n) - implicit def varIntToIntOps(n: Var[Int]): IntOpsCls = new IntOpsCls(readVar(n)) + implicit def intToIntOps(n: Int) = new IntOpsCls(unit(n)) + implicit def repIntToIntOps(n: Rep[Int]) = new IntOpsCls(n) + implicit def varIntToIntOps(n: Var[Int]) = new IntOpsCls(readVar(n)) class IntOpsCls(lhs: Rep[Int]){ // TODO (tiark): either of these cause scalac to crash @@ -229,28 +88,19 @@ trait PrimitiveOps extends Variables with OverloadHack { def doubleValue()(implicit pos: SourceContext) = int_double_value(lhs) def unary_~()(implicit pos: SourceContext) = int_bitwise_not(lhs) def toLong(implicit pos: SourceContext) = int_tolong(lhs) - def toDouble(implicit pos: SourceContext) = int_to_double(lhs) - def toFloat(implicit pos: SourceContext) = int_to_float(lhs) } - - def infix_%(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_mod(lhs, rhs) - def infix_&(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_binaryand(lhs, rhs) - def infix_|(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_binaryor(lhs, rhs) - def infix_^(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_binaryxor(lhs, rhs) - def infix_<<(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_leftshift(lhs, rhs) - def infix_>>(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_rightshiftarith(lhs, rhs) - def infix_>>>(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_rightshiftlogical(lhs, rhs) + //def infix_/(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_divide(lhs, rhs) //TR triggers bug in Scala-Virtualized 2.10.0 M7 together with Delite ArithOps + def infix_%(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_mod(lhs, rhs) + def infix_&(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_binaryand(lhs, rhs) + def infix_|(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_binaryor(lhs, rhs) + def infix_^(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_binaryxor(lhs, rhs) def obj_integer_parse_int(s: Rep[String])(implicit pos: SourceContext): Rep[Int] def obj_int_max_value(implicit pos: SourceContext): Rep[Int] def obj_int_min_value(implicit pos: SourceContext): Rep[Int] - def int_plus(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] - def int_minus(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] - def int_times(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] - // def int_divide_frac[A:Manifest:Fractional](lhs: Rep[Int], rhs: Rep[A])(implicit pos: SourceContext): Rep[A] + def int_divide_frac[A:Manifest:Fractional](lhs: Rep[Int], rhs: Rep[A])(implicit pos: SourceContext): Rep[A] def int_divide(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] - def int_mod(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] def int_binaryor(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] def int_binaryand(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] @@ -259,38 +109,43 @@ trait PrimitiveOps extends Variables with OverloadHack { def int_double_value(lhs: Rep[Int])(implicit pos: SourceContext): Rep[Double] def int_bitwise_not(lhs: Rep[Int])(implicit pos: SourceContext) : Rep[Int] def int_tolong(lhs: Rep[Int])(implicit pos: SourceContext) : Rep[Long] - def int_to_float(lhs: Rep[Int])(implicit pos: SourceContext) : Rep[Float] - def int_to_double(lhs: Rep[Int])(implicit pos: SourceContext) : Rep[Double] - def int_leftshift(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] - def int_rightshiftarith(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] - def int_rightshiftlogical(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] - + /** * Long */ - object Long { - def parseLong(s: Rep[String])(implicit pos: SourceContext) = obj_long_parse_long(s) - } - - def infix_%(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_mod(lhs, rhs) - def infix_&(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_binaryand(lhs, rhs) - def infix_|(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_binaryor(lhs, rhs) - def infix_<<(lhs: Rep[Long], rhs: Rep[Int])(implicit o: Overloaded2, pos: SourceContext) = long_shiftleft(lhs, rhs) - def infix_>>>(lhs: Rep[Long], rhs: Rep[Int])(implicit o: Overloaded2, pos: SourceContext) = long_shiftright_unsigned(lhs, rhs) - def infix_toInt(lhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_toint(lhs) + def infix_%(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_mod(lhs, rhs) + def infix_&(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_binaryand(lhs, rhs) + def infix_|(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_binaryor(lhs, rhs) + def infix_^(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_binaryxor(lhs, rhs) + def infix_<<(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext) = long_shiftleft(lhs, rhs) + def infix_>>(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext) = long_shiftright(lhs, rhs) + def infix_>>>(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext) = long_shiftright_unsigned(lhs, rhs) + def infix_toInt(lhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_toint(lhs) - def obj_long_parse_long(s: Rep[String])(implicit pos: SourceContext): Rep[Long] def long_mod(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long] def long_binaryand(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long] def long_binaryor(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long] + def long_binaryxor(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long] def long_shiftleft(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Long] + def long_shiftright(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Long] def long_shiftright_unsigned(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Long] def long_toint(lhs: Rep[Long])(implicit pos: SourceContext): Rep[Int] + + /** + * Character + */ + def infix_-(lhs: Rep[Character], rhs: Rep[Character])(implicit pos: SourceContext, o: Overloaded1) = char_minus(lhs, rhs) + def char_minus(lhs: Rep[Character], rhs: Rep[Character])(implicit pos: SourceContext): Rep[Int] + + /** + * Byte + */ + def infix_-(lhs: Rep[Byte], rhs: Rep[Byte])(implicit pos: SourceContext, o: Overloaded2) = char_minus(lhs.asInstanceOf[Rep[Character]], rhs.asInstanceOf[Rep[Character]]) } -trait PrimitiveOpsExp extends PrimitiveOps with EffectExp { +trait PrimitiveOpsExp extends PrimitiveOps with BaseExp { this: ImplicitOps => - + /** * Double */ @@ -300,12 +155,6 @@ trait PrimitiveOpsExp extends PrimitiveOps with EffectExp { case class ObjDoubleMinValue() extends Def[Double] case class ObjDoubleMaxValue() extends Def[Double] case class DoubleFloatValue(lhs: Exp[Double]) extends Def[Float] - case class DoubleToInt(lhs: Exp[Double]) extends Def[Int] - case class DoubleToFloat(lhs: Exp[Double]) extends Def[Float] - case class DoublePlus(lhs: Exp[Double], rhs: Exp[Double]) extends Def[Double] - case class DoubleMinus(lhs: Exp[Double], rhs: Exp[Double]) extends Def[Double] - case class DoubleTimes(lhs: Exp[Double], rhs: Exp[Double]) extends Def[Double] - case class DoubleDivide(lhs: Exp[Double], rhs: Exp[Double]) extends Def[Double] def obj_double_parse_double(s: Exp[String])(implicit pos: SourceContext) = ObjDoubleParseDouble(s) def obj_double_positive_infinity(implicit pos: SourceContext) = ObjDoublePositiveInfinity() @@ -313,80 +162,28 @@ trait PrimitiveOpsExp extends PrimitiveOps with EffectExp { def obj_double_min_value(implicit pos: SourceContext) = ObjDoubleMinValue() def obj_double_max_value(implicit pos: SourceContext) = ObjDoubleMaxValue() def double_float_value(lhs: Exp[Double])(implicit pos: SourceContext) = DoubleFloatValue(lhs) - def double_to_int(lhs: Exp[Double])(implicit pos: SourceContext) = DoubleToInt(lhs) - def double_to_float(lhs: Exp[Double])(implicit pos: SourceContext) = DoubleToFloat(lhs) - def double_plus(lhs: Exp[Double], rhs: Exp[Double])(implicit pos: SourceContext) : Exp[Double] = DoublePlus(lhs,rhs) - def double_minus(lhs: Exp[Double], rhs: Exp[Double])(implicit pos: SourceContext) : Exp[Double] = DoubleMinus(lhs,rhs) - def double_times(lhs: Exp[Double], rhs: Exp[Double])(implicit pos: SourceContext) : Exp[Double] = DoubleTimes(lhs,rhs) - def double_divide(lhs: Exp[Double], rhs: Exp[Double])(implicit pos: SourceContext) : Exp[Double] = DoubleDivide(lhs,rhs) - /** - * Float - */ - case class ObjFloatParseFloat(s: Exp[String]) extends Def[Float] - case class FloatToInt(lhs: Exp[Float]) extends Def[Int] - case class FloatToDouble(lhs: Exp[Float]) extends Def[Double] - case class FloatPlus(lhs: Exp[Float], rhs: Exp[Float]) extends Def[Float] - case class FloatMinus(lhs: Exp[Float], rhs: Exp[Float]) extends Def[Float] - case class FloatTimes(lhs: Exp[Float], rhs: Exp[Float]) extends Def[Float] - case class FloatDivide(lhs: Exp[Float], rhs: Exp[Float]) extends Def[Float] - - def obj_float_parse_float(s: Exp[String])(implicit pos: SourceContext) = ObjFloatParseFloat(s) - def float_to_int(lhs: Exp[Float])(implicit pos: SourceContext) = FloatToInt(lhs) - def float_to_double(lhs: Exp[Float])(implicit pos: SourceContext) = FloatToDouble(lhs) - def float_plus(lhs: Exp[Float], rhs: Exp[Float])(implicit pos: SourceContext) : Exp[Float] = FloatPlus(lhs,rhs) - def float_minus(lhs: Exp[Float], rhs: Exp[Float])(implicit pos: SourceContext) : Exp[Float] = FloatMinus(lhs,rhs) - def float_times(lhs: Exp[Float], rhs: Exp[Float])(implicit pos: SourceContext) : Exp[Float] = FloatTimes(lhs,rhs) - def float_divide(lhs: Exp[Float], rhs: Exp[Float])(implicit pos: SourceContext) : Exp[Float] = FloatDivide(lhs,rhs) - /** * Int */ case class ObjIntegerParseInt(s: Exp[String]) extends Def[Int] case class ObjIntMaxValue() extends Def[Int] case class ObjIntMinValue() extends Def[Int] - case class IntPlus(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] - case class IntMinus(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] - case class IntTimes(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] - // case class IntDivideFrac[A:Manifest:Fractional](lhs: Exp[Int], rhs: Exp[A]) extends Def[A] + case class IntDivideFrac[A:Manifest:Fractional](lhs: Exp[Int], rhs: Exp[A]) extends Def[A] case class IntDivide(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntMod(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntBinaryOr(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntBinaryAnd(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntBinaryXor(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] - case class IntShiftLeft(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] - case class IntShiftRightArith(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] - case class IntShiftRightLogical(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntDoubleValue(lhs: Exp[Int]) extends Def[Double] case class IntFloatValue(lhs: Exp[Int]) extends Def[Float] case class IntBitwiseNot(lhs: Exp[Int]) extends Def[Int] case class IntToLong(lhs: Exp[Int]) extends Def[Long] - case class IntToFloat(lhs: Exp[Int]) extends Def[Float] - case class IntToDouble(lhs: Exp[Int]) extends Def[Double] def obj_integer_parse_int(s: Rep[String])(implicit pos: SourceContext) = ObjIntegerParseInt(s) def obj_int_max_value(implicit pos: SourceContext) = ObjIntMaxValue() def obj_int_min_value(implicit pos: SourceContext) = ObjIntMinValue() - def int_plus(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs, rhs) match { - case (Const(0), r) => r - case (l, Const(0)) => l - case (Const(x), Const(y)) => Const(x+y) - case _ => IntPlus(lhs,rhs) - } - def int_minus(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs, rhs) match { - case (l, Const(0)) => l - case (Const(x), Const(y)) => Const(x-y) - case _ => IntMinus(lhs, rhs) - } - def int_times(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs, rhs) match { - case (l@Const(0), r) => l - case (l, r@Const(0)) => r - case (Const(1), r) => r - case (l, Const(1)) => l - case (Const(x), Const(y)) => Const(x*y) - case _ => IntTimes(lhs, rhs) - } - // def int_divide_frac[A:Manifest:Fractional](lhs: Exp[Int], rhs: Exp[A])(implicit pos: SourceContext) : Exp[A] = IntDivideFrac(lhs, rhs) + def int_divide_frac[A:Manifest:Fractional](lhs: Exp[Int], rhs: Exp[A])(implicit pos: SourceContext) : Exp[A] = IntDivideFrac(lhs, rhs) def int_divide(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = IntDivide(lhs, rhs) def int_mod(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntMod(lhs, rhs) def int_binaryor(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntBinaryOr(lhs, rhs) @@ -396,175 +193,64 @@ trait PrimitiveOpsExp extends PrimitiveOps with EffectExp { def int_float_value(lhs: Exp[Int])(implicit pos: SourceContext) = IntFloatValue(lhs) def int_bitwise_not(lhs: Exp[Int])(implicit pos: SourceContext) = IntBitwiseNot(lhs) def int_tolong(lhs: Exp[Int])(implicit pos: SourceContext) = IntToLong(lhs) - def int_to_float(lhs: Exp[Int])(implicit pos: SourceContext) = IntToFloat(lhs) - def int_to_double(lhs: Exp[Int])(implicit pos: SourceContext) = IntToDouble(lhs) - def int_leftshift(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntShiftLeft(lhs, rhs) - def int_rightshiftarith(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntShiftRightArith(lhs, rhs) - def int_rightshiftlogical(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntShiftRightLogical(lhs, rhs) - - + /** * Long */ - case class ObjLongParseLong(s: Exp[String]) extends Def[Long] + case class LongMod(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] case class LongBinaryOr(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] + case class LongBinaryXor(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] case class LongBinaryAnd(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] case class LongShiftLeft(lhs: Exp[Long], rhs: Exp[Int]) extends Def[Long] + case class LongShiftRight(lhs: Exp[Long], rhs: Exp[Int]) extends Def[Long] case class LongShiftRightUnsigned(lhs: Exp[Long], rhs: Exp[Int]) extends Def[Long] case class LongToInt(lhs: Exp[Long]) extends Def[Int] - case class LongMod(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] - def obj_long_parse_long(s: Exp[String])(implicit pos: SourceContext) = ObjLongParseLong(s) + def long_mod(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongMod(lhs, rhs) def long_binaryor(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryOr(lhs,rhs) - def long_binaryand(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryAnd(lhs,rhs) + def long_binaryxor(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryXor(lhs,rhs) + def long_binaryand(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryAnd(lhs,rhs) def long_shiftleft(lhs: Exp[Long], rhs: Exp[Int])(implicit pos: SourceContext) = LongShiftLeft(lhs,rhs) + def long_shiftright(lhs: Exp[Long], rhs: Exp[Int])(implicit pos: SourceContext) = LongShiftRight(lhs,rhs) def long_shiftright_unsigned(lhs: Exp[Long], rhs: Exp[Int])(implicit pos: SourceContext) = LongShiftRightUnsigned(lhs,rhs) def long_toint(lhs: Exp[Long])(implicit pos: SourceContext) = LongToInt(lhs) - def long_mod(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongMod(lhs, rhs) + /** + * Character + */ + case class CharMinus(lhs: Exp[Character], rhs: Exp[Character]) extends Def[Int] + def char_minus(lhs: Exp[Character], rhs: Exp[Character])(implicit pos: SourceContext) = CharMinus(lhs, rhs) + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = ({ implicit var a: Numeric[A] = null // hack!! need to store it in Def instances?? e match { case ObjDoubleParseDouble(x) => obj_double_parse_double(f(x)) case ObjDoublePositiveInfinity() => obj_double_positive_infinity - case ObjDoubleNegativeInfinity() => obj_double_negative_infinity - case ObjDoubleMinValue() => obj_double_min_value - case ObjDoubleMaxValue() => obj_double_max_value case DoubleFloatValue(x) => double_float_value(f(x)) - case DoubleToInt(x) => double_to_int(f(x)) - case DoubleToFloat(x) => double_to_float(f(x)) - case DoublePlus(x,y) => double_plus(f(x),f(y)) - case DoubleMinus(x,y) => double_minus(f(x),f(y)) - case DoubleTimes(x,y) => double_times(f(x),f(y)) - case DoubleDivide(x,y) => double_divide(f(x),f(y)) - case ObjFloatParseFloat(x) => obj_float_parse_float(f(x)) - case FloatToInt(x) => float_to_int(f(x)) - case FloatToDouble(x) => float_to_double(f(x)) - case FloatPlus(x,y) => float_plus(f(x),f(y)) - case FloatMinus(x,y) => float_minus(f(x),f(y)) - case FloatTimes(x,y) => float_times(f(x),f(y)) - case FloatDivide(x,y) => float_divide(f(x),f(y)) case ObjIntegerParseInt(x) => obj_integer_parse_int(f(x)) - case ObjIntMaxValue() => obj_int_max_value - case ObjIntMinValue() => obj_int_min_value case IntDoubleValue(x) => int_double_value(f(x)) case IntFloatValue(x) => int_float_value(f(x)) case IntBitwiseNot(x) => int_bitwise_not(f(x)) - case IntPlus(x,y) => int_plus(f(x),f(y)) - case IntMinus(x,y) => int_minus(f(x),f(y)) - case IntTimes(x,y) => int_times(f(x),f(y)) case IntDivide(x,y) => int_divide(f(x),f(y)) case IntMod(x,y) => int_mod(f(x),f(y)) - case IntBinaryOr(x,y) => int_binaryor(f(x),f(y)) + case IntBinaryOr(x,y) => int_binaryand(f(x),f(y)) + case IntBinaryXor(x,y) => int_binaryand(f(x),f(y)) case IntBinaryAnd(x,y) => int_binaryand(f(x),f(y)) - case IntBinaryXor(x,y) => int_binaryxor(f(x),f(y)) case IntToLong(x) => int_tolong(f(x)) - case IntToFloat(x) => int_to_float(f(x)) - case IntToDouble(x) => int_to_double(f(x)) - case IntShiftLeft(x,y) => int_leftshift(f(x),f(y)) - case IntShiftRightLogical(x,y) => int_rightshiftlogical(f(x),f(y)) - case IntShiftRightArith(x,y) => int_rightshiftarith(f(x),f(y)) - case ObjLongParseLong(x) => obj_long_parse_long(f(x)) - case LongMod(x,y) => long_mod(f(x),f(y)) case LongShiftLeft(x,y) => long_shiftleft(f(x),f(y)) - case LongBinaryOr(x,y) => long_binaryor(f(x),f(y)) + case LongShiftRight(x,y) => long_shiftright(f(x),f(y)) + case LongMod(x,y) => long_mod(f(x),f(y)) + case LongBinaryOr(x,y) => long_binaryand(f(x),f(y)) + case LongBinaryXor(x,y) => long_binaryand(f(x),f(y)) case LongBinaryAnd(x,y) => long_binaryand(f(x),f(y)) case LongToInt(x) => long_toint(f(x)) case LongShiftRightUnsigned(x,y) => long_shiftright_unsigned(f(x),f(y)) - - case Reflect(ObjDoubleParseDouble(x), u, es) => reflectMirrored(Reflect(ObjDoubleParseDouble(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjDoublePositiveInfinity(), u, es) => reflectMirrored(Reflect(ObjDoublePositiveInfinity(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjDoubleNegativeInfinity(), u, es) => reflectMirrored(Reflect(ObjDoubleNegativeInfinity(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjDoubleMinValue(), u, es) => reflectMirrored(Reflect(ObjDoubleMinValue(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjDoubleMaxValue(), u, es) => reflectMirrored(Reflect(ObjDoubleMaxValue(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(DoubleFloatValue(x), u, es) => reflectMirrored(Reflect(DoubleFloatValue(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(DoubleToInt(x), u, es) => reflectMirrored(Reflect(DoubleToInt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(DoubleToFloat(x), u, es) => reflectMirrored(Reflect(DoubleToFloat(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(DoublePlus(x,y), u, es) => reflectMirrored(Reflect(DoublePlus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(DoubleMinus(x,y), u, es) => reflectMirrored(Reflect(DoubleMinus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(DoubleTimes(x,y), u, es) => reflectMirrored(Reflect(DoubleTimes(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(DoubleDivide(x,y), u, es) => reflectMirrored(Reflect(DoubleDivide(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(FloatToInt(x), u, es) => reflectMirrored(Reflect(FloatToInt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(FloatToDouble(x), u, es) => reflectMirrored(Reflect(FloatToDouble(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(FloatPlus(x,y), u, es) => reflectMirrored(Reflect(FloatPlus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(FloatMinus(x,y), u, es) => reflectMirrored(Reflect(FloatMinus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(FloatTimes(x,y), u, es) => reflectMirrored(Reflect(FloatTimes(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(FloatDivide(x,y), u, es) => reflectMirrored(Reflect(FloatDivide(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjIntegerParseInt(x), u, es) => reflectMirrored(Reflect(ObjIntegerParseInt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjIntMinValue(), u, es) => reflectMirrored(Reflect(ObjIntMinValue(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ObjIntMaxValue(), u, es) => reflectMirrored(Reflect(ObjIntMaxValue(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntDoubleValue(x), u, es) => reflectMirrored(Reflect(IntDoubleValue(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntFloatValue(x), u, es) => reflectMirrored(Reflect(IntFloatValue(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntBitwiseNot(x), u, es) => reflectMirrored(Reflect(IntBitwiseNot(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntPlus(x,y), u, es) => reflectMirrored(Reflect(IntPlus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntMinus(x,y), u, es) => reflectMirrored(Reflect(IntMinus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntTimes(x,y), u, es) => reflectMirrored(Reflect(IntTimes(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntDivide(x,y), u, es) => reflectMirrored(Reflect(IntDivide(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntMod(x,y), u, es) => reflectMirrored(Reflect(IntMod(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntBinaryOr(x,y), u, es) => reflectMirrored(Reflect(IntBinaryOr(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntBinaryAnd(x,y), u, es) => reflectMirrored(Reflect(IntBinaryAnd(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntBinaryXor(x,y), u, es) => reflectMirrored(Reflect(IntBinaryXor(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntToLong(x), u, es) => reflectMirrored(Reflect(IntToLong(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntToFloat(x), u, es) => reflectMirrored(Reflect(IntToFloat(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntToDouble(x), u, es) => reflectMirrored(Reflect(IntToDouble(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntShiftLeft(x,y), u, es) => reflectMirrored(Reflect(IntShiftLeft(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntShiftRightLogical(x,y), u, es) => reflectMirrored(Reflect(IntShiftRightLogical(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(IntShiftRightArith(x,y), u, es) => reflectMirrored(Reflect(IntShiftRightArith(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(LongMod(x,y), u, es) => reflectMirrored(Reflect(LongMod(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(LongShiftLeft(x,y), u, es) => reflectMirrored(Reflect(LongShiftLeft(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(LongShiftRightUnsigned(x,y), u, es) => reflectMirrored(Reflect(LongShiftRightUnsigned(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(LongBinaryOr(x,y), u, es) => reflectMirrored(Reflect(LongBinaryOr(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(LongBinaryAnd(x,y), u, es) => reflectMirrored(Reflect(LongBinaryAnd(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(LongToInt(x), u, es) => reflectMirrored(Reflect(LongToInt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case CharMinus(x,y) => char_minus(f(x),f(y)) case _ => super.mirror(e,f) } }).asInstanceOf[Exp[A]] } -trait PrimitiveOpsExpOpt extends PrimitiveOpsExp { - override def int_plus(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs,rhs) match { - case (Const(a),Const(b)) => unit(a+b) - case (Const(0),b) => b - case (a,Const(0)) => a - case _ => super.int_plus(lhs,rhs) - } - override def int_minus(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs,rhs) match { - case (Const(a),Const(b)) => unit(a-b) - case (a,Const(0)) => a - case (Def(IntPlus(llhs,lrhs)), rhs) if lrhs.equals(rhs) => llhs - case _ => super.int_minus(lhs,rhs) - } - override def int_times(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs,rhs) match { - case (Const(a),Const(b)) => unit(a*b) - case (Const(0),b) => Const(0) - case (Const(1),b) => b - case (a,Const(0)) => Const(0) - case (a,Const(1)) => a - case _ => super.int_times(lhs,rhs) - } - override def int_to_float(lhs: Rep[Int])(implicit pos: SourceContext): Rep[Float] = lhs match { - case Const(x) => Const(x.toFloat) - case _ => super.int_to_float(lhs) - } - - override def int_to_double(lhs: Rep[Int])(implicit pos: SourceContext): Rep[Double] = lhs match { - case Const(x) => Const(x.toDouble) - case _ => super.int_to_double(lhs) - } - - override def float_to_double(lhs: Rep[Float])(implicit pos: SourceContext): Rep[Double] = lhs match { - case Const(x) => Const(x.toDouble) - case Def(IntToFloat(x)) => int_to_double(x) - case _ => super.float_to_double(lhs) - } - - override def double_to_int(lhs: Rep[Double])(implicit pos: SourceContext): Rep[Int] = lhs match { - case Const(x) => Const(x.toInt) - case Def(IntToDouble(x)) => x - case _ => super.double_to_int(lhs) - } -} - trait ScalaGenPrimitiveOps extends ScalaGenBase { val IR: PrimitiveOpsExp import IR._ @@ -575,48 +261,28 @@ trait ScalaGenPrimitiveOps extends ScalaGenBase { case ObjDoubleNegativeInfinity() => emitValDef(sym, "scala.Double.NegativeInfinity") case ObjDoubleMinValue() => emitValDef(sym, "scala.Double.MinValue") case ObjDoubleMaxValue() => emitValDef(sym, "scala.Double.MaxValue") - case DoubleFloatValue(lhs) => emitValDef(sym, quote(lhs) + ".floatValue()") - case DoublePlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) - case DoubleMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) - case DoubleTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) - case DoubleDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) - case DoubleToInt(lhs) => emitValDef(sym, quote(lhs) + ".toInt") - case DoubleToFloat(lhs) => emitValDef(sym, quote(lhs) + ".toFloat") - case ObjFloatParseFloat(s) => emitValDef(sym, "java.lang.Float.parseFloat(" + quote(s) + ")") - case FloatToInt(lhs) => emitValDef(sym, quote(lhs) + ".toInt") - case FloatToDouble(lhs) => emitValDef(sym, quote(lhs) + ".toDouble") - case FloatPlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) - case FloatMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) - case FloatTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) - case FloatDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) - case ObjIntegerParseInt(s) => emitValDef(sym, "java.lang.Integer.parseInt(" + quote(s) + ")") + case DoubleFloatValue(lhs) => emitValDef(sym, src"$lhs.floatValue()") + case ObjIntegerParseInt(s) => emitValDef(sym, src"java.lang.Integer.parseInt($s)") case ObjIntMaxValue() => emitValDef(sym, "scala.Int.MaxValue") - case ObjIntMinValue() => emitValDef(sym, "scala.Int.MinValue") - case IntPlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) - case IntMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) - case IntTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) - // case IntDivideFrac(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) - case IntDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) - case IntMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs)) - case IntBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs)) - case IntBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs)) - case IntBinaryXor(lhs,rhs) => emitValDef(sym, quote(lhs) + " ^ " + quote(rhs)) - case IntShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs)) - case IntShiftRightArith(lhs, rhs) => emitValDef(sym, quote(lhs) + " >> " + quote(rhs)) - case IntShiftRightLogical(lhs, rhs) => emitValDef(sym, quote(lhs) + " >>> " + quote(rhs)) - case IntDoubleValue(lhs) => emitValDef(sym, quote(lhs) + ".doubleValue()") - case IntFloatValue(lhs) => emitValDef(sym, quote(lhs) + ".floatValue()") - case IntBitwiseNot(lhs) => emitValDef(sym, "~" + quote(lhs)) - case IntToLong(lhs) => emitValDef(sym, quote(lhs) + ".toLong") - case IntToFloat(lhs) => emitValDef(sym, quote(lhs) + ".toFloat") - case IntToDouble(lhs) => emitValDef(sym, quote(lhs) + ".toDouble") - case ObjLongParseLong(s) => emitValDef(sym, "java.lang.Long.parseLong(" + quote(s) + ")") - case LongMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs)) - case LongBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs)) - case LongBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs)) - case LongShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs)) - case LongShiftRightUnsigned(lhs,rhs) => emitValDef(sym, quote(lhs) + " >>> " + quote(rhs)) - case LongToInt(lhs) => emitValDef(sym, quote(lhs) + ".toInt") + case ObjIntMinValue() => emitValDef(sym, "scala.Int.MinValue") + case IntDivideFrac(lhs,rhs) => emitValDef(sym, src"$lhs / $rhs") + case IntDivide(lhs,rhs) => emitValDef(sym, src"$lhs / $rhs") + case IntMod(lhs,rhs) => emitValDef(sym, src"$lhs % $rhs") + case IntBinaryOr(lhs,rhs) => emitValDef(sym, src"$lhs | $rhs") + case IntBinaryAnd(lhs,rhs) => emitValDef(sym, src"$lhs & $rhs") + case IntBinaryXor(lhs,rhs) => emitValDef(sym, src"$lhs ^ $rhs") + case IntDoubleValue(lhs) => emitValDef(sym, src"$lhs.doubleValue()") + case IntFloatValue(lhs) => emitValDef(sym, src"$lhs.floatValue()") + case IntBitwiseNot(lhs) => emitValDef(sym, src"~$lhs") + case IntToLong(lhs) => emitValDef(sym, src"$lhs.toLong") + case LongBinaryOr(lhs,rhs) => emitValDef(sym, src"$lhs | $rhs") + case LongBinaryXor(lhs,rhs) => emitValDef(sym, src"$lhs ^ $rhs") + case LongBinaryAnd(lhs,rhs) => emitValDef(sym, src"$lhs & $rhs") + case LongShiftLeft(lhs,rhs) => emitValDef(sym, src"$lhs << $rhs") + case LongShiftRight(lhs,rhs) => emitValDef(sym, src"$lhs >> $rhs") + case LongShiftRightUnsigned(lhs,rhs) => emitValDef(sym, src"$lhs >>> $rhs") + case LongToInt(lhs) => emitValDef(sym, src"$lhs.toInt") + case CharMinus(lhs,rhs) => emitValDef(sym, src"$lhs - $rhs") case _ => super.emitNode(sym, rhs) } } @@ -625,83 +291,35 @@ trait CLikeGenPrimitiveOps extends CLikeGenBase { val IR: PrimitiveOpsExp import IR._ + //TODO: stdlib.h needs to be included in the common header file override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { - case ObjDoubleParseDouble(s) => emitValDef(sym, "strtod(" + quote(s) + ",NULL)") - case ObjDoubleMinValue() => emitValDef(sym, "DBL_MIN") - case ObjDoubleMaxValue() => emitValDef(sym, "DBL_MAX") - case DoubleFloatValue(lhs) => emitValDef(sym, "(float)"+quote(lhs)) - case DoublePlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) - case DoubleMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) - case DoubleTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) - case DoubleDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) - case DoubleToInt(lhs) => emitValDef(sym, "(int32_t)" + quote(lhs)) - case DoubleToFloat(lhs) => emitValDef(sym, "(float)" + quote(lhs)) - case ObjFloatParseFloat(s) => emitValDef(sym, "strtof(" + quote(s) + ".c_str(),NULL)") - case FloatToInt(lhs) => emitValDef(sym, "(int32_t)" + quote(lhs)) - case FloatToDouble(lhs) => emitValDef(sym, "(double)" + quote(lhs)) - case FloatPlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) - case FloatMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) - case FloatTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) - case FloatDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) - case ObjIntegerParseInt(s) => emitValDef(sym, "atoi(" + quote(s) + ".c_str())") - case ObjIntMaxValue() => emitValDef(sym, "INT_MAX") - case ObjIntMinValue() => emitValDef(sym, "INT_MIN") - case IntPlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) - case IntMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) - case IntTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) - // case IntDivideFrac(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) - case IntDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) - case IntMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs)) - case IntBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs)) - case IntBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs)) - case IntBinaryXor(lhs,rhs) => emitValDef(sym, quote(lhs) + " ^ " + quote(rhs)) - case IntShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs)) - case IntShiftRightArith(lhs, rhs) => emitValDef(sym, quote(lhs) + " >> " + quote(rhs)) - case IntShiftRightLogical(lhs, rhs) => emitValDef(sym, "(uint32_t)" + quote(lhs) + " >> " + quote(rhs)) - case IntDoubleValue(lhs) => emitValDef(sym, "(double)"+quote(lhs)) - case IntFloatValue(lhs) => emitValDef(sym, "(float)"+quote(lhs)) - case IntBitwiseNot(lhs) => emitValDef(sym, "~" + quote(lhs)) - case IntToLong(lhs) => emitValDef(sym, "(int64_t)"+quote(lhs)) - case IntToFloat(lhs) => emitValDef(sym, "(float)"+quote(lhs)) - case IntToDouble(lhs) => emitValDef(sym, "(double)"+quote(lhs)) - case ObjLongParseLong(s) => emitValDef(sym, "strtod(" + quote(s) + ".c_str(),NULL)") - case LongMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs)) - case LongBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs)) - case LongBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs)) - case LongShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs)) - case LongShiftRightUnsigned(lhs,rhs) => emitValDef(sym, "(uint64_t)" + quote(lhs) + " >> " + quote(rhs)) - case LongToInt(lhs) => emitValDef(sym, "(int32_t)"+quote(lhs)) - case _ => super.emitNode(sym, rhs) - } - } -} - -trait CudaGenPrimitiveOps extends CudaGenBase with CLikeGenPrimitiveOps { - val IR: PrimitiveOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { - rhs match { - case ObjDoublePositiveInfinity() => emitValDef(sym, "__longlong_as_double(0x7ff0000000000000ULL)") - case ObjDoubleNegativeInfinity() => emitValDef(sym, "__longlong_as_double(0xfff0000000000000ULL)") + //case ObjDoubleParseDouble(s) => emitValDef(sym, "atof(" + quote(s) + ")") + case ObjDoublePositiveInfinity() => emitValDef(sym, "DBL_MAX") + //case ObjDoubleMinValue() => emitValDef(sym, "scala.Double.MinValue") + case DoubleFloatValue(lhs) => emitValDef(sym, src"(float)$lhs") + //case ObjIntegerParseInt(s) => emitValDef(sym, "java.lang.Integer.parseInt(" + quote(s) + ")") + //case ObjIntMaxValue() => emitValDef(sym, "scala.Int.MaxValue") + case IntDivideFrac(lhs,rhs) => emitValDef(sym, src"$lhs / $rhs") + case IntDivide(lhs,rhs) => emitValDef(sym, src"$lhs / $rhs") + case IntMod(lhs,rhs) => emitValDef(sym, src"$lhs % $rhs") + case IntBinaryOr(lhs,rhs) => emitValDef(sym, src"$lhs | $rhs") + case IntBinaryAnd(lhs,rhs) => emitValDef(sym, src"$lhs & $rhs") + case IntDoubleValue(lhs) => emitValDef(sym, src"(double)$lhs") + case LongMod(lhs,rhs) => emitValDef(sym, src"$lhs % $rhs") + case LongToInt(lhs) => emitValDef(sym, src"(int)$lhs") + case LongBinaryOr(lhs,rhs) => emitValDef(sym, src"$lhs | $rhs") + case LongBinaryAnd(lhs,rhs) => emitValDef(sym, src"$lhs & $rhs") + case CharMinus(lhs,rhs) => emitValDef(sym, src"$lhs - $rhs") + case LongShiftLeft(lhs,rhs) => emitValDef(sym, src"$lhs << $rhs") + case LongShiftRight(lhs,rhs) => emitValDef(sym, src"$lhs >> $rhs") + case LongShiftRightUnsigned(lhs,rhs) => emitValDef(sym, src"$lhs >>> $rhs") case _ => super.emitNode(sym, rhs) } } } +trait CudaGenPrimitiveOps extends CudaGenBase with CLikeGenPrimitiveOps trait OpenCLGenPrimitiveOps extends OpenCLGenBase with CLikeGenPrimitiveOps - -trait CGenPrimitiveOps extends CGenBase with CLikeGenPrimitiveOps { - val IR: PrimitiveOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { - rhs match { - case ObjDoublePositiveInfinity() => emitValDef(sym, "INFINITY") - case ObjDoubleNegativeInfinity() => emitValDef(sym, "-INFINITY") - case _ => super.emitNode(sym, rhs) - } - } -} +trait CGenPrimitiveOps extends CGenBase with CLikeGenPrimitiveOps diff --git a/src/common/RangeOps.scala b/src/common/RangeOps.scala index 8afb8dfb..4532cf93 100644 --- a/src/common/RangeOps.scala +++ b/src/common/RangeOps.scala @@ -1,29 +1,42 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException} +import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException} import scala.reflect.SourceContext trait RangeOps extends Base { - // workaround for infix not working with manifests - implicit def repRangeToRangeOps(r: Rep[Range]) = new rangeOpsCls(r) - class rangeOpsCls(r: Rep[Range]){ + trait LongRange + + implicit class rangeOpsCls(r: Rep[Range]) { def foreach(f: Rep[Int] => Rep[Unit])(implicit pos: SourceContext) = range_foreach(r, f) } + implicit class lrangeOpsCls(r: Rep[LongRange]) { + def foreach(f: Rep[Long] => Rep[Unit])(implicit pos: SourceContext) = lrange_foreach(r, f) + } + def infix_until(start: Rep[Int], end: Rep[Int])(implicit pos: SourceContext) = range_until(start,end) + def infix_until(start: Rep[Long], end: Rep[Long])(implicit pos: SourceContext, o: Overloaded1) = lrange_until(start,end) def infix_start(r: Rep[Range])(implicit pos: SourceContext) = range_start(r) + def infix_start(r: Rep[LongRange])(implicit pos: SourceContext, o: Overloaded1) = lrange_start(r) def infix_step(r: Rep[Range])(implicit pos: SourceContext) = range_step(r) + def infix_step(r: Rep[LongRange])(implicit pos: SourceContext, o: Overloaded1) = lrange_step(r) def infix_end(r: Rep[Range])(implicit pos: SourceContext) = range_end(r) - //def infix_foreach(r: Rep[Range], f: Rep[Int] => Rep[Unit]) = range_foreach(r, f) + def infix_end(r: Rep[LongRange])(implicit pos: SourceContext, o: Overloaded1) = lrange_end(r) def range_until(start: Rep[Int], end: Rep[Int])(implicit pos: SourceContext): Rep[Range] def range_start(r: Rep[Range])(implicit pos: SourceContext) : Rep[Int] def range_step(r: Rep[Range])(implicit pos: SourceContext) : Rep[Int] def range_end(r: Rep[Range])(implicit pos: SourceContext) : Rep[Int] def range_foreach(r: Rep[Range], f: (Rep[Int]) => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] + + def lrange_until(start: Rep[Long], end: Rep[Long])(implicit pos: SourceContext): Rep[LongRange] + def lrange_start(r: Rep[LongRange])(implicit pos: SourceContext) : Rep[Long] + def lrange_step(r: Rep[LongRange])(implicit pos: SourceContext) : Rep[Long] + def lrange_end(r: Rep[LongRange])(implicit pos: SourceContext) : Rep[Long] + def lrange_foreach(r: Rep[LongRange], f: (Rep[Long]) => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] } trait RangeOpsExp extends RangeOps with FunctionsExp { @@ -31,19 +44,23 @@ trait RangeOpsExp extends RangeOps with FunctionsExp { case class RangeStart(r: Exp[Range]) extends Def[Int] case class RangeStep(r: Exp[Range]) extends Def[Int] case class RangeEnd(r: Exp[Range]) extends Def[Int] - //case class RangeForeach(r: Exp[Range], i: Exp[Int], body: Exp[Unit]) extends Def[Unit] case class RangeForeach(start: Exp[Int], end: Exp[Int], i: Sym[Int], body: Block[Unit]) extends Def[Unit] + case class LongUntil(start: Exp[Long], end: Exp[Long]) extends Def[LongRange] + case class LongRangeStart(r: Exp[LongRange]) extends Def[Long] + case class LongRangeStep(r: Exp[LongRange]) extends Def[Long] + case class LongRangeEnd(r: Exp[LongRange]) extends Def[Long] + case class LongRangeForeach(start: Exp[Long], end: Exp[Long], i: Sym[Long], body: Block[Unit]) extends Def[Unit] + + def range_until(start: Exp[Int], end: Exp[Int])(implicit pos: SourceContext) : Exp[Range] = Until(start, end) def range_start(r: Exp[Range])(implicit pos: SourceContext) : Exp[Int] = r match { case Def(Until(start, end)) => start - case Def(Reflect(Until(start, end), u, es)) => start case _ => RangeStart(r) } def range_step(r: Exp[Range])(implicit pos: SourceContext) : Exp[Int] = RangeStep(r) def range_end(r: Exp[Range])(implicit pos: SourceContext) : Exp[Int] = r match { case Def(Until(start, end)) => end - case Def(Reflect(Until(start, end), u, es)) => end case _ => RangeEnd(r) } def range_foreach(r: Exp[Range], block: Exp[Int] => Exp[Unit])(implicit pos: SourceContext) : Exp[Unit] = { @@ -51,29 +68,45 @@ trait RangeOpsExp extends RangeOps with FunctionsExp { val a = reifyEffects(block(i)) reflectEffect(RangeForeach(r.start, r.end, i, a), summarizeEffects(a).star) } + + def lrange_until(start: Exp[Long], end: Exp[Long])(implicit pos: SourceContext) : Exp[LongRange] = LongUntil(start, end) + def lrange_start(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = r match { + case Def(LongUntil(start, end)) => start + case _ => LongRangeStart(r) + } + def lrange_step(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = LongRangeStep(r) + def lrange_end(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = r match { + case Def(LongUntil(start, end)) => end + case _ => LongRangeEnd(r) + } + def lrange_foreach(r: Exp[LongRange], block: Exp[Long] => Exp[Unit])(implicit pos: SourceContext) : Exp[Unit] = { + val i = fresh[Long] + val a = reifyEffects(block(i)) + reflectEffect(LongRangeForeach(r.start, r.end, i, a), summarizeEffects(a).star) + } override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case Reflect(RangeForeach(s,e,i,b), u, es) => reflectMirrored(Reflect(RangeForeach(f(s),f(e),f(i).asInstanceOf[Sym[Int]],f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(RangeStart(r), u, es) => reflectMirrored(Reflect(RangeStart(f(r)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(RangeStep(r), u, es) => reflectMirrored(Reflect(RangeStep(f(r)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(RangeEnd(r), u, es) => reflectMirrored(Reflect(RangeEnd(f(r)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(Until(s,e), u, es) => reflectMirrored(Reflect(Until(f(s),f(e)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(RangeForeach(s,e,i,b), u, es) => reflectMirrored(Reflect(RangeForeach(f(s),f(e),f(i).asInstanceOf[Sym[Int]],f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(LongRangeForeach(s,e,i,b), u, es) => reflectMirrored(Reflect(LongRangeForeach(f(s),f(e),f(i).asInstanceOf[Sym[Long]],f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] override def syms(e: Any): List[Sym[Any]] = e match { case RangeForeach(start, end, i, body) => syms(start):::syms(end):::syms(body) + case LongRangeForeach(start, end, i, body) => syms(start):::syms(end):::syms(body) case _ => super.syms(e) } override def boundSyms(e: Any): List[Sym[Any]] = e match { case RangeForeach(start, end, i, y) => i :: effectSyms(y) + case LongRangeForeach(start, end, i, y) => i :: effectSyms(y) case _ => super.boundSyms(e) } override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { case RangeForeach(start, end, i, body) => freqNormal(start):::freqNormal(end):::freqHot(body) + case LongRangeForeach(start, end, i, body) => freqNormal(start):::freqNormal(end):::freqHot(body) case _ => super.symsFreq(e) } @@ -104,9 +137,9 @@ trait ScalaGenRangeOps extends ScalaGenEffect with BaseGenRangeOps { case RangeForeach(start, end, i, body) => { // do not need to print unit result //stream.println(quote(getBlockResult(body))) - gen"""var $i : Int = $start - |val $sym = while ($i < $end) { - |${nestedBlock(body)} + gen"var $i : Int = $start" + emitValDef(sym, src"while ($i < $end) {") + gen"""${nestedBlock(body)} |$i = $i + 1 |}""" } @@ -167,15 +200,36 @@ trait OpenCLGenRangeOps extends OpenCLGenEffect with BaseGenRangeOps { trait CGenRangeOps extends CGenEffect with BaseGenRangeOps { val IR: RangeOpsExp import IR._ + + override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { + case RangeForeach(start, end, i, body) => { + LIRTraversal(body) + sym.atPhase(LIRLowering) { + val b = LIRLowering(body) + val be = summarizeEffects(b) + reflectEffect(RangeForeach(LIRLowering(start), LIRLowering(end), i, b), be.star).asInstanceOf[Exp[T]] + } + } + case _ => super.lowerNode(sym, rhs) + } override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case Until(start, end) => throw new GenerationFailedException("CGenRangeOps: Range vector is not supported") case RangeForeach(start, end, i, body) => - gen"""for(int $i=$start; $i < $end; $i++) { + // Some compilers don't like the initialization inside for + stream.println(remap(i.tp) + " " + quote(i) + ";") + gen"""for($i=$start; $i < $end; $i++) { + |${nestedBlock(body)} + |}""" + case LongRangeForeach(start, end, i, body) => + // Some compilers don't like the initialization inside for + stream.println(remap(i.tp) + " " + quote(i) + ";") + gen"""for($i=$start; $i < $end; $i++) { |${nestedBlock(body)} |}""" + case _ => super.emitNode(sym, rhs) } } diff --git a/src/common/SeqOps.scala b/src/common/SeqOps.scala index e60810ca..89d5cf37 100644 --- a/src/common/SeqOps.scala +++ b/src/common/SeqOps.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter diff --git a/src/common/SetOps.scala b/src/common/SetOps.scala index c965a092..9444ce09 100644 --- a/src/common/SetOps.scala +++ b/src/common/SetOps.scala @@ -1,17 +1,19 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal._ +import scala.virtualization.lms.internal._ import scala.collection.mutable.Set import scala.reflect.SourceContext -trait SetOps extends Base { +trait SetOps extends Base with Variables { object Set { def apply[A:Manifest](xs: Rep[A]*)(implicit pos: SourceContext) = set_new[A](xs) + def empty = set_empty() } implicit def repSetToSetOps[A:Manifest](v: Rep[Set[A]]) = new setOpsCls(v) + implicit def varSetToSetOps[A:Manifest](v: Var[Set[A]]) = new setOpsCls(readVar(v)) class setOpsCls[A:Manifest](s: Rep[Set[A]]) { def contains(i: Rep[A])(implicit pos: SourceContext) = set_contains(s, i) @@ -21,39 +23,92 @@ trait SetOps extends Base { def clear()(implicit pos: SourceContext) = set_clear(s) def toSeq(implicit pos: SourceContext) = set_toseq(s) def toArray(implicit pos: SourceContext) = set_toarray(s) + def map[B:Manifest](f: Rep[A] => Rep[B]) = set_map(s,f) + def foreach(block: Rep[A] => Rep[Unit])(implicit pos: SourceContext) = set_foreach(s, block) + def head(implicit pos: SourceContext) = set_head(s) } def set_new[A:Manifest](xs: Seq[Rep[A]])(implicit pos: SourceContext) : Rep[Set[A]] def set_contains[A:Manifest](s: Rep[Set[A]], i: Rep[A])(implicit pos: SourceContext) : Rep[Boolean] def set_add[A:Manifest](s: Rep[Set[A]], i: Rep[A])(implicit pos: SourceContext) : Rep[Unit] - def set_remove[A:Manifest](s: Rep[Set[A]], i: Rep[A])(implicit pos: SourceContext) : Rep[Unit] + def set_remove[A:Manifest](s: Rep[Set[A]], i: Rep[A])(implicit pos: SourceContext) : Rep[Boolean] def set_size[A:Manifest](s: Rep[Set[A]])(implicit pos: SourceContext) : Rep[Int] + def set_map[A:Manifest,B:Manifest](a: Rep[Set[A]], f: Rep[A] => Rep[B]): Rep[Set[B]] def set_clear[A:Manifest](s: Rep[Set[A]])(implicit pos: SourceContext) : Rep[Unit] def set_toseq[A:Manifest](s: Rep[Set[A]])(implicit pos: SourceContext): Rep[Seq[A]] def set_toarray[A:Manifest](s: Rep[Set[A]])(implicit pos: SourceContext): Rep[Array[A]] + def set_foreach[T:Manifest](x: Rep[Set[T]], block: Rep[T] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] + def set_empty[T:Manifest]() : Rep[Set[T]] + def set_head[T:Manifest](m: Rep[Set[T]])(implicit pos: SourceContext): Rep[T] } trait SetOpsExp extends SetOps with ArrayOps with EffectExp { case class SetNew[A:Manifest](xs: Seq[Exp[A]], mA: Manifest[A]) extends Def[Set[A]] case class SetContains[A:Manifest](s: Exp[Set[A]], i: Exp[A]) extends Def[Boolean] case class SetAdd[A:Manifest](s: Exp[Set[A]], i: Exp[A]) extends Def[Unit] - case class SetRemove[A:Manifest](s: Exp[Set[A]], i: Exp[A]) extends Def[Unit] + case class SetRemove[A:Manifest](s: Exp[Set[A]], i: Exp[A]) extends Def[Boolean] { + val m = manifest[A] + } case class SetSize[A:Manifest](s: Exp[Set[A]]) extends Def[Int] case class SetClear[A:Manifest](s: Exp[Set[A]]) extends Def[Unit] case class SetToSeq[A:Manifest](s: Exp[Set[A]]) extends Def[Seq[A]] - case class SetToArray[A:Manifest](s: Exp[Set[A]]) extends Def[Array[A]] { - //val array = unit(manifest[A].newArray(0)) - val array = NewArray[A](s.size) + case class SetToArray[A:Manifest](s: Exp[Set[A]]) extends Def[Array[A]] + case class SetMap[A:Manifest,B:Manifest](a: Exp[Set[A]], x: Sym[A], block: Block[B]) extends Def[Set[B]] + case class SetForeach[T](a: Exp[Set[T]], x: Sym[T], block: Block[Unit]) extends Def[Unit] + case class SetEmpty[T:Manifest]() extends Def[Set[T]] { + val m = manifest[T] + } + case class SetHead[T:Manifest](s: Exp[Set[T]]) extends Def[T] { + val m = manifest[T] } def set_new[A:Manifest](xs: Seq[Exp[A]])(implicit pos: SourceContext) = reflectMutable(SetNew(xs, manifest[A])) def set_contains[A:Manifest](s: Exp[Set[A]], i: Exp[A])(implicit pos: SourceContext) = SetContains(s, i) def set_add[A:Manifest](s: Exp[Set[A]], i: Exp[A])(implicit pos: SourceContext) = reflectWrite(s)(SetAdd(s, i)) - def set_remove[A:Manifest](s: Exp[Set[A]], i: Exp[A])(implicit pos: SourceContext) = reflectWrite(s)(SetRemove(s, i)) + def set_remove[A:Manifest](s: Exp[Set[A]], i: Exp[A])(implicit pos: SourceContext) = reflectEffect(SetRemove(s, i)) def set_size[A:Manifest](s: Exp[Set[A]])(implicit pos: SourceContext) = SetSize(s) def set_clear[A:Manifest](s: Exp[Set[A]])(implicit pos: SourceContext) = reflectWrite(s)(SetClear(s)) def set_toseq[A:Manifest](s: Exp[Set[A]])(implicit pos: SourceContext) = SetToSeq(s) def set_toarray[A:Manifest](s: Exp[Set[A]])(implicit pos: SourceContext) = SetToArray(s) + def set_foreach[T:Manifest](a: Exp[Set[T]], block: Exp[T] => Exp[Unit])(implicit pos: SourceContext): Exp[Unit] = { + val x = fresh[T] + val b = reifyEffects(block(x)) + reflectEffect(SetForeach(a, x, b), summarizeEffects(b).star) + } + def set_map[A:Manifest,B:Manifest](a: Exp[Set[A]], f: Exp[A] => Exp[B]) = { + val x = fresh[A] + val b = reifyEffects(f(x)) + reflectEffect(SetMap(a, x, b), summarizeEffects(b)) + } + def set_empty[T:Manifest]() = reflectEffect(SetEmpty()) + def set_head[T:Manifest](s: Exp[Set[T]])(implicit pos: SourceContext) = reflectEffect(SetHead(s)) + + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { + (e match { + case Reflect(st@SetHead(s), u, es) => reflectMirrored(Reflect(SetHead(f(s))(st.m), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(st@SetRemove(s,el), u, es) => reflectMirrored(Reflect(SetRemove(f(s),f(el))(st.m), mapOver(f,u), f(es)))(mtype(manifest[A])) + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] // why?? + } + + override def syms(e: Any): List[Sym[Any]] = e match { + case SetForeach(a, x, body) => syms(a):::syms(body) + case SetMap(a, x, body) => syms(a):::syms(body) + case _ => super.syms(e) + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case SetForeach(a, x, body) => x :: effectSyms(body) + case SetMap(a, x, body) => x :: effectSyms(body) + case _ => super.boundSyms(e) + } + + override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case SetForeach(a, x, body) => freqNormal(a):::freqHot(body) + case SetMap(a, x, body) => freqNormal(a):::freqHot(body) + case _ => super.symsFreq(e) + } + } trait BaseGenSetOps extends GenericNestedCodegen { @@ -65,7 +120,7 @@ trait BaseGenSetOps extends GenericNestedCodegen { trait ScalaGenSetOps extends BaseGenSetOps with ScalaGenEffect { val IR: SetOpsExp import IR._ - + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case SetNew(xs, mA) => emitValDef(sym, src"collection.mutable.HashSet[$mA](" + (xs map {quote}).mkString(",") + ")") case SetContains(s,i) => emitValDef(sym, src"$s.contains($i)") @@ -74,31 +129,76 @@ trait ScalaGenSetOps extends BaseGenSetOps with ScalaGenEffect { case SetSize(s) => emitValDef(sym, src"$s.size") case SetClear(s) => emitValDef(sym, src"$s.clear()") case SetToSeq(s) => emitValDef(sym, src"$s.toSeq") - case n@SetToArray(s) => //emitValDef(sym, quote(s) + ".toArray") - gen"""// workaround for refinedManifest problem - |val $sym = { - |val out = $n.array - |val in = $s.toSeq - |var i = 0 - |while (i < in.length) { - |out(i) = in(i) - |i += 1 - |} - |out + case n@SetToArray(s) => emitValDef(sym, quote(s) + ".toArray") + case SetForeach(a,x,block) => + emitValDef(sym, src"$a.foreach{") + gen"""$x => + |${nestedBlock(block)} + |$block + |}""" + case SetMap(a,x,block) => + emitValDef(sym, src"$a.map{") + gen"""$x => + |${nestedBlock(block)} + |$block |}""" + case SetEmpty() => emitValDef(sym, "scala.collection.mutable.HashSet.empty") + case SetHead(s) => emitValDef(sym, src"$s.head") case _ => super.emitNode(sym, rhs) } } trait CLikeGenSetOps extends BaseGenSetOps with CLikeCodegen { val IR: SetOpsExp - import IR._ - -// override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { -// case _ => super.emitNode(sym, rhs) -// } + import IR._ } trait CudaGenSetOps extends CudaGenEffect with CLikeGenSetOps trait OpenCLGenSetOps extends OpenCLGenEffect with CLikeGenSetOps -trait CGenSetOps extends CGenEffect with CLikeGenSetOps + +trait CGenSetOps extends CGenEffect with CNestedCodegen { + val IR: SetOpsExp + import IR._ + + override def remap[A](m: Manifest[A]) = m match { + case s if m <:< manifest[Set[Any]] => "GList**" + case _ => super.remap(m) + } + + override def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = { + if (sym.tp <:< manifest[Variable[Set[Any]]]) + stream.println(remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") + else super.emitVarDef(sym,rhs) + } + + override def emitValDef(sym: Sym[Any], rhs: String): Unit = { + if (sym.tp <:< manifest[Set[Any]]) { + stream.println(remap(sym.tp) + " " + quote(sym) + " = " + getMemoryAllocString("1", "GList*") + ";"); + stream.println("*" + quote(sym) + " = " + rhs + ";") + } + else super.emitValDef(sym,rhs) + } + + override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { + case sh@SetHead(s) => sym.atPhase(LIRLowering) { + val ls = LIRLowering(s) + set_head(ls.asInstanceOf[Exp[Set[Any]]])(remapManifest(fresh(sh.m))(sh.m).asInstanceOf[Manifest[Any]],implicitly[SourceContext]).asInstanceOf[Exp[A]] + } + case _ => super.lowerNode(sym,rhs) + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case SetHead(s) => { + //NOTE: TODO: I do not like this -- find a better way + if (sym.tp == manifest[Int] || sym.tp == manifest[Double]) + emitValDef(sym, src"GPOINTER_TO_INT(g_list_first(*$s)->data)") + else emitValDef(sym, src"g_list_first(*$s)->data;") + } + case SetRemove(s,e) => + //NOTE: TODO: I do not like this -- find a better way + if (e.tp == manifest[Int] || e.tp == manifest[Double]) + stream.println(src"*$s = g_list_remove(*$s,GINT_TO_POINTER($e));") + else stream.println(src"*$s = g_list_remove(*$s,$e);") + case _ => super.emitNode(sym, rhs) + } +} diff --git a/src/common/SimpleDateFormatOps.scala b/src/common/SimpleDateFormatOps.scala new file mode 100644 index 00000000..ca3fb56b --- /dev/null +++ b/src/common/SimpleDateFormatOps.scala @@ -0,0 +1,58 @@ +package scala.virtualization.lms +package common + +import scala.virtualization.lms.common._ +import scala.reflect.SourceContext +import java.util.Date +import java.text.SimpleDateFormat + +/** + * Lifter Classes for SimpleDateFormat + */ +trait SimpleDateFormatOps extends Base { + + class SimpleDateFormatOpsCls(x: Rep[SimpleDateFormat]) { + def format(d: Rep[Date]): Rep[String] = sdfFormat(x, d) + def parse(s: Rep[String]): Rep[Date] = sdfParse(x, s) + } + + implicit def date2SimpleDateFormatOpsCls(x: Rep[SimpleDateFormat]): SimpleDateFormatOpsCls = new SimpleDateFormatOpsCls(x) + def newSimpleDateFormat(format: Rep[String]): Rep[SimpleDateFormat] + def sdfFormat(x: Rep[SimpleDateFormat], d: Rep[Date]): Rep[String] + def sdfParse(x: Rep[SimpleDateFormat], s: Rep[String]): Rep[Date] +} + +trait SimpleDateFormatExp extends SimpleDateFormatOps with BaseExp { + + case class SdfFormat(x: Exp[SimpleDateFormat], d: Exp[Date]) extends Def[String] + case class SdfParse(x: Exp[SimpleDateFormat], s: Exp[String]) extends Def[Date] + case class NewSimpleDateFormat(format: Exp[String]) extends Def[SimpleDateFormat] + + def newSimpleDateFormat(format: Exp[String]): Exp[SimpleDateFormat] = NewSimpleDateFormat(format) + def sdfFormat(x: Exp[SimpleDateFormat], d: Exp[Date]) = SdfFormat(x, d) + def sdfParse(x: Exp[SimpleDateFormat], s: Exp[String]) = SdfParse(x, s) + + ////////////// + // mirroring + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case NewSimpleDateFormat(format) => newSimpleDateFormat(f(format)) + case SdfFormat(x, d) => sdfFormat(f(x), f(d)) + case SdfParse(x, s) => sdfParse(f(x), f(s)) + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] // why?? +} + +trait SimpleDateFormatExpOpt extends SimpleDateFormatExp { +} + +trait ScalaGenSimpleDateFormat extends ScalaGenBase { + val IR: SimpleDateFormatExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case NewSimpleDateFormat(fmt) => emitValDef(sym, "new java.text.SimpleDateFormat(%s)".format(quote(fmt))) + case SdfFormat(x, d) => emitValDef(sym, "%s.format(%s)".format(quote(x),quote(d))); + case SdfParse(x, s) => emitValDef(sym, "%s.parse(%s)".format(quote(x),quote(s))); + case _ => super.emitNode(sym, rhs) + } +} \ No newline at end of file diff --git a/src/common/SimplifyTransform.scala b/src/common/SimplifyTransform.scala index 6d4387ad..18c10b34 100644 --- a/src/common/SimplifyTransform.scala +++ b/src/common/SimplifyTransform.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import scala.reflect.SourceContext @@ -96,86 +96,81 @@ trait SimplifyTransform extends internal.FatScheduling { } // TODO: generalize, abstract out SimpleFatXX types - def transformAll(scope: List[Stm], t: SubstTransformer): List[Stm] = { - val scopeIndex = new java.util.IdentityHashMap[Sym[Any],Stm] - for (stm <- scope; s <- stm.lhs) scopeIndex.put(s,stm) - - scope flatMap { - case TP(sym, rhs) => - transformOne(sym, rhs, t) match { - case s: Sym[Any] => (Option(scopeIndex.get(s)) orElse findDefinition(s)).toList // check scope before target graph - case _ => Nil - } - case TTP(lhs, mhs, SimpleFatIfThenElse(c,as,bs)) => - // alternate strategy: transform thin def, then fatten again (a little detour) - printdbg("need to transform rhs of fat if/then/else: " + lhs + ", if " + c + " then " + as + " else " + bs) - val lhs2 = (lhs zip mhs).map { case (s,r) => transformOne(s, r, t) }.distinct.asInstanceOf[List[Sym[Any]]] - val mhs2 = lhs2.map(s => findDefinition(s).get.defines(s).get) - // TBD: we're mirroring the defs in mhs, creating new stms - // we don't really want new stms: if the defs are just abstract descriptions we only want them updated - - // this means we'll have both a TP and a TTP defining the same sym in globalDefs --> bad! - // not quite so fast, chances are the TTP's never make it into globalDefs (no toAtom call)!!! - - if (lhs != lhs2) { - val missing = Nil//(lhs2.map(s => findDefinition(s).get) diff innerScope) - printdbg("lhs changed! will add to innerScope: "+missing.mkString(",")) - //innerScope = innerScope ::: missing - } + def transformAll(scope: List[Stm], t: SubstTransformer): List[Stm] = scope flatMap { + case TP(sym, rhs) => + transformOne(sym, rhs, t) match { + case s: Sym[Any] => (scope.find(_.lhs contains s) orElse findDefinition(s)).toList // check scope before target graph + case _ => Nil + } + case TTP(lhs, mhs, SimpleFatIfThenElse(c,as,bs)) => + // alternate strategy: transform thin def, then fatten again (a little detour) + printdbg("need to transform rhs of fat if/then/else: " + lhs + ", if " + c + " then " + as + " else " + bs) + val lhs2 = (lhs zip mhs).map { case (s,r) => transformOne(s, r, t) }.distinct.asInstanceOf[List[Sym[Any]]] + val mhs2 = lhs2.map(s => findDefinition(s).get.defines(s).get) + // TBD: we're mirroring the defs in mhs, creating new stms + // we don't really want new stms: if the defs are just abstract descriptions we only want them updated + + // this means we'll have both a TP and a TTP defining the same sym in globalDefs --> bad! + // not quite so fast, chances are the TTP's never make it into globalDefs (no toAtom call)!!! + + if (lhs != lhs2) { + val missing = Nil//(lhs2.map(s => findDefinition(s).get) diff innerScope) + printdbg("lhs changed! will add to innerScope: "+missing.mkString(",")) + //innerScope = innerScope ::: missing + } - def infix_toIf(d: Def[Any]) = d match { - case l: AbstractIfThenElse[_] => l - case Reflect(l: AbstractIfThenElse[_], _, _) => l - } - val cond2 = if (lhs != lhs2) mhs2.map (_.toIf.cond) reduceLeft { (s1,s2) => assert(s1==s2,"conditions don't agree: "+s1+","+s2); s1 } - else t(c) - val as2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toIf.thenp))) - else (lhs zip as)) map { case (s,r) => transformIfBody(s,r,t) } - val bs2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toIf.elsep))) - else (lhs zip bs)) map { case (s,r) => transformIfBody(s,r,t) } + def infix_toIf(d: Def[Any]) = d match { + case l: AbstractIfThenElse[_] => l + case Reflect(l: AbstractIfThenElse[_], _, _) => l + } + val cond2 = if (lhs != lhs2) mhs2.map (_.toIf.cond) reduceLeft { (s1,s2) => assert(s1==s2,"conditions don't agree: "+s1+","+s2); s1 } + else t(c) + val as2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toIf.thenp))) + else (lhs zip as)) map { case (s,r) => transformIfBody(s,r,t) } + val bs2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toIf.elsep))) + else (lhs zip bs)) map { case (s,r) => transformIfBody(s,r,t) } + + printdbg("came up with: " + lhs2 + ", if " + cond2 + " then " + as2 + " else " + bs2 + " with subst " + t.subst.mkString(",")) + List(TTP(lhs2, mhs2, SimpleFatIfThenElse(cond2,as2,bs2))) - printdbg("came up with: " + lhs2 + ", if " + cond2 + " then " + as2 + " else " + bs2 + " with subst " + t.subst.mkString(",")) - List(TTP(lhs2, mhs2, SimpleFatIfThenElse(cond2,as2,bs2))) - - case TTP(lhs, mhs, SimpleFatLoop(s,x,rhs)) => - // alternate strategy: transform thin def, then fatten again (a little detour) - printdbg("need to transform rhs of fat loop: " + lhs + ", " + rhs) - val lhs2 = (lhs zip mhs).map { case (s,r) => transformOne(s, r, t) }.distinct.asInstanceOf[List[Sym[Any]]] - val mhs2 = lhs2.map(s => findDefinition(s).get.defines(s).get) - if (lhs != lhs2) { - val missing = (lhs2.map(s => findDefinition(s).get) diff scope/*innerScope*/) - printdbg("lhs changed! will add to innerScope: "+missing.mkString(",")) - //innerScope = innerScope ::: missing - } - //val shape2 = if (lhs != lhs2) lhs2.map { case Def(SimpleLoop(s,_,_)) => s } reduceLeft { (s1,s2) => assert(s1==s2,"shapes don't agree: "+s1+","+s2); s1 } - def infix_toLoop(d: Def[Any]) = d match { - case l: AbstractLoop[_] => l - case Reflect(l: AbstractLoop[_], _, _) => l - } - val shape2 = if (lhs != lhs2) mhs2.map (_.toLoop.size) reduceLeft { (s1,s2) => assert(s1==s2,"shapes don't agree: "+s1+","+s2); s1 } - else t(s) - val rhs2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toLoop.body))) - else (lhs zip rhs)) map { case (s,r) => transformLoopBody(s,r,t) } - - /* //update innerScope -- change definition of lhs2 in place (necessary?) - innerScope = innerScope map { - case TP(l,_) if lhs2 contains l => TP(l, SimpleLoop(shape2,t(x).asInstanceOf[Sym[Int]],rhs2(lhs2.indexOf(l)))) - case d => d - }*/ - - printdbg("came up with: " + lhs2 + ", " + rhs2 + " with subst " + t.subst.mkString(",")) - List(TTP(lhs2, mhs2, SimpleFatLoop(shape2,t(x).asInstanceOf[Sym[Int]],rhs2))) - // still problem: VectorSum(a,b) = SimpleLoop(i, ReduceElem(f(i))) - // might need to translate f(i), but looking up VectorSum will not be changed at all!!! - // --> change rhs nonetheless??? - - /* - // potential problem here: calling toAtom on a SimpleCollect (which does not have any symbol so far!) - val lhs2 = (lhs zip rhs).map(p=>transformOne(p._1,p._2,t)).map { case s: Sym[Any] => s }.distinct.asInstanceOf[List[Sym[Any]]] - val rhs2 = lhs2 map (findDefinition(_).get.rhs) //FIXME: will lookup old sym (ie VectorTrans) in case of AbstractCollect - List(TTP(lhs2, SimpleFatLoop(t(s),t(x).asInstanceOf[Sym[Int]],rhs2))) - */ - } + case TTP(lhs, mhs, SimpleFatLoop(s,x,rhs)) => + // alternate strategy: transform thin def, then fatten again (a little detour) + printdbg("need to transform rhs of fat loop: " + lhs + ", " + rhs) + val lhs2 = (lhs zip mhs).map { case (s,r) => transformOne(s, r, t) }.distinct.asInstanceOf[List[Sym[Any]]] + val mhs2 = lhs2.map(s => findDefinition(s).get.defines(s).get) + if (lhs != lhs2) { + val missing = (lhs2.map(s => findDefinition(s).get) diff scope/*innerScope*/) + printdbg("lhs changed! will add to innerScope: "+missing.mkString(",")) + //innerScope = innerScope ::: missing + } + //val shape2 = if (lhs != lhs2) lhs2.map { case Def(SimpleLoop(s,_,_)) => s } reduceLeft { (s1,s2) => assert(s1==s2,"shapes don't agree: "+s1+","+s2); s1 } + def infix_toLoop(d: Def[Any]) = d match { + case l: AbstractLoop[_] => l + case Reflect(l: AbstractLoop[_], _, _) => l + } + val shape2 = if (lhs != lhs2) mhs2.map (_.toLoop.size) reduceLeft { (s1,s2) => assert(s1==s2,"shapes don't agree: "+s1+","+s2); s1 } + else t(s) + val rhs2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toLoop.body))) + else (lhs zip rhs)) map { case (s,r) => transformLoopBody(s,r,t) } + +/* //update innerScope -- change definition of lhs2 in place (necessary?) + innerScope = innerScope map { + case TP(l,_) if lhs2 contains l => TP(l, SimpleLoop(shape2,t(x).asInstanceOf[Sym[Int]],rhs2(lhs2.indexOf(l)))) + case d => d + }*/ + + printdbg("came up with: " + lhs2 + ", " + rhs2 + " with subst " + t.subst.mkString(",")) + List(TTP(lhs2, mhs2, SimpleFatLoop(shape2,t(x).asInstanceOf[Sym[Int]],rhs2))) + // still problem: VectorSum(a,b) = SimpleLoop(i, ReduceElem(f(i))) + // might need to translate f(i), but looking up VectorSum will not be changed at all!!! + // --> change rhs nonetheless??? + +/* + // potential problem here: calling toAtom on a SimpleCollect (which does not have any symbol so far!) + val lhs2 = (lhs zip rhs).map(p=>transformOne(p._1,p._2,t)).map { case s: Sym[Any] => s }.distinct.asInstanceOf[List[Sym[Any]]] + val rhs2 = lhs2 map (findDefinition(_).get.rhs) //FIXME: will lookup old sym (ie VectorTrans) in case of AbstractCollect + List(TTP(lhs2, SimpleFatLoop(t(s),t(x).asInstanceOf[Sym[Int]],rhs2))) +*/ } def transformAllFully(currentScope0: List[Stm], result0: List[Exp[Any]], t: SubstTransformer): (List[Stm], List[Exp[Any]]) = { diff --git a/src/common/SplitEffects.scala b/src/common/SplitEffects.scala index 162cabfe..55de8bb2 100644 --- a/src/common/SplitEffects.scala +++ b/src/common/SplitEffects.scala @@ -1,9 +1,9 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.lms.internal.{GenericNestedCodegen, GenericFatCodegen, GenerationFailedException} +import scala.virtualization.lms.internal.{GenericNestedCodegen, GenericFatCodegen, GenerationFailedException} trait SplitEffectsExpFat extends IfThenElseFatExp with WhileExp with PreviousIterationDummyExp { this: BooleanOpsExp with EqualExpBridge => @@ -17,9 +17,6 @@ trait SplitEffectsExpFat extends IfThenElseFatExp with WhileExp with PreviousIte // TODO: SimpleLoops - // FIXME: wo do not account for mutable objectes allocated in a loop - // (see test8-speculative6) - override def reflectEffectInternal[A:Manifest](x: Def[A], u: Summary)(implicit pos: SourceContext): Exp[A] = x match { case IfThenElse(cond, thenp, elsep) => val affected = (u.mayRead ++ u.mayWrite).distinct diff --git a/src/common/StaticData.scala b/src/common/StaticData.scala index a622c633..819cceb7 100644 --- a/src/common/StaticData.scala +++ b/src/common/StaticData.scala @@ -1,8 +1,8 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal.GenericNestedCodegen +import scala.virtualization.lms.internal.GenericNestedCodegen import scala.reflect.SourceContext trait StaticData extends Base { @@ -13,24 +13,13 @@ trait StaticDataExp extends EffectExp { case class StaticData[T](x: T) extends Def[T] def staticData[T:Manifest](x: T): Exp[T] = StaticData(x) - // StaticData doesn't play well with control dependencies.. looks like we somehow lose updates - override implicit def toAtom[T:Manifest](d: Def[T])(implicit pos: SourceContext) = d match { - case StaticData(x) if addControlDeps => - val save = conditionalScope - conditionalScope = false - val z = super.toAtom(d) - conditionalScope = save - z - case _ => super.toAtom(d) - } - override def isWritableSym[A](w: Sym[A]): Boolean = findDefinition(w) match { case Some(TP(_, StaticData(_))) => true case _ => super.isWritableSym(w) } override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case StaticData(x) => staticData(x)(mtype(manifest[A])) + case StaticData(x) => staticData(x)(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] } @@ -66,21 +55,12 @@ trait BaseGenStaticData extends GenericNestedCodegen { trait ScalaGenStaticData extends ScalaGenEffect with BaseGenStaticData { val IR: StaticDataExp import IR._ - + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case StaticData(x) => + case StaticData(x) => emitValDef(sym, "p"+quote(sym) + " // static data: " + (x match { case x: Array[_] => "Array("+x.mkString(",")+")" case _ => x })) case _ => super.emitNode(sym, rhs) } + } -trait CGenStaticData extends CGenEffect with BaseGenStaticData { - val IR: StaticDataExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case StaticData(x) => - emitValDef(sym, /*"p"+quote(sym)*/ (x match { case x: Array[_] => "("+remap(sym.tp.typeArguments(0))+"[]){"+x.map(v=>quote(Const[Any](v))).mkString(",")+"}" case _ => quote(Const(x)) })) - case _ => super.emitNode(sym, rhs) - } -} diff --git a/src/common/StringOps.scala b/src/common/StringOps.scala index c80911f9..5d3acffc 100644 --- a/src/common/StringOps.scala +++ b/src/common/StringOps.scala @@ -1,9 +1,9 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.util.OverloadHack -import scala.lms.internal.{GenerationFailedException} +import scala.virtualization.lms.util.OverloadHack +import scala.virtualization.lms.internal.{GenerationFailedException,CNestedCodegen} import scala.reflect.SourceContext trait LiftString { @@ -15,114 +15,137 @@ trait LiftString { trait StringOps extends Variables with OverloadHack { // NOTE: if something doesn't get lifted, this won't give you a compile time error, // since string concat is defined on all objects - + def infix_+(s1: String, s2: Rep[Any])(implicit o: Overloaded1, pos: SourceContext) = string_plus(unit(s1), s2) def infix_+[T:Manifest](s1: String, s2: Var[T])(implicit o: Overloaded2, pos: SourceContext) = string_plus(unit(s1), readVar(s2)) - def infix_+(s1: Rep[String], s2: Rep[Any])(implicit o: Overloaded1, pos: SourceContext) = string_plus(s1, s2) - def infix_+[T:Manifest](s1: Rep[String], s2: Var[T])(implicit o: Overloaded2, pos: SourceContext) = string_plus(s1, readVar(s2)) + def infix_+[T:Manifest](s1: Rep[String], s2: Rep[T])(implicit o: Overloaded1, pos: SourceContext): Rep[String] = { + if (manifest[T] == classManifest[Array[Byte]]) + string_plus(s1, string_new(s2)) + else string_plus(s1, s2) + } + def infix_+[T:Manifest](s1: Rep[String], s2: Var[T])(implicit o: Overloaded2, pos: SourceContext): Rep[String] = string_plus(s1, readVar(s2)) def infix_+(s1: Rep[String], s2: Rep[String])(implicit o: Overloaded3, pos: SourceContext) = string_plus(s1, s2) def infix_+(s1: Rep[String], s2: Var[String])(implicit o: Overloaded4, pos: SourceContext) = string_plus(s1, readVar(s2)) def infix_+(s1: Rep[Any], s2: Rep[String])(implicit o: Overloaded5, pos: SourceContext) = string_plus(s1, s2) def infix_+(s1: Rep[Any], s2: Var[String])(implicit o: Overloaded6, pos: SourceContext) = string_plus(s1, readVar(s2)) def infix_+(s1: Rep[Any], s2: String)(implicit o: Overloaded7, pos: SourceContext) = string_plus(s1, unit(s2)) - - def infix_+(s1: Var[String], s2: Rep[Any])(implicit o: Overloaded8, pos: SourceContext) = string_plus(readVar(s1), s2) + + def infix_+(s1: Var[String], s2: Rep[Any])(implicit o: Overloaded8, pos: SourceContext) = string_plus(readVar(s1), s2) def infix_+[T:Manifest](s1: Var[String], s2: Var[T])(implicit o: Overloaded9, pos: SourceContext) = string_plus(readVar(s1), readVar(s2)) - def infix_+(s1: Var[String], s2: Rep[String])(implicit o: Overloaded10, pos: SourceContext) = string_plus(readVar(s1), s2) - def infix_+(s1: Var[String], s2: Var[String])(implicit o: Overloaded11, pos: SourceContext) = string_plus(readVar(s1), readVar(s2)) + def infix_+(s1: Var[String], s2: Rep[String])(implicit o: Overloaded10, pos: SourceContext) = string_plus(readVar(s1), s2) + def infix_+(s1: Var[String], s2: Var[String])(implicit o: Overloaded11, pos: SourceContext) = string_plus(readVar(s1), readVar(s2)) def infix_+[T:Manifest](s1: Var[T], s2: Rep[String])(implicit o: Overloaded12, pos: SourceContext) = string_plus(readVar(s1), s2) def infix_+[T:Manifest](s1: Var[T], s2: Var[String])(implicit o: Overloaded13, pos: SourceContext) = string_plus(readVar(s1), readVar(s2)) def infix_+[T:Manifest](s1: Var[T], s2: String)(implicit o: Overloaded14, pos: SourceContext) = string_plus(readVar(s1), unit(s2)) - + def infix_getBytes(s1: Rep[String])(implicit pos: SourceContext) = string_getBytes(s1) + // these are necessary to be more specific than arithmetic/numeric +. is there a more generic form of this that will work? - //def infix_+[R:Manifest](s1: Rep[String], s2: R)(implicit c: R => Rep[Any], o: Overloaded15, pos: SourceContext) = string_plus(s1, c(s2)) + //def infix_+[R:Manifest](s1: Rep[String], s2: R)(implicit c: R => Rep[Any], o: Overloaded15, pos: SourceContext) = string_plus(s1, c(s2)) def infix_+(s1: Rep[String], s2: Double)(implicit o: Overloaded15, pos: SourceContext) = string_plus(s1, unit(s2)) def infix_+(s1: Rep[String], s2: Float)(implicit o: Overloaded16, pos: SourceContext) = string_plus(s1, unit(s2)) def infix_+(s1: Rep[String], s2: Int)(implicit o: Overloaded17, pos: SourceContext) = string_plus(s1, unit(s2)) def infix_+(s1: Rep[String], s2: Long)(implicit o: Overloaded18, pos: SourceContext) = string_plus(s1, unit(s2)) - def infix_+(s1: Rep[String], s2: Short)(implicit o: Overloaded19, pos: SourceContext) = string_plus(s1, unit(s2)) - + def infix_+(s1: Rep[String], s2: Short)(implicit o: Overloaded19, pos: SourceContext) = string_plus(s1, unit(s2)) + def infix_startsWith(s1: Rep[String], s2: Rep[String])(implicit pos: SourceContext) = string_startswith(s1,s2) + def infix_endsWith(s1: Rep[String], s2: Rep[String])(implicit pos: SourceContext) = string_endswith(s1,s2) + def infix_replaceAll(s1: Rep[String], d1: Rep[String], d2: Rep[String])(implicit pos: SourceContext) = string_replaceAll(s1,d1,d2) def infix_trim(s: Rep[String])(implicit pos: SourceContext) = string_trim(s) - def infix_split(s: Rep[String], separators: Rep[String])(implicit pos: SourceContext) = string_split(s, separators, unit(0)) - def infix_split(s: Rep[String], separators: Rep[String], limit: Rep[Int])(implicit pos: SourceContext) = string_split(s, separators, limit) - def infix_charAt(s: Rep[String], i: Rep[Int])(implicit pos: SourceContext) = string_charAt(s,i) - def infix_endsWith(s: Rep[String], e: Rep[String])(implicit pos: SourceContext) = string_endsWith(s,e) - def infix_contains(s1: Rep[String], s2: Rep[String])(implicit pos: SourceContext) = string_contains(s1,s2) + def infix_length(s: Rep[String])(implicit pos: SourceContext) = string_length(s) + def infix_split(s: Rep[String], separators: Rep[String])(implicit pos: SourceContext) = string_split(s, separators) def infix_toDouble(s: Rep[String])(implicit pos: SourceContext) = string_todouble(s) def infix_toFloat(s: Rep[String])(implicit pos: SourceContext) = string_tofloat(s) def infix_toInt(s: Rep[String])(implicit pos: SourceContext) = string_toint(s) def infix_toLong(s: Rep[String])(implicit pos: SourceContext) = string_tolong(s) - def infix_substring(s: Rep[String], start: Rep[Int], end: Rep[Int])(implicit pos: SourceContext) = string_substring(s,start,end) - - // FIXME: enabling this causes trouble with DeliteOpSuite. investigate!! - //def infix_length(s: Rep[String])(implicit pos: SourceContext) = string_length(s) + def infix_substring(s: Rep[String], beginIndex: Rep[Int])(implicit pos: SourceContext) = string_substring(s, beginIndex) + def infix_substring(s: Rep[String], beginIndex: Rep[Int], endIndex: Rep[Int])(implicit pos: SourceContext) = string_substring(s, beginIndex, endIndex) object String { def valueOf(a: Rep[Any])(implicit pos: SourceContext) = string_valueof(a) } + def string_new(s: Rep[Any]): Rep[String] def string_plus(s: Rep[Any], o: Rep[Any])(implicit pos: SourceContext): Rep[String] def string_startswith(s1: Rep[String], s2: Rep[String])(implicit pos: SourceContext): Rep[Boolean] + def string_endswith(s1: Rep[String], s2: Rep[String])(implicit pos: SourceContext): Rep[Boolean] + def string_replaceAll(s1: Rep[String], d1: Rep[String], d2: Rep[String])(implicit pos: SourceContext): Rep[String] def string_trim(s: Rep[String])(implicit pos: SourceContext): Rep[String] - def string_split(s: Rep[String], separators: Rep[String], limit: Rep[Int])(implicit pos: SourceContext): Rep[Array[String]] + def string_length(s: Rep[String])(implicit pos: SourceContext): Rep[Int] + def string_split(s: Rep[String], separators: Rep[String])(implicit pos: SourceContext): Rep[Array[String]] def string_valueof(d: Rep[Any])(implicit pos: SourceContext): Rep[String] - def string_charAt(s: Rep[String], i: Rep[Int])(implicit pos: SourceContext): Rep[Char] - def string_endsWith(s: Rep[String], e: Rep[String])(implicit pos: SourceContext): Rep[Boolean] - def string_contains(s1: Rep[String], s2: Rep[String])(implicit pos: SourceContext): Rep[Boolean] def string_todouble(s: Rep[String])(implicit pos: SourceContext): Rep[Double] def string_tofloat(s: Rep[String])(implicit pos: SourceContext): Rep[Float] def string_toint(s: Rep[String])(implicit pos: SourceContext): Rep[Int] def string_tolong(s: Rep[String])(implicit pos: SourceContext): Rep[Long] - def string_substring(s: Rep[String], start:Rep[Int], end:Rep[Int])(implicit pos: SourceContext): Rep[String] - def string_length(s: Rep[String])(implicit pos: SourceContext): Rep[Int] + def string_substring(s: Rep[String], beginIndex: Rep[Int])(implicit pos: SourceContext): Rep[String] + def string_substring(s: Rep[String], beginIndex: Rep[Int], endIndex: Rep[Int])(implicit pos: SourceContext): Rep[String] + def string_getBytes(s1: Rep[String])(implicit pos: SourceContext): Rep[Array[Byte]] + def string_containsSlice(s1: Rep[String],s2:Rep[String])(implicit pos: SourceContext): Rep[Boolean] + def string_compareTo(s1: Rep[String],s2:Rep[String])(implicit pos: SourceContext): Rep[Int] + def string_indexOfSlice(s1: Rep[String],s2:Rep[String],idx:Rep[Int])(implicit pos: SourceContext): Rep[Int] } -trait StringOpsExp extends StringOps with VariablesExp { +trait StringOpsExp extends StringOps with VariablesExp with Structs { + case class StringNew(s: Rep[Any]) extends Def[String] case class StringPlus(s: Exp[Any], o: Exp[Any]) extends Def[String] case class StringStartsWith(s1: Exp[String], s2: Exp[String]) extends Def[Boolean] + case class StringEndsWith(s1: Exp[String], s2: Exp[String]) extends Def[Boolean] { + val lensuf = fresh[Int] + val lenstr = fresh[Int] + } + case class StringReplaceAll(s1: Exp[String], d1: Exp[String], d2: Exp[String]) extends Def[String] case class StringTrim(s: Exp[String]) extends Def[String] - case class StringSplit(s: Exp[String], separators: Exp[String], limit: Exp[Int]) extends Def[Array[String]] - case class StringEndsWith(s: Exp[String], e: Exp[String]) extends Def[Boolean] - case class StringCharAt(s: Exp[String], i: Exp[Int]) extends Def[Char] + case class StringLength(s: Exp[String]) extends Def[Int] + case class StringSplit(s: Exp[String], separators: Exp[String]) extends Def[Array[String]] case class StringValueOf(a: Exp[Any]) extends Def[String] case class StringToDouble(s: Exp[String]) extends Def[Double] case class StringToFloat(s: Exp[String]) extends Def[Float] case class StringToInt(s: Exp[String]) extends Def[Int] - case class StringContains(s1: Exp[String], s2: Exp[String]) extends Def[Boolean] case class StringToLong(s: Exp[String]) extends Def[Long] - case class StringSubstring(s: Exp[String], start:Exp[Int], end:Exp[Int]) extends Def[String] - case class StringLength(s: Exp[String]) extends Def[Int] + case class StringSubstring(s: Exp[String], beginIndex: Exp[Int]) extends Def[String] + case class StringGetBytes(s: Exp[String]) extends Def[Array[Byte]] + case class StringSubstringWithEndIndex(s: Exp[String], beginIndex: Exp[Int], endIndex: Exp[Int]) extends Def[String] + case class StringContainsSlice(s1: Exp[String], s2: Exp[String]) extends Def[Boolean] + case class StringCompareTo(s1: Exp[String], s2: Exp[String]) extends Def[Int] + case class StringIndexOfSlice(s1: Exp[String], s2: Exp[String], idx: Exp[Int]) extends Def[Int] + def string_new(s: Rep[Any]) = StringNew(s) def string_plus(s: Exp[Any], o: Exp[Any])(implicit pos: SourceContext): Rep[String] = StringPlus(s,o) def string_startswith(s1: Exp[String], s2: Exp[String])(implicit pos: SourceContext) = StringStartsWith(s1,s2) + def string_endswith(s1: Exp[String], s2: Exp[String])(implicit pos: SourceContext) = StringEndsWith(s1,s2) + def string_replaceAll(s1: Exp[String], d1: Exp[String], d2: Exp[String])(implicit pos: SourceContext) = StringReplaceAll(s1,d1,d2) def string_trim(s: Exp[String])(implicit pos: SourceContext) : Rep[String] = StringTrim(s) - def string_split(s: Exp[String], separators: Exp[String], limit: Exp[Int])(implicit pos: SourceContext) : Rep[Array[String]] = StringSplit(s, separators, limit) + def string_length(s: Exp[String])(implicit pos: SourceContext) : Rep[Int] = StringLength(s) + def string_split(s: Exp[String], separators: Exp[String])(implicit pos: SourceContext) : Rep[Array[String]] = StringSplit(s, separators) def string_valueof(a: Exp[Any])(implicit pos: SourceContext) = StringValueOf(a) - def string_charAt(s: Exp[String], i: Exp[Int])(implicit pos: SourceContext) = StringCharAt(s,i) - def string_endsWith(s: Exp[String], e: Exp[String])(implicit pos: SourceContext) = StringEndsWith(s,e) - def string_contains(s1: Exp[String], s2: Exp[String])(implicit pos: SourceContext) = StringContains(s1,s2) - def string_todouble(s: Rep[String])(implicit pos: SourceContext) = StringToDouble(s) - def string_tofloat(s: Rep[String])(implicit pos: SourceContext) = StringToFloat(s) - def string_toint(s: Rep[String])(implicit pos: SourceContext) = StringToInt(s) - def string_tolong(s: Rep[String])(implicit pos: SourceContext) = StringToLong(s) - def string_substring(s: Rep[String], start:Rep[Int], end:Rep[Int])(implicit pos: SourceContext) = StringSubstring(s,start,end) - def string_length(s: Rep[String])(implicit pos: SourceContext) = StringLength(s) + def string_todouble(s: Exp[String])(implicit pos: SourceContext) = StringToDouble(s) + def string_tofloat(s: Exp[String])(implicit pos: SourceContext) = StringToFloat(s) + def string_toint(s: Exp[String])(implicit pos: SourceContext) = StringToInt(s) + def string_tolong(s: Exp[String])(implicit pos: SourceContext) = StringToLong(s) + def string_substring(s: Exp[String], beginIndex: Exp[Int])(implicit pos: SourceContext) = StringSubstring(s, beginIndex) + def string_substring(s: Exp[String], beginIndex: Exp[Int], endIndex: Exp[Int])(implicit pos: SourceContext) = StringSubstringWithEndIndex(s, beginIndex, endIndex) + def string_getBytes(s1: Rep[String])(implicit pos: SourceContext) = StringGetBytes(s1) + def string_containsSlice(s1: Rep[String], s2:Rep[String])(implicit pos: SourceContext) = StringContainsSlice(s1,s2) + def string_compareTo(s1: Rep[String],s2:Rep[String])(implicit pos: SourceContext) = StringCompareTo(s1,s2) + def string_indexOfSlice(s1: Rep[String], s2:Rep[String], idx: Rep[Int])(implicit pos: SourceContext) = StringIndexOfSlice(s1,s2,idx) override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case StringNew(a) => string_new(f(a)) case StringPlus(a,b) => string_plus(f(a),f(b)) - case StringStartsWith(s1, s2) => string_startswith(f(s1), f(s2)) case StringTrim(s) => string_trim(f(s)) - case StringSplit(s,sep,l) => string_split(f(s),f(sep),f(l)) + case StringStartsWith(s1,s2) => string_startswith(f(s1),f(s2)) + case StringEndsWith(s1,s2) => string_endswith(f(s1),f(s2)) + case StringReplaceAll(s1,d1,d2) => string_replaceAll(f(s1),f(d1),f(d2)) + case StringSplit(s,sep) => string_split(f(s),f(sep)) case StringToDouble(s) => string_todouble(f(s)) case StringToFloat(s) => string_tofloat(f(s)) case StringToInt(s) => string_toint(f(s)) - case StringEndsWith(s, e) => string_endsWith(f(s),f(e)) - case StringCharAt(s,i) => string_charAt(f(s),f(i)) - case StringValueOf(a) => string_valueof(f(a)) - case StringContains(s1,s2) => string_contains(f(s1),f(s2)) - case StringSubstring(s,a,b) => string_substring(f(s),f(a),f(b)) - case StringLength(s) => string_length(f(s)) + case StringToLong(s) => string_tolong(f(s)) + case StringSubstring(s, beginIndex) => string_substring(f(s), f(beginIndex)) + case StringSubstringWithEndIndex(s, beginIndex, endIndex) => string_substring(f(s), f(beginIndex), f(endIndex)) + case StringContainsSlice(s1,s2) => string_containsSlice(f(s1), f(s2)) + case StringCompareTo(s1,s2) => string_compareTo(f(s1),f(s2)) + case StringIndexOfSlice(s1,s2,idx) => string_indexOfSlice(f(s1),f(s2),f(idx)) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] } @@ -130,22 +153,23 @@ trait StringOpsExp extends StringOps with VariablesExp { trait ScalaGenStringOps extends ScalaGenBase { val IR: StringOpsExp import IR._ - + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case StringNew(s1) => emitValDef(sym, src"new String($s1)") case StringPlus(s1,s2) => emitValDef(sym, src"$s1+$s2") case StringStartsWith(s1,s2) => emitValDef(sym, src"$s1.startsWith($s2)") + case StringEndsWith(s1,s2) => emitValDef(sym, src"$s1.endsWith($s2)") + case StringReplaceAll(s1,d1,d2) => emitValDef(sym, src"$s1.replaceAll($d1,$d2)") case StringTrim(s) => emitValDef(sym, src"$s.trim()") - case StringSplit(s, sep, l) => emitValDef(sym, src"$s.split($sep,$l)") - case StringEndsWith(s, e) => emitValDef(sym, "%s.endsWith(%s)".format(quote(s), quote(e))) - case StringCharAt(s,i) => emitValDef(sym, "%s.charAt(%s)".format(quote(s), quote(i))) + case StringSplit(s, sep) => emitValDef(sym, src"$s.split($sep)") case StringValueOf(a) => emitValDef(sym, src"java.lang.String.valueOf($a)") case StringToDouble(s) => emitValDef(sym, src"$s.toDouble") case StringToFloat(s) => emitValDef(sym, src"$s.toFloat") case StringToInt(s) => emitValDef(sym, src"$s.toInt") case StringToLong(s) => emitValDef(sym, src"$s.toLong") - case StringContains(s1,s2) => emitValDef(sym, "%s.contains(%s)".format(quote(s1),quote(s2))) - case StringSubstring(s,a,b) => emitValDef(sym, src"$s.substring($a,$b)") - case StringLength(s) => emitValDef(sym, src"$s.length") + case StringGetBytes(s) => emitValDef(sym, src"$s.getBytes") + case StringSubstring(s, beginIndex) => emitValDef(sym, src"$s.substring($beginIndex)") + case StringSubstringWithEndIndex(s, beginIndex, endIndex) => emitValDef(sym, src"$s.substring($beginIndex, $endIndex)") case _ => super.emitNode(sym, rhs) } } @@ -153,44 +177,62 @@ trait ScalaGenStringOps extends ScalaGenBase { trait CudaGenStringOps extends CudaGenBase { val IR: StringOpsExp import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case StringPlus(s1,s2) => throw new GenerationFailedException("CudaGen: Not GPUable") + case StringTrim(s) => throw new GenerationFailedException("CudaGen: Not GPUable") + case StringSplit(s, sep) => throw new GenerationFailedException("CudaGen: Not GPUable") + case _ => super.emitNode(sym, rhs) + } } trait OpenCLGenStringOps extends OpenCLGenBase { val IR: StringOpsExp import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case StringPlus(s1,s2) => throw new GenerationFailedException("OpenCLGen: Not GPUable") + case StringTrim(s) => throw new GenerationFailedException("OpenCLGen: Not GPUable") + case StringSplit(s, sep) => throw new GenerationFailedException("OpenCLGen: Not GPUable") + case _ => super.emitNode(sym, rhs) + } } -trait CGenStringOps extends CGenBase { +trait CGenStringOps extends CGenBase with CNestedCodegen { val IR: StringOpsExp import IR._ + override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { + case StringNew(s) => sym.atPhase(LIRLowering) { + // TODO: Find a better way than this. It assumes that the argument is an array of byte and it also assumes its implicit lowering + val ar = field[Array[Byte]](LIRLowering(s), "array") + ar.asInstanceOf[Exp[A]] + } + case _ => super.lowerNode(sym,rhs) + } + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case StringPlus(s1,s2) if remap(s1.tp) == "string" && remap(s2.tp) == "string" => emitValDef(sym,"string_plus(%s,%s)".format(quote(s1),quote(s2))) - case StringStartsWith(s1,s2) => emitValDef(sym, "string_startsWith(%s,%s)".format(quote(s1),quote(s2))) - case StringTrim(s) => emitValDef(sym, "string_trim(%s)".format(quote(s))) - case StringSplit(s, sep, Const(0)) => emitValDef(sym, "string_split(%s,%s)".format(quote(s),quote(sep))) - //case StringEndsWith(s, e) => emitValDef(sym, "(strlen(%s)>=strlen(%s)) && strncmp(%s+strlen(%s)-strlen(%s),%s,strlen(%s))".format(quote(s),quote(e),quote(s),quote(e),quote(s),quote(e),quote(e))) - case StringCharAt(s,i) => emitValDef(sym, "string_charAt(%s,%s)".format(quote(s), quote(i))) - //case StringValueOf(a) => - case StringToDouble(s) => emitValDef(sym, "string_toDouble(%s)".format(quote(s))) - case StringToFloat(s) => emitValDef(sym, "string_toFloat(%s)".format(quote(s))) - case StringToInt(s) => emitValDef(sym, "string_toInt(%s)".format(quote(s))) -/* - case StringSubstring(s,a,b) => emitValDef(sym, src"({ int l=$b-$a; char* r=(char*)malloc(l); memcpy(r,((char*)$s)+$a,l); r[l]=0; r; })") - case StringPlus(s1,s2) => s2.tp.toString match { - // Warning: memory leaks. We need a global mechanism like reference counting, possibly release pool(*) wrapping functions. - // (*) See https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html - case "java.lang.String" => emitValDef(sym,src"({ int l1=strlen($s1),l2=strlen($s2); char* r=(char*)malloc(l1+l2+1); memcpy(r,$s1,l1); memcpy(r+l1,$s2,l2); r[l1+l2]=0; r; })") - case "Char" => emitValDef(sym,src"({ int l1=strlen($s1); char* r=(char*)malloc(l1+2); memcpy(r,$s1,l1); r[l1]=$s2; r[l1+2]=0; r; })") + case StringNew(s1) => emitValDef(sym, src"$s1") + case StringLength(s1) => emitValDef(sym, src"tpch_strlen($s1)") + case StringPlus(s1,s2) => emitValDef(sym,src"strcat($s1,$s2);") + case StringStartsWith(s1,s2) => emitValDef(sym, "strncmp(" + quote(s1) + "," + quote(s2) + ", tpch_strlen(" + quote(s2) + ")) == 0;") + case sew@StringEndsWith(s1,s2) => { + emitValDef(sew.lenstr,"tpch_strlen("+quote(s1)+")") + emitValDef(sew.lensuf,"tpch_strlen("+quote(s2)+")") + emitValDef(sym, "strncmp(" + quote(s1) + "+" + quote(sew.lenstr) + "-" + quote(sew.lensuf) + "," + quote(s2) + ", " + quote(sew.lensuf) + ") == 0;") } - case StringToInt(s) => emitValDef(sym,src"atoi($s)") - case StringToLong(s) => emitValDef(sym,src"atol($s)") - case StringToFloat(s) => emitValDef(sym,src"atof($s)") - case StringToDouble(s) => emitValDef(sym,src"atof($s)") - case StringLength(s) => emitValDef(sym, src"strlen($s)") + case StringContainsSlice(s1,s2) => + emitValDef(sym, "tpch_strstr(" + quote(s1) + "," + quote(s2) + ") >= " + quote(s1)) + case StringCompareTo(s1,s2) => + emitValDef(sym, "tpch_strcmp(" + quote(s1) + "," + quote(s2) + ")") + case StringIndexOfSlice(s1,s2,idx) => + emitValDef(sym, "tpch_strstr(&(" + quote(s1) + "[" + quote(idx) + "])," + quote(s2) + ") - " + quote(s1)) + stream.println("if (" + quote(sym) + " < 0) " + quote(sym) + " = -1;") + case StringSubstringWithEndIndex(s, beginIndex, endIndex) => + emitValDef(sym, src"malloc($endIndex - $beginIndex + 1); memcpy(" + quote(sym) + "," + quote(s) + src", $endIndex - $beginIndex);" ) + //stream.println(src"char " + quote(sym) + src"[$endIndex - $beginIndex + 1]; memcpy(" + quote(sym) + "," + quote(s) + src", $endIndex - $beginIndex);") case StringTrim(s) => throw new GenerationFailedException("CGenStringOps: StringTrim not implemented yet") case StringSplit(s, sep) => throw new GenerationFailedException("CGenStringOps: StringSplit not implemented yet") -*/ case _ => super.emitNode(sym, rhs) } } diff --git a/src/common/Structs.scala b/src/common/Structs.scala index 6e23349a..16d38f69 100644 --- a/src/common/Structs.scala +++ b/src/common/Structs.scala @@ -1,29 +1,53 @@ -package scala.lms +package scala.virtualization.lms package common -import reflect.{SourceContext, RefinedManifest} -import util.OverloadHack -import java.io.PrintWriter -import internal.{GenericNestedCodegen, GenericFatCodegen} +import scala.virtualization.lms.common._ -abstract class Record extends Struct +import scala.virtualization.lms.util.OverloadHack +import scala.virtualization.lms.internal.{GenericNestedCodegen, GenericFatCodegen} +import scala.reflect.{SourceContext, RefinedManifest} +import java.io.{StringWriter,PrintWriter} +import scala.language.dynamics -trait StructOps extends Base { +/** + * Taken char-for-char from the delite-develop branch of lms + */ + +trait Structs extends Base with Variables { /** * Allows to write things like “val z = new Record { val re = 1.0; val im = -1.0 }; print(z.re)” */ - + abstract class Record extends Struct + abstract class CompositeRecord[T1:Manifest,T2:Manifest] extends Record def __new[T : Manifest](args: (String, Boolean, Rep[T] => Rep[_])*): Rep[T] = record_new(args) - class RecordOps(record: Rep[Record]) { - def selectDynamic[T : Manifest](field: String): Rep[T] = record_select[T](record, field) + class RecordOps[T1<:Record:Manifest](record: Rep[T1]) extends Dynamic { + def apply[TF: Manifest](field: String): Rep[TF] = record_select[T1,TF](record, field) + def selectDynamic[TF : Manifest](field: String): Rep[TF] = record_select[T1,TF](record, field) + def concatenate[T2: Manifest](record2: Rep[T2], leftAlias: String = "", rightAlias: String = ""): Rep[CompositeRecord[T1,T2]] = record_concatenate[T1,T2](record, record2, leftAlias, rightAlias) + def print = record_print[T1](record) + } + implicit def recordToRecordOps[T<:Record:Manifest](record: Rep[T]) = new RecordOps[T](record) + implicit def varrecordToRecordOps[T<:Record:Manifest](record: Var[T]) = new RecordOps[T](readVar(record)) + def infix_f[T<:Record:Manifest](record: Rep[T]) = new RecordOps(record)(manifest[T]) + + def registerStruct[T<:Record:Manifest](name: String, elems: Seq[(String, Manifest[_])]) + def structName[T](m: Manifest[T]): String + + object DefaultRecord { + def apply[T:Manifest]() = default_record[T]() } - implicit def recordToRecordOps(record: Rep[Record]) = new RecordOps(record) + def default_record[T: Manifest](): Rep[T] def record_new[T : Manifest](fields: Seq[(String, Boolean, Rep[T] => Rep[_])]): Rep[T] - def record_select[T : Manifest](record: Rep[Record], field: String): Rep[T] + def record_new[T:Manifest](structName: String, fieldSyms: Seq[(String, Rep[Any])]): Rep[T] + def record_select[T1:Manifest, TF:Manifest](record: Rep[T1], field: String): Rep[TF] + def record_concatenate[T1:Manifest, T2:Manifest](record: Rep[T1], record2: Rep[T2], leftAlias: String = "", rightAlias: String = ""): Rep[CompositeRecord[T1,T2]] + def record_print[T<:Record:Manifest](record: Rep[T]): Rep[Unit] def field[T:Manifest](struct: Rep[Any], index: String)(implicit pos: SourceContext): Rep[T] + def record_hash[T:Manifest](record: Rep[T]): Rep[Int] + def record_equals[T:Manifest](record1: Rep[T], record2: Rep[T]): Rep[Boolean] } trait StructTags { @@ -34,7 +58,7 @@ trait StructTags { case class MapTag[T]() extends StructTag[T] } -trait StructExp extends StructOps with StructTags with BaseExp with EffectExp with VariablesExp with ObjectOpsExp with StringOpsExp with OverloadHack { +trait StructExp extends Structs with StructTags with EffectExp with WhileExp with VariablesExp with ObjectOpsExp with StringOpsExp with FunctionsExp with MiscOpsExp with RangeOpsExp with ArrayOps with BooleanOps with Equal with PrimitiveOps with NumericOps with OrderingOps { // TODO: structs should take Def parameters that define how to generate constructor and accessor calls @@ -49,11 +73,11 @@ trait StructExp extends StructOps with StructTags with BaseExp with EffectExp wi } /* override def fresh[T:Manifest] = manifest[T] match { - case s if s <:< manifest[Record] => - val m = spawnRefinedManifest - super.fresh(m) - case _ => super.fresh - } */ //TODO: best way to ensure full structural type is always available? +case s if s <:< manifest[Record] => +val m = spawnRefinedManifest +super.fresh(m) +case _ => super.fresh +} */ //TODO: best way to ensure full structural type is always available? object Struct { def unapply[T](d: Def[T]) = unapplyStruct(d) @@ -73,8 +97,22 @@ trait StructExp extends StructOps with StructTags with BaseExp with EffectExp wi case _ => None } - case class SimpleStruct[T](tag: StructTag[T], elems: Seq[(String, Rep[Any])]) extends AbstractStruct[T] - case class FieldApply[T](struct: Rep[Any], index: String) extends AbstractField[T] + case class DefaultRecordDef[T:Manifest]() extends Def[T] { + val m = manifest[T] + } + case class SimpleStruct[T:Manifest](tag: StructTag[T], elems: Seq[(String, Rep[Any])]) extends AbstractStruct[T] { + if (tag.isInstanceOf[ClassTag[_]]) registerStruct(tag.asInstanceOf[ClassTag[_]].name, elems.map(e => (e._1, e._2.tp))) + } + case class ConcatenateRecords[T1:Manifest, T2:Manifest](x: Rep[T1], y: Rep[T2], leftAlias: String, rightAlias: String) extends Def[CompositeRecord[T1,T2]] { + val m1 = manifest[T1] + val m2 = manifest[T2] + } + case class RecordPrint[T<:Record:Manifest](rec: Rep[T]) extends Def[Unit] + case class RecordHash[T:Manifest](rec: Rep[T]) extends Def[Int] + case class RecordEquals[T:Manifest](rec1: Rep[T], rec2: Rep[T]) extends Def[Boolean] + case class FieldApply[T:Manifest](struct: Rep[Any], index: String) extends AbstractField[T] { + val m = manifest[T] + } case class FieldUpdate[T:Manifest](struct: Exp[Any], index: String, rhs: Exp[T]) extends Def[Unit] def struct[T:Manifest](tag: StructTag[T], elems: (String, Rep[Any])*)(implicit o: Overloaded1, pos: SourceContext): Rep[T] = struct[T](tag, elems) @@ -84,34 +122,45 @@ trait StructExp extends StructOps with StructTags with BaseExp with EffectExp wi def var_field[T:Manifest](struct: Rep[Any], index: String)(implicit pos: SourceContext): Var[T] = Variable(FieldApply[Var[T]](struct, index)) def field_update[T:Manifest](struct: Exp[Any], index: String, rhs: Exp[T]): Exp[Unit] = reflectWrite(struct)(FieldUpdate(struct, index, rhs)) + def default_record[T: Manifest]() = DefaultRecordDef[T]() def record_new[T : Manifest](fields: Seq[(String, Boolean, Rep[T] => Rep[_])]) = { val x: Sym[T] = Sym[T](-99) // self symbol -- not defined anywhere, so make it obvious!! (TODO) val fieldSyms = fields map { case (index, false, rhs) => (index, rhs(x)) case (index, true, rhs) => (index, var_new(rhs(x)).e) } - struct(AnonTag(manifest.asInstanceOf[RefinedManifest[T]]), fieldSyms) - } - - def record_select[T : Manifest](record: Rep[Record], fieldName: String) = { - field(record, fieldName) - } - - def imm_field(struct: Exp[Any], name: String, f: Exp[Any])(implicit pos: SourceContext): Exp[Any] = { - if (f.tp.erasure.getSimpleName == "Variable") { - field(struct,name)(mtype(f.tp.typeArguments(0)),pos) - } - else { - object_unsafe_immutable(f)(mtype(f.tp),pos) - } - } - - // don't let unsafeImmutable hide struct-ness - override def object_unsafe_immutable[A:Manifest](lhs: Exp[A])(implicit pos: SourceContext) = lhs match { - case Def(Struct(tag,elems)) => struct[A](tag, elems.map(t => (t._1, imm_field(lhs, t._1, t._2)))) - case Def(d@Reflect(Struct(tag, elems), u, es)) => struct[A](tag, elems.map(t => (t._1, imm_field(lhs, t._1, t._2)))) - case _ => super.object_unsafe_immutable(lhs) - } + struct(ClassTag(structName(manifest[T])),/*AnonTag(manifest[T].asInstanceOf[RefinedManifest[T]]),*/ fieldSyms) + } + + def record_new[T:Manifest](structName: String, fieldSyms: Seq[(String, Rep[Any])]) = { + struct(ClassTag(structName), fieldSyms) + } + + def record_select[T1 : Manifest, TF: Manifest](record: Rep[T1], fieldName: String) = { + field[TF](record, fieldName) + } + def record_concatenate[T1:Manifest,T2:Manifest](record: Rep[T1], record2: Rep[T2], leftAlias: String = "", rightAlias: String = "") = { + val name1 = structName(manifest[T1]).replace("CompositeRecord","") + val s1 = { + if (encounteredStructs.contains(name1)) encounteredStructs(name1) + else name1.split("Anon").filter(x => x.length != 0).map(x => encounteredStructs("Anon" + x)).flatten.toList + } + val name2 = structName(manifest[T2]).replace("CompositeRecord","") + val s2 = { + if (encounteredStructs.contains(name2)) encounteredStructs(name2) + else name2.split("Anon").filter(x => x.length != 0).map(x => encounteredStructs("Anon" + x)).flatten.toList + } + val elems: Seq[(String, Manifest[_])] = { + for (s <- s1) yield leftAlias + s._1 -> s._2 + } ++ { + for (s <- s2) yield rightAlias + s._1 -> s._2 + } + registerStruct(name1 + name2, elems) + /*reflectEffect*/(ConcatenateRecords(record, record2, leftAlias, rightAlias)(record.tp,record2.tp)) + } + def record_print[T<:Record:Manifest](rec: Rep[T]) = reflectEffect(RecordPrint[T](rec)) + def record_hash[T:Manifest](rec: Rep[T]) = reflectEffect(RecordHash(rec)) + def record_equals[T:Manifest](rec1: Rep[T], rec2: Rep[T]) = reflectEffect(RecordEquals(rec1,rec2)) override def syms(e: Any): List[Sym[Any]] = e match { case s:AbstractStruct[_] => s.elems.flatMap(e => syms(e._2)).toList @@ -167,18 +216,26 @@ trait StructExp extends StructOps with StructTags with BaseExp with EffectExp wi override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { case SimpleStruct(tag, elems) => struct(tag, elems map { case (k,v) => (k, f(v)) })(mtype(manifest[A]),pos) - case FieldApply(struct, key) => field(f(struct), key)(mtype(manifest[A]),pos) - case Reflect(FieldApply(struct, key), u, es) => reflectMirrored(Reflect(FieldApply(f(struct), key), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(FieldUpdate(struct, key, rhs), u, es) => reflectMirrored(Reflect(FieldUpdate(f(struct), key, f(rhs)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(SimpleStruct(tag, elems), u, es) => reflectMirrored(Reflect(SimpleStruct(tag, elems map { case (k,v) => (k, f(v)) }), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case fa@FieldApply(struct, key) => record_select(f(struct), key)(struct.tp,fa.m) + case cr@ConcatenateRecords(rec1,rec2,leftAlias,rightAlias) => record_concatenate(f(rec1),f(rec2),leftAlias,rightAlias)(rec1.tp,rec2.tp) + case Reflect(fa@FieldApply(struct, key), u, es) => record_select(f(struct),key)(struct.tp,fa.m) + case Reflect(FieldUpdate(struct, key, rhs), u, es) => reflectMirrored(Reflect(FieldUpdate(f(struct), key, f(rhs)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(SimpleStruct(tag, elems), u, es) => reflectMirrored(Reflect(SimpleStruct(tag, elems map { case (k,v) => (k, f(v)) }), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(RecordPrint(rec), u, es) => reflectMirrored(Reflect(RecordPrint(f(rec)), mapOver(f,u), f(es))) + case Reflect(RecordHash(rec), u, es) => reflectMirrored(Reflect(RecordHash(f(rec)), mapOver(f,u), f(es))) + case Reflect(RecordEquals(rec1,rec2), u, es) => reflectMirrored(Reflect(RecordEquals(f(rec1),f(rec2)), mapOver(f,u), f(es))) + case Reflect(cr@ConcatenateRecords(rec1,rec2,leftAlias,rightAlias), u, es) => record_concatenate(f(rec1),f(rec2),leftAlias,rightAlias)(rec1.tp,rec2.tp) + case dr@DefaultRecordDef() => default_record()(dr.m) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] def structName[T](m: Manifest[T]): String = m match { // FIXME: move to codegen? we should be able to have different policies/naming schemes - case rm: RefinedManifest[_] => "Anon" + math.abs(rm.fields.map(f => f._1.## + f._2.toString.##).sum) - case _ if (m <:< manifest[AnyVal]) => m.toString - case _ if m.erasure.isArray => "ArrayOf" + structName(m.typeArguments.head) + case s if s <:< manifest[CompositeRecord[Any,Any]] => m.typeArguments.map(structName(_)).mkString + case rm: RefinedManifest[_] => "Anon" + math.abs(rm.fields.zipWithIndex.map { case (f, i) => (f._1.## + f._2.toString.##) * (i + 1) /* don't want to multiply by 0 */ }.sum) + case s if m.erasure.isArray => "ArrayOf" + m.typeArguments.map(a => structName(a)).mkString("") + case s if (m <:< manifest[AnyVal]) => m.toString + case s if m.erasure.getSimpleName == "Tuple2" => "Tuple2" + m.typeArguments.foldLeft("")((x,y) => x + structName(y)) case _ => m.erasure.getSimpleName + m.typeArguments.map(a => structName(a)).mkString("") } @@ -191,8 +248,8 @@ trait StructExp extends StructOps with StructTags with BaseExp with EffectExp wi case _ => super.object_tostring(x) } - def registerStruct[T](name: String, elems: Seq[(String, Rep[Any])]) { - encounteredStructs += name -> elems.map(e => (e._1, e._2.tp)) + def registerStruct[T<:Record:Manifest](name: String, elems: Seq[(String, Manifest[_])]) = { + encounteredStructs += name -> elems } val encounteredStructs = new scala.collection.mutable.HashMap[String, Seq[(String, Manifest[_])]] } @@ -223,10 +280,10 @@ trait StructExpOpt extends StructExp { //TODO: need to be careful unwrapping Structs of vars since partial unwrapping can result in reads & writes to two different memory locations in the generated code //(the original var and the struct) /* override def var_field[T:Manifest](struct: Exp[Any], index: String)(implicit pos: SourceContext): Var[T] = fieldLookup(struct, index) match { - case Some(x: Exp[Var[T]]) if x.tp == manifest[Var[T]] => Variable(x) - case Some(x) => throw new RuntimeException("ERROR: " + index + " is not a variable field of type " + struct.tp) - case None => super.var_field(struct, index) - } */ +case Some(x: Exp[Var[T]]) if x.tp == manifest[Var[T]] => Variable(x) +case Some(x) => throw new RuntimeException("ERROR: " + index + " is not a variable field of type " + struct.tp) +case None => super.var_field(struct, index) +} */ } @@ -305,12 +362,12 @@ trait StructFatExpOptCommon extends StructFatExp with StructExpOptCommon with If def phiB[T:Manifest](c: Exp[Boolean], a1: Block[Unit], a2: Block[T], b1: Block[Unit], b2: Block[T])(parent: Exp[Unit]): Exp[T] = if (a2 == b2) a2.res else Phi(c,a1,a2,b1,b2)(parent) // FIXME: duplicate override def syms(x: Any): List[Sym[Any]] = x match { - // case Phi(c,a,u,b,v) => syms(List(c,a,b)) + // case Phi(c,a,u,b,v) => syms(List(c,a,b)) case _ => super.syms(x) } override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { - // case Phi(c,a,u,b,v) => freqNormal(c) ++ freqCold(a) ++ freqCold(b) + // case Phi(c,a,u,b,v) => freqNormal(c) ++ freqCold(a) ++ freqCold(b) case _ => super.symsFreq(e) } @@ -333,7 +390,7 @@ trait StructFatExpOptCommon extends StructFatExp with StructExpOptCommon with If override def ifThenElse[T:Manifest](cond: Rep[Boolean], a: Block[T], b: Block[T])(implicit pos: SourceContext) = (deReify(a),deReify(b)) match { case ((u, Def(Struct(tagA,elemsA))), (v, Def(Struct(tagB, elemsB)))) => //assert(tagA == tagB, tagA+" !== "+tagB) - if (tagA != tagB) println("ERROR: "+tagA+" !== "+tagB) + if (tagA != tagB) System.out.println("ERROR: "+tagA+" !== "+tagB) // create stm that computes all values at once // return struct of syms val combinedResult = super.ifThenElse(cond,u,v) @@ -346,7 +403,6 @@ trait StructFatExpOptCommon extends StructFatExp with StructExpOptCommon with If case _ => super.ifThenElse(cond,a,b) } - } trait BaseGenFatStruct extends GenericFatCodegen { @@ -368,7 +424,7 @@ trait BaseGenFatStruct extends GenericFatCodegen { val ss = phis collect { case TP(s, _) => s } val us = phis collect { case TP(_, Phi(c,a,u,b,v)) => u } // assert c,a,b match val vs = phis collect { case TP(_, Phi(c,a,u,b,v)) => v } - val c = phis collect { case TP(_, Phi(c,a,u,b,v)) => c } reduceLeft { (c1,c2) => assert(c1 == c2); c1 } + val c = phis collect { case TP(_, Phi(c,a,u,b,v)) => c } reduceLeft { (c1,c2) => assert(c1 == c2); c1 } TTP(ss, phis map (_.rhs), SimpleFatIfThenElse(c,us,vs)) } def fatif(s:Sym[Unit],o:Def[Unit],c:Exp[Boolean],a:Block[Unit],b:Block[Unit]) = fatphi(s) match { @@ -416,26 +472,77 @@ trait ScalaGenStruct extends ScalaGenBase with BaseGenStruct { import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case r@DefaultRecordDef() => + def defaultValue[T: ClassManifest]: T = classManifest[T].erasure.toString match { + case "boolean" => false.asInstanceOf[T] + case "byte" => (0: Byte).asInstanceOf[T] + case "short" => (0: Short).asInstanceOf[T] + case "char" => '\0'.asInstanceOf[T] + case "int" => 0.asInstanceOf[T] + case "long" => 0L.asInstanceOf[T] + case "float" => 0.0F.asInstanceOf[T] + case "double" => 0.0.asInstanceOf[T] + case _ => null.asInstanceOf[T] + } + val name = structName(r.m) + val fieldTypes = encounteredStructs(name).map(_._2) + val caseClassStr = if (fieldTypes.length < 22) "" else "new " + stream.println("val " + quote(sym) + " = " + caseClassStr + name + "(" + (for (f <- fieldTypes) yield defaultValue(f)).mkString(",") + ")") case Struct(tag, elems) => - registerStruct(structName(sym.tp), elems) - emitValDef(sym, "new " + structName(sym.tp) + "(" + elems.map(e => quote(e._2)).mkString(",") + ")") + val header = if (elems.length < 22) "" else "new " + emitValDef(sym, header + structName(sym.tp) + "(" + elems.map(e => quote(e._2)).mkString(",") + ")") case FieldApply(struct, index) => emitValDef(sym, quote(struct) + "." + index) case FieldUpdate(struct, index, rhs) => emitValDef(sym, quote(struct) + "." + index + " = " + quote(rhs)) + case RecordPrint(t) => + stream.println(src"println($t.toString)") + case RecordHash(t) => + emitValDef(sym, quote(t) + ".hashCode") + case RecordEquals(t1,t2) => + emitValDef(sym, quote(t1) + " equals " + quote(t2)) + case c@ConcatenateRecords(record1, record2, leftAlias, rightAlias) => + val name1 = structName(c.m1).replace("CompositeRecord", "") + val s1 = encounteredStructs(name1) + val name2 = structName(c.m2).replace("CompositeRecord", "") + val s2 = encounteredStructs(name2) + val header = if (s1.length + s2.length < 22) "" else "new " + emitValDef(sym, header + name1 + name2 + "(" + s1.map(x => quote(record1) + "." + x._1).mkString(",") + "," + s2.map(x => quote(record2) + "." + x._1).mkString(",") + ")") case _ => super.emitNode(sym, rhs) } override def remap[A](m: Manifest[A]) = m match { - case s if s <:< manifest[Record] => structName(m) + case s if s <:< manifest[Record] => structName(m).replace("CompositeRecord","") case _ => super.remap(m) } override def emitDataStructures(stream: PrintWriter) { for ((name, elems) <- encounteredStructs) { stream.println() - stream.print("case class " + name + "(") - stream.println(elems.map(e => e._1 + ": " + remap(e._2)).mkString(", ") + ")") + if (elems.length < 22) stream.print("case ") + stream.print("class " + name + "(") + stream.println(elems.map(e => "val " + e._1 + ": " + remap(e._2)).mkString(", ") + ") {") + stream.println("override def toString() = {") + stream.println(elems.map(e => { + if (e._2 == manifest[Array[Byte]]) "(if(" + e._1 + " != null) new String(" + e._1 + ") else \"\")" + else if (e._2.erasure.isArray) e._1 + ".mkString(\" \")" + else e._1 + }).mkString(" + \"|\" + ") + "+\"\"") + stream.println("}") + stream.println("override def hashCode() = {") + stream.println(elems.map(e => { + if (e._2.erasure.isArray) e._1 + ".foldLeft(0) { (cnt,x) => cnt + x.## }" + else e._1 + ".hashCode" + }).mkString(" + ")) + stream.println("}") + stream.println("override def equals(y: Any) = {") + stream.println("val e = y.asInstanceOf[" + name + "]") + stream.println(elems.map(e => { + if (e._2.erasure.isArray) e._1 + ".corresponds(e." + e._1 + "){_==_}" + else e._1 + " == e." + e._1 + }).mkString(" && ")) + stream.println("}") + stream.println("}") } stream.flush() super.emitDataStructures(stream) @@ -443,10 +550,216 @@ trait ScalaGenStruct extends ScalaGenBase with BaseGenStruct { } -trait CGenStruct extends CGenBase with BaseGenStruct -trait CudaGenStruct extends CudaGenBase with BaseGenStruct +trait CGenStruct extends CGenBase with BaseGenStruct { + val IR: StructExp + import IR._ + def remapToPrintFDescr[A:Manifest](m: Manifest[A]): String = m match { + case s if m == manifest[Int] => "%d|" + case s if m == manifest[Double] => "%lf|" + case s if m == manifest[java.lang.Character] => "%c|" + case s if m == manifest[Long] => "%lu|" + case s if m == manifest[Array[Byte]] => "%s|" + case s if m == manifest[Byte] => "%c|" + case s if m == manifest[java.lang.String] => "%s|" + case dflt@_ => throw new Exception("Unsupported printf descr " + dflt + " when emitting struct. Stringifying...") + } + + override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { + case fa@FieldApply(rec,fldname) => + if (encounteredStructs.get(structName(rec.tp)).isEmpty) { + System.out.println("XX struct not encountered: "+rec.tp) + System.out.println("XX at: "+(sym:AnyRef)+"/"+rhs) + //registerStruct(rec.tp) + } + + val fldtype = encounteredStructs(structName(rec.tp)).find(e => e._1 == fldname).get._2 + val lfldtype = { + val s = fresh(fldtype) + s.tp = fldtype + remapManifest(s)(fldtype.asInstanceOf[Manifest[Any]]) + } + sym.atPhase(LIRLowering) { + val e = (if (sym.tp.erasure.isArray) + reflectEffect(FieldApply(LIRLowering(rec),fldname)(remapManifest(fresh(sym.tp))(sym.tp))) + else record_select(LIRLowering(rec),fldname)(rec.tp,lfldtype)) + e.tp = lfldtype + e.asInstanceOf[Exp[A]] + } + case RecordHash(t) => + sym.atPhase(LIRLowering) { + val rec = LIRLowering(t) + def hash[T:Manifest](lrec: Exp[T]): Exp[Size] = { + val fields = encounteredStructs(structName(manifest[T])) + var h = var_new[Size](unit(0)) + fields.foreach { fld => + if (fld._2.erasure.isPrimitive || fld._2 == manifest[java.lang.Character]) + h += field(lrec, fld._1)(fld._2,implicitly[SourceContext]) + else if (fld._2 == manifest[Array[Byte]]) { + val fldtype = { + val s = fresh(fld._2) + s.tp = fld._2 + remapManifest(s)(fld._2.asInstanceOf[Manifest[Any]]) + } + val a = field(lrec, fld._1)(fld._2, implicitly[SourceContext]) + a.tp = fldtype + val arr = field[Array[Byte]](a,"array") + val arrlen = field[Size](a,"length").asInstanceOf[Rep[Size]] + var i = var_new[Size](unit(0)) + var harr = var_new[Size](unit(0)) + __whileDo(i < arrlen && arr(i) != unit('\0'), { + harr += arr(i) + i+=1 + }) + h += readVar(h) + } + else throw new Exception("Unsupported hash type " + fld._2 + " in record hash!") + } + h + } + val newrec = fresh(rec.tp) // so that there are no effects + val func = uninlinedFunc1(newrec.asInstanceOf[Sym[Any]], reifyEffects({hash(newrec)(rec.tp);})) + doApply(func, rec.asInstanceOf[Sym[Any]]).asInstanceOf[Exp[A]] + } + case RecordEquals(r1,r2) => + sym.atPhase(LIRLowering) { + val rec1 = LIRLowering(r1) + val rec2 = LIRLowering(r2) + def equals[T:Manifest](lrec1: Exp[T], lrec2: Exp[T]): Exp[Boolean] = { + val fields = encounteredStructs(structName(manifest[T])) + var e = var_new[Boolean](unit(true)) + fields.foreach { fld => + if (fld._2.erasure.isPrimitive || fld._2 == manifest[java.lang.Character]) + e = e && __equal(field(lrec1, fld._1)(fld._2,implicitly[SourceContext]).asInstanceOf[Exp[A]], field(lrec2, fld._1)(fld._2,implicitly[SourceContext]).asInstanceOf[Exp[A]]) + else if (fld._2 == manifest[Array[Byte]]) { + val fldtype = { + val s = fresh(fld._2) + s.tp = fld._2 + remapManifest(s)(fld._2.asInstanceOf[Manifest[Any]]) + } + val a1 = field(lrec1, fld._1)(fld._2, implicitly[SourceContext]) + a1.tp = fldtype + val a2 = field(lrec2, fld._1)(fld._2, implicitly[SourceContext]) + a2.tp = fldtype + val arr2 = field[Array[Byte]](LIRLowering(a2),"array") + e = e && __equal(a1.asInstanceOf[Exp[A]], arr2.asInstanceOf[Exp[A]]) + } + else throw new Exception("Unsupported equals type " + fld._2 + " in record equals!") + } + e + } + val (newrec1,newrec2) = (fresh(rec1.tp), fresh(rec2.tp)) // so that there are no effects + val func = uninlinedFunc2(newrec1.asInstanceOf[Sym[Any]], newrec2.asInstanceOf[Sym[Any]], reifyEffects({equals(newrec1,newrec2)(rec1.tp);})).asInstanceOf[Exp[Function1[Tuple2[_,_],Boolean]]] + doApply(func, Const(scala.Tuple2(rec1.asInstanceOf[Sym[Any]], rec2.asInstanceOf[Sym[Any]]))).asInstanceOf[Exp[A]] + } + case RecordPrint(r) => + sym.atPhase(LIRLowering) { + val rec = LIRLowering(r) + def recordprint[T:Manifest](lrec: Exp[T]): Unit = { + val fields = encounteredStructs(structName(manifest[T])) + fields.foreach { fld => + val (fldname, fldtype) = (fld._1, fld._2) + val repfld = field(lrec, fldname)(fldtype,implicitly[SourceContext]) + if (fldtype <:< manifest[Record]) + recordprint(repfld)(fldtype.asInstanceOf[Manifest[Any]]) + else if (fldtype.erasure.getSimpleName == "LoweredArray") { + val arrayType = fldtype.typeArguments.head + val arrayElemType = arrayType.typeArguments.head + val array = field(repfld, "array")(arrayType, implicitly[SourceContext]) + if (arrayType == manifest[Array[Byte]]) + printf(remapToPrintFDescr(arrayType), array) + else { + val length = field[Long](repfld, "length") + for (i <- unit(0L) until length: Rep[LongRange]) + printf(remapToPrintFDescr(arrayElemType), array_apply(array.asInstanceOf[Exp[Array[Any]]],i)(arrayElemType.asInstanceOf[Manifest[Any]], implicitly[SourceContext])) + } + } + else printf(remapToPrintFDescr(fld._2), repfld) + } + } + val newrec = fresh(rec.tp) // so that there are no effects + val func = uninlinedFunc1(newrec.asInstanceOf[Sym[Any]], reifyEffects({recordprint(newrec)(rec.tp); printf("\n");})) + doApply(func, rec.asInstanceOf[Sym[Any]]).asInstanceOf[Exp[A]] + } + case _ => super.lowerNode(sym,rhs) + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case r@DefaultRecordDef() => + def defaultValue[T: ClassManifest]: T = classManifest[T].erasure.toString match { + case "boolean" => false.asInstanceOf[T] + case "byte" => (0: Byte).asInstanceOf[T] + case "short" => (0: Short).asInstanceOf[T] + case "char" => '\0'.asInstanceOf[T] + case "int" => 0.asInstanceOf[T] + case "long" => 0L.asInstanceOf[T] + case "float" => 0.0F.asInstanceOf[T] + case "double" => 0.0.asInstanceOf[T] + case _ => "NULL".asInstanceOf[T] + } + val name = structName(r.m) + val fields = encounteredStructs(name) + allocStruct(sym, "struct " + structName(r.m), stream) + //fields.foreach( f => stream.println(quote(sym) + "->" + f._1 + " = " + defaultValue(f._2) + ";")) + fields.foreach( f => stream.println(quote(sym) + "." + f._1 + " = " + defaultValue(f._2) + ";")) + case Struct(tag, elems) => + val fields = encounteredStructs(tag.asInstanceOf[ClassTag[_]].name).map(x => x._1) zip elems + allocStruct(sym, "struct " + tag.asInstanceOf[ClassTag[_]].name, stream) + //fields.foreach( f => stream.println(quote(sym) + "->" + f._1 + " = " + quote(f._2._2) + ";")) + fields.foreach( f => stream.println(quote(sym) + "." + f._1 + " = " + quote(f._2._2) + ";")) + case fa@FieldApply(struct, index) => + //emitValDef(sym, quote(struct) + "->" + index + ";") + emitValDef(sym, quote(struct) + "." + index + ";") + case FieldUpdate(struct, index, rhs) => + emitValDef(sym, quote(struct) + "->" + index + " = " + quote(rhs)) + case RecordPrint(t) => + stream.println("print_" + structName(t.tp) + "(" + quote(t) + ");") + case c@ConcatenateRecords(record1, record2, leftAlias, rightAlias) => + val name1 = structName(record1.tp).replace("CompositeRecord", "") + val s1 = encounteredStructs(name1) + val name2 = structName(record2.tp).replace("CompositeRecord", "") + val s2 = encounteredStructs(name2) + allocStruct(sym, remap(sym.tp).replace("*",""), stream) + //stream.println(s1.map(x => quote(sym) + "->" + leftAlias + x._1 + " = " + quote(record1) + "->" + x._1).mkString(";\n") + ";") + //stream.println(s2.map(x => quote(sym) + "->" + rightAlias + x._1 + " = " + quote(record2) + "->" + x._1).mkString(";\n") + ";") + stream.println(s1.map(x => quote(sym) + "." + leftAlias + x._1 + " = " + quote(record1) + "." + x._1).mkString(";\n") + ";") + stream.println(s2.map(x => quote(sym) + "." + rightAlias + x._1 + " = " + quote(record2) + "." + x._1).mkString(";\n") + ";") + case _ => super.emitNode(sym, rhs) + } + + override def remap[A](m: Manifest[A]) = m match { + case s if s <:< manifest[CompositeRecord[Any,Any]] => "struct " + structName(m) // + "*" + case s if s <:< manifest[Record] => "struct " + structName(m) // + "*" + case s if s.toString.contains("Pointer") => // TODO find a better place + remap(m.typeArguments.head) + "*" + case _ => super.remap(m) + } + + override def emitDataStructures(stream: PrintWriter) { + // Forward references to resolve dependencies + val hs = new scala.collection.mutable.LinkedHashMap[String,Seq[(String, Manifest[_])]] + def hit(name: String, xs: Seq[(String,Manifest[_])]): Unit = { + xs foreach { x => + val name = structName(x._2) + encounteredStructs.get(name).map(x => hit(name, x)) + } + hs(name) = xs + } + encounteredStructs.foreach((hit _).tupled) + + for ((name, elems) <- hs) { + stream.println() + stream.println("struct " + name + " {") + for(e <- elems) stream.println(remap(e._2) + " " + e._1 + ";") + stream.println("};") + } + stream.flush() + super.emitDataStructures(stream) + } +} +/*trait CudaGenStruct extends CudaGenBase with BaseGenStruct trait OpenCLGenStruct extends OpenCLGenBase with BaseGenStruct trait CudaGenFatStruct extends CudaGenStruct with BaseGenFatStruct trait OpenCLGenFatStruct extends OpenCLGenStruct with BaseGenFatStruct trait CGenFatStruct extends CGenStruct with BaseGenFatStruct +*/ diff --git a/src/common/SynchronizedArrayBufferOps.scala b/src/common/SynchronizedArrayBufferOps.scala index 01b3fe94..5acd75ea 100644 --- a/src/common/SynchronizedArrayBufferOps.scala +++ b/src/common/SynchronizedArrayBufferOps.scala @@ -1,8 +1,8 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal.GenericNestedCodegen +import scala.virtualization.lms.internal.GenericNestedCodegen import collection.mutable.ArrayBuffer import scala.reflect.SourceContext diff --git a/src/common/TreeSet.scala b/src/common/TreeSet.scala new file mode 100644 index 00000000..7027aec8 --- /dev/null +++ b/src/common/TreeSet.scala @@ -0,0 +1,126 @@ +package scala.virtualization.lms.common + +import scala.collection.mutable +import scala.reflect.SourceContext +import scala.virtualization.lms.internal._ + +trait TreeSet extends Base with Variables with Pointer { + + object TreeSet { + def apply[M:Manifest](f: (Rep[M],Rep[M]) => Rep[Int])(implicit pos: SourceContext) = + newTreeSet[M](f) + } + + class TreeSetOps[M: Manifest](x: Rep[mutable.TreeSet[M]]) { + def insert(y: Rep[M]) = treeSetAdd[M](x,y) + def -=(y: Rep[M]) = treeSetRemove[M](x,y) + def head() = treeSetHead[M](x) + def size() = treeSetSize[M](x) + } + implicit def TreeSet2TreeSetOps[M: Manifest](x: Rep[mutable.TreeSet[M]]) = new TreeSetOps(x) + implicit def varTreeSet2TreeSetOps[M: Manifest](x: Var[mutable.TreeSet[M]]) = new TreeSetOps(readVar(x)) + + def newTreeSet[M: Manifest](x: (Rep[M],Rep[M])=>Rep[Int]): Rep[mutable.TreeSet[M]] + def treeSetAdd[M: Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]): Rep[Unit] + def treeSetRemove[M: Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]): Rep[Unit] + def treeSetHead[M: Manifest](x: Rep[mutable.TreeSet[M]]): Rep[M] + def treeSetSize[M: Manifest](x: Rep[mutable.TreeSet[M]]): Rep[Int] +} + +trait TreeSetExp extends TreeSet with BaseExp with Effects with FunctionsExp with PointerExp { + case class NewTreeSet[M: Manifest](x: Block[Int], o1: Sym[M], o2: Sym[M]) extends Def[mutable.TreeSet[M]] { val m = manifest[M] } + case class TreeSetAdd[M:Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]) extends Def[Unit] { val m = manifest[M] } + case class TreeSetRemove[M:Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]) extends Def[Unit] { val m = manifest[M] } + case class TreeSetHead[M:Manifest](x: Rep[mutable.TreeSet[M]]) extends Def[M] { val m = manifest[M] } + case class TreeSetSize[M:Manifest](x: Rep[mutable.TreeSet[M]]) extends Def[Int] { val m = manifest[M] } + + def newTreeSet[M: Manifest](x: (Exp[M],Exp[M])=>Exp[Int]) = { + val m = manifest[M] + val o1 = fresh[M] + val o2 = fresh[M] + val f = reifyEffects(x(o1,o2)) + reflectEffect(NewTreeSet[M](f, o1, o2), summarizeEffects(f).star) + } + def treeSetAdd[M: Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]): Rep[Unit] = reflectEffect(TreeSetAdd[M](x,s)) + def treeSetRemove[M: Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]): Rep[Unit] = reflectEffect(TreeSetRemove[M](x,s)) + def treeSetHead[M: Manifest](x: Rep[mutable.TreeSet[M]]): Rep[M] = reflectEffect(TreeSetHead[M](x)) + def treeSetSize[M: Manifest](x: Rep[mutable.TreeSet[M]]) = reflectEffect(TreeSetSize[M](x)) + + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { + (e match { + case e@NewTreeSet(func,o1,o2) => reflectEffect(NewTreeSet(f(func),o1,o2)(e.m)) + case Reflect(e@TreeSetSize(t), u, es) => reflectMirrored(Reflect(TreeSetSize(f(t))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@TreeSetAdd(t,el), u, es) => reflectMirrored(Reflect(TreeSetAdd(f(t),f(el))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@TreeSetHead(t), u, es) => reflectMirrored(Reflect(TreeSetHead(f(t))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@TreeSetRemove(t,el), u, es) => reflectMirrored(Reflect(TreeSetRemove(f(t),f(el))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] // why?? + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case NewTreeSet(x,o1,o2) => o1::o2::effectSyms(x) + case _ => super.boundSyms(e) + } +} + +trait ScalaGenTreeSet extends ScalaGenBase with GenericNestedCodegen { + val IR: TreeSetExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case t@NewTreeSet(f,o1,o2) => { + val treeType = remap(t.m)//.replace("Array[","ArrayOf").replace("]","") + emitValDef(sym, "new scala.collection.mutable.TreeSet[" + treeType + "]()(") + stream.println("new Ordering[" + treeType + "] {") + stream.println(" def compare(" + quote(o1) + ": " + treeType + ", " + quote(o2) +": " + treeType + ") = { ") + emitBlock(f) + stream.println(quote(getBlockResult(f))) + stream.println("}})") + } + case TreeSetAdd(x,s) => emitValDef(sym, quote(x) + "+=" + quote(s)) + case TreeSetRemove(x,s) => emitValDef(sym, quote(x) + "-=" + quote(s)) + case TreeSetHead(x) => emitValDef(sym, quote(x) + ".head") + case TreeSetSize(x) => emitValDef(sym, quote(x) + ".size") + case _ => super.emitNode(sym, rhs) + } +} + +trait CGenTreeSet extends CGenBase with GenericNestedCodegen with CGenPointer { + val IR: TreeSetExp + import IR._ + + override def remap[A](m: Manifest[A]) = m match { + case s if m <:< manifest[mutable.TreeSet[Any]] => "GTree*" + case _ => super.remap(m) + } + + override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { + case NewTreeSet(f,s1,s2) => + LIRTraversal(f) + sym.atPhase(LIRLowering) { + reflectEffect(NewTreeSet(LIRLowering(f),s1,s2)).asInstanceOf[Exp[T]] + } + case _ => super.lowerNode(sym,rhs) + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case t@NewTreeSet(f,s1,s2) => + val ucf = uninlinedFunc2(s2,s1,f) + emitValDef(sym, "g_tree_new((GCompareFunc)" + quote(ucf) + ");") + case TreeSetAdd(x,s) => + emitValDef(sym, "g_tree_insert(" + quote(x) + "," + quote(s) + "," + quote(s) + ");") + case TreeSetSize(x) => emitValDef(sym, "g_tree_nnodes(" + quote(x) + ")") + case h@TreeSetHead(x) => { + def func[A,B](s1: Exp[A], s2: Exp[A], s3: Exp[B]): Exp[Int] = { + pointer_assign(s3,s2) + unit(0) + } + val ptr = getPointerManifest(h.m) + val ucf = uninlinedFunc3(func)(h.m,h.m,ptr.asInstanceOf[Manifest[Any]],manifest[Int]) + emitValDef(sym, "NULL") + stream.println("g_tree_foreach(" + quote(x) + ", (GTraverseFunc)" + quote(ucf) + ", &" + quote(sym) + ");") + } + case TreeSetRemove(x,s) => stream.println("g_tree_remove(" + quote(x) + "," + quote(s) + ");") + case _ => super.emitNode(sym, rhs) + } +} diff --git a/src/common/TupleOps.scala b/src/common/TupleOps.scala index b8e6564d..11e31258 100644 --- a/src/common/TupleOps.scala +++ b/src/common/TupleOps.scala @@ -1,11 +1,19 @@ -package scala.lms +package scala.virtualization.lms package common -import scala.lms.internal.GenericCodegen -import java.io.PrintWriter +import scala.virtualization.lms.common._ +import scala.virtualization.lms.internal.GenericCodegen import scala.reflect.SourceContext +import java.io.PrintWriter + +/** + * Taken char-for-char from the delite-develop branch of lms + */ + trait TupleOps extends Base { + val tuple_elems: Seq[String] + implicit def make_tuple2[A:Manifest,B:Manifest](t: (Rep[A], Rep[B]))(implicit pos: SourceContext) : Rep[(A,B)] implicit def make_tuple3[A:Manifest,B:Manifest,C:Manifest](t: (Rep[A], Rep[B], Rep[C]))(implicit pos: SourceContext) : Rep[(A,B,C)] implicit def make_tuple4[A:Manifest,B:Manifest,C:Manifest,D:Manifest](t: (Rep[A], Rep[B], Rep[C], Rep[D]))(implicit pos: SourceContext) : Rep[(A,B,C,D)] @@ -37,49 +45,281 @@ trait TupleOps extends Base { def tuple5_get3[C:Manifest](t: Rep[(_,_,C,_,_)])(implicit pos: SourceContext) : Rep[C] def tuple5_get4[D:Manifest](t: Rep[(_,_,_,D,_)])(implicit pos: SourceContext) : Rep[D] def tuple5_get5[E:Manifest](t: Rep[(_,_,_,_,E)])(implicit pos: SourceContext) : Rep[E] + def hashTuple2(t: Rep[(_,_)]): Rep[Int] + def compareTuple2(t1: Rep[(_,_)], t2: Rep[(_,_)]): Rep[Boolean] + def hashTuple3(t: Rep[(_,_,_)]): Rep[Int] + def compareTuple3(t1: Rep[(_,_,_)], t2: Rep[(_,_,_)]): Rep[Boolean] + def hashTuple5(t: Rep[(_,_,_,_,_)]): Rep[Int] + def compareTuple5(t1: Rep[(_,_,_,_,_)], t2: Rep[(_,_,_,_,_)]): Rep[Boolean] } +object TupleOpsGenType { var isCGen: scala.Boolean = false } + trait TupleOpsExp extends TupleOps with StructExpOpt { + case class ETuple2[A:Manifest,B:Manifest](_1: Exp[A],_2: Exp[B]) extends Def[(A,B)] { + val m1 = manifest[A] + val m2 = manifest[B] + } + case class ETuple3[A:Manifest,B:Manifest,C:Manifest](_1: Exp[A],_2: Exp[B],_3: Exp[C]) extends Def[(A,B,C)] { + val m1 = manifest[A] + val m2 = manifest[B] + val m3 = manifest[C] + } + case class ETuple4[A:Manifest,B:Manifest,C:Manifest,D:Manifest](_1: Exp[A],_2: Exp[B],_3: Exp[C],_4: Exp[D]) extends Def[(A,B,C,D)] { + val m1 = manifest[A] + val m2 = manifest[B] + val m3 = manifest[C] + val m4 = manifest[D] + } + case class ETuple5[A:Manifest,B:Manifest,C:Manifest,D:Manifest,E:Manifest](_1: Exp[A],_2: Exp[B],_3: Exp[C],_4: Exp[D],_5: Exp[E]) extends Def[(A,B,C,D,E)] { + val m1 = manifest[A] + val m2 = manifest[B] + val m3 = manifest[C] + val m4 = manifest[D] + val m5 = manifest[E] + } + + val tuple_elems: Seq[String] = List("_1", "_2", "_3", "_4", "_5") + + implicit def make_tuple2[A:Manifest,B:Manifest](t: (Exp[A],Exp[B]))(implicit pos: SourceContext) : Exp[(A,B)] = { + if (TupleOpsGenType.isCGen) struct(classTag[(A,B)], tuple_elems(0) -> t._1, tuple_elems(1) -> t._2) + else ETuple2(t._1, t._2) + } + implicit def make_tuple3[A:Manifest,B:Manifest,C:Manifest](t: (Exp[A],Exp[B],Exp[C]))(implicit pos: SourceContext) : Exp[(A,B,C)] = { + if (TupleOpsGenType.isCGen) struct(classTag[(A,B,C)], tuple_elems(0) -> t._1, tuple_elems(1) -> t._2, tuple_elems(2) -> t._3) + else ETuple3(t._1, t._2, t._3) + } + implicit def make_tuple4[A:Manifest,B:Manifest,C:Manifest,D:Manifest](t: (Exp[A],Exp[B],Exp[C],Exp[D]))(implicit pos: SourceContext) : Exp[(A,B,C,D)] = { + if (TupleOpsGenType.isCGen) struct(classTag[(A,B,C,D)], tuple_elems(0) -> t._1, tuple_elems(1) -> t._2, tuple_elems(2) -> t._3, tuple_elems(3) -> t._4) + else ETuple4(t._1, t._2, t._3, t._4) + } + implicit def make_tuple5[A:Manifest,B:Manifest,C:Manifest,D:Manifest,E:Manifest](t: (Exp[A],Exp[B],Exp[C],Exp[D],Exp[E]))(implicit pos: SourceContext) : Exp[(A,B,C,D,E)] = { + if (TupleOpsGenType.isCGen) struct(classTag[(A,B,C,D,E)], tuple_elems(0) -> t._1, tuple_elems(1) -> t._2, tuple_elems(2) -> t._3, tuple_elems(3) -> t._4, tuple_elems(4) -> t._5) + else ETuple5(t._1, t._2, t._3, t._4, t._5) + } + + def hashTuple2(t: Rep[(_,_)]): Rep[Int] = reflectEffect(HashTuple2(t)) + def compareTuple2(t1: Rep[(_,_)], t2: Rep[(_,_)]): Rep[Boolean] = reflectEffect(CompareTuple2(t1,t2)) + def hashTuple3(t: Rep[(_,_,_)]): Rep[Int] = reflectEffect(HashTuple3(t)) + def compareTuple3(t1: Rep[(_,_,_)], t2: Rep[(_,_,_)]): Rep[Boolean] = reflectEffect(CompareTuple3(t1,t2)) + def hashTuple5(t: Rep[(_,_,_,_,_)]): Rep[Int] = reflectEffect(HashTuple5(t)) + def compareTuple5(t1: Rep[(_,_,_,_,_)], t2: Rep[(_,_,_,_,_)]): Rep[Boolean] = reflectEffect(CompareTuple5(t1,t2)) - implicit def make_tuple2[A:Manifest,B:Manifest](t: (Exp[A],Exp[B]))(implicit pos: SourceContext) : Exp[(A,B)] = struct(classTag[(A,B)], "_1" -> t._1, "_2" -> t._2) - implicit def make_tuple3[A:Manifest,B:Manifest,C:Manifest](t: (Exp[A],Exp[B],Exp[C]))(implicit pos: SourceContext) : Exp[(A,B,C)] = struct(classTag[(A,B,C)], "_1" -> t._1, "_2" -> t._2, "_3" -> t._3) - implicit def make_tuple4[A:Manifest,B:Manifest,C:Manifest,D:Manifest](t: (Exp[A],Exp[B],Exp[C],Exp[D]))(implicit pos: SourceContext) : Exp[(A,B,C,D)] = struct(classTag[(A,B,C,D)], "_1" -> t._1, "_2" -> t._2, "_3" -> t._3, "_4" -> t._4) - implicit def make_tuple5[A:Manifest,B:Manifest,C:Manifest,D:Manifest,E:Manifest](t: (Exp[A],Exp[B],Exp[C],Exp[D],Exp[E]))(implicit pos: SourceContext) : Exp[(A,B,C,D,E)] = struct(classTag[(A,B,C,D,E)], "_1" -> t._1, "_2" -> t._2, "_3" -> t._3, "_4" -> t._4, "_5" -> t._5) + case class Tuple2Access1[A:Manifest](t: Exp[(A,_)]) extends Def[A] { val m = manifest[A] } + case class Tuple2Access2[B:Manifest](t: Exp[(_,B)]) extends Def[B] { val m = manifest[B] } + case class Tuple3Access1[A:Manifest](t: Exp[(A,_,_)]) extends Def[A] { val m = manifest[A] } + case class Tuple3Access2[B:Manifest](t: Exp[(_,B,_)]) extends Def[B] { val m = manifest[B] } + case class Tuple3Access3[C:Manifest](t: Exp[(_,_,C)]) extends Def[C] { val m = manifest[C] } + case class Tuple4Access1[A:Manifest](t: Exp[(A,_,_,_)]) extends Def[A] { val m = manifest[A] } + case class Tuple4Access2[B:Manifest](t: Exp[(_,B,_,_)]) extends Def[B] { val m = manifest[B] } + case class Tuple4Access3[C:Manifest](t: Exp[(_,_,C,_)]) extends Def[C] { val m = manifest[C] } + case class Tuple4Access4[D:Manifest](t: Exp[(_,_,_,D)]) extends Def[D] { val m = manifest[D] } + case class Tuple5Access1[A:Manifest](t: Exp[(A,_,_,_,_)]) extends Def[A] { val m = manifest[A] } + case class Tuple5Access2[B:Manifest](t: Exp[(_,B,_,_,_)]) extends Def[B] { val m = manifest[B] } + case class Tuple5Access3[C:Manifest](t: Exp[(_,_,C,_,_)]) extends Def[C] { val m = manifest[C] } + case class Tuple5Access4[D:Manifest](t: Exp[(_,_,_,D,_)]) extends Def[D] { val m = manifest[D] } + case class Tuple5Access5[E:Manifest](t: Exp[(_,_,_,_,E)]) extends Def[E] { val m = manifest[E] } + case class HashTuple2(t: Exp[(_,_)]) extends Def[Int] + case class CompareTuple2(t1: Exp[(_,_)], t2: Exp[(_,_)]) extends Def[Boolean] + case class HashTuple3(t: Exp[(_,_,_)]) extends Def[Int] + case class CompareTuple3(t1: Exp[(_,_,_)], t2: Exp[(_,_,_)]) extends Def[Boolean] + case class HashTuple5(t: Exp[(_,_,_,_,_)]) extends Def[Int] + case class CompareTuple5(t1: Exp[(_,_,_,_,_)], t2: Exp[(_,_,_,_,_)]) extends Def[Boolean] - def tuple2_get1[A:Manifest](t: Exp[(A,_)])(implicit pos: SourceContext) = field[A](t, "_1") - def tuple2_get2[B:Manifest](t: Exp[(_,B)])(implicit pos: SourceContext) = field[B](t, "_2") + def tuple2_get1[A:Manifest](t: Exp[(A,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple2(a,b)) => a + case _ => + field[A](t, tuple_elems(0)) + } + def tuple2_get2[B:Manifest](t: Exp[(_,B)])(implicit pos: SourceContext) = t match { + case Def(ETuple2(a,b)) => b + case _ => + field[B](t, tuple_elems(1)) + } - def tuple3_get1[A:Manifest](t: Exp[(A,_,_)])(implicit pos: SourceContext) = field[A](t, "_1") - def tuple3_get2[B:Manifest](t: Exp[(_,B,_)])(implicit pos: SourceContext) = field[B](t, "_2") - def tuple3_get3[C:Manifest](t: Exp[(_,_,C)])(implicit pos: SourceContext) = field[C](t, "_3") + def tuple3_get1[A:Manifest](t: Exp[(A,_,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple3(a,b,c)) => a + case _ => + field[A](t, tuple_elems(0)) + } + def tuple3_get2[B:Manifest](t: Exp[(_,B,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple3(a,b,c)) => b + case _ => + field[B](t, tuple_elems(1)) + } + def tuple3_get3[C:Manifest](t: Exp[(_,_,C)])(implicit pos: SourceContext) = t match { + case Def(ETuple3(a,b,c)) => c + case _ => + field[C](t, tuple_elems(2)) + } - def tuple4_get1[A:Manifest](t: Exp[(A,_,_,_)])(implicit pos: SourceContext) = field[A](t, "_1") - def tuple4_get2[B:Manifest](t: Exp[(_,B,_,_)])(implicit pos: SourceContext) = field[B](t, "_2") - def tuple4_get3[C:Manifest](t: Exp[(_,_,C,_)])(implicit pos: SourceContext) = field[C](t, "_3") - def tuple4_get4[D:Manifest](t: Exp[(_,_,_,D)])(implicit pos: SourceContext) = field[D](t, "_4") + def tuple4_get1[A:Manifest](t: Exp[(A,_,_,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple4(a,b,c,d)) => a + case _ => + field[A](t, tuple_elems(0)) + } + def tuple4_get2[B:Manifest](t: Exp[(_,B,_,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple4(a,b,c,d)) => b + case _ => + field[B](t, tuple_elems(1)) + } + def tuple4_get3[C:Manifest](t: Exp[(_,_,C,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple4(a,b,c,d)) => c + case _ => + field[C](t, tuple_elems(2)) + } + def tuple4_get4[D:Manifest](t: Exp[(_,_,_,D)])(implicit pos: SourceContext) = t match { + case Def(ETuple4(a,b,c,d)) => d + case _ => + field[D](t, tuple_elems(3)) + } - def tuple5_get1[A:Manifest](t: Exp[(A,_,_,_,_)])(implicit pos: SourceContext) = field[A](t, "_1") - def tuple5_get2[B:Manifest](t: Exp[(_,B,_,_,_)])(implicit pos: SourceContext) = field[B](t, "_2") - def tuple5_get3[C:Manifest](t: Exp[(_,_,C,_,_)])(implicit pos: SourceContext) = field[C](t, "_3") - def tuple5_get4[D:Manifest](t: Exp[(_,_,_,D,_)])(implicit pos: SourceContext) = field[D](t, "_4") - def tuple5_get5[E:Manifest](t: Exp[(_,_,_,_,E)])(implicit pos: SourceContext) = field[E](t, "_5") + def tuple5_get1[A:Manifest](t: Exp[(A,_,_,_,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple5(a,b,c,d,e)) => a + case _ => + field[A](t, tuple_elems(0)) + } + def tuple5_get2[B:Manifest](t: Exp[(_,B,_,_,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple5(a,b,c,d,e)) => b + case _ => + field[B](t, tuple_elems(1)) + } + def tuple5_get3[C:Manifest](t: Exp[(_,_,C,_,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple5(a,b,c,d,e)) => c + case _ => + field[C](t, tuple_elems(2)) + } + def tuple5_get4[D:Manifest](t: Exp[(_,_,_,D,_)])(implicit pos: SourceContext) = t match { + case Def(ETuple5(a,b,c,d,e)) => d + case _ => + field[D](t, tuple_elems(3)) + } + def tuple5_get5[E:Manifest](t: Exp[(_,_,_,_,E)])(implicit pos: SourceContext) = t match { + case Def(ETuple5(a,b,c,d,e)) => e + case _ => + field[E](t, tuple_elems(4)) + } object Both { def unapply[T](x:T):Some[(T,T)] = Some((x,x)) } + + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case e@ETuple2(a,b) => make_tuple2(f(a),f(b))(e.m1,e.m2,pos) + case e@Tuple2Access1(t) => tuple2_get1(f(t))(mtype(e.m),pos) + case e@Tuple2Access2(t) => tuple2_get2(f(t))(mtype(e.m),pos) + case Reflect(e@Tuple2Access1(t), u, es) => reflectMirrored(Reflect(Tuple2Access1(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple2Access2(t), u, es) => reflectMirrored(Reflect(Tuple2Access2(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + + case e@ETuple3(a,b,c) => make_tuple3(f(a),f(b),f(c))(e.m1,e.m2,e.m3,pos) + case e@Tuple3Access1(t) => tuple3_get1(f(t))(mtype(e.m),pos) + case e@Tuple3Access2(t) => tuple3_get2(f(t))(mtype(e.m),pos) + case e@Tuple3Access3(t) => tuple3_get3(f(t))(mtype(e.m),pos) + case Reflect(e@Tuple3Access1(t), u, es) => reflectMirrored(Reflect(Tuple3Access1(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple3Access2(t), u, es) => reflectMirrored(Reflect(Tuple3Access2(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple3Access3(t), u, es) => reflectMirrored(Reflect(Tuple3Access3(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + + case e@ETuple4(a,b,c,d) => make_tuple4(f(a),f(b),f(c),f(d))(e.m1,e.m2,e.m3,e.m4,pos) + case e@Tuple4Access1(t) => tuple4_get1(f(t))(mtype(e.m),pos) + case e@Tuple4Access2(t) => tuple4_get2(f(t))(mtype(e.m),pos) + case e@Tuple4Access3(t) => tuple4_get3(f(t))(mtype(e.m),pos) + case e@Tuple4Access4(t) => tuple4_get4(f(t))(mtype(e.m),pos) + case Reflect(e@Tuple4Access1(t), u, es) => reflectMirrored(Reflect(Tuple4Access1(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple4Access2(t), u, es) => reflectMirrored(Reflect(Tuple4Access2(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple4Access3(t), u, es) => reflectMirrored(Reflect(Tuple4Access3(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple4Access4(t), u, es) => reflectMirrored(Reflect(Tuple4Access4(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + + case e@ETuple5(a,b,c,d,g) => make_tuple5(f(a),f(b),f(c),f(d),f(g))(e.m1,e.m2,e.m3,e.m4,e.m5,pos) + case e@Tuple5Access1(t) => tuple5_get1(f(t))(mtype(e.m),pos) + case e@Tuple5Access2(t) => tuple5_get2(f(t))(mtype(e.m),pos) + case e@Tuple5Access3(t) => tuple5_get3(f(t))(mtype(e.m),pos) + case e@Tuple5Access4(t) => tuple5_get4(f(t))(mtype(e.m),pos) + case e@Tuple5Access5(t) => tuple5_get5(f(t))(mtype(e.m),pos) + case Reflect(e@Tuple5Access1(t), u, es) => reflectMirrored(Reflect(Tuple5Access1(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple5Access2(t), u, es) => reflectMirrored(Reflect(Tuple5Access2(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple5Access3(t), u, es) => reflectMirrored(Reflect(Tuple5Access3(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple5Access4(t), u, es) => reflectMirrored(Reflect(Tuple5Access4(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@Tuple5Access5(t), u, es) => reflectMirrored(Reflect(Tuple5Access5(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] } -trait TupleGenBase extends GenericCodegen with BaseGenStruct { +trait TupleGenBase extends GenericCodegen with BaseGenStruct { val IR: TupleOpsExp } + +trait ScalaGenTupleOps extends ScalaGenBase with TupleGenBase { val IR: TupleOpsExp + import IR._ - override def remap[A](m: Manifest[A]) = m.erasure.getSimpleName match { - case "Tuple2" => IR.structName(m) - case "Tuple3" => IR.structName(m) - case "Tuple4" => IR.structName(m) - case "Tuple5" => IR.structName(m) - case _ => super.remap(m) + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ETuple2(a,b) => + emitValDef(sym, src"($a,$b)") + case Tuple2Access1(t) => emitValDef(sym, src"$t._1") + case Tuple2Access2(t) => emitValDef(sym, src"$t._2") + + case ETuple3(a,b,c) => + emitValDef(sym, src"($a,$b,$c)") + case Tuple3Access1(t) => emitValDef(sym, src"$t._1") + case Tuple3Access2(t) => emitValDef(sym, src"$t._2") + case Tuple3Access3(t) => emitValDef(sym, src"$t._3") + + case ETuple4(a,b,c,d) => + emitValDef(sym, src"($a,$b,$c,$d)") + case Tuple4Access1(t) => emitValDef(sym, src"$t._1") + case Tuple4Access2(t) => emitValDef(sym, src"$t._2") + case Tuple4Access3(t) => emitValDef(sym, src"$t._3") + case Tuple4Access4(t) => emitValDef(sym, src"$t._4") + + case ETuple5(a,b,c,d,e) => + emitValDef(sym, src"($a,$b,$c,$d,$e)") + case Tuple5Access1(t) => emitValDef(sym, src"$t._1") + case Tuple5Access2(t) => emitValDef(sym, src"$t._2") + case Tuple5Access3(t) => emitValDef(sym, src"$t._3") + case Tuple5Access4(t) => emitValDef(sym, src"$t._4") + case Tuple5Access5(t) => emitValDef(sym, src"$t._5") + + case _ => super.emitNode(sym, rhs) } + + +/* override def remap[A](m: Manifest[A]) = m.runtimeClass.getSimpleName match { + case "Tuple2" => "Tuple2" + m.typeArguments.foldLeft("")((x,y) => x + remap(y).toString).replace("Array[","ArrayOf").replace("]","") + case "Tuple3" => "Tuple3" + m.typeArguments.foldLeft("")((x,y) => x + remap(y).toString).replace("Array[","ArrayOf").replace("]","") + case "Tuple4" => "Tuple4" + m.typeArguments.foldLeft("")((x,y) => x + remap(y).toString).replace("Array[","ArrayOf").replace("]","") + case "Tuple5" => "Tuple5" + m.typeArguments.foldLeft("")((x,y) => x + remap(y).toString).replace("Array[","ArrayOf").replace("]","") + case _ => super.remap(m) + }*/ } -trait ScalaGenTupleOps extends ScalaGenBase with TupleGenBase with ScalaGenStruct { val IR: TupleOpsExp } -trait CGenTupleOps extends CGenBase with TupleGenBase with CGenStruct -trait CudaGenTupleOps extends CudaGenBase with TupleGenBase with CudaGenStruct -trait OpenCLGenTupleOps extends OpenCLGenBase with TupleGenBase with OpenCLGenStruct +trait CGenTupleOps extends CGenBase with TupleGenBase with CGenStruct { + val IR: TupleOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case HashTuple2(t) => emitValDef(sym, "(int)" + quote(t) + "->_1 + (int)" + quote(t) + "->_2;") + case CompareTuple2(t1,t2) => emitValDef(sym, quote(t1) + "->_1 == " + quote(t2) + "->_1 && " + quote(t1) + "->_2 == " + quote(t2) + "->_2;") + case HashTuple3(t) => emitValDef(sym, "(int)" + quote(t) + "->_1 + (int)" + quote(t) + "->_2 + (int)" + quote(t) + "->_3;") + case CompareTuple3(t1,t2) => emitValDef(sym, quote(t1) + "->_1 == " + quote(t2) + "->_1 && " + quote(t1) + "->_2 == " + quote(t2) + "->_2 && " + quote(t1) + "->_3 == " + quote(t2) + "->_3;") + case HashTuple5(t) => emitValDef(sym, "(int)" + quote(t) + "->_1 + (int)" + quote(t) + "->_2 + (int)" + quote(t) + "->_3 + (int)" + quote(t) + "->_4 + (int)" + quote(t) + "->_5;") + case CompareTuple5(t1,t2) => emitValDef(sym, quote(t1) + "->_1 == " + quote(t2) + "->_1 && " + quote(t1) + "->_2 == " + quote(t2) + "->_2 && " + quote(t1) + "->_3 == " + quote(t2) + "->_3 && " + quote(t1) + "->_4 == " + quote(t2) + "->_4 && " + quote(t1) + "->_5 == " + quote(t2) + "->_5;") + case _ => super.emitNode(sym, rhs) + } + + override def remap[A](m: Manifest[A]) = m.runtimeClass.getSimpleName match { + case "Tuple2" => + val elems = IR.tuple_elems.take(2) zip m.typeArguments + IR.registerStruct(IR.structName(m), elems) + IR.structName(m) + "*" + case "Tuple3" => + val elems = IR.tuple_elems.take(3) zip m.typeArguments + IR.registerStruct(IR.structName(m), elems) + IR.structName(m) + "*" + case "Tuple4" => + val elems = IR.tuple_elems.take(4) zip m.typeArguments + IR.registerStruct(IR.structName(m), elems) + IR.structName(m) + "*" + case "Tuple5" => + val elems = IR.tuple_elems.take(5) zip m.typeArguments + IR.registerStruct(IR.structName(m), elems) + IR.structName(m) + "*" + case _ => super.remap(m) + } +} diff --git a/src/common/Unchecked.scala b/src/common/Unchecked.scala index aa8af092..db4b80de 100644 --- a/src/common/Unchecked.scala +++ b/src/common/Unchecked.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter diff --git a/src/common/UninlinedFunctions.scala b/src/common/UninlinedFunctions.scala new file mode 100644 index 00000000..39a85d9e --- /dev/null +++ b/src/common/UninlinedFunctions.scala @@ -0,0 +1,299 @@ +/*package scala.virtualization.lms +package common + +import java.io.PrintWriter +import java.io.StringWriter +import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException} +import scala.virtualization.lms.util.ClosureCompare + +import scala.reflect.SourceContext + +trait UninlinedFunctions extends Base { + implicit def toUninlinedFuncOps0[B:Manifest](fun: Rep[()=>B]) = new UninlinedFuncOps0(fun) + implicit def toUninlinedFuncOps1[A:Manifest,B:Manifest](fun: Rep[A=>B]) = new UninlinedFuncOps1(fun) + implicit def toUninlinedFuncOps2[A1:Manifest,A2:Manifest,B:Manifest](fun: Rep[(A1,A2)=>B]) = new UninlinedFuncOps2(fun) + + class UninlinedFuncOps0[B:Manifest](f: Rep[()=>B]) { + def apply()(implicit pos: SourceContext): Rep[B] = uninlinedFuncApply(f) + } + class UninlinedFuncOps1[A:Manifest,B:Manifest](f: Rep[A=>B]) { + def apply(x: Rep[A])(implicit pos: SourceContext): Rep[B] = uninlinedFuncApply(f,x) + } + class UninlinedFuncOps2[A1:Manifest,A2:Manifest,B:Manifest](f: Rep[(A1,A2)=>B]) { + def apply(x: Rep[A1], y: Rep[A2])(implicit pos: SourceContext): Rep[B] = uninlinedFuncApply(f,x,y) + } + + def createUninlinedFunc0[B:Manifest](fun: () => Rep[B], dRet: String = "", si: () => Rep[Unit] = null)(implicit pos: SourceContext): Rep[()=>B] + def createUninlinedFunc1[A:Manifest,B:Manifest](fun: Rep[A] => Rep[B], argType: String = "", dRet: String = "", si: () => Rep[Unit] = null)(implicit pos: SourceContext): Rep[A=>B] + def createUninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](fun: (Rep[A1],Rep[A2]) => Rep[B], argType: String = "", argType2: String = "", dRet: String = "", si: () => Rep[Unit] = null)(implicit pos: SourceContext): Rep[(A1,A2)=>B] + def uninlinedFuncApply[B:Manifest](fun: Rep[() => B])(implicit pos: SourceContext): Rep[B] + def uninlinedFuncApply[A:Manifest,B:Manifest](fun: Rep[A => B], arg: Rep[A])(implicit pos: SourceContext): Rep[B] + def uninlinedFuncApply[A1:Manifest,A2:Manifest,B:Manifest](fun: Rep[(A1,A2)=>B], arg: Rep[A1], arg2: Rep[A2])(implicit pos: SourceContext): Rep[B] +} + +trait UninlinedFunctionsExp extends UninlinedFunctions with BaseExp with EffectExp { + val functionList0 = new scala.collection.mutable.ListBuffer[UninlinedFunc0[_]]() + val functionList1 = new scala.collection.mutable.ListBuffer[UninlinedFunc1[_,_]]() + val functionList2 = new scala.collection.mutable.ListBuffer[UninlinedFunc2[_,_,_]]() + + // UninlinedFunc generates nothing, but is saved in the list and is later printed in the preamble + // of the file of the generated code + case class UninlinedFunc0[B:Manifest](f: () => Exp[B], y:Sym[B], dRet:String = "", si: () => Exp[Unit]) extends Def[()=>B] + case class UninlinedFunc1[A:Manifest,B:Manifest](f: Exp[A] => Exp[B], x: Sym[A], y:Sym[B], dynamicType: String, dRet:String = "", si: () => Exp[Unit]) extends Def[A=>B] + case class UninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](f: (Exp[A1],Exp[A2]) => Exp[B], x: Sym[A1], y: Sym[A2], z: Sym[B], argType: String = "", argType2: String = "", dRet:String = "", si: () => Exp[Unit]) extends Def[(A1,A2)=>B] + case class UninlinedFuncApply0[B:Manifest](f: Exp[() => B]) extends Def[B] + case class UninlinedFuncApply1[A:Manifest,B:Manifest](f: Exp[A => B], arg: Exp[A]) extends Def[B] + case class UninlinedFuncApply2[A1:Manifest,A2:Manifest,B:Manifest](f: Exp[(A1,A2) => B], arg: Exp[A1], arg2: Exp[A2]) extends Def[B] + + // si stands for State Initializer + override def createUninlinedFunc0[B:Manifest](f: () => Exp[B], dRet: String = "", si: () => Exp[Unit] = null)(implicit pos: SourceContext): Exp[()=>B] = { + val res = fresh[B] // overcomes the fact that the list has B = Any + val l = UninlinedFunc0(f, res, dRet, si) + functionList0 += l + l + } + override def createUninlinedFunc1[A:Manifest,B:Manifest](f: Exp[A] => Exp[B], argType: String = "", dRet: String = "", si: () => Exp[Unit] = null)(implicit pos: SourceContext): Exp[A=>B] = { + val e = fresh[A] + val res = fresh[B] // overcomes the fact that the list has B = Any + val l = UninlinedFunc1(f, e, res, argType, dRet, si) + functionList1 += l + l + } + override def createUninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](f: (Exp[A1],Exp[A2]) => Exp[B], argType: String = "", argType2: String = "", dRet: String = "", si: () => Exp[Unit] = null)(implicit pos: SourceContext): Exp[(A1,A2)=>B] = { + val e1 = fresh[A1] + val e2 = fresh[A2] + val res = fresh[B] // overcomes the fact that the list has B = Any + val l = UninlinedFunc2(f, e1, e2, res, argType, argType2, dRet, si) + functionList2 += l + l + } + + def uninlinedFuncApply[B:Manifest](f: Exp[()=>B])(implicit pos: SourceContext): Exp[B] = { + reflectEffect(UninlinedFuncApply0(f)) + } + def uninlinedFuncApply[A:Manifest,B:Manifest](f: Exp[A=>B], x: Exp[A])(implicit pos: SourceContext): Exp[B] = { + reflectEffect(UninlinedFuncApply1(f, x)) + } + def uninlinedFuncApply[A1:Manifest,A2:Manifest,B:Manifest](f: Exp[(A1,A2)=>B], x1: Exp[A1], x2: Exp[A2])(implicit pos: SourceContext): Exp[B] = { + reflectEffect(UninlinedFuncApply2(f, x1, x2)) + } +} + +trait ScalaGenUninlinedFunctions extends ScalaGenEffect { + val IR: UninlinedFunctionsExp + import IR._ + + var emitEnabled: Boolean = false + + private def printState(si: () => Exp[Unit]) { + // Print state if si is set + if (si != null) { + val state = reifyEffects(si()) + emitBlock(state) + } + } + + private def argsToStr(e: List[Sym[Any]], argTypes: List[String]) = { + val z = e zip argTypes + z.map(x => { + if (quote(x._1) != "") quote(x._1) + ": " + x._2 + else "x" + x._1.toString.replace("Sym(","").replace(")","") + ": " + x._2 + }).mkString(",") + } + + private def printUninlinedFuncBody[T:Manifest](b: Block[T]) { + emitBlock(b) + stream.println(quote(getBlockResult(b))) + stream.println("}") + stream.println("}") + stream.println() + } + + private def getArgTypes(syms: List[Sym[Any]], args: String*) = { + val z = syms zip args.toList + z.map(x => if (x._2 != "") x._2 else remap(x._1.tp)) + } + + private def getReturnType(res: Sym[Any], dRet: String) = if (dRet != "") dRet else remap(res.tp) + + override def emitFileHeader() = { + emitEnabled = true + functionList0.foreach(func => traverseStm(findDefinition(func).get)) + functionList1.foreach(func => traverseStm(findDefinition(func).get)) + functionList2.foreach(func => traverseStm(findDefinition(func).get)) + emitEnabled = false + functionList0.clear + functionList1.clear + functionList2.clear + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case UninlinedFunc0(fun, res, dRet, si) => { + if (emitEnabled) { + val retType = getReturnType(res, dRet) + stream.println("object " + quote(sym) + + " extends (()=>" + retType +") {") + emitEnabled = false + printState(si) + // Now print function + val f = reifyEffects(fun()) + stream.println("def apply(): " + retType + " = {") + printUninlinedFuncBody(f) + emitEnabled = true + } + } + case UninlinedFunc1(fun, e, res, argType, dRet, si) => { + if (emitEnabled) { + val syms = List(e) + val argTypes = getArgTypes(syms, argType) + val retType = getReturnType(res, dRet) + stream.println("object " + quote(sym) + + " extends ((" + argTypes.mkString(",") + ")=>" + retType +") {") + emitEnabled = false + printState(si) + // Now print function + stream.println("def apply(" + argsToStr(syms, argTypes) + "): " + retType + " = {") + printUninlinedFuncBody(reifyEffects(fun(e))) + emitEnabled = true + } + } + case UninlinedFunc2(fun, e1, e2, res, argType, argType2, dRet, si) => { + if (emitEnabled) { + val syms = List(e1,e2) + val argTypes = getArgTypes(syms,argType,argType2) + val retType = getReturnType(res, dRet) + stream.println("object " + quote(sym) + + " extends ((" + argTypes.mkString(",") + ")=>" + retType +") {") + emitEnabled = false + printState(si) + // Now print function + stream.println("def apply(" + argsToStr(syms, argTypes) + "): " + retType + " = {") + printUninlinedFuncBody(reifyEffects(fun(e1,e2))) + emitEnabled = true + } + } + case UninlinedFuncApply0(fun) => + emitValDef(sym, quote(fun) + "()") + case UninlinedFuncApply1(fun, arg) => + emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") + case UninlinedFuncApply2(fun, arg, arg2) => + emitValDef(sym, quote(fun) + "(" + quote(arg) + ", " + quote(arg2) + ")") + + case _ => super.emitNode(sym, rhs) + } +} + +trait CGenUninlinedFunctions extends CGenEffect { + val IR: UninlinedFunctionsExp + import IR._ + + var emitEnabled: Boolean = false + + private def printState(si: () => Exp[Unit]) { + // Print state if si is set + if (si != null) { + val state = reifyEffects(si()) + emitBlock(state) + } + } + + private def argsToStr(e: List[Sym[Any]], argTypes: List[String]) = { + val z = e zip argTypes + z.map(x => { + if (quote(x._1) != "") x._2 + " " + quote(x._1) + else x._2 + " x" + x._1.toString.replace("Sym(","").replace(")","") + }).mkString(",") + } + + private def printUninlinedFuncBody[T:Manifest](b: Block[T]) = { + val sw = new StringWriter() + val pw = new PrintWriter(sw) + withStream(pw) { + emitBlock(b) + stream.println("return " + quote(getBlockResult(b)) + ";") + stream.println("}") + stream.println() + } + sw.toString + } + + private def getArgTypes(syms: List[Sym[Any]], args: String*) = { + val z = syms zip args.toList + z.map(x => if (x._2 != "") x._2 else remap(x._1.tp)) + } + + private def getReturnType(res: Sym[Any], dRet: String) = if (dRet != "") dRet else remap(res.tp) + + override def emitFileHeader() = { + emitEnabled = true + functionList0.foreach(func => traverseStm(findDefinition(func).get)) + functionList1.foreach(func => traverseStm(findDefinition(func).get)) + functionList2.foreach(func => traverseStm(findDefinition(func).get)) + emitEnabled = false + functionList0.clear + functionList1.clear + functionList2.clear + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case UninlinedFunc0(fun, res, dRet, si) => { + if (emitEnabled) { + val retType = getReturnType(res, dRet) + stream.println("object " + quote(sym) + + " extends (()=>" + retType +") {") + emitEnabled = false + printState(si) + // Now print function + stream.println("def apply(): " + retType + " = {") + printUninlinedFuncBody(reifyEffects(fun())) + emitEnabled = true + } + } + case UninlinedFunc1(fun, e, res, argType, dRet, si) => { + if (emitEnabled) { + val syms = List(e) + val argTypes = getArgTypes(syms, argType) + val retType = getReturnType(res, dRet) + emitEnabled = false + printState(si) + // Now print function + val argStr = argsToStr(syms, argTypes) + val header = retType + " " + quote(sym) + "(" + argStr + ") {\n" + var str = header + printUninlinedFuncBody(reifyEffects(fun(e))) + if (e.tp == manifest[Tuple2[Any,Any]]) { + str = str.replace(quote(e) + "._1", "key").replace(quote(e) + "._2", "value") + str = str.replace(argStr,"void* key, void* value") + } + stream.println(str) + emitEnabled = true + } + } + case UninlinedFunc2(fun, e1, e2, res, argType, argType2, dRet, si) => { + if (emitEnabled) { + val syms = List(e1,e2) + val argTypes = getArgTypes(syms,argType,argType2) + val retType = getReturnType(res, dRet) + emitEnabled = false + printState(si) + // Now print function + stream.println(retType + " " + quote(sym) + "(" + argsToStr(syms, argTypes) + ") {") + var str = printUninlinedFuncBody(reifyEffects(fun(e1,e2))) + // HACK -- STUPID GLIB! + if (argType.contains("**")) { + str = str.replace(quote(e1),"(*" + quote(e1) + ")") + str = str.replace(quote(e2),"(*" + quote(e2) + ")") + } + stream.println(str) + emitEnabled = true + } + } + case UninlinedFuncApply0(fun) => + emitValDef(sym, quote(fun) + "()") + case UninlinedFuncApply1(fun, arg) => + emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") + case UninlinedFuncApply2(fun, arg, arg2) => + emitValDef(sym, quote(fun) + "(" + quote(arg) + ", " + quote(arg2) + ")") + + case _ => super.emitNode(sym, rhs) + } +}*/ diff --git a/src/common/Variables.scala b/src/common/Variables.scala index 98ca5020..8c30dfec 100755 --- a/src/common/Variables.scala +++ b/src/common/Variables.scala @@ -1,9 +1,10 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.lms.util.OverloadHack +import scala.collection.mutable +import scala.virtualization.lms.util.OverloadHack import scala.reflect.SourceContext trait LiftVariables extends Base { @@ -53,7 +54,13 @@ trait Variables extends Base with OverloadHack with VariableImplicits with ReadV def var_plusequals[T:Manifest](lhs: Var[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Unit] def var_minusequals[T:Manifest](lhs: Var[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Unit] def var_timesequals[T:Manifest](lhs: Var[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Unit] + def var_divideequals[T:Manifest](lhs: Var[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Unit] + def var_tripleshift[T:Manifest](lhs: Var[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] + def var_doubleshift[T:Manifest](lhs: Var[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] + def var_leftshift[T:Manifest](lhs: Var[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] + def var_logicalOr[T:Manifest](lhs: Var[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] + def var_logicalAnd[T:Manifest](lhs: Var[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] def __assign[T:Manifest](lhs: Var[T], rhs: T)(implicit pos: SourceContext) = var_assign(lhs, unit(rhs)) def __assign[T](lhs: Var[T], rhs: Rep[T])(implicit o: Overloaded1, mT: Manifest[T], pos: SourceContext) = var_assign(lhs, rhs) @@ -76,6 +83,12 @@ trait Variables extends Base with OverloadHack with VariableImplicits with ReadV def infix_/=[T](lhs: Var[T], rhs: T)(implicit o: Overloaded1, mT: Manifest[T], pos: SourceContext) = var_divideequals(lhs, unit(rhs)) def infix_/=[T](lhs: Var[T], rhs: Rep[T])(implicit o: Overloaded2, mT: Manifest[T], pos: SourceContext) = var_divideequals(lhs,rhs) def infix_/=[T](lhs: Var[T], rhs: Var[T])(implicit o: Overloaded3, mT: Manifest[T], pos: SourceContext) = var_divideequals(lhs,readVar(rhs)) + def infix_>>>[T](lhs: Var[T], rhs: Rep[T])(implicit o: Overloaded3, mT: Manifest[T], pos: SourceContext) = var_tripleshift(lhs,rhs) + def infix_>>[T](lhs: Var[T], rhs: Rep[T])(implicit o: Overloaded3, mT: Manifest[T], pos: SourceContext) = var_doubleshift(lhs,rhs) + def infix_>>[T](lhs: Var[T], rhs: Var[T])(implicit o: Overloaded4, mT: Manifest[T], pos: SourceContext) = var_doubleshift(lhs,readVar(rhs)) + def infix_<<[T](lhs: Var[T], rhs: Rep[T])(implicit o: Overloaded3, mT: Manifest[T], pos: SourceContext) = var_leftshift(lhs,rhs) + def infix_|[T](lhs: Var[T], rhs: Var[T])(implicit o: Overloaded3, mT: Manifest[T], pos: SourceContext) = var_logicalOr(lhs,readVar(rhs)) + def infix_&[T](lhs: Var[T], rhs: Var[T])(implicit o: Overloaded3, mT: Manifest[T], pos: SourceContext) = var_logicalAnd(lhs,readVar(rhs)) } trait VariablesExp extends Variables with ImplicitOpsExp with VariableImplicits with ReadVarImplicitExp { @@ -95,6 +108,11 @@ trait VariablesExp extends Variables with ImplicitOpsExp with VariableImplicits case class VarMinusEquals[T:Manifest](lhs: Var[T], rhs: Exp[T]) extends Def[Unit] case class VarTimesEquals[T:Manifest](lhs: Var[T], rhs: Exp[T]) extends Def[Unit] case class VarDivideEquals[T:Manifest](lhs: Var[T], rhs: Exp[T]) extends Def[Unit] + case class VarDoubleShift[T:Manifest](lhs: Var[T], rhs: Exp[T]) extends Def[T] + case class VarTripleShift[T:Manifest](lhs: Var[T], rhs: Exp[T]) extends Def[T] + case class VarLeftShift[T:Manifest](lhs: Var[T], rhs: Exp[T]) extends Def[T] + case class VarLogicalOr[T:Manifest](lhs: Var[T], rhs: Exp[T]) extends Def[T] + case class VarLogicalAnd[T:Manifest](lhs: Var[T], rhs: Exp[T]) extends Def[T] def var_new[T:Manifest](init: Exp[T])(implicit pos: SourceContext): Var[T] = { //reflectEffect(NewVar(init)).asInstanceOf[Var[T]] @@ -125,6 +143,22 @@ trait VariablesExp extends Variables with ImplicitOpsExp with VariableImplicits reflectWrite(lhs.e)(VarDivideEquals(lhs, rhs)) Const() } + + def var_tripleshift[T:Manifest](lhs: Var[T], rhs: Exp[T])(implicit pos: SourceContext): Exp[T] = { + reflectEffect(VarTripleShift(lhs,rhs)) + } + def var_doubleshift[T:Manifest](lhs: Var[T], rhs: Exp[T])(implicit pos: SourceContext): Exp[T] = { + reflectEffect(VarDoubleShift(lhs,rhs)) + } + def var_leftshift[T:Manifest](lhs: Var[T], rhs: Exp[T])(implicit pos: SourceContext): Exp[T] = { + reflectEffect(VarLeftShift(lhs,rhs)) + } + def var_logicalOr[T:Manifest](lhs: Var[T], rhs: Exp[T])(implicit pos: SourceContext): Exp[T] = { + reflectEffect(VarLogicalOr(lhs,rhs)) + } + def var_logicalAnd[T:Manifest](lhs: Var[T], rhs: Exp[T])(implicit pos: SourceContext): Exp[T] = { + reflectEffect(VarLogicalAnd(lhs,rhs)) + } override def aliasSyms(e: Any): List[Sym[Any]] = e match { case NewVar(a) => Nil @@ -170,17 +204,38 @@ trait VariablesExp extends Variables with ImplicitOpsExp with VariableImplicits case _ => super.copySyms(e) } - + def findInitSymbol(s: Exp[_]): Exp[_] = { + println(s) + findDefinition(s.asInstanceOf[Sym[_]]).get match { + case TP(_, Reflect(v @ ReadVar(Variable(x)),_,_)) => findInitSymbol(x) + case TP(_, Reflect(NewVar(x),_,_)) => { + if (x.tp != manifest[Nothing]) findInitSymbol(x) + else { + var sym : Option[Exp[_]] = None + globalDefs.find { x => x match { + case TP(_,Reflect(Assign(Variable(v1),v2),_,_)) => { + if (v1 == s) {sym = Some(v2); true} + else false; + } + case _ => false + } } + if (sym != None) findInitSymbol(sym.get) + else throw new RuntimeException("findInitSymbol failed (1) during lookup in DynamicRecords while looking for " + sym + ".") + } + } + case TP(sym, _) => sym + case sy@_ => throw new RuntimeException("findInitSymbol failed (2) during lookup in DynamicRecords while looking for " + sy + ".") + } + } override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case ReadVar(Variable(a)) => readVar(Variable(f(a))) - case Reflect(NewVar(a), u, es) => reflectMirrored(Reflect(NewVar(f(a)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(ReadVar(Variable(a)), u, es) => reflectMirrored(Reflect(ReadVar(Variable(f(a))), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(Assign(Variable(a),b), u, es) => reflectMirrored(Reflect(Assign(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(VarPlusEquals(Variable(a),b), u, es) => reflectMirrored(Reflect(VarPlusEquals(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(VarMinusEquals(Variable(a),b), u, es) => reflectMirrored(Reflect(VarMinusEquals(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(VarTimesEquals(Variable(a),b), u, es) => reflectMirrored(Reflect(VarTimesEquals(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case Reflect(VarDivideEquals(Variable(a),b), u, es) => reflectMirrored(Reflect(VarDivideEquals(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(NewVar(a), u, es) => reflectMirrored(Reflect(NewVar(f(a)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(ReadVar(Variable(a)), u, es) => reflectMirrored(Reflect(ReadVar(Variable(f(a))), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(Assign(Variable(a),b), u, es) => reflectMirrored(Reflect(Assign(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(VarPlusEquals(Variable(a),b), u, es) => reflectMirrored(Reflect(VarPlusEquals(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(VarMinusEquals(Variable(a),b), u, es) => reflectMirrored(Reflect(VarMinusEquals(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(VarTimesEquals(Variable(a),b), u, es) => reflectMirrored(Reflect(VarTimesEquals(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(VarDivideEquals(Variable(a),b), u, es) => reflectMirrored(Reflect(VarDivideEquals(Variable(f(a)), f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] @@ -207,27 +262,8 @@ trait VariablesExpOpt extends VariablesExp { } } - // eliminate (some) redundant stores - // TODO: strong updates. overwriting a var makes previous stores unnecessary - - override implicit def var_assign[T:Manifest](v: Var[T], e: Exp[T])(implicit pos: SourceContext) : Exp[Unit] = { - if (context ne null) { - // find the last modification of variable v - // if it is an assigment with the same value, we don't need to do anything - val vs = v.e.asInstanceOf[Sym[Variable[T]]] - //TODO: could use calculateDependencies(Read(v)) - - context.reverse.foreach { - case w @ Def(Reflect(NewVar(rhs: Exp[T]), _, _)) if w == vs => if (rhs == e) return () - case Def(Reflect(Assign(`v`, rhs: Exp[T]), _, _)) => if (rhs == e) return () - case Def(Reflect(_, u, _)) if mayWrite(u, List(vs)) => // not a simple assignment - case _ => // ... - } - } - super.var_assign(v,e) - } - - + // TODO: could eliminate redundant stores, too + // by overriding assign ... } @@ -237,27 +273,40 @@ trait ScalaGenVariables extends ScalaGenEffect { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case ReadVar(Variable(a)) => emitValDef(sym, quote(a)) - case NewVar(init) => emitVarDef(sym.asInstanceOf[Sym[Variable[Any]]], quote(init)) - case Assign(Variable(a), b) => emitAssignment(a.asInstanceOf[Sym[Variable[Any]]],quote(b)) - case VarPlusEquals(Variable(a), b) => emitValDef(sym, quote(a) + " += " + quote(b)) - case VarMinusEquals(Variable(a), b) => emitValDef(sym, quote(a) + " -= " + quote(b)) - case VarTimesEquals(Variable(a), b) => emitValDef(sym, quote(a) + " *= " + quote(b)) - case VarDivideEquals(Variable(a), b) => emitValDef(sym, quote(a) + " /= " + quote(b)) - case _ => super.emitNode(sym, rhs) - } - -/* - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ReadVar(Variable(a)) => emitValDef(sym, quote(a)) - case NewVar(init) => emitVarDef(sym.asInstanceOf[Sym[Variable[Any]]], quote(init)) - case Assign(Variable(a), b) => emitValDef(sym, quote(a) + " = " + quote(b)) - case VarPlusEquals(Variable(a), b) => emitValDef(sym, quote(a) + " += " + quote(b)) - case VarMinusEquals(Variable(a), b) => emitValDef(sym, quote(a) + " -= " + quote(b)) - case VarTimesEquals(Variable(a), b) => emitValDef(sym, quote(a) + " *= " + quote(b)) - case VarDivideEquals(Variable(a), b) => emitValDef(sym, quote(a) + " /= " + quote(b)) + case y@NewVar(init) => { + if (sym.emitted == false && sym.tp != manifest[Variable[Nothing]] && sym.tp != manifest[Variable[Null]]) { + val obj = sym.asInstanceOf[Sym[Variable[Any]]] + emitVarDef(obj, quote(init)) + sym.emitted = true; + } + } + case ReadVar(null) => {} // emitVarDef(sym.asInstanceOf[Sym[Variable[Any]]], "null") + case Assign(v @ Variable(a), b) => { + val lhsIsNull = a match { + case Def(Reflect(NewVar(y: Exp[_]),_,_)) => + if (y.tp == manifest[Nothing]) true + else false + case y@_ => false + } + val obj = a.asInstanceOf[Sym[Variable[Any]]] + if (!obj.emitted) { + stream.println("var " + quote(obj) + ": " + remap(b.tp) + " = " + quote(b)) + obj.emitted = true + } + else emitAssignment(sym, quote(a), quote(b)) + } + //case Assign(a, b) => emitAssignment(quote(a), quote(b)) + case VarPlusEquals(Variable(a), b) => stream.println(quote(a) + " += " + quote(b)) + case VarMinusEquals(Variable(a), b) => stream.println(quote(a) + " -= " + quote(b)) + case VarTimesEquals(Variable(a), b) => stream.println(quote(a) + " *= " + quote(b)) + case VarDivideEquals(Variable(a), b) => stream.println(quote(a) + " /= " + quote(b)) + case VarTripleShift(Variable(a),b) => emitValDef(sym,quote(a) + ">>>" + quote(b)) + case VarDoubleShift(Variable(a),b) => emitValDef(sym,quote(a) + ">>" + quote(b)) + case VarLeftShift(Variable(a),b) => emitValDef(sym,quote(a) + "<<" + quote(b)) + case VarLogicalOr(Variable(a),b) => emitValDef(sym,quote(a) + "|" + quote(b)) + case VarLogicalAnd(Variable(a),b) => emitValDef(sym,quote(a) + "&" + quote(b)) case _ => super.emitNode(sym, rhs) } -*/ } trait CLikeGenVariables extends CLikeGenBase { @@ -266,13 +315,21 @@ trait CLikeGenVariables extends CLikeGenBase { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { - case ReadVar(Variable(a)) => emitValDef(sym, quote(a)) - case NewVar(init) => emitVarDef(sym.asInstanceOf[Sym[Variable[Any]]], quote(init)) - case Assign(Variable(a), b) => stream.println(quote(a) + " = " + quote(b) + ";") - case VarPlusEquals(Variable(a), b) => stream.println(quote(a) + " += " + quote(b) + ";") - case VarMinusEquals(Variable(a), b) =>stream.println(quote(a) + " -= " + quote(b) + ";") - case VarTimesEquals(Variable(a), b) => stream.println(quote(a) + " *= " + quote(b) + ";") - case VarDivideEquals(Variable(a), b) => stream.println(quote(a) + " /= " + quote(b) + ";") + case ReadVar(Variable(a)) => + stream.println(remap(sym.tp) + " " + quote(sym) + " = " + quote(a) + ";") + case ReadVar(null) => {} // emitVarDef(sym.asInstanceOf[Sym[Variable[Any]]], "null") + case NewVar(init) => + emitVarDef(sym.asInstanceOf[Sym[Variable[Any]]], quote(init)) + case Assign(Variable(a), b) => + emitAssignment(sym, quote(a), quote(b)) + case VarPlusEquals(Variable(a), b) => + emitAssignment(sym, quote(a), quote(a) + " + " + quote(b)) + case VarMinusEquals(Variable(a), b) => + emitAssignment(sym, quote(a), quote(a) + " - " + quote(b)) + case VarTimesEquals(Variable(a), b) => + emitAssignment(sym, quote(a), quote(a) + " * " + quote(b)) + case VarDivideEquals(Variable(a), b) => + emitAssignment(sym, quote(a), quote(a) + " / " + quote(b)) case _ => super.emitNode(sym, rhs) } } diff --git a/src/common/While.scala b/src/common/While.scala index daf0c82b..e4089346 100644 --- a/src/common/While.scala +++ b/src/common/While.scala @@ -1,17 +1,20 @@ -package scala.lms +package scala.virtualization.lms package common import java.io.PrintWriter -import scala.lms.internal.GenericNestedCodegen +import scala.virtualization.lms.internal.GenericNestedCodegen +import scala.virtualization.lms.internal.CNestedCodegen import scala.reflect.SourceContext trait While extends Base { def __whileDo(cond: => Rep[Boolean], body: => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] + def __doWhile(body: => Rep[Unit], cond: => Rep[Boolean])(implicit pos: SourceContext): Rep[Unit] } trait WhileExp extends While with EffectExp { case class While(cond: Block[Boolean], body: Block[Unit]) extends Def[Unit] + case class DoWhile(body: Block[Unit], cond: Block[Boolean]) extends Def[Unit] override def __whileDo(cond: => Exp[Boolean], body: => Rep[Unit])(implicit pos: SourceContext) = { val c = reifyEffects(cond) @@ -21,26 +24,52 @@ trait WhileExp extends While with EffectExp { reflectEffect(While(c, a), ce andThen ((ae andThen ce).star)) } + override def __doWhile(body: => Rep[Unit], cond: => Rep[Boolean])(implicit pos: SourceContext) = { + val a = reifyEffects(body) + val c = reifyEffects(cond) + val ae = summarizeEffects(a) + val ce = summarizeEffects(c) + reflectEffect(DoWhile(a, c), ae andThen ((ce andThen ae).star)) + } + override def syms(e: Any): List[Sym[Any]] = e match { case While(c, b) => syms(c):::syms(b) // wouldn't need to override... + case DoWhile(b, c) => syms(b):::syms(c) // wouldn't need to override... case _ => super.syms(e) } override def boundSyms(e: Any): List[Sym[Any]] = e match { case While(c, b) => effectSyms(c):::effectSyms(b) + case DoWhile(b, c) => effectSyms(b):::effectSyms(c) case _ => super.boundSyms(e) } override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { case While(c, b) => freqHot(c):::freqHot(b) + case DoWhile(b, c) => freqHot(b):::freqHot(c) case _ => super.symsFreq(e) } } +trait WhileExpOpt extends WhileExp { this: IfThenElseExp => -trait WhileExpOptSpeculative extends WhileExp with PreviousIterationDummyExp { + /** Optimization technique(s): + * - inversion : This technique changes a standard while loop into a do/while (a.k.a. repeat/until) + * loop wrapped in an if conditional, reducing the number of jumps by two for cases + * where the loop is executed. Doing so duplicates the condition check (increasing the + * size of the code) but is more efficient because jumps usually cause a pipeline stall. + * Additionally, if the initial condition is known at compile-time and is known to be + * side-effect-free, the if guard can be skipped. + */ + override def __whileDo(cond: => Exp[Boolean], body: => Rep[Unit])(implicit pos: SourceContext) = { + __ifThenElse(cond, __doWhile(body, cond), ()) + } + +} + +trait WhileExpOptSpeculative extends WhileExpOpt with PreviousIterationDummyExp { this: IfThenElseExp => override def __whileDo(cond: => Exp[Boolean], body: => Rep[Unit])(implicit pos: SourceContext) = { @@ -91,14 +120,42 @@ trait ScalaGenWhile extends ScalaGenEffect with BaseGenWhile { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case While(c,b) => - stream.print("val " + quote(sym) + " = while ({") +//<<<<<<< HEAD + emitValDef(sym, "while ({") emitBlock(c) - stream.print(quote(getBlockResult(c))) + stream.println(quote(getBlockResult(c))) stream.println("}) {") emitBlock(b) stream.println(quote(getBlockResult(b))) stream.println("}") - +/*======= + //while-do's output is unit, so why do we need to assign its result to a val + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + stream.print("while ({") + emitBlock(c) + stream.print(quote(getBlockResult(c))) + stream.println("}) {") + emitBlock(b) + stream.println(quote(getBlockResult(b))) + stream.print("}") + } + emitValDef(sym, strWriter.toString)*/ + case DoWhile(b,c) => + //do-while's output is unit, so why do we need to assign its result to a val + val strWriter = new java.io.StringWriter + val localStream = new PrintWriter(strWriter); + withStream(localStream) { + stream.print("do {") + emitBlock(b) + stream.println(quote(getBlockResult(b))) + stream.println("} while ({") + emitBlock(c) + stream.print(quote(getBlockResult(c))) + stream.print("})") + } + emitValDef(sym, strWriter.toString) case _ => super.emitNode(sym, rhs) } } @@ -119,6 +176,15 @@ trait CLikeGenWhile extends CLikeGenBase with BaseGenWhile { stream.println("if (!"+quote(getBlockResult(c))+") break;") emitBlock(b) stream.println("}") + case DoWhile(b, c) => + stream.println("{") + emitBlock(b) + stream.println("}") + stream.println("for (;;) {") + emitBlock(c) + stream.println("if (!"+quote(getBlockResult(c))+") break;") + emitBlock(b) + stream.println("}") case _ => super.emitNode(sym, rhs) } } @@ -128,4 +194,24 @@ trait CudaGenWhile extends CudaGenEffect with CLikeGenWhile trait OpenCLGenWhile extends OpenCLGenEffect with CLikeGenWhile -trait CGenWhile extends CGenEffect with CLikeGenWhile +trait CGenWhile extends CGenEffect with CLikeGenWhile { + val IR: WhileExp + import IR._ + + override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { + case While(cond,b) => { + LIRTraversal(cond) + LIRTraversal(b) + sym.atPhase(LIRLowering) { + val tc = LIRLowering(cond) + val ce = summarizeEffects(tc) + val tb = LIRLowering(b) + val ae = summarizeEffects(tb) + reflectEffect(While(tc, tb), ce andThen ((ae andThen ce).star)).asInstanceOf[Exp[T]] + } + } + case DoWhile(b,c) => + sym.atPhase(LIRLowering) { reflectEffect(DoWhile(runTransformations(b),c)).asInstanceOf[Exp[T]] } + case _ => super.lowerNode(sym, rhs) + } +} diff --git a/src/internal/AccModel.scala b/src/internal/AccModel.scala deleted file mode 100644 index 0a810e30..00000000 --- a/src/internal/AccModel.scala +++ /dev/null @@ -1,62 +0,0 @@ -package scala.lms.internal - -trait AbstractHostTransfer { - this: GenericCodegen => - - val IR: Expressions - import IR._ - - def emitSend(tp: Manifest[_], peer: Targets.Value): (String,String) - def emitRecv(tp: Manifest[_], peer: Targets.Value): (String,String) - def emitSendView(tp: Manifest[_], peer: Targets.Value): (String,String) - def emitRecvView(tp: Manifest[_], peer: Targets.Value): (String,String) - def emitSendUpdate(tp: Manifest[_], peer: Targets.Value): (String,String) - def emitRecvUpdate(tp: Manifest[_], peer: Targets.Value): (String,String) -} - -trait AbstractDeviceTransfer { - this: GenericCodegen => - - val IR: Expressions - import IR._ - - def emitSendSlave(tp: Manifest[_]) : (String,String) - def emitRecvSlave(tp: Manifest[_]) : (String,String) - //def emitSendViewSlave(tp: Manifest[_]) : (String,String) - //def emitRecvViewSlave(tp: Manifest[_]) : (String,String) - def emitSendUpdateSlave(tp: Manifest[_]) : (String,String) - def emitRecvUpdateSlave(tp: Manifest[_]) : (String,String) - - //def allocOutput(newSym: Sym[_], sym: Sym[_], reset: Boolean = false) : Unit -} - -object Targets extends Enumeration { - - //TODO: Get rid of JVM target, or make an hierarchy - val JVM = Value("jvm") - val Scala = Value("scala") - val Cpp = Value("cpp") - val Cuda = Value("cuda") - val OpenCL = Value("opencl") - - def apply(s: String): Value = s.toLowerCase() match { - case "jvm" => JVM - case "scala" => Scala - case "cpp" => Cpp - case "cuda" => Cuda - case "opencl" => OpenCL - case _ => throw new IllegalArgumentException("unsupported target: " + s) - } - - def getHostTarget(target: Value): Targets.Value = { - target match { - case Targets.Scala => Targets.Scala - case Targets.Cpp => Targets.Cpp - case Targets.Cuda => Targets.Cpp - case Targets.OpenCL => Targets.Cpp - case _ => throw new IllegalArgumentException("Cannot find a host target for target " + target) - } - } - - implicit def targettostring(target: Targets.Value): String = target.toString -} diff --git a/src/internal/BlockTraversal.scala b/src/internal/BlockTraversal.scala index 960e4b85..dcf3b651 100644 --- a/src/internal/BlockTraversal.scala +++ b/src/internal/BlockTraversal.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal import util.GraphUtil @@ -130,4 +130,3 @@ trait NestedBlockTraversal extends BlockTraversal with NestedGraphTraversal { super.reset } } - diff --git a/src/internal/CCodegen.scala b/src/internal/CCodegen.scala index e4811664..6380b96a 100644 --- a/src/internal/CCodegen.scala +++ b/src/internal/CCodegen.scala @@ -1,223 +1,443 @@ -package scala.lms +package scala.virtualization.lms package internal -import java.io.{FileWriter, PrintWriter, File} +import scala.virtualization.lms.common.{Base,BaseExp} +import java.io.{FileWriter, StringWriter, PrintWriter, File} +import java.util.ArrayList +import collection.mutable.{ListBuffer, ArrayBuffer, LinkedList, HashMap, ListMap, HashSet, Map => MMap} import collection.immutable.List._ -import collection.mutable.ArrayBuffer -trait CCodegen extends CLikeCodegen with CppHostTransfer { +trait CCodegen extends CLikeCodegen { val IR: Expressions import IR._ - override def deviceTarget: Targets.Value = Targets.Cpp - override def kernelFileExt = "cpp" - override def toString = "cpp" - - val helperFuncList = ArrayBuffer[String]() - - var kernelInputVals: List[Sym[Any]] = Nil - var kernelInputVars: List[Sym[Any]] = Nil - var kernelOutputs: List[Sym[Any]] = Nil - - override def remap[A](m: Manifest[A]) : String = { - m.toString match { - case "java.lang.String" => "string" - case _ => super.remap(m) - } + override def toString = "c" + + var compileCount = 0 + var helperFuncIdx = 0 + var helperFuncString:StringBuilder = null + var hstream: PrintWriter = null + var headerStream: PrintWriter = null + var kernelsList = ListBuffer[Exp[Any]]() + + override def hasMetaData: Boolean = true + override def getMetaData: String = metaData.toString + var metaData: CMetaData = null + + final class TransferFunc { + var funcHtoD:String = _ + var argsFuncHtoD:List[Sym[Any]] = _ + var funcDtoH:String = _ + var argsFuncDtoH:List[Sym[Any]] = _ } - - // we treat string as a primitive type to prevent memory management on strings - // strings are always stack allocated and freed automatically at the scope exit - override def isPrimitiveType(tpe: String) : Boolean = { - tpe match { - case "string" => true - case _ => super.isPrimitiveType(tpe) + final class CMetaData { + val inputs: ListMap[Sym[Any],TransferFunc] = ListMap() + val outputs: ListMap[Sym[Any],TransferFunc] = ListMap() + //val temps: ListMap[Sym[Any],TransferFunc] = ListMap() + //val sizeFuncs: ListMap[String,SizeFunc] = ListMap() + //var gpuLibCall: String = "" + override def toString: String = { + val out = new StringBuilder + out.append("{") + + out.append("\"cppInputs\":["+inputs.toList.reverse.map(in=>"{\""+quote(in._1)+"\":[\""+remap(in._1.tp)+"\",\""+in._2.funcHtoD+"\",\""+in._2.funcDtoH+"\"]}").mkString(",")+"],") + out.append("\"cppOutputs\":["+outputs.toList.reverse.map(out=>"{\""+quote(out._1)+"\":[\""+remap(out._1.tp)+"\",\""+out._2.funcDtoH+"\"]}").mkString(",")+"]") + out.append("}") + out.toString } } - - override def quote(x: Exp[Any]) = x match { - case Const(s: String) => "string(" + super.quote(x) + ")" - case _ => super.quote(x) - } - override def isPrimitiveType[A](m: Manifest[A]) : Boolean = isPrimitiveType(remap(m)) - - override def emitValDef(sym: Sym[Any], rhs: String): Unit = { - if (!isVoidType(sym.tp)) - stream.println(remapWithRef(sym.tp) + quote(sym) + " = " + rhs + ";") - else // we might still want the RHS for its effects - stream.println(rhs + ";") + def initCompile = { + val className = "staged" + compileCount + compileCount = compileCount + 1 + className } - override def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = { - stream.println(remapWithRef(sym.tp.typeArguments.head) + quote(sym) + " = " + rhs + ";") + override def kernelInit(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultIsVar: Boolean): Unit = { + // Set kernel input and output symbols + //setKernelInputs(vals) + //setKernelOutputs(syms) + + /* + // Conditions for not generating GPU kernels (may be relaxed later) + for (sym <- syms) { + if((!isObjectType(sym.tp)) && (remap(sym.tp)!="void")) throw new GenerationFailedException("GPUGen: Not GPUable output type : %s".format(remap(sym.tp))) + } + if((vars.length > 0) || (resultIsVar)) throw new GenerationFailedException("GPUGen: Not GPUable input/output types: Variable") +*/ + helperFuncString.clear + metaData = new CMetaData } - override def emitVarDecl(sym: Sym[Any]): Unit = { - stream.println(remapWithRef(sym.tp) + " " + quote(sym) + ";") + override def initializeGenerator(buildDir:String, args: Array[String], _analysisResults: MMap[String,Any]): Unit = { + val outDir = new File(buildDir) + outDir.mkdirs + helperFuncIdx = 0 + helperFuncString = new StringBuilder + hstream = new PrintWriter(new FileWriter(buildDir + "helperFuncs.cpp")) + headerStream = new PrintWriter(new FileWriter(buildDir + "dsl.hpp")) + headerStream.println("#include \"helperFuncs.cpp\"") + + /* + //TODO: Put all the DELITE APIs declarations somewhere + hstream.print(getDSLHeaders) + hstream.print("#include \n") + hstream.print("#include \n") + hstream.print("#include \n\n") + hstream.print("//Delite Runtime APIs\n") + hstream.print("extern void DeliteCudaMallocHost(void **ptr, size_t size);\n") + hstream.print("extern void DeliteCudaMalloc(void **ptr, size_t size);\n") + hstream.print("extern void DeliteCudaMemcpyHtoDAsync(void *dptr, void *sptr, size_t size);\n") + hstream.print("extern void DeliteCudaMemcpyDtoHAsync(void *dptr, void *sptr, size_t size);\n") + hstream.print("typedef jboolean jbool;\n") // TODO: Fix this + hstream.print("typedef jbooleanArray jboolArray;\n\n") // TODO: Fix this + */ + + super.initializeGenerator(buildDir, args, _analysisResults) } - override def emitAssignment(sym: Sym[Any], rhs: String): Unit = { - stream.println(quote(sym) + " = " + rhs + ";") + def copyInputHtoD(sym: Sym[Any]) : String = { + remap(sym.tp) match { + case _ => throw new GenerationFailedException("CGen: copyInputHtoD(sym) : Cannot copy to GPU device (%s)".format(remap(sym.tp))) + } } - override def kernelInit(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultIsVar: Boolean): Unit = { - kernelInputVals = vals - kernelInputVars = vars - kernelOutputs = syms + def copyOutputDtoH(sym: Sym[Any]) : String = { + remap(sym.tp) match { + case _ => throw new GenerationFailedException("CGen: copyOutputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) + } } - override def initializeGenerator(buildDir:String, args: Array[String]): Unit = { - val outDir = new File(buildDir) - outDir.mkdirs - - /* file for helper functions (transfer function, allocation function) */ - helperFuncStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.cpp")) - helperFuncStream.println("#include ") - helperFuncStream.println("#include \"" + deviceTarget + "helperFuncs.h\"") - - /* type aliases */ - typesStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "types.h")) - - /* header file for kernels and helper functions */ - headerStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.h")) - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include \"" + deviceTarget + "types.h\"") - headerStream.println(getDataStructureHeaders()) - - super.initializeGenerator(buildDir, args) + def copyMutableInputDtoH(sym: Sym[Any]) : String = { + remap(sym.tp) match { + case _ => throw new GenerationFailedException("CGen: copyMutableInputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) + } } def emitForwardDef[A:Manifest](args: List[Manifest[_]], functionName: String, out: PrintWriter) = { out.println(remap(manifest[A])+" "+functionName+"("+args.map(a => remap(a)).mkString(", ")+");") } - - def emitSource[A:Manifest](args: List[Sym[_]], body: Block[A], functionName: String, out: PrintWriter) = { - val sA = remap(manifest[A]) + def allocStruct(sym: Sym[Any], structName: String, out: PrintWriter) { + out.println(structName + " " + quote(sym)+ ";") + //out.println(structName + "* " + quote(sym) + " = (" + structName + "*)malloc(sizeof(" + structName + "));") + } + + def getMemoryAllocString(count: String, memType: String): String = { + "(" + memType + "*)malloc(" + count + " * sizeof(" + memType + "));" + } + def emitSource[A:Manifest](args: List[Sym[_]], b: Block[A], functionName: String, out: PrintWriter, dynamicReturnType: String = null, serializable: Boolean = false) = { + val body = runTransformations(b) + val sA = if (dynamicReturnType != null) dynamicReturnType else remap(getBlockResult(body).tp) withStream(out) { stream.println("/*****************************************\n"+ " Emitting C Generated Code \n"+ "*******************************************/\n" + "#include \n" + "#include \n" + - "#include \n" + - "#include " - ) + "#include \n" + + "#include ") + stream.println("int tpch_strcmp(const char *s1, const char *s2);") - // TODO: static data - - //stream.println("class "+className+(if (staticData.isEmpty) "" else "("+staticData.map(p=>"p"+quote(p._1)+":"+p._1.tp).mkString(",")+")")+" - //extends (("+args.map(a => remap(a.tp)).mkString(", ")+")=>("+sA+")) {") + stream.println("int timeval_subtract(struct timeval *result, struct timeval *t2, struct timeval *t1) {\n" + + "\tlong int diff = (t2->tv_usec + 1000000 * t2->tv_sec) - (t1->tv_usec + 1000000 * t1->tv_sec);\n" + + "\tresult->tv_sec = diff / 1000000;\n" + + "\tresult->tv_usec = diff % 1000000;\n" + + "\treturn (diff<0);\n" + + "}\n") - stream.println(sA+" "+functionName+"("+args.map(a => remapWithRef(a.tp)+" "+quote(a)).mkString(", ")+") {") - - emitBlock(body) - - val y = getBlockResult(body) + // TODO: static data + val sw = new StringWriter() + val tempWriter = new PrintWriter(sw) + tempWriter.println(sA+" "+functionName+"("+args.map(a => remap(a.tp)+" "+quote(a)).mkString(", ")+") {") + withStream(tempWriter) { emitBlock(body) } + val y = getBlockResult(body) if (remap(y.tp) != "void") - stream.println("return " + quote(y) + ";") - - stream.println("}") + tempWriter.println("return " + quote(y) + ";") + tempWriter.println("}") + + var code = sw.toString + sw.getBuffer().setLength(0) + withStream(tempWriter) { emitFileHeader() } + code = sw.toString + code + + stream.println("/********************* DATA STRUCTURES ***********************/") + emitDataStructures(stream) + stream.println("") + stream.println("/************************ FUNCTIONS **************************/") + sw.getBuffer().setLength(0) + withStream(tempWriter) { emitFunctions() } + val funs = sw.toString + printIndented(funs)(stream) + stream.println("") + stream.println("/************************ MAIN BODY **************************/") + //stream.println(code) + printIndented(code)(stream) stream.println("/*****************************************\n"+ - " End of C Generated Code \n"+ - "*******************************************/") + " * End of C Generated Code *\n"+ + " *****************************************/") } Nil - } - - override def emitTransferFunctions() { - - for ((tp,name) <- dsTypesList) { - try { - // Emit input copy helper functions for object type inputs - //TODO: For now just iterate over all possible hosts, but later we can pick one depending on the input target - val (recvHeader, recvSource) = emitRecv(tp, Targets.JVM) - if (!helperFuncList.contains(recvHeader)) { - headerStream.println(recvHeader) - helperFuncStream.println(recvSource) - helperFuncList.append(recvHeader) - } - val (recvViewHeader, recvViewSource) = emitRecvView(tp, Targets.JVM) - if (!helperFuncList.contains(recvViewHeader)) { - headerStream.println(recvViewHeader) - helperFuncStream.println(recvViewSource) - helperFuncList.append(recvViewHeader) - } - val (sendUpdateHeader, sendUpdateSource) = emitSendUpdate(tp, Targets.JVM) - if (!helperFuncList.contains(sendUpdateHeader)) { - headerStream.println(sendUpdateHeader) - helperFuncStream.println(sendUpdateSource) - helperFuncList.append(sendUpdateHeader) - } - val (recvUpdateHeader, recvUpdateSource) = emitRecvUpdate(tp, Targets.JVM) - if (!helperFuncList.contains(recvUpdateHeader)) { - headerStream.println(recvUpdateHeader) - helperFuncStream.println(recvUpdateSource) - helperFuncList.append(recvUpdateHeader) - } + } - // Emit output copy helper functions for object type inputs - val (sendHeader, sendSource) = emitSend(tp, Targets.JVM) - if (!helperFuncList.contains(sendHeader)) { - headerStream.println(sendHeader) - helperFuncStream.println(sendSource) - helperFuncList.append(sendHeader) + def printIndented(str: String)(out: PrintWriter): Unit = { + val lines = str.split("[\n\r]") + var indent = 0 + for (l0 <- lines) { + val l = l0.trim + if (l.length > 0) { + var open = 0 + var close = 0 + var initClose = 0 + var nonWsChar = false + l foreach { + case '{' /*| '(' | '['*/ => { + open += 1 + if (!nonWsChar) { + nonWsChar = true + initClose = close + } + } + case '}' /*| ')' | ']'*/ => close += 1 + case x => if (!nonWsChar && !x.isWhitespace) { + nonWsChar = true + initClose = close + } } - val (sendViewHeader, sendViewSource) = emitSendView(tp, Targets.JVM) - if (!helperFuncList.contains(sendViewHeader)) { - headerStream.println(sendViewHeader) - helperFuncStream.println(sendViewSource) - helperFuncList.append(sendViewHeader) - } - } - catch { - case e: GenerationFailedException => - helperFuncStream.flush - headerStream.flush - case e: Exception => throw(e) + if (!nonWsChar) initClose = close + out.println(" " * (indent - initClose) + l) + indent += (open - close) } } + } - helperFuncStream.flush - headerStream.flush - typesStream.flush + + +/* + //TODO: is sym of type Any or Variable[Any] ? + def emitConstDef(sym: Sym[Any], rhs: String): Unit = { + stream.print("const ") + emitVarDef(sym, rhs) + } +*/ + def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = { + // TODO: check void type? + stream.println(remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") } - def kernelName = "kernel_" + kernelOutputs.map(quote).mkString("") + def emitValDef(sym: Sym[Any], rhs: String): Unit = { + if (remap(sym.tp) == "void") + stream.println(rhs + "; // " + quote(sym, true)) + else + stream.println(remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") + } - override def emitKernelHeader(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { - super.emitKernelHeader(syms, vals, vars, resultType, resultIsVar, external) + def emitAssignment(sym: Sym[Any], lhs:String, rhs: String): Unit = { + // TODO: check void type? + stream.println(lhs + " = " + rhs + ";") } override def emitKernelFooter(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { - super.emitKernelFooter(syms, vals, vars, resultType, resultIsVar, external) + + //Currently only allow single return value + if(syms.size > 1) throw new GenerationFailedException("CLikeGen: Cannot have more than 1 results!\n"); + if(external) throw new GenerationFailedException("CLikeGen: Cannot have external libraries\n") + + if(resultType != "void") + stream.println("return " + quote(syms(0)) + ";") + stream.println("}") + + // Emit input copy helper functions for object type inputs + for(v <- (vals++vars) if isObjectType(v.tp)) { + helperFuncString.append(emitCopyInputHtoD(v, syms, copyInputHtoD(v))) + helperFuncString.append(emitCopyMutableInputDtoH(v, syms, copyMutableInputDtoH(v))) + } + + // Emit output copy helper functions for object type inputs + for(v <- (syms) if isObjectType(v.tp)) { + helperFuncString.append(emitCopyOutputDtoH(v, syms, copyOutputDtoH(v))) + } + + // Print helper functions to file stream + hstream.print(helperFuncString) + hstream.flush + + // Print out dsl.h file + if(kernelsList.intersect(syms).isEmpty) { + headerStream.println("#include \"%s.cpp\"".format(syms.map(quote).mkString(""))) + kernelsList ++= syms + } + headerStream.flush + + /* + // Print out device function + devStream.println(devFuncString) + devStream.flush + */ + } + + override def emitKernelHeader(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { + if(syms.size>1) throw new GenerationFailedException("CGen: Cannot have multiple kernel outputs!\n") + + //if( (vars.length>0) || (resultIsVar) ) throw new GenerationFailedException("Var is not supported for CPP kernels") + + val kernelName = syms.map(quote).mkString("") + + /* + if (resultIsVar){ + stream.print("PrimitiveRef<" + resultType + ">") + } + else { + stream.print(resultType) + } + */ + stream.print(resultType) + + stream.print(" kernel_" + kernelName + "(") + stream.print(vals.map(p=>remap(p.tp) + " " + quote(p)).mkString(", ")) + if (vals.length > 0 && vars.length > 0){ + stream.print(", ") + } + if (vars.length > 0){ + stream.print(vars.map(v => remap(v.tp) + " &" + quote(v)).mkString(",")) + } + + stream.println(") {") + } + + override def quote(x: Exp[Any]) : String = { + x match { + case Const(y: java.lang.Character) => + if (y == '\0') "'\\0'" + else "'" + y.toString + "'" + case Const(null) => "NULL" + case Const(()) => ";" + case _ => super.quote(x) + } + } + + override def remap[A](m: Manifest[A]) = { + m match { + case s if m == manifest[Int] => "int" + case s if m == manifest[Double] => "double" + case s if m == manifest[Long] => "long" + case s if m == manifest[Character] => "char" + case s if m == manifest[Byte] => "char" + case s if m == manifest[Boolean] => "bool" + case s if m == manifest[String] => "char*" + case s if m == manifest[Float] => "float" + case s if m == manifest[Unit] => "void" + case s if m == manifest[java.util.Date] => "long" + case _ => super.remap(m) + } } + /******************************************************* + * Methods below are for emitting helper functions + *******************************************************/ + // Yannis: Should these things be here? They do not seem to be general C, but + // rather CUDA like programming. + def emitCopyInputHtoD(sym: Sym[Any], ksym: List[Sym[Any]], contents: String) : String = { + val out = new StringBuilder + if(isObjectType(sym.tp)) { + helperFuncIdx += 1 + out.append("%s copyInputHtoD_%s_%s_%s(%s) {\n".format(remap(sym.tp), ksym.map(quote).mkString(""), quote(sym),helperFuncIdx, "JNIEnv *env , jobject obj")) + out.append(copyInputHtoD(sym)) + out.append("}\n") + val tr = metaData.inputs.getOrElse(sym,new TransferFunc) + tr.funcHtoD = "copyInputHtoD_%s_%s_%s".format(ksym.map(quote).mkString(""),quote(sym),helperFuncIdx) + metaData.inputs.put(sym,tr) + out.toString + } + else { + val tr = metaData.inputs.getOrElse(sym,new TransferFunc) + tr.funcHtoD = "copyInputHtoD_dummy".format(ksym.map(quote).mkString(""),quote(sym),helperFuncIdx) + metaData.inputs.put(sym,tr) + "" + } + } + + // For mutable inputs, copy the mutated datastructure from GPU to CPU after the kernel is terminated + def emitCopyMutableInputDtoH(sym: Sym[Any], ksym: List[Sym[Any]], contents: String): String = { + val out = new StringBuilder + if(isObjectType(sym.tp)) { + helperFuncIdx += 1 + out.append("void copyMutableInputDtoH_%s_%s_%s(%s) {\n".format(ksym.map(quote).mkString(""), quote(sym), helperFuncIdx, "JNIEnv *env , jobject obj, "+remap(sym.tp)+" *"+quote(sym)+"_ptr")) + out.append("%s %s = *(%s_ptr);\n".format(remap(sym.tp),quote(sym),quote(sym))) + out.append(copyMutableInputDtoH(sym)) + out.append("}\n") + val tr = metaData.inputs.getOrElse(sym,new TransferFunc) + tr.funcDtoH = "copyMutableInputDtoH_%s_%s_%s".format(ksym.map(quote).mkString(""),quote(sym),helperFuncIdx) + metaData.inputs.put(sym,tr) + out.toString + } + else { + val tr = metaData.inputs.getOrElse(sym,new TransferFunc) + tr.funcDtoH = "copyMutableInputDtoH_%s_%s_%s".format(ksym.map(quote).mkString(""),quote(sym),helperFuncIdx) + metaData.inputs.put(sym,tr) + "" + } + } + + def emitCopyOutputDtoH(sym: Sym[Any], ksym: List[Sym[Any]], contents: String): String = { + val out = new StringBuilder + if(isObjectType(sym.tp)) { + helperFuncIdx += 1 + out.append("jobject copyOutputDtoH_%s(JNIEnv *env,%s) {\n".format(helperFuncIdx,remap(sym.tp)+" *"+quote(sym)+"_ptr")) + out.append("\t%s %s = *(%s_ptr);\n".format(remap(sym.tp),quote(sym),quote(sym))) + out.append(copyOutputDtoH(sym)) + out.append("}\n") + val tr = metaData.outputs.getOrElse(sym,new TransferFunc) + tr.funcDtoH = "copyOutputDtoH_%s".format(helperFuncIdx) + metaData.outputs.put(sym,tr) + out.toString + } + else { + val tr = metaData.outputs.getOrElse(sym,new TransferFunc) + tr.funcDtoH = "copyOutputDtoH_%s".format(helperFuncIdx) + metaData.outputs.put(sym,tr) + "" + } + } + + + } -trait CNestedCodegen extends CLikeNestedCodegen with CCodegen { - val IR: Expressions with Effects +// TODO: do we need this for each target? +trait CNestedCodegen extends GenericNestedCodegen with CCodegen { + val IR: Expressions with Effects with LoweringTransform import IR._ - } -trait CFatCodegen extends CLikeFatCodegen with CCodegen { - val IR: Expressions with Effects with FatExpressions - import IR._ +trait CFatCodegen extends GenericFatCodegen with CCodegen { + val IR: Expressions with Effects with FatExpressions with LoweringTransform +} +trait Pointer extends Base { + class PointerManifest[A:Manifest] + def pointer_assign[A:Manifest](s: Rep[A], vl: Rep[A]): Rep[Unit] + def getPointerManifest[A:Manifest] = manifest[PointerManifest[A]] +} + +trait PointerExp extends Pointer with BaseExp with Effects { + case class PointerAssign[A:Manifest](s: Exp[A], vl: Exp[A]) extends Def[Unit] + def pointer_assign[A:Manifest](s: Exp[A], vl: Exp[A]) = reflectEffect(PointerAssign(s,vl)) +} + +trait CGenPointer extends GenericNestedCodegen { + val IR: PointerExp + import IR._ + + override def remap[A](m: Manifest[A]) = m match { + case s if m <:< manifest[PointerManifest[Any]] => remap(m.typeArguments.head) + "*" + case _ => super.remap(m) + } + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case PointerAssign(s,vl) => stream.println("*" + quote(s) + " = " + quote(vl) + ";") + case _ => super.emitNode(sym, rhs) + } } diff --git a/src/internal/CLikeCodegen.scala b/src/internal/CLikeCodegen.scala index 2f8ee4da..b24da551 100644 --- a/src/internal/CLikeCodegen.scala +++ b/src/internal/CLikeCodegen.scala @@ -1,183 +1,83 @@ -package scala.lms +package scala.virtualization.lms package internal import java.io.PrintWriter -import collection.mutable.HashSet trait CLikeCodegen extends GenericCodegen { val IR: Expressions import IR._ +/* + //TODO: is sym of type Any or Variable[Any] ? + def emitConstDef(sym: Sym[Any], rhs: String): Unit +*/ + def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit + def emitValDef(sym: Sym[Any], rhs: String): Unit + def emitAssignment(sym: Sym[Any], lhs:String, rhs: String): Unit + + override def emitKernelHeader(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { + val List(sym) = syms // TODO - def mangledName(name: String) = name.replaceAll("\\s","").map(c => if(!c.isDigit && !c.isLetter) '_' else c) - - // List of datastructure types that requires transfer functions to be generated for this target - val dsTypesList = HashSet[(Manifest[_],String)]() - - // Streams for helper functions and its header - var helperFuncStream: PrintWriter = _ - var headerStream: PrintWriter = _ - var actRecordStream: PrintWriter = _ - var typesStream: PrintWriter = _ - - def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = emitValDef(sym, rhs) - - def emitValDef(sym: Sym[Any], rhs: String): Unit = emitValDef(quote(sym), sym.tp, rhs) - - def emitValDef(sym: String, tpe: Manifest[_], rhs: String): Unit = { - if(remap(tpe) != "void") stream.println(remap(tpe) + " " + sym + " = " + rhs + ";") - } - - override def emitVarDecl(sym: Sym[Any]): Unit = { - stream.println(remap(sym.tp) + " " + quote(sym) + ";") - } - - override def emitAssignment(sym: Sym[Any], rhs: String): Unit = { - stream.println(quote(sym) + " = " + rhs + ";") - } - - def remapWithRef[A](m: Manifest[A]): String = remap(m) + addRef(m) - def remapWithRef(tpe: String): String = tpe + addRef(tpe) + if( (vars.length>0) || (resultIsVar) ) throw new GenerationFailedException("Var is not supported for CPP kernels") - override def remap[A](m: Manifest[A]) : String = { - if (m.erasure == classOf[Variable[AnyVal]]) - remap(m.typeArguments.head) - else if (m.erasure == classOf[List[Any]]) { // Use case: Delite Foreach sync list - deviceTarget.toString + "List< " + remap(m.typeArguments.head) + " >" - } - else { - m.toString match { - case "scala.collection.immutable.List[Float]" => "List" - case "Boolean" => "bool" - case "Byte" => "int8_t" - case "Char" => "uint16_t" - case "Short" => "int16_t" - case "Int" => "int32_t" - case "Long" => "int64_t" - case "Float" => "float" - case "Double" => "double" - case "Unit" => "void" - case "Nothing" => "void" - case _ => throw new GenerationFailedException("CLikeGen: remap(m) : Type %s cannot be remapped.".format(m.toString)) - } - } + val paramStr = vals.map(ele=>remap(ele.tp) + " " + quote(ele)).mkString(", ") + stream.println("%s kernel_%s(%s) {".format(resultType, quote(sym), paramStr)) } - def addRef(): String = if (cppMemMgr=="refcnt") " " else " *" - def addRef[A](m: Manifest[A]): String = addRef(remap(m)) - def addRef(tpe: String): String = { - if (!isPrimitiveType(tpe) && !isVoidType(tpe)) addRef() - else " " + override def emitKernelFooter(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { + val List(sym) = syms // TODO + + if(resultType != "void") + stream.println("return " + quote(sym) + ";") + stream.println("}") } - // move to CCodegen? - def unwrapSharedPtr(tpe: String): String = { - assert(cppMemMgr == "refcnt") - if(tpe.contains("std::shared_ptr")) - tpe.replaceAll("std::shared_ptr<","").replaceAll(">","") - else - tpe - } - def wrapSharedPtr(tpe: String): String = { - assert(cppMemMgr == "refcnt") - if(!isPrimitiveType(tpe) && !isVoidType(tpe)) - "std::shared_ptr<" + tpe + ">" - else - tpe - } - - override def emitKernelHeader(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { - - stream.append("#include \"" + deviceTarget + "helperFuncs.h\"\n") - - def kernelSignature: String = { - val out = new StringBuilder - if(resultIsVar) { - if (cppMemMgr == "refcnt") - out.append(wrapSharedPtr(hostTarget + "Ref" + unwrapSharedPtr(resultType))) - else - out.append(hostTarget + "Ref" + resultType + addRef()) - } - else { - out.append(resultType + addRef(resultType)) - } - - out.append(" kernel_" + syms.map(quote).mkString("") + "(") - out.append(vals.map(p => remap(p.tp) + " " + addRef(p.tp) + quote(p)).mkString(", ")) - if (vals.length > 0 && vars.length > 0) { - out.append(", ") - } - if (vars.length > 0) { - if (cppMemMgr == "refcnt") - out.append(vars.map(v => wrapSharedPtr(hostTarget + "Ref" + unwrapSharedPtr(remap(v.tp))) + " " + quote(v)).mkString(",")) - else - out.append(vars.map(v => hostTarget + "Ref" + remap(v.tp) + addRef() + " " + quote(v)).mkString(",")) - } - out.append(")") - out.toString + def isObjectType[A](m: Manifest[A]) : Boolean = { + m.toString match { + case _ => false } + } - //TODO: Remove the dependency to Multiloop to Delite - if (!resultType.startsWith("DeliteOpMultiLoop")) { - stream.println(kernelSignature + " {") - headerStream.println(kernelSignature + ";") + def remapToJNI[A](m: Manifest[A]) : String = { + remap(m) match { + case "bool" => "Boolean" + case "char" => "Byte" + case "CHAR" => "Char" + case "short" => "Short" + case "int" => "Int" + case "long" => "Long" + case "float" => "Float" + case "double" => "Double" + case _ => throw new GenerationFailedException("GPUGen: Cannot get array creation JNI function for this type " + remap(m)) } } - override def emitKernelFooter(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { - //TODO: Remove the dependency to Multiloop to Delite - if(resultType != "void" && !resultType.startsWith("DeliteOpMultiLoop")) - stream.println("return " + quote(syms(0)) + ";") - if(!resultType.startsWith("DeliteOpMultiLoop")) - stream.println("}") -/* - for(s <- syms++vals++vars) { - if(dsTypesList.contains(s.tp)) println("contains :" + remap(s.tp)) - else println("not contains: " + remap(s.tp)) - } - println(syms.map(quote).mkString("") + "adding dsTypesList:" + (syms++vals++vars).map(_.tp).mkString(",")) - dsTypesList ++= (syms++vals++vars).map(_.tp) - println("dsTyps-lms:" + dsTypesList.map(remap(_)).mkString(",")) //toString) - */ - dsTypesList ++= (syms++vals++vars).map(s => (s.tp,remap(s.tp))) + // Map a scala primitive type to JNI type descriptor + def JNITypeDescriptor[A](m: Manifest[A]) : String = m.toString match { + case "Boolean" => "Z" + case "Byte" => "B" + case "Char" => "C" + case "Short" => "S" + case "Int" => "I" + case "Long" => "J" + case "Float" => "F" + case "Double" => "D" + case _ => throw new GenerationFailedException("Undefined GPU type") } - def isPrimitiveType(tpe: String) : Boolean = { - tpe match { - case "bool" | "int8_t" | "uint16_t" | "int16_t" | "int32_t" | "int64_t" | "float" | "double" => true - case _ => false - } - } - def isVoidType(tpe: String) : Boolean = { - if(tpe == "void") true - else false - } - - def CLikeConsts(x:Exp[Any], s:String): String = { - s match { - case "Infinity" => "std::numeric_limits<%s>::max()".format(remap(x.tp)) - case _ => super.quote(x) - } - } - - override def quote(x: Exp[Any]) = x match { - case Const(s: Unit) => "" - case Const(s: Float) => s+"f" - case Const(null) => "NULL" - case Const(z) => CLikeConsts(x, z.toString) - case Sym(-1) => "_" - case _ => super.quote(x) - } } trait CLikeNestedCodegen extends GenericNestedCodegen with CLikeCodegen { - val IR: Expressions with Effects + val IR: Expressions with Effects with LoweringTransform import IR._ } trait CLikeFatCodegen extends GenericFatCodegen with CLikeCodegen { - val IR: Expressions with Effects with FatExpressions + val IR: Expressions with Effects with FatExpressions with LoweringTransform import IR._ + + def emitMultiLoopCond(sym: Sym[Any], funcs:List[Block[Any]], idx: Sym[Int], postfix: String="", stream:PrintWriter):(String,List[Exp[Any]]) + } diff --git a/src/internal/CodeMotion.scala b/src/internal/CodeMotion.scala index e8bb5247..503d8e4d 100644 --- a/src/internal/CodeMotion.scala +++ b/src/internal/CodeMotion.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal import util.GraphUtil @@ -98,12 +98,11 @@ trait CodeMotion extends Scheduling { // sanity check to make sure all effects are accounted for result foreach { - case LocalDef(TP(_, Reify(x, u, effects))) => - val observable = if (addControlDeps) effects.filterNot(controlDep) else effects - val acteffects = levelScope.flatMap(_.lhs) filter (observable contains _) - if (observable.toSet != acteffects.toSet) { - val actual = levelScope.filter(_.lhs exists (observable contains _)) - val expected = observable.map(d=>/*fatten*/(findDefinition(d.asInstanceOf[Sym[Any]]).get)) + case LocalDef(TP(_, Reify(x, u, effects))) => + val acteffects = levelScope.flatMap(_.lhs) filter (effects contains _) + if (effects.toSet != acteffects.toSet) { + val actual = levelScope.filter(_.lhs exists (effects contains _)) + val expected = effects.map(d=>/*fatten*/(findDefinition(d.asInstanceOf[Sym[Any]]).get)) val missing = expected filterNot (actual contains _) val printfn = if (missing.isEmpty) printlog _ else printerr _ printfn("error: violated ordering of effects") diff --git a/src/internal/Config.scala b/src/internal/Config.scala index 3727162b..ea067e92 100644 --- a/src/internal/Config.scala +++ b/src/internal/Config.scala @@ -1,17 +1,7 @@ -package scala.lms +package scala.virtualization.lms package internal -trait Config { - val verbosity = System.getProperty("lms.verbosity","0").toInt - val sourceinfo = System.getProperty("lms.sourceinfo","0").toInt - val addControlDeps = System.getProperty("lms.controldeps","true").toBoolean - - // memory management type for C++ target (refcnt or gc) - val cppMemMgr = System.getProperty("lms.cpp.memmgr","malloc") - - // explicit return type of lambda functions (allows recursive functions but is less generic) - val cppExplicitFunRet = System.getProperty("lms.cpp.explicitFunRet","true") - - // auto return value of if-else expressions (allows type deduction on if-then-else expressions) - val cppIfElseAutoRet = System.getProperty("lms.cpp.ifElseAutoRet","false") +object Config { + var verbosity = System.getProperty("lms.verbosity","0").toInt + var sourceinfo = System.getProperty("lms.sourceinfo","0").toInt } diff --git a/src/internal/CppHostTransfer.scala b/src/internal/CppHostTransfer.scala deleted file mode 100644 index 22f36297..00000000 --- a/src/internal/CppHostTransfer.scala +++ /dev/null @@ -1,301 +0,0 @@ -package scala.lms.internal - -trait CppHostTransfer extends AbstractHostTransfer { - this: CLikeCodegen => - - val IR: Expressions - import IR._ - - // NOTE: strings are in general treated as primitive types to avoid the memory management, - // but for transfer functions strings must be treated separately from primitive types - - def emitSend(tp: Manifest[_], peer: Targets.Value): (String,String) = { - if (peer == Targets.JVM) { - if (remap(tp) == "string") { - val out = new StringBuilder - val signature = "jobject sendCPPtoJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("return env->NewStringUTF(sym.c_str());\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "%s sendCPPtoJVM_%s(JNIEnv *env, %s sym)".format(JNIType(tp),mangledName(remapHost(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\treturn (%s)sym;\n".format(JNIType(tp))) - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "jobject sendCPPtoJVM_%s(JNIEnv *env, %s *sym)".format(mangledName(remapHost(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn NULL;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) - } - } - else if (peer == Targets.Cpp) { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - } - - def emitRecv(tp: Manifest[_], peer: Targets.Value): (String,String) = { - if (peer == Targets.JVM) { - if (remap(tp) == "string") { - val out = new StringBuilder - val signature = "%s recvCPPfromJVM_%s(JNIEnv *env, jobject obj)".format(remapHost(tp),mangledName(remapHost(tp))) - out.append(signature + " {\n") - out.append("\tconst char *str = env->GetStringUTFChars((jstring)obj,NULL);\n") - //TODO: check if this copy is necessary - out.append("\tchar *str2 = (char *)malloc((1+strlen(str))*sizeof(char));\n") - out.append("\tstrcpy(str2,str);\n") - out.append("\tstring sym(str2);\n") - out.append("\tenv->ReleaseStringUTFChars((jstring)obj,str);") - out.append("\treturn sym;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "%s recvCPPfromJVM_%s(JNIEnv *env, %s sym)".format(remap(tp),mangledName(remapHost(tp)),JNIType(tp)) - out.append(signature + " {\n") - out.append("\treturn (%s)sym;\n".format(remap(tp))) - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "%s *recvCPPfromJVM_%s(JNIEnv *env, jobject obj)".format(remapHost(tp),mangledName(remapHost(tp))) - out.append(signature + " {\n") - out.append("\t%s *sym = new %s();\n".format(remapHost(tp),remapHost(tp))) - out.append("\treturn sym;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) - } - } - else if (peer == Targets.Cpp) { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - } - - def emitSendView(tp: Manifest[_], peer: Targets.Value): (String,String) = { - if (peer == Targets.JVM) { - if (remap(tp) == "string") { - val out = new StringBuilder - val signature = "jobject sendViewCPPtoJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remapHost(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn NULL;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "%s sendViewCPPtoJVM_%s(JNIEnv *env, %s sym)".format(JNIType(tp),mangledName(remapHost(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn (%s)sym;\n".format(JNIType(tp))) - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "jobject sendViewCPPtoJVM_%s(JNIEnv *env, %s *sym)".format(mangledName(remapHost(tp)),remapHost(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn NULL;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) - } - } - else if (peer == Targets.Cpp) { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - } - - def emitRecvView(tp: Manifest[_], peer: Targets.Value): (String,String) = { - if (peer == Targets.JVM) { - if (remap(tp) == "string") { - val out = new StringBuilder - val signature = "%s recvViewCPPfromJVM_%s(JNIEnv *env, jobject *obj)".format(remapHost(tp),mangledName(remapHost(tp))) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn NULL;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "%s recvViewCPPfromJVM_%s(JNIEnv *env, %s sym)".format(remap(tp),mangledName(remapHost(tp)),JNIType(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn (%s)sym;\n".format(remap(tp))) - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "%s *recvViewCPPfromJVM_%s(JNIEnv *env, jobject *obj)".format(remapHost(tp),mangledName(remapHost(tp))) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn NULL;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) - } - } - else if (peer == Targets.Cpp) { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - } - - def emitSendUpdate(tp: Manifest[_], peer: Targets.Value): (String,String) = { - if (peer == Targets.JVM) { - if(isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "void sendUpdateCPPtoJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "void sendUpdateCPPtoJVM_%s(JNIEnv *env, jobject obj, %s *sym)".format(mangledName(remapHost(tp)),remapHost(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (remap(tp) == "string") { - val out = new StringBuilder - val signature = "void sendUpdateCPPtoJVM_%s(JNIEnv *env, jobject obj, %s sym)".format(mangledName(remapHost(tp)),remapHost(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) - } - } - else if (peer == Targets.Cpp) { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - } - - def emitRecvUpdate(tp: Manifest[_], peer: Targets.Value): (String,String) = { - if (peer == Targets.JVM) { - if (remap(tp) == "string") { - val out = new StringBuilder - val signature = "void recvUpdateCPPfromJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if(isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "void recvUpdateCPPfromJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "void recvUpdateCPPfromJVM_%s(JNIEnv *env, jobject obj, %s *sym)".format(mangledName(remapHost(tp)),remapHost(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) - } - } - else if (peer == Targets.Cpp) { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - else { - throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) - } - } - - def JNIType[A](m: Manifest[A]) : String = { - remap(m) match { - case "bool" => "jboolean" - case "int8_t" => "jbyte" - case "uint16_t" => "jchar" - case "int16_t" => "jshort" - case "int32_t" => "jint" - case "int64_t" => "jlong" - case "float" => "jfloat" - case "double" => "jdouble" - case _ => "jobject"//all other types are objects - } - } - - def remapToJNI[A](m: Manifest[A]) : String = { - remap(m) match { - case "bool" => "Boolean" - case "int8_t" => "Byte" - case "uint16_t" => "Char" - case "int16_t" => "Short" - case "int32_t" => "Int" - case "int64_t" => "Long" - case "float" => "Float" - case "double" => "Double" - case _ => "Object" - } - } - - def JNITypeDescriptor[A](m: Manifest[A]) : String = JNITypeDescriptor(m.toString) - def JNITypeDescriptor(tp: String): String = tp match { - case "Boolean" => "Z" - case "Byte" => "B" - case "Char" => "C" - case "Short" => "S" - case "Int" => "I" - case "Long" => "J" - case "Float" => "F" - case "Double" => "D" - case array if array.startsWith("Array[") => "[" + JNITypeDescriptor(array.slice(6,array.length-1)) - case _ => { //all other types are objects - var objectType = tp.replace('.','/') - if (objectType.indexOf('[') != -1) objectType = objectType.substring(0, objectType.indexOf('[')) //erasure - "L"+objectType+";" //'L' + fully qualified type + ';' - } - //case _ => throw new GenerationFailedException("Undefined JNI type") - } - -} diff --git a/src/internal/CudaCodegen.scala b/src/internal/CudaCodegen.scala index 7bc505b9..c3bdbdb7 100644 --- a/src/internal/CudaCodegen.scala +++ b/src/internal/CudaCodegen.scala @@ -1,47 +1,132 @@ -package scala.lms +package scala.virtualization.lms package internal import java.io.{FileWriter, StringWriter, PrintWriter, File} +import java.util.ArrayList +import collection.mutable.{ListBuffer, ArrayBuffer, LinkedList, HashMap, ListMap, HashSet} +import collection.mutable.{Map => MMap} import collection.immutable.List._ -trait CudaCodegen extends GPUCodegen with CppHostTransfer with CudaDeviceTransfer { +trait CudaCodegen extends GPUCodegen { val IR: Expressions import IR._ - override def deviceTarget: Targets.Value = Targets.Cuda - override def kernelFileExt = "cu" override def toString = "cuda" override def devFuncPrefix = "__device__" - - override def initializeGenerator(buildDir:String, args: Array[String]): Unit = { + + override def initializeGenerator(buildDir:String, args: Array[String], _analysisResults: MMap[String,Any]): Unit = { + val outDir = new File(buildDir) outDir.mkdirs + helperFuncIdx = 0 + helperFuncString = new StringBuilder + hstream = new PrintWriter(new FileWriter(buildDir + "helperFuncs.cu")) + helperFuncHdrStream = new PrintWriter(new FileWriter(buildDir + "helperFuncs.h")) + //headerStream = new PrintWriter(new FileWriter(buildDir + "dsl.h")) - actRecordStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "actRecords.h")) - - helperFuncStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.cu")) - helperFuncStream.print("#include \"" + deviceTarget + "helperFuncs.h\"\n") - - typesStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "types.h")) - typesStream.flush - //TODO: Put all the DELITE APIs declarations somewhere - headerStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.h")) - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include \"" + deviceTarget + "types.h\"") - headerStream.println(getDataStructureHeaders()) - headerStream.println("#include \"" + deviceTarget + "actRecords.h\"") + hstream.print("#include \"helperFuncs.h\"\n") + helperFuncHdrStream.print(getDSLHeaders) + helperFuncHdrStream.print("#include \n") + helperFuncHdrStream.print("#include \n") + helperFuncHdrStream.print("#include \n\n") + helperFuncHdrStream.print("#define CHAR short\n") + helperFuncHdrStream.print("#define jCHAR jshort\n") + helperFuncHdrStream.print("#include \"DeliteCuda.h\"\n") + helperFuncHdrStream.print("#include \"DeliteArray.h\"\n") + super.initializeGenerator(buildDir, args, _analysisResults) + } - super.initializeGenerator(buildDir, args) + // TODO: Move to Delite? + def copyInputHtoD(sym: Sym[Any]) : String = { + checkGPUableType(sym.tp) + remap(sym.tp) match { + case "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeiteArray" | "DeliteArray" | "DeliteArray" => + val out = new StringBuilder + val typeArg = sym.tp.typeArguments.head + val numBytesStr = "length * sizeof(%s)".format(remap(typeArg)) + out.append("\tint length = env->GetArrayLength((j%sArray)obj);\n".format(remapToJNI(typeArg).toLowerCase)) + out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)obj,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) + out.append("\t%s *%s = new %s(length);\n".format(remap(sym.tp),quote(sym),remap(sym.tp))) + out.append("\t%s *hostPtr;\n".format(remap(typeArg))) + out.append("\tDeliteCudaMallocHost((void**)&hostPtr,%s);\n".format(numBytesStr)) + out.append("\tmemcpy(hostPtr, dataPtr, %s);\n".format(numBytesStr)) + out.append("\tDeliteCudaMemcpyHtoDAsync(%s->data, hostPtr, %s);\n".format(quote(sym),numBytesStr)) + out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)obj, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) + out.append("\treturn %s;\n".format(quote(sym))) + out.toString + case _ => throw new Exception("CudaGen: copyInputHtoD(sym) : Cannot copy to GPU device (%s)".format(remap(sym.tp))) + } + } + + def copyOutputDtoH(sym: Sym[Any]) : String = { + checkGPUableType(sym.tp) + if (isPrimitiveType(sym.tp)) { + val out = new StringBuilder + out.append("\t%s *ptr;\n".format(remap(sym.tp))) + out.append("\tDeliteCudaMallocHost((void**)&ptr,sizeof(%s));\n".format(remap(sym.tp))) + out.append("\tDeliteCudaMemcpyDtoHAsync(ptr, %s, sizeof(%s));\n".format(quote(sym),remap(sym.tp))) + out.append("\treturn *ptr;\n") + out.toString + } + else { + remap(sym.tp) match { + case "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeiteArray" | "DeliteArray" | "DeliteArray" => + val out = new StringBuilder + val typeArg = sym.tp.typeArguments.head + val numBytesStr = "%s.length * sizeof(%s)".format(quote(sym),remap(typeArg)) + out.append("\tj%sArray arr = env->New%sArray(%s.length);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg),quote(sym))) + out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)arr,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) + out.append("\t%s *hostPtr;\n".format(remap(typeArg))) + out.append("\tDeliteCudaMallocHost((void**)&hostPtr,%s);\n".format(numBytesStr)) + out.append("\tDeliteCudaMemcpyDtoHAsync(hostPtr, %s.data, %s);\n".format(quote(sym),numBytesStr)) + out.append("\tmemcpy(dataPtr, hostPtr, %s);\n".format(numBytesStr)) + out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)arr, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) + out.append("\treturn arr;\n") + out.toString + case _ => throw new Exception("CudaGen: copyOutputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) + } + } + } + + def copyMutableInputDtoH(sym: Sym[Any]) : String = { + checkGPUableType(sym.tp) + remap(sym.tp) match { + case "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeiteArray" | "DeliteArray" | "DeliteArray" => + val out = new StringBuilder + val typeArg = sym.tp.typeArguments.head + val numBytesStr = "length * sizeof(%s)".format(remap(typeArg)) + out.append("\tint length = %s.length;\n".format(quote(sym))) + out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)obj,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) + out.append("\t%s *hostPtr;\n".format(remap(typeArg))) + out.append("\tDeliteCudaMallocHost((void**)&hostPtr,%s);\n".format(numBytesStr)) + out.append("\tDeliteCudaMemcpyDtoHAsync(hostPtr, %s.data, %s);\n".format(quote(sym),numBytesStr)) + out.append("\tmemcpy(dataPtr, hostPtr, %s);\n".format(numBytesStr)) + out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)obj, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) + out.toString + case _ => throw new Exception("CudaGen: copyMutableInputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) + } + } + + //TODO: Remove below methods + def allocOutput(newSym: Sym[_], sym: Sym[_], reset: Boolean = false) : Unit = { + throw new GenerationFailedException("CudaGen: allocOutput(newSym, sym) : Cannot allocate GPU memory (%s)".format(remap(sym.tp))) + } + def allocReference(newSym: Sym[Any], sym: Sym[Any]) : Unit = { + throw new GenerationFailedException("CudaGen: allocReference(newSym, sym) : Cannot allocate GPU memory (%s)".format(remap(sym.tp))) + } + + def positionMultDimInputs(sym: Sym[Any]) : String = { + throw new GenerationFailedException("CudaGen: positionMultDimInputs(sym) : Cannot reposition GPU memory (%s)".format(remap(sym.tp))) + } + + def cloneObject(sym: Sym[Any], src: Sym[Any]) : String = { + throw new GenerationFailedException("CudaGen: cloneObject(sym)") } def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, out: PrintWriter) = { + val sB = remap(manifest[A]) withStream(out) { @@ -65,15 +150,88 @@ trait CudaCodegen extends GPUCodegen with CppHostTransfer with CudaDeviceTransfe Nil } +/* + //TODO: is sym of type Any or Variable[Any] ? + def emitConstDef(sym: Sym[Any], rhs: emitK): Unit = { + stream.print("const ") + emitVarDef(sym, rhs) + } +*/ + + def emitValDef(sym: Sym[Any], rhs: String): Unit = { + stream.println(addTab() + remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") + } + + def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = { + stream.println(addTab()+ remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") + } + + def emitAssignment(sym: Sym[Any], lhs:String, rhs: String): Unit = { + stream.println(addTab() + " " + lhs + " = " + rhs + ";") + } + } // TODO: do we need this for each target? trait CudaNestedCodegen extends CLikeNestedCodegen with CudaCodegen { - val IR: Expressions with Effects + val IR: Expressions with Effects with LoweringTransform import IR._ + + def CudaConsts(x:Exp[Any], s:String): String = { + s match { + case "Infinity" => "std::numeric_limits<%s>::max()".format(remap(x.tp)) + case _ => s + } + } + + override def quote(x: Exp[Any]) = x match { // TODO: quirk! + case Const(s: String) => "\""+s+"\"" + case Const(s: Char) => "'"+s+"'" + case Const(null) => "NULL" + case Const(z) => CudaConsts(x, z.toString) + case Sym(-1) => "_" + case _ => super.quote(x) + } + } trait CudaFatCodegen extends CLikeFatCodegen with CudaCodegen { - val IR: Expressions with Effects with FatExpressions + val IR: Expressions with Effects with FatExpressions with LoweringTransform import IR._ + + def emitMultiLoopCond(sym: Sym[Any], funcs:List[Block[Any]], idx: Sym[Int], postfix: String="", stream:PrintWriter):(String,List[Exp[Any]]) = { + isNestedNode = true + devFuncIdx += 1 + val currIdx = devFuncIdx + val tempString = new StringWriter + val tempStream = new PrintWriter(tempString, true) + val header = new StringWriter + val footer = new StringWriter + + val currentTab = tabWidth + tabWidth = 1 + withStream(tempStream) { + emitFatBlock(funcs) + } + tabWidth = currentTab + + val inputs = getFreeVarBlock(Block(Combine(funcs.map(getBlockResultFull))),Nil).filterNot(quote(_)==quote(idx)).distinct + val paramStr = (inputs++List(idx)).map(ele=>remap(ele.tp)+" "+quote(ele)).mkString(",") + header.append(devFuncPrefix + " bool dev_%s(%s) {\n".format(postfix,paramStr)) + footer.append("\treturn %s;\n".format(funcs.map(f=>quote(getBlockResult(f))).mkString("&&"))) + footer.append("}\n") + stream.print(header) + stream.print(tempString) + stream.print(footer) + + //Register Metadata for loop function + val lf = metaData.loopFuncs.getOrElse(sym,new LoopFunc) + lf.hasCond = true + lf.loopCondInputs = inputs.map(quote) + metaData.loopFuncs.put(sym,lf) + isNestedNode = false + + ("dev_"+currIdx,inputs) + } + } diff --git a/src/internal/CudaDeviceTransfer.scala b/src/internal/CudaDeviceTransfer.scala deleted file mode 100644 index 3fd2bd73..00000000 --- a/src/internal/CudaDeviceTransfer.scala +++ /dev/null @@ -1,134 +0,0 @@ -package scala.lms.internal - -/* Defines Cuda specific device transfer functions */ -trait CudaDeviceTransfer extends AbstractDeviceTransfer { - this: CudaCodegen => - - val IR: Expressions - import IR._ - - - def emitSendSlave(tp: Manifest[_]): (String,String) = { - if (isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "%s sendCuda_%s(%s sym)".format(remap(tp),mangledName(remap(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\treturn sym;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "%s *sendCuda_%s(%s *sym)".format(remap(tp),mangledName(remap(tp)),remapHost(tp)) - out.append(signature + " {\n") - out.append("\t%s *sym_dev = new %s();\n".format(remap(tp),remap(tp))) - out.append("\treturn sym_dev;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + tp.toString) - } - } - - def emitRecvSlave(tp: Manifest[_]): (String,String) = { - if (isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "%s recvCuda_%s(%s *sym_dev)".format(remap(tp),mangledName(remap(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\t%s *hostPtr;\n".format(remap(tp))) - out.append("\tDeliteCudaMallocHost((void**)&hostPtr,sizeof(%s));\n".format(remap(tp))) - out.append("\tDeliteCudaMemcpyDtoHAsync(hostPtr, sym_dev, sizeof(%s));\n".format(remap(tp))) - out.append("\treturn *hostPtr;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "%s *recvCuda_%s(%s *sym_dev)".format(remapHost(tp),mangledName(remap(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\t%s *sym = new %s();\n".format(remapHost(tp),remapHost(tp))) - out.append("\treturn sym;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + tp.toString) - } - } -/* - def emitSendViewSlave(sym: Sym[Any]): (String,String) = { - if (isPrimitiveType(sym.tp)) { - val out = new StringBuilder - val signature = "%s sendViewCuda_%s(%s %s)".format(remap(sym.tp),quote(sym),remap(sym.tp),quote(sym)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn %s;\n".format(quote(sym))) - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + sym.tp.toString) - } - } - - def emitRecvViewSlave(sym: Sym[Any]): (String,String) = { - if (isPrimitiveType(sym.tp)) { - val out = new StringBuilder - val signature = "%s recvViewCuda_%s(%s %s)".format(remap(sym.tp),quote(sym),remap(sym.tp),quote(sym)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn %s;\n".format(quote(sym))) - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + sym.tp.toString) - } - } -*/ - def emitSendUpdateSlave(tp: Manifest[_]): (String,String) = { - if(isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "void sendUpdateCuda_%s(%s sym)".format(mangledName(remap(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "void sendUpdateCuda_%s(%s *sym_dev, %s *sym)".format(mangledName(remap(tp)),remap(tp),remapHost(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + tp.toString) - } - } - - def emitRecvUpdateSlave(tp: Manifest[_]): (String,String) = { - if(isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "void recvUpdateCuda_%s(%s sym)".format(mangledName(remap(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else if (tp.erasure == classOf[List[Any]]) { - val out = new StringBuilder - val signature = "void recvUpdateCuda_%s(%s *sym_dev, %s *sym)".format(mangledName(remap(tp)),remap(tp),remapHost(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + tp.toString) - } - } - -} diff --git a/src/internal/Effects.scala b/src/internal/Effects.scala index d64617f1..7274bb5f 100644 --- a/src/internal/Effects.scala +++ b/src/internal/Effects.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal import scala.reflect.SourceContext @@ -28,8 +28,6 @@ trait Effects extends Expressions with Blocks with Utils { var context: State = _ - var conditionalScope = false // used to construct Control nodes - // --- class defs case class Reflect[+A](x:Def[A], summary: Summary, deps: List[Exp[Any]]) extends Def[A] @@ -43,27 +41,26 @@ trait Effects extends Expressions with Blocks with Utils { val mayGlobal: Boolean, val mstGlobal: Boolean, val resAlloc: Boolean, - val control: Boolean, val mayRead: List[Sym[Any]], val mstRead: List[Sym[Any]], val mayWrite: List[Sym[Any]], val mstWrite: List[Sym[Any]]) - def Pure() = new Summary(false,false,false,false,false,false,Nil,Nil,Nil,Nil) - def Simple() = new Summary(true,true,false,false,false,false,Nil,Nil,Nil,Nil) - def Global() = new Summary(false,false,true,true,false,false,Nil,Nil,Nil,Nil) - def Alloc() = new Summary(false,false,false,false,true,false,Nil,Nil,Nil,Nil) - def Control() = new Summary(false,false,false,false,false,true,Nil,Nil,Nil,Nil) + def Pure() = new Summary(false,false,false,false,false,Nil,Nil,Nil,Nil) + def Simple() = new Summary(true,true,false,false,false,Nil,Nil,Nil,Nil) + def Global() = new Summary(false,false,true,true,false,Nil,Nil,Nil,Nil) + def Alloc() = new Summary(false,false,false,false,true,Nil,Nil,Nil,Nil) - def Read(v: List[Sym[Any]]) = new Summary(false,false,false,false,false,false,v.distinct,v.distinct,Nil,Nil) - def Write(v: List[Sym[Any]]) = new Summary(false,false,false,false,false,false,Nil,Nil,v.distinct,v.distinct) + def Read(v: List[Sym[Any]]) = new Summary(false,false,false,false,false,v.distinct,v.distinct,Nil,Nil) + def Write(v: List[Sym[Any]]) = new Summary(false,false,false,false,false,Nil,Nil,v.distinct,v.distinct) def mayRead(u: Summary, a: List[Sym[Any]]): Boolean = u.mayGlobal || a.exists(u.mayRead contains _) def mayWrite(u: Summary, a: List[Sym[Any]]): Boolean = u.mayGlobal || a.exists(u.mayWrite contains _) - def maySimple(u: Summary): Boolean = u.mayGlobal || u.maySimple + def maySimple(u: Summary): Boolean = u.mayGlobal || u.maySimple def mustMutable(u: Summary): Boolean = u.resAlloc def mustPure(u: Summary): Boolean = u == Pure() + def mustOnlyAlloc(u: Summary): Boolean = u == Alloc() // only has a resource allocation def mustOnlyRead(u: Summary): Boolean = u == Pure().copy(mayRead=u.mayRead, mstRead=u.mstRead) // only reads allowed def mustIdempotent(u: Summary): Boolean = mustOnlyRead(u) // currently only reads are treated as idempotent @@ -73,7 +70,6 @@ trait Effects extends Expressions with Blocks with Utils { u.maySimple || v.maySimple, u.mstSimple && v.mstSimple, u.mayGlobal || v.mayGlobal, u.mstGlobal && v.mstGlobal, false, //u.resAlloc && v.resAlloc, <--- if/then/else will not be mutable! - u.control || v.control, (u.mayRead ++ v.mayRead).distinct, (u.mstRead intersect v.mstRead), (u.mayWrite ++ v.mayWrite).distinct, (u.mstWrite intersect v.mstWrite) ) @@ -82,30 +78,20 @@ trait Effects extends Expressions with Blocks with Utils { u.maySimple || v.maySimple, u.mstSimple || v.mstSimple, u.mayGlobal || v.mayGlobal, u.mstGlobal || v.mstGlobal, u.resAlloc || v.resAlloc, - u.control || v.control, (u.mayRead ++ v.mayRead).distinct, (u.mstRead ++ v.mstRead).distinct, (u.mayWrite ++ v.mayWrite).distinct, (u.mstWrite ++ v.mstWrite).distinct ) def infix_andThen(u: Summary, v: Summary) = new Summary( u.maySimple || v.maySimple, u.mstSimple || v.mstSimple, - u.mayGlobal || v.mayGlobal, u.mstGlobal || v.mstGlobal, + u.mayGlobal || v.mayGlobal, u.mstGlobal || v.mstGlobal, v.resAlloc, - u.control || v.control, (u.mayRead ++ v.mayRead).distinct, (u.mstRead ++ v.mstRead).distinct, (u.mayWrite ++ v.mayWrite).distinct, (u.mstWrite ++ v.mstWrite).distinct ) def infix_star(u: Summary) = Pure() orElse u // any number of repetitions, including 0 - def infix_withoutControl(u: Summary) = new Summary( - u.maySimple, u.mstSimple, - u.mayGlobal, u.mstGlobal, - u.resAlloc, - false, - u.mayRead, u.mstRead, - u.mayWrite, u.mstWrite - ) def summarizeEffects(e: Block[Any]) = e match { case Block(Def(Reify(_,u,_))) => u @@ -117,29 +103,8 @@ trait Effects extends Expressions with Blocks with Utils { // --- reflect helpers - def controlDep(x: Exp[Any]) = x match { - case Def(Reflect(y,u,es)) if u == Control() => true - case _ => false - } - - // performance hotspot - def nonControlSyms[R](es: List[Exp[Any]], ss: Any => List[R]): List[R] = { - // es.filterNot(controlDep).flatMap(syms) - val out = new mutable.ListBuffer[R] - var it = es.iterator - while (it.hasNext) { - val e = it.next() - if (!controlDep(e)) out ++= ss(e) - } - out.result - } - override def syms(e: Any): List[Sym[Any]] = e match { case s: Summary => Nil // don't count effect summaries as dependencies! - - // enable DCE of reflect nodes if they are only control dependencies - case Reflect(x,u,es) if addControlDeps => syms(x) ::: nonControlSyms(es, syms) - case Reify(x,u,es) if addControlDeps => syms(x) ::: nonControlSyms(es, syms) case _ => super.syms(e) } @@ -150,10 +115,6 @@ trait Effects extends Expressions with Blocks with Utils { override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { case s: Summary => Nil // don't count effect summaries as dependencies! - - // enable DCE of reflect nodes if they are only control dependencies - case Reflect(x,u,es) if addControlDeps => symsFreq(x) ::: nonControlSyms(es, symsFreq) - case Reify(x,u,es) if addControlDeps => symsFreq(x) ::: nonControlSyms(es, symsFreq) case _ => super.symsFreq(e) } @@ -353,7 +314,8 @@ trait Effects extends Expressions with Blocks with Utils { createReflectDefinition // if summary is not pure */ // warn if type is Any. TODO: make optional, sometimes Exp[Any] is fine - if (manifest[T] == manifest[Any]) printlog("warning: possible missing mtype call - toAtom with Def of type Any " + d) + if (Config.verbosity == 2 && manifest[T] == manifest[Any]) + printlog("warning: possible missing mtype call - toAtom with Def of type Any " + d) // AKS NOTE: this was removed on 6/27/12, but it is still a problem in OptiML apps without it, // so I'm putting it back until we can get it resolved properly. @@ -363,24 +325,23 @@ trait Effects extends Expressions with Blocks with Utils { // specifically, if we return the reified version of a mutable bound var, we get a Reflect(Reify(..)) error, e.g. mutable Sum // printlog("ignoring read of Reify(): " + d) super.toAtom(d) - case _ if conditionalScope && addControlDeps => reflectEffect(d, Control()) case _ => reflectEffect(d, Pure()) } // reflectEffect(d, Pure()) } - def reflectMirrored[A:Manifest](zd: Reflect[A])(implicit pos: SourceContext): Exp[A] = { + def reflectMirrored[A:Manifest](zd: Reflect[A]): Exp[A] = { checkContext() // warn if type is Any. TODO: make optional, sometimes Exp[Any] is fine if (manifest[A] == manifest[Any]) printlog("warning: possible missing mtype call - reflectMirrored with Def of type Any: " + zd) context.filter { case Def(d) if d == zd => true case _ => false }.reverse match { //case z::_ => z.asInstanceOf[Exp[A]] -- unsafe: we don't have a tight context, so we might pick one from a flattened subcontext - case _ => createReflectDefinition(fresh[A].withPos(List(pos)), zd) + case _ => createReflectDefinition(fresh[A], zd) } } def checkIllegalSharing(z: Exp[Any], mutableAliases: List[Sym[Any]]) { - if (mutableAliases.nonEmpty) { + if (mutableAliases.nonEmpty && Config.verbosity >= 1) { val zd = z match { case Def(zd) => zd } printerr("error: illegal sharing of mutable objects " + mutableAliases.mkString(", ")) printerr("at " + z + "=" + zd) @@ -429,21 +390,35 @@ trait Effects extends Expressions with Blocks with Utils { val mutableInputs = readMutableData(d) reflectEffectInternal(d, u andAlso Read(mutableInputs)) // will call super.toAtom if mutableInput.isEmpty } - + def reflectEffectInternal[A:Manifest](x: Def[A], u: Summary)(implicit pos: SourceContext): Exp[A] = { - if (mustPure(u)) super.toAtom(x) else { + /* + * We want to handle the case where a variable is first initialized to null, + * and later initialized to its actual value (also see variables.scala). + * This is the case with local state in the DBMS system of DATA lab. There, + * when the var is initialized to null, the context is null, since it is + * _outside_ any compiled method (we do not lift everything in this + * system!). Initial solution was to override the case where context == + * null, however this breaks test4-fac4 (reflectEffect when not needed). + */ + if (context == null) { + context = Nil + if (mustPure(u)) super.toAtom(x) + else { + val z = fresh[A] + val zd = Reflect(x,u,null) + createReflectDefinition(z, zd) + } + } else if (mustPure(u)) super.toAtom(x) else { checkContext() // NOTE: reflecting mutable stuff *during mirroring* doesn't work right now. - // FIXME: Reflect(Reflect(ObjectUnsafeImmutable(..))) on delite - assert(!x.isInstanceOf[Reflect[_]], x) - val deps = calculateDependencies(u) val zd = Reflect(x,u,deps) if (mustIdempotent(u)) { context find { case Def(d) => d == zd } map { _.asInstanceOf[Exp[A]] } getOrElse { // findDefinition(zd) map (_.sym) filter (context contains _) getOrElse { // local cse TODO: turn around and look at context first?? - val z = fresh[A](List(pos)) + val z = fresh[A] if (!x.toString.startsWith("ReadVar")) { // supress output for ReadVar printlog("promoting to effect: " + z + "=" + zd) for (w <- u.mayRead) @@ -454,11 +429,13 @@ trait Effects extends Expressions with Blocks with Utils { } else { val z = fresh[A](List(pos)) // make sure all writes go to allocs - for (w <- u.mayWrite if !isWritableSym(w)) { - printerr("error: write to non-mutable " + w + " -> " + findDefinition(w)) - printerr("at " + z + "=" + zd) - printsrc("in " + quotePos(z)) - } + if (Config.verbosity >= 1) { + for (w <- u.mayWrite if !isWritableSym(w)) { + printerr("error: write to non-mutable " + w + " -> " + findDefinition(w)) + printerr("at " + z + "=" + zd) + printsrc("in " + quotePos(z)) + } + } // prevent sharing between mutable objects / disallow mutable escape for non read-only operations // make sure no mutable object becomes part of mutable result (in case of allocation) // or is written to another mutable object (in case of write) @@ -509,12 +486,11 @@ trait Effects extends Expressions with Blocks with Utils { val softWriteDeps = if (write.isEmpty) Nil else scope filter { case e@Def(Reflect(_, u, _)) => mayRead(u, write) } val writeDeps = if (write.isEmpty) Nil else scope filter { case e@Def(Reflect(_, u, _)) => mayWrite(u, write) || write.contains(e) } val simpleDeps = if (!u.maySimple) Nil else scope filter { case e@Def(Reflect(_, u, _)) => u.maySimple } - val controlDeps = if (!u.control) Nil else scope filter { case e@Def(Reflect(_, u, _)) => u.control } val globalDeps = scope filter { case e@Def(Reflect(_, u, _)) => u.mayGlobal } // TODO: write-on-read deps should be weak // TODO: optimize!! - val allDeps = canonic(readDeps ++ softWriteDeps ++ writeDeps ++ canonicLinear(simpleDeps) ++ canonicLinear(controlDeps) ++ canonicLinear(globalDeps)) + val allDeps = canonic(readDeps ++ softWriteDeps ++ writeDeps ++ canonicLinear(simpleDeps) ++ canonicLinear(globalDeps)) scope filter (allDeps contains _) } } @@ -561,18 +537,12 @@ trait Effects extends Expressions with Blocks with Utils { // reify the effects of an isolated block. // no assumptions about the current context remain valid. - def reifyEffects[A:Manifest](block: => Exp[A], controlScope: Boolean = false): Block[A] = { + def reifyEffects[A:Manifest](block: => Exp[A]): Block[A] = { val save = context context = Nil - // only add control dependencies scopes where controlScope is explicitly true (i.e., the first-level of an IfThenElse) - val saveControl = conditionalScope - conditionalScope = controlScope - val (result, defs) = reifySubGraph(block) - reflectSubGraph(defs) - - conditionalScope = saveControl + reflectSubGraph(defs) val deps = context val summary = summarizeAll(deps) @@ -583,19 +553,14 @@ trait Effects extends Expressions with Blocks with Utils { // reify the effects of a block that is executed 'here' (if it is executed at all). // all assumptions about the current context carry over unchanged. - def reifyEffectsHere[A:Manifest](block: => Exp[A], controlScope: Boolean = false): Block[A] = { + def reifyEffectsHere[A:Manifest](block: => Exp[A]): Block[A] = { val save = context if (save eq null) context = Nil - val saveControl = conditionalScope - conditionalScope = controlScope - val (result, defs) = reifySubGraph(block) reflectSubGraph(defs) - conditionalScope = saveControl - if ((save ne null) && context.take(save.length) != save) // TODO: use splitAt printerr("error: 'here' effects must leave outer information intact: " + save + " is not a prefix of " + context) diff --git a/src/internal/Exceptions.scala b/src/internal/Exceptions.scala index a5774163..c367c0a5 100644 --- a/src/internal/Exceptions.scala +++ b/src/internal/Exceptions.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal class GenerationFailedException(msg: String) extends Exception(msg) \ No newline at end of file diff --git a/src/internal/Expressions.scala b/src/internal/Expressions.scala index a2898c8c..841b80df 100644 --- a/src/internal/Expressions.scala +++ b/src/internal/Expressions.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal import scala.reflect.SourceContext @@ -16,22 +16,130 @@ import java.lang.{StackTraceElement,Thread} trait Expressions extends Utils { abstract class Exp[+T:Manifest] { // constants/symbols (atomic) - def tp: Manifest[T @uncheckedVariance] = manifest[T] //invariant position! but hey... + var tp: Manifest[T @uncheckedVariance] = manifest[T] //invariant position! but hey... def pos: List[SourceContext] = Nil + var emitted = false; } - case class Const[+T:Manifest](x: T) extends Exp[T] + case class Const[+T:Manifest](x: T) extends Exp[T] { + /** + * equals implementation in Const can not simply rely on default + * implementation for a case class, because we should check the + * type of Const for equality test. + * Otherwise, we might end-up generating code with wrong typing, + * specially upon CSE. + * + * For example, have a look at test1-arith/TestConstCSE: + * + * trait Prog extends ScalaOpsPkg { + * def test1(test_param: Rep[Boolean], acc: Rep[Long]): Rep[Long] = { + * val dblVal = if(test_param) unit(1.0) else unit(0.0) + * val lngVal = if(test_param) unit(1L) else unit(0L) + * auxMethod(acc + lngVal, dblVal) + * } + * + * def auxMethod(val1: Rep[Long], val2: Rep[Double]): Rep[Long] = { + * val1 + unit(133L) + rep_asinstanceof[Double, Long](val2,manifest[Double],manifest[Long]) + * } + * } + * + * That would generate a code containing a compile error: + * + * class test1 extends ((Boolean, Long)=>(Long)) { + * def apply(x0:Boolean, x1:Long): Long = { + * val x2 = if (x0) { + * 1.0 + * } else { + * 0.0 + * } + * val x3 = x1 + x2 + * val x4 = x3 + 133L + * val x5 = x2.asInstanceOf[Long] + * val x6 = x4 + x5 + * x6 + * } + * } + * + * :15: error: type mismatch; + * found : Double + * required: Long + * x6 + * ^ + * one error found + * compilation: had errors + * + * But, by introducing this new implementation for equals, the + * correct code will be generated: + * + * class test1 extends ((Boolean, Long)=>(Long)) { + * def apply(x0:Boolean, x1:Long): Long = { + * val x3 = if (x0) { + * 1L + * } else { + * 0L + * } + * val x4 = x1 + x3 + * val x5 = x4 + 133L + * val x2 = if (x0) { + * 1.0 + * } else { + * 0.0 + * } + * val x6 = x2.asInstanceOf[Long] + * val x7 = x5 + x6 + * x7 + * } + * } + * + * compilation: ok + */ + override def equals(that: Any) = that match { + case c@Const(y) => if(y == x) { + val thisTp = tp + //val thatTp = c.tp + if (Const.isNumeric[T](thisTp) /*&& isNumeric(thatTp)*/) + thisTp == c.tp //thatTp + else + true + } else false + case _ => false + } + } + + object Const { + val doubleManifest: Manifest[Double] = manifest[Double] + val floatManifest: Manifest[Float] = manifest[Float] + val longManifest: Manifest[Long] = manifest[Long] + val intManifest: Manifest[Int] = manifest[Int] + val shortManifest: Manifest[Short] = manifest[Short] + val byteManifest: Manifest[Byte] = manifest[Byte] + + def isNumeric[T:Manifest](m: Manifest[T]) = m == doubleManifest || + m == floatManifest || + m == longManifest || + m == intManifest || + m == shortManifest || + m == byteManifest + } case class Sym[+T:Manifest](val id: Int) extends Exp[T] { + val attributes: scala.collection.mutable.Map[Any,Any] = scala.collection.mutable.ListMap.empty + var sourceInfo = Thread.currentThread.getStackTrace // will go away var sourceContexts: List[SourceContext] = Nil override def pos = sourceContexts def withPos(pos: List[SourceContext]) = { sourceContexts :::= pos; this } } - case class Variable[+T](val e: Exp[Variable[T]]) // TODO: decide whether it should stay here ... FIXME: should be invariant + case class Variable[+T](val e: Exp[Variable[T]]) { + } // TODO: decide whether it should stay here ... FIXME: should be invariant var nVars = 0 - def fresh[T:Manifest]: Sym[T] = Sym[T] { nVars += 1; if (nVars%1000 == 0) printlog("nVars="+nVars); nVars -1 } + def fresh[T:Manifest]: Sym[T] = Sym[T] { + nVars += 1; + //if (nVars%1000 == 0) println("nVars="+nVars); + nVars - 1 + } + def fresh[T:Manifest](id: Int): Sym[T] = Sym[T] { id } def fresh[T:Manifest](pos: List[SourceContext]): Sym[T] = fresh[T].withPos(pos) @@ -45,6 +153,48 @@ trait Expressions extends Utils { cs.map(c => all(c).reverse.map(c => c.fileName.split("/").last + ":" + c.line).mkString("//")).mkString(";") } +/* + def fresh[T:Manifest] = { + val (name, id, nameId) = nextName("x") + val sym = Sym[T](id) + sym.name = name + sym.nameId = nameId + sym + } + + def fresh[T:Manifest](d: Def[T], ctx: Option[SourceContext]) = { + def enclosingNamedContext(sc: SourceContext): Option[SourceContext] = sc.bindings match { + case (null, _) :: _ => + if (!sc.parent.isEmpty) enclosingNamedContext(sc.parent.get) + else None + case (name, line) :: _ => + Some(sc) + } + + // create base name from source context + val (basename, line, srcCtx) = if (!ctx.isEmpty) { + enclosingNamedContext(ctx.get) match { + case None => + // no enclosing context has variable assignment + var outermost = ctx.get + while (!outermost.parent.isEmpty) { + outermost = outermost.parent.get + } + ("x", 0, Some(outermost)) + case Some(sc) => sc.bindings match { + case (n, l) :: _ => + (n, l, Some(sc)) + } + } + } else ("x", 0, None) + val (name, id, nameId) = nextName(basename) + val sym = Sym[T](id) + sym.name = name + sym.nameId = nameId + sym.sourceContext = srcCtx + sym + } +*/ abstract class Def[+T] { // operations (composite) override final lazy val hashCode = scala.runtime.ScalaRunTime._hashCode(this.asInstanceOf[Product]) @@ -94,8 +244,7 @@ trait Expressions extends Utils { def reflectSubGraph(ds: List[Stm]): Unit = { val lhs = ds.flatMap(_.lhs) assert(lhs.length == lhs.distinct.length, "multiple defs: " + ds) - // equivalent to: globalDefs filter (_.lhs exists (lhs contains _)) - val existing = lhs flatMap (globalDefsCache get _) + val existing = lhs flatMap (globalDefsCache get _)//globalDefs filter (_.lhs exists (lhs contains _)) assert(existing.isEmpty, "already defined: " + existing + " for " + ds) localDefs = localDefs ::: ds globalDefs = globalDefs ::: ds @@ -131,7 +280,7 @@ trait Expressions extends Utils { } object Def { - def unapply[T](e: Exp[T]): Option[Def[T]] = e match { + def unapply[T](e: Exp[T]): Option[Def[T]] = e match { // really need to test for sym? case s @ Sym(_) => findDefinition(s).flatMap(_.defines(s)) case _ => @@ -148,9 +297,8 @@ trait Expressions extends Utils { case ss: Iterable[Any] => ss.toList.flatMap(syms(_)) // All case classes extend Product! case p: Product => - // performance hotspot: this is the same as - // p.productIterator.toList.flatMap(syms(_)) - // but faster + //return p.productIterator.toList.flatMap(syms(_)) + /* performance hotspot */ val iter = p.productIterator val out = new ListBuffer[Sym[Any]] while (iter.hasNext) { @@ -192,7 +340,7 @@ trait Expressions extends Utils { case _ => Nil } - // generic symbol traversal: f is expected to call rsyms again + def rsyms[T](e: Any)(f: Any=>List[T]): List[T] = e match { case s: Sym[Any] => f(s) case ss: Iterable[Any] => ss.toList.flatMap(f) @@ -215,6 +363,25 @@ trait Expressions extends Utils { def freqCold(e: Any) = symsFreq(e).map(p=>(p._1,p._2*0.5)) + +/* + def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case s: Sym[Any] => List((s,1.0)) + case p: Product => p.productIterator.toList.flatMap(symsFreq(_)) + case _ => Nil + } +*/ + +/* + def symsShare(e: Any): List[(Sym[Any], Int)] = { + case s: Sym[Any] => List(s) + case p: Product => p.productIterator.toList.flatMap(symsShare(_)) + case _ => Nil + } +*/ + + + // bookkeeping def reset { // used by delite? diff --git a/src/internal/ExtendedExpressions.scala b/src/internal/ExtendedExpressions.scala new file mode 100644 index 00000000..5e4450cf --- /dev/null +++ b/src/internal/ExtendedExpressions.scala @@ -0,0 +1,53 @@ +package scala.virtualization.lms +package internal + +import scala.reflect.SourceContext +import scala.annotation.unchecked.uncheckedVariance +import scala.collection.mutable.ListBuffer +import java.lang.{StackTraceElement,Thread} + + +trait ExtendedExpressions extends Expressions with Blocks { + val RefCountAttributeKey = "refCnt" + val ParentBlockAttributeKey = "pBlk" + + def infix_refCount(s: Sym[Any]): Int = { + s.attributes.get(RefCountAttributeKey).getOrElse(0).asInstanceOf[Int] + } + + def infix_incRefCount(s: Sym[Any], inc: Int): Unit = { + s.setRefCount(s.refCount + inc) + } + + def infix_setRefCount(s: Sym[Any], refCnt: Int): Unit = { + s.attributes.update(RefCountAttributeKey, refCnt) + } + + def infix_parentBlock(s: Sym[Any]): Option[Block[Any]] = { + s.attributes.get(ParentBlockAttributeKey).asInstanceOf[Option[Block[Any]]] + } + + def infix_setParentBlock(s: Sym[Any], pBlk: Option[Block[Any]]): Unit = pBlk match { + case Some(blk) => s.attributes.update(ParentBlockAttributeKey, blk) + case None => + } + + def infix_inSameParentBlockAs(thiz: Sym[Any], other: Sym[Any]): Boolean = { + val thizParent: Option[Block[Any]] = thiz.attributes.get(ParentBlockAttributeKey).asInstanceOf[Option[Block[Any]]] + val otherParent: Option[Block[Any]] = other.attributes.get(ParentBlockAttributeKey).asInstanceOf[Option[Block[Any]]] + thizParent match { + case Some(thizP) => otherParent match { + case Some(otherP) => thizP.res == otherP.res + case None => false + } + case None => otherParent match { + case Some(otherP) => false + case None => true + } + } + } + + def infix_possibleToInline(s: Sym[Any]): Boolean = s.refCount == 1 + + def infix_noReference(s: Sym[Any]): Boolean = s.refCount == 0 +} \ No newline at end of file diff --git a/src/internal/FatCodegen.scala b/src/internal/FatCodegen.scala index 497d3f5d..cc1d2eee 100644 --- a/src/internal/FatCodegen.scala +++ b/src/internal/FatCodegen.scala @@ -1,11 +1,11 @@ -package scala.lms +package scala.virtualization.lms package internal import util.GraphUtil import java.io.{File, PrintWriter} trait GenericFatCodegen extends GenericNestedCodegen with FatBlockTraversal { - val IR: Expressions with Effects with FatExpressions + val IR: Expressions with Effects with FatExpressions with LoweringTransform import IR._ @@ -31,4 +31,4 @@ trait GenericFatCodegen extends GenericNestedCodegen with FatBlockTraversal { emitBlock(Block(Combine(rhs.map(getBlockResultFull)))) // TODO: find another way } -} \ No newline at end of file +} diff --git a/src/internal/FatExpressions.scala b/src/internal/FatExpressions.scala index 3181e999..b875d6b2 100644 --- a/src/internal/FatExpressions.scala +++ b/src/internal/FatExpressions.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal trait FatExpressions extends Expressions { diff --git a/src/internal/FatScheduling.scala b/src/internal/FatScheduling.scala index b1d3eae4..0783cf72 100644 --- a/src/internal/FatScheduling.scala +++ b/src/internal/FatScheduling.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal import util.GraphUtil diff --git a/src/internal/FatTraversal.scala b/src/internal/FatTraversal.scala index a3ef6107..b5a1c29f 100644 --- a/src/internal/FatTraversal.scala +++ b/src/internal/FatTraversal.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal import util.GraphUtil diff --git a/src/internal/GPUCodegen.scala b/src/internal/GPUCodegen.scala index 4ed86ad7..c1d7c169 100644 --- a/src/internal/GPUCodegen.scala +++ b/src/internal/GPUCodegen.scala @@ -1,81 +1,218 @@ -package scala.lms +package scala.virtualization.lms package internal import java.io.{StringWriter, PrintWriter, File} +import collection.mutable.{ArrayBuffer, HashMap, ListMap, HashSet} import collection.immutable.List._ import scala.reflect.SourceContext -import collection.mutable.{HashMap, HashSet, ArrayBuffer, ListMap, ListBuffer} -trait GPUCodegen extends CLikeCodegen with AbstractHostTransfer with AbstractDeviceTransfer { +trait GPUCodegen extends CLikeCodegen { val IR: Expressions import IR._ - // Prefix string for device functions on the target GPU programming model (e.g., __device__ for CUDA) - def devFuncPrefix:String = "" + /* Kernel input / output symbols */ + private var kernelInputs: List[Sym[Any]] = null + private var kernelOutputs: List[Sym[Any]] = null + def getKernelInputs = kernelInputs + def setKernelInputs(syms: List[Sym[Any]]): Unit = { kernelInputs = syms } + def getKernelOutputs = kernelOutputs + def setKernelOutputs(syms: List[Sym[Any]]): Unit = { kernelOutputs = syms } + def getKernelTemps = metaData.temps.toList.reverse.map(ele => ele._1) + def devFuncPrefix = "" - // List of kernels and helper functions emitted so far (not to emit the same thing multiple times) - private val kernelsList = ArrayBuffer[Exp[Any]]() - protected val helperFuncList = ArrayBuffer[String]() - - // Current tab location for pretty printing - protected var tabWidth:Int = 0 + /* For using GPU local variables */ + final class GPUOptimizer { + // Map (collection,idx) -> localVar + var collToVar: HashMap[(Sym[Any],String),String] = HashMap[(Sym[Any],String),String]() + // Map variable symbol -> set of aliased symbols + var varToSet: HashMap[String,HashSet[String]] = HashMap[String,HashSet[String]]() + + /* + //TODO: deal with aliased collection + def hasLocalVar(coll:Sym[Any], idx: String): Boolean = { + var hit = false + for (i <- varToSet(idx)) { + if (collToVar contains (coll,i)) + hit = true + } + hit + } + def getLocalVar(coll:Sym[Any], idx: String): String = { + assert(hasLocalVar(coll,idx)) + for (i <- varToSet(idx) if (collToVar contains (coll,i))) { + return collToVar.get(coll,i).get + } + } + def registerAlias(sym:String,aliased:String) { + if (varToSet contains aliased) { + val set = varToSet.get(aliased).get + set.add(sym) + varToSet.put(sym,set) + } + else if (varToSet contains sym) { + val set = varToSet.get(sym).get + set.add(aliased) + varToSet.put(aliased,set) + } + else { + val set = HashSet[String](sym,aliased) + varToSet.put(sym,set) + varToSet.put(aliased,set) + } + println("resitested alias: %s = %s".format(sym,aliased)) + } + */ + //def registerLocalVarArith(sym:String, ) + //def registerLocalVar(key:(Sym[Any],String), value:String) { + // collToVar.put(key,value) + //} + } + var optimizer: GPUOptimizer = null + + /* Indicates current dimension of work threads */ + /* + var currDim = 0 + val xDimList = ListBuffer[String]() + val yDimList = ListBuffer[String]() + def getCurrDimStr():String = currDim match { + case 0 => throw new RuntimeException("GPUGen: Cannot get current dimension string when the dimension is 0.") + case 1 => "idxX" + //case 2 => "idxY" + case _ => throw new GenerationFailedException("GPUGen: Maximum 2 dimensions for GPU kernels.") + } + def getPrevDimStr():String = currDim match { + case 0 => throw new RuntimeException("GPUGen: Cannot get previous dimension string when the dimension is 0.") + case 1 => throw new RuntimeException("GPUGen: Cannot get previous dimension string when the dimension is 1.") + case 2 => "idxX" + //case 3 => "idxY" + case _ => throw new GenerationFailedException("GPUGen: Maximum 1 dimensions for GPU kernels.") + } + def getNextDimStr():String = currDim match { + case 0 => "idxX" + //case 1 => throw new RuntimeException("GPUGen: Cannot get next dimension string when the dimension is 1.") + case _ => throw new GenerationFailedException("GPUGen: Maximum 1 dimensions for GPU kernels.") + } + def setCurrDimLength(length: String) { + currDim match { + case 0 => throw new RuntimeException("GPUGen: Cannot set dimension length when the dimension is 0.") + case 1 => xDimList += length + //case 2 => yDimList += length + case _ => throw new GenerationFailedException("GPUGen: Maximum 1 dimensions for GPU kernels.") + } + } + val multDimInputs = ListBuffer[Sym[Any]]() + */ + + var helperFuncIdx = 0 + val kernelsList = ArrayBuffer[Exp[Any]]() + val helperFuncsList = ArrayBuffer[String]() + + var tabWidth:Int = 0 def addTab():String = "\t"*tabWidth + var forceParallel = false + + var helperFuncString:StringBuilder = null + var hstream: PrintWriter = null + var helperFuncHdrStream: PrintWriter = null + //var devFuncString:StringBuilder = null var devFuncIdx = 0 + //var devStream: PrintWriter = null + //var headerStream: PrintWriter = null + var isGPUable:Boolean = false + var processingHelperFunc: Boolean = false var isNestedNode: Boolean = false - var outerLoopSize: Exp[Int] = null - var outerLoopSym: Exp[Int] = null - - //TODO: Get rid of this variable - protected var inVars = List[Sym[Any]]() - protected val boundMap = HashMap[Exp[Int],Exp[Int]]() - private val ptrSymSet = HashSet[Sym[Any]]() - - // GPU currently does not use reference types - override def remapWithRef[A](m: Manifest[A]): String = remap(m) - - protected def registerTempAlloc(sym:Sym[Any], tp:Manifest[Any], size:Exp[Int]):String = { - metaData.temps prepend TempAlloc(quote(sym)+"_temp",remap(tp),quote(size)) - quote(sym) + "_temp" + + def emitMultiLoopFunc(func:Block[Any], postfix: String, lastInputs: List[Sym[Any]], stream:PrintWriter): List[String] = { + isNestedNode = true + val tempString = new StringWriter + val tempStream = new PrintWriter(tempString, true) + val header = new StringWriter + val footer = new StringWriter + + val currentTab = tabWidth + tabWidth = 1 + withStream(tempStream) { + emitBlock(func) + } + tabWidth = currentTab + + val inputs = getFreeVarBlock(func,lastInputs).distinct + val paramStr = (inputs++lastInputs).map(ele=>remap(ele.tp)+" "+quote(ele)).mkString(",") + + header.append(devFuncPrefix + " %s dev_%s(%s) {\n".format(remap(getBlockResult(func).tp),postfix,paramStr)) + if(remap(getBlockResult(func).tp) != "void") + footer.append("\treturn %s;\n".format(quote(getBlockResult(func)))) + footer.append("}\n") + stream.print(header) + stream.print(tempString) + stream.print(footer) + + /* + if(loopType=="FOREACH") { + val tr = metaData.outputs.getOrElse(sym,new TransferFunc) + tr.funcHtoD = "" + tr.argsFuncHtoD = List() + tr.funcDtoH = "" + tr.argsFuncDtoH = List() + metaData.outputs.put(sym,tr) + } + */ + isNestedNode = false + inputs.map(quote(_)) } + // MetaData override def hasMetaData: Boolean = true override def getMetaData: String = metaData.toString var metaData: GPUMetaData = null - final class LoopElem(val elemType: String, val types: Map[String,String]) { - val funcs = new HashMap[String,List[String]]() // Mapping of function name to the argument list + final class LoopFunc { + var tpe: String = "" + var hasCond: Boolean = false + var loopFuncInputs: List[String] = Nil + var loopFuncInputs_2: List[String] = Nil + var loopFuncOutputType: String = "" + var loopFuncOutputType_2: String = "" + var loopCondInputs: List[String] = Nil + var loopReduceInputs: List[String] = Nil + var loopReduceInputs_2: List[String] = Nil + var loopReduceParInputs: List[String] = Nil + var loopReduceParInputs_2: List[String] = Nil + var loopZeroInputs: List[String] = Nil + var loopZeroInputs_2: List[String] = Nil override def toString: String = { - "{\"elemType\":\"" + - elemType + - "\",\"types\":" + - types.map(t => "\"" + t._1 + "\":\"" + t._2 + "\"").mkString("{",",","}") + - ",\"funcs\":" + - funcs.map(f => "\"" + f._1 + "\":[" + f._2.map(i => "\"" + i + "\"").mkString(",") + "]").mkString("{",",","}") + - "}" + "\"" + tpe + "\"," + hasCond + ",[" + loopFuncInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopFuncInputs_2.map(i => "\""+ i +"\"").mkString(",") + "]" + + ",\"" + loopFuncOutputType + "\",\"" + loopFuncOutputType_2 + "\",[" + loopCondInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopReduceInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopReduceInputs_2.map(i => "\""+ i +"\"").mkString(",") + "]" + + ",[" + loopReduceParInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopReduceParInputs_2.map(i => "\""+ i +"\"").mkString(",") + "]" + + ",[" + loopZeroInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopZeroInputs_2.map(i => "\""+ i +"\"").mkString(",") + "]" } } - - case class TempAlloc(sym: String, tp: String, size:String) + final class TransferFunc { + var funcHtoD:String = "" + var argsFuncHtoD:List[Sym[Any]] = Nil + var funcDtoH:String = "" + var argsFuncDtoH:List[Sym[Any]] = Nil + //override def toString: String = { } + } - final class GPUMetaData(val kernelInputs: List[Sym[Any]], val auxMeta: ListBuffer[(String,Any)]) { - //val inputs: ListMap[Sym[Any],TransferFunc] = ListMap() - val outputs: ListMap[Sym[Any],LoopElem] = ListMap() - val temps: ListBuffer[TempAlloc] = ListBuffer() + final class GPUMetaData { + val inputs: ListMap[Sym[Any],TransferFunc] = ListMap() + val outputs: ListMap[Sym[Any],TransferFunc] = ListMap() + val temps: ListMap[Sym[Any],TransferFunc] = ListMap() var gpuLibCall: String = "" + var loopFuncs: ListMap[Sym[Any],LoopFunc] = ListMap() override def toString: String = { val out = new StringBuilder out.append("{") //if (kernelFileExt == "cu") { - // out.append("\"gpuInputs\":["+kernelInputs.filter(in => !isPrimitiveType(in.tp)).map(in=>"{\""+quote(in)+"\":[\""+remap(in.tp)+"\"]}").mkString(",")+"],") - out.append("\"gpuOutputs\":{"+outputs.map(o => "\""+quote(o._1)+"\":"+o._2.toString).mkString(",")+"},") - out.append("\"gpuTemps\":["+temps.map(t=>"{\""+t.sym+"\":[\""+t.tp+"\",\""+t.size+"\"]}").mkString(",")+"],") - out.append("\"aux\":{"+auxMeta.map(m => "\"" + m._1 + "\":" + m._2.toString).mkString(",")+"}") + out.append("\"gpuInputs\":["+getKernelInputs.filter(in=>isObjectType(in.tp)).map(in=>"{\""+quote(in)+"\":[\""+remap(in.tp)+"\"]}").mkString(",")+"],") + out.append("\"gpuOutputs\":["+outputs.toList.reverse.map(out=>"{\""+quote(out._1)+"\":[\""+remap(out._1.tp)+"\",["+ out._2.argsFuncHtoD.map("\""+quote(_)+"\"").mkString(",")+"],"+loopFuncs.getOrElse(out._1,new LoopFunc).toString+"]}").mkString(",")+"]") //} //else { //opencl // out.append("\"gpuInputs\":["+getKernelInputs.filter(in=>isObjectType(in.Type)).map(in=>"{\""+quote(in)+"\":[\""+remap(in.Type)+"\",{"+unpackObject(in).map(f => "\"%s\":\"%s\"".format(f._1,remap(f._2)).replaceAll("__global ","")).mkString(",")+"}]}").mkString(",")+"],") @@ -87,13 +224,35 @@ trait GPUCodegen extends CLikeCodegen with AbstractHostTransfer with AbstractDev } } + // Exception Handler function + override def exceptionHandler(e: Exception, outFile:File, kstream:PrintWriter): Unit = { + super.exceptionHandler(e, outFile, kstream) + // TODO: Need to cleanup some data structures + } + override def kernelInit(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultIsVar: Boolean): Unit = { - inVars = vars - boundMap.clear - ptrSymSet.clear + // Set kernel input and output symbols + setKernelInputs(vals) + setKernelOutputs(syms) - //helperFuncString.clear - metaData = new GPUMetaData(vals, new ListBuffer[(String,Any)]()) + // Conditions for not generating GPU kernels (may be relaxed later) + //for (sym <- syms) { + // if((!isObjectType(sym.Type)) && (remap(sym.Type)!="void")) throw new GenerationFailedException("GPUGen: Not GPUable output type : %s".format(remap(sym.Type))) + //} + if((vars.length > 0) || (resultIsVar)) throw new GenerationFailedException("GPUGen: Not GPUable input/output types: Variable") + + // Initialize global variables + //useLocalVar = false + //GPUVarMap.clear + //optimizer = new GPUOptimizer + + //currDim = 0 + //xDimList.clear + //yDimList.clear + //multDimInputs.clear + + helperFuncString.clear + metaData = new GPUMetaData tabWidth = 1 isGPUable = false processingHelperFunc = false @@ -103,8 +262,13 @@ trait GPUCodegen extends CLikeCodegen with AbstractHostTransfer with AbstractDev override def emitKernelHeader(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { if (external) { // CUDA library ops use a C wrapper, so should be generated as a C kernel - super.emitKernelHeader(syms, syms ::: vals, vars, resultType, resultIsVar, external) + stream.println(getDSLHeaders) + super.emitKernelHeader(syms, getKernelOutputs ::: vals, vars, resultType, resultIsVar, external) + return } + val out = new StringBuilder + out.append(getDSLHeaders) + stream.print(out.toString) } override def emitKernelFooter(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { @@ -118,93 +282,17 @@ trait GPUCodegen extends CLikeCodegen with AbstractHostTransfer with AbstractDev // should probably be refactored... tabWidth -= 1 - dsTypesList ++= (syms++vals++vars).map(s => (s.tp,remap(s.tp))) - - // Print helper functions to file stream - helperFuncStream.flush - headerStream.flush - actRecordStream.flush - typesStream.flush - } - - override def emitTransferFunctions() { - for ((tp,name) <- dsTypesList) { - // Emit input copy helper functions for object type inputs - //TODO: For now just iterate over all possible hosts, but later we can pick one depending on the input target - try { - val (recvHeader, recvSource) = emitRecv(tp, Targets.JVM) - if (!helperFuncList.contains(recvHeader)) { - headerStream.println(recvHeader) - helperFuncStream.println(recvSource) - helperFuncList.append(recvHeader) - } - val (recvViewHeader, recvViewSource) = emitRecvView(tp, Targets.JVM) - if (!helperFuncList.contains(recvViewHeader)) { - headerStream.println(recvViewHeader) - helperFuncStream.println(recvViewSource) - helperFuncList.append(recvViewHeader) - } - val (sendUpdateHeader, sendUpdateSource) = emitSendUpdate(tp, Targets.JVM) - if (!helperFuncList.contains(sendUpdateHeader)) { - headerStream.println(sendUpdateHeader) - helperFuncStream.println(sendUpdateSource) - helperFuncList.append(sendUpdateHeader) - } - val (recvUpdateHeader, recvUpdateSource) = emitRecvUpdate(tp, Targets.JVM) - if (!helperFuncList.contains(recvUpdateHeader)) { - headerStream.println(recvUpdateHeader) - helperFuncStream.println(recvUpdateSource) - helperFuncList.append(recvUpdateHeader) - } - val (sendSlaveHeader, sendSlaveSource) = emitSendSlave(tp) - if (!helperFuncList.contains(sendSlaveHeader)) { - headerStream.println(sendSlaveHeader) - helperFuncStream.println(sendSlaveSource) - helperFuncList.append(sendSlaveHeader) - } - val (sendUpdateSlaveHeader, sendUpdateSlaveSource) = emitSendUpdateSlave(tp) - if (!helperFuncList.contains(sendUpdateSlaveHeader)) { - headerStream.println(sendUpdateSlaveHeader) - helperFuncStream.println(sendUpdateSlaveSource) - helperFuncList.append(sendUpdateSlaveHeader) - } - val (recvUpdateSlaveHeader, recvUpdateSlaveSource) = emitRecvUpdateSlave(tp) - if (!helperFuncList.contains(recvUpdateSlaveHeader)) { - headerStream.println(recvUpdateSlaveHeader) - helperFuncStream.println(recvUpdateSlaveSource) - helperFuncList.append(recvUpdateSlaveHeader) - } - - // Emit output copy helper functions for object type inputs - val (sendHeader, sendSource) = emitSend(tp, Targets.JVM) - if (!helperFuncList.contains(sendHeader)) { - headerStream.println(sendHeader) - helperFuncStream.println(sendSource) - helperFuncList.append(sendHeader) - } - val (sendViewHeader, sendViewSource) = emitSendView(tp, Targets.JVM) - if (!helperFuncList.contains(sendViewHeader)) { - headerStream.println(sendViewHeader) - helperFuncStream.println(sendViewSource) - helperFuncList.append(sendViewHeader) - } - val (recvSlaveHeader, recvSlaveSource) = emitRecvSlave(tp) - if (!helperFuncList.contains(recvSlaveHeader)) { - headerStream.println(recvSlaveHeader) - helperFuncStream.println(recvSlaveSource) - helperFuncList.append(recvSlaveHeader) - } - } - catch { - case e: GenerationFailedException => - helperFuncStream.flush - headerStream.flush - case e: Exception => throw(e) - } + // Emit input copy helper functions for object type inputs + for(v <- vals if isObjectType(v.tp)) { + helperFuncString.append(emitCopyInputHtoD(v, syms, copyInputHtoD(v))) + helperFuncString.append(emitCopyMutableInputDtoH(v, syms, copyMutableInputDtoH(v))) } - helperFuncStream.flush - headerStream.flush + // Print helper functions to file stream + hstream.print(helperFuncString) + hstream.flush + helperFuncHdrStream.flush + //headerStream.flush } def registerKernel(syms: List[Sym[Any]]) { @@ -215,6 +303,236 @@ trait GPUCodegen extends CLikeCodegen with AbstractHostTransfer with AbstractDev } } + override def remap[A](m: Manifest[A]) : String = { + checkGPUableType(m) + if (m.erasure == classOf[Variable[AnyVal]]) + remap(m.typeArguments.head) + else { + m.toString match { + case "Boolean" => "bool" + case "Byte" => "char" + case "Char" => "CHAR" + case "Short" => "short" + case "Int" => "int" + case "Long" => "long" + case "Float" => "float" + case "Double" => "double" + case "Unit" => "void" + case _ => throw new Exception("GPUGen: remap(m) : GPUable Type %s does not have mapping table.".format(m.toString)) + } + } + } + + def isPrimitiveType[A](m: Manifest[A]) : Boolean = { + m.toString match { + case "Boolean" | "Byte" | "Char" | "Short" | "Int" | "Long" | "Float" | "Double" => true + case _ => false + } + } + + def isVariableType[A](m: Manifest[A]) : Boolean = { + if(m.erasure == classOf[Variable[AnyVal]]) true + else false + } + + // Check the type and generate Exception if the type is not GPUable + def checkGPUableType[A](m: Manifest[A]) : Unit = { + if(!isGPUableType(m)) + throw new GenerationFailedException("GPUGen: Type %s is not a GPUable Type.".format(m.toString)) + } + + // All the types supported by GPU Generation + def isGPUableType[A](m : Manifest[A]) : Boolean = { + if(!isObjectType(m) && !isPrimitiveType(m) && !isVoidType(m) && !isVariableType(m)) + false + else + true + } + + def unpackObject[A](sym: Sym[Any]) : Map[String,Manifest[_]] = remap(sym.tp) match { + case _ => throw new GenerationFailedException("GPUCodegen: Type %s cannot be unpacked.".format(sym.tp.toString)) + } + + def copyInputHtoD(sym: Sym[Any]) : String + def copyOutputDtoH(sym: Sym[Any]) : String + def copyMutableInputDtoH(sym: Sym[Any]) : String + def allocOutput(newSym: Sym[_], sym: Sym[_], reset: Boolean = false) : Unit + def allocReference(newSym: Sym[Any], sym: Sym[Any]) : Unit + def positionMultDimInputs(sym: Sym[Any]) : String + def cloneObject(sym: Sym[Any], src: Sym[Any]) : String + + + /******************************************************* + * Methods below are for emitting helper functions + *******************************************************/ + // TODO: Change the metadata function names + + // For object type inputs, allocate GPU memory and copy from CPU to GPU. + def emitCopyInputHtoD(sym: Sym[Any], ksym: List[Sym[Any]], contents: String) : String = { + val out = new StringBuilder + val funcName = "copyInputHtoD_%s_%s".format(ksym.map(quote).mkString(""),quote(sym)) + if(isObjectType(sym.tp) && !helperFuncsList.contains(funcName)) { + helperFuncsList += funcName + out.append("%s *%s(JNIEnv *env, jobject obj)".format(remap(sym.tp),funcName)) + helperFuncHdrStream.append(out.toString + ";\n") + out.append("{\n") + out.append(contents) + out.append("}\n") + out.toString + } + else "" + } + + // For mutable inputs, copy the mutated datastructure from GPU to CPU after the kernel is terminated + def emitCopyMutableInputDtoH(sym: Sym[Any], ksym: List[Sym[Any]], contents: String): String = { + val out = new StringBuilder + val funcName = "copyMutableInputDtoH_%s_%s".format(ksym.map(quote).mkString(""),quote(sym)) + if(isObjectType(sym.tp) && !helperFuncsList.contains(funcName)) { + helperFuncsList += funcName + out.append("void %s(JNIEnv *env, jobject obj, %s *%s_ptr)".format(funcName,remap(sym.tp),quote(sym))) + helperFuncHdrStream.append(out.toString + ";\n") + out.append("{\n") + out.append("%s %s = *(%s_ptr);\n".format(remap(sym.tp),quote(sym),quote(sym))) + out.append(contents) + out.append("}\n") + out.toString + } + else "" + } + + def emitAllocOutput(sym: Sym[Any], ksym: List[Sym[Any]], contents: String, args: List[Sym[Any]], aV: Sym[Any]): String = { + val out = new StringBuilder + val funcName = "allocFunc_%s".format(quote(sym)) + if(helperFuncsList contains funcName) return "" + helperFuncsList += funcName + + if(!isPrimitiveType(sym.tp)) { + val paramStr = args.map(ele => + if(isPrimitiveType(ele.tp)) remap(ele.tp) + " " + quote(ele) + else remap(ele.tp) + " *" + quote(ele) + "_ptr" + ).mkString(",") + val derefParams = args.map(ele=> + if(isPrimitiveType(ele.tp)) "" + else "\t%s %s = *(%s_ptr);\n".format(remap(ele.tp),quote(ele),quote(ele)) + ).mkString("") + out.append("%s *%s(%s %s)".format(remap(sym.tp), funcName, paramStr, if(args.nonEmpty) ",int size" else "int size")) + helperFuncHdrStream.append(out.toString + ";\n") + out.append("{\n") + out.append(derefParams) + //out.append("\t%s *%s_ptr = new %s(size);\n".format(remap(aV.tp),quote(aV),remap(aV.tp))) + //out.append("\t%s %s = *%s_ptr;\n".format(remap(aV.tp),quote(aV),quote(aV))) + out.append(contents) + out.append("}\n") + out.toString + } + else { + out.append("%s *%s(void)".format(remap(sym.tp),funcName)) + helperFuncHdrStream.append(out.toString + ";\n") + out.append("{\n") + out.append(contents) + out.append("}\n") + out.toString + } + } + + def emitCopyOutputDtoH(sym: Sym[Any], ksym: List[Sym[Any]], contents: String): String = { + val out = new StringBuilder + val funcName = "copyOutputDtoH_%s".format(quote(sym)) + if(helperFuncsList contains funcName) return "" + helperFuncsList += funcName + + if(isObjectType(sym.tp)) { + out.append("jobject %s(JNIEnv *env,%s)".format(funcName,remap(sym.tp)+" *"+quote(sym)+"_ptr")) + helperFuncHdrStream.append(out.toString + ";\n") + out.append("{\n") + out.append("\t%s %s = *(%s_ptr);\n".format(remap(sym.tp),quote(sym),quote(sym))) + out.append(contents) + out.append("}\n") + out.toString + } + else { + out.append("%s %s(JNIEnv *env,%s)".format(remap(sym.tp),funcName,remap(sym.tp)+" *"+quote(sym))) + helperFuncHdrStream.append(out.toString + ";\n") + out.append("{\n") + out.append(contents) + out.append("}\n") + out.toString + } + } + + /* emitAllocFunc method emits code for allocating the output memory of a kernel, + and copying it to CPU memory with allocation of new object in CPU */ + //TODO: Separate output and temporary allocations + def emitAllocFunc(sym:Sym[Any], allocFunc:Block[Any], aV:Sym[Any]=null, size:Exp[Any]=null) { + processingHelperFunc = true + val tempString = new StringWriter + val tempString2 = new StringWriter + val tempStream = new PrintWriter(tempString,true) + + // Get free variables (exclude the arrayVariable) + val inputs = if(allocFunc==null) Nil + else getFreeVarBlock(allocFunc,List(aV)) + + // Register metadata + val tr = metaData.outputs.getOrElse(sym,new TransferFunc) + tr.argsFuncHtoD = inputs + metaData.outputs.put(sym,tr) + + // Get the body (string) of the allocation function in tempString + if(allocFunc!=null) { + withStream(tempStream) { + emitBlock(allocFunc) + } + tempString.append("\treturn %s_ptr;\n".format(quote(getBlockResult(allocFunc)))) + } + else { + tempString.append("\treturn %s_ptr;\n".format(quote(sym))) + } + + // Emit the full allocation function + val allocOutputStr = emitAllocOutput(sym, null, tempString.toString, inputs, aV) + + // Generate copy (D->H) helper function + tempString2.append(copyOutputDtoH(sym)) + val copyOutputStr = emitCopyOutputDtoH(sym, null, tempString2.toString) + + // Write to helper function string + helperFuncString.append(allocOutputStr) + helperFuncString.append(copyOutputStr) + + processingHelperFunc = false + } + + def emitAllocFuncPrimitive(sym:Sym[Any]) { + processingHelperFunc = true + assert(isPrimitiveType(sym.tp)) + + val tempString = new StringWriter + val tempString2 = new StringWriter + + // Register metadata + val tr = metaData.outputs.getOrElse(sym,new TransferFunc) + tr.argsFuncHtoD = Nil + metaData.outputs.put(sym,tr) + + tempString.append("\t%s *ptr;\n".format(remap(sym.tp))) + tempString.append("\tDeliteCudaMalloc((void**)&ptr, sizeof(%s));\n".format(remap(sym.tp))) + tempString.append("\treturn ptr;\n") + + // Emit the full allocation function + val allocOutputStr = emitAllocOutput(sym, null, tempString.toString, null, null) + + // Generate copy (D->H) helper function + tempString2.append(copyOutputDtoH(sym)) + val copyOutputStr = emitCopyOutputDtoH(sym, null, tempString2.toString) + + // Write to helper function string + helperFuncString.append(allocOutputStr) + helperFuncString.append(copyOutputStr) + + processingHelperFunc = false + } + def checkGPUAlloc(sym: Sym[Any]) { if(!processingHelperFunc) { if (isNestedNode) { @@ -240,21 +558,4 @@ trait GPUCodegen extends CLikeCodegen with AbstractHostTransfer with AbstractDev println(msg) println("Stack Trace: " + quotePos(sym)) } - - def clearPtrDef() = ptrSymSet.clear - - def registerPtrDef(sym: Sym[Any]): Unit = ptrSymSet.add(sym) - - def emitPtrDef(sym: Sym[Any], rhs: Exp[Any]): Unit = { - if(processingHelperFunc && !isPrimitiveType(sym.tp)) { - rhs match { - case s@Sym(_) => - if(!ptrSymSet.contains(s)) throw new GenerationFailedException("Ptr is not defined for " + quote(s)) - emitValDef(quote(sym) + "_ptr", sym.tp, quote(rhs) + "_ptr") - registerPtrDef(s) - case _ => throw new GenerationFailedException("Ptr is not defined for " + quote(rhs)) - } - } - } - } diff --git a/src/internal/GenericCodegen.scala b/src/internal/GenericCodegen.scala index 3e9639fe..6e5f7201 100644 --- a/src/internal/GenericCodegen.scala +++ b/src/internal/GenericCodegen.scala @@ -1,9 +1,10 @@ -package scala.lms +package scala.virtualization.lms package internal import util.GraphUtil import java.io.{File, PrintWriter} import scala.reflect.RefinedManifest +import scala.collection.mutable.{Map => MMap} trait GenericCodegen extends BlockTraversal { val IR: Expressions @@ -11,25 +12,36 @@ trait GenericCodegen extends BlockTraversal { // TODO: should some of the methods be moved into more specific subclasses? - def deviceTarget: Targets.Value = throw new Exception("deviceTarget is not defined for this codegen.") - def hostTarget: Targets.Value = Targets.getHostTarget(deviceTarget) - def isAcceleratorTarget: Boolean = hostTarget != deviceTarget - def kernelFileExt = "" - def emitFileHeader(): Unit = {} def emitKernelHeader(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = {} def emitKernelFooter(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = {} + var analysisResults: MMap[String,Any] = null.asInstanceOf[MMap[String,Any]] + + /** + * List of transformers that should be applied before code generation + */ + var transformers: List[AbstractTransformer] = List[AbstractTransformer]() + + def performTransformations[A:Manifest](body: Block[A]): Block[A] = { + var transformedBody = body + transformers foreach { trans => + transformedBody = trans.apply[A](body.asInstanceOf[trans.IR.Block[A]]).asInstanceOf[this.Block[A]] + } + transformedBody + } + + def emitFileHeader(): Unit = {} + def emitFunctions(): Unit = {} + // Initializer - def initializeGenerator(buildDir:String, args: Array[String]): Unit = { } + def initializeGenerator(buildDir:String, args: Array[String], _analysisResults: MMap[String,Any]): Unit = { analysisResults = _analysisResults } def finalizeGenerator(): Unit = {} def kernelInit(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultIsVar: Boolean): Unit = {} - def emitDataStructures(stream: PrintWriter): Unit = {} + def emitDataStructures(out: PrintWriter): Unit = {} def emitDataStructures(path: String): Unit = {} - def getDataStructureHeaders(): String = "" - def emitTransferFunctions(): Unit = {} - + def dataPath = { "data" + java.io.File.separator } @@ -50,15 +62,24 @@ trait GenericCodegen extends BlockTraversal { stream.close() } - + + def runTransformations[A:Manifest](body: Block[A]): Block[A] = body + // exception handler def exceptionHandler(e: Exception, outFile:File, kstream:PrintWriter): Unit = { kstream.close() outFile.delete } - // optional type remapping (default is identity) - def remap(s: String): String = s + /** + * optional type remapping (default is identity) + * except that we should replace all '$' by '.' + * because inner class names might contain $ sign + */ + def remap(s: String): String = s match { + case "java.lang.Character" => "Character" + case _ => s.replace('$', '.') + } def remap[A](s: String, method: String, t: Manifest[A]) : String = remap(s, method, t.toString) def remap(s: String, method: String, t: String) : String = s + method + "[" + remap(t) + "]" def remap[A](m: Manifest[A]): String = m match { @@ -70,18 +91,18 @@ trait GenericCodegen extends BlockTraversal { val targs = m.typeArguments if (targs.length > 0) { val ms = m.toString - ms.take(ms.indexOf("[")+1) + targs.map(tp => remap(tp)).mkString(", ") + "]" + remap(ms.take(ms.indexOf("["))) + "[" + targs.map(tp => remap(tp)).mkString(", ") + "]" } - else m.toString + else remap(m.toString) } def remapImpl[A](m: Manifest[A]): String = remap(m) //def remapVar[A](m: Manifest[Variable[A]]) : String = remap(m.typeArguments.head) - - def remapHost[A](m: Manifest[A]): String = remap(m).replaceAll(deviceTarget.toString,hostTarget.toString) def hasMetaData: Boolean = false def getMetaData: String = null + def getDSLHeaders: String = null + // --------- var stream: PrintWriter = _ @@ -100,29 +121,36 @@ trait GenericCodegen extends BlockTraversal { } def emitBlock(y: Block[Any]): Unit = traverseBlock(y) + + def emitBlockResult[A: Manifest](b: Block[A]) { + if (remap(manifest[A]) != "Unit") stream.println(quote(getBlockResult(b))) + } def emitNode(sym: Sym[Any], rhs: Def[Any]): Unit = { throw new GenerationFailedException("don't know how to generate code for: " + rhs) } def emitValDef(sym: Sym[Any], rhs: String): Unit - def emitVarDecl(sym: Sym[Any]): Unit = throw new GenerationFailedException("don't know how to emit variable declaration " + quote(sym)) - def emitAssignment(sym: Sym[Any], rhs: String): Unit = throw new GenerationFailedException("don't know how to emit variable assignment " + quote(sym)) + + def emitSource0[R : Manifest](f: () => Exp[R], className: String, stream: PrintWriter, dynamicReturnType: String = null): List[(Sym[Any], Any)] = { + val body = reifyBlock(f()) + emitSource(List(), body, className, stream, dynamicReturnType) + } - def emitSource[T : Manifest, R : Manifest](f: Exp[T] => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { - val s = fresh[T] - val body = reifyBlock(f(s)) - emitSource(List(s), body, className, stream) + def emitSource1[T1: Manifest, R : Manifest](f: (Exp[T1]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val body = reifyBlock(f(s1)) + emitSource(List(s1), body, className, stream) } - def emitSource2[T1 : Manifest, T2 : Manifest, R : Manifest](f: (Exp[T1], Exp[T2]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + def emitSource2[T1: Manifest, T2: Manifest, R : Manifest](f: (Exp[T1], Exp[T2]) => Exp[R], className: String, stream: PrintWriter, dynamicReturnType: String = null): List[(Sym[Any], Any)] = { val s1 = fresh[T1] val s2 = fresh[T2] val body = reifyBlock(f(s1, s2)) - emitSource(List(s1, s2), body, className, stream) + emitSource(List(s1, s2), body, className, stream, dynamicReturnType) } - def emitSource3[T1 : Manifest, T2 : Manifest, T3 : Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + def emitSource3[T1: Manifest, T2: Manifest, T3: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { val s1 = fresh[T1] val s2 = fresh[T2] val s3 = fresh[T3] @@ -130,7 +158,7 @@ trait GenericCodegen extends BlockTraversal { emitSource(List(s1, s2, s3), body, className, stream) } - def emitSource4[T1 : Manifest, T2 : Manifest, T3 : Manifest, T4 : Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + def emitSource4[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { val s1 = fresh[T1] val s2 = fresh[T2] val s3 = fresh[T3] @@ -138,8 +166,8 @@ trait GenericCodegen extends BlockTraversal { val body = reifyBlock(f(s1, s2, s3, s4)) emitSource(List(s1, s2, s3, s4), body, className, stream) } - - def emitSource5[T1 : Manifest, T2 : Manifest, T3 : Manifest, T4 : Manifest, T5 : Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + + def emitSource5[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { val s1 = fresh[T1] val s2 = fresh[T2] val s3 = fresh[T3] @@ -148,6 +176,238 @@ trait GenericCodegen extends BlockTraversal { val body = reifyBlock(f(s1, s2, s3, s4, s5)) emitSource(List(s1, s2, s3, s4, s5), body, className, stream) } + + def emitSource6[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6)) + emitSource(List(s1, s2, s3, s4, s5, s6), body, className, stream) + } + def emitSource7[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7), body, className, stream) + } + def emitSource8[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8), body, className, stream) + } + def emitSource9[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9), body, className, stream) + } + def emitSource10[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10), body, className, stream) + } + def emitSource11[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, T11: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10], Exp[T11]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val s11 = fresh[T11] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11), body, className, stream) + } + def emitSource12[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, T11: Manifest, T12: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10], Exp[T11], Exp[T12]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val s11 = fresh[T11] + val s12 = fresh[T12] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12), body, className, stream) + } + def emitSource13[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, T11: Manifest, T12: Manifest, T13: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10], Exp[T11], Exp[T12], Exp[T13]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val s11 = fresh[T11] + val s12 = fresh[T12] + val s13 = fresh[T13] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13), body, className, stream) + } + def emitSource14[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, T11: Manifest, T12: Manifest, T13: Manifest, T14: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10], Exp[T11], Exp[T12], Exp[T13], Exp[T14]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val s11 = fresh[T11] + val s12 = fresh[T12] + val s13 = fresh[T13] + val s14 = fresh[T14] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14), body, className, stream) + } + def emitSource15[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, T11: Manifest, T12: Manifest, T13: Manifest, T14: Manifest, T15: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10], Exp[T11], Exp[T12], Exp[T13], Exp[T14], Exp[T15]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val s11 = fresh[T11] + val s12 = fresh[T12] + val s13 = fresh[T13] + val s14 = fresh[T14] + val s15 = fresh[T15] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15), body, className, stream) + } + def emitSource16[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, T11: Manifest, T12: Manifest, T13: Manifest, T14: Manifest, T15: Manifest, T16: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10], Exp[T11], Exp[T12], Exp[T13], Exp[T14], Exp[T15], Exp[T16]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val s11 = fresh[T11] + val s12 = fresh[T12] + val s13 = fresh[T13] + val s14 = fresh[T14] + val s15 = fresh[T15] + val s16 = fresh[T16] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16), body, className, stream) + } + def emitSource17[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, T11: Manifest, T12: Manifest, T13: Manifest, T14: Manifest, T15: Manifest, T16: Manifest, T17: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10], Exp[T11], Exp[T12], Exp[T13], Exp[T14], Exp[T15], Exp[T16], Exp[T17]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val s11 = fresh[T11] + val s12 = fresh[T12] + val s13 = fresh[T13] + val s14 = fresh[T14] + val s15 = fresh[T15] + val s16 = fresh[T16] + val s17 = fresh[T17] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17), body, className, stream) + } + def emitSource18[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, T11: Manifest, T12: Manifest, T13: Manifest, T14: Manifest, T15: Manifest, T16: Manifest, T17: Manifest, T18: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10], Exp[T11], Exp[T12], Exp[T13], Exp[T14], Exp[T15], Exp[T16], Exp[T17], Exp[T18]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val s11 = fresh[T11] + val s12 = fresh[T12] + val s13 = fresh[T13] + val s14 = fresh[T14] + val s15 = fresh[T15] + val s16 = fresh[T16] + val s17 = fresh[T17] + val s18 = fresh[T18] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18), body, className, stream) + } + def emitSource19[T1: Manifest, T2: Manifest, T3: Manifest, T4: Manifest, T5: Manifest, T6: Manifest, T7: Manifest, T8: Manifest, T9: Manifest, T10: Manifest, T11: Manifest, T12: Manifest, T13: Manifest, T14: Manifest, T15: Manifest, T16: Manifest, T17: Manifest, T18: Manifest, T19: Manifest, R : Manifest](f: (Exp[T1], Exp[T2], Exp[T3], Exp[T4], Exp[T5], Exp[T6], Exp[T7], Exp[T8], Exp[T9], Exp[T10], Exp[T11], Exp[T12], Exp[T13], Exp[T14], Exp[T15], Exp[T16], Exp[T17], Exp[T18], Exp[T19]) => Exp[R], className: String, stream: PrintWriter): List[(Sym[Any], Any)] = { + val s1 = fresh[T1] + val s2 = fresh[T2] + val s3 = fresh[T3] + val s4 = fresh[T4] + val s5 = fresh[T5] + val s6 = fresh[T6] + val s7 = fresh[T7] + val s8 = fresh[T8] + val s9 = fresh[T9] + val s10 = fresh[T10] + val s11 = fresh[T11] + val s12 = fresh[T12] + val s13 = fresh[T13] + val s14 = fresh[T14] + val s15 = fresh[T15] + val s16 = fresh[T16] + val s17 = fresh[T17] + val s18 = fresh[T18] + val s19 = fresh[T19] + val body = reifyBlock(f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19)) + emitSource(List(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19), body, className, stream) + } /** * @param args List of symbols bound to `body` @@ -155,16 +415,25 @@ trait GenericCodegen extends BlockTraversal { * @param className Name of the generated identifier * @param stream Output stream */ - def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, stream: PrintWriter): List[(Sym[Any], Any)] // return free static data in block + def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, stream: PrintWriter, dynamicReturnType: String = null, serializable: Boolean = false): List[(Sym[Any], Any)] // return free static data in block + + def quote(x: Exp[Any]) : String = quote(x, false) - def quote(x: Exp[Any]) : String = x match { - case Const(s: String) => "\""+s.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n")+"\"" // TODO: more escapes? - case Const(c: Char) => "'"+(""+c).replace("'", "\\'").replace("\n", "\\n")+"'" + def quote(x: Exp[Any], forcePrintSymbol: Boolean = false) : String = x match { + case Const(s: String) => "\""+s.replace("\"", "\\\"").replace("\n", "\\n")+"\"" // TODO: more escapes? + case Const(c: Char) => "'"+c+"'" case Const(f: Float) => "%1.10f".format(f) + "f" case Const(l: Long) => l.toString + "L" case Const(null) => "null" case Const(z) => z.toString - case Sym(n) => "x"+n + case s@Sym(n) => { + if (forcePrintSymbol) "x" + n + // Avoid printing symbols that are of type null + else if (s.tp.toString == "Unit") "" + else "x"+n + } + case x@_ if x == Const(null) => "null" + case null => "null" case _ => throw new RuntimeException("could not quote " + x) } @@ -175,25 +444,13 @@ trait GenericCodegen extends BlockTraversal { super.reset } - def isPrimitiveType[A](m: Manifest[A]) : Boolean = { - m.toString match { - case "Boolean" | "Byte" | "Char" | "Short" | "Int" | "Long" | "Float" | "Double" => true - case _ => false - } - } - def isVoidType[A](m: Manifest[A]) : Boolean = { m.toString match { case "Unit" => true case _ => false } } - - def isVariableType[A](m: Manifest[A]) : Boolean = { - if(m.erasure == classOf[Variable[AnyVal]]) true - else false - } - + // Provides automatic quoting and remapping in the gen string interpolater implicit class CodegenHelper(sc: StringContext) { def printToStream(arg: Any): Unit = { @@ -205,6 +462,7 @@ trait GenericCodegen extends BlockTraversal { case e: Exp[_] => quote(e) case m: Manifest[_] => remap(m) case s: String => s + case null => "null" case _ => throw new RuntimeException(s"Could not quote or remap $arg") } @@ -235,10 +493,41 @@ trait GenericCodegen extends BlockTraversal { -trait GenericNestedCodegen extends NestedBlockTraversal with GenericCodegen { - val IR: Expressions with Effects +trait GenericNestedCodegen extends NestedBlockTraversal with GenericCodegen { self => + val IR: Expressions with Effects with LoweringTransform import IR._ + /* Lowering stuff */ + def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]): Unit = { +// println("Lowering " + sym + " with def " + rhs ) + rhs match { + case Reflect(s, u, effects) => lowerNode(sym, s) + case dflt@_ => { + //System.out.println("Don't know how to lower symbol " + dflt + ".") + () + } + } + } + + object HIRLowering extends LoweringTransformer + object LIRLowering extends LoweringTransformer + object LIRTraversal extends NestedBlockTraversal { + val IR: self.IR.type = self.IR + def apply[A: Manifest](b: Block[A]) = traverseBlock(b) + override def traverseStm(stm: Stm): Unit = stm match { + case TP(sym, rhs) => lowerNode(sym, rhs)(sym.tp) + case _ => throw new GenerationFailedException(s"don't know how to generate code for statement: $stm during LIRTraversal") + } + } + + def remapManifest[A:Manifest](m: Sym[A]): Manifest[_] = manifest[A] + + override def runTransformations[A:Manifest](body: Block[A]): Block[A] = { + val b = HIRLowering.run(body) + LIRTraversal(b) + LIRLowering.run(b) + } + override def traverseStm(stm: Stm) = super[GenericCodegen].traverseStm(stm) override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { @@ -257,11 +546,10 @@ trait GenericNestedCodegen extends NestedBlockTraversal with GenericCodegen { // Allows the gen string interpolator to perform emitBlock when passed a Block implicit class NestedCodegenHelper(sc: StringContext) extends CodegenHelper(sc) { - override def printToStream(arg: Any): Unit = arg match { + override def printToStream(arg: Any): Unit = arg match { case NestedBlock(b) => emitBlock(b) case b: Block[_] => stream.print(quoteOrRemap(getBlockResult(b))) case _ => stream.print(quoteOrRemap(arg)) } } - } diff --git a/src/internal/GraphVizDependencyGraphExport.scala b/src/internal/GraphVizDependencyGraphExport.scala new file mode 100644 index 00000000..8da94fc5 --- /dev/null +++ b/src/internal/GraphVizDependencyGraphExport.scala @@ -0,0 +1,214 @@ +package scala.virtualization.lms +package internal + +import java.io.{File, FileWriter, PrintWriter} +import scala.virtualization.lms.util.ReflectionUtil +import scala.reflect.SourceContext + +/** + * This code-generator, actually generates DependencyGraph + * between IR nodes graph in GraphViz format + * It works similar to other codeg-generators like + * ScalaCodegen or etc. + */ +trait GraphVizDependencyGraphExport extends GenericCodegen with NestedBlockTraversal { self => + val IR: ExtendedExpressions with Effects + import IR._ + + val GraphNodeKindInput = "input" + val GraphNodeKindOutput = "output" + + var levelCounter = 0; + + /** + * Produces IR graph node representation string, given: + * - a: node's symbol + * - kind: meta-data for the shape of node + * (can be GraphNodeKindInput, GraphNodeKindOutput + * , or any name for special nodes) + * - rhs: definition of this node (for finding dependencies) + */ + def getGraphNodeString[A](a: Sym[_], kind: String, rhs: Def[A]): String = { + var atp = remap(a.tp).toString; + + val extra = kind match { + case GraphNodeKindInput => "" + case _ => "shape=record" + } + + var indentation = indentString(levelCounter) + var output = { + indentation + "\"" + quote(a, true) + "\" [ " + extra + + " label = <" + getNodeLabel(a) + ":" + + atp + " = " + kind + ">];" + } + indentation = indentString(levelCounter+1) + if(rhs != null) { + ReflectionUtil.caseNameTypeValues(rhs) foreach { + x => if(x._2 == classOf[Block[A]]) { + val blk: Block[A] = x._3.asInstanceOf[Block[A]] + focusExactScope(blk) { levelScope => + val clusterName: String = findSymString(blk.res, levelScope) + val clusterStartingElem: String = findSymString(Const(0), levelScope) + if(clusterName != "") { + output += "\n"+indentation+"\"" + quote(a,true) + + "\" -> \"" + clusterStartingElem + + "\" [lhead=cluster_"+clusterName+" color=gray];" + } + } + emitBlock(blk) + } else if(x._2 == classOf[Exp[A]]) { + x._3 match { + case s:Sym[_] => { + output += "\n"+indentation+"\"" + quote(s,true) + + "\" -> \"" + quote(a,true) + "\";" + } + case _ => + } + } else if (x._2 == classOf[Variable[A]]) { + x._3.asInstanceOf[Variable[A]].e match { + case s:Sym[_] => { + output += "\n"+indentation+"\"" + quote(s,true) + + "\" -> \"" + quote(a,true) + "\";" + } + case _ => + } + } + } + } + + output + } + + override def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, out: PrintWriter, dynamicReturnType: String = null, serializable: Boolean = false) = { + + val sA = remap(manifest[A]) + + // TODO - reflect this static data with some (if any exists) representation in the graph + val staticData = getFreeDataBlock(body) + + withStream(out) { + levelCounter+=2 + val indentation = indentString(levelCounter-1) + val indentationPlus1 = indentString(levelCounter) + + stream.println(indentation + "subgraph cluster" + className + " {") + + emitFileHeader() + + var transformedBody = performTransformations(body) + + stream.println(args.map( a => getGraphNodeString(a, GraphNodeKindInput, null)).mkString("\n")) + emitBlock(transformedBody) + val res = quote(getBlockResult(transformedBody)) + if(res != "()" && res.isInstanceOf[Sym[_]]) { + stream.print("\n" + getGraphNodeString(res.asInstanceOf[Sym[_]], GraphNodeKindOutput, null)) + } + + stream.println("\n"+indentationPlus1+"label = \"" + className + "\";") + stream.println(indentationPlus1+"node [style=filled];") + stream.println(indentationPlus1+"color=blue;") + stream.println(indentation+"}") + levelCounter-=2 + } + + staticData + } + + override def traverseBlockFocused[A](block: Block[A]): Unit = { + focusExactScope(block) { levelScope => + val clusterName: String = findSymString(block.res, levelScope) + + val indentation = indentString(levelCounter) + val indentationPlus1 = indentString(levelCounter+1) + + if(clusterName != "") { + stream.println(indentation+"subgraph cluster_" + clusterName + " {") + } + traverseStmsInBlock(levelScope) + if(clusterName != "") { + stream.println("\n"+indentationPlus1+"label = \"" + clusterName + "\";") + stream.println(indentationPlus1+"node [style=filled];") + stream.println(indentationPlus1+"color=red;") + stream.println(indentation+"}") + } + } + } + + override def traverseStmsInBlock[A](stms: List[Stm]): Unit = { + levelCounter+=1 + stms foreach traverseStm + levelCounter-=1 + } + + override def traverseStm(stm: Stm) = stm match { + case TP(sym, rhs) => rhs match { + case Reflect(s, u, effects) => stream.println(getGraphNodeString(sym, s+"", s)) + case Reify(s, u, effects) => // just ignore -- effects are accounted for in emitBlock + case _ => stream.println(getGraphNodeString(sym, rhs+"", rhs)) + } + case _ => throw new GenerationFailedException("don't know how to generate code for statement: " + stm) + } + + /** + * This method produces the symbol name for a block, given: + * - an Exp for block result + * - list of statements in block + * returns: + * - in the case that block result is a symbol => symbol name + * - in the case that block result is a constant => + * first symbol name in the statements list + */ + def findSymString(e: Exp[_], stms: List[Stm]): String = { + def findFirstSymString: String = { + stms match { + case head :: tail => findSymString(head.asInstanceOf[TP[_]].sym, tail) + case Nil => "" + } + } + + e match { + case Const(x) => findFirstSymString + case s@Sym(n) => quote(s, true) + } + } + + /** + * It is possible to print more meta-data in the node-label + * by overriding this method + */ + def getNodeLabel(s: Sym[_]): String = quote(s, true); + + /** + * utility method for generating proper indentation prefix + * for given level. + */ + private def indentString(level: Int): String = { + def indentString(level: Int, acc: String): String = { + if(level <= 0) acc + else indentString(level - 1 , acc + " ") + } + indentString(level, "") + } + + // emitValDef is not used in this code generator + def emitValDef(sym: Sym[Any], rhs: String): Unit = {} + + override def performTransformations[A:Manifest](body: Block[A]): Block[A] = { + val transformedBody = super.performTransformations[A](body) + val fixer = new SymMetaDataFixerTransform{ val IR: self.IR.type = self.IR } + fixer.traverseBlock(transformedBody.asInstanceOf[fixer.Block[A]]) + transformedBody + } + + override def remap(s: String): String = { + val rs = super.remap(s) + val lastDot = rs.lastIndexOf('.') + val len = rs.length + if(lastDot > 0 && lastDot+1 < len) { + rs.substring(lastDot+1, len) + } else { + rs + } + } +} diff --git a/src/internal/GraphVizExport.scala b/src/internal/GraphVizExport.scala index a01ee214..fb11b876 100644 --- a/src/internal/GraphVizExport.scala +++ b/src/internal/GraphVizExport.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal import java.io.{PrintWriter, FileOutputStream} diff --git a/src/internal/OpenCLCodegen.scala b/src/internal/OpenCLCodegen.scala index 321cd47f..7ec7b862 100755 --- a/src/internal/OpenCLCodegen.scala +++ b/src/internal/OpenCLCodegen.scala @@ -1,43 +1,168 @@ -package scala.lms +package scala.virtualization.lms package internal import java.io.{FileWriter, StringWriter, PrintWriter, File} import java.util.ArrayList import collection.mutable.{ListBuffer, ArrayBuffer, LinkedList, HashMap} +import collection.mutable.{Map => MMap} import collection.immutable.List._ -trait OpenCLCodegen extends GPUCodegen with CppHostTransfer with OpenCLDeviceTransfer { +trait OpenCLCodegen extends GPUCodegen { val IR: Expressions import IR._ - override def deviceTarget: Targets.Value = Targets.OpenCL - override def kernelFileExt = "cl" override def toString = "opencl" - override def initializeGenerator(buildDir:String, args: Array[String]): Unit = { + override def initializeGenerator(buildDir:String, args: Array[String], _analysisResults: MMap[String,Any]): Unit = { val outDir = new File(buildDir) outDir.mkdirs - helperFuncStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.cpp")) - helperFuncStream.println("#include \"" + deviceTarget + "helperFuncs.h\"") + helperFuncIdx = 0 + helperFuncString = new StringBuilder + hstream = new PrintWriter(new FileWriter(buildDir + "helperFuncs.cpp")) + helperFuncHdrStream = new PrintWriter(new FileWriter(buildDir + "helperFuncs.h")) - typesStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "types.h")) - //TODO: Put all the DELITE APIs declarations somewhere - headerStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.h")) - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include ") - headerStream.println("#include \"DeliteOpenCL.h\"") - headerStream.println("#include \"" + deviceTarget + "types.h\"") - headerStream.println(getDataStructureHeaders()) - - super.initializeGenerator(buildDir, args) + hstream.print("#include \"helperFuncs.h\"\n") + helperFuncHdrStream.print(getDSLHeaders) + helperFuncHdrStream.print("#include \n") + helperFuncHdrStream.print("#include \n") + helperFuncHdrStream.print("#include \n\n") + helperFuncHdrStream.print("#define CHAR short\n") + helperFuncHdrStream.print("#define jCHAR jshort\n") + helperFuncHdrStream.print("#include \"DeliteOpenCL.h\"\n") + helperFuncHdrStream.print("#include \"DeliteArray.h\"\n") + + super.initializeGenerator(buildDir, args, _analysisResults) } - def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, out: PrintWriter) = { + /* + override def isObjectType[A](m: Manifest[A]) : Boolean = { + m.toString match { + case "scala.collection.immutable.List[Int]" => true + //TODO: ObjectTypes needs to be able to broken down, but array does not have to be. + //TODO: What we need to do is to distinguish between passable types or not to the opencl kernel + case "Array[Int]" | "Array[Long]" | "Array[Float]" | "Array[Double]" | "Array[Boolean]" => true + case _ => super.isObjectType(m) + } + } + */ + + /* + override def remap[A](m: Manifest[A]) : String = { + checkGPUableType(m) + if (m.erasure == classOf[Variable[AnyVal]]) + remap(m.typeArguments.head) + else { + m.toString match { + case "Int" => "int" + case "Long" => "long" + case "Float" => "float" + case "Double" => "double" + case "Boolean" => "char" + case "Unit" => "void" + case "scala.Tuple2[Int,Float]" => "Tuple2_Int_Float" + case "scala.collection.immutable.List[Int]" => "OpenCLIntList" //TODO: Use C++ list + //TODO: When retrieving the type arguments of array from Manifest works, then below can be simplified + //case "Array[Int]" | "Array[Long]" | "Array[Float]" | "Array[Double]" | "Array[Boolean]" => remap(m.typeArguments(0)) + " *" + //TODO: Is it appropriate to put global here? + case "Array[Int]" => "__global int *" + case "Array[Long]" => "__global long *" + case "Array[Float]" => "__global float *" + case "Array[Double]" => "__global double *" + case "Array[Boolean]" => "__global char *" + case _ => throw new Exception("OpenCLGen: remap(m) : GPUable Type %s does not have mapping table.".format(m.toString)) + } + } + } + */ + + /* + override def unpackObject[A](sym: Sym[Any]) : Map[String,Manifest[_]] = remap(sym.Type) match { + case "OpenCLIntList" => Map("length"->Manifest.Int) //TODO: How to initialize the data array type for the list? + case _ => throw new GenerationFailedException("OpenCLGen: Type %s cannot be unpacked.".format(sym.Type.toString)) + } + */ + + // TODO: Move to Delite? + def copyInputHtoD(sym: Sym[Any]) : String = { + checkGPUableType(sym.tp) + remap(sym.tp) match { + case "DeliteArray_bool" | "DeliteArray_char" | "DeliteArray_CHAR" | "DeliteArray_short" | "DeliteArray_int" | "DeiteArray_long" | "DeliteArray_float" | "DeliteArray_double" => + val out = new StringBuilder + val typeArg = sym.tp.typeArguments.head + val numBytesStr = "length * sizeof(%s)".format(remap(typeArg)) + out.append("\tint length = env->GetArrayLength((j%sArray)obj);\n".format(remapToJNI(typeArg).toLowerCase)) + out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)obj,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) + out.append("\t%s *%s = new %s(length);\n".format(remap(sym.tp),quote(sym),remap(sym.tp))) + out.append("\tDeliteOpenCLMemcpyHtoDAsync(%s->data, dataPtr, %s);\n".format(quote(sym),numBytesStr)) + out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)obj, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) + out.append("\treturn %s;\n".format(quote(sym))) + out.toString + case _ => throw new Exception("OpenCLGen: copyInputHtoD(sym) : Cannot copy to GPU device (%s)".format(remap(sym.tp))) + } + } + + def copyOutputDtoH(sym: Sym[Any]) : String = { + checkGPUableType(sym.tp) + if (isPrimitiveType(sym.tp)) { + val out = new StringBuilder + out.append("\t%s data;\n".format(remap(sym.tp))) + out.append("\tDeliteOpenCLMemcpyDtoHAsync(&data, %s, sizeof(%s));\n".format(quote(sym),remap(sym.tp))) + out.append("\treturn data;\n") + out.toString + } + else { + remap(sym.tp) match { + case "DeliteArray_bool" | "DeliteArray_char" | "DeliteArray_CHAR" | "DeliteArray_short" | "DeliteArray_int" | "DeiteArray_long" | "DeliteArray_float" | "DeliteArray_double" => + val out = new StringBuilder + val typeArg = sym.tp.typeArguments.head + val numBytesStr = "%s.length * sizeof(%s)".format(quote(sym),remap(typeArg)) + out.append("\tj%sArray arr = env->New%sArray(%s.length);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg),quote(sym))) + out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)arr,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) + out.append("\tDeliteOpenCLMemcpyDtoHAsync(dataPtr, %s.data, %s);\n".format(quote(sym),numBytesStr)) + out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)arr, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) + out.append("\treturn arr;\n") + out.toString + case _ => throw new Exception("OpenCLGen: copyOutputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) + } + } + } + + def copyMutableInputDtoH(sym: Sym[Any]) : String = { + checkGPUableType(sym.tp) + remap(sym.tp) match { + case "DeliteArray_bool" | "DeliteArray_char" | "DeliteArray_CHAR" | "DeliteArray_short" | "DeliteArray_int" | "DeiteArray_long" | "DeliteArray_float" | "DeliteArray_double" => + val out = new StringBuilder + val typeArg = sym.tp.typeArguments.head + val numBytesStr = "length * sizeof(%s)".format(remap(typeArg)) + out.append("\tint length = %s.length;\n".format(quote(sym))) + out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)obj,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) + out.append("\tDeliteOpenCLMemcpyDtoHAsync(dataPtr, %s.data, %s);\n".format(quote(sym),numBytesStr)) + out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)obj, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) + out.toString + case _ => throw new Exception("OpenCLGen: copyMutableInputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) + } + } + + //TODO: Remove below methods + def allocOutput(newSym: Sym[_], sym: Sym[_], reset: Boolean = false) : Unit = { + throw new GenerationFailedException("OpenCLGen: allocOutput(newSym, sym) : Cannot allocate GPU memory (%s)".format(remap(sym.tp))) + } + def allocReference(newSym: Sym[Any], sym: Sym[Any]) : Unit = { + throw new GenerationFailedException("OpenCLGen: allocReference(newSym, sym) : Cannot allocate GPU memory (%s)".format(remap(sym.tp))) + } + + def positionMultDimInputs(sym: Sym[Any]) : String = { + throw new GenerationFailedException("OpenCLGen: positionMultDimInputs(sym) : Cannot reposition GPU memory (%s)".format(remap(sym.tp))) + + } + def cloneObject(sym: Sym[Any], src: Sym[Any]) : String = { + throw new GenerationFailedException("OpenCLGen: cloneObject(sym)") + } + + def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, out: PrintWriter) = { val sB = manifest[A].toString withStream(out) { @@ -61,16 +186,80 @@ trait OpenCLCodegen extends GPUCodegen with CppHostTransfer with OpenCLDeviceTra Nil } + def emitValDef(sym: Sym[Any], rhs: String): Unit = { + stream.println(addTab() + remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") + } + + def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = { + stream.println(addTab()+ remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") + } + + def emitAssignment(sym: Sym[Any], lhs:String, rhs: String): Unit = { + stream.println(addTab() + " " + lhs + " = " + rhs + ";") + } + } // TODO: do we need this for each target? trait OpenCLNestedCodegen extends CLikeNestedCodegen with OpenCLCodegen { - val IR: Expressions with Effects + val IR: Expressions with Effects with LoweringTransform import IR._ + + def OpenCLConsts(x:Exp[Any], s:String): String = { + s match { + case "Infinity" => "std::numeric_limits<%s>::max()".format(remap(x.tp)) + case _ => s + } + } + + override def quote(x: Exp[Any]) = x match { // TODO: quirk! + case Const(s: String) => "\""+s+"\"" + case Const(s: Char) => "'"+s+"'" + case Const(null) => "NULL" + case Const(z) => OpenCLConsts(x, z.toString) + case Sym(-1) => "_" + case _ => super.quote(x) + } } trait OpenCLFatCodegen extends CLikeFatCodegen with OpenCLCodegen { - val IR: Expressions with Effects with FatExpressions - import IR._ + val IR: Expressions with Effects with FatExpressions with LoweringTransform + import IR._ + + def emitMultiLoopCond(sym: Sym[Any], funcs:List[Block[Any]], idx: Sym[Int], postfix: String="", stream:PrintWriter):(String,List[Exp[Any]]) = { + isNestedNode = true + devFuncIdx += 1 + val currIdx = devFuncIdx + val tempString = new StringWriter + val tempStream = new PrintWriter(tempString, true) + val header = new StringWriter + val footer = new StringWriter + + val currentTab = tabWidth + tabWidth = 1 + withStream(tempStream) { + emitFatBlock(funcs) + } + tabWidth = currentTab + + val inputs = getFreeVarBlock(Block(Combine(funcs.map(getBlockResultFull))),Nil).filterNot(quote(_)==quote(idx)).distinct + val paramStr = (inputs++List(idx)).map(ele=>remap(ele.tp)+" "+quote(ele)).mkString(",") + header.append("bool dev_%s(%s) {\n".format(postfix,paramStr)) + footer.append("\treturn %s;\n".format(funcs.map(f=>quote(getBlockResult(f))).mkString("&&"))) + footer.append("}\n") + stream.print(header) + stream.print(tempString) + stream.print(footer) + + //Register Metadata for loop function + val lf = metaData.loopFuncs.getOrElse(sym,new LoopFunc) + lf.hasCond = true + lf.loopCondInputs = inputs.map(quote) + metaData.loopFuncs.put(sym,lf) + isNestedNode = false + + ("dev_"+currIdx,inputs) + } + } diff --git a/src/internal/OpenCLDeviceTransfer.scala b/src/internal/OpenCLDeviceTransfer.scala deleted file mode 100644 index 88e9e6d2..00000000 --- a/src/internal/OpenCLDeviceTransfer.scala +++ /dev/null @@ -1,95 +0,0 @@ -package scala.lms.internal - -/* Defines OpenCL specific device transfer functions */ -trait OpenCLDeviceTransfer extends AbstractDeviceTransfer { - this: OpenCLCodegen => - - val IR: Expressions - import IR._ - - def emitSendSlave(tp: Manifest[_]): (String,String) = { - if (isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "%s sendOpenCL_%s(%s sym)".format(remap(tp),mangledName(remap(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\treturn sym;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + tp.toString) - } - } - - def emitRecvSlave(tp: Manifest[_]): (String,String) = { - if (isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "%s recvOpenCL_%s(%s sym)".format(remap(tp),mangledName(remap(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\treturn sym;\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + tp.toString) - } - } -/* - def emitSendViewSlave(sym: Sym[Any]): (String,String) = { - if (isPrimitiveType(sym.tp)) { - val out = new StringBuilder - val signature = "%s sendViewOpenCL_%s(%s %s)".format(remap(sym.tp),quote(sym),remap(sym.tp),quote(sym)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn %s;\n".format(quote(sym))) - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + sym.tp.toString) - } - } - - def emitRecvViewSlave(sym: Sym[Any]): (String,String) = { - if (isPrimitiveType(sym.tp)) { - val out = new StringBuilder - val signature = "%s recvViewOpenCL_%s(%s %s)".format(remap(sym.tp),quote(sym),remap(sym.tp),quote(sym)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("\treturn %s;\n".format(quote(sym))) - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + sym.tp.toString) - } - } -*/ - def emitSendUpdateSlave(tp: Manifest[_]): (String,String) = { - if(isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "void sendUpdateOpenCL_%s(%s sym)".format(mangledName(remap(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + tp.toString) - } - } - - def emitRecvUpdateSlave(tp: Manifest[_]): (String,String) = { - if(isPrimitiveType(tp)) { - val out = new StringBuilder - val signature = "void recvUpdateOpenCL_%s(%s sym)".format(mangledName(remap(tp)),remap(tp)) - out.append(signature + " {\n") - out.append("\tassert(false);\n") - out.append("}\n") - (signature+";\n", out.toString) - } - else { - throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + tp.toString) - } - } -} diff --git a/src/internal/ScalaCodegen.scala b/src/internal/ScalaCodegen.scala index 2d108fd0..d1e2f3bc 100644 --- a/src/internal/ScalaCodegen.scala +++ b/src/internal/ScalaCodegen.scala @@ -1,16 +1,14 @@ -package scala.lms +package scala.virtualization.lms package internal import java.io.{File, FileWriter, PrintWriter} import scala.reflect.SourceContext -trait ScalaCodegen extends GenericCodegen with Config { +trait ScalaCodegen extends GenericCodegen { val IR: Expressions import IR._ - override def deviceTarget: Targets.Value = Targets.Scala - override def kernelFileExt = "scala" override def toString = "scala" @@ -21,10 +19,9 @@ trait ScalaCodegen extends GenericCodegen with Config { outFile.delete } - def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, out: PrintWriter) = { - - val sA = remap(manifest[A]) + def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, out: PrintWriter, dynamicReturnType: String = null, serializable: Boolean = false) = { + val sA = if (dynamicReturnType != null) dynamicReturnType else remap(manifest[A]) val staticData = getFreeDataBlock(body) withStream(out) { @@ -33,13 +30,15 @@ trait ScalaCodegen extends GenericCodegen with Config { "*******************************************/") emitFileHeader() + val transformedBody = performTransformations(body) + // TODO: separate concerns, should not hard code "pxX" name scheme for static data here - stream.println("class "+className+(if (staticData.isEmpty) "" else "("+staticData.map(p=>"p"+quote(p._1)+":"+p._1.tp).mkString(",")+")")+" extends (("+args.map(a => remap(a.tp)).mkString(", ")+")=>("+sA+")) {") - stream.println("def apply("+args.map(a => quote(a) + ":" + remap(a.tp)).mkString(", ")+"): "+sA+" = {") - - emitBlock(body) - stream.println(quote(getBlockResult(body))) - + stream.print("class "+className+(if (staticData.isEmpty) "" else "("+staticData.map(p=>"p"+quote(p._1)+":"+p._1.tp).mkString(",")+")")+" extends (("+args.map( a => remap(a.tp)).mkString(", ")+")=>("+sA+"))") + if (serializable) stream.println("with Serializable {") else stream.println(" {") + emitFunctions() + stream.println("def apply("+args.map(a => quote(a, true) + ":" + remap(a.tp)).mkString(", ")+"): "+sA+" = {") + emitBlock(transformedBody) + if (sA != "Unit") stream.println(quote(getBlockResult(transformedBody))) stream.println("}") stream.println("}") @@ -51,15 +50,13 @@ trait ScalaCodegen extends GenericCodegen with Config { staticData } - override def emitFileHeader() { - // empty by default. override to emit package or import declarations. - } - override def emitKernelHeader(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { val kernelName = syms.map(quote).mkString("") + + stream.println("package generated." + this.toString) stream.println("object kernel_" + kernelName + " {") stream.print("def apply(") - stream.print(vals.map(p => quote(p) + ":" + remap(p.tp)).mkString(",")) + stream.print(vals.map(p => quote(p, true) + ":" + remap(p.tp)).mkString(",")) // variable name mangling if (vals.length > 0 && vars.length > 0){ @@ -67,7 +64,7 @@ trait ScalaCodegen extends GenericCodegen with Config { } // TODO: remap Ref instead of explicitly adding generated.scala if (vars.length > 0){ - stream.print(vars.map(v => quote(v) + ":" + "generated.scala.Ref[" + remap(v.tp) +"]").mkString(",")) + stream.print(vars.map(v => quote(v, true) + ":" + "generated.scala.Ref[" + remap(v.tp) +"]").mkString(",")) } if (resultIsVar){ stream.print("): " + "generated.scala.Ref[" + resultType + "] = {") @@ -91,28 +88,26 @@ trait ScalaCodegen extends GenericCodegen with Config { } def emitValDef(sym: Sym[Any], rhs: String): Unit = { - val extra = if ((sourceinfo < 2) || sym.pos.isEmpty) "" else { + val extra = if ((Config.sourceinfo < 2) || sym.pos.isEmpty) "" else { val context = sym.pos(0) " // " + relativePath(context.fileName) + ":" + context.line } - stream.println("val " + quote(sym) + " = " + rhs + extra) + if (sym.tp != manifest[Unit]) + stream.println("val " + quote(sym) + " = " + rhs + extra) + else + stream.println(rhs + extra) } def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = { stream.println("var " + quote(sym) + ": " + remap(sym.tp) + " = " + rhs) +// stream.println("var " + quote(sym) + " = " + rhs) } - override def emitVarDecl(sym: Sym[Any]): Unit = { - stream.println("var " + quote(sym) + ": " + remap(sym.tp) + " = null.asInstanceOf[" + remap(sym.tp) + "];") - } - - override def emitAssignment(sym: Sym[Any], rhs: String): Unit = { - stream.println(quote(sym) + " = " + rhs) - } + def emitAssignment(sym: Sym[Any], lhs: String, rhs: String): Unit = emitValDef(sym, lhs + " = " + rhs) } trait ScalaNestedCodegen extends GenericNestedCodegen with ScalaCodegen { - val IR: Expressions with Effects + val IR: Expressions with Effects with LoweringTransform import IR._ // emit forward decls for recursive vals @@ -122,7 +117,7 @@ trait ScalaNestedCodegen extends GenericNestedCodegen with ScalaCodegen { } def emitForwardDef(sym: Sym[Any]): Unit = { - stream.println("var " + quote(sym) + /*": " + remap(sym.tp) +*/ " = null.asInstanceOf[" + remap(sym.tp) + "]") + stream.println("var " + quote(sym, true) + /*": " + remap(sym.tp) + */ " = null.asInstanceOf[" + remap(sym.tp) + "]") } // special case for recursive vals @@ -137,7 +132,7 @@ trait ScalaNestedCodegen extends GenericNestedCodegen with ScalaCodegen { trait ScalaFatCodegen extends GenericFatCodegen with ScalaCodegen { - val IR: Expressions with Effects with FatExpressions + val IR: Expressions with Effects with FatExpressions with LoweringTransform import IR._ def emitKernelExtra(syms: List[Sym[Any]]): Unit = { diff --git a/src/internal/ScalaCompile.scala b/src/internal/ScalaCompile.scala index 78f69424..5d8a5639 100644 --- a/src/internal/ScalaCompile.scala +++ b/src/internal/ScalaCompile.scala @@ -1,29 +1,40 @@ -package scala.lms +package scala.virtualization.lms package internal -import java.io._ +import java.io.{StringWriter, PrintWriter} +import scala.virtualization.lms.util._ +import scala.sys.process._ import scala.tools.nsc._ +import scala.tools.nsc.settings._ import scala.tools.nsc.util._ import scala.tools.nsc.reporters._ import scala.tools.nsc.io._ - import scala.tools.nsc.interpreter.AbstractFileClassLoader +import java.lang.management.ManagementFactory; +import javax.management.ObjectName; +import javax.management.openmbean.CompositeData; +import javax.management.openmbean.CompositeDataSupport; -trait ScalaCompile extends Expressions { - - val codegen: ScalaCodegen { val IR: ScalaCompile.this.type } - +object ScalaCompile { + var compileCount = 0 + var dumpGeneratedCode = false var compiler: Global = _ var reporter: ConsoleReporter = _ - //var output: ByteArrayOutputStream = _ + // From what I understand, this is not currently exported from the JVM, but it used internally. + // (To check, run java -XX:+PrintFlagsFinal -version | grep Huge) and check for the limit. + val maximumHugeMethodLimit = 8000 + // NOTE: Always disable these two flags when running the test suite + val byteCodeSizeCheckEnabled: Boolean =false + var cleanerEnabled: Boolean = false + val source = new StringWriter() + var writer = new PrintWriter(source) + val workingDir = System.getProperty("user.dir") + "/CompiledClasses" + var loader: AbstractFileClassLoader = null + lazy val comp = this.compiler def setupCompiler() = { - /* - output = new ByteArrayOutputStream() - val writer = new PrintWriter(new OutputStreamWriter(output)) - */ val settings = new Settings() val pathSeparator = System.getProperty("path.separator") @@ -36,59 +47,162 @@ trait ScalaCompile extends Expressions { case _ => System.getProperty("sun.boot.class.path") } settings.encoding.value = "UTF-8" - settings.outdir.value = "." + //settings.processArguments(List("-optimise", "-feature", "-deprecation", "-language:postfixOps", "-Yinline-warnings"), true) + settings.processArguments(List("-feature", "-deprecation", "-language:postfixOps", "-Yinline-warnings"), true) + // XX TR: do not optimize (save compile time!) + + // Create output directory if it does not exist + val f = new java.io.File(ScalaCompile.workingDir) + if (!f.exists) + f.mkdirs() + + settings.outdir.value = ScalaCompile.workingDir settings.extdirs.value = "" //settings.verbose.value = true // -usejavacp needed on windows? + ScalaCompile.loader = new AbstractFileClassLoader(AbstractFile.getDirectory(workingDir), this.getClass.getClassLoader) + ScalaCompile.reporter = new ConsoleReporter(settings, null, new PrintWriter(System.out))//writer + ScalaCompile.compiler = new Global(settings, ScalaCompile.reporter) + } + def reset() { + setupCompiler() + compileCount = 0 + dumpGeneratedCode = false + } + +} + +trait ScalaCompile extends Expressions { - reporter = new ConsoleReporter(settings, null, new PrintWriter(System.out))//writer - compiler = new Global(settings, reporter) + val codegen: ScalaCodegen { val IR: ScalaCompile.this.type } + + def initCompile = { + // System.out.println("Initializing compiler...") // This unfortunately + // breaks the test suite as well :-( + ScalaCompile.source.getBuffer().setLength(0) + val className = "staged" + ScalaCompile.compileCount + ScalaCompile.compileCount = ScalaCompile.compileCount + 1 + className } - var compileCount = 0 - - var dumpGeneratedCode = false + def checkByteCodeSize(className: String): Int = { + lazy val runtime: Runtime = Runtime.getRuntime(); + // Is compiling huge methods allowed? + val mserver = ManagementFactory.getPlatformMBeanServer(); + val name = new ObjectName("com.sun.management:type=HotSpotDiagnostic"); + val operationName = "getVMOption"; + val params = Array[Object]("DontCompileHugeMethods") + val signature = Array[String](classOf[String].getName()) + val result = mserver.invoke(name,operationName,params,signature).asInstanceOf[CompositeDataSupport].get("value") + // If yes, then check the size + if (result == "true") { + val cmd = Seq("javap","-classpath",ScalaCompile.workingDir,"-c",className) #| Seq("cut","-d:","-f1") #| Seq("sort","-n") #| Seq("tail","-n1") + val size = cmd.!!.trim.toInt + if (size > ScalaCompile.maximumHugeMethodLimit) { + println("\n\n|------------------------------------------------------------------------------------|") + println("| CATASTROPHIC ERROR ENCOUNTERED!!! YOUR CODE IS TOO BIG (" + size + ") TO BE COMPILED BY THE JVM |") + println("| AND WILL BE INTERPRETED INSTEAD. THIS WILL CAUSE A DRAMATIC PERFORMANCE DROP. |") + println("| THE DEVELOPERS WORRY ABOUT YOUR MENTAL HEALTH, AND CANNOT ALLOW YOU TO EXPERIENCE |") + println("| THAT. EXITING NOW! |") + println("| |") + println("| Note: You have two alternatives: |") + println("| \t(a) Refactor your code so that the generated code size is smaller.(advised) |") + println("| \t(b) Set JVM Option DontCompileHugeMethods to false and rerun (Not advised). |") + println("| -----------------------------------------------------------------------------------|") + System.exit(0) + } + return size; + } + -1; + } - def compile[A,B](f: Exp[A] => Exp[B])(implicit mA: Manifest[A], mB: Manifest[B]): A=>B = { - if (this.compiler eq null) - setupCompiler() - - val className = "staged$" + compileCount - compileCount += 1 - - val source = new StringWriter() - val writer = new PrintWriter(source) - val staticData = codegen.emitSource(f, className, writer) + def compileLoadClass(src: StringWriter, className: String) = { + if (ScalaCompile.compiler eq null) + ScalaCompile.setupCompiler() + if (ScalaCompile.dumpGeneratedCode) println(src) + + ScalaCompile.compiler.settings.outputDirs.setSingleOutput(AbstractFile.getDirectory(ScalaCompile.workingDir)) + val run = new ScalaCompile.comp.Run + var parsedsrc = src.toString + + if (ScalaCompile.cleanerEnabled) { + println("\n\n------------------------------------------------") + println("EXPERIMENTAL:: CODE BEFORE RUNNING CODEGEN CLEANER.\n" + parsedsrc) + parsedsrc = CodegenCleaner.clean(src.toString) + println("\n\n------------------------------------------------") + println("EXPERIMENTAL:: CODE AFTER RUNNING CODEGEN CLEANER\n" + parsedsrc) + } - codegen.emitDataStructures(writer) + run.compileSources(List(new util.BatchSourceFile("", parsedsrc))) - if (dumpGeneratedCode) println(source) + ScalaCompile.reporter.printSummary() + if (ScalaCompile.reporter.hasErrors) { + println("compilation of the following code had errors:") + println(src) + System.exit(0) + } + ScalaCompile.reporter.reset - val compiler = this.compiler - val run = new compiler.Run + if (ScalaCompile.byteCodeSizeCheckEnabled) { + val size = checkByteCodeSize(className) + if (size != -1) println("ByteCode size of the compiled code is: " + size) + } - val fileSystem = new VirtualDirectory("", None) - compiler.settings.outputDirs.setSingleOutput(fileSystem) - // compiler.genJVM.outputDir = fileSystem + val cls: Class[_] = ScalaCompile.loader.loadClass(className) + cls + } - run.compileSources(List(new util.BatchSourceFile("", source.toString))) - reporter.printSummary() + def compile0[B](f: () => Exp[B], dynamicReturnType: String = null)(implicit mB: Manifest[B]): () =>B = { + val className = initCompile + val staticData = codegen.emitSource0(f, className, ScalaCompile.writer, dynamicReturnType) + codegen.emitDataStructures(ScalaCompile.writer) + val cls = compileLoadClass(ScalaCompile.source, className) + val cons = cls.getConstructor(staticData.map(_._1.tp.erasure):_*) + cons.newInstance(staticData.map(_._2.asInstanceOf[AnyRef]):_*).asInstanceOf[()=>B] + } - if (!reporter.hasErrors) - println("compilation: ok") - else - println("compilation: had errors") + def compile1[A,B](f: Exp[A] => Exp[B])(implicit mA: Manifest[A], mB: Manifest[B]): A=>B = { + val className = initCompile + val staticData = codegen.emitSource1(f, className, ScalaCompile.writer) + codegen.emitDataStructures(ScalaCompile.writer) + val cls = compileLoadClass(ScalaCompile.source, className) + val cons = cls.getConstructor(staticData.map(_._1.tp.erasure):_*) + cons.newInstance(staticData.map(_._2.asInstanceOf[AnyRef]):_*).asInstanceOf[A=>B] + } - reporter.reset - //output.reset + def compile2[A1,A2,B](f: (Exp[A1],Exp[A2]) => Exp[B])(implicit mA1: Manifest[A1], mA2: Manifest[A2], mB: Manifest[B]): (A1,A2)=>B = { + val className = initCompile + val staticData = codegen.emitSource2(f, className, ScalaCompile.writer) + codegen.emitDataStructures(ScalaCompile.writer) + val cls = compileLoadClass(ScalaCompile.source, className) + val cons = cls.getConstructor(staticData.map(_._1.tp.erasure):_*) + cons.newInstance(staticData.map(_._2.asInstanceOf[AnyRef]):_*).asInstanceOf[(A1,A2)=>B] + } - val parent = this.getClass.getClassLoader - val loader = new AbstractFileClassLoader(fileSystem, this.getClass.getClassLoader) + def compile3[A1,A2,A3,B](f: (Exp[A1], Exp[A2], Exp[A3]) => Exp[B])(implicit mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mB: Manifest[B]): (A1,A2,A3)=>B = { + val className = initCompile + val staticData = codegen.emitSource3(f, className, ScalaCompile.writer) + codegen.emitDataStructures(ScalaCompile.writer) + val cls = compileLoadClass(ScalaCompile.source, className) + val cons = cls.getConstructor(staticData.map(_._1.tp.erasure):_*) + cons.newInstance(staticData.map(_._2.asInstanceOf[AnyRef]):_*).asInstanceOf[(A1,A2,A3)=>B] + } - val cls: Class[_] = loader.loadClass(className) + def compile4[A1,A2,A3,A4,B](f: (Exp[A1], Exp[A2], Exp[A3], Exp[A4]) => Exp[B])(implicit mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mB: Manifest[B]): (A1,A2,A3,A4)=>B = { + val className = initCompile + val staticData = codegen.emitSource4(f, className, ScalaCompile.writer) + codegen.emitDataStructures(ScalaCompile.writer) + val cls = compileLoadClass(ScalaCompile.source, className) + val cons = cls.getConstructor(staticData.map(_._1.tp.erasure):_*) + cons.newInstance(staticData.map(_._2.asInstanceOf[AnyRef]):_*).asInstanceOf[(A1,A2,A3,A4)=>B] + } + + def compile5[A1,A2,A3,A4,A5,B](f: (Exp[A1], Exp[A2], Exp[A3], Exp[A4], Exp[A5]) => Exp[B])(implicit mA1: Manifest[A1], mA2: Manifest[A2], mA3: Manifest[A3], mA4: Manifest[A4], mA5: Manifest[A5], mB: Manifest[B]): (A1,A2,A3,A4,A5)=>B = { + val className = initCompile + val staticData = codegen.emitSource5(f, className, ScalaCompile.writer) + codegen.emitDataStructures(ScalaCompile.writer) + val cls = compileLoadClass(ScalaCompile.source, className) val cons = cls.getConstructor(staticData.map(_._1.tp.erasure):_*) - - val obj: A=>B = cons.newInstance(staticData.map(_._2.asInstanceOf[AnyRef]):_*).asInstanceOf[A=>B] - obj + cons.newInstance(staticData.map(_._2.asInstanceOf[AnyRef]):_*).asInstanceOf[(A1,A2,A3,A4,A5)=>B] } -} \ No newline at end of file +} diff --git a/src/internal/ScalaConciseCodegen.scala b/src/internal/ScalaConciseCodegen.scala new file mode 100644 index 00000000..87e95c53 --- /dev/null +++ b/src/internal/ScalaConciseCodegen.scala @@ -0,0 +1,100 @@ +package scala.virtualization.lms +package internal + +import java.io.{File, FileWriter, PrintWriter} +import scala.virtualization.lms.util.ReflectionUtil +import scala.reflect.SourceContext + +/** + * ScalaConciseCodegen is just an extension to ScalaCodegen + * which inlines expressions that are possible to inline, + * instead of creating a new val-def for each of them, leading + * to a more compact and concise code. + * + * @author Mohammad Dashti (mohammad.dashti@epfl.ch) + */ +trait ScalaConciseCodegen extends ScalaNestedCodegen { self => + val IR: ExtendedExpressions with Effects with LoweringTransform + import IR._ + + override def emitValDef(sym: Sym[Any], rhs: String): Unit = { + val extra = if ((Config.sourceinfo < 2) || sym.pos.isEmpty) "" else { + val context = sym.pos(0) + " // " + relativePath(context.fileName) + ":" + context.line + } + sym match { + case s@Sym(n) => isVoidType(s.tp) match { + case true => stream.println("" + rhs + extra) + case false => if(s.possibleToInline || s.noReference) { + stream.print("("+rhs+")") + } else { + stream.println("val " + quote(sym) + " = " + rhs + extra) + } + } + case _ => stream.println("val " + quote(sym) + " = " + rhs + extra) + } + } + + override def emitAssignment(sym: Sym[Any], lhs: String, rhs: String): Unit = { + // if(isVoidType(sym.tp)) { + stream.println(lhs + " = " + rhs) + // } else { + // emitValDef(sym, lhs + " = " + rhs) + // } + } + + override def emitForwardDef(sym: Sym[Any]): Unit = { + if(!isVoidType(sym.tp)) { stream.println("var " + quote(sym, true) + /*": " + remap(sym.tp) +*/ " = null.asInstanceOf[" + remap(sym.tp) + "]") } + } + + override def traverseStm(stm: Stm) = stm match { + case TP(sym, rhs) => if(!sym.possibleToInline && sym.refCount > 0 /*for eliminating read-only effect-ful statements*/) emitNode(sym,rhs) + case _ => throw new GenerationFailedException("don't know how to generate code for statement: " + stm) + } + + override def quote(x: Exp[Any], forcePrintSymbol: Boolean) : String = { + def printSym(s: Sym[Any]): String = { + if(s.possibleToInline || s.noReference) { + Def.unapply(s) match { + case Some(d: Def[Any]) => { + val strWriter: java.io.StringWriter = new java.io.StringWriter; + val stream = new PrintWriter(strWriter); + withStream(stream) { + emitNode(s, d) + } + strWriter.toString + } + case None => "x"+s.id + } + } else { + "x"+s.id + } + } + x match { + case Const(s: String) => "\""+s.replace("\"", "\\\"").replace("\n", "\\n")+"\"" // TODO: more escapes? + case Const(c: Char) => "'"+c+"'" + case Const(f: Float) => "%1.10f".format(f) + "f" + case Const(l: Long) => l.toString + "L" + case Const(null) => "null" + case Const(z) => z.toString + case s@Sym(n) => if (forcePrintSymbol) { + printSym(s) + } else { + isVoidType(s.tp) match { + case true => "(" + /*"x" + n +*/ ")" + case false => printSym(s) + } + } + case null => "null" + case _ => throw new RuntimeException("could not quote " + x) + } + } + + override def performTransformations[A:Manifest](body: Block[A]): Block[A] = { + val transformedBody = super.performTransformations[A](body) + val fixer = new SymMetaDataFixerTransform{ val IR: self.IR.type = self.IR } + fixer.traverseBlock(transformedBody.asInstanceOf[fixer.Block[A]]) + transformedBody + } + +} diff --git a/src/internal/Scheduling.scala b/src/internal/Scheduling.scala index 5308e04a..7f9bfa8a 100644 --- a/src/internal/Scheduling.scala +++ b/src/internal/Scheduling.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal import util.GraphUtil @@ -14,6 +14,8 @@ trait Scheduling { getSchedule(scope)(result, false) } + // PERFORMANCE: 'intersect' calls appear to be a hotspot + // checks if a and b share at least one element. O(N^2), but with no allocation and possible early exit. def containsAny(a: List[Sym[Any]], b: List[Sym[Any]]): Boolean = { var aIter = a @@ -46,41 +48,19 @@ trait Scheduling { xx.flatten.reverse } - //performance hotspot! - //should be O(1) wrt 'scope' (nodes in graph), try to keep this as efficient as possible - protected def scheduleDepsWithIndex(syms: List[Sym[Any]], cache: IdentityHashMap[Sym[Any], (Stm,Int)]): List[Stm] = { - //syms.map(cache.get(_)).filter(_ ne null).distinct.sortBy(_._2).map(_._1) - val sortedSet = new java.util.TreeSet[(Stm,Int)]( - new java.util.Comparator[(Stm,Int)] { def compare(a:(Stm,Int), b:(Stm,Int)) = if (b._2 < a._2) -1 else if (b._2 == a._2) 0 else 1 } - ) - - for (sym <- syms) { - val stm = cache.get(sym) - if (stm ne null) sortedSet.add(stm) - } - - var res: List[Stm] = Nil - val iter = sortedSet.iterator //return stms in the original order given by 'scope' - while (iter.hasNext) { - res ::= iter.next._1 - } - res - } + //FIXME: hotspot + def getSchedule(scope: List[Stm])(result: Any, sort: Boolean = true): List[Stm] = { + val scopeCache = new mutable.HashMap[Sym[Any],Stm] + for (stm <- scope; s <- stm.lhs) + scopeCache(s) = stm - protected def buildScopeIndex(scope: List[Stm]): IdentityHashMap[Sym[Any], (Stm,Int)] = { - val cache = new IdentityHashMap[Sym[Any], (Stm,Int)] - var idx = 0 - for (stm <- scope) { - for (s <- stm.lhs) cache.put(s, (stm,idx)) //remember the original order of the stms - idx += 1 + def deps(st: List[Sym[Any]]): List[Stm] = {//st flatMap (scopeCache.get(_).toList) + // scope.filter(d => (st intersect d.lhs).nonEmpty) + // scope.filter(d => containsAny(st, d.lhs)) + st sortBy(_.id) flatMap (scopeCache.get(_).toList) } - cache - } - def getSchedule(scope: List[Stm])(result: Any, sort: Boolean = true): List[Stm] = { - val scopeIndex = buildScopeIndex(scope) - - val xx = GraphUtil.stronglyConnectedComponents[Stm](scheduleDepsWithIndex(syms(result), scopeIndex), t => scheduleDepsWithIndex(syms(t.rhs), scopeIndex)) + val xx = GraphUtil.stronglyConnectedComponents[Stm](deps(syms(result)), t => deps(syms(t.rhs))) if (sort) xx.foreach { x => if (x.length > 1) { printerr("warning: recursive schedule for result " + result + ": " + x) @@ -90,6 +70,7 @@ trait Scheduling { xx.flatten.reverse } + //FIXME: hotspot def getScheduleM(scope: List[Stm])(result: Any, cold: Boolean, hot: Boolean): List[Stm] = { def mysyms(st: Any) = { val db = symsFreq(st).groupBy(_._1).mapValues(_.map(_._2).sum).toList @@ -100,9 +81,17 @@ trait Scheduling { else db.withFilter(p=>p._2 > 0.75 && p._2 < 100.0).map(_._1) } - val scopeIndex = buildScopeIndex(scope) + val scopeCache = new mutable.HashMap[Sym[Any],Stm] + for (stm <- scope; s <- stm.lhs) + scopeCache(s) = stm + + def deps(st: List[Sym[Any]]): List[Stm] = {//st flatMap (scopeCache.get(_).toList) + // scope.filter(d => (st intersect d.lhs).nonEmpty) + // scope.filter(d => containsAny(st, d.lhs)) + st flatMap (scopeCache.get(_).toList) + } - GraphUtil.stronglyConnectedComponents[Stm](scheduleDepsWithIndex(mysyms(result), scopeIndex), t => scheduleDepsWithIndex(mysyms(t.rhs), scopeIndex)).flatten.reverse + GraphUtil.stronglyConnectedComponents[Stm](deps(mysyms(result)), t => deps(mysyms(t.rhs))).flatten.reverse } @@ -171,8 +160,6 @@ trait Scheduling { traverse syms by ascending id. if sym s1 is used by s2, do not evaluate further uses of s2 because they are already there. - CAVEAT: TRANSFORMERS !!! - assumption: if s2 uses s1, the scope of s2 is completely included in s1's scope: val A = loop { s1 => ... val B = sum { s2 => ... val y = s2 + s1; .../* use y */ ... } } @@ -186,7 +173,7 @@ trait Scheduling { def getDepStuff(st: Sym[Any]) = { // could also precalculate uses, but computing all combinations eagerly is also expensive def uses(s: Sym[Any]): List[Stm] = if (seen(s)) Nil else { - //seen += s + seen += s lhsCache.getOrElse(s,Nil) ::: symsCache.getOrElse(s,Nil) filterNot (boundSymsCache.getOrElse(st, Nil) contains _) } GraphUtil.stronglyConnectedComponents[Stm]( @@ -196,21 +183,13 @@ trait Scheduling { } /* - reference impl:*/ - val res = sts.flatMap(getDepStuff).distinct + reference impl: + sts.flatMap(getDepStuff).distinct + */ - /*if (sts.contains(Sym(1064))) { - println("dep on x1064:") - res.foreach { r => - println(" " + r) - } - }*/ - res - - // CAVEAT: TRANSFORMERS !!! see CloseWorldRestage app in Delite - //sts.sortBy(_.id).flatMap(getDepStuff) + sts.sortBy(_.id).flatMap(getDepStuff) } /** end performance hotspot **/ -} +} \ No newline at end of file diff --git a/src/internal/SymMetaDataFixerTransform.scala b/src/internal/SymMetaDataFixerTransform.scala new file mode 100644 index 00000000..32982645 --- /dev/null +++ b/src/internal/SymMetaDataFixerTransform.scala @@ -0,0 +1,88 @@ +package scala.virtualization.lms +package internal + +import scala.virtualization.lms.util.ReflectionUtil + +/** + * There are some meta-data added to Sym using infix + * operations in ExtendedExpressions. + * This trait fixes this properties, e.g parentBlock + * and refCount. + * + * This information are gathered by a single pass + * traversal over Exp graph. + */ +trait SymMetaDataFixerTransform extends NestedBlockTraversal { + val IR: ExtendedExpressions with Effects + import IR._ + + override def traverseBlockFocused[A](block: Block[A]): Unit = { + focusExactScope(block) { levelScope => + levelScope foreach { stm => stm match { + case TP(sym, rhs) => sym.setParentBlock(Some(block)) + case _ => + } + } + + traverseStmsInBlock(levelScope) + } + } + + override def traverseStm(stm: Stm): Unit = { // override this to implement custom traversal + stm match { + case TP(sym, rhs) => { + rhs match { + case Reflect(s, u, effects) => { + if(!mustOnlyRead(u) && !mustOnlyAlloc(u)) { + sym.incRefCount(100) + } else if(mustOnlyAlloc(u)) { + sym.incRefCount(1) + } + increaseRefCountsOnRhs(sym, s) + } + case Reify(s, u, effects) => { + sym.incRefCount(-1000) // just ignore -- effects are accounted for in emitBlock + s match { + case s@Sym(n) => s.incRefCount(1) + case Const(x) => + } + } + case rhs => increaseRefCountsOnRhs(sym, rhs) + } + } + case _ => + } + blocks(stm.rhs) foreach traverseBlock + } + + private def increaseRefCountsOnRhs[A](s: Exp[Any], rhs: Def[A]): Unit = { + val sym = s.asInstanceOf[Sym[Any]] + ReflectionUtil.caseNameTypeValues(rhs) foreach { + x => if(x._2 == classOf[Block[A]]) { + val blk: Block[A] = x._3.asInstanceOf[Block[A]] + blk.res match { + case s:Sym[_] => if(s.inSameParentBlockAs(sym)) { s.incRefCount(1) } else { s.incRefCount(10) } + case _ => + } + //transformBlock[Any](blk) + } else if(x._2 == classOf[Exp[A]]) { + x._3 match { + case s:Sym[_] => if(s.inSameParentBlockAs(sym)) { s.incRefCount(1) } else { s.incRefCount(10) } + case _ => + } + } else if (x._2 == classOf[Variable[A]]) { + if (x._3 != null) { + x._3.asInstanceOf[Variable[A]].e match { + case s:Sym[_] => if(s.inSameParentBlockAs(sym)) { s.incRefCount(1) } else { s.incRefCount(10) } + case _ => + } + } + } else { + syms(x._3).foreach { + s: Sym[Any] => if(s.inSameParentBlockAs(sym)) { s.incRefCount(1) } else { s.incRefCount(10) } + } + } + } + } + +} diff --git a/src/internal/Transforming.scala b/src/internal/Transforming.scala index bf074ba0..c22a956c 100644 --- a/src/internal/Transforming.scala +++ b/src/internal/Transforming.scala @@ -1,9 +1,10 @@ -package scala.lms +package scala.virtualization.lms package internal import util.OverloadHack import scala.collection.{immutable,mutable} import scala.reflect.SourceContext +import scala.virtualization.lms.common.WorklistTransformer trait AbstractTransformer { val IR: Expressions with Blocks with OverloadHack @@ -22,9 +23,6 @@ trait AbstractTransformer { def apply[A](xs: Seq[Exp[A]]): Seq[Exp[A]] = xs map (e => apply(e)) def apply[X,A](f: X=>Exp[A]): X=>Exp[A] = (z:X) => apply(f(z)) def apply[X,Y,A](f: (X,Y)=>Exp[A]): (X,Y)=>Exp[A] = (z1:X,z2:Y) => apply(f(z1,z2)) - def apply[X,Y,Z,A](f: (X,Y,Z)=>Exp[A]): (X,Y,Z)=>Exp[A] = (z1:X,z2:Y,z3:Z) => apply(f(z1,z2,z3)) - def apply[W,X,Y,Z,A](f: (W,X,Y,Z)=>Exp[A]): (W,X,Y,Z)=>Exp[A] = (z1:W,z2:X,z3:Y,z4:Z) => apply(f(z1,z2,z3,z4)) - def apply[V,W,X,Y,Z,A](f: (V,W,X,Y,Z)=>Exp[A]): (V,W,X,Y,Z)=>Exp[A] = (z1:V,z2:W,z3:X,z4:Y,z5:Z) => apply(f(z1,z2,z3,z4,z5)) //def apply[A](xs: Summary): Summary = xs //TODO def onlySyms[A](xs: List[Sym[A]]): List[Sym[A]] = xs map (e => apply(e)) collect { case e: Sym[A] => e } @@ -100,3 +98,27 @@ trait FatTransforming extends Transforming with FatExpressions { //def mirror[A:Manifest](e: FatDef, f: Transformer): Exp[A] = sys.error("don't know how to mirror " + e) } + +/* Lewis: adapted from LMS TestWorklistTransform2.scala */ +trait LoweringTransform extends FatTransforming with Effects { self => + trait LoweringTransformer extends WorklistTransformer { val IR: self.type = self } + + // ---------- Exp api + implicit def toAfter[A:Manifest](x: Def[A]) = new { def atPhase(t: LoweringTransformer)(y: => Exp[A]) = transformAtPhase(x)(t)(y) } + implicit def toAfter[A](x: Exp[A]) = new { def atPhase(t: LoweringTransformer)(y: => Exp[A]) = transformAtPhase(x)(t)(y) } + + // transform x to y at the *next* iteration of t. + // note: if t is currently active, it will continue the current pass with x = x. + // do we need a variant that replaces x -> y immediately if t is active? + def transformAtPhase[A](x: Exp[A])(t: LoweringTransformer)(y: => Exp[A]): Exp[A] = { + t.register(x)(y) + x + } + + def onCreate[A:Manifest](s: Sym[A], d: Def[A]): Exp[A] = s + + override def createDefinition[T](s: Sym[T], d: Def[T]): Stm = { + onCreate(s,d)(s.tp) + super.createDefinition(s,d) + } +} diff --git a/src/internal/Traversal.scala b/src/internal/Traversal.scala index 36e805fb..090134a6 100644 --- a/src/internal/Traversal.scala +++ b/src/internal/Traversal.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package internal import util.GraphUtil @@ -55,7 +55,7 @@ trait NestedGraphTraversal extends GraphTraversal with CodeMotion { rval = body } catch { - case e => throw e + case e: Throwable => throw e } finally { innerScope = saveInner @@ -79,9 +79,27 @@ trait NestedGraphTraversal extends GraphTraversal with CodeMotion { // strong order for levelScope (as obtained by code motion), taking care of recursive dependencies. def getStronglySortedSchedule2(scope: List[Stm], level: List[Stm], result: Any): (List[Stm], List[Sym[Any]]) = { - val scopeIndex = buildScopeIndex(scope) + import util.GraphUtil + import scala.collection.{mutable,immutable} + + val scopeCache = new mutable.HashMap[Sym[Any],Stm] + for (stm <- scope; s <- stm.lhs) + scopeCache(s) = stm + + //TR: wip! + + def deps(st: List[Sym[Any]]): List[Stm] = //st flatMap (scopeCache.get(_).toList) + { + val l1 = st sortBy(_.id) flatMap (scopeCache.get(_).toList) distinct; // need distinc?? + /*val l2 = scope.filter(d => (st intersect d.lhs).nonEmpty) sortBy(_.lhs.intersec(st).map(_.id).min) + if (l1 != l2) { + println("l1: " + l1) + println("l2: " + l2) + }*/ + l1 + } - val fixed = new collection.mutable.HashMap[Any,List[Sym[Any]]] + val fixed = new mutable.HashMap[Any,List[Sym[Any]]] def allSyms(r: Any) = fixed.getOrElse(r, syms(r) ++ softSyms(r)) @@ -89,7 +107,7 @@ trait NestedGraphTraversal extends GraphTraversal with CodeMotion { var recursive: List[Sym[Any]] = Nil - var xx = GraphUtil.stronglyConnectedComponents[Stm](scheduleDepsWithIndex(allSyms(result), scopeIndex), t => scheduleDepsWithIndex(allSyms(t.rhs), scopeIndex)) + var xx = GraphUtil.stronglyConnectedComponents[Stm](deps(allSyms(result)), t => deps(allSyms(t.rhs))) xx.foreach { xs => if (xs.length > 1 && (xs intersect level).nonEmpty) { printdbg("warning: recursive schedule for result " + result + ": " + xs) @@ -121,7 +139,7 @@ trait NestedGraphTraversal extends GraphTraversal with CodeMotion { } } } - xx = GraphUtil.stronglyConnectedComponents[Stm](scheduleDepsWithIndex(allSyms(result) ++ allSyms(recursive), scopeIndex), t => scheduleDepsWithIndex(allSyms(t.rhs), scopeIndex)) + xx = GraphUtil.stronglyConnectedComponents[Stm](deps(allSyms(result) ++ allSyms(recursive)), t => deps(allSyms(t.rhs))) xx.foreach { xs => if (xs.length > 1 && (xs intersect level).nonEmpty) { // see test5-schedfun. since we're only returning level scope (not inner) diff --git a/src/internal/Utils.scala b/src/internal/Utils.scala index d107bf38..3086c04f 100644 --- a/src/internal/Utils.scala +++ b/src/internal/Utils.scala @@ -1,15 +1,12 @@ -package scala.lms +package scala.virtualization.lms package internal // TODO: add logging, etc. -trait Utils extends Config { +trait Utils { def __ = throw new RuntimeException("unsupported embedded dsl operation") - def printdbg(x: =>Any) { if (verbosity >= 2) System.err.println(x) } - def printlog(x: =>Any) { if (verbosity >= 1) System.err.println(x) } - def printerr(x: =>Any) { System.err.println(x); hadErrors = true } - - def printsrc(x: =>Any) { if (sourceinfo >= 1) System.err.println(x) } - - var hadErrors = false -} \ No newline at end of file + def printdbg(x: =>Any) { if (Config.verbosity >= 2) System.err.println(x) } + def printlog(x: =>Any) { if (Config.verbosity >= 1) System.err.println(x) } + def printerr(x: =>Any) { System.err.println(x); } + def printsrc(x: =>Any) { if (Config.sourceinfo >= 1) System.err.println(x) } +} diff --git a/src/util/ClosureCompare.scala b/src/util/ClosureCompare.scala index a1bfe6cc..16a0344f 100644 --- a/src/util/ClosureCompare.scala +++ b/src/util/ClosureCompare.scala @@ -1,4 +1,4 @@ -package scala.lms +package scala.virtualization.lms package util import java.io._ diff --git a/src/util/GencodeCleaner.scala b/src/util/GencodeCleaner.scala new file mode 100644 index 00000000..8f914ab1 --- /dev/null +++ b/src/util/GencodeCleaner.scala @@ -0,0 +1,117 @@ +package scala.virtualization.lms.util + +import java.util.regex.Pattern +import scala.collection.mutable.ListBuffer + +object CodegenCleaner { + val pattern1 = Pattern.compile("val x[0-9]* = x[0-9]*$") + val pattern2 = Pattern.compile("var x[0-9]* = ") + val pattern3 = Pattern.compile("val x[0-9]* =") + val pattern4 = Pattern.compile("var x[0-9]* = x[0-9]*$") + val pattern5 = Pattern.compile("x[0-9]*$") + + def clean(src: String) = { + var lines = src.split("\n").map(x => x.trim) + // Extract variables + val variables = lines.filter(x => pattern2.matcher(x).find).map(x => { + val y = x.split("=") + ( y(0).replaceAll("var ","").trim, y(1).trim ) + }).sortBy(x => x._1) + // Extract values + val values = lines.filter(x => pattern3.matcher(x).find).map(x => { + val y = x.split("=") + ( y(0).replaceAll("val ","").trim, y(1).trim ) + }).sortBy(x => x._1) + // Extract "val x = x" lines + var resList = new ListBuffer[(String,String)]() + lines = lines.map(x => + if (pattern1.matcher(x).find) { + val y = x.split("=") + val valId = y(0).replaceAll("val ","").trim + val lhs = y(1).trim + variables.find(z => z._1 == lhs) match { + case Some(w) => { + resList += new Tuple2[String,String](valId,lhs) + "" + } + case None => x + } + } else x + ) +// println("PHASE 1A DONE") + // Now remove all references to this val + resList.foreach( res => { + lines = lines.map( line => line.replaceAll(res._1 + "\\.", res._2 + ".").replaceAll(res._1 + "$",res._2).replaceAll(res._1 + " ", res._2 + " ").replaceAll(res._1 + "\\(",res._2 + "(").replaceAll(res._1 + "\\+",res._2 + "+").replaceAll(res._1 + "\\)",res._2 + ")").replaceAll("= __" + res._1 + "Size", "= __" + res._2 + "Size").replaceAll("^__" + res._1 + "Size", "__" + res._2 + "Size").replaceAll("< __" + res._1 + "Size", "< __" + res._2 + "Size").replaceAll("__" + res._1 + "Indices", "__" + res._2 + "Indices").replaceAll("__" + res._1 + "LastIndex", "__" + res._2 + "LastIndex") ) + }) + + // Extract "var x = x" lines + resList = new ListBuffer[(String,String)]() + lines = lines.map(x => + if (pattern4.matcher(x).find) { + val y = x.split("=") + val valId = y(0).replaceAll("var ","").trim + val lhs = y(1).trim + variables.find(z => z._1 == lhs) match { + case Some(w) => { + resList += new Tuple2[String,String](valId,lhs) + "" + } + case None => x + } + } else x + ) +// println("PHASE 1A DONE") + // Now remove all references to this val + resList.foreach( res => { + lines = lines.map( line => line.replaceAll(res._1 + "\\.", res._2 + ".").replaceAll(res._1 + "$",res._2).replaceAll(res._1 + " ", res._2 + " ").replaceAll(res._1 + "\\(",res._2 + "(").replaceAll(res._1 + "\\+",res._2 + "+").replaceAll(res._1 + "\\)",res._2 + ")").replaceAll("= __" + res._1 + "Size", "= __" + res._2 + "Size").replaceAll("^__" + res._1 + "Size", "__" + res._2 + "Size").replaceAll("< __" + res._1 + "Size", "< __" + res._2 + "Size").replaceAll("__" + res._1 + "Indices", "__" + res._2 + "Indices").replaceAll("__" + res._1 + "LastIndex", "__" + res._2 + "LastIndex") ) + }) + + +// println("PHASE 1B DONE") + // CASE 2 + resList = new ListBuffer[(String,String)]() + lines = lines.map( line => { + if (pattern4.matcher(line).find) { + val y = line.split("=") + val varId = y(0).replaceAll("var ","").trim + val lhs = y(1).trim + values.find(z => z._1 == lhs) match { + case Some(w) => { + resList += new Tuple2[String,String](varId,lhs) + "" + } + case None => line + } + } else line + }) +// println("PHASE 2A DONE") + // Now change the val to var + resList.foreach( res => { + lines = lines.map( line => line.replaceAll("val " + res._2 + " ","var " + res._1 + " ")) + }) + +resList.foreach( res => { + lines = lines.map( line => line.replaceAll(res._1 + "\\.", res._2 + ".").replaceAll(res._1 + "$",res._2).replaceAll(res._1 + " ", res._2 + " ").replaceAll(res._1 + "\\(",res._2 + "(").replaceAll(res._1 + "\\+",res._2 + "+").replaceAll(res._1 + "\\)",res._2 + ")").replaceAll("= __" + res._1 + "Size", "= __" + res._2 + "Size").replaceAll("^__" + res._1 + "Size", "__" + res._2 + "Size").replaceAll("< __" + res._1 + "Size", "< __" + res._2 + "Size").replaceAll("__" + res._1 + "Indices", "__" + res._2 + "Indices").replaceAll("__" + res._1 + "LastIndex", "__" + res._2 + "LastIndex") ) + }) + + +// println("PHASE 2B DONE") + // CASE 3 + for (i <- 1 to lines.length - 1) { + if (lines(i).matches("x[0-9]*$") && pattern3.matcher(lines(i-1)).find) { + if (lines(i-1).startsWith("val " + lines(i))) { + val lhs = lines(i-1).split("=").drop(1).mkString("=") + lines(i-1) = lhs + lines(i) = "" + } + } + } +// println("PHASE 3 DONE") + + // print result + lines = lines.filter(x => x!= "" && x!="()") +// println("PHASE 4 DONE") + lines.mkString("\n") + } +} + diff --git a/src/util/GraphUtil.scala b/src/util/GraphUtil.scala index 1070bd66..dd774ab2 100644 --- a/src/util/GraphUtil.scala +++ b/src/util/GraphUtil.scala @@ -1,7 +1,11 @@ -package scala.lms +package scala.virtualization.lms package util -import java.util.{ArrayDeque, HashMap} +import scala.collection.mutable.Map +import scala.collection.mutable.HashMap +import scala.collection.mutable.Stack +import scala.collection.mutable.Buffer +import scala.collection.mutable.ArrayBuffer object GraphUtil { @@ -29,27 +33,27 @@ object GraphUtil { def stronglyConnectedComponents[T](start: List[T], succ: T=>List[T]): List[List[T]] = { val id: Ref[Int] = new Ref(0) - val stack = new ArrayDeque[T] - val mark = new HashMap[T,Int] + val stack: Stack[T] = new Stack() + val mark: Map[T,Int] = new HashMap() - val res = new Ref[List[List[T]]](Nil) + val res: Buffer[Buffer[T]] = new ArrayBuffer() for (node <- start) visit(node,succ,id,stack,mark,res) - res.value + // TODO: get rid of reverse + + (for (scc <- res) yield scc.toList.reverse).toList.reverse } - def visit[T](node: T, succ: T=>List[T], id: Ref[Int], stack: ArrayDeque[T], - mark: HashMap[T,Int], res: Ref[List[List[T]]]): Int = { + def visit[T](node: T, succ: T=>List[T], id: Ref[Int], stack: Stack[T], + mark: Map[T,Int], res: Buffer[Buffer[T]]): Int = { + + mark.getOrElse(node, { - - if (mark.containsKey(node)) - mark.get(node) - else { id.value = id.value + 1 mark.put(node, id.value) - stack.addFirst(node) + stack.push(node) // println("push " + node) var min: Int = id.value @@ -60,20 +64,23 @@ object GraphUtil { min = m } - if (min == mark.get(node)) { - var scc: List[T] = Nil + if (min == mark(node)) { + + val scc: Buffer[T] = new ArrayBuffer() var loop: Boolean = true do { - val element = stack.removeFirst() + val element = stack.pop() // println("appending " + element) - scc ::= element + scc.append(element) mark.put(element, Integer.MAX_VALUE) loop = element != node } while (loop) - res.value ::= scc + res.append(scc) } min - } + + }) } + } diff --git a/src/util/OverloadHack.scala b/src/util/OverloadHack.scala index 8402e093..04f80b35 100644 --- a/src/util/OverloadHack.scala +++ b/src/util/OverloadHack.scala @@ -1,109 +1,33 @@ -package scala.lms +package scala.virtualization.lms package util // hack to appease erasure -trait OverloadHack { - class Overloaded1 - class Overloaded2 - class Overloaded3 - class Overloaded4 - class Overloaded5 - class Overloaded6 - class Overloaded7 - class Overloaded8 - class Overloaded9 - class Overloaded10 - class Overloaded11 - class Overloaded12 - class Overloaded13 - class Overloaded14 - class Overloaded15 - class Overloaded16 - class Overloaded17 - class Overloaded18 - class Overloaded19 - class Overloaded20 - class Overloaded21 - class Overloaded22 - class Overloaded23 - class Overloaded24 - class Overloaded25 - class Overloaded26 - class Overloaded27 - class Overloaded28 - class Overloaded29 - class Overloaded30 - class Overloaded31 - class Overloaded32 - class Overloaded33 - class Overloaded34 - class Overloaded35 - class Overloaded36 - class Overloaded37 - class Overloaded38 - class Overloaded39 - class Overloaded40 - class Overloaded41 - class Overloaded42 - class Overloaded43 - class Overloaded44 - class Overloaded45 - class Overloaded46 - class Overloaded47 - class Overloaded48 - class Overloaded49 - class Overloaded50 - class Overloaded51 - class Overloaded52 - class Overloaded53 - class Overloaded54 - class Overloaded55 - class Overloaded56 - class Overloaded57 - class Overloaded58 - class Overloaded59 - class Overloaded60 - class Overloaded61 - class Overloaded62 - class Overloaded63 - class Overloaded64 - class Overloaded65 - class Overloaded66 - class Overloaded67 - class Overloaded68 - class Overloaded69 - class Overloaded70 - class Overloaded71 - class Overloaded72 - class Overloaded73 - class Overloaded74 - class Overloaded75 - class Overloaded76 - class Overloaded77 - class Overloaded78 - class Overloaded79 - class Overloaded80 - class Overloaded81 - class Overloaded82 - class Overloaded83 - class Overloaded84 - class Overloaded85 - class Overloaded86 - class Overloaded87 - class Overloaded88 - class Overloaded89 - class Overloaded90 - class Overloaded91 - class Overloaded92 - class Overloaded93 - class Overloaded94 - class Overloaded95 - class Overloaded96 - class Overloaded97 - class Overloaded98 - class Overloaded99 - class Overloaded100 +trait OverloadHack extends Serializable { + class Overloaded1 extends Serializable + class Overloaded2 extends Serializable + class Overloaded3 extends Serializable + class Overloaded4 extends Serializable + class Overloaded5 extends Serializable + class Overloaded6 extends Serializable + class Overloaded7 extends Serializable + class Overloaded8 extends Serializable + class Overloaded9 extends Serializable + class Overloaded10 extends Serializable + class Overloaded11 extends Serializable + class Overloaded12 extends Serializable + class Overloaded13 extends Serializable + class Overloaded14 extends Serializable + class Overloaded15 extends Serializable + class Overloaded16 extends Serializable + class Overloaded17 extends Serializable + class Overloaded18 extends Serializable + class Overloaded19 extends Serializable + class Overloaded20 extends Serializable + class Overloaded21 extends Serializable + class Overloaded22 extends Serializable + class Overloaded23 extends Serializable + class Overloaded24 extends Serializable implicit val overloaded1 = new Overloaded1 implicit val overloaded2 = new Overloaded2 @@ -129,81 +53,4 @@ trait OverloadHack { implicit val overloaded22 = new Overloaded22 implicit val overloaded23 = new Overloaded23 implicit val overloaded24 = new Overloaded24 - implicit val overloaded25 = new Overloaded25 - implicit val overloaded26 = new Overloaded26 - implicit val overloaded27 = new Overloaded27 - implicit val overloaded28 = new Overloaded28 - implicit val overloaded29 = new Overloaded29 - implicit val overloaded30 = new Overloaded30 - implicit val overloaded31 = new Overloaded31 - implicit val overloaded32 = new Overloaded32 - implicit val overloaded33 = new Overloaded33 - implicit val overloaded34 = new Overloaded34 - implicit val overloaded35 = new Overloaded35 - implicit val overloaded36 = new Overloaded36 - implicit val overloaded37 = new Overloaded37 - implicit val overloaded38 = new Overloaded38 - implicit val overloaded39 = new Overloaded39 - implicit val overloaded40 = new Overloaded40 - implicit val overloaded41 = new Overloaded41 - implicit val overloaded42 = new Overloaded42 - implicit val overloaded43 = new Overloaded43 - implicit val overloaded44 = new Overloaded44 - implicit val overloaded45 = new Overloaded45 - implicit val overloaded46 = new Overloaded46 - implicit val overloaded47 = new Overloaded47 - implicit val overloaded48 = new Overloaded48 - implicit val overloaded49 = new Overloaded49 - implicit val overloaded50 = new Overloaded50 - implicit val overloaded51 = new Overloaded51 - implicit val overloaded52 = new Overloaded52 - implicit val overloaded53 = new Overloaded53 - implicit val overloaded54 = new Overloaded54 - implicit val overloaded55 = new Overloaded55 - implicit val overloaded56 = new Overloaded56 - implicit val overloaded57 = new Overloaded57 - implicit val overloaded58 = new Overloaded58 - implicit val overloaded59 = new Overloaded59 - implicit val overloaded60 = new Overloaded60 - implicit val overloaded61 = new Overloaded61 - implicit val overloaded62 = new Overloaded62 - implicit val overloaded63 = new Overloaded63 - implicit val overloaded64 = new Overloaded64 - implicit val overloaded65 = new Overloaded65 - implicit val overloaded66 = new Overloaded66 - implicit val overloaded67 = new Overloaded67 - implicit val overloaded68 = new Overloaded68 - implicit val overloaded69 = new Overloaded69 - implicit val overloaded70 = new Overloaded70 - implicit val overloaded71 = new Overloaded71 - implicit val overloaded72 = new Overloaded72 - implicit val overloaded73 = new Overloaded73 - implicit val overloaded74 = new Overloaded74 - implicit val overloaded75 = new Overloaded75 - implicit val overloaded76 = new Overloaded76 - implicit val overloaded77 = new Overloaded77 - implicit val overloaded78 = new Overloaded78 - implicit val overloaded79 = new Overloaded79 - implicit val overloaded80 = new Overloaded80 - implicit val overloaded81 = new Overloaded81 - implicit val overloaded82 = new Overloaded82 - implicit val overloaded83 = new Overloaded83 - implicit val overloaded84 = new Overloaded84 - implicit val overloaded85 = new Overloaded85 - implicit val overloaded86 = new Overloaded86 - implicit val overloaded87 = new Overloaded87 - implicit val overloaded88 = new Overloaded88 - implicit val overloaded89 = new Overloaded89 - implicit val overloaded90 = new Overloaded90 - implicit val overloaded91 = new Overloaded91 - implicit val overloaded92 = new Overloaded92 - implicit val overloaded93 = new Overloaded93 - implicit val overloaded94 = new Overloaded94 - implicit val overloaded95 = new Overloaded95 - implicit val overloaded96 = new Overloaded96 - implicit val overloaded97 = new Overloaded97 - implicit val overloaded98 = new Overloaded98 - implicit val overloaded99 = new Overloaded99 - implicit val overloaded100 = new Overloaded100 - -} \ No newline at end of file +} diff --git a/src/util/ReflectionUtil.scala b/src/util/ReflectionUtil.scala new file mode 100644 index 00000000..b270780c --- /dev/null +++ b/src/util/ReflectionUtil.scala @@ -0,0 +1,30 @@ +package scala.virtualization.lms +package util + +/** + * An object for reflection related utility methods + */ +object ReflectionUtil { + /** + * This method accepts an instance of a case class and returns + * the list of its fields. + * Each entry in the returned list is a tripple: + * - field name + * - field type + * - field value + */ + def caseNameTypeValues(a: AnyRef) = { + /** + * returns number of parameters for the first constructor of an object + */ + def numConstructorParams(a: AnyRef) = a.getClass.getConstructors()(0).getParameterTypes.size + /** + * returns list of fields in an instance of a case class + */ + def caseFields(a: AnyRef) = a.getClass.getDeclaredFields.toSeq.filterNot(_.isSynthetic).take(numConstructorParams(a)).map{field => + field.setAccessible(true) + field + } + caseFields(a).map{field => (field.getName, field.getType, field.get(a))} + } +} \ No newline at end of file diff --git a/src/util/Timing.scala b/src/util/Timing.scala new file mode 100644 index 00000000..680a4b4f --- /dev/null +++ b/src/util/Timing.scala @@ -0,0 +1,100 @@ +package scala.virtualization.lms +package util + +import scala.reflect.{SourceContext, RefinedManifest} +import scala.virtualization.lms.common._ +import scala.virtualization.lms.internal._ + +trait Timing extends Base { + def timeGeneratedCode[A: Manifest](f: => Rep[A], msg: Rep[String] = unit("")): Rep[A] +} + +trait TimingExp extends BaseExp with EffectExp { + case class TimeGeneratedCode[A: Manifest](start: Exp[Long], end: Exp[Long], f: Block[A], msg: Rep[String] = unit("")) extends Def[A] { + val diff = fresh[Long] + } + + def timeGeneratedCode[A: Manifest](f: => Rep[A], msg: Rep[String] = unit("")) = { + val b = reifyEffects(f) + val start = fresh[Long] + val end = fresh[Long] + reflectEffect(TimeGeneratedCode[A](start, end, b, msg), summarizeEffects(b).star) + } + + override def syms(e: Any): List[Sym[Any]] = e match { + case TimeGeneratedCode(a, x, body, msg) => syms(body) + case _ => super.syms(e) + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case TimeGeneratedCode(a, x, body, msg) => effectSyms(body) + case _ => super.boundSyms(e) + } + + override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case TimeGeneratedCode(a, x, body, msg) => freqHot(body) + case _ => super.symsFreq(e) + } + + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case Reflect(TimeGeneratedCode(s,e,body,msg),u,ef) => reflectMirrored(Reflect(TimeGeneratedCode(f(s),f(e),f(body),f(msg)), mapOver(f,u), f(ef))) + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] +} + +trait ScalaGenTiming extends ScalaGenBase with GenericNestedCodegen { + val IR: TimingExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case TimeGeneratedCode(start, end, f, msg) => { + stream.println("val " + quote(start) + " = System.nanoTime") + if (sym.tp != manifest[Unit]) + stream.print("val " + quote(sym) + " = { ") + emitBlock(f) + stream.println(quote(getBlockResult(f))) + if (sym.tp != manifest[Unit]) + stream.println("}") + stream.println("val " + quote(end) + " = System.nanoTime") + stream.print("System.out.println(\"Generated Code Profiling Info: Operation " + quote(msg).replaceAll("\"","") + " completed") + val calcStr = "((" + quote(end) + "-" + quote(start) + ")/(1000*1000))" + stream.println(" in \" + " + calcStr + " + \" milliseconds\")") + } + case _ => super.emitNode(sym, rhs) + } + } +} + + +trait CGenTiming extends CGenBase with GenericNestedCodegen { + val IR: TimingExp + import IR._ + + override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { + case TimeGeneratedCode(start, end, f, msg) => { + LIRTraversal(f) + sym.atPhase(LIRLowering) { + reflectEffect(TimeGeneratedCode(start, end, LIRLowering(f), msg)).asInstanceOf[Exp[T]] + } + } + case _ => super.lowerNode(sym, rhs) + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case t@TimeGeneratedCode(start, end, f, msg) => { + stream.println("struct timeval " + quote(start) + ", " + quote(end) + ", " + quote(t.diff) + ";") + stream.println("gettimeofday(&" + quote(start) + ", NULL);") + emitBlock(f) + stream.println("gettimeofday(&" + quote(end) + ", NULL);") + stream.println("timeval_subtract(&" + quote(t.diff) + ", &" + quote(end) + ", &" + quote(start) + ");") + + stream.print("fprintf(stderr,\"Generated Code Profiling Info: Operation completed in %ld milliseconds\\n\",") + stream.print("((" + quote(t.diff) + ".tv_sec * 1000) + (" +quote(t.diff) + ".tv_usec/1000))") + stream.println(");") + } + case _ => super.emitNode(sym, rhs) + } + } +} diff --git a/test-out/epfl/test9-struct6.check b/test-out/epfl/test1-constcse1.check similarity index 51% rename from test-out/epfl/test9-struct6.check rename to test-out/epfl/test1-constcse1.check index d27d5840..1a307830 100644 --- a/test-out/epfl/test9-struct6.check +++ b/test-out/epfl/test1-constcse1.check @@ -1,17 +1,26 @@ /***************************************** Emitting Generated Code *******************************************/ -class Test extends ((Int)=>(Unit)) { -def apply(x0:Int): Unit = { -val x1 = new Anon189207751(1.0,2.0) -val x2 = println(x1) -val x3 = new Anon189207751(3.0,4.0) -val x4 = println(x3) -x4 +class test1 extends ((Boolean, Long)=>(Long)) { +def apply(x0:Boolean, x1:Long): Long = { +val x3 = if (x0) { +1L +} else { +0L +} +val x4 = x1 + x3 +val x5 = x4 + 133L +val x2 = if (x0) { +1.0 +} else { +0.0 +} +val x6 = x2.asInstanceOf[Long] +val x7 = x5 + x6 +x7 } } /***************************************** End of Generated Code *******************************************/ - -case class Anon189207751(re: Double, im: Double) +147 diff --git a/test-out/epfl/test10-effects1.check b/test-out/epfl/test10-effects1.check index fab9aa63..a9df5c5f 100644 --- a/test-out/epfl/test10-effects1.check +++ b/test-out/epfl/test10-effects1.check @@ -1,5 +1,5 @@ killing: List(Sym(1))/List(Sym(1), Sym(2)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) -**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(3),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2)))), TP(Sym(5),Mutate(Sym(2),Sym(3))), TP(Sym(6),VectorApply(Sym(5),Const(0))), TP(Sym(7),Reflect(Print(Sym(6)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(8),Reify(Sym(7),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(7))))) +**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(3),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2)))), TP(Sym(5),Mutate(Sym(2),Sym(3))), TP(Sym(6),VectorApply(Sym(5),Const(0))), TP(Sym(7),Reflect(Print(Sym(6)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())), TP(Sym(8),Reify(Sym(7),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(7))))) /***************************************** Emitting Generated Code *******************************************/ @@ -9,12 +9,11 @@ val x1 = VectorZeros(Const(100)) val x2 = VectorLiteral(List(Sym(1))) // begin multi // soft deps: x1,x2 -val x3 = VectorUpdate(Sym(1),Const(5),Const(7.0)) +VectorUpdate(Sym(1),Const(5),Const(7.0)) val x5 = x2 // mutated by x3 // end multi val x6 = VectorApply(Sym(5),Const(0)) -val x7 = println(x6) -x7 +println(x6) } } /***************************************** diff --git a/test-out/epfl/test10-effects2.check b/test-out/epfl/test10-effects2.check index c5d02d2c..43c1d4d6 100644 --- a/test-out/epfl/test10-effects2.check +++ b/test-out/epfl/test10-effects2.check @@ -1,26 +1,25 @@ cse: Sym(2) -> Sym(1) killing: List(Sym(1))/List(Sym(1), Sym(2), Sym(3), Sym(4)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) -**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(3),VectorLiteral(List(Sym(1)))), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(8),Mutate(Sym(3),Sym(5))), TP(Sym(10),VectorApply(Sym(8),Const(0))), TP(Sym(12),Reflect(Print(Sym(10)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(2),Copy(Sym(1))), TP(Sym(4),VectorLiteral(List(Sym(2)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(11),VectorApply(Sym(9),Const(0))), TP(Sym(13),Reflect(Print(Sym(11)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))), TP(Sym(14),Reify(Sym(13),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12), Sym(13))))) +**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(3),VectorLiteral(List(Sym(1)))), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(8),Mutate(Sym(3),Sym(5))), TP(Sym(10),VectorApply(Sym(8),Const(0))), TP(Sym(12),Reflect(Print(Sym(10)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())), TP(Sym(2),Copy(Sym(1))), TP(Sym(4),VectorLiteral(List(Sym(2)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(11),VectorApply(Sym(9),Const(0))), TP(Sym(13),Reflect(Print(Sym(11)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))), TP(Sym(14),Reify(Sym(13),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12), Sym(13))))) /***************************************** Emitting Generated Code *******************************************/ class Test extends ((Int)=>(Unit)) { def apply(x0:Int): Unit = { val x1 = VectorZeros(Const(100)) -val x3 = VectorLiteral(List(Sym(1))) val x2 = x1.clone +val x3 = VectorLiteral(List(Sym(1))) val x4 = VectorLiteral(List(Sym(2))) // begin multi // soft deps: x1,x2,x3,x4 -val x5 = VectorUpdate(Sym(1),Const(5),Const(7.0)) +VectorUpdate(Sym(1),Const(5),Const(7.0)) val x8 = x3 // mutated by x5 val x9 = x4 // mutated by x5 // end multi val x10 = VectorApply(Sym(8),Const(0)) -val x12 = println(x10) +println(x10) val x11 = VectorApply(Sym(9),Const(0)) -val x13 = println(x11) -x13 +println(x11) } } /***************************************** diff --git a/test-out/epfl/test10-effects3.check b/test-out/epfl/test10-effects3.check index 35d7e4f4..37ddf772 100644 --- a/test-out/epfl/test10-effects3.check +++ b/test-out/epfl/test10-effects3.check @@ -1,6 +1,6 @@ cse: Sym(2) -> Sym(1) killing: List(Sym(1))/List(Sym(1), Sym(2), Sym(3), Sym(4)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) -**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),Copy(Sym(1))), TP(Sym(3),VectorLiteral(List(Sym(2)))), TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(10),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(4)))), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(9), Sym(10))))) +**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),Copy(Sym(1))), TP(Sym(3),VectorLiteral(List(Sym(2)))), TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(10),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(4)))), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(9), Sym(10))))) /***************************************** Emitting Generated Code *******************************************/ @@ -9,14 +9,13 @@ def apply(x0:Int): Unit = { val x1 = VectorZeros(Const(100)) val x2 = x1.clone val x3 = VectorLiteral(List(Sym(2))) -val x4 = println(x3) +println(x3) // begin multi -// soft deps: x1,x2,x3,x4 -val x5 = VectorUpdate(Sym(1),Const(5),Const(7.0)) +// soft deps: x1,x2,x3, +VectorUpdate(Sym(1),Const(5),Const(7.0)) val x9 = x4 // mutated by x5 // end multi -val x10 = println(x3) -x10 +println(x3) } } /***************************************** diff --git a/test-out/epfl/test10-effects4.check b/test-out/epfl/test10-effects4.check index 888b08a3..a8711169 100644 --- a/test-out/epfl/test10-effects4.check +++ b/test-out/epfl/test10-effects4.check @@ -1,6 +1,6 @@ cse: Sym(3) -> Sym(2) killing: List(Sym(1))/List(Sym(1), Sym(2), Sym(3)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) -**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(4),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3)))), TP(Sym(6),Mutate(Sym(2),Sym(4))), TP(Sym(8),VectorApply(Sym(6),Const(0))), TP(Sym(10),Reflect(Print(Sym(8)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10))))) +**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(4),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3)))), TP(Sym(6),Mutate(Sym(2),Sym(4))), TP(Sym(8),VectorApply(Sym(6),Const(0))), TP(Sym(10),Reflect(Print(Sym(8)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10))))) /***************************************** Emitting Generated Code *******************************************/ @@ -10,12 +10,11 @@ val x1 = VectorZeros(Const(100)) val x2 = VectorLiteral(List(Sym(1))) // begin multi // soft deps: x1,x2,x3 -val x4 = VectorUpdate(Sym(1),Const(5),Const(7.0)) +VectorUpdate(Sym(1),Const(5),Const(7.0)) val x6 = x2 // mutated by x4 // end multi val x8 = VectorApply(Sym(6),Const(0)) -val x10 = println(x8) -x10 +println(x8) } } /***************************************** diff --git a/test-out/epfl/test10-misc1.check b/test-out/epfl/test10-misc1.check index 1f9c7d9e..ddc360ad 100644 --- a/test-out/epfl/test10-misc1.check +++ b/test-out/epfl/test10-misc1.check @@ -2,18 +2,18 @@ TP(Sym(1),VectorZeros(Const(100))) TP(Sym(2),VectorPlus(Sym(1),Sym(1))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(4)))) +TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(4)))) -- before transformation val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -val x4 = println(x3) +println(x3) replacing TP(Sym(2),VectorPlus(Sym(1),Sym(1))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(2),Sym(1)) -val x4 = println(x3) +println(x3) -- done diff --git a/test-out/epfl/test10-misc2.check b/test-out/epfl/test10-misc2.check index 59b395fd..aba09082 100644 --- a/test-out/epfl/test10-misc2.check +++ b/test-out/epfl/test10-misc2.check @@ -4,30 +4,30 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -- before transformation val x4 = x0 == 0 -val x10 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x6 = println(x5) -x6 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x8 = println(x5) -x8 +println(x5) + } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) error: java.lang.AssertionError: assertion failed: already defined: List(TP(Sym(3),VectorPlus(Sym(2),Sym(1)))) for List(TP(Sym(3),VectorPlus(Sym(1),Sym(2)))) -- done diff --git a/test-out/epfl/test10-misc3.check b/test-out/epfl/test10-misc3.check index d2fd9788..f306cc6f 100644 --- a/test-out/epfl/test10-misc3.check +++ b/test-out/epfl/test10-misc3.check @@ -4,91 +4,91 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) TP(Sym(11),Equal(Sym(0),Const(1))) -TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))) -TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(14)))) -TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) +TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))) +TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(14)))) +TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) -- before transformation val x4 = x0 == 0 -val x10 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x6 = println(x5) -x6 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x8 = println(x5) -x8 +println(x5) + } val x11 = x0 == 1 -val x16 = if (x11) { +if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x12 = println(x5) -x12 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x14 = println(x5) -x14 +println(x5) + } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) *** conflict TP(Sym(3),VectorPlus(Sym(1),Sym(2))) *** conflict TP(Sym(5),VectorLength(Sym(18))) -encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) *** conflict TP(Sym(3),VectorPlus(Sym(1),Sym(2))) *** conflict TP(Sym(5),VectorLength(Sym(20))) -- after transformation val x4 = x0 == 0 -val x10 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(2),Sym(1)) val x5 = VectorLength(Sym(3)) -val x6 = println(x5) -x6 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(1),Sym(2)) val x19 = VectorLength(Sym(18)) -val x8 = println(x19) -x8 +println(x19) + } val x11 = x0 == 1 -val x16 = if (x11) { +if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(2),Sym(1)) val x5 = VectorLength(Sym(3)) -val x12 = println(x5) -x12 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x20 = VectorPlus(Sym(1),Sym(2)) val x21 = VectorLength(Sym(20)) -val x14 = println(x21) -x14 +println(x21) + } // note how the last else branch lost sharing of common subexpressions // this is because NestedBlockTransformer does not go through findOrCreateDefinition diff --git a/test-out/epfl/test10-misc4.check b/test-out/epfl/test10-misc4.check index 34efd0a0..0a03bb01 100644 --- a/test-out/epfl/test10-misc4.check +++ b/test-out/epfl/test10-misc4.check @@ -4,87 +4,87 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) TP(Sym(11),Equal(Sym(0),Const(1))) -TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))) -TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(14)))) -TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) +TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))) +TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(14)))) +TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) -- before transformation val x4 = x0 == 0 -val x10 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x6 = println(x5) -x6 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x8 = println(x5) -x8 +println(x5) + } val x11 = x0 == 1 -val x16 = if (x11) { +if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x12 = println(x5) -x12 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x14 = println(x5) -x14 +println(x5) + } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x18 = x0 == 0 -val x29 = if (x18) { +if (x18) { val x19 = VectorZeros(Const(100)) val x20 = VectorZeros(Const(50)) val x21 = VectorPlus(Sym(20),Sym(19)) val x22 = VectorLength(Sym(21)) -val x23 = println(x22) -x23 +println(x22) + } else { val x19 = VectorZeros(Const(100)) val x20 = VectorZeros(Const(50)) val x25 = VectorPlus(Sym(19),Sym(20)) val x26 = VectorLength(Sym(25)) -val x27 = println(x26) -x27 +println(x26) + } val x30 = x0 == 1 -val x35 = if (x30) { +if (x30) { val x19 = VectorZeros(Const(100)) val x20 = VectorZeros(Const(50)) val x21 = VectorPlus(Sym(20),Sym(19)) val x22 = VectorLength(Sym(21)) -val x31 = println(x22) -x31 +println(x22) + } else { val x19 = VectorZeros(Const(100)) val x20 = VectorZeros(Const(50)) val x25 = VectorPlus(Sym(19),Sym(20)) val x26 = VectorLength(Sym(25)) -val x33 = println(x26) -x33 +println(x26) + } // note how the else branches share symbols for expressions again (cf misc3) // but we have created new identifiers for everything. diff --git a/test-out/epfl/test10-misc5.check b/test-out/epfl/test10-misc5.check index 056fdbbe..8c23577b 100644 --- a/test-out/epfl/test10-misc5.check +++ b/test-out/epfl/test10-misc5.check @@ -4,87 +4,87 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) TP(Sym(11),Equal(Sym(0),Const(1))) -TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))) -TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(14)))) -TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) +TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))) +TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(14)))) +TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) -- before transformation val x4 = x0 == 0 -val x10 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x6 = println(x5) -x6 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x8 = println(x5) -x8 +println(x5) + } val x11 = x0 == 1 -val x16 = if (x11) { +if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x12 = println(x5) -x12 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x14 = println(x5) -x14 +println(x5) + } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x4 = x0 == 0 -val x22 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(2),Sym(1)) val x19 = VectorLength(Sym(18)) -val x20 = println(x19) -x20 +println(x19) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x8 = println(x5) -x8 +println(x5) + } val x11 = x0 == 1 -val x27 = if (x11) { +if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(2),Sym(1)) val x19 = VectorLength(Sym(18)) -val x23 = println(x19) -x23 +println(x19) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x25 = println(x5) -x25 +println(x5) + } // trying to retain more expressions from original program. // not resetting graph inbetween runs and smarter pruning of statements based on their inputs. diff --git a/test-out/epfl/test10-transform1.check b/test-out/epfl/test10-transform1.check index 2047ac70..a73470ec 100644 --- a/test-out/epfl/test10-transform1.check +++ b/test-out/epfl/test10-transform1.check @@ -2,16 +2,16 @@ TP(Sym(1),VectorZeros(Const(100))) TP(Sym(2),VectorPlus(Sym(1),Sym(1))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(4)))) +TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(4)))) -- before transformation val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -val x4 = println(x3) +println(x3) -- after transformation val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -val x6 = println(x3) +println(x3) -- done diff --git a/test-out/epfl/test10-transform2.check b/test-out/epfl/test10-transform2.check index db0776a9..658feb5b 100644 --- a/test-out/epfl/test10-transform2.check +++ b/test-out/epfl/test10-transform2.check @@ -4,46 +4,46 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -- before transformation val x4 = x0 == 0 -val x10 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x6 = println(x5) -x6 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x8 = println(x5) -x8 +println(x5) + } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x4 = x0 == 0 -val x18 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x12 = VectorPlus(Sym(2),Sym(1)) val x13 = VectorLength(Sym(12)) -val x14 = println(x13) -x14 +println(x13) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x16 = println(x5) -x16 +println(x5) + } -- done diff --git a/test-out/epfl/test10-transform3.check b/test-out/epfl/test10-transform3.check index 1f3aecb2..ecdbb20c 100644 --- a/test-out/epfl/test10-transform3.check +++ b/test-out/epfl/test10-transform3.check @@ -4,86 +4,86 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) TP(Sym(11),Equal(Sym(0),Const(1))) -TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))) -TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(14)))) -TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) +TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))) +TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(14)))) +TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) -- before transformation val x4 = x0 == 0 -val x10 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x6 = println(x5) -x6 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x8 = println(x5) -x8 +println(x5) + } val x11 = x0 == 1 -val x16 = if (x11) { +if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x12 = println(x5) -x12 +println(x5) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x14 = println(x5) -x14 +println(x5) + } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x4 = x0 == 0 -val x24 = if (x4) { +if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(2),Sym(1)) val x19 = VectorLength(Sym(18)) -val x20 = println(x19) -x20 +println(x19) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x22 = println(x5) -x22 +println(x5) + } val x11 = x0 == 1 -val x29 = if (x11) { +if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(2),Sym(1)) val x19 = VectorLength(Sym(18)) -val x25 = println(x19) -x25 +println(x19) + } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -val x27 = println(x5) -x27 +println(x5) + } -- done diff --git a/test-out/epfl/test10-transformrec3.check b/test-out/epfl/test10-transformrec3.check index 79b60e7c..d2e8d047 100644 --- a/test-out/epfl/test10-transformrec3.check +++ b/test-out/epfl/test10-transformrec3.check @@ -1,11 +1,6 @@ -- before transformation var x1 = null.asInstanceOf[scala.Function1[Double, Double]] var x4 = null.asInstanceOf[scala.Function1[Double, Double]] -x4 = {x5: (Double) => -val x6 = x5-1.0 -val x7 = x1(x6) -x7 -} x1 = {x2: (Double) => val x3 = x2 == 0 val x10 = if (x3) { @@ -17,44 +12,49 @@ x9 } x10 } +x4 = {x5: (Double) => +val x6 = x5-1.0 +val x7 = x1(x6) +x7 +} val x11 = x1(x0) -- after null transformation var x12 = null.asInstanceOf[scala.Function1[Double, Double]] var x13 = null.asInstanceOf[scala.Function1[Double, Double]] -x13 = {x5: (Double) => -val x6 = x5-1.0 -val x14 = x12(x6) -x14 -} x12 = {x2: (Double) => val x3 = x2 == 0 -val x18 = if (x3) { +val x16 = if (x3) { 1.0 } else { -val x16 = x13(x2) -val x17 = x2*x16 -x17 +val x14 = x13(x2) +val x15 = x2*x14 +x15 +} +x16 } +x13 = {x5: (Double) => +val x6 = x5-1.0 +val x18 = x12(x6) x18 } val x20 = x12(x0) -- after transformation var x21 = null.asInstanceOf[scala.Function1[Double, Double]] var x22 = null.asInstanceOf[scala.Function1[Double, Double]] -x22 = /*2*/{x5: (Double) => -val x6 = x5-1.0 -val x23 = x21(x6) -x23 -} x21 = /*2*/{x2: (Double) => val x3 = x2 == 0 -val x27 = if (x3) { +val x25 = if (x3) { 1.0 } else { -val x25 = x22(x2) -val x26 = x2*x25 -x26 +val x23 = x22(x2) +val x24 = x2*x23 +x24 +} +x25 } +x22 = /*2*/{x5: (Double) => +val x6 = x5-1.0 +val x27 = x21(x6) x27 } val x29 = x21(x0) diff --git a/test-out/epfl/test10-worklist1.check b/test-out/epfl/test10-worklist1.check index 96996f9d..73ba82ff 100644 --- a/test-out/epfl/test10-worklist1.check +++ b/test-out/epfl/test10-worklist1.check @@ -7,12 +7,12 @@ register replacement for Sym(3) val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -val x4 = println(x3) +println(x3) ### next install replacement for Sym(1) install replacement for Sym(2) -toAtom transform FieldApply(Sym(1),length) List(Sym(1)) -> List(Sym(8)) +toAtom transform Field(Sym(1),length,Int) List(Sym(1)) -> List(Sym(8)) toAtom transform VectorApply(Sym(1),Sym(9)) List(Sym(1), Sym(9)) -> List(Sym(8), Sym(9)) register replacement for Sym(10) discarding, already have a replacement for Sym(10) @@ -20,7 +20,7 @@ toAtom transform VectorApply(Sym(1),Sym(9)) List(Sym(1), Sym(9)) -> List(Sym(8), discarding, already have a replacement for Sym(10) discarding, already have a replacement for Sym(10) install replacement for Sym(3) -toAtom transform FieldApply(Sym(1),length) List(Sym(1)) -> List(Sym(8)) +toAtom transform Field(Sym(1),length,Int) List(Sym(1)) -> List(Sym(8)) toAtom transform VectorApply(Sym(1),Sym(14)) List(Sym(1), Sym(14)) -> List(Sym(8), Sym(14)) register replacement for Sym(15) discarding, already have a replacement for Sym(15) @@ -31,21 +31,21 @@ discarding, already have a replacement for Sym(16) val x7 = LoopArray(100) { x6 => 0.0 } -val x8 = new VectorDouble(x7,100) +val x8 = new { val data = x7; val length = 100 } val x12 = LoopArray(100) { x9 => val x10 = VectorApply(Sym(8),Sym(9)) val x11 = x10+x10 x11 } -val x13 = new VectorDouble(x12,100) +val x13 = new { val data = x12; val length = 100 } val x18 = LoopArray(100) { x14 => val x15 = VectorApply(Sym(8),Sym(14)) val x16 = VectorApply(Sym(13),Sym(14)) val x17 = x15+x16 x17 } -val x19 = new VectorDouble(x18,100) -val x20 = println(x19) +val x19 = new { val data = x18; val length = 100 } +println(x19) ### next install replacement for Sym(10) @@ -69,5 +69,5 @@ val x32 = x28.apply(x30) val x33 = x31+x32 x33 } -val x35 = new VectorDouble(x34,100) -val x36 = println(x35) +val x35 = new { val data = x34; val length = 100 } +println(x35) diff --git a/test-out/epfl/test10-worklist2.check b/test-out/epfl/test10-worklist2.check index 954d9d12..421f7e0f 100644 --- a/test-out/epfl/test10-worklist2.check +++ b/test-out/epfl/test10-worklist2.check @@ -2,7 +2,7 @@ register replacement for Sym(1) --- code --- val x1 = VectorZeros(Const(100)) -val x3 = println(x1) +println(x1) ### next install replacement for Sym(1) @@ -10,5 +10,5 @@ install replacement for Sym(1) val x6 = LoopArray(100) { x5 => 0.0 } -val x7 = new VectorDouble(x6,100) -val x8 = println(x7) +val x7 = new { val data = x6; val length = 100 } +println(x7) diff --git a/test-out/epfl/test10-worklist21.check b/test-out/epfl/test10-worklist21.check index 0b2cdb5e..1bf13c51 100644 --- a/test-out/epfl/test10-worklist21.check +++ b/test-out/epfl/test10-worklist21.check @@ -6,7 +6,7 @@ register replacement for Sym(3) val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -val x4 = println(x3) +println(x3) ### next install replacement for Sym(1) @@ -20,22 +20,22 @@ register replacement for Sym(17) val x7 = LoopArray(100) { x6 => 0.0 } -val x8 = new VectorDouble(x7,100) +val x8 = new { val data = x7; val length = 100 } val x9 = VectorLength(Sym(8)) val x13 = LoopArray(x9) { x10 => val x11 = VectorApply(Sym(8),Sym(10)) val x12 = x11+x11 x12 } -val x14 = new VectorDouble(x13,x9) +val x14 = new { val data = x13; val length = x9 } val x19 = LoopArray(x9) { x15 => val x16 = VectorApply(Sym(8),Sym(15)) val x17 = VectorApply(Sym(14),Sym(15)) val x18 = x16+x17 x18 } -val x20 = new VectorDouble(x19,x9) -val x21 = println(x20) +val x20 = new { val data = x19; val length = x9 } +println(x20) ### next install replacement for Sym(9) @@ -57,5 +57,5 @@ val x33 = x29.apply(x31) val x34 = x32+x33 x34 } -val x36 = new VectorDouble(x35,100) -val x37 = println(x36) +val x36 = new { val data = x35; val length = 100 } +println(x36) diff --git a/test-out/epfl/test10-worklist22.check b/test-out/epfl/test10-worklist22.check index 954d9d12..421f7e0f 100644 --- a/test-out/epfl/test10-worklist22.check +++ b/test-out/epfl/test10-worklist22.check @@ -2,7 +2,7 @@ register replacement for Sym(1) --- code --- val x1 = VectorZeros(Const(100)) -val x3 = println(x1) +println(x1) ### next install replacement for Sym(1) @@ -10,5 +10,5 @@ install replacement for Sym(1) val x6 = LoopArray(100) { x5 => 0.0 } -val x7 = new VectorDouble(x6,100) -val x8 = println(x7) +val x7 = new { val data = x6; val length = 100 } +println(x7) diff --git a/test-out/epfl/test10-worklist23.check b/test-out/epfl/test10-worklist23.check index 92db0f06..9dbb62d9 100644 --- a/test-out/epfl/test10-worklist23.check +++ b/test-out/epfl/test10-worklist23.check @@ -12,7 +12,7 @@ val x2 = VectorZeros(Const(50)) x2 } val x5 = VectorPlus(Sym(4),Sym(1)) -val x6 = println(x5) +println(x5) ### next install replacement for Sym(1) @@ -35,17 +35,17 @@ val x12 = LoopArray(50) { x11 => } (x12,50) } -val x17 = new VectorDouble(x15,x16) +val x17 = new { val data = x15; val length = x16 } val x18 = VectorLength(Sym(17)) -val x10 = new VectorDouble(x9,100) +val x10 = new { val data = x9; val length = 100 } val x23 = LoopArray(x18) { x19 => val x20 = VectorApply(Sym(17),Sym(19)) val x21 = VectorApply(Sym(10),Sym(19)) val x22 = x20+x21 x22 } -val x24 = new VectorDouble(x23,x18) -val x25 = println(x24) +val x24 = new { val data = x23; val length = x18 } +println(x24) ### next install replacement for Sym(18) @@ -71,5 +71,5 @@ val x36 = x28.apply(x34) val x37 = x35+x36 x37 } -val x39 = new VectorDouble(x38,x16) -val x40 = println(x39) +val x39 = new { val data = x38; val length = x16 } +println(x39) diff --git a/test-out/epfl/test10-worklist3.check b/test-out/epfl/test10-worklist3.check index 33e430bb..17248480 100644 --- a/test-out/epfl/test10-worklist3.check +++ b/test-out/epfl/test10-worklist3.check @@ -13,13 +13,13 @@ val x2 = VectorZeros(Const(50)) x2 } val x5 = VectorPlus(Sym(4),Sym(1)) -val x6 = println(x5) +println(x5) ### next install replacement for Sym(1) install replacement for Sym(2) install replacement for Sym(5) -toAtom transform FieldApply(Sym(4),length) List(Sym(4)) -> List(Sym(17)) +toAtom transform Field(Sym(4),length,Int) List(Sym(4)) -> List(Sym(17)) toAtom transform VectorApply(Sym(4),Sym(18)) List(Sym(4), Sym(18)) -> List(Sym(17), Sym(18)) register replacement for Sym(19) discarding, already have a replacement for Sym(19) @@ -40,16 +40,16 @@ val x12 = LoopArray(50) { x11 => } (50,x12) } -val x17 = new VectorDouble(x15,x16) -val x10 = new VectorDouble(x9,100) +val x17 = new { val data = x15; val length = x16 } +val x10 = new { val data = x9; val length = 100 } val x22 = LoopArray(x16) { x18 => val x19 = VectorApply(Sym(17),Sym(18)) val x20 = VectorApply(Sym(10),Sym(18)) val x21 = x19+x20 x21 } -val x23 = new VectorDouble(x22,x16) -val x24 = println(x23) +val x23 = new { val data = x22; val length = x16 } +println(x23) ### next install replacement for Sym(19) @@ -76,5 +76,5 @@ val x35 = x27.apply(x33) val x36 = x34+x35 x36 } -val x38 = new VectorDouble(x37,x16) -val x39 = println(x38) +val x38 = new { val data = x37; val length = x16 } +println(x38) diff --git a/test-out/epfl/test11-hmm1.check b/test-out/epfl/test11-hmm1.check index 21d18001..883b4269 100644 --- a/test-out/epfl/test11-hmm1.check +++ b/test-out/epfl/test11-hmm1.check @@ -7,43 +7,42 @@ val x1 = new Array[Int](5) val x2 = x1(0) val x3 = x0(0) val x4 = x2 + x3 -val x5 = x1(0) = x4 +x1(0) = x4 val x6 = x0(3) val x7 = x4 + x6 -val x8 = x1(0) = x7 +x1(0) = x7 val x9 = x1(1) val x10 = x0(2) val x11 = x9 + x10 -val x12 = x1(1) = x11 +x1(1) = x11 val x13 = x1(2) val x14 = x0(1) val x15 = x13 + x14 -val x16 = x1(2) = x15 +x1(2) = x15 val x20 = px20 // static data: Array(0,0,1,1,1) var x18 : Int = 0 -val x27 = while (x18 < 5) { +while (x18 < 5) { val x19 = x1(3) val x21 = x20(x18) val x22 = x0(x18) val x23 = x21 * x22 val x24 = x19 + x23 -val x25 = x1(3) = x24 +x1(3) = x24 x18 = x18 + 1 } val x28 = x1(4) val x29 = x28 + x10 -val x30 = x1(4) = x29 +x1(4) = x29 val x31 = x0(4) val x32 = x29 + x31 -val x33 = x1(4) = x32 +x1(4) = x32 x1 } } /***************************************** End of Generated Code *******************************************/ -compilation: ok 1 5 1 diff --git a/test-out/epfl/test11-hmm2.check b/test-out/epfl/test11-hmm2.check index 89b4d5a6..12d98e4f 100644 --- a/test-out/epfl/test11-hmm2.check +++ b/test-out/epfl/test11-hmm2.check @@ -7,46 +7,45 @@ val x1 = new Array[Int](5) val x2 = x1(0) val x4 = x0(0) val x5 = x2 + x4 -val x6 = x1(0) = x5 +x1(0) = x5 val x9 = x0(3) val x10 = x5 + x9 -val x11 = x1(0) = x10 +x1(0) = x10 val x13 = x1(1) -val x15 = x1(1) = x13 +x1(1) = x13 val x8 = x0(2) val x16 = x13 + x8 -val x17 = x1(1) = x16 +x1(1) = x16 val x18 = x1(2) -val x20 = x1(2) = x18 +x1(2) = x18 val x7 = x0(1) val x21 = x18 + x7 -val x22 = x1(2) = x21 +x1(2) = x21 val x26 = px26 // static data: Array(0,0,1,1,1) var x24 : Int = 0 -val x33 = while (x24 < 5) { +while (x24 < 5) { val x25 = x1(3) val x27 = x26(x24) val x28 = x0(x24) val x29 = x27 * x28 val x30 = x25 + x29 -val x31 = x1(3) = x30 +x1(3) = x30 x24 = x24 + 1 } val x34 = x1(4) -val x36 = x1(4) = x34 +x1(4) = x34 val x37 = x34 + x8 -val x38 = x1(4) = x37 +x1(4) = x37 val x12 = x0(4) val x39 = x37 + x12 -val x40 = x1(4) = x39 +x1(4) = x39 x1 } } /***************************************** End of Generated Code *******************************************/ -compilation: ok 1 5 1 diff --git a/test-out/epfl/test11-stencil0.check b/test-out/epfl/test11-stencil0.check index c81f7b67..52e31b80 100644 --- a/test-out/epfl/test11-stencil0.check +++ b/test-out/epfl/test11-stencil0.check @@ -1,11 +1,11 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged$0 extends ((Array[Double])=>(Array[Double])) { +class staged0 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = new Array[Double](20) var x3 : Int = 0 -val x14 = while (x3 < 20) { +while (x3 < 20) { val x4 = x3.doubleValue() val x5 = 2.0 * x4 val x6 = x5 + 3.0 @@ -14,7 +14,7 @@ val x8 = x7.doubleValue() val x9 = 2.0 * x8 val x10 = x9 + 3.0 val x11 = x6 + x10 -val x12 = x1(x3) = x11 +x1(x3) = x11 x3 = x3 + 1 } @@ -25,7 +25,6 @@ x1 End of Generated Code *******************************************/ -compilation: ok 8.0 12.0 16.0 diff --git a/test-out/epfl/test11-stencil1.check b/test-out/epfl/test11-stencil1.check index 2162c64b..b6aa9fd6 100644 --- a/test-out/epfl/test11-stencil1.check +++ b/test-out/epfl/test11-stencil1.check @@ -1,28 +1,28 @@ Map(Sym(10) -> Sym(16), Sym(4) -> Sym(8), Sym(6) -> Sym(12), Sym(7) -> Sym(13), Sym(11) -> Sym(17), Sym(3) -> Sym(7), Sym(5) -> Sym(9), Sym(8) -> Sym(14), Sym(9) -> Sym(15), Sym(2) -> Sym(6)) r0: TP(Sym(3),IntDoubleValue(Sym(2))) -TP(Sym(4),DoubleTimes(Const(2.0),Sym(3))) -TP(Sym(5),DoublePlus(Sym(4),Const(3.0))) -TP(Sym(6),IntPlus(Sym(2),Const(1))) +TP(Sym(4),NumericTimes(Const(2.0),Sym(3))) +TP(Sym(5),NumericPlus(Sym(4),Const(3.0))) +TP(Sym(6),NumericPlus(Sym(2),Const(1))) TP(Sym(7),IntDoubleValue(Sym(6))) -TP(Sym(8),DoubleTimes(Const(2.0),Sym(7))) -TP(Sym(9),DoublePlus(Sym(8),Const(3.0))) -TP(Sym(10),DoublePlus(Sym(5),Sym(9))) -TP(Sym(11),Reflect(ArrayUpdate(Sym(1),Sym(2),Sym(10)),Summary(false,false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) +TP(Sym(8),NumericTimes(Const(2.0),Sym(7))) +TP(Sym(9),NumericPlus(Sym(8),Const(3.0))) +TP(Sym(10),NumericPlus(Sym(5),Sym(9))) +TP(Sym(11),Reflect(ArrayUpdate(Sym(1),Sym(2),Sym(10)),Summary(false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) r1: -TP(Sym(12),IntPlus(Sym(2),Const(2))) +TP(Sym(12),NumericPlus(Sym(2),Const(2))) TP(Sym(13),IntDoubleValue(Sym(12))) -TP(Sym(14),DoubleTimes(Const(2.0),Sym(13))) -TP(Sym(15),DoublePlus(Sym(14),Const(3.0))) -TP(Sym(16),DoublePlus(Sym(9),Sym(15))) -TP(Sym(17),Reflect(ArrayUpdate(Sym(1),Sym(6),Sym(16)),Summary(false,false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) +TP(Sym(14),NumericTimes(Const(2.0),Sym(13))) +TP(Sym(15),NumericPlus(Sym(14),Const(3.0))) +TP(Sym(16),NumericPlus(Sym(9),Sym(15))) +TP(Sym(17),Reflect(ArrayUpdate(Sym(1),Sym(6),Sym(16)),Summary(false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) r2: -TP(Sym(18),IntPlus(Sym(2),Const(3))) +TP(Sym(18),NumericPlus(Sym(2),Const(3))) TP(Sym(19),IntDoubleValue(Sym(18))) -TP(Sym(20),DoubleTimes(Const(2.0),Sym(19))) -TP(Sym(21),DoublePlus(Sym(20),Const(3.0))) -TP(Sym(22),DoublePlus(Sym(15),Sym(21))) -TP(Sym(23),Reflect(ArrayUpdate(Sym(1),Sym(12),Sym(22)),Summary(false,false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) +TP(Sym(20),NumericTimes(Const(2.0),Sym(19))) +TP(Sym(21),NumericPlus(Sym(20),Const(3.0))) +TP(Sym(22),NumericPlus(Sym(15),Sym(21))) +TP(Sym(23),Reflect(ArrayUpdate(Sym(1),Sym(12),Sym(22)),Summary(false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) Map(Sym(10) -> Sym(16), Sym(4) -> Sym(8), Sym(6) -> Sym(12), Sym(7) -> Sym(13), Sym(11) -> Sym(17), Sym(3) -> Sym(7), Sym(5) -> Sym(9), Sym(8) -> Sym(14), Sym(9) -> Sym(15), Sym(2) -> Sym(6)) overlap1: (Sym(9),Sym(15)) @@ -36,7 +36,7 @@ var writes: List((Sym(15),Const(())), (Sym(12),Const(()))) /***************************************** Emitting Generated Code *******************************************/ -class staged$0 extends ((Array[Double])=>(Array[Double])) { +class staged1 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = new Array[Double](20) val x24 = 0.doubleValue() @@ -46,11 +46,11 @@ val x27 = 1.doubleValue() val x28 = 2.0 * x27 val x29 = x28 + 3.0 val x30 = x26 + x29 -val x31 = x1(0) = x30 -var x32: Double = x29 -var x33: Int = 1 +x1(0) = x30 +var x32 = x29 +var x33 = 1 var x35 : Int = 1 -val x48 = while (x35 < 20) { +while (x35 < 20) { val x36 = x32 val x37 = x33 val x39 = x35 + 1 @@ -58,7 +58,7 @@ val x40 = x39.doubleValue() val x41 = 2.0 * x40 val x42 = x41 + 3.0 val x43 = x36 + x42 -val x44 = x1(x37) = x43 +x1(x37) = x43 x32 = x42 x33 = x39 @@ -71,7 +71,6 @@ x1 End of Generated Code *******************************************/ -compilation: ok 8.0 12.0 16.0 diff --git a/test-out/epfl/test11-stencil2a.check b/test-out/epfl/test11-stencil2a.check index c4eafdfc..4a2c6d1e 100644 --- a/test-out/epfl/test11-stencil2a.check +++ b/test-out/epfl/test11-stencil2a.check @@ -1,13 +1,13 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged$0 extends ((Array[Double])=>(Array[Double])) { +class staged2 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = x0.length val x2 = new Array[Double](x1) val x3 = x1 - 1 var x5 : Int = 1 -val x17 = while (x5 < x3) { +while (x5 < x3) { val x6 = x0(x5) val x7 = x5 + 1 val x8 = x0(x7) @@ -17,7 +17,7 @@ val x11 = x5 - 1 val x12 = x0(x11) val x13 = x12 * x6 val x14 = x10 + x13 -val x15 = x2(x5) = x14 +x2(x5) = x14 x5 = x5 + 1 } @@ -28,7 +28,6 @@ x2 End of Generated Code *******************************************/ -compilation: ok 0.0 0.8800000000000001 0.96 diff --git a/test-out/epfl/test11-stencil2b.check b/test-out/epfl/test11-stencil2b.check index e9ae88bd..228d7f25 100644 --- a/test-out/epfl/test11-stencil2b.check +++ b/test-out/epfl/test11-stencil2b.check @@ -1,29 +1,29 @@ Map(Sym(14) -> Sym(20), Sym(10) -> Sym(19), Sym(6) -> Sym(8), Sym(7) -> Sym(16), Sym(13) -> Sym(9), Sym(11) -> Sym(5), Sym(12) -> Sym(6), Sym(5) -> Sym(7), Sym(15) -> Sym(21), Sym(8) -> Sym(17), Sym(9) -> Sym(18)) r0: TP(Sym(6),ArrayApply(Sym(0),Sym(5))) -TP(Sym(7),IntPlus(Sym(5),Const(1))) +TP(Sym(7),NumericPlus(Sym(5),Const(1))) TP(Sym(8),ArrayApply(Sym(0),Sym(7))) -TP(Sym(9),DoubleTimes(Sym(6),Sym(8))) -TP(Sym(10),DoubleMinus(Sym(6),Sym(9))) -TP(Sym(11),IntMinus(Sym(5),Const(1))) +TP(Sym(9),NumericTimes(Sym(6),Sym(8))) +TP(Sym(10),NumericMinus(Sym(6),Sym(9))) +TP(Sym(11),NumericMinus(Sym(5),Const(1))) TP(Sym(12),ArrayApply(Sym(0),Sym(11))) -TP(Sym(13),DoubleTimes(Sym(12),Sym(6))) -TP(Sym(14),DoublePlus(Sym(10),Sym(13))) -TP(Sym(15),Reflect(ArrayUpdate(Sym(2),Sym(5),Sym(14)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(13),NumericTimes(Sym(12),Sym(6))) +TP(Sym(14),NumericPlus(Sym(10),Sym(13))) +TP(Sym(15),Reflect(ArrayUpdate(Sym(2),Sym(5),Sym(14)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) r1: -TP(Sym(16),IntPlus(Sym(5),Const(2))) +TP(Sym(16),NumericPlus(Sym(5),Const(2))) TP(Sym(17),ArrayApply(Sym(0),Sym(16))) -TP(Sym(18),DoubleTimes(Sym(8),Sym(17))) -TP(Sym(19),DoubleMinus(Sym(8),Sym(18))) -TP(Sym(20),DoublePlus(Sym(19),Sym(9))) -TP(Sym(21),Reflect(ArrayUpdate(Sym(2),Sym(7),Sym(20)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(18),NumericTimes(Sym(8),Sym(17))) +TP(Sym(19),NumericMinus(Sym(8),Sym(18))) +TP(Sym(20),NumericPlus(Sym(19),Sym(9))) +TP(Sym(21),Reflect(ArrayUpdate(Sym(2),Sym(7),Sym(20)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) r2: -TP(Sym(22),IntPlus(Sym(5),Const(3))) +TP(Sym(22),NumericPlus(Sym(5),Const(3))) TP(Sym(23),ArrayApply(Sym(0),Sym(22))) -TP(Sym(24),DoubleTimes(Sym(17),Sym(23))) -TP(Sym(25),DoubleMinus(Sym(17),Sym(24))) -TP(Sym(26),DoublePlus(Sym(25),Sym(18))) -TP(Sym(27),Reflect(ArrayUpdate(Sym(2),Sym(16),Sym(26)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(24),NumericTimes(Sym(17),Sym(23))) +TP(Sym(25),NumericMinus(Sym(17),Sym(24))) +TP(Sym(26),NumericPlus(Sym(25),Sym(18))) +TP(Sym(27),Reflect(ArrayUpdate(Sym(2),Sym(16),Sym(26)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) Map(Sym(14) -> Sym(20), Sym(10) -> Sym(19), Sym(6) -> Sym(8), Sym(7) -> Sym(16), Sym(13) -> Sym(9), Sym(11) -> Sym(5), Sym(12) -> Sym(6), Sym(5) -> Sym(7), Sym(15) -> Sym(21), Sym(8) -> Sym(17), Sym(9) -> Sym(18)) overlap1: (Sym(8),Sym(17)) @@ -38,13 +38,13 @@ var writes: List((Sym(17),Const(())), (Sym(18),Const(())), (Sym(16),Const(()))) /***************************************** Emitting Generated Code *******************************************/ -class staged$0 extends ((Array[Double])=>(Array[Double])) { +class staged3 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = x0.length val x2 = new Array[Double](x1) val x3 = x1 - 1 val x28 = x3 > 1 -val x58 = if (x28) { +if (x28) { val x29 = x0(1) val x30 = x0(2) val x31 = x29 * x30 @@ -52,12 +52,12 @@ val x32 = x29 - x31 val x33 = x0(0) val x34 = x33 * x29 val x35 = x32 + x34 -val x36 = x2(1) = x35 -var x37: Double = x30 -var x38: Double = x31 -var x39: Int = 2 +x2(1) = x35 +var x37 = x30 +var x38 = x31 +var x39 = 2 var x41 : Int = 2 -val x56 = while (x41 < x3) { +while (x41 < x3) { val x42 = x37 val x43 = x38 val x44 = x39 @@ -66,14 +66,14 @@ val x47 = x0(x46) val x48 = x42 * x47 val x49 = x42 - x48 val x50 = x49 + x43 -val x51 = x2(x44) = x50 +x2(x44) = x50 x37 = x47 x38 = x48 x39 = x46 x41 = x41 + 1 } -x56 + } else { () } @@ -84,7 +84,6 @@ x2 End of Generated Code *******************************************/ -compilation: ok 0.0 0.8800000000000001 0.96 diff --git a/test-out/epfl/test11-stencil3a.check b/test-out/epfl/test11-stencil3a.check index daab8c4f..c25290ae 100644 --- a/test-out/epfl/test11-stencil3a.check +++ b/test-out/epfl/test11-stencil3a.check @@ -1,13 +1,13 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged$0 extends ((Array[Double])=>(Array[Double])) { +class staged4 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = x0.length val x2 = new Array[Double](x1) val x3 = x1 - 2 var x5 : Int = 2 -val x31 = while (x5 < x3) { +while (x5 < x3) { val x6 = x0(x5) val x7 = x5 + 1 val x8 = x0(x7) @@ -31,7 +31,7 @@ val x25 = x24 * x12 val x26 = x22 + x25 val x27 = x26 * x14 val x28 = x21 + x27 -val x29 = x2(x5) = x28 +x2(x5) = x28 x5 = x5 + 1 } @@ -42,7 +42,6 @@ x2 End of Generated Code *******************************************/ -compilation: ok 0.0 0.0 0.8063999999999999 diff --git a/test-out/epfl/test11-stencil3b.check b/test-out/epfl/test11-stencil3b.check index 28163b4b..8bbc30b8 100644 --- a/test-out/epfl/test11-stencil3b.check +++ b/test-out/epfl/test11-stencil3b.check @@ -1,49 +1,49 @@ Map(Sym(14) -> Sym(19), Sym(10) -> Sym(18), Sym(17) -> Sym(32), Sym(24) -> Sym(12), Sym(6) -> Sym(8), Sym(20) -> Sym(35), Sym(7) -> Sym(15), Sym(27) -> Sym(20), Sym(13) -> Sym(9), Sym(11) -> Sym(5), Sym(12) -> Sym(6), Sym(5) -> Sym(7), Sym(19) -> Sym(34), Sym(23) -> Sym(11), Sym(15) -> Sym(30), Sym(8) -> Sym(16), Sym(9) -> Sym(17), Sym(21) -> Sym(36), Sym(28) -> Sym(37), Sym(16) -> Sym(31), Sym(18) -> Sym(33), Sym(26) -> Sym(14), Sym(29) -> Sym(38), Sym(25) -> Sym(13), Sym(22) -> Sym(10)) r0: TP(Sym(6),ArrayApply(Sym(0),Sym(5))) -TP(Sym(7),IntPlus(Sym(5),Const(1))) +TP(Sym(7),NumericPlus(Sym(5),Const(1))) TP(Sym(8),ArrayApply(Sym(0),Sym(7))) -TP(Sym(9),DoubleTimes(Sym(6),Sym(8))) -TP(Sym(10),DoubleMinus(Sym(6),Sym(9))) -TP(Sym(11),IntMinus(Sym(5),Const(1))) +TP(Sym(9),NumericTimes(Sym(6),Sym(8))) +TP(Sym(10),NumericMinus(Sym(6),Sym(9))) +TP(Sym(11),NumericMinus(Sym(5),Const(1))) TP(Sym(12),ArrayApply(Sym(0),Sym(11))) -TP(Sym(13),DoubleTimes(Sym(12),Sym(6))) -TP(Sym(14),DoublePlus(Sym(10),Sym(13))) -TP(Sym(15),IntPlus(Sym(5),Const(2))) +TP(Sym(13),NumericTimes(Sym(12),Sym(6))) +TP(Sym(14),NumericPlus(Sym(10),Sym(13))) +TP(Sym(15),NumericPlus(Sym(5),Const(2))) TP(Sym(16),ArrayApply(Sym(0),Sym(15))) -TP(Sym(17),DoubleTimes(Sym(8),Sym(16))) -TP(Sym(18),DoubleMinus(Sym(8),Sym(17))) -TP(Sym(19),DoublePlus(Sym(18),Sym(9))) -TP(Sym(20),DoubleTimes(Sym(14),Sym(19))) -TP(Sym(21),DoubleMinus(Sym(14),Sym(20))) -TP(Sym(22),DoubleMinus(Sym(12),Sym(13))) -TP(Sym(23),IntMinus(Sym(5),Const(2))) +TP(Sym(17),NumericTimes(Sym(8),Sym(16))) +TP(Sym(18),NumericMinus(Sym(8),Sym(17))) +TP(Sym(19),NumericPlus(Sym(18),Sym(9))) +TP(Sym(20),NumericTimes(Sym(14),Sym(19))) +TP(Sym(21),NumericMinus(Sym(14),Sym(20))) +TP(Sym(22),NumericMinus(Sym(12),Sym(13))) +TP(Sym(23),NumericMinus(Sym(5),Const(2))) TP(Sym(24),ArrayApply(Sym(0),Sym(23))) -TP(Sym(25),DoubleTimes(Sym(24),Sym(12))) -TP(Sym(26),DoublePlus(Sym(22),Sym(25))) -TP(Sym(27),DoubleTimes(Sym(26),Sym(14))) -TP(Sym(28),DoublePlus(Sym(21),Sym(27))) -TP(Sym(29),Reflect(ArrayUpdate(Sym(2),Sym(5),Sym(28)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(25),NumericTimes(Sym(24),Sym(12))) +TP(Sym(26),NumericPlus(Sym(22),Sym(25))) +TP(Sym(27),NumericTimes(Sym(26),Sym(14))) +TP(Sym(28),NumericPlus(Sym(21),Sym(27))) +TP(Sym(29),Reflect(ArrayUpdate(Sym(2),Sym(5),Sym(28)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) r1: -TP(Sym(30),IntPlus(Sym(5),Const(3))) +TP(Sym(30),NumericPlus(Sym(5),Const(3))) TP(Sym(31),ArrayApply(Sym(0),Sym(30))) -TP(Sym(32),DoubleTimes(Sym(16),Sym(31))) -TP(Sym(33),DoubleMinus(Sym(16),Sym(32))) -TP(Sym(34),DoublePlus(Sym(33),Sym(17))) -TP(Sym(35),DoubleTimes(Sym(19),Sym(34))) -TP(Sym(36),DoubleMinus(Sym(19),Sym(35))) -TP(Sym(37),DoublePlus(Sym(36),Sym(20))) -TP(Sym(38),Reflect(ArrayUpdate(Sym(2),Sym(7),Sym(37)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(32),NumericTimes(Sym(16),Sym(31))) +TP(Sym(33),NumericMinus(Sym(16),Sym(32))) +TP(Sym(34),NumericPlus(Sym(33),Sym(17))) +TP(Sym(35),NumericTimes(Sym(19),Sym(34))) +TP(Sym(36),NumericMinus(Sym(19),Sym(35))) +TP(Sym(37),NumericPlus(Sym(36),Sym(20))) +TP(Sym(38),Reflect(ArrayUpdate(Sym(2),Sym(7),Sym(37)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) r2: -TP(Sym(39),IntPlus(Sym(5),Const(4))) +TP(Sym(39),NumericPlus(Sym(5),Const(4))) TP(Sym(40),ArrayApply(Sym(0),Sym(39))) -TP(Sym(41),DoubleTimes(Sym(31),Sym(40))) -TP(Sym(42),DoubleMinus(Sym(31),Sym(41))) -TP(Sym(43),DoublePlus(Sym(42),Sym(32))) -TP(Sym(44),DoubleTimes(Sym(34),Sym(43))) -TP(Sym(45),DoubleMinus(Sym(34),Sym(44))) -TP(Sym(46),DoublePlus(Sym(45),Sym(35))) -TP(Sym(47),Reflect(ArrayUpdate(Sym(2),Sym(15),Sym(46)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(41),NumericTimes(Sym(31),Sym(40))) +TP(Sym(42),NumericMinus(Sym(31),Sym(41))) +TP(Sym(43),NumericPlus(Sym(42),Sym(32))) +TP(Sym(44),NumericTimes(Sym(34),Sym(43))) +TP(Sym(45),NumericMinus(Sym(34),Sym(44))) +TP(Sym(46),NumericPlus(Sym(45),Sym(35))) +TP(Sym(47),Reflect(ArrayUpdate(Sym(2),Sym(15),Sym(46)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) Map(Sym(14) -> Sym(19), Sym(10) -> Sym(18), Sym(17) -> Sym(32), Sym(24) -> Sym(12), Sym(6) -> Sym(8), Sym(20) -> Sym(35), Sym(7) -> Sym(15), Sym(27) -> Sym(20), Sym(13) -> Sym(9), Sym(11) -> Sym(5), Sym(12) -> Sym(6), Sym(5) -> Sym(7), Sym(19) -> Sym(34), Sym(23) -> Sym(11), Sym(15) -> Sym(30), Sym(8) -> Sym(16), Sym(9) -> Sym(17), Sym(21) -> Sym(36), Sym(28) -> Sym(37), Sym(16) -> Sym(31), Sym(18) -> Sym(33), Sym(26) -> Sym(14), Sym(29) -> Sym(38), Sym(25) -> Sym(13), Sym(22) -> Sym(10)) overlap1: (Sym(16),Sym(31)) @@ -62,13 +62,13 @@ var writes: List((Sym(31),Const(())), (Sym(32),Const(())), (Sym(34),Const(())), /***************************************** Emitting Generated Code *******************************************/ -class staged$0 extends ((Array[Double])=>(Array[Double])) { +class staged5 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = x0.length val x2 = new Array[Double](x1) val x3 = x1 - 2 val x48 = x3 > 2 -val x102 = if (x48) { +if (x48) { val x49 = x0(2) val x50 = x0(3) val x51 = x49 * x50 @@ -88,15 +88,15 @@ val x64 = x63 * x53 val x65 = x62 + x64 val x66 = x65 * x55 val x67 = x61 + x66 -val x68 = x2(2) = x67 -var x69: Double = x56 -var x70: Double = x57 -var x71: Double = x59 -var x72: Double = x60 -var x73: Int = 3 -var x74: Int = 4 +x2(2) = x67 +var x69 = x56 +var x70 = x57 +var x71 = x59 +var x72 = x60 +var x73 = 3 +var x74 = 4 var x76 : Int = 3 -val x100 = while (x76 < x3) { +while (x76 < x3) { val x77 = x69 val x78 = x70 val x79 = x71 @@ -111,7 +111,7 @@ val x88 = x87 + x78 val x89 = x79 * x88 val x90 = x79 - x89 val x91 = x90 + x80 -val x92 = x2(x81) = x91 +x2(x81) = x91 x69 = x85 x70 = x86 x71 = x88 @@ -121,7 +121,7 @@ x74 = x84 x76 = x76 + 1 } -x100 + } else { () } @@ -132,7 +132,6 @@ x2 End of Generated Code *******************************************/ -compilation: ok 0.0 0.0 0.8063999999999999 diff --git a/test-out/epfl/test12-array-seq-creation.check b/test-out/epfl/test12-array-seq-creation.check index 90186aa4..0ecf1b8d 100644 --- a/test-out/epfl/test12-array-seq-creation.check +++ b/test-out/epfl/test12-array-seq-creation.check @@ -5,8 +5,7 @@ class IntArrayCreation extends ((Int)=>(Unit)) { def apply(x0:Int): Unit = { val x1 = Array(1,2,3) val x2 = x1(0) -val x3 = println(x2) -x3 +println(x2) } } /***************************************** @@ -19,8 +18,7 @@ class CharArrayCreation extends ((Int)=>(Unit)) { def apply(x5:Int): Unit = { val x6 = Array('a','b','c') val x7 = x6(0) -val x8 = println(x7) -x8 +println(x7) } } /***************************************** diff --git a/test-out/epfl/test12-map-flatmap-filter.check b/test-out/epfl/test12-map-flatmap-filter.check index 56103dde..c0dc1299 100644 --- a/test-out/epfl/test12-map-flatmap-filter.check +++ b/test-out/epfl/test12-map-flatmap-filter.check @@ -9,6 +9,7 @@ val x4 = x3 < 3 x4 } + val x9 = x0.flatMap { x1 => val x8 = x5.map { x6 => val x7 = x1 * x6 @@ -16,8 +17,10 @@ val x7 = x1 * x6 x7 } + x8 } + x9 } } diff --git a/test-out/epfl/test13-interpret2.check b/test-out/epfl/test13-interpret2.check index a0e6ee66..bf27b950 100644 --- a/test-out/epfl/test13-interpret2.check +++ b/test-out/epfl/test13-interpret2.check @@ -1,15 +1,15 @@ -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(85),Summary(true,true,false,false,false,false,List(),List(),List(Sym(1), Sym(7), Sym(12), Sym(21), Sym(26), Sym(31), Sym(36), Sym(41), Sym(50), Sym(55), Sym(60), Sym(65), Sym(70), Sym(79)),List(Sym(1), Sym(7), Sym(12), Sym(21), Sym(26), Sym(31), Sym(36), Sym(41), Sym(50), Sym(55), Sym(60), Sym(65), Sym(70), Sym(79))),List(Sym(5), Sym(6), Sym(10), Sym(11), Sym(15), Sym(16), Sym(19), Sym(20), Sym(24), Sym(25), Sym(29), Sym(30), Sym(34), Sym(35), Sym(39), Sym(40), Sym(44), Sym(45), Sym(48), Sym(49), Sym(53), Sym(54), Sym(58), Sym(59), Sym(63), Sym(64), Sym(68), Sym(69), Sym(73), Sym(74), Sym(77), Sym(78), Sym(82), Sym(83), Sym(85))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(85),Summary(true,true,false,false,false,List(),List(),List(Sym(1), Sym(7), Sym(12), Sym(21), Sym(26), Sym(31), Sym(36), Sym(41), Sym(50), Sym(55), Sym(60), Sym(65), Sym(70), Sym(79)),List(Sym(1), Sym(7), Sym(12), Sym(21), Sym(26), Sym(31), Sym(36), Sym(41), Sym(50), Sym(55), Sym(60), Sym(65), Sym(70), Sym(79))),List(Sym(5), Sym(6), Sym(10), Sym(11), Sym(15), Sym(16), Sym(19), Sym(20), Sym(24), Sym(25), Sym(29), Sym(30), Sym(34), Sym(35), Sym(39), Sym(40), Sym(44), Sym(45), Sym(48), Sym(49), Sym(53), Sym(54), Sym(58), Sym(59), Sym(63), Sym(64), Sym(68), Sym(69), Sym(73), Sym(74), Sym(77), Sym(78), Sym(82), Sym(83), Sym(85))) /***************************************** Emitting Generated Code *******************************************/ -class staged$0(px2:scala.lms.common.Compile,px3:Object,px4:Object,px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px8:Object,px9:Object,px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px13:Object,px14:Object,px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px17:Object,px18:Object,px22:Object,px23:Object,px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px27:Object,px28:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px32:Object,px33:Object,px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px37:Object,px38:Object,px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px42:Object,px43:Object,px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px46:Object,px47:Object,px51:Object,px52:Object,px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px56:Object,px57:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px61:Object,px62:Object,px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px66:Object,px67:Object,px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px71:Object,px72:Object,px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px75:Object,px76:Object,px80:Object,px81:Object,px79:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x0:java.util.HashMap[java.lang.String, Any]): Any = { -val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +class staged0(px2:scala.virtualization.lms.common.Compile,px3:Object,px4:Object,px1:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px8:Object,px9:Object,px7:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px13:Object,px14:Object,px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px17:Object,px18:Object,px22:Object,px23:Object,px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px27:Object,px28:Object,px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px32:Object,px33:Object,px31:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px37:Object,px38:Object,px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px42:Object,px43:Object,px41:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px46:Object,px47:Object,px51:Object,px52:Object,px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px56:Object,px57:Object,px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px61:Object,px62:Object,px60:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px66:Object,px67:Object,px65:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px71:Object,px72:Object,px70:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px75:Object,px76:Object,px80:Object,px81:Object,px79:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x0:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x3 = px3 // static data: val x4 = px4 // static data: -val x5 = new scala.lms.epfl.test13.RFun { +val x5 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x3.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x4.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -19,9 +19,9 @@ val x1 = px1 // static data: RCell(dyn - ConstN(0)) val x6 = x1.set(x5) val x8 = px8 // static data: val x9 = px9 // static data: -val x10 = new scala.lms.epfl.test13.RFun { +val x10 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x8.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x9.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -31,9 +31,9 @@ val x7 = px7 // static data: RCell(dyn - AssignN(x,ConstN(0))) val x11 = x7.set(x10) val x13 = px13 // static data: val x14 = px14 // static data: -val x15 = new scala.lms.epfl.test13.RFun { +val x15 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x13.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x14.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -43,9 +43,9 @@ val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x16 = x12.set(x15) val x17 = px17 // static data: val x18 = px18 // static data: -val x19 = new scala.lms.epfl.test13.RFun { +val x19 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x17.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x18.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -54,9 +54,9 @@ def execInt(f: HM): Int = fInt(f) val x20 = x12.set(x19) val x22 = px22 // static data: val x23 = px23 // static data: -val x24 = new scala.lms.epfl.test13.RFun { +val x24 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x22.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x23.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -66,9 +66,9 @@ val x21 = px21 // static data: RCell(dyn - ConstN(-1)) val x25 = x21.set(x24) val x27 = px27 // static data: val x28 = px28 // static data: -val x29 = new scala.lms.epfl.test13.RFun { +val x29 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x27.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x28.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -78,9 +78,9 @@ val x26 = px26 // static data: RCell(dyn - AddN(LookupN(n),ConstN(-1))) val x30 = x26.set(x29) val x32 = px32 // static data: val x33 = px33 // static data: -val x34 = new scala.lms.epfl.test13.RFun { +val x34 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x32.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x33.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -90,9 +90,9 @@ val x31 = px31 // static data: RCell(dyn - AssignN(n,AddN(LookupN(n),ConstN(-1)) val x35 = x31.set(x34) val x37 = px37 // static data: val x38 = px38 // static data: -val x39 = new scala.lms.epfl.test13.RFun { +val x39 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x37.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x38.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -102,9 +102,9 @@ val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x40 = x36.set(x39) val x42 = px42 // static data: val x43 = px43 // static data: -val x44 = new scala.lms.epfl.test13.RFun { +val x44 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x42.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x43.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -114,9 +114,9 @@ val x41 = px41 // static data: RCell(dyn - LookupN(a)) val x45 = x41.set(x44) val x46 = px46 // static data: val x47 = px47 // static data: -val x48 = new scala.lms.epfl.test13.RFun { +val x48 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x46.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x47.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -125,9 +125,9 @@ def execInt(f: HM): Int = fInt(f) val x49 = x12.set(x48) val x51 = px51 // static data: val x52 = px52 // static data: -val x53 = new scala.lms.epfl.test13.RFun { +val x53 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x51.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x52.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -137,9 +137,9 @@ val x50 = px50 // static data: RCell(dyn - AppN(LookupN(a),LookupN(n))) val x54 = x50.set(x53) val x56 = px56 // static data: val x57 = px57 // static data: -val x58 = new scala.lms.epfl.test13.RFun { +val x58 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x56.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x57.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -149,9 +149,9 @@ val x55 = px55 // static data: RCell(dyn - AddN(LookupN(x),AppN(LookupN(a),Looku val x59 = x55.set(x58) val x61 = px61 // static data: val x62 = px62 // static data: -val x63 = new scala.lms.epfl.test13.RFun { +val x63 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x61.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x62.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -161,9 +161,9 @@ val x60 = px60 // static data: RCell(dyn - AssignN(x,AddN(LookupN(x),AppN(Lookup val x64 = x60.set(x63) val x66 = px66 // static data: val x67 = px67 // static data: -val x68 = new scala.lms.epfl.test13.RFun { +val x68 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x66.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x67.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -173,9 +173,9 @@ val x65 = px65 // static data: RCell(dyn - SeqN(List(AssignN(n,AddN(LookupN(n),C val x69 = x65.set(x68) val x71 = px71 // static data: val x72 = px72 // static data: -val x73 = new scala.lms.epfl.test13.RFun { +val x73 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x71.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x72.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -185,9 +185,9 @@ val x70 = px70 // static data: RCell(dyn - WhileN(LookupN(n),SeqN(List(AssignN(n val x74 = x70.set(x73) val x75 = px75 // static data: val x76 = px76 // static data: -val x77 = new scala.lms.epfl.test13.RFun { +val x77 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x75.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x76.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -196,9 +196,9 @@ def execInt(f: HM): Int = fInt(f) val x78 = x36.set(x77) val x80 = px80 // static data: val x81 = px81 // static data: -val x82 = new scala.lms.epfl.test13.RFun { +val x82 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x80.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x81.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -215,13 +215,12 @@ x85 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any StaticData(0) /***************************************** Emitting Generated Code *******************************************/ -class staged$1(px88:Any) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x87:java.util.HashMap[java.lang.String, Any]): Any = { +class staged1(px88:Any) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x87:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x88 = px88 // static data: 0 x88 } @@ -230,13 +229,12 @@ x88 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any StaticData(0) /***************************************** Emitting Generated Code *******************************************/ -class staged$2(px88:Any) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x89:java.util.HashMap[java.lang.String, Any]): Int = { +class staged2(px88:Any) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x89:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x88 = px88 // static data: 0 val x90 = x88.asInstanceOf[Int] x90 @@ -246,19 +244,18 @@ x90 End of Generated Code *******************************************/ -compilation: ok error: write to non-mutable Sym(91) -> None -at Sym(94)=Reflect(HashMapUpdate(Sym(91),Const(x),Sym(93)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(91)),List(Sym(91))),List()) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(94),Summary(true,true,false,false,false,false,List(),List(),List(Sym(91)),List(Sym(91))),List(Sym(93), Sym(94))) +at Sym(94)=Reflect(HashMapUpdate(Sym(91),Const(x),Sym(93)),Summary(false,false,false,false,false,List(),List(),List(Sym(91)),List(Sym(91))),List()) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(94),Summary(true,true,false,false,false,List(),List(),List(Sym(91)),List(Sym(91))),List(Sym(93), Sym(94))) /***************************************** Emitting Generated Code *******************************************/ -class staged$3(px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x91:java.util.HashMap[java.lang.String, Any]): Any = { +class staged3(px1:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x91:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x1 = px1 // static data: RCell(dyn - ConstN(0)) val x92 = x1.value val x93 = x92.exec(x91) -val x94 = x91.put("x", x93) +val x94 = x91("x") = x93 x94 } } @@ -266,18 +263,17 @@ x94 End of Generated Code *******************************************/ -compilation: ok error: write to non-mutable Sym(96) -> None -at Sym(98)=Reflect(HashMapUpdate(Sym(96),Const(x),Sym(97)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(96)),List(Sym(96))),List()) +at Sym(98)=Reflect(HashMapUpdate(Sym(96),Const(x),Sym(97)),Summary(false,false,false,false,false,List(),List(),List(Sym(96)),List(Sym(96))),List()) /***************************************** Emitting Generated Code *******************************************/ -class staged$4(px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x96:java.util.HashMap[java.lang.String, Any]): Int = { +class staged4(px1:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x96:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x1 = px1 // static data: RCell(dyn - ConstN(0)) val x92 = x1.value val x97 = x92.exec(x96) -val x98 = x96.put("x", x97) +val x98 = x96("x") = x97 val x99 = x98.asInstanceOf[Int] x99 } @@ -286,14 +282,13 @@ x99 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(101),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged$5 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x101:java.util.HashMap[java.lang.String, Any]): Any = { -val x102 = x101.get("n") +class staged5 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x101:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +val x102 = x101("n") x102 } } @@ -301,14 +296,13 @@ x102 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(103),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged$6 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x103:java.util.HashMap[java.lang.String, Any]): Int = { -val x104 = x103.get("n") +class staged6 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x103:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +val x104 = x103("n") val x105 = x104.asInstanceOf[Int] x105 } @@ -317,14 +311,13 @@ x105 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(106),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged$7 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x106:java.util.HashMap[java.lang.String, Any]): Any = { -val x107 = x106.get("n") +class staged7 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x106:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +val x107 = x106("n") x107 } } @@ -332,14 +325,13 @@ x107 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(108),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged$8 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x108:java.util.HashMap[java.lang.String, Any]): Int = { -val x109 = x108.get("n") +class staged8 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x108:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +val x109 = x108("n") val x110 = x109.asInstanceOf[Int] x110 } @@ -348,13 +340,12 @@ x110 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) /***************************************** Emitting Generated Code *******************************************/ -class staged$9(px112:Any) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x111:java.util.HashMap[java.lang.String, Any]): Any = { +class staged9(px112:Any) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x111:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x112 = px112 // static data: -1 x112 } @@ -363,13 +354,12 @@ x112 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) /***************************************** Emitting Generated Code *******************************************/ -class staged$10(px112:Any) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x113:java.util.HashMap[java.lang.String, Any]): Int = { +class staged10(px112:Any) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x113:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x112 = px112 // static data: -1 val x114 = x112.asInstanceOf[Int] x114 @@ -379,13 +369,12 @@ x114 End of Generated Code *******************************************/ -compilation: ok -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(134),Summary(true,true,false,false,false,false,List(),List(),List(Sym(26)),List()),List(Sym(117), Sym(119), Sym(134))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(134),Summary(true,true,false,false,false,List(),List(),List(Sym(26)),List()),List(Sym(117), Sym(119), Sym(134))) /***************************************** Emitting Generated Code *******************************************/ -class staged$11(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px124:Object,px125:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x115:java.util.HashMap[java.lang.String, Any]): Any = { +class staged11(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px2:scala.virtualization.lms.common.Compile,px124:Object,px125:Object,px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x115:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x117 = x116.exec(x115) @@ -394,15 +383,19 @@ val x118 = x21.value val x119 = x118.exec(x115) val x120 = x117.isInstanceOf[Int] val x121 = x119.isInstanceOf[Int] -val x122 = x120 && x121 +val x122 = if (x120 == true) { + +x121 +} else false + val x134 = if (x122) { val x123 = println("spec-add-int: AddN(LookupN(n),ConstN(-1))") -val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x124 = px124 // static data: val x125 = px125 // static data: -val x126 = new scala.lms.epfl.test13.RFun { +val x126 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x124.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x125.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -425,12 +418,11 @@ x134 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$12(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px143:Object,px144:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x136:java.util.HashMap[java.lang.String, Any]): Int = { +class staged12(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px2:scala.virtualization.lms.common.Compile,px143:Object,px144:Object,px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x136:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x137 = x116.exec(x136) @@ -439,15 +431,19 @@ val x118 = x21.value val x138 = x118.exec(x136) val x139 = x137.isInstanceOf[Int] val x140 = x138.isInstanceOf[Int] -val x141 = x139 && x140 +val x141 = if (x139 == true) { + +x140 +} else false + val x153 = if (x141) { val x142 = println("spec-add-int: AddN(LookupN(n),ConstN(-1))") -val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x143 = px143 // static data: val x144 = px144 // static data: -val x145 = new scala.lms.epfl.test13.RFun { +val x145 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x143.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x144.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -471,19 +467,18 @@ x154 End of Generated Code *******************************************/ -compilation: ok error: write to non-mutable Sym(156) -> None -at Sym(159)=Reflect(HashMapUpdate(Sym(156),Const(n),Sym(158)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(156)),List(Sym(156))),List()) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(159),Summary(true,true,false,false,false,false,List(),List(),List(Sym(156)),List(Sym(156))),List(Sym(158), Sym(159))) +at Sym(159)=Reflect(HashMapUpdate(Sym(156),Const(n),Sym(158)),Summary(false,false,false,false,false,List(),List(),List(Sym(156)),List(Sym(156))),List()) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(159),Summary(true,true,false,false,false,List(),List(),List(Sym(156)),List(Sym(156))),List(Sym(158), Sym(159))) /***************************************** Emitting Generated Code *******************************************/ -class staged$13(px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x156:java.util.HashMap[java.lang.String, Any]): Any = { +class staged13(px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x156:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x26 = px26 // static data: RCell(dyn - AddN(LookupN(n),ConstN(-1))) val x157 = x26.value val x158 = x157.exec(x156) -val x159 = x156.put("n", x158) +val x159 = x156("n") = x158 x159 } } @@ -491,18 +486,17 @@ x159 End of Generated Code *******************************************/ -compilation: ok error: write to non-mutable Sym(161) -> None -at Sym(163)=Reflect(HashMapUpdate(Sym(161),Const(n),Sym(162)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(161)),List(Sym(161))),List()) +at Sym(163)=Reflect(HashMapUpdate(Sym(161),Const(n),Sym(162)),Summary(false,false,false,false,false,List(),List(),List(Sym(161)),List(Sym(161))),List()) /***************************************** Emitting Generated Code *******************************************/ -class staged$14(px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x161:java.util.HashMap[java.lang.String, Any]): Int = { +class staged14(px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x161:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x26 = px26 // static data: RCell(dyn - AddN(LookupN(n),ConstN(-1))) val x157 = x26.value val x162 = x157.exec(x161) -val x163 = x161.put("n", x162) +val x163 = x161("n") = x162 val x164 = x163.asInstanceOf[Int] x164 } @@ -511,14 +505,13 @@ x164 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(166),Const(x)) /***************************************** Emitting Generated Code *******************************************/ -class staged$15 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x166:java.util.HashMap[java.lang.String, Any]): Any = { -val x167 = x166.get("x") +class staged15 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x166:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +val x167 = x166("x") x167 } } @@ -526,14 +519,13 @@ x167 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(168),Const(x)) /***************************************** Emitting Generated Code *******************************************/ -class staged$16 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x168:java.util.HashMap[java.lang.String, Any]): Int = { -val x169 = x168.get("x") +class staged16 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x168:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +val x169 = x168("x") val x170 = x169.asInstanceOf[Int] x170 } @@ -542,14 +534,13 @@ x170 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(171),Const(a)) /***************************************** Emitting Generated Code *******************************************/ -class staged$17 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x171:java.util.HashMap[java.lang.String, Any]): Any = { -val x172 = x171.get("a") +class staged17 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x171:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +val x172 = x171("a") x172 } } @@ -557,14 +548,13 @@ x172 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(173),Const(a)) /***************************************** Emitting Generated Code *******************************************/ -class staged$18 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x173:java.util.HashMap[java.lang.String, Any]): Int = { -val x174 = x173.get("a") +class staged18 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x173:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +val x174 = x173("a") val x175 = x174.asInstanceOf[Int] x175 } @@ -573,14 +563,13 @@ x175 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(176),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged$19 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x176:java.util.HashMap[java.lang.String, Any]): Any = { -val x177 = x176.get("n") +class staged19 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x176:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +val x177 = x176("n") x177 } } @@ -588,14 +577,13 @@ x177 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(178),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged$20 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x178:java.util.HashMap[java.lang.String, Any]): Int = { -val x179 = x178.get("n") +class staged20 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x178:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +val x179 = x178("n") val x180 = x179.asInstanceOf[Int] x180 } @@ -604,13 +592,12 @@ x180 End of Generated Code *******************************************/ -compilation: ok -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(186),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(183), Sym(184))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(186),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(183), Sym(184))) /***************************************** Emitting Generated Code *******************************************/ -class staged$21(px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x181:java.util.HashMap[java.lang.String, Any]): Any = { +class staged21(px41:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x181:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x41 = px41 // static data: RCell(dyn - LookupN(a)) val x182 = x41.value val x183 = x182.exec(x181) @@ -626,12 +613,11 @@ x186 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$22(px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x188:java.util.HashMap[java.lang.String, Any]): Int = { +class staged22(px41:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x188:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x41 = px41 // static data: RCell(dyn - LookupN(a)) val x182 = x41.value val x189 = x182.exec(x188) @@ -648,13 +634,12 @@ x193 End of Generated Code *******************************************/ -compilation: ok -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(214),Summary(true,true,false,false,false,false,List(),List(),List(Sym(55)),List()),List(Sym(197), Sym(199), Sym(214))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(214),Summary(true,true,false,false,false,List(),List(),List(Sym(55)),List()),List(Sym(197), Sym(199), Sym(214))) /***************************************** Emitting Generated Code *******************************************/ -class staged$23(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px204:Object,px205:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x195:java.util.HashMap[java.lang.String, Any]): Any = { +class staged23(px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px2:scala.virtualization.lms.common.Compile,px204:Object,px205:Object,px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x195:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value val x197 = x196.exec(x195) @@ -663,15 +648,19 @@ val x198 = x50.value val x199 = x198.exec(x195) val x200 = x197.isInstanceOf[Int] val x201 = x199.isInstanceOf[Int] -val x202 = x200 && x201 +val x202 = if (x200 == true) { + +x201 +} else false + val x214 = if (x202) { val x203 = println("spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))") -val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x204 = px204 // static data: val x205 = px205 // static data: -val x206 = new scala.lms.epfl.test13.RFun { +val x206 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x204.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x205.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -694,12 +683,11 @@ x214 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$24(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px223:Object,px224:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x216:java.util.HashMap[java.lang.String, Any]): Int = { +class staged24(px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px2:scala.virtualization.lms.common.Compile,px223:Object,px224:Object,px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x216:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value val x217 = x196.exec(x216) @@ -708,15 +696,19 @@ val x198 = x50.value val x218 = x198.exec(x216) val x219 = x217.isInstanceOf[Int] val x220 = x218.isInstanceOf[Int] -val x221 = x219 && x220 +val x221 = if (x219 == true) { + +x220 +} else false + val x233 = if (x221) { val x222 = println("spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))") -val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x223 = px223 // static data: val x224 = px224 // static data: -val x225 = new scala.lms.epfl.test13.RFun { +val x225 = new scala.virtualization.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = java.util.HashMap[String,Any] +type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x223.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x224.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -740,19 +732,18 @@ x234 End of Generated Code *******************************************/ -compilation: ok error: write to non-mutable Sym(236) -> None -at Sym(239)=Reflect(HashMapUpdate(Sym(236),Const(x),Sym(238)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(236)),List(Sym(236))),List()) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(239),Summary(true,true,false,false,false,false,List(),List(),List(Sym(236)),List(Sym(236))),List(Sym(238), Sym(239))) +at Sym(239)=Reflect(HashMapUpdate(Sym(236),Const(x),Sym(238)),Summary(false,false,false,false,false,List(),List(),List(Sym(236)),List(Sym(236))),List()) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(239),Summary(true,true,false,false,false,List(),List(),List(Sym(236)),List(Sym(236))),List(Sym(238), Sym(239))) /***************************************** Emitting Generated Code *******************************************/ -class staged$25(px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x236:java.util.HashMap[java.lang.String, Any]): Any = { +class staged25(px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x236:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x55 = px55 // static data: RCell(dyn - AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))) val x237 = x55.value val x238 = x237.exec(x236) -val x239 = x236.put("x", x238) +val x239 = x236("x") = x238 x239 } } @@ -760,18 +751,17 @@ x239 End of Generated Code *******************************************/ -compilation: ok error: write to non-mutable Sym(241) -> None -at Sym(243)=Reflect(HashMapUpdate(Sym(241),Const(x),Sym(242)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(241)),List(Sym(241))),List()) +at Sym(243)=Reflect(HashMapUpdate(Sym(241),Const(x),Sym(242)),Summary(false,false,false,false,false,List(),List(),List(Sym(241)),List(Sym(241))),List()) /***************************************** Emitting Generated Code *******************************************/ -class staged$26(px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x241:java.util.HashMap[java.lang.String, Any]): Int = { +class staged26(px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x241:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x55 = px55 // static data: RCell(dyn - AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))) val x237 = x55.value val x242 = x237.exec(x241) -val x243 = x241.put("x", x242) +val x243 = x241("x") = x242 val x244 = x243.asInstanceOf[Int] x244 } @@ -780,13 +770,12 @@ x244 End of Generated Code *******************************************/ -compilation: ok -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(250),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(248), Sym(250))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(250),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(248), Sym(250))) /***************************************** Emitting Generated Code *******************************************/ -class staged$27(px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x246:java.util.HashMap[java.lang.String, Any]): Any = { +class staged27(px31:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px60:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x246:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x31 = px31 // static data: RCell(dyn - AssignN(n,AddN(LookupN(n),ConstN(-1)))) val x247 = x31.value val x248 = x247.exec(x246) @@ -800,12 +789,11 @@ x250 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$28(px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x252:java.util.HashMap[java.lang.String, Any]): Int = { +class staged28(px31:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px60:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x252:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x31 = px31 // static data: RCell(dyn - AssignN(n,AddN(LookupN(n),ConstN(-1)))) val x247 = x31.value val x253 = x247.exec(x252) @@ -820,20 +808,21 @@ x255 End of Generated Code *******************************************/ -compilation: ok -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(264),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(264))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(264),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(264))) /***************************************** Emitting Generated Code *******************************************/ -class staged$29(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x257:java.util.HashMap[java.lang.String, Any]): Any = { +class staged29(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px65:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x257:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x65 = px65 // static data: RCell(dyn - SeqN(List(AssignN(n,AddN(LookupN(n),ConstN(-1))), AssignN(x,AddN(LookupN(x),AppN(LookupN(a),LookupN(n))))))) val x261 = x65.value -val x264 = while ({val x258 = x116.execInt(x257) +val x264 = while ({ +val x258 = x116.execInt(x257) val x259 = x258 != 0 -x259}) { +x259 +}) { val x262 = x261.exec(x257) () } @@ -844,19 +833,20 @@ x264 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$30(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x266:java.util.HashMap[java.lang.String, Any]): Int = { +class staged30(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px65:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x266:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x65 = px65 // static data: RCell(dyn - SeqN(List(AssignN(n,AddN(LookupN(n),ConstN(-1))), AssignN(x,AddN(LookupN(x),AppN(LookupN(a),LookupN(n))))))) val x261 = x65.value -val x272 = while ({val x267 = x116.execInt(x266) +val x272 = while ({ +val x267 = x116.execInt(x266) val x268 = x267 != 0 -x268}) { +x268 +}) { val x270 = x261.exec(x266) () } @@ -868,14 +858,13 @@ x273 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(275),Const(x)) /***************************************** Emitting Generated Code *******************************************/ -class staged$31 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x275:java.util.HashMap[java.lang.String, Any]): Any = { -val x276 = x275.get("x") +class staged31 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x275:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +val x276 = x275("x") x276 } } @@ -883,14 +872,13 @@ x276 End of Generated Code *******************************************/ -compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(277),Const(x)) /***************************************** Emitting Generated Code *******************************************/ -class staged$32 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x277:java.util.HashMap[java.lang.String, Any]): Int = { -val x278 = x277.get("x") +class staged32 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x277:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +val x278 = x277("x") val x279 = x278.asInstanceOf[Int] x279 } @@ -899,13 +887,12 @@ x279 End of Generated Code *******************************************/ -compilation: ok -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(285),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(282), Sym(284), Sym(285))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(285),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(282), Sym(284), Sym(285))) /***************************************** Emitting Generated Code *******************************************/ -class staged$33(px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x280:java.util.HashMap[java.lang.String, Any]): Any = { +class staged33(px7:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px70:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x280:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x7 = px7 // static data: RCell(dyn - AssignN(x,ConstN(0))) val x281 = x7.value val x282 = x281.exec(x280) @@ -922,12 +909,11 @@ x285 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$34(px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x287:java.util.HashMap[java.lang.String, Any]): Int = { +class staged34(px7:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px70:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x287:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x7 = px7 // static data: RCell(dyn - AssignN(x,ConstN(0))) val x281 = x7.value val x288 = x281.exec(x287) @@ -945,14 +931,13 @@ x291 End of Generated Code *******************************************/ -compilation: ok spec-add-int: AddN(LookupN(n),ConstN(-1)) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(296),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(294), Sym(295))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(296),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(294), Sym(295))) /***************************************** Emitting Generated Code *******************************************/ -class staged$35(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x293:java.util.HashMap[java.lang.String, Any]): Any = { +class staged35(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x293:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x294 = x116.execInt(x293) @@ -967,12 +952,11 @@ x296 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$36(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x298:java.util.HashMap[java.lang.String, Any]): Int = { +class staged36(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x298:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x299 = x116.execInt(x298) @@ -987,14 +971,13 @@ x301 End of Generated Code *******************************************/ -compilation: ok spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(306),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(304), Sym(305))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(306),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(304), Sym(305))) /***************************************** Emitting Generated Code *******************************************/ -class staged$37(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x303:java.util.HashMap[java.lang.String, Any]): Any = { +class staged37(px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x303:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value val x304 = x196.execInt(x303) @@ -1009,12 +992,11 @@ x306 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$38(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x308:java.util.HashMap[java.lang.String, Any]): Int = { +class staged38(px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x308:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value val x309 = x196.execInt(x308) @@ -1029,5 +1011,4 @@ x311 End of Generated Code *******************************************/ -compilation: ok 65280 diff --git a/test-out/epfl/test13-interpret3.check b/test-out/epfl/test13-interpret3.check index faef1cd4..4fa0fe35 100644 --- a/test-out/epfl/test13-interpret3.check +++ b/test-out/epfl/test13-interpret3.check @@ -1,63 +1,67 @@ -call with arg {a=SomethingElse, n=256} +call with arg Map(n -> 256, a -> SomethingElse) (re) compiling -read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) sym Sym(3) +read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) sym Sym(3) -- Sym(2) -read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) sym Sym(7) +read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) sym Sym(7) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(2),Const(n)) -read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) +read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(29),Summary(true,true,false,false,false,false,List(),List(),List(Sym(3)),List()),List(Sym(29))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(35),Summary(true,true,false,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(32), Sym(34), Sym(35))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(37),Summary(true,true,false,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(37))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(42),Summary(true,true,false,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(39), Sym(41), Sym(42))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(44),Summary(true,true,false,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(44))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(49),Summary(true,true,false,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(46), Sym(48), Sym(49))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(51),Summary(true,true,false,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(1), Sym(2), Sym(51))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(29),Summary(true,true,false,false,false,List(),List(),List(Sym(3)),List()),List(Sym(29))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(35),Summary(true,true,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(32), Sym(34), Sym(35))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(37),Summary(true,true,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(37))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(42),Summary(true,true,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(39), Sym(41), Sym(42))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(44),Summary(true,true,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(44))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(49),Summary(true,true,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(46), Sym(48), Sym(49))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(51),Summary(true,true,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(1), Sym(2), Sym(51))) /***************************************** Emitting Generated Code *******************************************/ -class staged$0(px3:scala.lms.epfl.test13.RCell[Object],px5:Object,px7:scala.lms.epfl.test13.RCell[Object],px9:Object,px12:scala.lms.epfl.test13.RCell[Object],px14:Object,px16:Any,px21:Object,px31:scala.lms.epfl.test13.RCell[scala.Function1[java.util.HashMap[java.lang.String, Any], Any]],px33:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px40:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px47:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x0:java.util.HashMap[java.lang.String, Any]): Any = { -var x1: java.util.HashMap[java.lang.String, Any] = x0 +class staged39(px3:scala.virtualization.lms.epfl.test13.RCell[Object],px5:Object,px7:scala.virtualization.lms.epfl.test13.RCell[Object],px9:Object,px12:scala.virtualization.lms.epfl.test13.RCell[Object],px14:Object,px16:Any,px21:Object,px31:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[scala.collection.mutable.HashMap[java.lang.String, Any], Any]],px33:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px40:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px47:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x0:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +var x1 = x0 val x2 = x1 -val x3 = px3 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) +val x3 = px3 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) val x4 = x3.value -val x5 = px5 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$23@XXX +val x5 = px5 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$24@XXX val x6 = x4 == x5 val x51 = if (x6) { -val x7 = px7 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) +val x7 = px7 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) val x8 = x7.value -val x9 = px9 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$27@XXX +val x9 = px9 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$28@XXX val x10 = x8 == x9 val x44 = if (x10) { -val x12 = px12 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) +val x12 = px12 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) val x13 = x12.value -val x14 = px14 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$29@XXX +val x14 = px14 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$30@XXX val x15 = x13 == x14 val x37 = if (x15) { -val x11 = x2.get("n") +val x11 = x2("n") val x17 = x11.isInstanceOf[Int] val x16 = px16 // static data: -1 val x18 = x16.isInstanceOf[Int] -val x19 = x17 && x18 +val x19 = if (x17 == true) { + +x18 +} else false + val x29 = if (x19) { -val x20 = println("spec-add-int: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX") -val x21 = px21 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$24@XXX -val x22 = x3.set(x21) +println("spec-add-int: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX") +val x21 = px21 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$25@XXX +x3.set(x21) val x23 = x11.asInstanceOf[Int] val x24 = x16.asInstanceOf[Int] val x25 = x23 + x24 x25 } else { -val x27 = println("GENERIC") -x27 +println("GENERIC") + } x29 } else { val x31 = px31 // static data: RCell(code) -val x32 = x31.set(null) +x31.set(null) val x33 = px33 // static data: val x34 = x33.apply(List(x13, x2))// compile dynamic: fv = List(Sym(13), Sym(2)) val x35 = x34.apply(()) @@ -66,7 +70,7 @@ x35 x37 } else { val x31 = px31 // static data: RCell(code) -val x39 = x31.set(null) +x31.set(null) val x40 = px40 // static data: val x41 = x40.apply(List(x8, x2))// compile dynamic: fv = List(Sym(8), Sym(2)) val x42 = x41.apply(()) @@ -75,7 +79,7 @@ x42 x44 } else { val x31 = px31 // static data: RCell(code) -val x46 = x31.set(null) +x31.set(null) val x47 = px47 // static data: val x48 = x47.apply(List(x4, x2))// compile dynamic: fv = List(Sym(4), Sym(2)) val x49 = x48.apply(()) @@ -88,38 +92,37 @@ x51 End of Generated Code *******************************************/ -compilation: ok -spec-add-int: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX +spec-add-int: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX 255 -call with arg {a=SomethingElse, n=256} +call with arg Map(n -> 256, a -> SomethingElse) -- Sym(2) -read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) sym Sym(6) +read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) sym Sym(6) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(2),Const(n)) -read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) +read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(23),Summary(true,true,false,false,false,false,List(),List(),List(Sym(19)),List(Sym(19))),List(Sym(20), Sym(22), Sym(23))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(25),Summary(true,false,false,false,false,false,List(),List(),List(Sym(19)),List()),List(Sym(25))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(30),Summary(true,true,false,false,false,false,List(),List(),List(Sym(19)),List(Sym(19))),List(Sym(27), Sym(29), Sym(30))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(32),Summary(true,false,false,false,false,false,List(),List(),List(Sym(19)),List()),List(Sym(32))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(23),Summary(true,true,false,false,false,List(),List(),List(Sym(19)),List(Sym(19))),List(Sym(20), Sym(22), Sym(23))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(25),Summary(true,false,false,false,false,List(),List(),List(Sym(19)),List()),List(Sym(25))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(30),Summary(true,true,false,false,false,List(),List(),List(Sym(19)),List(Sym(19))),List(Sym(27), Sym(29), Sym(30))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(32),Summary(true,false,false,false,false,List(),List(),List(Sym(19)),List()),List(Sym(32))) /***************************************** Emitting Generated Code *******************************************/ -class staged$1(px6:scala.lms.epfl.test13.RCell[Object],px8:Object,px12:scala.lms.epfl.test13.RCell[Object],px14:Object,px2:java.util.HashMap[java.lang.String, Any],px16:Any,px19:scala.lms.epfl.test13.RCell[scala.Function1[java.util.HashMap[java.lang.String, Any], Any]],px21:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px28:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((Unit)=>(Any)) { +class staged40(px6:scala.virtualization.lms.epfl.test13.RCell[Object],px8:Object,px12:scala.virtualization.lms.epfl.test13.RCell[Object],px14:Object,px2:scala.collection.mutable.HashMap[java.lang.String, Any],px16:Any,px19:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[scala.collection.mutable.HashMap[java.lang.String, Any], Any]],px21:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px28:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((Unit)=>(Any)) { def apply(x5:Unit): Any = { -val x6 = px6 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) +val x6 = px6 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) val x7 = x6.value -val x8 = px8 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$27@XXX +val x8 = px8 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$28@XXX val x9 = x7 == x8 val x32 = if (x9) { -val x12 = px12 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) +val x12 = px12 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) val x13 = x12.value -val x14 = px14 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$29@XXX +val x14 = px14 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$30@XXX val x15 = x13 == x14 val x25 = if (x15) { -val x2 = px2 // static data: {a=SomethingElse, n=256} -val x10 = x2.get("n") +val x2 = px2 // static data: Map(n -> 256, a -> SomethingElse) +val x10 = x2("n") val x11 = x10.asInstanceOf[Int] val x16 = px16 // static data: -1 val x17 = x16.asInstanceOf[Int] @@ -127,8 +130,8 @@ val x18 = x11 + x17 x18 } else { val x19 = px19 // static data: RCell(code) -val x20 = x19.set(null) -val x2 = px2 // static data: {a=SomethingElse, n=256} +x19.set(null) +val x2 = px2 // static data: Map(n -> 256, a -> SomethingElse) val x21 = px21 // static data: val x22 = x21.apply(List(x13, x2))// compile dynamic: fv = List(Sym(13), Sym(2)) val x23 = x22.apply(()) @@ -137,8 +140,8 @@ x23 x25 } else { val x19 = px19 // static data: RCell(code) -val x27 = x19.set(null) -val x2 = px2 // static data: {a=SomethingElse, n=256} +x19.set(null) +val x2 = px2 // static data: Map(n -> 256, a -> SomethingElse) val x28 = px28 // static data: val x29 = x28.apply(List(x7, x2))// compile dynamic: fv = List(Sym(7), Sym(2)) val x30 = x29.apply(()) @@ -151,5 +154,4 @@ x32 End of Generated Code *******************************************/ -compilation: ok 255 diff --git a/test-out/epfl/test13-stable1.check b/test-out/epfl/test13-stable1.check index 492235b0..0c2b800f 100644 --- a/test-out/epfl/test13-stable1.check +++ b/test-out/epfl/test13-stable1.check @@ -1,7 +1,7 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged$0(px3:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Int, Int]],px5:scala.lms.epfl.test13.RCell[Int]) extends ((Int)=>(Int)) { +class staged0(px3:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Int, Int]],px5:scala.virtualization.lms.epfl.test13.RCell[Int]) extends ((Int)=>(Int)) { def apply(x0:Int): Int = { val x1 = x0 + 1 val x2 = x0 * 2 @@ -17,11 +17,10 @@ x7 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$1(px1:Int,px2:Int) extends ((Int)=>(Int)) { +class staged1(px1:Int,px2:Int) extends ((Int)=>(Int)) { def apply(x3:Int): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -34,12 +33,11 @@ x5 End of Generated Code *******************************************/ -compilation: ok 28 /***************************************** Emitting Generated Code *******************************************/ -class staged$2(px1:Int,px2:Int) extends ((Int)=>(Int)) { +class staged2(px1:Int,px2:Int) extends ((Int)=>(Int)) { def apply(x3:Int): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -52,12 +50,11 @@ x5 End of Generated Code *******************************************/ -compilation: ok 140 /***************************************** Emitting Generated Code *******************************************/ -class staged$3(px1:Int,px2:Int) extends ((Int)=>(Int)) { +class staged3(px1:Int,px2:Int) extends ((Int)=>(Int)) { def apply(x3:Int): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -70,5 +67,4 @@ x5 End of Generated Code *******************************************/ -compilation: ok 56 diff --git a/test-out/epfl/test13-stable2.check b/test-out/epfl/test13-stable2.check index c6338b0e..e26a7174 100644 --- a/test-out/epfl/test13-stable2.check +++ b/test-out/epfl/test13-stable2.check @@ -4,41 +4,41 @@ read value RCell(stable) sym Sym(3) /***************************************** Emitting Generated Code *******************************************/ -class staged$0(px3:scala.lms.epfl.test13.RCell[Int],px5:Int,px8:scala.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px10:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { +class staged4(px3:scala.virtualization.lms.epfl.test13.RCell[Int],px5:Int,px9:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px11:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { def apply(x0:Int): Int = { val x3 = px3 // static data: RCell(stable) val x4 = x3.value val x5 = px5 // static data: 1 val x6 = x4 == x5 -val x14 = if (x6) { +val x15 = if (x6) { val x1 = x0 + 1 val x2 = x0 * 2 val x7 = x1 + x2 -x7 +val x8 = 1 * x7 +x8 } else { -val x8 = px8 // static data: RCell(code) -val x9 = x8.set(null) +val x9 = px9 // static data: RCell(code) +x9.set(null) val x1 = x0 + 1 val x2 = x0 * 2 -val x10 = px10 // static data: -val x11 = x10.apply(List(x4, x1, x2))// compile dynamic: fv = List(Sym(4), Sym(1), Sym(2)) -val x12 = x11.apply(()) -x12 +val x11 = px11 // static data: +val x12 = x11.apply(List(x4, x1, x2))// compile dynamic: fv = List(Sym(4), Sym(1), Sym(2)) +val x13 = x12.apply(()) +x13 } -x14 +x15 } } /***************************************** End of Generated Code *******************************************/ -compilation: ok 28 call with arg 9 /***************************************** Emitting Generated Code *******************************************/ -class staged$1(px1:Int,px2:Int) extends ((Unit)=>(Int)) { +class staged5(px1:Int,px2:Int) extends ((Unit)=>(Int)) { def apply(x5:Unit): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -51,7 +51,6 @@ x7 End of Generated Code *******************************************/ -compilation: ok 140 call with arg 9 (re) compiling @@ -59,7 +58,7 @@ read value RCell(stable) sym Sym(11) /***************************************** Emitting Generated Code *******************************************/ -class staged$2(px11:scala.lms.epfl.test13.RCell[Int],px13:Int,px17:scala.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px19:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { +class staged6(px11:scala.virtualization.lms.epfl.test13.RCell[Int],px13:Int,px17:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px19:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { def apply(x8:Int): Int = { val x11 = px11 // static data: RCell(stable) val x12 = x11.value @@ -73,7 +72,7 @@ val x16 = 2 * x15 x16 } else { val x17 = px17 // static data: RCell(code) -val x18 = x17.set(null) +x17.set(null) val x9 = x8 + 1 val x10 = x8 * 2 val x19 = px19 // static data: @@ -88,5 +87,4 @@ x23 End of Generated Code *******************************************/ -compilation: ok 56 diff --git a/test-out/epfl/test13-unstage1.check b/test-out/epfl/test13-unstage1.check index d6a4a1e0..05d189c1 100644 --- a/test-out/epfl/test13-unstage1.check +++ b/test-out/epfl/test13-unstage1.check @@ -1,7 +1,7 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged$0(px4:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { +class staged7(px4:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { def apply(x0:Int): Int = { val x1 = x0 + 1 val x2 = x0 * 2 @@ -16,11 +16,10 @@ x6 End of Generated Code *******************************************/ -compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged$1(px1:Int,px2:Int) extends ((Unit)=>(Int)) { +class staged8(px1:Int,px2:Int) extends ((Unit)=>(Int)) { def apply(x4:Unit): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -33,12 +32,11 @@ x6 End of Generated Code *******************************************/ -compilation: ok 784 /***************************************** Emitting Generated Code *******************************************/ -class staged$2(px1:Int,px2:Int) extends ((Unit)=>(Int)) { +class staged9(px1:Int,px2:Int) extends ((Unit)=>(Int)) { def apply(x4:Unit): Int = { val x1 = px1 // static data: 4 val x2 = px2 // static data: 6 @@ -51,12 +49,11 @@ x6 End of Generated Code *******************************************/ -compilation: ok 100 /***************************************** Emitting Generated Code *******************************************/ -class staged$3(px1:Int,px2:Int) extends ((Unit)=>(Int)) { +class staged10(px1:Int,px2:Int) extends ((Unit)=>(Int)) { def apply(x4:Unit): Int = { val x1 = px1 // static data: 2 val x2 = px2 // static data: 2 @@ -69,5 +66,4 @@ x6 End of Generated Code *******************************************/ -compilation: ok 16 diff --git a/test-out/epfl/test14-cgen1.check b/test-out/epfl/test14-cgen1.check index 3e63396e..183c44d8 100644 --- a/test-out/epfl/test14-cgen1.check +++ b/test-out/epfl/test14-cgen1.check @@ -1,21 +1,20 @@ /* FILE: main.c */ -int32_t main(int32_t); +int main(int); /***************************************** Emitting C Generated Code *******************************************/ #include #include -#include #include -int32_t main(int32_t x0) { -int32_t x1 = 0; +int main(int x0) { +int x1 = 0; for (;;) { -int32_t x2 = x1; +int x2 = x1; bool x3 = x2 < 10; if (!x3) break; -int32_t x5 = x1; -printf(string("Hello, world! %d\n").c_str(),x5); -int32_t x7 = x5 + 1; +int x5 = x1; +printf("Hello, world! %d\n",x5); // x6 +int x7 = x5 + 1; x1 = x7; } return 0; diff --git a/test-out/epfl/test14-cgen2.check b/test-out/epfl/test14-cgen2.check index 7ccbff9f..d4766343 100644 --- a/test-out/epfl/test14-cgen2.check +++ b/test-out/epfl/test14-cgen2.check @@ -1,30 +1,29 @@ /* FILE: main.c */ -int32_t main(int32_t); +int main(int); /***************************************** Emitting C Generated Code *******************************************/ #include #include -#include #include -int32_t main(int32_t x0) { -function x1 = [&](int32_t x2,int32_t x3) { -int32_t x4 = x2; +int main(int x0) { +int x1(int x2,int x3) { +int x4 = x2; bool x6 = x4 == 0; -int32_t x12; +int x12; if (x6) { x12 = 1; } else { -int32_t x5 = x3; -int32_t x7 = x4 - 1; -int32_t x9 = x1(x7,x5); -int32_t x10 = x4 * x9; +int x5 = x3; +int x7 = x4 - 1; +int x9 = x1(x7,x5); +int x10 = x4 * x9; x12 = x10; } return x12; -}; -int32_t x15 = x1(4,0); -printf(string("Hello, world! %d\n").c_str(),x15); +} +int x15 = x1(4,0); +printf("Hello, world! %d\n",x15); // x16 return 0; } /***************************************** diff --git a/test-out/epfl/test14-cgen3.check b/test-out/epfl/test14-cgen3.check index 5453b5c0..7ada95dc 100644 --- a/test-out/epfl/test14-cgen3.check +++ b/test-out/epfl/test14-cgen3.check @@ -1,54 +1,51 @@ /* FILE: test2.c */ -int32_t test2(int32_t); -int32_t test1(int32_t); -int32_t main(int32_t); +int test2(int); +int test1(int); +int main(int); /***************************************** Emitting C Generated Code *******************************************/ #include #include -#include #include -int32_t test2(int32_t x0) { -printf(string("Hello, world: test2\n").c_str()); +int test2(int x0) { +printf("Hello, world: test2\n"); // x1 return x0; } /***************************************** End of C Generated Code *******************************************/ /* FILE: test1.c */ -int32_t test2(int32_t); -int32_t test1(int32_t); -int32_t main(int32_t); +int test2(int); +int test1(int); +int main(int); /***************************************** Emitting C Generated Code *******************************************/ #include #include -#include #include -int32_t test1(int32_t x3) { -printf(string("Hello, world: test1\n").c_str()); -int32_t x5 = test2(x3); +int test1(int x3) { +printf("Hello, world: test1\n"); // x4 +int x5 = test2(x3); return x5; } /***************************************** End of C Generated Code *******************************************/ /* FILE: main.c */ -int32_t test2(int32_t); -int32_t test1(int32_t); -int32_t main(int32_t); +int test2(int); +int test1(int); +int main(int); /***************************************** Emitting C Generated Code *******************************************/ #include #include -#include #include -int32_t main(int32_t x7) { -printf(string("Hello, world: main\n").c_str()); -int32_t x9 = test1(x7); +int main(int x7) { +printf("Hello, world: main\n"); // x8 +int x9 = test1(x7); return x9; } /***************************************** diff --git a/test-out/epfl/test14-dataop1.check b/test-out/epfl/test14-dataop1.check index 16e7ea54..678c8c26 100644 --- a/test-out/epfl/test14-dataop1.check +++ b/test-out/epfl/test14-dataop1.check @@ -1,30 +1,29 @@ /* FILE: main.c */ -int32_t main(int32_t); +int main(int); /***************************************** Emitting C Generated Code *******************************************/ #include #include -#include #include -int32_t main(int32_t x0) { -int32_t x5 = 0; -int* *x1 = mmap('table_field1.dat') // XX TODO ; -int32_t x4 = x1->length; -int* *x2 = mmap('table_field2.dat') // XX TODO ; +int main(int x0) { +int x5 = 0; +int* x1 = mmap('table_field1.dat') // XX TODO ; +int x4 = x1.length; +int* x2 = mmap('table_field2.dat') // XX TODO ; for (;;) { -int32_t x6 = x5; +int x6 = x5; bool x7 = x6 < x4; if (x7) { -x5 += 1; +x5 = x5 + 1; } else { } if (!x7) break; -int32_t x12 = x5; -int32_t x14 = x2[x12]; -int32_t x13 = x1[x12]; -int32_t x16 = 2 * x13; -printf(string("foo: %d, bar: %d\n").c_str(),x14,x16); +int x12 = x5; +int x14 = x2[x12]; +int x13 = x1[x12]; +int x16 = 2 * x13; +printf("foo: %d, bar: %d\n",x14,x16); // x17 } return 0; } diff --git a/test-out/epfl/test14-dataop2.check b/test-out/epfl/test14-dataop2.check index 8286baba..f8d0107e 100644 --- a/test-out/epfl/test14-dataop2.check +++ b/test-out/epfl/test14-dataop2.check @@ -1,54 +1,60 @@ /* FILE: main.c */ -int32_t main(int32_t); +int main(int); /***************************************** Emitting C Generated Code *******************************************/ #include #include -#include #include -int32_t main(int32_t x0) { -int32_t x3 = 0; -int* *x1 = mmap('table.dat') // XX TODO ; -int32_t x2 = x1->length; +int main(int x0) { +int x3 = 0; +int* x1 = mmap('table.dat') // XX TODO ; +int x2 = x1.length; for (;;) { -int32_t x4 = x3; +int x4 = x3; bool x5 = x4 < x2; if (x5) { -x3 += 3; +x3 = x3 + 3; } else { } bool x9 = x5; +int x10 = x3; +bool x11 = x10 < x2; +if (x11) { +x3 = x3 + 3; +} else { +} for (;;) { -bool x10 = x9; -bool x20; -if (x10) { -int32_t x11 = x3; -int32_t x13 = x11 + 1; -int32_t x14 = x1[x13]; -bool x17 = x14 > 0; -bool x18 = !x17; -x20 = x18; +bool x15 = x9; +bool x26; +if (x15) { +int x16 = x3; +int x19 = x16 + 1; +int x20 = x1[x19]; +bool x23 = x20 > 0; +bool x24 = !x23; +x26 = x24; } else { -x20 = false; +x26 = false; } -if (!x20) break; -int32_t x22 = x3; -bool x23 = x22 < x2; -if (x23) { -x3 += 3; +if (!x26) break; +int x28 = x3; +bool x29 = x28 < x2; +if (x29) { +x3 = x3 + 3; } else { } -x9 = x23; +x9 = x29; } -bool x30 = x9; -if (!x30) break; -int32_t x32 = x3; -int32_t x34 = x32 + 1; -int32_t x35 = x1[x34]; -int32_t x33 = x1[x32]; -int32_t x38 = 2 * x33; -printf(string("foo: %d, bar: %d\n").c_str(),x35,x38); +bool x36 = x9; +if (!x36) break; +int x38 = x3; +int x41 = x38 + 1; +int x42 = x1[x41]; +int x39 = x38 + 0; +int x40 = x1[x39]; +int x45 = 2 * x40; +printf("foo: %d, bar: %d\n",x42,x45); // x46 } return 0; } diff --git a/test-out/epfl/test14-dataop3.check b/test-out/epfl/test14-dataop3.check deleted file mode 100644 index b7c8eb79..00000000 --- a/test-out/epfl/test14-dataop3.check +++ /dev/null @@ -1,220 +0,0 @@ -/* FILE: main.c */ -int32_t main(int32_t); -/***************************************** - Emitting C Generated Code -*******************************************/ -#include -#include -#include -#include -int32_t main(int32_t x0) { -int32_t x7 = 0; -int32_t x8 = 0; -int32_t x9 = 0; -bool x10 = false; -bool x11 = false; -int* *x1 = mmap('A.dat') // XX TODO ; -int32_t x2 = x1->length; -bool x12 = 0 < x2; -if (x12) { -x7 += 2; -} else { -} -x11 = x12; -int* *x3 = mmap('B.dat') // XX TODO ; -int32_t x4 = x3->length; -bool x17 = 0 < x4; -if (x17) { -x8 += 2; -} else { -} -x10 = x17; -int* *x5 = mmap('C.dat') // XX TODO ; -int32_t x6 = x5->length; -for (;;) { -bool x22 = true; -for (;;) { -bool x23 = x11; -bool x26; -if (x23) { -bool x24 = x22; -x26 = x24; -} else { -x26 = false; -} -if (!x26) break; -bool x28 = true; -for (;;) { -bool x29 = x10; -bool x32; -if (x29) { -bool x30 = x28; -x32 = x30; -} else { -x32 = false; -} -if (!x32) break; -int32_t x34 = x9; -bool x35 = x34 < x6; -if (x35) { -x9 += 2; -} else { -} -bool x39 = x35; -for (;;) { -bool x40 = x39; -bool x51; -if (x40) { -int32_t x41 = x8; -int32_t x45 = x9; -int32_t x43 = x41 + 1; -int32_t x44 = x3[x43]; -int32_t x46 = x5[x45]; -bool x49 = x44 != x46; -x51 = x49; -} else { -x51 = false; -} -if (!x51) break; -int32_t x53 = x9; -bool x54 = x53 < x6; -if (x54) { -x9 += 2; -} else { -} -x39 = x54; -} -bool x61 = x39; -bool x62 = !x61; -if (x62) { -int32_t x63 = x8; -bool x64 = x63 < x4; -if (x64) { -x8 += 2; -} else { -} -x10 = x64; -x9 = 0; -} else { -x28 = false; -} -} -bool x76 = x10; -bool x77 = x76; -for (;;) { -bool x78 = x77; -bool x93; -if (x78) { -int32_t x79 = x7; -int32_t x83 = x8; -int32_t x87 = x9; -int32_t x81 = x79 + 1; -int32_t x82 = x1[x81]; -int32_t x84 = x3[x83]; -bool x91 = x82 != x84; -x93 = x91; -} else { -x93 = false; -} -if (!x93) break; -bool x95 = true; -for (;;) { -bool x96 = x10; -bool x99; -if (x96) { -bool x97 = x95; -x99 = x97; -} else { -x99 = false; -} -if (!x99) break; -int32_t x101 = x9; -bool x102 = x101 < x6; -if (x102) { -x9 += 2; -} else { -} -bool x106 = x102; -for (;;) { -bool x107 = x106; -bool x118; -if (x107) { -int32_t x108 = x8; -int32_t x112 = x9; -int32_t x110 = x108 + 1; -int32_t x111 = x3[x110]; -int32_t x113 = x5[x112]; -bool x116 = x111 != x113; -x118 = x116; -} else { -x118 = false; -} -if (!x118) break; -int32_t x120 = x9; -bool x121 = x120 < x6; -if (x121) { -x9 += 2; -} else { -} -x106 = x121; -} -bool x128 = x106; -bool x129 = !x128; -if (x129) { -int32_t x130 = x8; -bool x131 = x130 < x4; -if (x131) { -x8 += 2; -} else { -} -x10 = x131; -x9 = 0; -} else { -x95 = false; -} -} -bool x143 = x10; -x77 = x143; -} -bool x147 = x77; -bool x148 = !x147; -if (x148) { -int32_t x149 = x7; -bool x150 = x149 < x2; -if (x150) { -x7 += 2; -} else { -} -x11 = x150; -x8 = 0; -if (x17) { -x8 += 2; -} else { -} -x10 = x17; -x9 = 0; -} else { -x22 = false; -} -} -bool x167 = x11; -if (!x167) break; -int32_t x169 = x7; -int32_t x173 = x8; -int32_t x177 = x9; -int32_t x170 = x1[x169]; -int32_t x171 = x169 + 1; -int32_t x172 = x1[x171]; -int32_t x174 = x3[x173]; -int32_t x175 = x173 + 1; -int32_t x176 = x3[x175]; -int32_t x178 = x5[x177]; -int32_t x179 = x177 + 1; -int32_t x180 = x5[x179]; -printf(string("a1: %d, a2: %d, b1: %d, b2: %d, c1: %d, c2: %d\n").c_str(),x170,x172,x174,x176,x178,x180); -} -return 0; -} -/***************************************** - End of C Generated Code -*******************************************/ diff --git a/test-out/epfl/test14-queries2.check b/test-out/epfl/test14-queries2.check index 3f13fe95..6375b403 100644 --- a/test-out/epfl/test14-queries2.check +++ b/test-out/epfl/test14-queries2.check @@ -1,12 +1,10 @@ -nVars=1000 -nVars=2000 /***************************************** Emitting Generated Code *******************************************/ -import scala.lms.epfl.test14.Schema -class staged$0 extends ((Unit)=>(Unit)) { +import scala.virtualization.lms.epfl.test14.Schema +class staged0 extends ((Unit)=>(Unit)) { def apply(x0:Unit): Unit = { -val x2550 = println("rangeFromNames(\"Edna\",\"Bert\"):") +println("rangeFromNames(\"Edna\",\"Bert\"):") val x617 = Schema.db.people.flatMap { x111 => val x616 = Schema.db.people.flatMap { x435 => val x615 = Schema.db.people.flatMap { x598 => @@ -19,13 +17,25 @@ val x602 = x598.age val x603 = x116 <= x602 val x441 = x435.age val x604 = x602 < x441 -val x605 = x603 && x604 -val x611 = x439 && x605 -val x613 = x113 && x611 +val x605 = if (x603 == true) { + +x604 +} else false + +val x611 = if (x439 == true) { + +x605 +} else false + +val x613 = if (x113 == true) { + +x611 +} else false + val x614 = if (x613) { -val x607 = x598.name -val x608 = new Schema.Record { val name = x607 } -val x609 = List(x608) +val x608 = x598.name +val x607 = new Schema.Record { val name = x608 } +val x609 = List(x607) x609 } else { val x19 = List() @@ -37,14 +47,12 @@ x615 } x616 } -val x2551 = println(x617) -x2551 +println(x617) } } /***************************************** End of Generated Code *******************************************/ -compilation: ok rangeFromNames("Edna","Bert"): List({name:Cora}, {name:Drew}, {name:Edna}) diff --git a/test-out/epfl/test14-queries3.check b/test-out/epfl/test14-queries3.check index 1526c97a..19d0c2e2 100644 --- a/test-out/epfl/test14-queries3.check +++ b/test-out/epfl/test14-queries3.check @@ -1,12 +1,10 @@ -nVars=1000 -nVars=2000 /***************************************** Emitting Generated Code *******************************************/ -import scala.lms.epfl.test14.Schema -class staged$0 extends ((Unit)=>(Unit)) { +import scala.virtualization.lms.epfl.test14.Schema +class staged1 extends ((Unit)=>(Unit)) { def apply(x0:Unit): Unit = { -val x2550 = println("expertise(\"abstract\"):") +println("expertise(\"abstract\"):") val x800 = Schema.org.departments.flatMap { x732 => val x792 = Schema.org.employees.flatMap { x763 => val x734 = x732.dpt @@ -18,7 +16,11 @@ val x777 = x776.emp val x778 = x767 == x777 val x779 = x776.tsk val x780 = x779 == "abstract" -val x781 = x778 && x780 +val x781 = if (x778 == true) { + +x780 +} else false + val x784 = if (x781) { val x661 = new Schema.Record { val ignore = () } val x688 = List(x661) @@ -30,7 +32,11 @@ x19 x784 } val x786 = x785.isEmpty -val x788 = x765 && x786 +val x788 = if (x765 == true) { + +x786 +} else false + val x791 = if (x788) { val x661 = new Schema.Record { val ignore = () } val x688 = List(x661) @@ -53,16 +59,12 @@ x19 } x799 } -val x2551 = println(x800) -x2551 +println(x800) } } /***************************************** End of Generated Code *******************************************/ -warning: there were 9 feature warnings; re-run with -feature for details -one warning found -compilation: ok expertise("abstract"): List({dpt:Quality}, {dpt:Research}) diff --git a/test-out/epfl/test14-queries4.check b/test-out/epfl/test14-queries4.check index fa5b5c59..ee531905 100644 --- a/test-out/epfl/test14-queries4.check +++ b/test-out/epfl/test14-queries4.check @@ -1,24 +1,26 @@ -nVars=1000 -nVars=2000 /***************************************** Emitting Generated Code *******************************************/ -import scala.lms.epfl.test14.Schema -class staged$0 extends ((Unit)=>(Unit)) { +import scala.virtualization.lms.epfl.test14.Schema +class staged2 extends ((Unit)=>(Unit)) { def apply(x0:Unit): Unit = { -val x2550 = println("expertise2(\"abstract\"):") +println("expertise2(\"abstract\"):") val x1147 = Schema.org.departments.flatMap { x991 => val x1140 = Schema.org.employees.flatMap { x1083 => val x993 = x991.dpt val x1084 = x1083.dpt val x1085 = x993 == x1084 val x1133 = Schema.org.tasks.flatMap { x1120 => -val x1088 = x1083.emp +val x1089 = x1083.emp val x1121 = x1120.emp -val x1122 = x1088 == x1121 +val x1122 = x1089 == x1121 val x1125 = x1120.tsk val x1128 = x1125 == "abstract" -val x1130 = x1122 && x1128 +val x1130 = if (x1122 == true) { + +x1128 +} else false + val x1132 = if (x1130) { val x661 = new Schema.Record { val ignore = () } val x688 = List(x661) @@ -30,7 +32,11 @@ x19 x1132 } val x1134 = x1133.isEmpty -val x1137 = x1085 && x1134 +val x1137 = if (x1085 == true) { + +x1134 +} else false + val x1139 = if (x1137) { val x661 = new Schema.Record { val ignore = () } val x688 = List(x661) @@ -53,16 +59,12 @@ x19 } x1146 } -val x2551 = println(x1147) -x2551 +println(x1147) } } /***************************************** End of Generated Code *******************************************/ -warning: there were 9 feature warnings; re-run with -feature for details -one warning found -compilation: ok expertise2("abstract"): List({dpt:Quality}, {dpt:Research}) diff --git a/test-out/epfl/test15-generator-array.check b/test-out/epfl/test15-generator-array.check new file mode 100644 index 00000000..de7ace41 --- /dev/null +++ b/test-out/epfl/test15-generator-array.check @@ -0,0 +1,103 @@ +/***************************************** + Emitting Generated Code +*******************************************/ +class testMul extends ((Array[scala.Tuple2[Int, Int]], Int)=>(Unit)) { +def apply(x0:Array[scala.Tuple2[Int, Int]], x1:Int): Unit = { +val x2 = x0.length +val x3 = x2 + 1 +val x4 = x3 * x3 +val x5 = new Array[Recordintintint](x4) +var x7 : Int = 1 +while (x7 < x3) { +val x8 = x3 - x7 +var x10 : Int = 0 +while (x10 < x8) { +var x15 = 0 +var x16 = 0 +var x17 = 10000 +val x11 = x10 + x7 +val x12 = x10 + 1 +val x19 = x12 == x11 +if (x19) { +val x24 = x15 +val x25 = x16 +val x26 = x17 +val x28 = 0 < x26 +if (x28) { +val x20 = x0(x10) +val x21 = x20._1 +x15 = x21 +val x22 = x20._2 +x16 = x22 +x17 = 0 +() +} else { +() +} + +} else { +() +} +val x13 = x12 < x11 +val x38 = x10 * x3 +if (x13) { +var x37 : Int = x12 +while (x37 < x11) { +val x39 = x38 + x37 +val x40 = x5(x39) +val x41 = x37 * x3 +val x42 = x41 + x11 +val x43 = x5(x42) +val x44 = (x40,x43) +val x45 = x44._1 +val x46 = x44._2 +val x47 = x45.rows +val x48 = x46.cols +val x49 = x45.mults +val x50 = x46.mults +val x52 = x45.cols +val x57 = x15 +val x58 = x16 +val x59 = x17 +val x51 = x49 + x50 +val x53 = x47 * x52 +val x54 = x53 * x48 +val x55 = x51 + x54 +val x61 = x55 < x59 +if (x61) { +x15 = x47 +x16 = x48 +x17 = x55 +() +} else { +() +} + +x37 = x37 + 1 +} + +} else { +() +} +val x72 = x15 +val x73 = x16 +val x74 = x17 +val x71 = x38 + x11 +val x75 = Recordintintint(rows = x72, cols = x73, mults = x74) +x5(x71) = x75 + +x10 = x10 + 1 +} + +x7 = x7 + 1 +} +val x81 = 0 * x3 +val x82 = x81 + x2 +val x83 = x5(x82) +println(x83) +} +} +/***************************************** + End of Generated Code +*******************************************/ +case class Recordintintint(rows: Int, cols: Int, mults: Int) diff --git a/test-out/epfl/test15-generator-simple.check b/test-out/epfl/test15-generator-simple.check new file mode 100644 index 00000000..b755a7ee --- /dev/null +++ b/test-out/epfl/test15-generator-simple.check @@ -0,0 +1,374 @@ +/***************************************** + Emitting Generated Code +*******************************************/ +class test1 extends ((Int, Int)=>(Int)) { +def apply(x0:Int, x1:Int): Int = { +var x3 = 0 +val x2 = x0 < x1 +if (x2) { +var x5 : Int = x0 +while (x5 < x1) { +x3 = x5 + +x5 = x5 + 1 +} + +} else { +() +} +val x11 = x3 +x11 +} +} +/***************************************** + End of Generated Code +*******************************************/ +/***************************************** + Emitting Generated Code +*******************************************/ +class test2 extends ((Int, Int)=>(Int)) { +def apply(x13:Int, x14:Int): Int = { +var x16 = 0 +val x15 = x13 < x14 +if (x15) { +var x18 : Int = x13 +while (x18 < x14) { +val x19 = x18 * 2 +x16 = x19 + +x18 = x18 + 1 +} + +} else { +() +} +val x25 = x16 +x25 +} +} +/***************************************** + End of Generated Code +*******************************************/ +20 +/***************************************** + Emitting Generated Code +*******************************************/ +class test3 extends ((Int, Int)=>(Int)) { +def apply(x41:Int, x42:Int): Int = { +var x44 = 0 +val x43 = x41 < x42 +if (x43) { +var x46 : Int = x41 +while (x46 < x42) { +val x47 = x44 +val x48 = x47 + x46 +x44 = x48 + +x46 = x46 + 1 +} + +} else { +() +} +val x54 = x44 +x54 +} +} +/***************************************** + End of Generated Code +*******************************************/ +55 +/***************************************** + Emitting Generated Code +*******************************************/ +class test4 extends ((Int, Int)=>(Int)) { +def apply(x71:Int, x72:Int): Int = { +var x74 = 0 +val x73 = x71 < x72 +if (x73) { +var x76 : Int = x71 +while (x76 < x72) { +val x77 = x76 % 2 +val x78 = x77 != 0 +if (x78) { +val x79 = x74 +val x80 = x79 + x76 +x74 = x80 +() +} else { +() +} + +x76 = x76 + 1 +} + +} else { +() +} +val x88 = x74 +x88 +} +} +/***************************************** + End of Generated Code +*******************************************/ +25 +/***************************************** + Emitting Generated Code +*******************************************/ +class test5 extends ((Int, Int)=>(Int)) { +def apply(x109:Int, x110:Int): Int = { +var x112 = 0 +val x111 = x109 < x110 +if (x111) { +var x114 : Int = x109 +while (x114 < x110) { +val x115 = x112 +val x116 = x115 + x114 +x112 = x116 + +x114 = x114 + 1 +} + +} else { +() +} +if (x111) { +var x122 : Int = x109 +while (x122 < x110) { +val x123 = x122 % 2 +val x124 = x123 != 0 +if (x124) { +val x125 = x112 +val x126 = x125 + x122 +x112 = x126 +() +} else { +() +} + +x122 = x122 + 1 +} + +} else { +() +} +val x134 = x112 +x134 +} +} +/***************************************** + End of Generated Code +*******************************************/ +80 +/***************************************** + Emitting Generated Code +*******************************************/ +class test6 extends ((Int, Int)=>(Int)) { +def apply(x163:Int, x164:Int): Int = { +var x166 = 0 +val x165 = x163 < x164 +if (x165) { +var x168 : Int = x163 +while (x168 < x164) { +val x169 = x163 < x168 +if (x169) { +var x171 : Int = x163 +while (x171 < x168) { +val x172 = x166 +val x173 = x172 + x171 +x166 = x173 + +x171 = x171 + 1 +} + +} else { +() +} + +x168 = x168 + 1 +} + +} else { +() +} +val x183 = x166 +x183 +} +} +/***************************************** + End of Generated Code +*******************************************/ +20 +/***************************************** + Emitting Generated Code +*******************************************/ +class test8 extends ((Int)=>(Int)) { +def apply(x207:Int): Int = { +var x208 = 0 +val x209 = x208 +val x210 = x209 + 1 +x208 = x210 +val x212 = x208 +val x213 = x212 + 2 +x208 = x213 +val x215 = x208 +val x216 = x215 + 3 +x208 = x216 +val x218 = x208 +x218 +} +} +/***************************************** + End of Generated Code +*******************************************/ +6 +/***************************************** + Emitting Generated Code +*******************************************/ +class test6b extends ((Int, Int)=>(Int)) { +def apply(x233:Int, x234:Int): Int = { +var x236 = 0 +val x235 = x233 < x234 +val x252 = if (x235) { +var x238 : Int = x233 +while (x238 < x234) { +val x239 = x233 < x238 +val x248 = if (x239) { +var x241 : Int = x233 +while (x241 < x238) { +val x242 = x236 +val x243 = x242 + x241 +x236 = x243 + +x241 = x241 + 1 +} +true +} else { +false +} + +x238 = x238 + 1 +} +true +} else { +false +} +val x253 = x236 +x253 +} +} +/***************************************** + End of Generated Code +*******************************************/ +20 +/***************************************** + Emitting Generated Code +*******************************************/ +class test9 extends ((Int, Int)=>(Int)) { +def apply(x277:Int, x278:Int): Int = { +var x280 = 0 +val x279 = x277 < x278 +if (x279) { +var x282 : Int = x277 +while (x282 < x278) { +val x286 = x280 +val x283 = x282 * 2 +val x284 = x283 + 1 +val x285 = x284 * 3 +val x287 = x286 + x285 +x280 = x287 + +x282 = x282 + 1 +} + +} else { +() +} +val x293 = x280 +x293 +} +} +/***************************************** + End of Generated Code +*******************************************/ +297 +/***************************************** + Emitting Generated Code +*******************************************/ +class test10 extends ((Int)=>(Int)) { +def apply(x313:Int): Int = { +var x315 = 0 +val x314 = 1 < x313 +if (x314) { +var x317 : Int = 1 +while (x317 < x313) { +val x318 = 1 < x317 +if (x318) { +var x320 : Int = 1 +while (x320 < x317) { +val x322 = x315 +val x321 = x317 * x320 +val x323 = x322 + x321 +x315 = x323 + +x320 = x320 + 1 +} + +} else { +() +} + +x317 = x317 + 1 +} + +} else { +() +} +val x333 = x315 +x333 +} +} +/***************************************** + End of Generated Code +*******************************************/ +870 +/***************************************** + Emitting Generated Code +*******************************************/ +class test11 extends ((Int, Int)=>(Int)) { +def apply(x357:Int, x358:Int): Int = { +var x360 = 0 +val x359 = x357 < x358 +if (x359) { +var x362 : Int = x357 +while (x362 < x358) { +val x363 = x357 < x362 +if (x363) { +var x366 : Int = x357 +while (x366 < x362) { +val x367 = x360 +val x368 = x367 + x366 +x360 = x368 + +x366 = x366 + 1 +} + +} else { +() +} + +x362 = x362 + 1 +} + +} else { +() +} +val x378 = x360 +x378 +} +} +/***************************************** + End of Generated Code +*******************************************/ +20 diff --git a/test-out/epfl/test15-tupled-generator-flatten.check b/test-out/epfl/test15-tupled-generator-flatten.check new file mode 100644 index 00000000..8b9b65e0 --- /dev/null +++ b/test-out/epfl/test15-tupled-generator-flatten.check @@ -0,0 +1,27 @@ +/***************************************** + Emitting Generated Code +*******************************************/ +class test1 extends ((Double, Long, Long, Double, Double, org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Long, Double], org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Double], org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Long], org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Long], org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Double])=>(scala.collection.immutable.List[scala.Tuple2[scala.Tuple2[Double, Long], Long]])) { +def apply(x0:Double, x1:Long, x2:Long, x3:Double, x4:Double, x5:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Long, Double], x6:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Double], x7:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Long], x8:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Long], x9:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Double]): scala.collection.immutable.List[scala.Tuple2[scala.Tuple2[Double, Long], Long]] = { +val x13 = x8 // mutable K3PersistentCollection +var x18 = (List()) +val x25 = -1L * x4 +(x13.slice(x2,(List(0)))).foreach{ +x19 => +val x23 = (x19._1)._2 +x18 = (((((x23,((if ((1000.0 < (x23 + x25))) { +1L +} else { +0L +}) + (if ((1000.0 < (x4 + (-1L * x23)))) { +1L +} else { +0L +})))),((x19._2) * 1L))) :: (x18)) +} +(x18) +} +} +/***************************************** + End of Generated Code +*******************************************/ diff --git a/test-out/epfl/test15-tupled-generator-huge.check b/test-out/epfl/test15-tupled-generator-huge.check new file mode 100644 index 00000000..2886eb3a --- /dev/null +++ b/test-out/epfl/test15-tupled-generator-huge.check @@ -0,0 +1,93 @@ +/***************************************** + Emitting Generated Code +*******************************************/ +class VWAPonInsertBIDS extends ((Double, Long, Long, Double, Double, org.dbtoaster.dbtoasterlib.K3Collection.SimpleVal[Double], org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double], org.dbtoaster.dbtoasterlib.K3Collection.SimpleVal[Double], org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double])=>(Unit)) { +def apply(x0:Double, x1:Long, x2:Long, x3:Double, x4:Double, x5:org.dbtoaster.dbtoasterlib.K3Collection.SimpleVal[Double], x6:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double], x7:org.dbtoaster.dbtoasterlib.K3Collection.SimpleVal[Double], x8:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double]): Unit = { +val x9 = x5 // mutable SimpleVal +val x10 = x6 // mutable K3PersistentCollection +val x11 = x7 // mutable SimpleVal +val x12 = x8 // mutable K3PersistentCollection +x10.updateValue(x4,((if ((x10.contains(x4))) { +(x10.lookup(x4,0)) +} else { +0.0 +}) + (x4 * x3))) +x11.update(((x11.get()) + x3)) +x12.updateValue(x4,((if ((x12.contains(x4))) { +(x12.lookup(x4,0)) +} else { +0.0 +}) + x3)) +var x33 = 0.0 +val x31 = (x11.get()) * 0.25 +x10.foreach{ +x35 => +var x42 = 0.0 +val x36 = x35._1 +x12.foreach{ +x43 => +x42 = ((x42) + ((x43._2) * (if ((x36 < (x43._1))) { +1.0 +} else { +0.0 +}))) +} +x33 = ((x33) + (((1L * (x35._2)) * 1L) * (if (((x42) < x31)) { +1.0 +} else { +0.0 +}))) +} +x9.update((0.0 + (x33))) +} +} +/***************************************** + End of Generated Code +*******************************************/ +/***************************************** + Emitting Generated Code +*******************************************/ +class VWAPonDeleteBIDS extends ((Double, Long, Long, Double, Double, org.dbtoaster.dbtoasterlib.K3Collection.SimpleVal[Double], org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double], org.dbtoaster.dbtoasterlib.K3Collection.SimpleVal[Double], org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double])=>(Unit)) { +def apply(x76:Double, x77:Long, x78:Long, x79:Double, x80:Double, x81:org.dbtoaster.dbtoasterlib.K3Collection.SimpleVal[Double], x82:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double], x83:org.dbtoaster.dbtoasterlib.K3Collection.SimpleVal[Double], x84:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double]): Unit = { +val x85 = x81 // mutable SimpleVal +val x86 = x82 // mutable K3PersistentCollection +val x87 = x83 // mutable SimpleVal +val x88 = x84 // mutable K3PersistentCollection +x86.updateValue(x80,((if ((x86.contains(x80))) { +(x86.lookup(x80,0)) +} else { +0.0 +}) + ((-1L * x80) * x79))) +val x98 = -1L * x79 +x87.update(((x87.get()) + x98)) +x88.updateValue(x80,((if ((x88.contains(x80))) { +(x88.lookup(x80,0)) +} else { +0.0 +}) + x98)) +var x111 = 0.0 +val x109 = (x87.get()) * 0.25 +x86.foreach{ +x113 => +var x120 = 0.0 +val x114 = x113._1 +x88.foreach{ +x121 => +x120 = ((x120) + ((x121._2) * (if ((x114 < (x121._1))) { +1.0 +} else { +0.0 +}))) +} +x111 = ((x111) + (((1L * (x113._2)) * 1L) * (if (((x120) < x109)) { +1.0 +} else { +0.0 +}))) +} +x85.update((0.0 + (x111))) +} +} +/***************************************** + End of Generated Code +*******************************************/ diff --git a/test-out/epfl/test15-tupled-generator-simple.check b/test-out/epfl/test15-tupled-generator-simple.check new file mode 100644 index 00000000..f51e9d9d --- /dev/null +++ b/test-out/epfl/test15-tupled-generator-simple.check @@ -0,0 +1,36 @@ +/***************************************** + Emitting Generated Code +*******************************************/ +class test1 extends ((org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double], org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Double])=>(Unit)) { +def apply(x0:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[Double, Double], x1:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Double]): Unit = { +var x2 = 0.0 +x0.foreach{ +x3 => +x2 = ((x2) + ((x3._2) * (if ((12.2 < (x3._1))) { +1.0 +} else { +0.0 +}))) +} +} +} +/***************************************** + End of Generated Code +*******************************************/ +/***************************************** + Emitting Generated Code +*******************************************/ +class test2 extends ((Long, org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Double])=>(Double)) { +def apply(x17:Long, x18:org.dbtoaster.dbtoasterlib.K3Collection.K3PersistentCollection[scala.Tuple2[Long, Double], Double]): Double = { +var x22 = 0.0 +val x30 = 200L * 75.32 +(x18.slice(x17,(List(0)))).foreach{ +x23 => +x22 = ((x22) + x30) +} +(x22) +} +} +/***************************************** + End of Generated Code +*******************************************/ diff --git a/test-out/epfl/test16-DBMSOpt1.check b/test-out/epfl/test16-DBMSOpt1.check new file mode 100644 index 00000000..e0554ad5 --- /dev/null +++ b/test-out/epfl/test16-DBMSOpt1.check @@ -0,0 +1,2 @@ +-1 +0 diff --git a/test-out/epfl/test16-DBMSOpt2.check b/test-out/epfl/test16-DBMSOpt2.check new file mode 100644 index 00000000..f7f62d72 --- /dev/null +++ b/test-out/epfl/test16-DBMSOpt2.check @@ -0,0 +1,69 @@ +/***************************************** + Emitting Generated Code +*******************************************/ +class lala extends (()=>(Array[Array[Int]])) { +def apply(): Array[Array[Int]] = { +val x0 = new Array[Array[Int]](3) +var x1 = x0 +val x2 = x1 +val x3 = new Array[Int](3) +x2(0) = x3 +val x5 = new Array[Int](3) +x2(1) = x5 +val x7 = new Array[Int](3) +x2(2) = x7 +val x9 = x2(0) +var x10 = x9 +val x11 = x10 +x11(0) = 2 +val x13 = x11.mkString(",") +println(x13) +val x15 = new Array[Int](7) +x10 = x15 +val x17 = x10 +x17(6) = 1 +val x19 = x17.mkString(",") +println(x19) +x2(0) = x17 +val x22 = x2(1) +var x23 = x22 +val x24 = x23 +x24(1) = 2 +val x26 = x24.mkString(",") +println(x26) +val x28 = new Array[Int](7) +x23 = x28 +val x30 = x23 +x30(5) = 1 +val x32 = x30.mkString(",") +println(x32) +x2(1) = x30 +val x35 = x2(2) +var x36 = x35 +val x37 = x36 +x37(2) = 2 +val x39 = x37.mkString(",") +println(x39) +val x41 = new Array[Int](7) +x36 = x41 +val x43 = x36 +x43(4) = 1 +val x45 = x43.mkString(",") +println(x45) +x2(2) = x43 +x2 +} +} +/***************************************** + End of Generated Code +*******************************************/ +2,0,0 +0,0,0,0,0,0,1 +0,2,0 +0,0,0,0,0,1,0 +0,0,2 +0,0,0,0,1,0,0 +3 +0,0,0,0,0,0,1 +0,0,0,0,0,1,0 +0,0,0,0,1,0,0 diff --git a/test-out/epfl/test2-fft3.check b/test-out/epfl/test2-fft3.check index b25a3270..35188b88 100644 --- a/test-out/epfl/test2-fft3.check +++ b/test-out/epfl/test2-fft3.check @@ -34,5 +34,4 @@ x27 /***************************************** End of Generated Code *******************************************/ -compilation: ok 6.0,0.0,-1.0,1.0,0.0,0.0,-1.0,-1.0 diff --git a/test-out/epfl/test2-power.check b/test-out/epfl/test2-power.check index e286c129..1304d6c4 100644 --- a/test-out/epfl/test2-power.check +++ b/test-out/epfl/test2-power.check @@ -58,5 +58,4 @@ x3 /***************************************** End of Generated Code *******************************************/ -compilation: ok 16.0 diff --git a/test-out/epfl/test2-sort1-dot.check b/test-out/epfl/test2-sort1-dot.check deleted file mode 100644 index 9feb3b6c..00000000 --- a/test-out/epfl/test2-sort1-dot.check +++ /dev/null @@ -1,303 +0,0 @@ -digraph G { -rankdir=LR -"Sym(8)" [ -label="Sym(8) \n Min(Sym(0),Sym(1))" -shape=box -] -"Sym(0)" -> "Sym(8)" -"Sym(1)" -> "Sym(8)" -"Sym(10)" [ -label="Sym(10) \n Min(Sym(2),Sym(3))" -shape=box -] -"Sym(2)" -> "Sym(10)" -"Sym(3)" -> "Sym(10)" -"Sym(12)" [ -label="Sym(12) \n Min(Sym(8),Sym(10))" -shape=box -] -"Sym(8)" -> "Sym(12)" -"Sym(10)" -> "Sym(12)" -"Sym(9)" [ -label="Sym(9) \n Max(Sym(0),Sym(1))" -shape=box -] -"Sym(0)" -> "Sym(9)" -"Sym(1)" -> "Sym(9)" -"Sym(11)" [ -label="Sym(11) \n Max(Sym(2),Sym(3))" -shape=box -] -"Sym(2)" -> "Sym(11)" -"Sym(3)" -> "Sym(11)" -"Sym(14)" [ -label="Sym(14) \n Min(Sym(9),Sym(11))" -shape=box -] -"Sym(9)" -> "Sym(14)" -"Sym(11)" -> "Sym(14)" -"Sym(16)" [ -label="Sym(16) \n Min(Sym(12),Sym(14))" -shape=box -] -"Sym(12)" -> "Sym(16)" -"Sym(14)" -> "Sym(16)" -"Sym(20)" [ -label="Sym(20) \n Min(Sym(4),Sym(5))" -shape=box -] -"Sym(4)" -> "Sym(20)" -"Sym(5)" -> "Sym(20)" -"Sym(22)" [ -label="Sym(22) \n Min(Sym(6),Sym(7))" -shape=box -] -"Sym(6)" -> "Sym(22)" -"Sym(7)" -> "Sym(22)" -"Sym(24)" [ -label="Sym(24) \n Min(Sym(20),Sym(22))" -shape=box -] -"Sym(20)" -> "Sym(24)" -"Sym(22)" -> "Sym(24)" -"Sym(21)" [ -label="Sym(21) \n Max(Sym(4),Sym(5))" -shape=box -] -"Sym(4)" -> "Sym(21)" -"Sym(5)" -> "Sym(21)" -"Sym(23)" [ -label="Sym(23) \n Max(Sym(6),Sym(7))" -shape=box -] -"Sym(6)" -> "Sym(23)" -"Sym(7)" -> "Sym(23)" -"Sym(26)" [ -label="Sym(26) \n Min(Sym(21),Sym(23))" -shape=box -] -"Sym(21)" -> "Sym(26)" -"Sym(23)" -> "Sym(26)" -"Sym(28)" [ -label="Sym(28) \n Min(Sym(24),Sym(26))" -shape=box -] -"Sym(24)" -> "Sym(28)" -"Sym(26)" -> "Sym(28)" -"Sym(32)" [ -label="Sym(32) \n Min(Sym(16),Sym(28))" -shape=box -] -"Sym(16)" -> "Sym(32)" -"Sym(28)" -> "Sym(32)" -"Sym(13)" [ -label="Sym(13) \n Max(Sym(8),Sym(10))" -shape=box -] -"Sym(8)" -> "Sym(13)" -"Sym(10)" -> "Sym(13)" -"Sym(15)" [ -label="Sym(15) \n Max(Sym(9),Sym(11))" -shape=box -] -"Sym(9)" -> "Sym(15)" -"Sym(11)" -> "Sym(15)" -"Sym(18)" [ -label="Sym(18) \n Min(Sym(13),Sym(15))" -shape=box -] -"Sym(13)" -> "Sym(18)" -"Sym(15)" -> "Sym(18)" -"Sym(25)" [ -label="Sym(25) \n Max(Sym(20),Sym(22))" -shape=box -] -"Sym(20)" -> "Sym(25)" -"Sym(22)" -> "Sym(25)" -"Sym(27)" [ -label="Sym(27) \n Max(Sym(21),Sym(23))" -shape=box -] -"Sym(21)" -> "Sym(27)" -"Sym(23)" -> "Sym(27)" -"Sym(30)" [ -label="Sym(30) \n Min(Sym(25),Sym(27))" -shape=box -] -"Sym(25)" -> "Sym(30)" -"Sym(27)" -> "Sym(30)" -"Sym(34)" [ -label="Sym(34) \n Min(Sym(18),Sym(30))" -shape=box -] -"Sym(18)" -> "Sym(34)" -"Sym(30)" -> "Sym(34)" -"Sym(36)" [ -label="Sym(36) \n Min(Sym(32),Sym(34))" -shape=box -] -"Sym(32)" -> "Sym(36)" -"Sym(34)" -> "Sym(36)" -"Sym(17)" [ -label="Sym(17) \n Max(Sym(12),Sym(14))" -shape=box -] -"Sym(12)" -> "Sym(17)" -"Sym(14)" -> "Sym(17)" -"Sym(29)" [ -label="Sym(29) \n Max(Sym(24),Sym(26))" -shape=box -] -"Sym(24)" -> "Sym(29)" -"Sym(26)" -> "Sym(29)" -"Sym(40)" [ -label="Sym(40) \n Min(Sym(17),Sym(29))" -shape=box -] -"Sym(17)" -> "Sym(40)" -"Sym(29)" -> "Sym(40)" -"Sym(19)" [ -label="Sym(19) \n Max(Sym(13),Sym(15))" -shape=box -] -"Sym(13)" -> "Sym(19)" -"Sym(15)" -> "Sym(19)" -"Sym(31)" [ -label="Sym(31) \n Max(Sym(25),Sym(27))" -shape=box -] -"Sym(25)" -> "Sym(31)" -"Sym(27)" -> "Sym(31)" -"Sym(42)" [ -label="Sym(42) \n Min(Sym(19),Sym(31))" -shape=box -] -"Sym(19)" -> "Sym(42)" -"Sym(31)" -> "Sym(42)" -"Sym(44)" [ -label="Sym(44) \n Min(Sym(40),Sym(42))" -shape=box -] -"Sym(40)" -> "Sym(44)" -"Sym(42)" -> "Sym(44)" -"Sym(48)" [ -label="Sym(48) \n Min(Sym(36),Sym(44))" -shape=box -] -"Sym(36)" -> "Sym(48)" -"Sym(44)" -> "Sym(48)" -"Sym(49)" [ -label="Sym(49) \n Max(Sym(36),Sym(44))" -shape=box -] -"Sym(36)" -> "Sym(49)" -"Sym(44)" -> "Sym(49)" -"Sym(37)" [ -label="Sym(37) \n Max(Sym(32),Sym(34))" -shape=box -] -"Sym(32)" -> "Sym(37)" -"Sym(34)" -> "Sym(37)" -"Sym(45)" [ -label="Sym(45) \n Max(Sym(40),Sym(42))" -shape=box -] -"Sym(40)" -> "Sym(45)" -"Sym(42)" -> "Sym(45)" -"Sym(50)" [ -label="Sym(50) \n Min(Sym(37),Sym(45))" -shape=box -] -"Sym(37)" -> "Sym(50)" -"Sym(45)" -> "Sym(50)" -"Sym(51)" [ -label="Sym(51) \n Max(Sym(37),Sym(45))" -shape=box -] -"Sym(37)" -> "Sym(51)" -"Sym(45)" -> "Sym(51)" -"Sym(33)" [ -label="Sym(33) \n Max(Sym(16),Sym(28))" -shape=box -] -"Sym(16)" -> "Sym(33)" -"Sym(28)" -> "Sym(33)" -"Sym(35)" [ -label="Sym(35) \n Max(Sym(18),Sym(30))" -shape=box -] -"Sym(18)" -> "Sym(35)" -"Sym(30)" -> "Sym(35)" -"Sym(38)" [ -label="Sym(38) \n Min(Sym(33),Sym(35))" -shape=box -] -"Sym(33)" -> "Sym(38)" -"Sym(35)" -> "Sym(38)" -"Sym(41)" [ -label="Sym(41) \n Max(Sym(17),Sym(29))" -shape=box -] -"Sym(17)" -> "Sym(41)" -"Sym(29)" -> "Sym(41)" -"Sym(43)" [ -label="Sym(43) \n Max(Sym(19),Sym(31))" -shape=box -] -"Sym(19)" -> "Sym(43)" -"Sym(31)" -> "Sym(43)" -"Sym(46)" [ -label="Sym(46) \n Min(Sym(41),Sym(43))" -shape=box -] -"Sym(41)" -> "Sym(46)" -"Sym(43)" -> "Sym(46)" -"Sym(52)" [ -label="Sym(52) \n Min(Sym(38),Sym(46))" -shape=box -] -"Sym(38)" -> "Sym(52)" -"Sym(46)" -> "Sym(52)" -"Sym(53)" [ -label="Sym(53) \n Max(Sym(38),Sym(46))" -shape=box -] -"Sym(38)" -> "Sym(53)" -"Sym(46)" -> "Sym(53)" -"Sym(39)" [ -label="Sym(39) \n Max(Sym(33),Sym(35))" -shape=box -] -"Sym(33)" -> "Sym(39)" -"Sym(35)" -> "Sym(39)" -"Sym(47)" [ -label="Sym(47) \n Max(Sym(41),Sym(43))" -shape=box -] -"Sym(41)" -> "Sym(47)" -"Sym(43)" -> "Sym(47)" -"Sym(54)" [ -label="Sym(54) \n Min(Sym(39),Sym(47))" -shape=box -] -"Sym(39)" -> "Sym(54)" -"Sym(47)" -> "Sym(54)" -"Sym(55)" [ -label="Sym(55) \n Max(Sym(39),Sym(47))" -shape=box -] -"Sym(39)" -> "Sym(55)" -"Sym(47)" -> "Sym(55)" -"Sym(56)" [ -label="Sym(56) \n Result(List(Sym(48), Sym(49), Sym(50), Sym(51), Sym(52), Sym(53), Sym(54), Sym(55)))" -shape=box -] -"Sym(48)" -> "Sym(56)" -"Sym(49)" -> "Sym(56)" -"Sym(50)" -> "Sym(56)" -"Sym(51)" -> "Sym(56)" -"Sym(52)" -> "Sym(56)" -"Sym(53)" -> "Sym(56)" -"Sym(54)" -> "Sym(56)" -"Sym(55)" -> "Sym(56)" -} diff --git a/test-out/epfl/test2-sort1.check b/test-out/epfl/test2-sort1.check deleted file mode 100644 index 0af4f15d..00000000 --- a/test-out/epfl/test2-sort1.check +++ /dev/null @@ -1,49 +0,0 @@ -TP(Sym(8),Min(Sym(0),Sym(1))) -TP(Sym(9),Max(Sym(0),Sym(1))) -TP(Sym(10),Min(Sym(2),Sym(3))) -TP(Sym(11),Max(Sym(2),Sym(3))) -TP(Sym(12),Min(Sym(8),Sym(10))) -TP(Sym(13),Max(Sym(8),Sym(10))) -TP(Sym(14),Min(Sym(9),Sym(11))) -TP(Sym(15),Max(Sym(9),Sym(11))) -TP(Sym(16),Min(Sym(12),Sym(14))) -TP(Sym(17),Max(Sym(12),Sym(14))) -TP(Sym(18),Min(Sym(13),Sym(15))) -TP(Sym(19),Max(Sym(13),Sym(15))) -TP(Sym(20),Min(Sym(4),Sym(5))) -TP(Sym(21),Max(Sym(4),Sym(5))) -TP(Sym(22),Min(Sym(6),Sym(7))) -TP(Sym(23),Max(Sym(6),Sym(7))) -TP(Sym(24),Min(Sym(20),Sym(22))) -TP(Sym(25),Max(Sym(20),Sym(22))) -TP(Sym(26),Min(Sym(21),Sym(23))) -TP(Sym(27),Max(Sym(21),Sym(23))) -TP(Sym(28),Min(Sym(24),Sym(26))) -TP(Sym(29),Max(Sym(24),Sym(26))) -TP(Sym(30),Min(Sym(25),Sym(27))) -TP(Sym(31),Max(Sym(25),Sym(27))) -TP(Sym(32),Min(Sym(16),Sym(28))) -TP(Sym(33),Max(Sym(16),Sym(28))) -TP(Sym(34),Min(Sym(18),Sym(30))) -TP(Sym(35),Max(Sym(18),Sym(30))) -TP(Sym(36),Min(Sym(32),Sym(34))) -TP(Sym(37),Max(Sym(32),Sym(34))) -TP(Sym(38),Min(Sym(33),Sym(35))) -TP(Sym(39),Max(Sym(33),Sym(35))) -TP(Sym(40),Min(Sym(17),Sym(29))) -TP(Sym(41),Max(Sym(17),Sym(29))) -TP(Sym(42),Min(Sym(19),Sym(31))) -TP(Sym(43),Max(Sym(19),Sym(31))) -TP(Sym(44),Min(Sym(40),Sym(42))) -TP(Sym(45),Max(Sym(40),Sym(42))) -TP(Sym(46),Min(Sym(41),Sym(43))) -TP(Sym(47),Max(Sym(41),Sym(43))) -TP(Sym(48),Min(Sym(36),Sym(44))) -TP(Sym(49),Max(Sym(36),Sym(44))) -TP(Sym(50),Min(Sym(37),Sym(45))) -TP(Sym(51),Max(Sym(37),Sym(45))) -TP(Sym(52),Min(Sym(38),Sym(46))) -TP(Sym(53),Max(Sym(38),Sym(46))) -TP(Sym(54),Min(Sym(39),Sym(47))) -TP(Sym(55),Max(Sym(39),Sym(47))) -List(Sym(48), Sym(49), Sym(50), Sym(51), Sym(52), Sym(53), Sym(54), Sym(55)) diff --git a/test-out/epfl/test3-match1-dot.check b/test-out/epfl/test3-match1-dot.check index 6f7647a5..6b9096ba 100644 --- a/test-out/epfl/test3-match1-dot.check +++ b/test-out/epfl/test3-match1-dot.check @@ -1,6 +1,6 @@ digraph G { "Sym(2)" [ -label="Sym(2) \n Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))" +label="Sym(2) \n Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))" shape=box color=red ] @@ -18,7 +18,7 @@ shape=box "Sym(2)" -> "Sym(4)" [color=red] "Sym(3)" -> "Sym(4)" [color=red] "Sym(6)" [ -label="Sym(6) \n Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))" +label="Sym(6) \n Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))" shape=box color=red ] diff --git a/test-out/epfl/test3-match1.check b/test-out/epfl/test3-match1.check index 3c189f90..41c00225 100644 --- a/test-out/epfl/test3-match1.check +++ b/test-out/epfl/test3-match1.check @@ -1,9 +1,9 @@ TP(Sym(1),Lambda()) -TP(Sym(2),Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))) +TP(Sym(2),Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))) TP(Sym(3),Test(Sym(2),7)) TP(Sym(4),Reify(Const(yes),List(Sym(2), Sym(3)))) TP(Sym(5),Lambda()) -TP(Sym(6),Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))) +TP(Sym(6),Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))) TP(Sym(7),Reify(Const(maybe),List(Sym(6)))) TP(Sym(8),Lambda()) TP(Sym(9),OrElse(List(Sym(4), Sym(7), Pure(Const(no))))) diff --git a/test-out/epfl/test3-match2-dot.check b/test-out/epfl/test3-match2-dot.check index 1f98dd52..b60aa5fe 100644 --- a/test-out/epfl/test3-match2-dot.check +++ b/test-out/epfl/test3-match2-dot.check @@ -1,6 +1,6 @@ digraph G { "Sym(2)" [ -label="Sym(2) \n Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))" +label="Sym(2) \n Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))" shape=box color=red ] diff --git a/test-out/epfl/test3-match2.check b/test-out/epfl/test3-match2.check index ae4c40b7..2870b929 100644 --- a/test-out/epfl/test3-match2.check +++ b/test-out/epfl/test3-match2.check @@ -1,5 +1,5 @@ TP(Sym(1),Lambda()) -TP(Sym(2),Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))) +TP(Sym(2),Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))) TP(Sym(3),Test(Sym(2),7)) TP(Sym(4),Reify(Const(yes),List(Sym(2), Sym(3)))) TP(Sym(5),Lambda()) diff --git a/test-out/epfl/test3-parse1-dot.check b/test-out/epfl/test3-parse1-dot.check index 3cf8efdb..f7faef93 100644 --- a/test-out/epfl/test3-parse1-dot.check +++ b/test-out/epfl/test3-parse1-dot.check @@ -22,7 +22,7 @@ shape=box ] "Sym(2)" -> "Sym(4)" "Sym(6)" [ -label="Sym(6) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(4))" +label="Sym(6) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(4))" shape=box ] "Sym(4)" -> "Sym(6)" @@ -39,7 +39,7 @@ shape=box ] "Sym(7)" -> "Sym(9)" "Sym(11)" [ -label="Sym(11) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(9))" +label="Sym(11) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(9))" shape=box color=red ] @@ -67,7 +67,7 @@ shape=box ] "Sym(13)" -> "Sym(15)" "Sym(17)" [ -label="Sym(17) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(15))" +label="Sym(17) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(15))" shape=box ] "Sym(15)" -> "Sym(17)" @@ -95,7 +95,7 @@ shape=box ] "Sym(21)" -> "Sym(23)" "Sym(25)" [ -label="Sym(25) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(23))" +label="Sym(25) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(23))" shape=box color=red ] @@ -123,7 +123,7 @@ shape=box ] "Sym(27)" -> "Sym(29)" "Sym(31)" [ -label="Sym(31) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(29))" +label="Sym(31) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(29))" shape=box ] "Sym(29)" -> "Sym(31)" @@ -151,7 +151,7 @@ shape=box ] "Sym(35)" -> "Sym(37)" "Sym(39)" [ -label="Sym(39) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(37))" +label="Sym(39) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(37))" shape=box color=red ] @@ -179,7 +179,7 @@ shape=box ] "Sym(41)" -> "Sym(43)" "Sym(45)" [ -label="Sym(45) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(43))" +label="Sym(45) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(43))" shape=box ] "Sym(43)" -> "Sym(45)" @@ -207,7 +207,7 @@ shape=box ] "Sym(49)" -> "Sym(51)" "Sym(53)" [ -label="Sym(53) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(51))" +label="Sym(53) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(51))" shape=box color=red ] @@ -235,7 +235,7 @@ shape=box ] "Sym(55)" -> "Sym(57)" "Sym(59)" [ -label="Sym(59) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(57))" +label="Sym(59) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(57))" shape=box ] "Sym(57)" -> "Sym(59)" @@ -263,7 +263,7 @@ shape=box ] "Sym(63)" -> "Sym(65)" "Sym(67)" [ -label="Sym(67) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(65))" +label="Sym(67) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(65))" shape=box color=red ] @@ -291,7 +291,7 @@ shape=box ] "Sym(69)" -> "Sym(71)" "Sym(73)" [ -label="Sym(73) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(71))" +label="Sym(73) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(71))" shape=box ] "Sym(71)" -> "Sym(73)" @@ -308,7 +308,7 @@ shape=box ] "Sym(74)" -> "Sym(76)" "Sym(78)" [ -label="Sym(78) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(76))" +label="Sym(78) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(76))" shape=box color=red ] @@ -336,7 +336,7 @@ shape=box ] "Sym(80)" -> "Sym(82)" "Sym(84)" [ -label="Sym(84) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(82))" +label="Sym(84) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(82))" shape=box ] "Sym(82)" -> "Sym(84)" @@ -353,7 +353,7 @@ shape=box ] "Sym(85)" -> "Sym(87)" "Sym(89)" [ -label="Sym(89) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(87))" +label="Sym(89) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(87))" shape=box color=red ] @@ -381,7 +381,7 @@ shape=box ] "Sym(91)" -> "Sym(93)" "Sym(95)" [ -label="Sym(95) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(93))" +label="Sym(95) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(93))" shape=box ] "Sym(93)" -> "Sym(95)" @@ -409,7 +409,7 @@ shape=box ] "Sym(99)" -> "Sym(101)" "Sym(103)" [ -label="Sym(103) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(101))" +label="Sym(103) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(101))" shape=box color=red ] @@ -437,7 +437,7 @@ shape=box ] "Sym(105)" -> "Sym(107)" "Sym(109)" [ -label="Sym(109) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(107))" +label="Sym(109) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(107))" shape=box ] "Sym(107)" -> "Sym(109)" @@ -465,7 +465,7 @@ shape=box ] "Sym(113)" -> "Sym(115)" "Sym(117)" [ -label="Sym(117) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(115))" +label="Sym(117) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(115))" shape=box color=red ] @@ -493,7 +493,7 @@ shape=box ] "Sym(119)" -> "Sym(121)" "Sym(123)" [ -label="Sym(123) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(121))" +label="Sym(123) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(121))" shape=box ] "Sym(121)" -> "Sym(123)" @@ -521,7 +521,7 @@ shape=box ] "Sym(127)" -> "Sym(129)" "Sym(131)" [ -label="Sym(131) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(129))" +label="Sym(131) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(129))" shape=box color=red ] @@ -549,7 +549,7 @@ shape=box ] "Sym(133)" -> "Sym(135)" "Sym(137)" [ -label="Sym(137) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(135))" +label="Sym(137) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(135))" shape=box ] "Sym(135)" -> "Sym(137)" @@ -599,7 +599,7 @@ shape=box ] "Sym(147)" -> "Sym(149)" "Sym(151)" [ -label="Sym(151) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(149))" +label="Sym(151) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(149))" shape=box color=red ] @@ -633,7 +633,7 @@ shape=box ] "Sym(155)" -> "Sym(157)" "Sym(159)" [ -label="Sym(159) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(157))" +label="Sym(159) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(157))" shape=box ] "Sym(157)" -> "Sym(159)" @@ -650,7 +650,7 @@ shape=box ] "Sym(160)" -> "Sym(162)" "Sym(164)" [ -label="Sym(164) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(162))" +label="Sym(164) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(162))" shape=box color=red ] @@ -678,7 +678,7 @@ shape=box ] "Sym(166)" -> "Sym(168)" "Sym(170)" [ -label="Sym(170) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(168))" +label="Sym(170) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(168))" shape=box ] "Sym(168)" -> "Sym(170)" @@ -706,7 +706,7 @@ shape=box ] "Sym(174)" -> "Sym(176)" "Sym(178)" [ -label="Sym(178) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(176))" +label="Sym(178) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(176))" shape=box color=red ] @@ -734,7 +734,7 @@ shape=box ] "Sym(180)" -> "Sym(182)" "Sym(184)" [ -label="Sym(184) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(182))" +label="Sym(184) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(182))" shape=box ] "Sym(182)" -> "Sym(184)" @@ -762,7 +762,7 @@ shape=box ] "Sym(188)" -> "Sym(190)" "Sym(192)" [ -label="Sym(192) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(190))" +label="Sym(192) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(190))" shape=box color=red ] @@ -790,7 +790,7 @@ shape=box ] "Sym(194)" -> "Sym(196)" "Sym(198)" [ -label="Sym(198) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(196))" +label="Sym(198) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(196))" shape=box ] "Sym(196)" -> "Sym(198)" @@ -818,7 +818,7 @@ shape=box ] "Sym(202)" -> "Sym(204)" "Sym(206)" [ -label="Sym(206) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(204))" +label="Sym(206) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(204))" shape=box color=red ] @@ -846,7 +846,7 @@ shape=box ] "Sym(208)" -> "Sym(210)" "Sym(212)" [ -label="Sym(212) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(210))" +label="Sym(212) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(210))" shape=box ] "Sym(210)" -> "Sym(212)" @@ -874,7 +874,7 @@ shape=box ] "Sym(216)" -> "Sym(218)" "Sym(220)" [ -label="Sym(220) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(218))" +label="Sym(220) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(218))" shape=box color=red ] @@ -902,7 +902,7 @@ shape=box ] "Sym(222)" -> "Sym(224)" "Sym(226)" [ -label="Sym(226) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(224))" +label="Sym(226) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(224))" shape=box ] "Sym(224)" -> "Sym(226)" @@ -919,7 +919,7 @@ shape=box ] "Sym(227)" -> "Sym(229)" "Sym(231)" [ -label="Sym(231) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(229))" +label="Sym(231) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(229))" shape=box color=red ] @@ -947,7 +947,7 @@ shape=box ] "Sym(233)" -> "Sym(235)" "Sym(237)" [ -label="Sym(237) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(235))" +label="Sym(237) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(235))" shape=box ] "Sym(235)" -> "Sym(237)" @@ -964,7 +964,7 @@ shape=box ] "Sym(238)" -> "Sym(240)" "Sym(242)" [ -label="Sym(242) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(240))" +label="Sym(242) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(240))" shape=box color=red ] @@ -992,7 +992,7 @@ shape=box ] "Sym(244)" -> "Sym(246)" "Sym(248)" [ -label="Sym(248) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(246))" +label="Sym(248) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(246))" shape=box ] "Sym(246)" -> "Sym(248)" @@ -1020,7 +1020,7 @@ shape=box ] "Sym(252)" -> "Sym(254)" "Sym(256)" [ -label="Sym(256) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(254))" +label="Sym(256) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(254))" shape=box color=red ] @@ -1048,7 +1048,7 @@ shape=box ] "Sym(258)" -> "Sym(260)" "Sym(262)" [ -label="Sym(262) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(260))" +label="Sym(262) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(260))" shape=box ] "Sym(260)" -> "Sym(262)" @@ -1076,7 +1076,7 @@ shape=box ] "Sym(266)" -> "Sym(268)" "Sym(270)" [ -label="Sym(270) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(268))" +label="Sym(270) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(268))" shape=box color=red ] @@ -1104,7 +1104,7 @@ shape=box ] "Sym(272)" -> "Sym(274)" "Sym(276)" [ -label="Sym(276) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(274))" +label="Sym(276) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(274))" shape=box ] "Sym(274)" -> "Sym(276)" @@ -1132,7 +1132,7 @@ shape=box ] "Sym(280)" -> "Sym(282)" "Sym(284)" [ -label="Sym(284) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(282))" +label="Sym(284) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(282))" shape=box color=red ] @@ -1160,7 +1160,7 @@ shape=box ] "Sym(286)" -> "Sym(288)" "Sym(290)" [ -label="Sym(290) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(288))" +label="Sym(290) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(288))" shape=box ] "Sym(288)" -> "Sym(290)" diff --git a/test-out/epfl/test3-parse1.check b/test-out/epfl/test3-parse1.check index f363b82a..da101b6c 100644 --- a/test-out/epfl/test3-parse1.check +++ b/test-out/epfl/test3-parse1.check @@ -3,18 +3,18 @@ TP(Sym(2),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(0))) TP(Sym(3),First(Sym(2))) TP(Sym(4),Second(Sym(2))) TP(Sym(5),Test(Sym(3),s)) -TP(Sym(6),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(4))) +TP(Sym(6),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(4))) TP(Sym(7),Reify(Sym(6),List(Sym(2), Sym(5)))) TP(Sym(8),Lambda()) TP(Sym(9),OrElse(List(Sym(7), Pure(Const(Failure()))))) TP(Sym(10),Lambda()) -TP(Sym(11),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(9))) +TP(Sym(11),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(9))) TP(Sym(12),Lambda()) TP(Sym(13),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(11))) TP(Sym(14),First(Sym(13))) TP(Sym(15),Second(Sym(13))) TP(Sym(16),Test(Sym(14),c)) -TP(Sym(17),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(15))) +TP(Sym(17),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(15))) TP(Sym(18),Reify(Sym(17),List(Sym(13), Sym(16)))) TP(Sym(19),Lambda()) TP(Sym(20),OrElse(List(Sym(18), Pure(Const(Failure()))))) @@ -22,13 +22,13 @@ TP(Sym(21),Reify(Sym(20),List(Sym(11)))) TP(Sym(22),Lambda()) TP(Sym(23),OrElse(List(Sym(21), Pure(Const(Failure()))))) TP(Sym(24),Lambda()) -TP(Sym(25),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(23))) +TP(Sym(25),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(23))) TP(Sym(26),Lambda()) TP(Sym(27),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(25))) TP(Sym(28),First(Sym(27))) TP(Sym(29),Second(Sym(27))) TP(Sym(30),Test(Sym(28),a)) -TP(Sym(31),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(29))) +TP(Sym(31),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(29))) TP(Sym(32),Reify(Sym(31),List(Sym(27), Sym(30)))) TP(Sym(33),Lambda()) TP(Sym(34),OrElse(List(Sym(32), Pure(Const(Failure()))))) @@ -36,13 +36,13 @@ TP(Sym(35),Reify(Sym(34),List(Sym(25)))) TP(Sym(36),Lambda()) TP(Sym(37),OrElse(List(Sym(35), Pure(Const(Failure()))))) TP(Sym(38),Lambda()) -TP(Sym(39),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(37))) +TP(Sym(39),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(37))) TP(Sym(40),Lambda()) TP(Sym(41),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(39))) TP(Sym(42),First(Sym(41))) TP(Sym(43),Second(Sym(41))) TP(Sym(44),Test(Sym(42),l)) -TP(Sym(45),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(43))) +TP(Sym(45),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(43))) TP(Sym(46),Reify(Sym(45),List(Sym(41), Sym(44)))) TP(Sym(47),Lambda()) TP(Sym(48),OrElse(List(Sym(46), Pure(Const(Failure()))))) @@ -50,13 +50,13 @@ TP(Sym(49),Reify(Sym(48),List(Sym(39)))) TP(Sym(50),Lambda()) TP(Sym(51),OrElse(List(Sym(49), Pure(Const(Failure()))))) TP(Sym(52),Lambda()) -TP(Sym(53),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(51))) +TP(Sym(53),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(51))) TP(Sym(54),Lambda()) TP(Sym(55),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(53))) TP(Sym(56),First(Sym(55))) TP(Sym(57),Second(Sym(55))) TP(Sym(58),Test(Sym(56),a)) -TP(Sym(59),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(57))) +TP(Sym(59),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(57))) TP(Sym(60),Reify(Sym(59),List(Sym(55), Sym(58)))) TP(Sym(61),Lambda()) TP(Sym(62),OrElse(List(Sym(60), Pure(Const(Failure()))))) @@ -64,35 +64,35 @@ TP(Sym(63),Reify(Sym(62),List(Sym(53)))) TP(Sym(64),Lambda()) TP(Sym(65),OrElse(List(Sym(63), Pure(Const(Failure()))))) TP(Sym(66),Lambda()) -TP(Sym(67),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(65))) +TP(Sym(67),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(65))) TP(Sym(68),Lambda()) TP(Sym(69),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(67))) TP(Sym(70),First(Sym(69))) TP(Sym(71),Second(Sym(69))) TP(Sym(72),Test(Sym(70), )) -TP(Sym(73),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(71))) +TP(Sym(73),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(71))) TP(Sym(74),Reify(Sym(73),List(Sym(69), Sym(72)))) TP(Sym(75),Lambda()) TP(Sym(76),OrElse(List(Sym(74), Pure(Const(Failure()))))) TP(Sym(77),Lambda()) -TP(Sym(78),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(76))) +TP(Sym(78),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(76))) TP(Sym(79),Lambda()) TP(Sym(80),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(78))) TP(Sym(81),First(Sym(80))) TP(Sym(82),Second(Sym(80))) TP(Sym(83),Test(Sym(81),r)) -TP(Sym(84),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(82))) +TP(Sym(84),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(82))) TP(Sym(85),Reify(Sym(84),List(Sym(80), Sym(83)))) TP(Sym(86),Lambda()) TP(Sym(87),OrElse(List(Sym(85), Pure(Const(Failure()))))) TP(Sym(88),Lambda()) -TP(Sym(89),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(87))) +TP(Sym(89),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(87))) TP(Sym(90),Lambda()) TP(Sym(91),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(89))) TP(Sym(92),First(Sym(91))) TP(Sym(93),Second(Sym(91))) TP(Sym(94),Test(Sym(92),u)) -TP(Sym(95),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(93))) +TP(Sym(95),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(93))) TP(Sym(96),Reify(Sym(95),List(Sym(91), Sym(94)))) TP(Sym(97),Lambda()) TP(Sym(98),OrElse(List(Sym(96), Pure(Const(Failure()))))) @@ -100,13 +100,13 @@ TP(Sym(99),Reify(Sym(98),List(Sym(89)))) TP(Sym(100),Lambda()) TP(Sym(101),OrElse(List(Sym(99), Pure(Const(Failure()))))) TP(Sym(102),Lambda()) -TP(Sym(103),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(101))) +TP(Sym(103),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(101))) TP(Sym(104),Lambda()) TP(Sym(105),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(103))) TP(Sym(106),First(Sym(105))) TP(Sym(107),Second(Sym(105))) TP(Sym(108),Test(Sym(106),l)) -TP(Sym(109),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(107))) +TP(Sym(109),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(107))) TP(Sym(110),Reify(Sym(109),List(Sym(105), Sym(108)))) TP(Sym(111),Lambda()) TP(Sym(112),OrElse(List(Sym(110), Pure(Const(Failure()))))) @@ -114,13 +114,13 @@ TP(Sym(113),Reify(Sym(112),List(Sym(103)))) TP(Sym(114),Lambda()) TP(Sym(115),OrElse(List(Sym(113), Pure(Const(Failure()))))) TP(Sym(116),Lambda()) -TP(Sym(117),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(115))) +TP(Sym(117),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(115))) TP(Sym(118),Lambda()) TP(Sym(119),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(117))) TP(Sym(120),First(Sym(119))) TP(Sym(121),Second(Sym(119))) TP(Sym(122),Test(Sym(120),e)) -TP(Sym(123),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(121))) +TP(Sym(123),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(121))) TP(Sym(124),Reify(Sym(123),List(Sym(119), Sym(122)))) TP(Sym(125),Lambda()) TP(Sym(126),OrElse(List(Sym(124), Pure(Const(Failure()))))) @@ -128,13 +128,13 @@ TP(Sym(127),Reify(Sym(126),List(Sym(117)))) TP(Sym(128),Lambda()) TP(Sym(129),OrElse(List(Sym(127), Pure(Const(Failure()))))) TP(Sym(130),Lambda()) -TP(Sym(131),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(129))) +TP(Sym(131),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(129))) TP(Sym(132),Lambda()) TP(Sym(133),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(131))) TP(Sym(134),First(Sym(133))) TP(Sym(135),Second(Sym(133))) TP(Sym(136),Test(Sym(134),s)) -TP(Sym(137),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(135))) +TP(Sym(137),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(135))) TP(Sym(138),Reify(Sym(137),List(Sym(133), Sym(136)))) TP(Sym(139),Lambda()) TP(Sym(140),OrElse(List(Sym(138), Pure(Const(Failure()))))) @@ -148,7 +148,7 @@ TP(Sym(147),Reify(Sym(146),List(Sym(67)))) TP(Sym(148),Lambda()) TP(Sym(149),OrElse(List(Sym(147), Pure(Const(Failure()))))) TP(Sym(150),Lambda()) -TP(Sym(151),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(149))) +TP(Sym(151),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(149))) TP(Sym(152),Reify(Sym(149),List(Sym(151)))) TP(Sym(153),Lambda()) TP(Sym(154),Lambda()) @@ -156,18 +156,18 @@ TP(Sym(155),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(0))) TP(Sym(156),First(Sym(155))) TP(Sym(157),Second(Sym(155))) TP(Sym(158),Test(Sym(156),s)) -TP(Sym(159),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(157))) +TP(Sym(159),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(157))) TP(Sym(160),Reify(Sym(159),List(Sym(155), Sym(158)))) TP(Sym(161),Lambda()) TP(Sym(162),OrElse(List(Sym(160), Pure(Const(Failure()))))) TP(Sym(163),Lambda()) -TP(Sym(164),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(162))) +TP(Sym(164),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(162))) TP(Sym(165),Lambda()) TP(Sym(166),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(164))) TP(Sym(167),First(Sym(166))) TP(Sym(168),Second(Sym(166))) TP(Sym(169),Test(Sym(167),c)) -TP(Sym(170),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(168))) +TP(Sym(170),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(168))) TP(Sym(171),Reify(Sym(170),List(Sym(166), Sym(169)))) TP(Sym(172),Lambda()) TP(Sym(173),OrElse(List(Sym(171), Pure(Const(Failure()))))) @@ -175,13 +175,13 @@ TP(Sym(174),Reify(Sym(173),List(Sym(164)))) TP(Sym(175),Lambda()) TP(Sym(176),OrElse(List(Sym(174), Pure(Const(Failure()))))) TP(Sym(177),Lambda()) -TP(Sym(178),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(176))) +TP(Sym(178),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(176))) TP(Sym(179),Lambda()) TP(Sym(180),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(178))) TP(Sym(181),First(Sym(180))) TP(Sym(182),Second(Sym(180))) TP(Sym(183),Test(Sym(181),a)) -TP(Sym(184),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(182))) +TP(Sym(184),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(182))) TP(Sym(185),Reify(Sym(184),List(Sym(180), Sym(183)))) TP(Sym(186),Lambda()) TP(Sym(187),OrElse(List(Sym(185), Pure(Const(Failure()))))) @@ -189,13 +189,13 @@ TP(Sym(188),Reify(Sym(187),List(Sym(178)))) TP(Sym(189),Lambda()) TP(Sym(190),OrElse(List(Sym(188), Pure(Const(Failure()))))) TP(Sym(191),Lambda()) -TP(Sym(192),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(190))) +TP(Sym(192),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(190))) TP(Sym(193),Lambda()) TP(Sym(194),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(192))) TP(Sym(195),First(Sym(194))) TP(Sym(196),Second(Sym(194))) TP(Sym(197),Test(Sym(195),l)) -TP(Sym(198),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(196))) +TP(Sym(198),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(196))) TP(Sym(199),Reify(Sym(198),List(Sym(194), Sym(197)))) TP(Sym(200),Lambda()) TP(Sym(201),OrElse(List(Sym(199), Pure(Const(Failure()))))) @@ -203,13 +203,13 @@ TP(Sym(202),Reify(Sym(201),List(Sym(192)))) TP(Sym(203),Lambda()) TP(Sym(204),OrElse(List(Sym(202), Pure(Const(Failure()))))) TP(Sym(205),Lambda()) -TP(Sym(206),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(204))) +TP(Sym(206),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(204))) TP(Sym(207),Lambda()) TP(Sym(208),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(206))) TP(Sym(209),First(Sym(208))) TP(Sym(210),Second(Sym(208))) TP(Sym(211),Test(Sym(209),a)) -TP(Sym(212),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(210))) +TP(Sym(212),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(210))) TP(Sym(213),Reify(Sym(212),List(Sym(208), Sym(211)))) TP(Sym(214),Lambda()) TP(Sym(215),OrElse(List(Sym(213), Pure(Const(Failure()))))) @@ -217,35 +217,35 @@ TP(Sym(216),Reify(Sym(215),List(Sym(206)))) TP(Sym(217),Lambda()) TP(Sym(218),OrElse(List(Sym(216), Pure(Const(Failure()))))) TP(Sym(219),Lambda()) -TP(Sym(220),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(218))) +TP(Sym(220),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(218))) TP(Sym(221),Lambda()) TP(Sym(222),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(220))) TP(Sym(223),First(Sym(222))) TP(Sym(224),Second(Sym(222))) TP(Sym(225),Test(Sym(223), )) -TP(Sym(226),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(224))) +TP(Sym(226),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(224))) TP(Sym(227),Reify(Sym(226),List(Sym(222), Sym(225)))) TP(Sym(228),Lambda()) TP(Sym(229),OrElse(List(Sym(227), Pure(Const(Failure()))))) TP(Sym(230),Lambda()) -TP(Sym(231),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(229))) +TP(Sym(231),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(229))) TP(Sym(232),Lambda()) TP(Sym(233),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(231))) TP(Sym(234),First(Sym(233))) TP(Sym(235),Second(Sym(233))) TP(Sym(236),Test(Sym(234),r)) -TP(Sym(237),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(235))) +TP(Sym(237),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(235))) TP(Sym(238),Reify(Sym(237),List(Sym(233), Sym(236)))) TP(Sym(239),Lambda()) TP(Sym(240),OrElse(List(Sym(238), Pure(Const(Failure()))))) TP(Sym(241),Lambda()) -TP(Sym(242),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(240))) +TP(Sym(242),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(240))) TP(Sym(243),Lambda()) TP(Sym(244),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(242))) TP(Sym(245),First(Sym(244))) TP(Sym(246),Second(Sym(244))) TP(Sym(247),Test(Sym(245),o)) -TP(Sym(248),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(246))) +TP(Sym(248),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(246))) TP(Sym(249),Reify(Sym(248),List(Sym(244), Sym(247)))) TP(Sym(250),Lambda()) TP(Sym(251),OrElse(List(Sym(249), Pure(Const(Failure()))))) @@ -253,13 +253,13 @@ TP(Sym(252),Reify(Sym(251),List(Sym(242)))) TP(Sym(253),Lambda()) TP(Sym(254),OrElse(List(Sym(252), Pure(Const(Failure()))))) TP(Sym(255),Lambda()) -TP(Sym(256),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(254))) +TP(Sym(256),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(254))) TP(Sym(257),Lambda()) TP(Sym(258),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(256))) TP(Sym(259),First(Sym(258))) TP(Sym(260),Second(Sym(258))) TP(Sym(261),Test(Sym(259),c)) -TP(Sym(262),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(260))) +TP(Sym(262),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(260))) TP(Sym(263),Reify(Sym(262),List(Sym(258), Sym(261)))) TP(Sym(264),Lambda()) TP(Sym(265),OrElse(List(Sym(263), Pure(Const(Failure()))))) @@ -267,13 +267,13 @@ TP(Sym(266),Reify(Sym(265),List(Sym(256)))) TP(Sym(267),Lambda()) TP(Sym(268),OrElse(List(Sym(266), Pure(Const(Failure()))))) TP(Sym(269),Lambda()) -TP(Sym(270),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(268))) +TP(Sym(270),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(268))) TP(Sym(271),Lambda()) TP(Sym(272),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(270))) TP(Sym(273),First(Sym(272))) TP(Sym(274),Second(Sym(272))) TP(Sym(275),Test(Sym(273),k)) -TP(Sym(276),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(274))) +TP(Sym(276),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(274))) TP(Sym(277),Reify(Sym(276),List(Sym(272), Sym(275)))) TP(Sym(278),Lambda()) TP(Sym(279),OrElse(List(Sym(277), Pure(Const(Failure()))))) @@ -281,13 +281,13 @@ TP(Sym(280),Reify(Sym(279),List(Sym(270)))) TP(Sym(281),Lambda()) TP(Sym(282),OrElse(List(Sym(280), Pure(Const(Failure()))))) TP(Sym(283),Lambda()) -TP(Sym(284),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(282))) +TP(Sym(284),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(282))) TP(Sym(285),Lambda()) TP(Sym(286),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(284))) TP(Sym(287),First(Sym(286))) TP(Sym(288),Second(Sym(286))) TP(Sym(289),Test(Sym(287),s)) -TP(Sym(290),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(288))) +TP(Sym(290),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(288))) TP(Sym(291),Reify(Sym(290),List(Sym(286), Sym(289)))) TP(Sym(292),Lambda()) TP(Sym(293),OrElse(List(Sym(291), Pure(Const(Failure()))))) diff --git a/test-out/epfl/test3-parse2-dot.check b/test-out/epfl/test3-parse2-dot.check index 00b355a4..6a67f4a4 100644 --- a/test-out/epfl/test3-parse2-dot.check +++ b/test-out/epfl/test3-parse2-dot.check @@ -22,7 +22,7 @@ shape=box ] "Sym(2)" -> "Sym(4)" "Sym(6)" [ -label="Sym(6) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(4))" +label="Sym(6) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(4))" shape=box ] "Sym(4)" -> "Sym(6)" @@ -39,7 +39,7 @@ shape=box ] "Sym(7)" -> "Sym(9)" "Sym(11)" [ -label="Sym(11) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(9))" +label="Sym(11) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(9))" shape=box color=red ] @@ -67,7 +67,7 @@ shape=box ] "Sym(13)" -> "Sym(15)" "Sym(17)" [ -label="Sym(17) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(15))" +label="Sym(17) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(15))" shape=box ] "Sym(15)" -> "Sym(17)" @@ -95,7 +95,7 @@ shape=box ] "Sym(21)" -> "Sym(23)" "Sym(25)" [ -label="Sym(25) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(23))" +label="Sym(25) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(23))" shape=box color=red ] @@ -123,7 +123,7 @@ shape=box ] "Sym(27)" -> "Sym(29)" "Sym(31)" [ -label="Sym(31) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(29))" +label="Sym(31) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(29))" shape=box ] "Sym(29)" -> "Sym(31)" @@ -151,7 +151,7 @@ shape=box ] "Sym(35)" -> "Sym(37)" "Sym(39)" [ -label="Sym(39) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(37))" +label="Sym(39) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(37))" shape=box color=red ] @@ -179,7 +179,7 @@ shape=box ] "Sym(41)" -> "Sym(43)" "Sym(45)" [ -label="Sym(45) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(43))" +label="Sym(45) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(43))" shape=box ] "Sym(43)" -> "Sym(45)" @@ -207,7 +207,7 @@ shape=box ] "Sym(49)" -> "Sym(51)" "Sym(53)" [ -label="Sym(53) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(51))" +label="Sym(53) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(51))" shape=box color=red ] @@ -235,7 +235,7 @@ shape=box ] "Sym(55)" -> "Sym(57)" "Sym(59)" [ -label="Sym(59) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(57))" +label="Sym(59) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(57))" shape=box ] "Sym(57)" -> "Sym(59)" @@ -263,7 +263,7 @@ shape=box ] "Sym(63)" -> "Sym(65)" "Sym(67)" [ -label="Sym(67) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(65))" +label="Sym(67) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(65))" shape=box color=red ] @@ -291,7 +291,7 @@ shape=box ] "Sym(69)" -> "Sym(71)" "Sym(73)" [ -label="Sym(73) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(71))" +label="Sym(73) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(71))" shape=box ] "Sym(71)" -> "Sym(73)" @@ -308,7 +308,7 @@ shape=box ] "Sym(74)" -> "Sym(76)" "Sym(78)" [ -label="Sym(78) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(76))" +label="Sym(78) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(76))" shape=box color=red ] @@ -336,7 +336,7 @@ shape=box ] "Sym(80)" -> "Sym(82)" "Sym(84)" [ -label="Sym(84) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(82))" +label="Sym(84) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(82))" shape=box ] "Sym(82)" -> "Sym(84)" @@ -353,7 +353,7 @@ shape=box ] "Sym(85)" -> "Sym(87)" "Sym(89)" [ -label="Sym(89) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(87))" +label="Sym(89) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(87))" shape=box color=red ] @@ -381,7 +381,7 @@ shape=box ] "Sym(91)" -> "Sym(93)" "Sym(95)" [ -label="Sym(95) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(93))" +label="Sym(95) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(93))" shape=box ] "Sym(93)" -> "Sym(95)" @@ -409,7 +409,7 @@ shape=box ] "Sym(99)" -> "Sym(101)" "Sym(103)" [ -label="Sym(103) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(101))" +label="Sym(103) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(101))" shape=box color=red ] @@ -437,7 +437,7 @@ shape=box ] "Sym(105)" -> "Sym(107)" "Sym(109)" [ -label="Sym(109) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(107))" +label="Sym(109) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(107))" shape=box ] "Sym(107)" -> "Sym(109)" @@ -465,7 +465,7 @@ shape=box ] "Sym(113)" -> "Sym(115)" "Sym(117)" [ -label="Sym(117) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(115))" +label="Sym(117) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(115))" shape=box color=red ] @@ -493,7 +493,7 @@ shape=box ] "Sym(119)" -> "Sym(121)" "Sym(123)" [ -label="Sym(123) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(121))" +label="Sym(123) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(121))" shape=box ] "Sym(121)" -> "Sym(123)" @@ -521,7 +521,7 @@ shape=box ] "Sym(127)" -> "Sym(129)" "Sym(131)" [ -label="Sym(131) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(129))" +label="Sym(131) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(129))" shape=box color=red ] @@ -549,7 +549,7 @@ shape=box ] "Sym(133)" -> "Sym(135)" "Sym(137)" [ -label="Sym(137) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(135))" +label="Sym(137) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(135))" shape=box ] "Sym(135)" -> "Sym(137)" @@ -599,7 +599,7 @@ shape=box ] "Sym(147)" -> "Sym(149)" "Sym(151)" [ -label="Sym(151) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(149))" +label="Sym(151) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(149))" shape=box color=red ] @@ -640,7 +640,7 @@ shape=box ] "Sym(184)" -> "Sym(186)" "Sym(188)" [ -label="Sym(188) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(186))" +label="Sym(188) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(186))" shape=box color=red ] @@ -668,7 +668,7 @@ shape=box ] "Sym(190)" -> "Sym(192)" "Sym(194)" [ -label="Sym(194) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(192))" +label="Sym(194) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(192))" shape=box ] "Sym(192)" -> "Sym(194)" @@ -696,7 +696,7 @@ shape=box ] "Sym(198)" -> "Sym(200)" "Sym(202)" [ -label="Sym(202) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(200))" +label="Sym(202) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(200))" shape=box color=red ] @@ -724,7 +724,7 @@ shape=box ] "Sym(204)" -> "Sym(206)" "Sym(208)" [ -label="Sym(208) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(206))" +label="Sym(208) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(206))" shape=box ] "Sym(206)" -> "Sym(208)" @@ -752,7 +752,7 @@ shape=box ] "Sym(212)" -> "Sym(214)" "Sym(216)" [ -label="Sym(216) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(214))" +label="Sym(216) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(214))" shape=box color=red ] @@ -780,7 +780,7 @@ shape=box ] "Sym(218)" -> "Sym(220)" "Sym(222)" [ -label="Sym(222) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(220))" +label="Sym(222) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(220))" shape=box ] "Sym(220)" -> "Sym(222)" diff --git a/test-out/epfl/test3-parse2.check b/test-out/epfl/test3-parse2.check index 67b0c299..7a248fcd 100644 --- a/test-out/epfl/test3-parse2.check +++ b/test-out/epfl/test3-parse2.check @@ -3,18 +3,18 @@ TP(Sym(2),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(0))) TP(Sym(3),First(Sym(2))) TP(Sym(4),Second(Sym(2))) TP(Sym(5),Test(Sym(3),s)) -TP(Sym(6),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(4))) +TP(Sym(6),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(4))) TP(Sym(7),Reify(Sym(6),List(Sym(2), Sym(5)))) TP(Sym(8),Lambda()) TP(Sym(9),OrElse(List(Sym(7), Pure(Const(Failure()))))) TP(Sym(10),Lambda()) -TP(Sym(11),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(9))) +TP(Sym(11),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(9))) TP(Sym(12),Lambda()) TP(Sym(13),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(11))) TP(Sym(14),First(Sym(13))) TP(Sym(15),Second(Sym(13))) TP(Sym(16),Test(Sym(14),c)) -TP(Sym(17),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(15))) +TP(Sym(17),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(15))) TP(Sym(18),Reify(Sym(17),List(Sym(13), Sym(16)))) TP(Sym(19),Lambda()) TP(Sym(20),OrElse(List(Sym(18), Pure(Const(Failure()))))) @@ -22,13 +22,13 @@ TP(Sym(21),Reify(Sym(20),List(Sym(11)))) TP(Sym(22),Lambda()) TP(Sym(23),OrElse(List(Sym(21), Pure(Const(Failure()))))) TP(Sym(24),Lambda()) -TP(Sym(25),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(23))) +TP(Sym(25),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(23))) TP(Sym(26),Lambda()) TP(Sym(27),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(25))) TP(Sym(28),First(Sym(27))) TP(Sym(29),Second(Sym(27))) TP(Sym(30),Test(Sym(28),a)) -TP(Sym(31),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(29))) +TP(Sym(31),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(29))) TP(Sym(32),Reify(Sym(31),List(Sym(27), Sym(30)))) TP(Sym(33),Lambda()) TP(Sym(34),OrElse(List(Sym(32), Pure(Const(Failure()))))) @@ -36,13 +36,13 @@ TP(Sym(35),Reify(Sym(34),List(Sym(25)))) TP(Sym(36),Lambda()) TP(Sym(37),OrElse(List(Sym(35), Pure(Const(Failure()))))) TP(Sym(38),Lambda()) -TP(Sym(39),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(37))) +TP(Sym(39),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(37))) TP(Sym(40),Lambda()) TP(Sym(41),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(39))) TP(Sym(42),First(Sym(41))) TP(Sym(43),Second(Sym(41))) TP(Sym(44),Test(Sym(42),l)) -TP(Sym(45),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(43))) +TP(Sym(45),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(43))) TP(Sym(46),Reify(Sym(45),List(Sym(41), Sym(44)))) TP(Sym(47),Lambda()) TP(Sym(48),OrElse(List(Sym(46), Pure(Const(Failure()))))) @@ -50,13 +50,13 @@ TP(Sym(49),Reify(Sym(48),List(Sym(39)))) TP(Sym(50),Lambda()) TP(Sym(51),OrElse(List(Sym(49), Pure(Const(Failure()))))) TP(Sym(52),Lambda()) -TP(Sym(53),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(51))) +TP(Sym(53),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(51))) TP(Sym(54),Lambda()) TP(Sym(55),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(53))) TP(Sym(56),First(Sym(55))) TP(Sym(57),Second(Sym(55))) TP(Sym(58),Test(Sym(56),a)) -TP(Sym(59),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(57))) +TP(Sym(59),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(57))) TP(Sym(60),Reify(Sym(59),List(Sym(55), Sym(58)))) TP(Sym(61),Lambda()) TP(Sym(62),OrElse(List(Sym(60), Pure(Const(Failure()))))) @@ -64,35 +64,35 @@ TP(Sym(63),Reify(Sym(62),List(Sym(53)))) TP(Sym(64),Lambda()) TP(Sym(65),OrElse(List(Sym(63), Pure(Const(Failure()))))) TP(Sym(66),Lambda()) -TP(Sym(67),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(65))) +TP(Sym(67),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(65))) TP(Sym(68),Lambda()) TP(Sym(69),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(67))) TP(Sym(70),First(Sym(69))) TP(Sym(71),Second(Sym(69))) TP(Sym(72),Test(Sym(70), )) -TP(Sym(73),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(71))) +TP(Sym(73),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(71))) TP(Sym(74),Reify(Sym(73),List(Sym(69), Sym(72)))) TP(Sym(75),Lambda()) TP(Sym(76),OrElse(List(Sym(74), Pure(Const(Failure()))))) TP(Sym(77),Lambda()) -TP(Sym(78),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(76))) +TP(Sym(78),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(76))) TP(Sym(79),Lambda()) TP(Sym(80),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(78))) TP(Sym(81),First(Sym(80))) TP(Sym(82),Second(Sym(80))) TP(Sym(83),Test(Sym(81),r)) -TP(Sym(84),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(82))) +TP(Sym(84),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(82))) TP(Sym(85),Reify(Sym(84),List(Sym(80), Sym(83)))) TP(Sym(86),Lambda()) TP(Sym(87),OrElse(List(Sym(85), Pure(Const(Failure()))))) TP(Sym(88),Lambda()) -TP(Sym(89),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(87))) +TP(Sym(89),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(87))) TP(Sym(90),Lambda()) TP(Sym(91),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(89))) TP(Sym(92),First(Sym(91))) TP(Sym(93),Second(Sym(91))) TP(Sym(94),Test(Sym(92),u)) -TP(Sym(95),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(93))) +TP(Sym(95),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(93))) TP(Sym(96),Reify(Sym(95),List(Sym(91), Sym(94)))) TP(Sym(97),Lambda()) TP(Sym(98),OrElse(List(Sym(96), Pure(Const(Failure()))))) @@ -100,13 +100,13 @@ TP(Sym(99),Reify(Sym(98),List(Sym(89)))) TP(Sym(100),Lambda()) TP(Sym(101),OrElse(List(Sym(99), Pure(Const(Failure()))))) TP(Sym(102),Lambda()) -TP(Sym(103),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(101))) +TP(Sym(103),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(101))) TP(Sym(104),Lambda()) TP(Sym(105),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(103))) TP(Sym(106),First(Sym(105))) TP(Sym(107),Second(Sym(105))) TP(Sym(108),Test(Sym(106),l)) -TP(Sym(109),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(107))) +TP(Sym(109),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(107))) TP(Sym(110),Reify(Sym(109),List(Sym(105), Sym(108)))) TP(Sym(111),Lambda()) TP(Sym(112),OrElse(List(Sym(110), Pure(Const(Failure()))))) @@ -114,13 +114,13 @@ TP(Sym(113),Reify(Sym(112),List(Sym(103)))) TP(Sym(114),Lambda()) TP(Sym(115),OrElse(List(Sym(113), Pure(Const(Failure()))))) TP(Sym(116),Lambda()) -TP(Sym(117),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(115))) +TP(Sym(117),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(115))) TP(Sym(118),Lambda()) TP(Sym(119),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(117))) TP(Sym(120),First(Sym(119))) TP(Sym(121),Second(Sym(119))) TP(Sym(122),Test(Sym(120),e)) -TP(Sym(123),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(121))) +TP(Sym(123),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(121))) TP(Sym(124),Reify(Sym(123),List(Sym(119), Sym(122)))) TP(Sym(125),Lambda()) TP(Sym(126),OrElse(List(Sym(124), Pure(Const(Failure()))))) @@ -128,13 +128,13 @@ TP(Sym(127),Reify(Sym(126),List(Sym(117)))) TP(Sym(128),Lambda()) TP(Sym(129),OrElse(List(Sym(127), Pure(Const(Failure()))))) TP(Sym(130),Lambda()) -TP(Sym(131),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(129))) +TP(Sym(131),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(129))) TP(Sym(132),Lambda()) TP(Sym(133),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(131))) TP(Sym(134),First(Sym(133))) TP(Sym(135),Second(Sym(133))) TP(Sym(136),Test(Sym(134),s)) -TP(Sym(137),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(135))) +TP(Sym(137),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(135))) TP(Sym(138),Reify(Sym(137),List(Sym(133), Sym(136)))) TP(Sym(139),Lambda()) TP(Sym(140),OrElse(List(Sym(138), Pure(Const(Failure()))))) @@ -148,7 +148,7 @@ TP(Sym(147),Reify(Sym(146),List(Sym(67)))) TP(Sym(148),Lambda()) TP(Sym(149),OrElse(List(Sym(147), Pure(Const(Failure()))))) TP(Sym(150),Lambda()) -TP(Sym(151),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(149))) +TP(Sym(151),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(149))) TP(Sym(152),Reify(Sym(149),List(Sym(151)))) TP(Sym(153),Lambda()) TP(Sym(154),Lambda()) @@ -185,13 +185,13 @@ TP(Sym(184),Reify(Sym(183),List(Sym(89)))) TP(Sym(185),Lambda()) TP(Sym(186),OrElse(List(Sym(184), Pure(Const(Failure()))))) TP(Sym(187),Lambda()) -TP(Sym(188),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(186))) +TP(Sym(188),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(186))) TP(Sym(189),Lambda()) TP(Sym(190),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(188))) TP(Sym(191),First(Sym(190))) TP(Sym(192),Second(Sym(190))) TP(Sym(193),Test(Sym(191),c)) -TP(Sym(194),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(192))) +TP(Sym(194),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(192))) TP(Sym(195),Reify(Sym(194),List(Sym(190), Sym(193)))) TP(Sym(196),Lambda()) TP(Sym(197),OrElse(List(Sym(195), Pure(Const(Failure()))))) @@ -199,13 +199,13 @@ TP(Sym(198),Reify(Sym(197),List(Sym(188)))) TP(Sym(199),Lambda()) TP(Sym(200),OrElse(List(Sym(198), Pure(Const(Failure()))))) TP(Sym(201),Lambda()) -TP(Sym(202),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(200))) +TP(Sym(202),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(200))) TP(Sym(203),Lambda()) TP(Sym(204),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(202))) TP(Sym(205),First(Sym(204))) TP(Sym(206),Second(Sym(204))) TP(Sym(207),Test(Sym(205),k)) -TP(Sym(208),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(206))) +TP(Sym(208),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(206))) TP(Sym(209),Reify(Sym(208),List(Sym(204), Sym(207)))) TP(Sym(210),Lambda()) TP(Sym(211),OrElse(List(Sym(209), Pure(Const(Failure()))))) @@ -213,13 +213,13 @@ TP(Sym(212),Reify(Sym(211),List(Sym(202)))) TP(Sym(213),Lambda()) TP(Sym(214),OrElse(List(Sym(212), Pure(Const(Failure()))))) TP(Sym(215),Lambda()) -TP(Sym(216),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(214))) +TP(Sym(216),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(214))) TP(Sym(217),Lambda()) TP(Sym(218),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(216))) TP(Sym(219),First(Sym(218))) TP(Sym(220),Second(Sym(218))) TP(Sym(221),Test(Sym(219),s)) -TP(Sym(222),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(220))) +TP(Sym(222),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(220))) TP(Sym(223),Reify(Sym(222),List(Sym(218), Sym(221)))) TP(Sym(224),Lambda()) TP(Sym(225),OrElse(List(Sym(223), Pure(Const(Failure()))))) diff --git a/test-out/epfl/test4-counter1.check b/test-out/epfl/test4-counter1.check index 3362f21d..37311313 100644 --- a/test-out/epfl/test4-counter1.check +++ b/test-out/epfl/test4-counter1.check @@ -1,9 +1,9 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x1 = null.asInstanceOf[scala.Function1[Double, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x1 = null.asInstanceOf[scala.Function1[Double, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x1 = {x2: (Double) => val x3 = List(x2) val x4 = {x5: (Char) => @@ -12,7 +12,7 @@ val x7 = x6+1.0 val x8 = x1(x7) x8 } -val x9 = scala.lms.epfl.test4.Automaton(x3,x4) +val x9 = scala.virtualization.lms.epfl.test4.Automaton(x3,x4) x9 } val x10 = x1(0.0) @@ -22,7 +22,6 @@ x10 /***************************************** End of Generated Code *******************************************/ -compilation: ok idx: 0 out: List(0.0) char: X diff --git a/test-out/epfl/test4-counter2.check b/test-out/epfl/test4-counter2.check index 92a61f0c..bf161253 100644 --- a/test-out/epfl/test4-counter2.check +++ b/test-out/epfl/test4-counter2.check @@ -1,11 +1,11 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x59 = null.asInstanceOf[scala.Function1[Tuple2ListCharListChar, Tuple2ListCharListChar]] -var x7 = null.asInstanceOf[scala.Function1[Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -x59 = {x60: (Tuple2ListCharListChar) => +class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x59 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.collection.immutable.List[Char], scala.collection.immutable.List[Char]], scala.Tuple2[scala.collection.immutable.List[Char], scala.collection.immutable.List[Char]]]] +var x7 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.Tuple2[scala.Tuple2[scala.Tuple2[Double, scala.Tuple2[Double, Double]], Double], Double], scala.collection.immutable.List[Char]], scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +x59 = {x60: (scala.Tuple2[scala.collection.immutable.List[Char], scala.collection.immutable.List[Char]]) => val x61 = x60._1 val x63 = x61.isEmpty val x65 = if (x63) { @@ -19,7 +19,7 @@ val x62 = x60._2 val x67 = x61.head val x68 = List(x67) val x69 = x62 ::: x68 -val x70 = new Tuple2ListCharListChar(x66,x69) +val x70 = (x66,x69) val x71 = x59(x70) x71 } else { @@ -27,7 +27,7 @@ x60 } x72 } -x7 = {x8: (Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar) => +x7 = {x8: (scala.Tuple2[scala.Tuple2[scala.Tuple2[scala.Tuple2[Double, scala.Tuple2[Double, Double]], Double], Double], scala.collection.immutable.List[Char]]) => val x10 = x8._2 val x9 = x8._1 val x12 = x9._2 @@ -37,10 +37,10 @@ val x13 = x11._1 val x15 = x13._1 val x16 = x13._2 val x18 = x16._2 -val x19 = new Tuple2DoubleDouble(x15,x18) -val x20 = new Tuple2Tuple2DoubleDoubleDouble(x19,x14) -val x21 = new Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(x20,x12) -val x22 = new Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(x21,x10) +val x19 = (x15,x18) +val x20 = (x19,x14) +val x21 = (x20,x12) +val x22 = (x21,x10) val x23 = List(x22) val x24 = {x25: (Char) => val x27 = x8 // x25 @@ -63,7 +63,7 @@ val x40 = x35._2 val x43 = x40+1.0 x43 } -val x45 = new Tuple2DoubleDouble(0.0,x44) +val x45 = (0.0,x44) (x37,x45) } else { val x28 = x27._1 @@ -74,10 +74,10 @@ val x35 = x32._2 val x40 = x35._2 val x39 = x35._1 val x46 = x39+1.0 -val x47 = new Tuple2DoubleDouble(x46,x40) +val x47 = (x46,x40) (x34,x47) } -val x49 = new Tuple2DoubleTuple2DoubleDouble(x38,x48) +val x49 = (x38,x48) val x50 = x25 == 'B' val x52 = if (x50) { val x28 = x27._1 @@ -91,7 +91,7 @@ val x30 = x28._1 val x33 = x30._2 x33 } -val x53 = new Tuple2Tuple2DoubleTuple2DoubleDoubleDouble(x49,x52) +val x53 = (x49,x52) val x54 = x25 == 'C' val x56 = if (x54) { val x28 = x27._1 @@ -103,25 +103,25 @@ val x28 = x27._1 val x31 = x28._2 x31 } -val x57 = new Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDouble(x53,x56) +val x57 = (x53,x56) val x26 = List(x25,x25,x25) val x29 = x27._2 -val x58 = new Tuple2ListCharListChar(x26,x29) +val x58 = (x26,x29) val x73 = x59(x58) val x75 = x73._2 -val x76 = new Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar(x57,x75) +val x76 = (x57,x75) val x77 = x7(x76) x77 } -val x78 = scala.lms.epfl.test4.Automaton(x23,x24) +val x78 = scala.virtualization.lms.epfl.test4.Automaton(x23,x24) x78 } val x1 = List() -val x2 = new Tuple2DoubleDouble(0.0,0.0) -val x3 = new Tuple2DoubleTuple2DoubleDouble(0.0,x2) -val x4 = new Tuple2Tuple2DoubleTuple2DoubleDoubleDouble(x3,0.0) -val x5 = new Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDouble(x4,0.0) -val x6 = new Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar(x5,x1) +val x2 = (0.0,0.0) +val x3 = (0.0,x2) +val x4 = (x3,0.0) +val x5 = (x4,0.0) +val x6 = (x5,x1) val x79 = x7(x6) x79 } @@ -129,66 +129,47 @@ x79 /***************************************** End of Generated Code *******************************************/ - -case class Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDouble(_1: Tuple2Tuple2DoubleTuple2DoubleDoubleDouble, _2: Double) - -case class Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(_1: Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble, _2: scala.collection.immutable.List[Char]) - -case class Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(_1: Tuple2Tuple2DoubleDoubleDouble, _2: Double) - -case class Tuple2DoubleTuple2DoubleDouble(_1: Double, _2: Tuple2DoubleDouble) - -case class Tuple2ListCharListChar(_1: scala.collection.immutable.List[Char], _2: scala.collection.immutable.List[Char]) - -case class Tuple2DoubleDouble(_1: Double, _2: Double) - -case class Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar(_1: Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDouble, _2: scala.collection.immutable.List[Char]) - -case class Tuple2Tuple2DoubleDoubleDouble(_1: Tuple2DoubleDouble, _2: Double) - -case class Tuple2Tuple2DoubleTuple2DoubleDoubleDouble(_1: Tuple2DoubleTuple2DoubleDouble, _2: Double) -compilation: ok idx: 0 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(0.0,0.0),0.0),0.0),List())) +out: List(((((0.0,0.0),0.0),0.0),List())) char: X idx: 1 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(0.0,0.0),0.0),0.0),List(X, X, X))) +out: List(((((0.0,0.0),0.0),0.0),List(X, X, X))) char: A idx: 2 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(1.0,1.0),0.0),0.0),List(X, X, X, A, A, A))) +out: List(((((1.0,1.0),0.0),0.0),List(X, X, X, A, A, A))) char: B idx: 3 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(1.0,1.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B))) +out: List(((((1.0,1.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B))) char: Z idx: 4 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(1.0,1.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z))) +out: List(((((1.0,1.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z))) char: A idx: 5 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(2.0,2.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A))) +out: List(((((2.0,2.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A))) char: A idx: 6 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(3.0,2.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A))) +out: List(((((3.0,2.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A))) char: B idx: 7 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(3.0,2.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B))) +out: List(((((3.0,2.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B))) char: W idx: 8 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(3.0,2.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W))) +out: List(((((3.0,2.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W))) char: A idx: 9 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(4.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A))) +out: List(((((4.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A))) char: A idx: 10 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(5.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A))) +out: List(((((5.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A))) char: A idx: 11 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(6.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A))) +out: List(((((6.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A))) char: A idx: 12 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(7.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A))) +out: List(((((7.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A))) char: B idx: 13 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(7.0,3.0),3.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A, B, B, B))) +out: List(((((7.0,3.0),3.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A, B, B, B))) char: Q idx: 14 -out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(7.0,3.0),3.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A, B, B, B, Q, Q, Q))) +out: List(((((7.0,3.0),3.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A, B, B, B, Q, Q, Q))) diff --git a/test-out/epfl/test4-fac3.check b/test-out/epfl/test4-fac3.check index c74d3aa0..48083712 100644 --- a/test-out/epfl/test4-fac3.check +++ b/test-out/epfl/test4-fac3.check @@ -1,4 +1,4 @@ --- hit recursion: class scala.lms.epfl.test3.MatchingExtractorsExp$$anonfun$liftAlt$1$1 Sym(5) <- Sym(0) +-- hit recursion: class scala.virtualization.lms.epfl.test3.MatchingExtractorsExp$$anonfun$liftAlt$1$1 Sym(5) <- Sym(0) TP(Sym(1),Lambda()) TP(Sym(2),Test(Sym(0),0.0)) TP(Sym(3),Reify(Const(1.0),List(Sym(2)))) diff --git a/test-out/epfl/test4-matchernew1.check b/test-out/epfl/test4-matchernew1.check index da550cf8..ec085db7 100644 --- a/test-out/epfl/test4-matchernew1.check +++ b/test-out/epfl/test4-matchernew1.check @@ -1,15 +1,15 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x10 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x1 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x17 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x4 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x13 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x7 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x11 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x10 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x1 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x17 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x4 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x13 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x7 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x11 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] x1 = {x2: (Char) => val x3 = x2 == 'A' val x18 = if (x3) { @@ -19,8 +19,15 @@ x10 } x18 } -x10 = scala.lms.epfl.test4.Automaton(List(),x1) -x11 = x10.copy(out = "found"::x10.out) +x4 = {x5: (Char) => +val x6 = x5 == 'A' +val x16 = if (x6) { +x13 +} else { +x10 +} +x16 +} x7 = {x8: (Char) => val x9 = x8 == 'B' val x15 = if (x9) { @@ -36,24 +43,16 @@ x14 } x15 } -x13 = scala.lms.epfl.test4.Automaton(List(),x7) -x4 = {x5: (Char) => -val x6 = x5 == 'A' -val x16 = if (x6) { -x13 -} else { -x10 -} -x16 -} -x17 = scala.lms.epfl.test4.Automaton(List(),x4) +x10 = scala.virtualization.lms.epfl.test4.Automaton(List(),x1) +x11 = x10.copy(out = "found"::x10.out) +x13 = scala.virtualization.lms.epfl.test4.Automaton(List(),x7) +x17 = scala.virtualization.lms.epfl.test4.Automaton(List(),x4) x10 } } /***************************************** End of Generated Code *******************************************/ -compilation: ok idx: 0 out: List() char: X diff --git a/test-out/epfl/test4-matchernew1b.check b/test-out/epfl/test4-matchernew1b.check index 829e37b5..afd393bb 100644 --- a/test-out/epfl/test4-matchernew1b.check +++ b/test-out/epfl/test4-matchernew1b.check @@ -1,15 +1,15 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x12 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x1 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x17 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x4 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x10 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x7 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x13 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x12 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x1 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x17 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x4 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x10 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x7 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x13 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] x1 = {x2: (Char) => val x3 = x2 == 'A' val x18 = if (x3) { @@ -19,8 +19,15 @@ x12 } x18 } -x12 = scala.lms.epfl.test4.Automaton(List(),x1) -x13 = x12.copy(out = "found"::x12.out) +x4 = {x5: (Char) => +val x6 = x5 == 'A' +val x16 = if (x6) { +x10 +} else { +x12 +} +x16 +} x7 = {x8: (Char) => val x9 = x8 == 'A' val x15 = if (x9) { @@ -36,24 +43,16 @@ x14 } x15 } -x10 = scala.lms.epfl.test4.Automaton(List(),x7) -x4 = {x5: (Char) => -val x6 = x5 == 'A' -val x16 = if (x6) { -x10 -} else { -x12 -} -x16 -} -x17 = scala.lms.epfl.test4.Automaton(List(),x4) +x10 = scala.virtualization.lms.epfl.test4.Automaton(List(),x7) +x12 = scala.virtualization.lms.epfl.test4.Automaton(List(),x1) +x13 = x12.copy(out = "found"::x12.out) +x17 = scala.virtualization.lms.epfl.test4.Automaton(List(),x4) x12 } } /***************************************** End of Generated Code *******************************************/ -compilation: ok idx: 0 out: List() char: X diff --git a/test-out/epfl/test4-matchernew2.check b/test-out/epfl/test4-matchernew2.check index d3f86295..b5c1e2d9 100644 --- a/test-out/epfl/test4-matchernew2.check +++ b/test-out/epfl/test4-matchernew2.check @@ -1,21 +1,21 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x23 = null.asInstanceOf[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] -var x22 = null.asInstanceOf[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] -var x20 = null.asInstanceOf[scala.Function1[Char, scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]]] -var x24 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x23 = null.asInstanceOf[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] +var x22 = null.asInstanceOf[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] +var x20 = null.asInstanceOf[scala.Function1[Char, scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]]] +var x24 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]], scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x20 = {x21: (Char) => x23 } -x22 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x20)) +x22 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x20)) val x12 = List() val x10 = {x11: (Char) => x12 } -val x13 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(1),x10)) +val x13 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(1),x10)) val x7 = {x8: (Char) => val x9 = x8 == 'B' val x14 = if (x9) { @@ -25,7 +25,7 @@ x12 } x14 } -val x15 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x7)) +val x15 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x7)) val x1 = {x2: (Char) => val x3 = x2 == 'A' val x18 = if (x3) { @@ -38,23 +38,23 @@ x12 } x16 } -val x17 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x4)) +val x17 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x4)) x17 } else { x12 } x18 } -val x19 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x1)) +val x19 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x1)) x23 = x19 ::: x22 -x24 = {x25: (scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]) => +x24 = {x25: (scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]) => val x26 = x25.flatMap(_.out) val x27 = {x28: (Char) => val x29 = x25.flatMap(_.next.apply(x28)) val x30 = x24(x29) x30 } -val x31 = scala.lms.epfl.test4.Automaton(x26,x27) +val x31 = scala.virtualization.lms.epfl.test4.Automaton(x26,x27) x31 } val x32 = x24(x23) @@ -64,7 +64,6 @@ x32 /***************************************** End of Generated Code *******************************************/ -compilation: ok idx: 0 out: List() char: X diff --git a/test-out/epfl/test4-matchernew2b.check b/test-out/epfl/test4-matchernew2b.check index 74c9198c..709f0c79 100644 --- a/test-out/epfl/test4-matchernew2b.check +++ b/test-out/epfl/test4-matchernew2b.check @@ -1,21 +1,21 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x23 = null.asInstanceOf[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] -var x22 = null.asInstanceOf[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] -var x20 = null.asInstanceOf[scala.Function1[Char, scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]]] -var x24 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x23 = null.asInstanceOf[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] +var x22 = null.asInstanceOf[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] +var x20 = null.asInstanceOf[scala.Function1[Char, scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]]] +var x24 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]], scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x20 = {x21: (Char) => x23 } -x22 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x20)) +x22 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x20)) val x12 = List() val x10 = {x11: (Char) => x12 } -val x13 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(1),x10)) +val x13 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(1),x10)) val x7 = {x8: (Char) => val x9 = x8 == 'B' val x14 = if (x9) { @@ -25,7 +25,7 @@ x12 } x14 } -val x15 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x7)) +val x15 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x7)) val x1 = {x2: (Char) => val x3 = x2 == 'A' val x18 = if (x3) { @@ -38,23 +38,23 @@ x12 } x16 } -val x17 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x4)) +val x17 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x4)) x17 } else { x12 } x18 } -val x19 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x1)) +val x19 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x1)) x23 = x22 ::: x19 -x24 = {x25: (scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]) => +x24 = {x25: (scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]) => val x26 = x25.flatMap(_.out) val x27 = {x28: (Char) => val x29 = x25.flatMap(_.next.apply(x28)) val x30 = x24(x29) x30 } -val x31 = scala.lms.epfl.test4.Automaton(x26,x27) +val x31 = scala.virtualization.lms.epfl.test4.Automaton(x26,x27) x31 } val x32 = x24(x23) @@ -64,7 +64,6 @@ x32 /***************************************** End of Generated Code *******************************************/ -compilation: ok idx: 0 out: List() char: X diff --git a/test-out/epfl/test4-stream1.check b/test-out/epfl/test4-stream1.check index 329e918d..d009dc79 100644 --- a/test-out/epfl/test4-stream1.check +++ b/test-out/epfl/test4-stream1.check @@ -1,12 +1,12 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { var x1 = null.asInstanceOf[scala.Function1[Double, Double]] var x33 = null.asInstanceOf[scala.Function1[Double, Double]] -var x19 = null.asInstanceOf[scala.Function1[Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble, Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble]] -var x12 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[Tuple2DoubleDouble], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x19 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.Tuple2[Double, Double], scala.collection.immutable.List[scala.Tuple2[Double, Double]]], scala.Tuple2[scala.Tuple2[Double, Double], scala.collection.immutable.List[scala.Tuple2[Double, Double]]]]] +var x12 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.Tuple2[Double, Double]], scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x1 = {x2: (Double) => val x4 = x2%2 == 0 val x5 = if (x4) { @@ -24,6 +24,8 @@ x2 } x8 } +val x9 = x1(0.0) +val x10 = (0.0,x9) x33 = {x34: (Double) => val x36 = x34%2 == 0 val x37 = if (x36) { @@ -41,7 +43,7 @@ x34 } x40 } -x19 = {x20: (Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble) => +x19 = {x20: (scala.Tuple2[scala.Tuple2[Double, Double], scala.collection.immutable.List[scala.Tuple2[Double, Double]]]) => val x21 = x20._1 val x23 = x21._1 val x25 = x23 < 8.0 @@ -68,12 +70,12 @@ val x31 = x23+1.0 val x24 = x21._2 val x32 = x24+1.0 val x41 = x33(x32) -val x42 = new Tuple2DoubleDouble(x31,x41) +val x42 = (x31,x41) val x22 = x20._2 -val x43 = new Tuple2DoubleDouble(x23,x24) +val x43 = (x23,x24) val x44 = List(x43) val x45 = x22 ::: x44 -val x46 = new Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble(x42,x45) +val x46 = (x42,x45) val x47 = x19(x46) x47 } else { @@ -81,19 +83,17 @@ x20 } x48 } -val x9 = x1(0.0) -val x10 = new Tuple2DoubleDouble(0.0,x9) -x12 = {x13: (scala.collection.immutable.List[Tuple2DoubleDouble]) => +x12 = {x13: (scala.collection.immutable.List[scala.Tuple2[Double, Double]]) => val x14 = List(x13) val x15 = {x16: (Char) => val x17 = x13 // x16 -val x18 = new Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble(x10,x17) +val x18 = (x10,x17) val x49 = x19(x18) val x51 = x49._2 val x52 = x12(x51) x52 } -val x53 = scala.lms.epfl.test4.Automaton(x14,x15) +val x53 = scala.virtualization.lms.epfl.test4.Automaton(x14,x15) x53 } val x11 = List() @@ -104,52 +104,47 @@ x54 /***************************************** End of Generated Code *******************************************/ - -case class Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble(_1: Tuple2DoubleDouble, _2: scala.collection.immutable.List[Tuple2DoubleDouble]) - -case class Tuple2DoubleDouble(_1: Double, _2: Double) -compilation: ok idx: 0 out: List(List()) char: X idx: 1 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: A idx: 2 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: B idx: 3 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: Z idx: 4 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: A idx: 5 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: A idx: 6 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: B idx: 7 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: W idx: 8 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: A idx: 9 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: A idx: 10 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: A idx: 11 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: A idx: 12 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: B idx: 13 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) char: Q idx: 14 -out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) +out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) diff --git a/test-out/epfl/test5-conditional.check b/test-out/epfl/test5-conditional.check index cf408c71..5c04ffab 100644 --- a/test-out/epfl/test5-conditional.check +++ b/test-out/epfl/test5-conditional.check @@ -4,20 +4,20 @@ *******************************************/ class Test extends ((Double)=>(Double)) { def apply(x0:Double): Double = { -val x1 = println("yoyo") +println("yoyo") val x2 = x0 == x0 val x6 = x0+4.0 val x9 = if (x2) { -val x3 = println("yoyo") -val x4 = println("xxx") -val x5 = println("yoyo") +println("yoyo") +println("xxx") +println("yoyo") x6 } else { val x8 = x0+6.0 x8 } -val x10 = println("yyy") -val x11 = println("yoyo") +println("yyy") +println("yoyo") val x12 = x9+x6 x12 } @@ -25,7 +25,6 @@ x12 /***************************************** End of Generated Code *******************************************/ -compilation: ok yoyo yoyo xxx @@ -34,21 +33,21 @@ yyy yoyo 22.0 function main(x0) { -var x1 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) +document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) var x2 = x0==x0 var x6 = x0+4.0 var x9 if (x2) { -var x3 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) -var x4 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("xxx")) -var x5 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) +document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) +document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("xxx")) +document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) x9=x6 } else { var x8 = x0+6.0 x9=x8 } -var x10 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yyy")) -var x11 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) +document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yyy")) +document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) var x12 = x9+x6 return x12 } diff --git a/test-out/epfl/test5-conditional.html.check b/test-out/epfl/test5-conditional.html.check index 85435a0f..2dac1b60 100644 --- a/test-out/epfl/test5-conditional.html.check +++ b/test-out/epfl/test5-conditional.html.check @@ -1,18 +1,18 @@ Scala2JS") - stream.println("") - stream.flush - } - - def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], methName: String, out: PrintWriter) = { - withStream(out) { - stream.println("function "+methName+"("+args.map(quote).mkString(", ")+") {") - - emitBlock(body) - stream.println("return "+quote(getBlockResult(body))) - - stream.println("}") - } - Nil - } - def emitValDef(sym: Sym[Any], rhs: String): Unit = { - stream.println("var " + quote(sym) + " = " + rhs) - } -} - -trait JSNestedCodegen extends GenericNestedCodegen with JSCodegen { - import IR._ - -} - -trait JSGenBase extends JSCodegen { - val IR: BaseExp -} - -trait JSGenEffect extends JSNestedCodegen with JSGenBase { - val IR: EffectExp -} - - -trait JSGenIfThenElse extends BaseGenIfThenElse with JSGenEffect { // it's more or less generic... - val IR: IfThenElseExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case IfThenElse(c,a,b) => - stream.println("var " + quote(sym)) - stream.println("if (" + quote(c) + ") {") - emitBlock(a) - stream.println(quote(sym) + "=" + quote(getBlockResult(a))) - stream.println("} else {") - emitBlock(b) - stream.println(quote(sym) + "=" + quote(getBlockResult(b))) - stream.println("}") - case _ => super.emitNode(sym, rhs) - } -} - -trait JSGenArith extends JSGenBase { // TODO: define a generic one - val IR: ArithExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Plus(a,b) => emitValDef(sym, "" + quote(a) + "+" + quote(b)) - case Minus(a,b) => emitValDef(sym, "" + quote(a) + "-" + quote(b)) - case Times(a,b) => emitValDef(sym, "" + quote(a) + "*" + quote(b)) - case Div(a,b) => emitValDef(sym, "" + quote(a) + "/" + quote(b)) - case _ => super.emitNode(sym, rhs) - } -} diff --git a/test-src/epfl/test5-js/TestConditional.scala b/test-src/epfl/test5-js/TestConditional.scala deleted file mode 100644 index 7eb3a935..00000000 --- a/test-src/epfl/test5-js/TestConditional.scala +++ /dev/null @@ -1,130 +0,0 @@ -package scala.lms -package epfl -package test5 - -import common._ -import test1._ - -import java.io.PrintWriter -import java.io.FileOutputStream - -trait JSGenEqual extends JSGenBase { - val IR: EqualExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Equal(a,b) => emitValDef(sym, "" + quote(a) + "==" + quote(b)) - case _ => super.emitNode(sym, rhs) - } -} - - - -trait Print extends Base { - implicit def unit(s: String): Rep[String] - def print(s: Rep[Any]): Rep[Unit] -} - -trait PrintExp extends Print with EffectExp { - implicit def unit(s: String): Rep[String] = Const(s) - case class Print(s: Rep[Any]) extends Def[Unit] - def print(s: Rep[Any]) = reflectEffect(Print(s)) -} - -trait ScalaGenPrint extends ScalaGenEffect { - val IR: PrintExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Print(s) => emitValDef(sym, "println(" + quote(s) + ")") - case _ => super.emitNode(sym, rhs) - } -} - -trait JSGenPrint extends JSGenEffect { - val IR: PrintExp - import IR._ - - // TODO: should have a function for this - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Print(s) => emitValDef(sym, "document.body.appendChild(document.createElement(\"div\"))"+ - ".appendChild(document.createTextNode("+quote(s)+"))") - case _ => super.emitNode(sym, rhs) - } -} - - - -trait Dom extends Base { - // not used yet... - type DOMObjectInternal - type DOMObject = Rep[DOMObjectInternal] - def document: DOMObject - def infix_getElementById(s: Rep[String]) -} - - - - - -trait ConditionalProg { this: Arith with Equal with Print with IfThenElse => - - def test(x: Rep[Double]): Rep[Double] = { - - print("yoyo") - - val z = if (x == x) { - print("yoyo") - print("xxx") - print("yoyo") - (x+4) - } else { - (x+6) - } - - print("yyy") - print("yoyo") - - z + (x + 4) - } - -} - - - -class TestConditional extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test5-" - - def testConditional = { - withOutFile(prefix+"conditional") { - - println("-- begin") - - new ConditionalProg with ArithExpOpt with EqualExp with PrintExp - with IfThenElseExp with CompileScala { self => - val codegen = new ScalaGenIfThenElse with ScalaGenArith - with ScalaGenEqual with ScalaGenPrint { val IR: self.type = self } - - val f = (x: Rep[Double]) => test(x) - codegen.emitSource(f, "Test", new PrintWriter(System.out)) - val g = compile(f) - println(g(7)) - } - - new ConditionalProg with IfThenElseExp with ArithExpOpt with EqualExp - with PrintExp { self => - val codegen = new JSGenIfThenElse with JSGenArith - with JSGenEqual with JSGenPrint { val IR: self.type = self } - - val f = (x: Rep[Double]) => test(x) - codegen.emitSource(f, "main", new PrintWriter(System.out)) - codegen.emitHTMLPage(() => f(7), new PrintWriter(new FileOutputStream(prefix+"conditional.html"))) - } - - println("-- end") - } - assertFileEqualsCheck(prefix+"conditional") - assertFileEqualsCheck(prefix+"conditional.html") - } -} diff --git a/test-src/epfl/test5-js/TestFunctions.scala b/test-src/epfl/test5-js/TestFunctions.scala deleted file mode 100644 index 1e992132..00000000 --- a/test-src/epfl/test5-js/TestFunctions.scala +++ /dev/null @@ -1,297 +0,0 @@ -package scala.lms -package epfl -package test5 - -import common._ -import test1._ - -import java.io.PrintWriter -import java.io.FileOutputStream - -trait JSGenFunctions extends JSGenEffect with BaseGenFunctions { - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Lambda(fun, x, y) => - stream.println("var " + quote(sym) + " = function(" + quote(x) + ") {") - emitBlock(y) - stream.println("return " + quote(getBlockResult(y))) - stream.println("}") - - case Apply(fun, arg) => - emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") - - case _ => super.emitNode(sym, rhs) - } -} - -trait JSGenTupledFunctions extends JSGenFunctions { - val IR: TupledFunctionsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Lambda(fun, UnboxedTuple(xs), y) => - stream.println("var " + quote(sym) + " = function" + xs.map(quote).mkString("(", ",", ")") + " {") - emitBlock(y) - stream.println("return " + quote(getBlockResult(y))) - stream.println("}") - - case Apply(fun, UnboxedTuple(args)) => - emitValDef(sym, quote(fun) + args.map(quote).mkString("(", ",", ")")) - - case _ => super.emitNode(sym, rhs) - } - - override def quote(x: Exp[Any]) : String = x match { - case UnboxedTuple(t) => - t.zipWithIndex.map({ case(el, i) => "_" + (i+1) + ":" + quote(el)}).mkString("{", ",", "}") - case _ => super.quote(x) - } -} - -trait JSGenStruct extends JSGenBase { - val IR: StructExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Struct(tag, elems) => - registerStruct(structName(sym.tp), elems) - emitValDef(sym, "{__structName:" + structName(sym.tp) + "," + elems.map(e => e._1+":"+quote(e._2)).mkString(",") + "}") -// printlog("WARNING: emitting " + structName(sym.tp) + " struct " + quote(sym)) - case FieldApply(struct, index) => - emitValDef(sym, quote(struct) + "." + index) -// printlog("WARNING: emitting field access: " + quote(struct) + "." + index) - case FieldUpdate(struct, index, rhs) => - emitValDef(sym, quote(struct) + "." + index + " = " + quote(rhs)) -// printlog("WARNING: emitting field update: " + quote(struct) + "." + index) - case _ => super.emitNode(sym, rhs) - } -} - -trait JSGenTupleOps extends JSGenBase with JSGenStruct { - val IR: TupleOpsExp - import IR._ - -/* FIXME: now using structs to implement tuples - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ETuple2(a,b) => - emitValDef(sym, "{_1:"+ quote(a) + ",_2:" + quote(b) + "}") - case Tuple2Access1(t) => emitValDef(sym, quote(t) + "._1") - case Tuple2Access2(t) => emitValDef(sym, quote(t) + "._2") - - case _ => super.emitNode(sym, rhs) - } -*/ -} - -trait FunctionsProg { this: Print with Functions with IfThenElse with Equal => - def test(x: Rep[Any]): Rep[Any] = { - val f = fun { x : Rep[Any] => - print("foo") - x - } - f(f(x)) - } - - def test2(x: Rep[Double]): Rep[Double => Double] = - fun {(y: Rep[Double]) => if(y == x) unit(2 : Double) else y} -} - -trait FunctionsRecursiveProg { this: Arith with Print with Functions => - def test(x: Rep[Any]): Rep[Any] = { - val f = fun { x : Rep[Any] => - print("foo") - x - } - lazy val g : Rep[Any => Any] = fun { x => - print("bar") - g(x) - } - val h = fun { x : Rep[Any] => - print("baz") - 1 - } - h(g(f(f(x)))) - } -} - -trait TwoArgsFunProg { this: TupledFunctions => - def test(x: Rep[Double]): Rep[(Double, Double)] = { - val f = fun { (a : Rep[Double], b : Rep[Double]) => (b,a) } - f(f(x, x)) - } -} - -trait TupleFunProg { this: Arith with TupledFunctions => - def test (x: Rep[Double]): Rep[(Double, Double)] = { - val f = fun { t : Rep[(Double, Double)] => t } - f(1.0, x) - } -} - -trait NoArgFunProg { this: TupledFunctions => - def test (x: Rep[Any]): Rep[Any] = { - val f = fun { () => x } - f() - } -} - -trait TwoArgsRecursiveFunProg { this: TupledFunctions with Arith with Equal with IfThenElse => - def test(x: Rep[Double]): Rep[Double] = { - lazy val iter : Rep[((Double,Double)) => Double] = fun { (n, acc) => - if (n == 0) acc else iter(n-1, n*acc) - } - iter(x, unit(1.0)) - } -} - -trait SchedFunProg { this: Functions with Arith with Equal with IfThenElse => - def foo: Rep[Double => Double] = fun { a => - def iter : Rep[Double => Double] = fun { b => - if (b == 0) a - else iter(b-1) - } - iter(a) - } - - def test(x: Rep[Double]): Rep[Double] = { - foo(x) - } -} - -class TestFunctions extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test5-" - - def testFunctions = { - withOutFile(prefix+"functions") { - - println("-- begin") - - new FunctionsProg with PrintExp with FunctionsExp with IfThenElseExp with EqualExp{ self => - val codegen = new ScalaGenPrint with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenEqual{ val IR: self.type = self } - - val f = (x: Rep[Double]) => test(x) - codegen.emitSource(f, "Test", new PrintWriter(System.out)) - - val g = (x: Rep[Double]) => test2(x) - codegen.emitSource(g, "Test2", new PrintWriter(System.out)) - } - - new FunctionsProg with PrintExp with FunctionsExp with IfThenElseExp with EqualExp{ self => - val codegen = new JSGenPrint with JSGenFunctions with JSGenIfThenElse with JSGenEqual{ val IR: self.type = self } - - val f = (x: Rep[Double]) => test(x) - codegen.emitSource(f, "main", new PrintWriter(System.out)) - - val g = (x: Rep[Double]) => test2(x) - codegen.emitSource(g, "main2", new PrintWriter(System.out)) - } - - println("-- end") - } - assertFileEqualsCheck(prefix+"functions") - } - - def testFunRetFun = { - withOutFile(prefix+"funretfun") { - - println("-- begin") - - new FunctionsProg with PrintExp with FunctionsExp with IfThenElseExp with EqualExp{ self => - val codegen = new ScalaGenPrint with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenEqual{ - val IR: self.type = self - } - - val f = (x: Rep[Double]) => doLambda{(y: Rep[Int]) => test(x)} - codegen.emitSource(f, "Test", new PrintWriter(System.out)) - } - - new FunctionsProg with PrintExp with FunctionsExp with IfThenElseExp with EqualExp{ self => - val codegen = new JSGenPrint with JSGenFunctions with JSGenIfThenElse with JSGenEqual{ val IR: self.type = self } - - val f = (x: Rep[Double]) => doLambda{(y: Rep[Int]) => test(x)} - codegen.emitSource(f, "main", new PrintWriter(System.out)) - } - - println("-- end") - } - assertFileEqualsCheck(prefix+"funretfun") - } - - def testFunctionsRecursive = { - withOutFile(prefix+"functionsrecursive") { - - println("-- begin") - - new FunctionsRecursiveProg with ArithExpOpt with PrintExp with FunctionsRecursiveExp { self => - val codegen = new ScalaGenArith with ScalaGenPrint with ScalaGenFunctions { val IR: self.type = self } - - val f = (x: Rep[Double]) => test(x) - codegen.emitSource(f, "Test", new PrintWriter(System.out)) - } - - new FunctionsRecursiveProg with ArithExpOpt with PrintExp with FunctionsRecursiveExp { self => - val codegen = new JSGenArith with JSGenPrint with JSGenFunctions { val IR: self.type = self } - - val f = (x: Rep[Double]) => test(x) - codegen.emitSource(f, "main", new PrintWriter(System.out)) - } - - println("-- end") - } - assertFileEqualsCheck(prefix+"functionsrecursive") - } - - def testTwoArgsFun = { - withOutFile(prefix+"twoargsfun") { - new TwoArgsFunProg with TupledFunctionsExp { self => - val codegen = new JSGenTupledFunctions with JSGenTupleOps with GenericGenUnboxedTupleAccess { val IR: self.type = self } - codegen.emitSource(test _, "main", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"twoargsfun") - } - - def testTupleFun = { - withOutFile(prefix+"tuplefun") { - new TupleFunProg with ArithExp with TupledFunctionsExp { self => - val codegen = new JSGenTupledFunctions with JSGenTupleOps with GenericGenUnboxedTupleAccess { val IR: self.type = self } - codegen.emitSource(test _, "main", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"tuplefun") - } - - def testNoArgFun = { - withOutFile(prefix+"noargfun") { - new NoArgFunProg with TupledFunctionsRecursiveExp { self => - val codegen = new JSGenTupledFunctions with JSGenTupleOps with GenericGenUnboxedTupleAccess { val IR: self.type = self } - codegen.emitSource(test _, "main", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"noargfun") - } - - def testTwoArgsRecursiveFun = { - withOutFile(prefix+"twoargsrecfun") { - new TwoArgsRecursiveFunProg with TupledFunctionsRecursiveExp with ArithExpOpt with EqualExp with IfThenElseExp { self => - val codegen = new JSGenTupledFunctions with JSGenArith with JSGenEqual with JSGenIfThenElse with JSGenTupleOps with GenericGenUnboxedTupleAccess { val IR: self.type = self } - codegen.emitSource(test _, "main", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"twoargsrecfun") - } - - def testSchedFun = { - withOutFile(prefix+"schedfun") { - new SchedFunProg with FunctionsRecursiveExp with ArithExpOpt with EqualExp with IfThenElseExp { self => - val codegen = new JSGenFunctions with JSGenArith with JSGenEqual with JSGenIfThenElse { val IR: self.type = self } - val f = (x: Rep[Double]) => test(x) - codegen.emitSource(f, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"schedfun") - } - -} diff --git a/test-src/epfl/test6-layered/Test.scala b/test-src/epfl/test6-layered/Test.scala deleted file mode 100644 index 26a9654e..00000000 --- a/test-src/epfl/test6-layered/Test.scala +++ /dev/null @@ -1,239 +0,0 @@ -package scala.lms -package epfl -package test6 - -import common._ -import test1._ - -import util.OverloadHack - -import java.io.PrintWriter -import java.io.FileOutputStream - - -trait Utils extends Base with OverloadHack { - - def infix_+(a: Rep[String], b: Rep[Any])(implicit x: Overloaded1): Rep[String] - def infix_+(a: Rep[Any], b: Rep[String])(implicit x: Overloaded2): Rep[String] - def infix_+(a: String, b: Rep[Any])(implicit x: Overloaded4): Rep[String] - def infix_+(a: Rep[Any], b: String)(implicit x: Overloaded5): Rep[String] - - implicit def unit(x:String): Rep[String] - implicit def unit(x:Int): Rep[Int] - -} - - -trait UtilExp extends BaseExp with Utils { - - implicit def unit(x:Int): Rep[Int] = Const(x) - implicit def unit(x:String): Rep[String] = Const(x) - - def infix_+(a: Rep[String], b: Rep[Any])(implicit x: Overloaded1): Rep[String] = StrCat(a,b) - def infix_+(a: Rep[Any], b: Rep[String])(implicit x: Overloaded2): Rep[String] = StrCat(a,b) - def infix_+(a: String, b: Rep[Any])(implicit x: Overloaded4): Rep[String] = StrCat(Const(a),b) - def infix_+(a: Rep[Any], b: String)(implicit x: Overloaded5): Rep[String] = StrCat(a,Const(b)) - - case class StrCat(a: Exp[Any],b: Exp[Any]) extends Def[String] - - case class Tup[A,B](a: Exp[A],b: Exp[B]) extends Def[(A,B)] - - case class External[A:Manifest](s: String, fmt_args: List[Exp[Any]] = List()) extends Exp[A] - -} - -trait ScalaGenUtil extends ScalaGenBase { - val IR: UtilExp - import IR._ - - // case External(s: String, args: List[Exp[Any]]) => s.format(args map (quote(_)) : _*) - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case StrCat(a,b) => - emitValDef(sym, quote(a) + ".toString + " + quote(b) + ".toString") - case Tup(a,b) => - emitValDef(sym, "("+ quote(a) + "," + quote(b) + ")") - case _ => super.emitNode(sym, rhs) - } - - override def quote(x: Exp[Any]) = x match { - case External(s: String, args: List[Exp[Any]]) => s.format(args map (quote(_)) : _*) - case _ => super.quote(x) - } - - -} - -trait Vectors extends Utils { - - type Vector - implicit def mV: Manifest[Vector] - - def ZeroVector(n: Rep[Int]): Rep[Vector] - def RandomVector(n: Rep[Int]): Rep[Vector] - def infix_+(a: Rep[Vector], b: Rep[Vector])(implicit x: Overloaded3): Rep[Vector] -} - -trait VectorsExp extends Vectors with BaseExp { this: VectorsImpl => - - // use Apply directly (instead of doApply) to signal that operations are pure - - def ZeroVector(n: Exp[Int]) = Apply(vectorZero, n) - def RandomVector(n: Exp[Int]) = doApply(vectorRandom, n) // random vectors are different... - - def infix_+(a: Exp[Vector], b: Exp[Vector])(implicit x: Overloaded3) = (a,b) match { - case (Def(ZeroVector(_)), b) => b - case (a, Def(ZeroVector(_))) => a - case _ => Apply(vectorPlus, toAtom(Tup(a, b))) - } - - class ApplyExtractor[A:Manifest,B:Manifest](f: Exp[A => B]) { - def apply(x: Exp[A]): Exp[B] = Apply(f,x) - def unapply(e: Def[B]): Option[Exp[A]] = e match { - case Apply(`f`, x: Exp[A]) => Some(x) - case _ => None - } - } - - object ZeroVector extends ApplyExtractor[Int,Vector](vectorZero) - -/* - object ZeroVector { - def unapply(e: Def[Vector]): Option[Exp[Int]] = e match { - case Apply(`vectorZero`, n: Exp[Int]) => Some(n) - case _ => - None - } - } -*/ - -} - - -trait VectorsImpl extends Vectors with FunctionsExp with UtilExp { - - val vectorZero: Exp[Int => Vector] - val vectorRandom: Exp[Int => Vector] - val vectorPlus: Exp[((Vector,Vector)) => Vector] - -} - - -trait VectorsImplExternal extends VectorsImpl { - - type Vector = Array[Double] - def mV = manifest[Array[Double]] - - val base = "scala.lms.epfl.test6.VectorOps.%s" - - // FIXME: using base + "zero" crashes the compiler! - - val vectorZero = External[Int => Vector](base format "zero") - val vectorRandom = External[Int => Vector](base format "random") - val vectorPlus = External[((Vector,Vector)) => Vector](base format "plus") - -} - -object VectorOps { - - def zero(n: Int) = new Array[Double](n) - def random(n: Int) = new Array[Double](n) - def plus(p: (Array[Double], Array[Double])) = p._1 - -} - - - -// possible future alternatives: - -trait VectorsImplConst extends VectorsImpl { - - type Vector = Array[Double] - def mV = manifest[Array[Double]] - - // kernels implementations as function-type constants - - val vectorZero = Const((n:Int) => new Array[Double](n)) - val vectorRandom = Const((n:Int) => new Array[Double](n)) // fill with random data... - val vectorPlus = Const((p:(Vector,Vector)) => p._1) // actually do the addition - -} - - -/* - -trait VectorImplInternal extends VectorImpl { - - trait Vector - - // kernels implemented as staged coded within lambdas - - val vectorZero = doLambda { x:Rep[Int] => ... } - val vectorRandom = doLambda { x:Rep[Int] => ... } - val vectorPlus = doLambda { x:Rep[(Vector,Vector)] => ... } - -} - -*/ - - -trait VectorsProg extends Vectors { - - def test(x: Rep[Unit]): Rep[Vector] = { - RandomVector(7) + (ZeroVector(7) + RandomVector(7)) - } - -} - -trait StringsProg extends Vectors { - - def test(x: Rep[Any]) = { - val s: Rep[Any] = "hi " + "yo " + x + " done" - s - } - -} - - - -class TestVectors extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test6-" - - def testVectors = { - withOutFile(prefix+"vectors") { - - println("-- begin") - - new VectorsProg with VectorsExp with VectorsImplExternal - with CompileScala { self => - val codegen = new ScalaGenFunctions with ScalaGenUtil { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - val g = compile(test) - println(g().mkString(",")) - } - - new StringsProg with VectorsExp with VectorsImplExternal - with CompileScala { self => - val codegen = new ScalaGenFunctions with ScalaGenUtil { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - val g = compile(test) - println(g(0)) - } - /* - new TestConditional with ArithExpOpt with EqualExp with PrintExp - with JSGenIfThenElse - with JSGenArith with JSGenEqual with JSGenPrint - { - val f = (x: Rep[Double]) => test(x) - emitJSSource(f, "main", new PrintWriter(System.out)) - emitHTMLPage(() => f(7), new PrintWriter(new FileOutputStream("test5.html"))) - } - - */ - println("-- end") - } - assertFileEqualsCheck(prefix+"vectors") - - } -} diff --git a/test-src/epfl/test7-analysis/Arrays.scala b/test-src/epfl/test7-analysis/Arrays.scala deleted file mode 100644 index 8f680cd8..00000000 --- a/test-src/epfl/test7-analysis/Arrays.scala +++ /dev/null @@ -1,232 +0,0 @@ -package scala.lms -package epfl -package test7 - -import common._ -import test1._ - -import internal.AbstractSubstTransformer - - -import util.OverloadHack -import scala.reflect.SourceContext -import java.io.{PrintWriter,StringWriter,FileOutputStream} - - - -trait ArrayLoops extends Loops with OverloadHack { - def array[T:Manifest](shape: Rep[Int])(f: Rep[Int] => Rep[T]): Rep[Array[T]] - def sum(shape: Rep[Int])(f: Rep[Int] => Rep[Double]): Rep[Double] // TODO: make reduce operation configurable! - def arrayIf[T:Manifest](shape: Rep[Int])(f: Rep[Int] => (Rep[Boolean],Rep[T])): Rep[Array[T]] - def sumIf(shape: Rep[Int])(f: Rep[Int] => (Rep[Boolean],Rep[Double])): Rep[Double] // TODO: make reduce operation configurable! - def flatten[T:Manifest](shape: Rep[Int])(f: Rep[Int] => Rep[Array[T]]): Rep[Array[T]] - - def infix_at[T:Manifest](a: Rep[Array[T]], i: Rep[Int]): Rep[T] - def infix_length[T:Manifest](a: Rep[Array[T]]): Rep[Int] -} - - -trait ArrayLoopsExp extends LoopsExp { - - case class ArrayElem[T](y: Block[T]) extends Def[Array[T]] - case class ReduceElem(y: Block[Double]) extends Def[Double] - - case class ArrayIfElem[T](c: Exp[Boolean], y: Block[T]) extends Def[Array[T]] - case class ReduceIfElem(c: Exp[Boolean], y: Block[Double]) extends Def[Double] - - case class FlattenElem[T](y: Block[Array[T]]) extends Def[Array[T]] - - case class ArrayIndex[T](a: Rep[Array[T]], i: Rep[Int]) extends Def[T] - case class ArrayLength[T](a: Rep[Array[T]]) extends Def[Int] - - def array[T:Manifest](shape: Rep[Int])(f: Rep[Int] => Rep[T]): Rep[Array[T]] = { - val x = fresh[Int] - val y = reifyEffects(f(x)) - simpleLoop(shape, x, ArrayElem(y)) - } - - def sum(shape: Rep[Int])(f: Rep[Int] => Rep[Double]): Rep[Double] = { - val x = fresh[Int] - val y = reifyEffects(f(x)) - simpleLoop(shape, x, ReduceElem(y)) - } - - def arrayIf[T:Manifest](shape: Rep[Int])(f: Rep[Int] => (Rep[Boolean],Rep[T])): Rep[Array[T]] = { - val x = fresh[Int] - //val (c,y) = f(x) - var c: Rep[Boolean] = null - val y = reifyEffects { val p = f(x); c = p._1; p._2 } - simpleLoop(shape, x, ArrayIfElem(c,y)) // TODO: simplify for const true/false - } - - def sumIf(shape: Rep[Int])(f: Rep[Int] => (Rep[Boolean],Rep[Double])): Rep[Double] = { - val x = fresh[Int] - //val (c,y) = f(x) - var c: Rep[Boolean] = null - val y = reifyEffects { val p = f(x); c = p._1; p._2 } - simpleLoop(shape, x, ReduceIfElem(c,y)) // TODO: simplify for const true/false - } - - def flatten[T:Manifest](shape: Rep[Int])(f: Rep[Int] => Rep[Array[T]]): Rep[Array[T]] = { - val x = fresh[Int] - val y = reifyEffects(f(x)) - simpleLoop(shape, x, FlattenElem(y)) - } - - - def infix_at[T:Manifest](a: Rep[Array[T]], i: Rep[Int]): Rep[T] = ArrayIndex(a, i) - - def infix_length[T:Manifest](a: Rep[Array[T]]): Rep[Int] = a match { - case Def(SimpleLoop(s, x, ArrayElem(y))) => s - case _ => ArrayLength(a) - } - - - override def boundSyms(e: Any): List[Sym[Any]] = e match { - case ArrayElem(y) => effectSyms(y) - case ReduceElem(y) => effectSyms(y) - case FlattenElem(y) => effectSyms(y) - case _ => super.boundSyms(e) - } - - - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case SimpleLoop(s,i, ArrayElem(y)) if f.hasContext => - array(f(s)) { j => f.asInstanceOf[AbstractSubstTransformer{val IR:ArrayLoopsExp.this.type}].withSubstScope(i -> j) { f.reflectBlock(y) } } - case ArrayIndex(a,i) => infix_at(f(a), f(i))(mtype(manifest[A])) - case ArrayLength(a) => infix_length(f(a))(mtype(manifest[A])) - case _ => super.mirror(e,f) - }).asInstanceOf[Exp[A]] - - override def mirrorFatDef[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Def[A] = (e match { - case ArrayElem(y) => ArrayElem(f(y)) - case ReduceElem(y) => ReduceElem(f(y)) - case ArrayIfElem(c,y) => ArrayIfElem(f(c),f(y)) - case ReduceIfElem(c,y) => ReduceIfElem(f(c),f(y)) - case _ => super.mirrorFatDef(e,f) - }).asInstanceOf[Def[A]] - - -} - -trait ArrayLoopsFatExp extends ArrayLoopsExp with LoopsFatExp - - - - -trait ScalaGenArrayLoops extends ScalaGenLoops { - val IR: ArrayLoopsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case SimpleLoop(s,x,ArrayElem(y)) => - stream.println("val " + quote(sym) + " = LoopArray("+quote(s)+") { " + quote(x) + " => ") - emitBlock(y) - stream.println(quote(getBlockResult(y))) - stream.println("}") - case SimpleLoop(s,x,ReduceElem(y)) => - stream.println("val " + quote(sym) + " = LoopReduce("+quote(s)+") { " + quote(x) + " => ") - emitBlock(y) - stream.println(quote(getBlockResult(y))) - stream.println("}") - // TODO: conditional variants ... - case SimpleLoop(s,x,FlattenElem(y)) => - stream.println("val " + quote(sym) + " = LoopFlatten("+quote(s)+") { " + quote(x) + " => ") - emitBlock(y) - stream.println(quote(getBlockResult(y))) - stream.println("}") - case ArrayIndex(a,i) => - emitValDef(sym, quote(a) + ".apply(" + quote(i) + ")") - case ArrayLength(a) => - emitValDef(sym, quote(a) + ".length") - case _ => super.emitNode(sym, rhs) - } -} - -trait ScalaGenArrayLoopsFat extends ScalaGenArrayLoops with ScalaGenLoopsFat { - val IR: ArrayLoopsFatExp - import IR._ - - override def emitFatNode(sym: List[Sym[Any]], rhs: FatDef) = rhs match { - case SimpleFatLoop(s,x,rhs) => - for ((l,r) <- sym zip rhs) { - r match { - case ArrayElem(y) => - stream.println("var " + quote(l) + " = new Array[" + remap(getBlockResult(y).tp) + "]("+quote(s)+")") - case ReduceElem(y) => - stream.println("var " + quote(l) + ": " + remap(getBlockResult(y).tp) + " = 0") - case ArrayIfElem(c,y) => - stream.println("var " + quote(l) + " = new ArrayBuilder[" + remap(getBlockResult(y).tp) + "]") - case ReduceIfElem(c,y) => - stream.println("var " + quote(l) + ": " + remap(getBlockResult(y).tp) + " = 0") - case FlattenElem(y) => - stream.println("var " + quote(l) + " = new ArrayBuilder[" + remap(getBlockResult(y).tp) + "]") - } - } - val ii = x // was: x(i) -// stream.println("var " + quote(ii) + " = 0") -// stream.println("while ("+quote(ii)+" < "+quote(s)+") {") - stream.println("for ("+quote(ii)+" <- 0 until "+quote(s)+") {") -// for (jj <- x.drop(1)) { -// stream.println(quote(jj)+" = "+quote(ii)) -// } - emitFatBlock(syms(rhs).map(Block(_))) // TODO: check this - for ((l,r) <- sym zip rhs) { - r match { - case ArrayElem(y) => - stream.println(quote(l) + "("+quote(ii)+") = " + quote(getBlockResult(y))) - case ReduceElem(y) => - stream.println(quote(l) + " += " + quote(getBlockResult(y))) - case ArrayIfElem(c,y) => - stream.println("if ("+quote(/*getBlockResult*/(c))+") " + quote(l) + " += " + quote(getBlockResult(y))) - case ReduceIfElem(c,y) => - stream.println("if ("+quote(/*getBlockResult*/(c))+") " + quote(l) + " += " + quote(getBlockResult(y))) - case FlattenElem(y) => - stream.println(quote(l) + " ++= " + quote(getBlockResult(y))) - } - } -// stream.println(quote(ii)+" += 1") - stream.println("}") - case _ => super.emitFatNode(sym, rhs) - } -} - - - - - - - - -trait Arrays extends Base with OverloadHack { - def zeroes(n: Rep[Int]): Rep[Array[Int]] - def infix_update(a: Rep[Array[Int]], x: Rep[Int], v: Rep[Int]): Rep[Array[Int]] - def infix_+(a: Rep[Array[Int]], b: Rep[Array[Int]])(implicit o: Overloaded1): Rep[Array[Int]] -} - -trait ArraysExp extends Arrays with EffectExp { - case class ArrayZero(n: Rep[Int]) extends Def[Array[Int]] - case class ArrayUpdate(a: Rep[Array[Int]], x: Rep[Int], v: Rep[Int]) extends Def[Array[Int]] - case class ArrayPlus(a: Rep[Array[Int]], b: Rep[Array[Int]]) extends Def[Array[Int]] - def zeroes(n: Rep[Int]) = ArrayZero(n) - def infix_update(a: Rep[Array[Int]], x: Rep[Int], v: Rep[Int]) = ArrayUpdate(a,x,v) - def infix_+(a: Rep[Array[Int]], b: Rep[Array[Int]])(implicit o: Overloaded1) = ArrayPlus(a,b) -} - -trait ScalaGenArrays extends ScalaGenEffect { - val IR: ArraysExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ArrayZero(n) => - emitValDef(sym, "new Array[Int](" + quote(n) + ")") - case ArrayUpdate(a,x,v) => - emitValDef(sym, quote(a) +".clone()") - stream.println(quote(sym) + "(" + quote(x) + ") = " + quote(v)) - case ArrayPlus(a,b) => - emitValDef(sym, "new Array[Int](" + quote(a) + ".length)") - stream.println("arrayPlus("+ quote(sym) + "," + quote(a) + "," + quote(b) + ")") - case _ => super.emitNode(sym, rhs) - } -} - diff --git a/test-src/epfl/test7-analysis/TestAnalysis.scala b/test-src/epfl/test7-analysis/TestAnalysis.scala deleted file mode 100644 index 229fa653..00000000 --- a/test-src/epfl/test7-analysis/TestAnalysis.scala +++ /dev/null @@ -1,228 +0,0 @@ -package scala.lms -package epfl -package test7 - -import common._ -import test1._ - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} -import scala.reflect.SourceContext - -trait Print extends Base { - implicit def unit(s: String): Rep[String] - def print(s: Rep[Any]): Rep[Unit] -} - -trait PrintExp extends Print with EffectExp { - implicit def unit(s: String): Rep[String] = Const(s) - case class Print(s: Rep[Any]) extends Def[Unit] - def print(s: Rep[Any]) = reflectEffect(Print(s)) - override def mirrorDef[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Def[A] = (e match { - case Print(s) => Print(f(s)) - case _ => super.mirrorDef(e,f) - }).asInstanceOf[Def[A]] // why?? - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case Reflect(Print(s), u, es) => reflectMirrored(Reflect(Print(f(s)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) - case _ => super.mirror(e,f) - }).asInstanceOf[Exp[A]] // why?? -} - -trait ScalaGenPrint extends ScalaGenEffect { - val IR: PrintExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Print(s) => emitValDef(sym, "println(" + quote(s) + ")") - case _ => super.emitNode(sym, rhs) - } -} - - - -/* - - TODO interesting cases: - - val y = if (c) { - val x = read() - write() - x - } else { - 0 - } - - ------ - - val a = Array.make(100) { i => - i * i - } - - val b = Array.make(100) { j => - val y = j * j - y * j - } - - val c = Array.reduce(100)(+) { k => - val z = a(k) - z * 3 - } - - translate to: (caveat: alpha convert j and k <- howto generalize?) - - step 0) flat schedule (strip dead code) - step 1) find things worthwhile to fuse (CAREFUL ABOUT NESTING!!) - step 2) alpha-convert (does algebraic opts + cse) - step 3) actual codegen - - val i = Reflect(InRange(100)) - val x1 = i * i - val a = Reify(Array.makeElem(x1), i) - val y1 = j * j - val y2 = y1 * j - val b = Array.make(100)(j,y2) - val z1 = a(k) // or: k*k - val z2 = z1 * 3 - val c = Array.reduce(100)(+)(k,z2) - - - - LoopFused(100) { i => - val x1 = i * i - val x2 = x1 * i - val x3 = x1 * 3 - export val a = Array.makeElem(x1) - export val b = Array.makeElem(x2) - export val c = Array.reduceElem(+,x3) - } - - val a,b,c = Array.fused { i => - val x1 = i * i - val x2 = x1 * i - val x3 = x1 * 3 - yieldMake(x1) - yieldMake(x2) - yieldReduce(+)(x1*3) - } - - var a = new Array(100) // might stack alloc, or reuse mem - var b = new Array(100) - var c = 0 - for (i <- 0 until 100) { - val x1 = i * i - val x2 = x1 * i - val x3 = x1 * 3 - a(i) = x1 - b(i) = x2 - c = c + x3 - } - - ------ - - Folding vs. Fusion: - - val a = Array(100) { ia => ia * 3 } - - val b = Array(100) { ib => a(ib) + 3 } // can fold or fuse - - val c = Array(100) { ic => a(ic + 3) } // can fold but not fuse! a(i+3) not available to c(i) - - val ac = Array(100) { iac => iac*3, (iac+3)*3 } // can fold but not fuse! a(i+3) not available to c(i) - val ac = Array(100) { iac => t = iac*3; t,t+9 } // will not be done!!! - - - - ------ - - Folding decisions are similar to inlining decisions. Might duplicate computations - (instead of reusing stored results). If the computations are small this is worthwile (see above), - otherwise not. - - We should be specific about inlining -> should we be specific about folding as well? - - After all, arrays are just cached function results (of partial functions, that is). - More exactly: partitioning of the domain into multiple function results (<- concat). - - -- - - idea: not everything should be hoisted out of loops. an array construction L1 might be - better folded into the loop L2 (removing the need for the intermediate array). however, - if L1 is very costly, it might be better to construct it explicitly. it might even - be worth to extract scalar subexpressions into arrays! - - val a = Array(100) { ia => val xa = gold(ia+1); xa * 4 } - val b = Array(100) { ib => val xb = gold(ib+2); xb * 3 } - - gold(ia) cannot be moved out. assume gold is expensive, so it might be worth doing - - val g = Array(100) { ig => gold(ig) } // g = Array(100)(gold) - val a = Array(100) { ia => val xa = g(ia+1); xa * 4 } // a = g.rotate(-1) *. scatter(100)(4) - val b = Array(100) { ib => val xb = g(ib+2); xb * 3 } // b = g.rotate(-2) *. scatter(100)(3) <- DEFINITELY inline scatter! - - (although we'd really want to fuse all three into one, the +1 and +2 don't allow parallel loop) - - currently we can do CSE only for scalar values. - - -- - - another option is to always array-ify things that depend on i: eta-expand, basically. - need to think some more about this. - - -- - - SAC: - folding: forward subsitute L1 into L2 if that is the only use of L1 - fusion: if data dependency hinders fusion of L1 and L2, forward substitute anyways. - other uses of L1 will be redirected to fused L1', so L1 goes away. - - Question: does that enable fusion of ALL loops with same generators? - "sets of generators .. sufficiently simple or similar to make fusion feasible" - - what about a(i+2) dependency? --> will cause duplicate work, no?? gold(i), gold(i+1) - what about fold(a) dep? not elem-wise access! would duplicate whole loop? - - --> assume for now only a(i) deps trigger forward subst! --> make sure not to pessimize - --> regular folding can also handle other indices, like a(i+j) - - - "fusion of two with-loops may prevent further fusion with a third with-loop" - - -- - - what about: traverse nodes from root (result) breadth first wise, with no interdep - at each level. then do maximal munch. - - not sure. - - -- - - SAC-style fusion: - - 1. try to bring loops closer together (by removing interdependent stuff) - 2. can fuse adjacent loops if L1 not in freevars(L2) - - -- - - Kennedy's line of work: it's probably not worth (much) fusing loops that do not share anything - - -- - - to find which loops can be fused: - - simple interdependencies are ok (i.e. A(i) where A is an Array and i is a loop var, or affine in the future) - - complex ones prevent fusion - need to distinguish the two! temporarily remove the simple ones --> only the others are left! - - if loops are unrelated (no interdeps) in the modified graph they can be fused! - - strongly connected components cannot be fused internally (they are sequential), only externally - - -*/ - - - -class TestAnalysis extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test7-" - - - -} diff --git a/test-src/epfl/test7-analysis/TestCodeMotion.scala b/test-src/epfl/test7-analysis/TestCodeMotion.scala deleted file mode 100644 index 1f6c3716..00000000 --- a/test-src/epfl/test7-analysis/TestCodeMotion.scala +++ /dev/null @@ -1,252 +0,0 @@ -package scala.lms -package epfl -package test7 - -import common._ -import test1._ - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} - - - -trait NestLambdaProg1 extends Arith with Functions with Print { // also used by TestLambdaLift - - def test(x: Rep[Unit]) = { - val f = doLambda { x: Rep[Double] => - val g = doLambda { y: Rep[Double] => - print("yo") - y + (unit(4.0) * unit(3.0)) - } - g - } - f - } - -} - -trait NestCondProg2 extends Arith with Functions with IfThenElse with Print { - - /* Previously this program exhibited behavior that is likely undesired in many - cases. The definition of f was moved *into* g and into the conditional. - The doLambda in the else branch would not be hoisted out of g either. - - Although there are situations where this particular kind of code motion - is an improvement (namely, if the probability of y == true is very low - and the else branch would be cheap). - */ - - - def test(x: Rep[Unit]) = { - val f = doLambda { x: Rep[Double] => 2 * x } - - val g = doLambda { y: Rep[Boolean] => - print("yo") - if (y) - f - else - doLambda { x: Rep[Double] => x + 1 } - } - g - } - -} - - -trait NestCondProg3 extends Arith with Functions with IfThenElse with Print { - - def test(x: Rep[Unit]) = { - val f = if (unit(true)) doLambda { x: Rep[Double] => 2 * x } else doLambda { x: Rep[Double] => 4 * x } - - val g = doLambda { y: Rep[Boolean] => - print("yo") - if (y) { - print("then") - f - } else { - print("else") - if (unit(false)) doLambda { x: Rep[Double] => x + 1 } else doLambda { x: Rep[Double] => x + 2 } - } - } - g - } - -} - -trait NestCondProg4 extends Arith with Functions with IfThenElse with Print { - - def test(x: Rep[Unit]) = { - val g = doLambda { y: Rep[Double] => - if (unit(true)) { - val x = y + 1.0 - print(x) - () - } else { - } - } - g - } - -} - - -trait NestCondProg5 extends Arith with Functions with IfThenElse with Print { - - def test(x: Rep[Unit]) = { - if (unit(true)) { - // should place 7 + 9 here - doLambda { y: Rep[Double] => - print(unit(7.0) + unit(9.0)) - } - } else { - } - } - -} - - -trait NestCondProg6 extends Arith with Functions with IfThenElse with Print { - - // FIXME: this one doesn't work yet!!! - - def test(x: Rep[Unit]) = { - val z = unit(7.0) + unit(9.0) // should move into the conditional (but isn't currently) - val x = if (unit(true)) { - print(z) - } else { - } - doLambda { y: Rep[Boolean] => - print(x) - } - } - -} - - -trait NestCondProg7 extends Arith with OrderingOps with Functions with IfThenElse with Print { - - def test(x: Rep[Unit]) = { - doLambda { y: Rep[Double] => - if (y < 100) { - val z = y + unit(9.0) // should stay inside conditional: - // apparently z was moved up because it is also used in the lambda (z+u) - doLambda { u: Rep[Double] => - z + u - } - } else { - } - } - } - -} - -/* -seems to be another incarnation of test6 - -trait NestCondProg8 extends Arith with OrderingOps with Functions with IfThenElse with Print { - - // FIXME - - def test(x: Rep[Unit]) = { - doLambda { y: Rep[Double] => - if (y < 100) { - val z = y + unit(9.0) // should stay inside conditional - z + unit(1.0) - } else { - val z = y + unit(9.0) // should stay inside conditional, although used again - z + unit(2.0) - } - } - } - -} -*/ - - -class TestCodemotion extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test7-" - - def testCodemotion1 = { - // test loop hoisting (should use loops but lambdas will do for now) - withOutFile(prefix+"codemotion1") { - new NestLambdaProg1 with ArithExp with FunctionsExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"codemotion1") - } - - def testCodemotion2 = { - // test loop hoisting (should use loops but lambdas will do for now) - withOutFile(prefix+"codemotion2") { - new NestCondProg2 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"codemotion2") - } - - def testCodemotion3 = { - // test loop hoisting (should use loops but lambdas will do for now) - withOutFile(prefix+"codemotion3") { - new NestCondProg3 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"codemotion3") - } - - def testCodemotion4 = { - // test loop hoisting (should use loops but lambdas will do for now) - withOutFile(prefix+"codemotion4") { - new NestCondProg4 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"codemotion4") - } - - def testCodemotion5 = { - // test loop hoisting (should use loops but lambdas will do for now) - withOutFile(prefix+"codemotion5") { - new NestCondProg5 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"codemotion5") - } - - def testCodemotion6 = { - // test loop hoisting (should use loops but lambdas will do for now) - withOutFile(prefix+"codemotion6") { - new NestCondProg6 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - println("// NOTE: generated code is not ideal yet (x1=7+9 should be moved inside conditional). see source for discussion.") - } - } - // PENDING TEST - // assertFileEqualsCheck(prefix+"codemotion6") - } - - def testCodemotion7 = { - // test loop hoisting (should use loops but lambdas will do for now) - withOutFile(prefix+"codemotion7") { - new NestCondProg7 with ArithExp with OrderingOpsExp with FunctionsExp with IfThenElseExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenOrderingOps with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - println("// was a Delite issue (Scratchpad in optiml-beta).") - } - } - assertFileEqualsCheck(prefix+"codemotion7") - } - - -} diff --git a/test-src/epfl/test7-analysis/TestDB.scalax b/test-src/epfl/test7-analysis/TestDB.scalax deleted file mode 100644 index ddac7830..00000000 --- a/test-src/epfl/test7-analysis/TestDB.scalax +++ /dev/null @@ -1,114 +0,0 @@ -package scala.lms -package epfl -package test7 - -import common._ -import test1._ - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} - - - -// trait NestLambdaProg extends Arith with Functions with Print -// --> from TestCodeMotion.scala - -trait DB extends Base { - - def field[A](a: Rep[Any], table: String, name: String): Rep[A] - -} - -trait DBExp extends DB with BaseExp { - - def field[A](a: Rep[Any], table: String, name: String): Rep[A] = error("arg") - -} - - - -trait DBProg extends Arith with Loops with Print with DB with OverloadHack { - - trait Facilities0 - trait Features0 - trait Meanings0 - - - type Facilities = Rep[Facilities0] - type Features = Rep[Features0] - type Meanings = Rep[Meanings0] - - case class Table[T](name: String) - - val Facilities: Rep[Table[Facilities0]] = Table[Facilities0]("Facilities") - val Features: Rep[Table[Features0]] = Table[Features0]("Facilities") - val Meanings: Rep[Table[Meanings0]] = Table[Meanings0]("Facilities") - - - implicit def table2ops[T](t: Rep[Table[T]]) = new { - def map[A](f: Rep[T] => Rep[A]): Rep[Table[A]] = error("boom!") - def filter(f: Rep[T] => Rep[Boolean]): Rep[Table[T]] = error("boom!") - def distinct(): Rep[Table[T]] = error("boom!") - def nonEmpty: Rep[Boolean] = error("boom!") - } - - def infix_fac(a: Facilities)(implicit z: Overloaded1): Rep[String] = field[String](a, "Facilities", "fac") - def infix_cat(a: Facilities): Rep[String] = field[String](a, "Facilities", "cat") - - def infix_fac(a: Features)(implicit z: Overloaded2): Rep[String] = field[String](a, "Features", "fac") - def infix_feature(a: Features)(implicit z: Overloaded1): Rep[String] = field[String](a, "Features", "feature") - - def infix_feature(a: Meanings)(implicit z: Overloaded2): Rep[String] = field[String](a, "Meanings", "meaning") - def infix_meaning(a: Meanings): Rep[String] = field[String](a, "Meanings", "feature") - - def infix_===(a: Rep[Any], b: Rep[Any]): Rep[Boolean] = error("boom!") - - - def test() = { - - def hasFeatures(fac: Facilities) = Features.filter(b => b.fac === fac).map(b => ()) - - def cats = Facilities.map (b => b.cat).distinct() - - for (a <- cats) yield { - - val facilities = Facilities.filter(d => d.cat === a) - - val features = Features.filter (b => facilities.filter(d => b.fac === d.fac).nonEmpty) - - val meanings = features.map (b => Meanings.filter (c => c.feature === b.feature)) - - (a, meanings) - } - - } - -} - - -class TestDB extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test7-" - - def testDB1 = { - withOutFile(prefix+"db1") { - new DBProg with DBExp with ArithExp with LoopsExp with PrintExp { self => - //val codegen = new ScalaGenArith with ScalaGenPrint { val IR: self.type = self } - //codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"db1") - } - - def testDB2 = { - withOutFile(prefix+"db2") { - new DBProg with DBExp with ArithExp with LoopsExp with PrintExp { self => - //val codegen = new ScalaGenArith with ScalaGenPrint { val IR: self.type = self } - //codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"db2") - } - -} diff --git a/test-src/epfl/test7-analysis/TestFusion.scala b/test-src/epfl/test7-analysis/TestFusion.scala deleted file mode 100644 index e49120ff..00000000 --- a/test-src/epfl/test7-analysis/TestFusion.scala +++ /dev/null @@ -1,191 +0,0 @@ -package scala.lms -package epfl -package test7 - -import common._ -import test1._ - -import util.OverloadHack -import scala.reflect.SourceContext - -import java.io.{PrintWriter,StringWriter,FileOutputStream} -import scala.reflect.SourceContext - - -trait ScalaGenFatArrayLoopsFusionOpt extends ScalaGenArrayLoopsFat with ScalaGenIfThenElseFat with LoopFusionOpt { - val IR: ArrayLoopsFatExp with IfThenElseFatExp - import IR._ - - override def unapplySimpleIndex(e: Def[Any]) = e match { - case ArrayIndex(a, i) => Some((a,i)) - case _ => super.unapplySimpleIndex(e) - } - override def unapplySimpleDomain(e: Def[Int]): Option[Exp[Any]] = e match { - case ArrayLength(a) => Some(a) - case _ => super.unapplySimpleDomain(e) - } - - override def unapplySimpleCollect(e: Def[Any]) = e match { - case ArrayElem(Block(a)) => Some(a) //TODO: block?? - case _ => super.unapplySimpleCollect(e) - } - - override def unapplySimpleCollectIf(e: Def[Any]) = e match { - case ArrayIfElem(c,Block(a)) => Some((a,List(c))) //TODO: block? - case _ => super.unapplySimpleCollectIf(e) - } - - override def applyAddCondition(e: Def[Any], c: List[Exp[Boolean]]) = e match { //TODO: should c be list or not? - case ArrayElem(a) if c.length == 1 => ArrayIfElem(c(0),a) - case ReduceElem(a) if c.length == 1 => ReduceIfElem(c(0),a) - case _ => super.applyAddCondition(e,c) - } - - - -} - - -// trait NestLambdaProg extends Arith with Functions with Print -// --> from TestCodeMotion.scala - -trait FusionProg extends Arith with ArrayLoops with Print { - - implicit def bla(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] - - def test(x: Rep[Unit]) = { - - val constant = array(100) { i => 1 } - - val linear = array(100) { i => 2*i } - - val affine = array(100) { i => constant.at(i) + linear.at(i) } - - def square(x: Rep[Double]) = x*x - def mean(x: Rep[Array[Double]]) = sum(x.length) { i => x.at(i) } / x.length - def variance(x: Rep[Array[Double]]) = sum(x.length) { i => square(x.at(i)) } / x.length - square(mean(x)) - - val data = affine - - val m = mean(data) - val v = variance(data) - - print(m) - print(v) - } - -} - -trait FusionProg2 extends Arith with ArrayLoops with Print with OrderingOps { - - implicit def bla(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] - - def test(x: Rep[Unit]) = { - - def filter[T:Manifest](x: Rep[Array[T]])(p: Rep[T] => Rep[Boolean]) = - arrayIf(x.length) { i => (p(x.at(i)), x.at(i)) } - - val range = array(100) { i => i } - - val odds = filter(range) { z => z > 50 } - - val res = sum(odds.length) { i => odds.at(i) } - - print(res) - } - -} - - - -/* - some thoughts on cse/gvn : - - - currently cse works fine for first-order, point-free things: - val x = a + b - val y = a + b - will always be represented internally as - val x = a + b - val y = x - - - if bound variables are involved, cse no longer works: - val a = array { i => 0 } - val b = array { i => 0 } - will create two separate objects: - val a = array { i0 => 0 } - val b = array { i1 => 0 } - the same holds for lambdas. - - - this is due to the choice of representing bound vars using fresh symbols. - alternatively we could use DeBruijn indices. - - however, some care would have to be taken in managing the indices: - val a = array { i => - val b = array { j => f(j) } - sum(b) - } - code motion will move b out of a ... but we know that only after looking at b's body - - - for now this is not really a problem because loop fusion will take - care of duplicate loops (effectively lifting scalar cse to array cse) - - - another solution (as done by delite) is to wrap array { i => 0 } - as ArrayZero(len) extends DeliteOP(array(len) { i => 0}). - here, cse will be done on the case class representation -*/ - - - -class TestFusion extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test7-" - - def testFusion1 = { - withOutFile(prefix+"fusion1") { - new FusionProg with ArithExp with ArrayLoopsExp with PrintExp { self => - val codegen = new ScalaGenArrayLoops with ScalaGenArith with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"fusion1") - } - - def testFusion2 = { - withOutFile(prefix+"fusion2") { - // LoopsExp2 with ArithExp with PrintExp with BaseFatExp - new FusionProg with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp { self => - override val verbosity = 1 - val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"fusion2") - } - - def testFusion3 = { - withOutFile(prefix+"fusion3") { - new FusionProg2 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => - override val verbosity = 1 - val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint - with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; - override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = false } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"fusion3") - } - - def testFusion4 = { - withOutFile(prefix+"fusion4") { - new FusionProg2 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => - override val verbosity = 1 - val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint - with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; - override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"fusion4") - } - -} diff --git a/test-src/epfl/test7-analysis/TestFusion2.scala b/test-src/epfl/test7-analysis/TestFusion2.scala deleted file mode 100644 index e6d9e8ed..00000000 --- a/test-src/epfl/test7-analysis/TestFusion2.scala +++ /dev/null @@ -1,228 +0,0 @@ -package scala.lms -package epfl -package test7 - -import common._ -import test1._ - -import util.OverloadHack -import scala.reflect.SourceContext - -import java.io.{PrintWriter,StringWriter,FileOutputStream} - - - - -trait FusionProg21 extends Arith with ArrayLoops with Print with OrderingOps { - - def infix_foo(x: Rep[Array[Double]]): Rep[Double] = x.at(0) - - def test(x: Rep[Unit]) = { - - // there was a bug were this would lead to a recursive schedule: - // as,bs are fused (no dependencies) - // cs,ds are fused (no dependencies) - // but there are cross deps ds->as, bs->cs ... - - val cs = array(100) { i => 9.0 } - - val as = array(50) { i => 3.0 } - val bs = array(50) { i => cs.foo } - - val ds = array(100) { i => as.foo } - - print(as) - print(bs) - print(cs) - print(ds) - } - -} - - -trait FusionProg22 extends Arith with ArrayLoops with Print with OrderingOps { - - def infix_foo(x: Rep[Array[Double]]): Rep[Double] = x.at(0) - - def test(x: Rep[Unit]) = { - - // test some nested loops - the inner ones should be moved to the top level and be fused there - - // previously this did not work completely: - // if an inner loop can be hoisted as a result of fusing two outer loops - // it would not be considered for outer-level fusion (Wloops is not recalculated) - // between iterations. - - // the question is how far this can be taken: fusion at the innermost level could - // cause a loop to be moved to the top level, in which case the top level would - // need to apply fusion all over again. - - - val as = array(100) { i => - array(50) { j => 1.0 } - } - - val bs = array(100) { i => - array(50) { j => 2.0 } - } - - val cs = array(100) { i => - sum(50) { j => 4.0 } - } - - val ds = array(100) { i => - val x = sum(50) { j => as.at(i).at(j) + bs.at(i).at(j) } // this one depends on i, cannot move up - val y = cs.at(i) - x + y - } - - print(as) - print(bs) - print(cs) - print(ds) - } - -} - - -trait FusionProg23 extends Arith with ArrayLoops with Print with OrderingOps { - - def infix_foo(x: Rep[Array[Double]]): Rep[Double] = x.at(0) - - def test(x: Rep[Unit]) = { - - // test some nested loops - this times they are tryly nested (inner ones depend on loop var) - - val as = array(100) { i => - array(i) { j => 1.0 } - } - - val bs = array(100) { i => - array(i) { j => 2.0 } - } - - val cs = array(100) { i => - sum(i) { j => 4.0 } - } - - val ds = array(100) { i => - val x = sum(i) { j => as.at(i).at(j) + bs.at(i).at(j) } - val y = cs.at(i) - x + y - } - - - print(as) - print(bs) - print(cs) - print(ds) - } - -} - - -trait FusionProg24 extends Arith with ArrayLoops with Print with OrderingOps { - - def infix_foo(x: Rep[Array[Double]]): Rep[Double] = x.at(0) - - def test(x: Rep[Unit]) = { - - // test some nested loops - - // there is a question related to DCE: we might have fused two loops early, - // and by some later fusion one of them becomes dead. - - // currently this is not handled because fusion goes from outermost inwards - - val as = array(200) { i => - 1.0 - } - - val bs = array(200) { i => - 2.0 - } - - val cs = array(100) { i => - array(i) { j => as.foo } - } - - val ds = array(100) { i => - array(i) { j => cs.at(i).at(j) - as.foo } - // this will become as.foo - as.foo = 0 --> i.e. as becomes dead but is already fused with bs, which is used... - } - - - //print(as) - print(bs) - //print(cs) - print(ds) - } - -} - - - - -class TestFusion2 extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test7-" - - def testFusion21 = { - withOutFile(prefix+"fusion21") { - new FusionProg21 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => - override val verbosity = 1 - val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint - with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; - override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"fusion21") - } - - def testFusion22 = { - withOutFile(prefix+"fusion22") { - new FusionProg22 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => - override val verbosity = 1 - val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint - with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; - override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"fusion22") - } - - def testFusion23 = { - withOutFile(prefix+"fusion23") { - new FusionProg23 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => - override val verbosity = 1 - val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint - with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; - override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"fusion23") - } - - def testFusion24 = { - withOutFile(prefix+"fusion24") { - new FusionProg24 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => - - override def infix_-(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = if (x == y) { - println("*** removing self subtraction " + x + " - " + y) - 0 - } else super.infix_-(x,y) // optimizations to trigger test behavior - - override val verbosity = 1 - val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint - with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; - override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - println("// NOTE: generated code is not ideal yet (x2 is never used). see source for discussion.") - } - } - assertFileEqualsCheck(prefix+"fusion24") - } -} diff --git a/test-src/epfl/test7-analysis/TestLambalift.scala b/test-src/epfl/test7-analysis/TestLambalift.scala deleted file mode 100644 index 69dda489..00000000 --- a/test-src/epfl/test7-analysis/TestLambalift.scala +++ /dev/null @@ -1,134 +0,0 @@ -package scala.lms -package epfl -package test7 - -import common._ -import test1._ - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} - -/* - TODO outstanding issues: - - - mutable variable need to be heap-allocated if referenced from within a closure - and stack allocated from within a nested function that is not a closure. - this can be done conservatively (always alloc ref cells on the heap). - but a better approach would be to heap- or stack-alloc only the necessary ones. - - - closures should not unnecessarily be heap-allocated as well (currently all - nested functions are closures and heap-allocated). - - this complicates the analysis for variables, as witnessed by scalac: - - def foo = { - var x = 0 - val f = (y:Int) => x = y - f(7) - } - - compiled with -optimize results in - - // methods - def foo(): Unit { - locals: variable x$1 - startBlock: 1 - blocks: [1] - - 1: - 1 NEW REF(class IntRef) - 1 DUP(REF(class IntRef)) - 1 CONSTANT(Constant(0)) - 1 CALL_METHOD scala.runtime.IntRef. (static-instance) - 1 STORE_LOCAL(variable x$1) - 1 SCOPE_ENTER variable x$1 - 1 SCOPE_ENTER value f - undef LOAD_LOCAL(variable x$1) - 1 CONSTANT(Constant(7)) - 1 STORE_FIELD variable elem (dynamic) - 1 SCOPE_EXIT variable x$1 - 1 SCOPE_EXIT value f - 1 RETURN(UNIT) - - } - - which still allocates the IntRef although the closure record is eliminated - and the code inlined. - - Phase ordering bites again! - -*/ - - - -class TestLambdalift extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test7-" - - def testLambdalift1 = { - // test lambda lifting - withOutFile(prefix+"lambdalift1") { - var classes: List[String] = Nil - - trait ScalaGenBla extends ScalaGenBase { - import IR._ - def emitFocused[A,B](name: String, params: List[Exp[Any]], x: Exp[A], y: Block[B], out: PrintWriter): Unit - } - - new NestLambdaProg1 with ArithExp with FunctionsExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenPrint { - val IR: self.type = self - - /*def boundAndUsedInScope(x: Exp[Any], y: Exp[Any]): (List[Sym[Any]], List[Sym[Any]]) = { - val used = (syms(y):::innerScope.flatMap(t => syms(t.rhs))).distinct - val bound = (syms(x):::innerScope.flatMap(t => t.sym::boundSyms(t.rhs))).distinct - (bound, used) - } - def freeInScope(x: Exp[Any], y: Exp[Any]): List[Sym[Any]] = { - val (bound, used) = boundAndUsedInScope(x,y) - used diff bound - }*/ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case e@Lambda(fun, x, y) => - - focusBlock(y) { - var free = freeInScope(List(x),List(getBlockResultFull(y))) - - val sw = new StringWriter - codegenInner.emitFocused("Anonfun_"+quote(sym), free, x, y, new PrintWriter(sw)) - classes = sw.toString :: classes - - stream.println("val " + quote(sym) + " = new Anonfun_" + quote(sym) + "("+free.map(quote).mkString(",")+")") - } - - case _ => super.emitNode(sym, rhs) - } - } - val codegen2 = new ScalaGenBla with ScalaGenArith with ScalaGenFunctions with ScalaGenPrint { - val IR: self.type = self - - override def initialDefs = codegen.availableDefs - - def emitFocused[A,B](name: String, params: List[Exp[Any]], x: Exp[A], y: Block[B], out: PrintWriter) = { - // TODO: this is not valid Scala code. the types are missing. - withStream(out) { - stream.println("class "+name+"("+params.map(quote).mkString(",")+") {") - stream.println("def apply("+quote(x)+") = {") - traverseBlockFocused(y) - stream.println(quote(getBlockResult(y))) - stream.println("}") - stream.println("}") - } - } - } - val codegenInner: ScalaGenBla { val IR: self.type; type Block[+T] = self.Block[T] } = codegen2 - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - classes.foreach(println) - } - } - assertFileEqualsCheck(prefix+"lambdalift1") - } - -} diff --git a/test-src/epfl/test7-analysis/TestLiveness.scala b/test-src/epfl/test7-analysis/TestLiveness.scala deleted file mode 100644 index 3d2759a0..00000000 --- a/test-src/epfl/test7-analysis/TestLiveness.scala +++ /dev/null @@ -1,150 +0,0 @@ -package scala.lms -package epfl -package test7 - -import common._ -import test1._ - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} - -// very preliminary! - -trait Liveness extends internal.GenericNestedCodegen { - import IR._ - - var defuse: List[(Sym[Any],Sym[Any])] = Nil - - override def traverseBlockFocused[A](result: Block[A]): Unit = { - focusExactScope(result) { levelScope => - - // TODO: what is the intended behavior for uses in innerScope? - // this will likely depend on the node, i.e. ifThenElse vs. loop - - // a possible first step: handle only straightline code and mark - // everything used by innerScope as escaping (plus the result) - - def usesOf(s: Sym[Any]): List[TP[Any]] = levelScope.flatMap { - case TP(s1, Reify(rhs1,_,_)) => // reify nodes are eliminated, so we need to find all uses of the reified thing - if (syms(rhs1).contains(s)) usesOf(s1) else Nil - case d@TP(_, rhs1) => - if (syms(rhs1).contains(s)) List(d) else Nil - } - defuse = levelScope.flatMap { - case TP(sym, Reify(_,_,_)) => Nil - case TP(sym, rhs) => - usesOf(sym).map(d => (sym,d.sym):(Sym[Any],Sym[Any])) - } - - for (TP(sym, rhs) <- levelScope) { - emitNode(sym, rhs) - - rhs match { - case Reify(s, u, effects) => - case _ => - // remove everything only used here from defuse - // output dealloc for stuff that goes away - - val livebefore = defuse.map(_._1).distinct - defuse = defuse.filterNot(_._2 == sym) - val liveafter = defuse.map(_._1).distinct - val killed = livebefore diff liveafter - if (killed.nonEmpty) stream.println("// kill: " + killed.map(quote).mkString(", ")) - //stream.println("// def->use: " + defuse.map(p=>quote(p._1)+"->"+quote(p._2)).mkString(", ")) - } - - } - } - } - - -} - - -trait ScalaGenArraysLiveOpt extends ScalaGenArrays with Liveness { - val IR: ArraysExp - import IR._ - - def canKill(e: Exp[Any], u: Sym[Any]) = { - !defuse.exists(p => p._1 == e && p._2 != u) - } - - def tryKill(e: Exp[Any], u: Sym[Any]) = { - if (!defuse.exists(p => p._1 == e && p._2 != u)) { - defuse = defuse.filterNot(p => p._1 == e) - true - } else false - } - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ArrayZero(n) => - emitValDef(sym, "new Array[Int](" + quote(n) + ")") - case ArrayUpdate(a,x,v) => - if (tryKill(a, sym)) - emitValDef(sym, quote(a)) - else - emitValDef(sym, quote(a) +".clone()") - stream.println(quote(sym) + "(" + quote(x) + ") = " + quote(v)) - case ArrayPlus(a,b) => - if (tryKill(a, sym)) - emitValDef(sym, quote(a)) - else if (canKill(b, sym)) - emitValDef(sym, quote(b)) - else - emitValDef(sym, "new Array[Int](" + quote(a) + ".length)") - stream.println("arrayPlus("+ quote(sym) + "," + quote(a) + "," + quote(b) + ")") - case _ => super.emitNode(sym, rhs) - } -} - - - - -// trait NestLambdaProg extends Arith with Functions with Print -// --> from TestCodeMotion.scala - -trait LiveProg extends Arith with Arrays with Print { - - def test(x: Rep[Unit]) = { - val a = zeroes(100) // allocation - - val ab = a.update(7, 42) // in place, a not used below - - val abc = ab.update(2, 42) // not in place (will copy), b is used again - - val abd = ab.update(4, 42) // in place again - - val e = abc + abd // in place addition, dealloc one - - print(e) // dealloc the other one - } - -} - - -class TestLiveness extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test7-" - - def testLiveness1 = { - withOutFile(prefix+"liveness1") { - new LiveProg with ArithExp with ArraysExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenArrays with ScalaGenPrint with Liveness { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"liveness1") - } - - def testLiveness2 = { - withOutFile(prefix+"liveness2") { - new LiveProg with ArithExp with ArraysExp with PrintExp { self => - val codegen = new ScalaGenArith with ScalaGenArraysLiveOpt with ScalaGenPrint with Liveness { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"liveness2") - } - -} diff --git a/test-src/epfl/test8-effects/TestMutation.scala b/test-src/epfl/test8-effects/TestMutation.scala deleted file mode 100644 index 3909a5e8..00000000 --- a/test-src/epfl/test8-effects/TestMutation.scala +++ /dev/null @@ -1,361 +0,0 @@ -package scala.lms -package epfl -package test8 - -import common._ -import test1._ -import test7.{Print,PrintExp,ScalaGenPrint} -import test7.{ArrayLoops,ArrayLoopsExp,ScalaGenArrayLoops} - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} - - -/* - if there's a crash here during compilation, it's likely due to #4363 (need latest scala-virtualized for fix) -*/ - -trait ArrayMutation extends ArrayLoops { - - def infix_update[T:Manifest](a: Rep[Array[T]], i: Rep[Int], x: Rep[T]): Rep[Unit] - - def infix_mutable[T:Manifest](a: Rep[Array[T]]): Rep[Array[T]] - def infix_clone[T:Manifest](a: Rep[Array[T]]): Rep[Array[T]] - -} - - -trait ArrayMutationExp extends ArrayMutation with ArrayLoopsExp { - - case class ArrayUpdate[T](a: Rep[Array[T]], i: Rep[Int], x: Rep[T]) extends Def[Unit] - case class ArrayMutable[T](a: Rep[Array[T]]) extends Def[Array[T]] - case class ArrayClone[T](a: Rep[Array[T]]) extends Def[Array[T]] - - def infix_update[T:Manifest](a: Rep[Array[T]], i: Rep[Int], x: Rep[T]) = reflectWrite(a)(ArrayUpdate(a,i,x)) - - def infix_mutable[T:Manifest](a: Rep[Array[T]]) = reflectMutable(ArrayMutable(a)) - def infix_clone[T:Manifest](a: Rep[Array[T]]) = ArrayClone(a) - - override def aliasSyms(e: Any): List[Sym[Any]] = e match { - case SimpleLoop(s,i, ArrayElem(y)) => Nil - case SimpleLoop(s,i, ReduceElem(y)) => syms(y) // could also return zero value - case SimpleLoop(s,i, ArrayIfElem(c,y)) => Nil - case SimpleLoop(s,i, ReduceIfElem(c,y)) => syms(y) // could also return zero value - case ArrayIndex(a,i) => Nil - case ArrayLength(a) => Nil - case ArrayUpdate(a,i,x) => Nil // syms(a) <-- any use to return a? - case ArrayMutable(a) => Nil - case ArrayClone(a) => Nil - case _ => super.aliasSyms(e) - } - - override def containSyms(e: Any): List[Sym[Any]] = e match { - case SimpleLoop(s,i, ArrayElem(y)) => syms(y) - case SimpleLoop(s,i, ReduceElem(y)) => Nil - case SimpleLoop(s,i, ArrayIfElem(c,y)) => syms(y) - case SimpleLoop(s,i, ReduceIfElem(c,y)) => Nil - case ArrayIndex(a,i) => Nil - case ArrayLength(a) => Nil - case ArrayUpdate(a,i,x) => syms(x) - case ArrayMutable(a) => Nil - case ArrayClone(a) => Nil - case _ => super.containSyms(e) - } - - override def extractSyms(e: Any): List[Sym[Any]] = e match { - case SimpleLoop(s,i, ArrayElem(y)) => Nil - case SimpleLoop(s,i, ReduceElem(y)) => Nil - case SimpleLoop(s,i, ArrayIfElem(c,y)) => Nil - case SimpleLoop(s,i, ReduceIfElem(c,y)) => Nil - case ArrayIndex(a,i) => syms(a) - case ArrayLength(a) => Nil - case ArrayUpdate(a,i,x) => Nil - case ArrayMutable(a) => Nil - case ArrayClone(a) => Nil - case _ => super.extractSyms(e) - } - - override def copySyms(e: Any): List[Sym[Any]] = e match { - case SimpleLoop(s,i, ArrayElem(y)) => Nil - case SimpleLoop(s,i, ReduceElem(y)) => Nil - case SimpleLoop(s,i, ArrayIfElem(c,y)) => Nil - case SimpleLoop(s,i, ReduceIfElem(c,y)) => Nil - case ArrayIndex(a,i) => Nil - case ArrayLength(a) => Nil - case ArrayUpdate(a,i,x) => syms(a) - case ArrayMutable(a) => syms(a) - case ArrayClone(a) => syms(a) - case _ => super.copySyms(e) - } - - -} - -trait ScalaGenArrayMutation extends ScalaGenArrayLoops { - val IR: ArrayMutationExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ArrayUpdate(a,i,x) => - emitValDef(sym, quote(a) + ".update(" + quote(i) + ", " + quote(x) + ")") - case ArrayMutable(a) => - emitValDef(sym, quote(a) + ".clone // mutable") - case ArrayClone(a) => - emitValDef(sym, quote(a) + ".clone") - case _ => super.emitNode(sym, rhs) - } -} - - - - - -class TestMutation extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test8-" - - trait DSL extends ArrayMutation with Arith with OrderingOps with Variables with IfThenElse with While with RangeOps with Print { - def zeros(l: Rep[Int]) = array(l) { i => 0 } - def mzeros(l: Rep[Int]) = zeros(l).mutable - def infix_toDouble(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] - - def test(x: Rep[Int]): Rep[Unit] - } - trait Impl extends DSL with ArrayMutationExp with ArithExp with OrderingOpsExp with VariablesExp - with IfThenElseExp with WhileExp with RangeOpsExp with PrintExp { self => - override val verbosity = 2 - val codegen = new ScalaGenArrayMutation with ScalaGenArith with ScalaGenOrderingOps - with ScalaGenVariables with ScalaGenIfThenElse with ScalaGenWhile with ScalaGenRangeOps - with ScalaGenPrint { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - - def testMutation1 = { - withOutFile(prefix+"mutation1") { - // a write operation must unambigously identify the object being mutated - trait Prog extends DSL { - def test(x: Rep[Int]) = { - val vector1 = mzeros(100) - val vector2 = mzeros(100) - val a = if (x > 7) vector1 else vector2 - - a.update(40,40) // error: not clear which object is mutated (vector1 or vector2) - - print(a.at(50)) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation1") - } - - def testMutation1b = { - withOutFile(prefix+"mutation1b") { - // a write operation must unambigously identify the object being mutated - trait Prog extends DSL { - def test(x: Rep[Int]) = { - val vector1 = mzeros(100) - val vector2 = mzeros(100) - val a = if (x > 7) vector1 else vector2 - - val a2 = a.mutable - a2.update(40,40) // ok: we have made a copy - - print(a2.at(50)) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation1b") - } - - def testMutation2 = { - withOutFile(prefix+"mutation2") { - // an operation that might read from mutable data v will be serialized with all writes to v - trait Prog extends DSL { - def test(x: Rep[Int]) = { - val vector1 = mzeros(100) - val vector2 = mzeros(100) - val a = if (x > 7) vector1 else vector2 - - val x0 = a.at(10) - - vector1.update(10,10) // must come after x0 - vector2.update(10,20) // must come after x0 - - val x1 = a.at(10) // must come after both writes, no cse with x0 - - print(x1-x0) // minus should not have effect dep - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation2") - } - - - def testMutation3 = { - withOutFile(prefix+"mutation3") { - // vars may not reference mutable objects - trait Prog extends DSL with LiftVariables { - def test(x: Rep[Int]) = { - var a = zeros(100) - val b = mzeros(100) - for (i <- 0 until b.length) { // this is also a curious case: range creation must not be reflected - val x1 = a.at(i) - b.update(i,8) - val x2 = a.at(i) // must be cse'd - a = b // error: here we learn that reads on a would need to be serialized with b but it's too late... - } - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation3") - } - - def testMutation3b = { - withOutFile(prefix+"mutation3b") { - // vars may not reference mutable objects - trait Prog extends DSL with LiftVariables { - def test(x: Rep[Int]) = { - var a = zeros(100) - val b = mzeros(100) - for (i <- 0 until b.length) { - val x1 = a.at(i) - b.update(i,8) - val x2 = a.at(i) // must be cse'd - a = b.clone // ok: making a copy - } - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation3b") - } - - def testMutation4 = { - withOutFile(prefix+"mutation4") { - // mutable objects cannot be nested - trait Prog extends DSL { - def test(x: Rep[Int]) = { - val a = mzeros(100) - val b = array(10) { i => a } // nested array - val b1 = b.mutable // error: internal arrays are mutable on their own - val x1 = b1.at(5).at(50) - print(x1) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation4") - } - - def testMutation4b = { - withOutFile(prefix+"mutation4b") { - // mutable objects cannot be nested - trait Prog extends DSL { - def test(x: Rep[Int]) = { - val a = mzeros(100) - val b = array(10) { i => a } // nested array - val b1 = b.clone - val b2 = b1.mutable // error: internal arrays are *still* mutable, despite shallow clone - val x1 = b2.at(5).at(50) - print(x1) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation4b") - } - - def testMutation4c = { - withOutFile(prefix+"mutation4c") { - // mutable objects cannot be nested - trait Prog extends DSL { - def test(x: Rep[Int]) = { - val a = mzeros(100) - val b = array(10) { i => a.clone } // nested array - val b1 = b.mutable // ok: internal arrays are immutable - val x1 = b1.at(5).at(50) - print(x1) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation4c") - } - - - def testMutation5 = { - withOutFile(prefix+"mutation5") { - // mutable objects cannot be nested - trait Prog extends DSL { - def test(x: Rep[Int]) = { - val a = zeros(100) - val b = array(10) { i => a } // nested array - val b1 = b.mutable - - val c = mzeros(20) - b1.update(4,a) // ok: insert immutable array - b1.update(5,c) // error: cannot insert mutable array - - c.update(50,50) - val x1 = b1.at(5).at(50) - print(x1) - } - } - - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation5") - } - - def testMutation6 = { - withOutFile(prefix+"mutation6") { - // mutate nested object (within an immutable one) - trait Prog extends DSL { - def test(x: Rep[Int]) = { - val a = mzeros(100) - val b = array(10) { i => a } // nested array - val u = array(10) { i => zeros(100) } - val c = if (x > 7) b else u - - val x1 = c.at(5).at(50) - - a.update(50,50) - - val x2 = c.at(5).at(50) // no cse, must serialize with update to a - - print(x2-x1) - } - } - - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation6") - } - - def testMutation7 = { - withOutFile(prefix+"mutation7") { - // local variables of primitive type - trait Prog extends DSL with LiftVariables { - def test(x0: Rep[Int]) = { - val x = x0.toDouble // avoid codegen for implicit convert - var c = 0.0 - while (c < x) { - c = c + 1 - } - if (c < x) - c = 8 - print(c) - } - } - - new Prog with Impl - } - assertFileEqualsCheck(prefix+"mutation7") - } - -} diff --git a/test-src/epfl/test8-effects/TestSpeculative.scala b/test-src/epfl/test8-effects/TestSpeculative.scala deleted file mode 100644 index 0706a138..00000000 --- a/test-src/epfl/test8-effects/TestSpeculative.scala +++ /dev/null @@ -1,238 +0,0 @@ -package scala.lms -package epfl -package test8 - -import common._ -import internal.{NestedBlockTraversal} -import test1._ -import test7.{Print,PrintExp,ScalaGenPrint} -import test7.{ArrayLoops,ArrayLoopsExp,ScalaGenArrayLoops} - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} -import scala.reflect.SourceContext - -class TestSpeculative extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test8-" - - trait DSL extends ArrayMutation with Arith with OrderingOps with BooleanOps with LiftVariables with IfThenElse with While with RangeOps with Print { - def zeros(l: Rep[Int]) = array(l) { i => 0 } - def mzeros(l: Rep[Int]) = zeros(l).mutable - def infix_toDouble(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] - - def test(x: Rep[Int]): Rep[Unit] - } - trait Impl extends DSL with ArrayMutationExp with ArithExp with OrderingOpsExpOpt with BooleanOpsExp - with EqualExpOpt with VariablesExpOpt - with IfThenElseExpOpt with WhileExpOptSpeculative with SplitEffectsExpFat with RangeOpsExp with PrintExp - with CompileScala { self => - override val verbosity = 1 - val codegen = new ScalaGenArrayMutation with ScalaGenArith with ScalaGenOrderingOps - with ScalaGenVariables with ScalaGenIfThenElseFat with ScalaGenWhileOptSpeculative with ScalaGenSplitEffects - with ScalaGenRangeOps with ScalaGenPrint /*with LivenessOpt*/ { val IR: self.type = self } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - val f = compile(test) - f(7) - } - - def testSpeculative1 = { - withOutFile(prefix+"speculative1") { - // test simple copy propagation through variable - trait Prog extends DSL { - def test(x: Rep[Int]) = { - var x = 7 - - if (x > 3) // should remove conditional - print(x) - else - print("no") - print(x) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"speculative1") - } - - def testSpeculative1b = { - withOutFile(prefix+"speculative1b") { - // test simple copy propagation through variable - trait Prog extends DSL { - def test(x: Rep[Int]) = { - var x = 7 - - if (x > 3) // should remove conditional - x = 5 - else - print("no") - - print(x) // should be const 5 - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"speculative1b") - } - - def testSpeculative1c = { - withOutFile(prefix+"speculative1c") { - // test simple copy propagation through variable - trait Prog extends DSL { - def test(y: Rep[Int]) = { - var x = 7 - - if (x > y) // cannot remove conditional - x = 5 - else - print("no") - - print(x) // should be var read - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"speculative1c") - } - - def testSpeculative1d = { - withOutFile(prefix+"speculative1d") { - // test simple copy propagation through variable - trait Prog extends DSL { - def test(y: Rep[Int]) = { - var x = 7 - var z = 9 // should remove z because it is never read - - if (x > y) { // cannot remove conditional - x = 5 - z = 12 // assignment should be removed, too - } else - print("no") - - print(x) // should be var read - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"speculative1d") - } - - - def testSpeculative3 = { - withOutFile(prefix+"speculative3") { - // test simple copy propagation through variable - trait Prog extends DSL { - def test(x: Rep[Int]) = { - var x = 7 - var c = 0.0 - while (c < 10) { - print(x) // should be const 7 - print(c) - var z = 2 // should remove var - c = c + 1 - print(z) // should be const 2 - } - print(x) // should be const 7 - print(c) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"speculative3") - } - - def testSpeculative3b = { - withOutFile(prefix+"speculative3b") { - // test simple copy propagation through variable - trait Prog extends DSL { - def test(x: Rep[Int]) = { - var x = 7 - var y = 4.0 // should remove - var c = 0.0 - while (c < 10) { - print(x) // should be const 7 - print(c) - var z = 2 // should remove var - c = c + 1 - print(z) // should be const 2 - y = y + 2 // should remove - } - print(x) // should be const 7 - print(c) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"speculative3b") - } - - def testSpeculative4 = { - withOutFile(prefix+"speculative4") { - // test simple copy propagation through variable - trait Prog extends DSL { - def test(x: Rep[Int]) = { - var c = 0.0 - while (c > 10) { - print("booooring!") - } - print("done") - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"speculative4") - } - - def testSpeculative5 = { - withOutFile(prefix+"speculative5") { - // test simple copy propagation through variable - trait Prog extends DSL { - def test(x: Rep[Int]) = { - var x = 7 - var c = 0.0 - while (c < 10) { - if (x < 10) - print("test") - else - x = c - print(x) - c += 1 - } - print(x) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"speculative5") - } - - // FIXME: this one breaks. Variable j is lifted to - // top scope because it is not part of the mayWrite - // summary of the inner loop. - def testSpeculative6 = { - withOutFile(prefix+"speculative6") { - // test simple copy propagation through variable - trait Prog extends DSL { - def test(x: Rep[Int]) = { - print("FIXME -- WRONG RESULT") - var i = 0 - while (i < 10) { - var j = 0 - while (j < 10) { - print("test") - print(i) - print(j) - j += 1 - } - i += 1 - } - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"speculative6") - } - - -} diff --git a/test-src/epfl/test9-experimental/TestCPS.scala b/test-src/epfl/test9-experimental/TestCPS.scala deleted file mode 100644 index 875c4c90..00000000 --- a/test-src/epfl/test9-experimental/TestCPS.scala +++ /dev/null @@ -1,228 +0,0 @@ -package scala.lms -package epfl -package test9 - -import common._ -import test1._ - -import test7.{Print,PrintExp,ScalaGenPrint} -import internal.ScalaCompile - -import scala.util.continuations._ - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} - - -trait CpsProg1 extends Arith with IfThenElse with Equal with Print with Compile { - - def choose[A:Manifest](x: Rep[Boolean]): Boolean @cps[Rep[A]] = shift { k: (Boolean => Rep[A]) => - if (x) - k(true) - else - k(false) - } - - def test(x: Rep[Boolean]): Rep[Unit] = { // recompile - reset { - val c = choose[Unit](x) - if (c) { - this.print("is true") - } else { - this.print("is false") - } - } - } - -} - -trait CpsProg2 extends Arith with IfThenElse with Equal with Print with Compile { - - def choose[A:Manifest](x: Rep[Boolean]): Boolean @cps[Rep[A]] = shift { k: (Boolean => Rep[A]) => - if (x) - k(true) - else - k(false) - } - - - def pickValue[A:Manifest](x: Rep[Boolean]): Rep[Int] @cps[Rep[A]] = { - val c = choose[A](x) - if (c) - unit(7) - else - unit(9) - } - - def test(x: Rep[Boolean]): Rep[Unit] = { // recompile - reset { - val z = pickValue[Unit](x) - this.print(z) - } - } - -} - - -trait AmbProg1 extends Arith with IfThenElse with Equal with Print with Compile { - - //def __ifThenElse[T:Manifest,U](cond: Rep[Boolean], thenp: => Rep[T]@cps[U], elsep: => Rep[T]@cps[U]): Rep[T]@cps[U] = cond match { case true => thenp case false => elsep } - - - // xs could be either Rep[List[T]] or List[Rep[T]] - // if List[Rep[T]], code paths could be duplicated or not... - - // this is the BAM variant of AMB: be careful, it can cause code explosion. - def amb[T](xs: List[Rep[T]]): Rep[T] @cps[Rep[Unit]] = shift { k => - xs foreach k - } - - def require(x: Rep[Boolean]): Rep[Unit] @cps[Rep[Unit]] = shift { k: (Rep[Unit]=>Rep[Unit]) => - if (x) k() else () - } - - - def test(x: Rep[Int]): Rep[Unit] = { - - reset { - val a = amb(List(unit(1),unit(2),x)) - val b = amb(List(unit(1),unit(2),unit(3))) - require(a == b) - this.print("found:") - this.print(a) - this.print(b) - } - - () -/* - def joins(s1:String, s2:String) = s1.endsWith(s2.substring(0,1)) - val w1 = amb(List("the","that","a")) - val w2 = amb(List("frog","elephant","thing")) - val w3 = amb(List("walked","treaded","grows")) - val w4 = amb(List("slowly","quickly")) - require(joins(w1,w2)) - require(joins(w2,w3)) - require(joins(w3,w4)) - yld(List(w1,w2,w3,w4)) - - // result: that thing grows slowly -*/ - -/* -val i = amb(low to high) -val j = amb(i to high) -val k = amb(j to high) -require(i*i + j*j == k*k) -yld((i,j,k)) - -//output using (low=1,high=20): -// (3,4,5) -// (5,12,13) -// (6,8,10) -// (8,15,17) -// (9,12,15) -// (12,16,20) -*/ - } -} - - -trait AmbProg2 extends AmbProg1 { - - override def test(x: Rep[Int]): Rep[Unit] = { - - reset { - val a = amb(List(unit(1),unit(2),unit(3),unit(4))) - val b = amb(List(unit(1),unit(2),unit(3),unit(4))) - val c = amb(List(unit(1),unit(2),unit(3),unit(4))) - require(a != b) - require(b != c) -// require(c != a) - - this.print("found:") - this.print(a) - this.print(b) - this.print(c) - } - - () - } - - -} - - - - -class TestCPS extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test9-" - - def testCps1 = { - withOutFile(prefix+"cps1") { - new CpsProg1 with ArithExp with EqualExp with IfThenElseExp with PrintExp with ScalaCompile { self => - val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - //override def compile - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"cps1") - } - - def testCps2 = { - withOutFile(prefix+"cps2") { - new CpsProg2 with ArithExp with EqualExp with IfThenElseExp with PrintExp with ScalaCompile { self => - val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - //override def compile - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"cps2") - } - - def testAmb1a = { - withOutFile(prefix+"amb1a") { - new AmbProg1 with ArithExp with EqualExp with IfThenElseExp with PrintExp with ScalaCompile { self => - val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - //override def compile - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"amb1a") - } - - def testAmb1b = { - withOutFile(prefix+"amb1b") { - new AmbProg1 with ArithExp with EqualExpOpt with IfThenElseExpOpt with BooleanOpsExp with PrintExp with ScalaCompile { self => - val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - //override def compile - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"amb1b") - } - - def testAmb2a = { - withOutFile(prefix+"amb2a") { - new AmbProg2 with ArithExp with EqualExp with IfThenElseExp with PrintExp with ScalaCompile { self => - val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - //override def compile - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"amb2a") - } - - def testAmb2b = { - withOutFile(prefix+"amb2b") { - new AmbProg2 with ArithExp with EqualExpOpt with IfThenElseExpOpt with BooleanOpsExp with PrintExp with ScalaCompile { self => - val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } - //override def compile - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - } - } - assertFileEqualsCheck(prefix+"amb2b") - } - -} diff --git a/test-src/epfl/test9-experimental/TestCrossStage.scala b/test-src/epfl/test9-experimental/TestCrossStage.scala deleted file mode 100644 index c144eb20..00000000 --- a/test-src/epfl/test9-experimental/TestCrossStage.scala +++ /dev/null @@ -1,84 +0,0 @@ -package scala.lms -package epfl -package test9 - -import common._ -import internal.{ScalaCompile} -import test1._ -import test7.{Print,PrintExp,ScalaGenPrint} -import test7.{ArrayLoops,ArrayLoopsExp,ArrayLoopsFatExp,ScalaGenArrayLoops,ScalaGenFatArrayLoopsFusionOpt} - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} -import collection.mutable.ArrayBuffer - -class TestCrossStage extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test9-" - - trait DSL extends Functions with ArrayBufferOps with Arith with OrderingOps with Variables with LiftVariables with IfThenElse with RangeOps with Print { - def infix_toDouble(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] - def test(x: Rep[Int]): Rep[Unit] - - implicit def funToRep[T:Manifest,U:Manifest](x:T=>U): Rep[T=>U] - implicit def abToRep[T:Manifest](x:ArrayBuffer[T]): Rep[ArrayBuffer[T]] - } - - trait Impl extends DSL with StaticDataExp with FunctionsExp with ArrayBufferOpsExp with ArithExp with OrderingOpsExp with VariablesExp - with IfThenElseExp with RangeOpsExp with PrintExp with ScalaCompile { self => - - def funToRep[T:Manifest,U:Manifest](x:T=>U): Rep[T=>U] = staticData(x) - def abToRep[T:Manifest](x:ArrayBuffer[T]): Rep[ArrayBuffer[T]] = staticData(x) - - override val verbosity = 2 - val codegen = new ScalaGenStaticData with ScalaGenFunctions with ScalaGenArrayBufferOps with ScalaGenArith with ScalaGenOrderingOps - with ScalaGenVariables with ScalaGenIfThenElse with ScalaGenRangeOps - with ScalaGenPrint { - val IR: self.type = self - } - codegen.emitSource(test, "Test", new PrintWriter(System.out)) - println("-- running program") - val f = compile(test) - f(21) - } - - // don't know sharing dependencies between static data in general -- for now assume there is no sharing - - def testCrossStage1 = { - withOutFile(prefix+"csp1") { - val f = (x: Int) => println("this is external non-DSL code: " + (2*x)) - - trait Prog extends DSL { - def test(x: Rep[Int]) = { - - doApply(f, x) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"csp1") - } - - def testCrossStage2 = { - withOutFile(prefix+"csp2") { - val acc = new ArrayBuffer[Int] - - trait Prog extends DSL { - def test(x: Rep[Int]) = { -// Broke test compilation: -// array buffer switched to use implicis instead of -// infix methods and lifting did not kick in - acc += x - acc += x - print("done") - } - } - new Prog with Impl - - println("accumulated: " + acc.mkString(",")) - } - assertFileEqualsCheck(prefix+"csp2") - } - -} diff --git a/test-src/epfl/test9-experimental/TestStruct.scala b/test-src/epfl/test9-experimental/TestStruct.scala deleted file mode 100644 index 206f635e..00000000 --- a/test-src/epfl/test9-experimental/TestStruct.scala +++ /dev/null @@ -1,303 +0,0 @@ -package scala.lms -package epfl -package test9 - -import common._ -import internal.{FatExpressions,GenericFatCodegen} - - -import test1._ -import test7.{Print,PrintExp,ScalaGenPrint} -import test7.{ArrayLoops,ArrayLoopsExp,ArrayLoopsFatExp,ScalaGenArrayLoops,ScalaGenFatArrayLoopsFusionOpt} -import scala.reflect.SourceContext - -import util.OverloadHack - -import java.io.{PrintWriter,StringWriter,FileOutputStream} - - -trait ComplexArith extends Arith with ComplexBase with OverloadHack { - - def infix_+(x: Rep[Complex], y: Rep[Complex])(implicit o: Overloaded1): Rep[Complex] = Complex(x.re + y.re, x.im + y.im) - def infix_-(x: Rep[Complex], y: Rep[Complex])(implicit o: Overloaded1): Rep[Complex] = Complex(x.re - y.re, x.im - y.im) - //def infix_*(x: Rep[Complex], y: Rep[Complex]): Rep[Complex] = Complex(x.re + y.re, x.im + y.im) - -} - -trait ComplexBase extends Arith with StructOps { - type Complex = Record { val re: Double; val im: Double } - def Complex(r: Rep[Double], i: Rep[Double]): Rep[Complex] = new Record { val re = r; val im = i } -} - -// ------ struct impl follows, will move to common once stable - -trait StructExpOptLoops extends StructExpOptCommon with ArrayLoopsExp { - - case class ArraySoaTag[T](base: StructTag[T], len: Exp[Int]) extends StructTag[T] - - override def simpleLoop[A:Manifest](size: Exp[Int], v: Sym[Int], body: Def[A])(implicit pos: SourceContext): Exp[A] = body match { - case ArrayElem(Block(Def(Struct(tag:StructTag[A], elems)))) => - struct[A](ArraySoaTag[A](tag,size), elems.map(p=>(p._1,simpleLoop(size, v, ArrayElem(Block(p._2)))(p._2.tp.arrayManifest, pos)))) - case ArrayElem(Block(Def(ArrayIndex(b,`v`)))) if infix_length(b) == size => b.asInstanceOf[Exp[A]] - // eta-reduce! <--- should live elsewhere, not specific to struct - // rewrite loop(a.length) { i => a(i) } to a - case _ => super.simpleLoop(size, v, body) - } - - - override def infix_at[T:Manifest](a: Rep[Array[T]], i: Rep[Int]): Rep[T] = a match { - case Def(Struct(ArraySoaTag(tag,len),elems: Iterable[(String,Rep[Array[T]])])) => - def unwrap[A](m:Manifest[Array[A]]): Manifest[A] = m.typeArguments match { - case a::_ => mtype(a) - case _ => - if (m.erasure.isArray) mtype(Manifest.classType(m.erasure.getComponentType)) - else { printerr("warning: expect type Array[A] but got "+m); mtype(manifest[Any]) } - } - struct[T](tag.asInstanceOf[StructTag[T]], elems.map(p=>(p._1,infix_at(p._2, i)(unwrap(p._2.tp))))) - case _ => super.infix_at(a,i) - } - - override def infix_length[T:Manifest](a: Rep[Array[T]]): Rep[Int] = a match { - case Def(Struct(ArraySoaTag(tag,len),elems)) => len - case _ => super.infix_length(a) - } - -} - -// ----- test cases - - -class TestStruct extends FileDiffSuite { - - val prefix = home + "test-out/epfl/test9-" - - trait DSL extends ComplexArith with ArrayLoops with Arith with OrderingOps with Variables with LiftVariables with IfThenElse with RangeOps with Print { - def infix_toDouble(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] - def test(x: Rep[Int]): Rep[Unit] - } - - trait Impl extends DSL with StructExp with ArrayLoopsExp with StructExpOptLoops with ArithExp with OrderingOpsExp with VariablesExp - with IfThenElseExp with RangeOpsExp with PrintExp { self => - override val verbosity = 1 - val codegen = new ScalaGenArrayLoops with ScalaGenStruct with ScalaGenArith with ScalaGenOrderingOps - with ScalaGenVariables with ScalaGenIfThenElse with ScalaGenRangeOps - with ScalaGenPrint { val IR: self.type = self } - - /*override def fresh[T:Manifest]: Sym[T] = Sym[T] { - if (nVars < 3) { - System.out.println(nVars) - (new Exception).printStackTrace - } - - nVars += 1; nVars -1 - }*/ - - { - val x = fresh[Int] - val y = reifyEffects(test(x)) - //globalDefs.foreach(Console.println _) - codegen.emitSource(List(x),y, "Test", new PrintWriter(System.out)) - codegen.emitDataStructures(new PrintWriter(System.out)) - } - } - - trait ImplFused extends DSL with StructExp with StructExpOptLoops with StructFatExpOptCommon with ArrayLoopsFatExp with ArithExp with OrderingOpsExp with VariablesExp - with IfThenElseExp with RangeOpsExp with PrintExp { self => - override val verbosity = 1 - val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenFatStruct with ScalaGenArith with ScalaGenOrderingOps - with ScalaGenVariables with ScalaGenIfThenElse with ScalaGenRangeOps - with ScalaGenPrint { val IR: self.type = self; - override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } - { - val x = fresh[Int] - val y = reifyEffects(test(x)) - //globalDefs.foreach(Console.println _) - codegen.emitSource(List(x),y, "Test", new PrintWriter(System.out)) - codegen.emitDataStructures(new PrintWriter(System.out)) - } - } - - - - def testStruct1 = { - withOutFile(prefix+"struct1") { - // test variable splitting - trait Prog extends DSL { - def test(x: Rep[Int]) = { - var c = Complex(x.toDouble, 0) - c = c + Complex(0,x.toDouble) - print(c) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"struct1") - } - - def testStruct2 = { - withOutFile(prefix+"struct2") { - // test basic struct flattening (loops, variables, conditionals) - println("REMARK: this makes only sense with fat codegen (computation duplicated and some structs not removed otherwise)") - trait Prog extends DSL { - def test(x: Rep[Int]) = { - // split loops (rely on fusion, don't want to duplicate computation!) - - val vector1 = array(100) { i => Complex(i.toDouble, 0.0 - i.toDouble) } - val vector2 = array(100) { i => Complex(0.0 - i.toDouble, i.toDouble) } - - var vvar = vector2 - - // split conditionals (be careful about effects) - - val vector3 = if (x > 7) vector1 else vvar - - // conditional is reflected because it reads vvar -- effect ordering for split terms? - - vvar = vector1 - - print(vvar) - print(vector3) - } - } - new Prog with Impl - } - assertFileEqualsCheck(prefix+"struct2") - } - - def testStruct2b = { - withOutFile(prefix+"struct2b") { - // test basic struct flattening (loops, variables, conditionals) - trait Prog extends DSL { - def test(x: Rep[Int]) = { - // split loops (rely on fusion, don't want to duplicate computation!) - - val vector1 = array(100) { i => Complex(i.toDouble, 0.0 - i.toDouble) } - val vector2 = array(100) { i => Complex(0.0 - i.toDouble, i.toDouble) } - - var vvar = vector2 - - // split conditionals (be careful about effects) - - val vector3 = if (x > 7) { - print("foobar true") - vector1 - } else { - print("foobar false") - vvar - } - - vvar = vector1 - - print(vvar) - print(vector3) - } - } - new Prog with ImplFused - } - assertFileEqualsCheck(prefix+"struct2b") - } - - def testStruct3 = { - withOutFile(prefix+"struct3") { - // fuse conjugate computation with construction, essentially a no-op - trait Prog extends DSL { - def test(x: Rep[Int]) = { - - val vector1 = array(100) { i => Complex(i.toDouble, 0.0 - i.toDouble) } - - def conj(c: Rep[Complex]) = Complex(c.re, 0.0 - c.im) - def infix_map[A:Manifest,B:Manifest](c: Rep[Array[A]], f: Rep[A] => Rep[B]) = array(c.length) { i => f(c.at(i)) } - - val vector3 = vector1.map(conj) - - print(vector3) - } - } - new Prog with ImplFused { - // TODO: use a generic Opt trait instead of defining rewrites here... - override def infix_-(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = (x, y) match { - case (x, Def(Minus(Const(0.0),y))) => infix_+(x,y) - case _ => super.infix_-(x,y) - } - override def infix_+(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = (x, y) match { - case (Const(0.0), y) => y - case _ => super.infix_+(x,y) - } - } - } - assertFileEqualsCheck(prefix+"struct3") - } - - def testStruct4 = { - withOutFile(prefix+"struct4") { - trait Prog extends DSL { - // recognize that only imaginary part is modified, real part untouched - def test(x: Rep[Int]) = { - - val vector1 = array(100) { i => Complex(i.toDouble, 0.0 - i.toDouble) } - val vector2 = array(100) { i => Complex(0.0 - i.toDouble, i.toDouble) } - - def conj(c: Rep[Complex]) = Complex(c.re, 0.0 - c.im) - def infix_map[A:Manifest,B:Manifest](c: Rep[Array[A]], f: Rep[A] => Rep[B]) = array(c.length) { i => f(c.at(i)) } - - var vvar = vector1 // force access outside conditional, otherwise construction will be moved inside, defeating purpose of test - - // result of this conditional should be a *single* array - // containing the flattened im fields. re fields should be - // unconditional. - val vector3 = if (x > 7) { - vector1.map(conj) - } else { - vector1 - } - - print(vector3) - } - } - new Prog with ImplFused - } - assertFileEqualsCheck(prefix+"struct4") - } - - // Two classes are generated if the refined type’s fields have the same type but different names - def testStruct5 = { - withOutFile(prefix+"struct5") { - - trait Vectors extends StructOps { - type Vector2D = Record { val x: Double; val y: Double } - def Vector2D(px: Rep[Double], py: Rep[Double]): Rep[Vector2D] = new Record { val x = px; val y = py } - } - - trait Prog extends DSL with Vectors { - def test(x: Rep[Int]) = { - print(Vector2D(1, 2)) - print(Complex(3, 4)) - } - } - - new Prog with Impl - } - assertFileEqualsCheck(prefix+"struct5") - } - - // Only one class is generated if refined types are equivalent (their fields have the same names and types) - def testStruct6 = { - withOutFile(prefix+"struct6") { - - trait Complex2 extends Arith with StructOps { - type Complex2 = Record { val re: Double; val im: Double } - def Complex2(r: Rep[Double], i: Rep[Double]): Rep[Complex2] = new Record { val re = r; val im = i } - } - - trait Prog extends DSL with Complex2 { - def test(x: Rep[Int]) = { - print(Complex2(1, 2)) - print(Complex(3, 4)) - } - } - - new Prog with Impl - } - assertFileEqualsCheck(prefix+"struct6") - } -} From f843409be38076604bb9d171cddf75c74eade2ce Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Sun, 18 Dec 2016 16:00:45 -0500 Subject: [PATCH 02/10] change package name --- src/common/ArrayBufferOps.scala | 4 +- src/common/ArrayOps.scala | 2 +- src/common/Base.scala | 2 +- src/common/BooleanOps.scala | 4 +- src/common/CastingOps.scala | 4 +- src/common/Compile.scala | 2 +- src/common/DSLBase.scala | 2 +- src/common/DSLOps.scala | 4 +- src/common/DateOps.scala | 6 +- src/common/DynamicRecord.scala | 6 +- src/common/Equal.scala | 6 +- src/common/ExceptionOps.scala | 2 +- src/common/ExportGraph.scala | 2 +- src/common/ForwardTransformer.scala | 4 +- src/common/FractionalOps.scala | 4 +- src/common/FunctionBlocks.scala | 6 +- src/common/Functions.scala | 6 +- src/common/GeneratorOps.scala | 4 +- src/common/GregorianCalendarOps.scala | 4 +- src/common/HashCodeOps.scala | 6 +- src/common/HashMapOps.scala | 4 +- src/common/IOOps.scala | 4 +- src/common/IfThenElse.scala | 4 +- src/common/ImplicitOps.scala | 2 +- src/common/IterableOps.scala | 2 +- src/common/Iterator.scala | 4 +- src/common/ListBuffer.scala | 4 +- src/common/ListOps.scala | 4 +- src/common/LivenessOpt.scala | 4 +- src/common/LoopFusionOpt.scala | 2 +- src/common/Loops.scala | 4 +- src/common/MathOps.scala | 2 +- src/common/MiscOps.scala | 4 +- src/common/MultiMap.scala | 6 +- src/common/NumericOps.scala | 2 +- src/common/ObjectOps.scala | 6 +- src/common/OrderingOps.scala | 4 +- src/common/Packages.scala | 4 +- src/common/PrimitiveOps.scala | 4 +- src/common/RangeOps.scala | 4 +- src/common/SeqOps.scala | 2 +- src/common/SetOps.scala | 4 +- src/common/SimpleDateFormatOps.scala | 4 +- src/common/SimplifyTransform.scala | 2 +- src/common/SplitEffects.scala | 4 +- src/common/StaticData.scala | 4 +- src/common/StringOps.scala | 6 +- src/common/Structs.scala | 8 +- src/common/SynchronizedArrayBufferOps.scala | 4 +- src/common/TreeSet.scala | 4 +- src/common/TupleOps.scala | 6 +- src/common/Unchecked.scala | 2 +- src/common/UninlinedFunctions.scala | 6 +- src/common/Variables.scala | 4 +- src/common/While.scala | 6 +- src/internal/BlockTraversal.scala | 2 +- src/internal/CCodegen.scala | 4 +- src/internal/CLikeCodegen.scala | 2 +- src/internal/CodeMotion.scala | 2 +- src/internal/Config.scala | 2 +- src/internal/CudaCodegen.scala | 2 +- src/internal/Effects.scala | 2 +- src/internal/Exceptions.scala | 2 +- src/internal/Expressions.scala | 2 +- src/internal/ExtendedExpressions.scala | 2 +- src/internal/FatCodegen.scala | 2 +- src/internal/FatExpressions.scala | 2 +- src/internal/FatScheduling.scala | 2 +- src/internal/FatTraversal.scala | 2 +- src/internal/GPUCodegen.scala | 2 +- src/internal/GenericCodegen.scala | 2 +- .../GraphVizDependencyGraphExport.scala | 4 +- src/internal/GraphVizExport.scala | 2 +- src/internal/OpenCLCodegen.scala | 2 +- src/internal/ScalaCodegen.scala | 2 +- src/internal/ScalaCompile.scala | 4 +- src/internal/ScalaConciseCodegen.scala | 4 +- src/internal/Scheduling.scala | 2 +- src/internal/SymMetaDataFixerTransform.scala | 4 +- src/internal/Transforming.scala | 4 +- src/internal/Traversal.scala | 2 +- src/internal/Utils.scala | 2 +- src/util/ClosureCompare.scala | 2 +- src/util/GencodeCleaner.scala | 2 +- src/util/GraphUtil.scala | 2 +- src/util/OverloadHack.scala | 2 +- src/util/ReflectionUtil.scala | 2 +- src/util/Timing.scala | 6 +- test-out/epfl/test13-interpret2.check | 98 +++++++++---------- test-out/epfl/test13-interpret3.check | 40 ++++---- test-out/epfl/test13-stable1.check | 2 +- test-out/epfl/test13-stable2.check | 4 +- test-out/epfl/test14-queries2.check | 2 +- test-out/epfl/test14-queries3.check | 2 +- test-out/epfl/test14-queries4.check | 2 +- test-out/epfl/test3-match1-dot.check | 4 +- test-out/epfl/test3-match1.check | 4 +- test-out/epfl/test3-match2-dot.check | 2 +- test-out/epfl/test3-match2.check | 2 +- test-out/epfl/test3-parse1-dot.check | 86 ++++++++-------- test-out/epfl/test3-parse1.check | 86 ++++++++-------- test-out/epfl/test3-parse2-dot.check | 56 +++++------ test-out/epfl/test3-parse2.check | 56 +++++------ test-out/epfl/test4-counter1.check | 8 +- test-out/epfl/test4-counter2.check | 8 +- test-out/epfl/test4-fac3.check | 2 +- test-out/epfl/test4-matchernew1.check | 24 ++--- test-out/epfl/test4-matchernew1b.check | 24 ++--- test-out/epfl/test4-matchernew2.check | 26 ++--- test-out/epfl/test4-matchernew2b.check | 26 ++--- test-out/epfl/test4-stream1.check | 8 +- test-out/epfl/test6-vectors.check | 6 +- test-src/epfl/FileDiffSuite.scala | 2 +- test-src/epfl/test1-arith/Arith.scala | 2 +- test-src/epfl/test1-arith/Arrays.scala | 2 +- test-src/epfl/test1-arith/Relat.scala | 2 +- test-src/epfl/test1-arith/TestConstCSE.scala | 2 +- test-src/epfl/test1-arith/TestNumeric.scala | 2 +- test-src/epfl/test1-arith/Trig.scala | 2 +- test-src/epfl/test14-scratch/TestCGen.scala | 2 +- test-src/epfl/test2-fft/DisableOpts.scala | 2 +- test-src/epfl/test2-fft/TestFFT.scala | 2 +- test-src/epfl/test2-fft/TestPower.scala | 2 +- test-src/epfl/test2-fft/TestSort.scala | 2 +- 124 files changed, 452 insertions(+), 452 deletions(-) diff --git a/src/common/ArrayBufferOps.scala b/src/common/ArrayBufferOps.scala index 876db24f..f8ab7920 100644 --- a/src/common/ArrayBufferOps.scala +++ b/src/common/ArrayBufferOps.scala @@ -1,10 +1,10 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter import scala.reflect.SourceContext import scala.collection.mutable.ArrayBuffer -import scala.virtualization.lms.internal.GenericNestedCodegen +import scala.lms.internal.GenericNestedCodegen import collection.mutable.ArrayBuffer import scala.reflect.SourceContext diff --git a/src/common/ArrayOps.scala b/src/common/ArrayOps.scala index a9b5a2af..4f43ee1c 100644 --- a/src/common/ArrayOps.scala +++ b/src/common/ArrayOps.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter diff --git a/src/common/Base.scala b/src/common/Base.scala index c7970497..714cd6fc 100644 --- a/src/common/Base.scala +++ b/src/common/Base.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import internal._ diff --git a/src/common/BooleanOps.scala b/src/common/BooleanOps.scala index 061b2665..13268753 100644 --- a/src/common/BooleanOps.scala +++ b/src/common/BooleanOps.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.virtualization.lms.internal._ +import scala.lms.internal._ trait LiftBoolean { this: Base => diff --git a/src/common/CastingOps.scala b/src/common/CastingOps.scala index 61bf6c99..4675fd82 100644 --- a/src/common/CastingOps.scala +++ b/src/common/CastingOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.util.OverloadHack +import scala.lms.util.OverloadHack import scala.reflect.SourceContext trait CastingOps extends Variables with OverloadHack { diff --git a/src/common/Compile.scala b/src/common/Compile.scala index 87ce734d..7391636c 100644 --- a/src/common/Compile.scala +++ b/src/common/Compile.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import internal.ScalaCompile diff --git a/src/common/DSLBase.scala b/src/common/DSLBase.scala index 072f5468..ea02712c 100644 --- a/src/common/DSLBase.scala +++ b/src/common/DSLBase.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common trait DSLBase extends BaseExp with UncheckedOps { diff --git a/src/common/DSLOps.scala b/src/common/DSLOps.scala index e60a74a0..541b330d 100644 --- a/src/common/DSLOps.scala +++ b/src/common/DSLOps.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException} +import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException} //TODO: is this used at all? should it be merge with DeliteOps? diff --git a/src/common/DateOps.scala b/src/common/DateOps.scala index 0283656f..4ca96799 100644 --- a/src/common/DateOps.scala +++ b/src/common/DateOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common -import scala.virtualization.lms.common._ -import scala.virtualization.lms.internal.CNestedCodegen +import scala.lms.common._ +import scala.lms.internal.CNestedCodegen import scala.reflect.SourceContext import java.util.Date diff --git a/src/common/DynamicRecord.scala b/src/common/DynamicRecord.scala index 83adbee6..995f4037 100644 --- a/src/common/DynamicRecord.scala +++ b/src/common/DynamicRecord.scala @@ -1,11 +1,11 @@ -/*package scala.virtualization.lms +/*package scala.lms package common import java.io._ import reflect.ClassManifest import scala.collection.mutable.HashMap -import scala.virtualization.lms.internal._ -import scala.virtualization.lms.util._ +import scala.lms.internal._ +import scala.lms.util._ import scala.reflect.SourceContext object DynamicRecordsMap extends Serializable { diff --git a/src/common/Equal.scala b/src/common/Equal.scala index 0a90d250..92092e8c 100644 --- a/src/common/Equal.scala +++ b/src/common/Equal.scala @@ -1,10 +1,10 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.util.OverloadHack +import scala.lms.util.OverloadHack import scala.reflect.SourceContext -import scala.virtualization.lms.internal.CNestedCodegen +import scala.lms.internal.CNestedCodegen trait LiftEquals extends Base { this: Equal => diff --git a/src/common/ExceptionOps.scala b/src/common/ExceptionOps.scala index e4f094d3..224f0b8f 100644 --- a/src/common/ExceptionOps.scala +++ b/src/common/ExceptionOps.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter diff --git a/src/common/ExportGraph.scala b/src/common/ExportGraph.scala index 92eef6c1..f82516dc 100644 --- a/src/common/ExportGraph.scala +++ b/src/common/ExportGraph.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import internal.GraphVizExport diff --git a/src/common/ForwardTransformer.scala b/src/common/ForwardTransformer.scala index 2d473ac1..9a035ad4 100644 --- a/src/common/ForwardTransformer.scala +++ b/src/common/ForwardTransformer.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import scala.collection.{immutable,mutable} import scala.reflect.SourceContext -import scala.virtualization.lms.internal.{Effects, FatTransforming, AbstractSubstTransformer, FatBlockTraversal} +import scala.lms.internal.{Effects, FatTransforming, AbstractSubstTransformer, FatBlockTraversal} trait ForwardTransformer extends internal.AbstractSubstTransformer with internal.FatBlockTraversal { self => val IR: FatTransforming with Effects //LoopsFatExp with IfThenElseFatExp diff --git a/src/common/FractionalOps.scala b/src/common/FractionalOps.scala index 96c1bef5..3ed56e75 100644 --- a/src/common/FractionalOps.scala +++ b/src/common/FractionalOps.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.virtualization.lms.internal.GenericNestedCodegen +import scala.lms.internal.GenericNestedCodegen trait FractionalOps extends ImplicitOps { def infix_/[A,T](lhs: Rep[T], rhs: Rep[A])(implicit c: A => T, f: Fractional[T], mA: Manifest[A], mT: Manifest[T], pos: SourceContext) = fractional_divide(lhs,implicit_convert[A,T](rhs)) diff --git a/src/common/FunctionBlocks.scala b/src/common/FunctionBlocks.scala index 93159e6a..98cf0855 100644 --- a/src/common/FunctionBlocks.scala +++ b/src/common/FunctionBlocks.scala @@ -1,10 +1,10 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.virtualization.lms.internal.{Blocks, Effects, AbstractTransformer} -import scala.virtualization.lms.util.OverloadHack +import scala.lms.internal.{Blocks, Effects, AbstractTransformer} +import scala.lms.util.OverloadHack /* * This trait allows functions to be stored as case class parameters in a way that works correctly diff --git a/src/common/Functions.scala b/src/common/Functions.scala index d309ca15..8154b54a 100644 --- a/src/common/Functions.scala +++ b/src/common/Functions.scala @@ -1,10 +1,10 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException, CNestedCodegen} -import scala.virtualization.lms.util.ClosureCompare +import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException, CNestedCodegen} +import scala.lms.util.ClosureCompare import scala.reflect.SourceContext diff --git a/src/common/GeneratorOps.scala b/src/common/GeneratorOps.scala index 23a6ae3d..0b71a608 100644 --- a/src/common/GeneratorOps.scala +++ b/src/common/GeneratorOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.common._ +import scala.lms.common._ import scala.collection.mutable import scala.collection.mutable.Set import scala.reflect.SourceContext diff --git a/src/common/GregorianCalendarOps.scala b/src/common/GregorianCalendarOps.scala index 30797b93..7c0f278e 100644 --- a/src/common/GregorianCalendarOps.scala +++ b/src/common/GregorianCalendarOps.scala @@ -1,7 +1,7 @@ -package scala.virtualization.lms +package scala.lms package common -import scala.virtualization.lms.common._ +import scala.lms.common._ import scala.reflect.SourceContext import java.util.Date import java.util.GregorianCalendar diff --git a/src/common/HashCodeOps.scala b/src/common/HashCodeOps.scala index 46df8b91..b9270d14 100644 --- a/src/common/HashCodeOps.scala +++ b/src/common/HashCodeOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common -import scala.virtualization.lms.util._ -import scala.virtualization.lms.internal._ +import scala.lms.util._ +import scala.lms.internal._ trait HashCodeOps extends Base { def __hashCode(x: Rep[Any]): Rep[Int] diff --git a/src/common/HashMapOps.scala b/src/common/HashMapOps.scala index ff6396cd..f425616d 100644 --- a/src/common/HashMapOps.scala +++ b/src/common/HashMapOps.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter import java.io.StringWriter -import scala.virtualization.lms.internal._ +import scala.lms.internal._ import scala.collection.mutable.{HashMap,Set} import scala.reflect.SourceContext diff --git a/src/common/IOOps.scala b/src/common/IOOps.scala index bebbbbaf..74f52201 100644 --- a/src/common/IOOps.scala +++ b/src/common/IOOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.{File, FileReader, FileWriter, BufferedReader, BufferedWriter, PrintWriter, FileOutputStream, ObjectOutputStream, FileInputStream, ObjectInputStream} -import scala.virtualization.lms.internal.{GenerationFailedException, GenericNestedCodegen} +import scala.lms.internal.{GenerationFailedException, GenericNestedCodegen} import util.OverloadHack import scala.reflect.SourceContext diff --git a/src/common/IfThenElse.scala b/src/common/IfThenElse.scala index 6aa74c75..e79c5dbd 100644 --- a/src/common/IfThenElse.scala +++ b/src/common/IfThenElse.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.virtualization.lms.internal.{GenericNestedCodegen, GenericFatCodegen, GenerationFailedException} +import scala.lms.internal.{GenericNestedCodegen, GenericFatCodegen, GenerationFailedException} trait IfThenElse extends Base { def __ifThenElse[T:Manifest](cond: Rep[Boolean], thenp: => Rep[T], elsep: => Rep[T])(implicit pos: SourceContext): Rep[T] diff --git a/src/common/ImplicitOps.scala b/src/common/ImplicitOps.scala index da88a99b..37372160 100644 --- a/src/common/ImplicitOps.scala +++ b/src/common/ImplicitOps.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter diff --git a/src/common/IterableOps.scala b/src/common/IterableOps.scala index 296b32cc..a41ec626 100644 --- a/src/common/IterableOps.scala +++ b/src/common/IterableOps.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter diff --git a/src/common/Iterator.scala b/src/common/Iterator.scala index fbd00297..4b0d9e9b 100644 --- a/src/common/Iterator.scala +++ b/src/common/Iterator.scala @@ -1,6 +1,6 @@ -package scala.virtualization.lms.common +package scala.lms.common -import scala.virtualization.lms.internal._ +import scala.lms.internal._ trait Iterator extends Base with Variables { class IteratorOps[A: Manifest](x: Rep[scala.Iterator[A]]) { diff --git a/src/common/ListBuffer.scala b/src/common/ListBuffer.scala index 520f3cb0..18eaaaa7 100644 --- a/src/common/ListBuffer.scala +++ b/src/common/ListBuffer.scala @@ -1,7 +1,7 @@ -package scala.virtualization.lms.common +package scala.lms.common import scala.collection.mutable -import scala.virtualization.lms.internal._ +import scala.lms.internal._ trait ListBuffer extends Base with Expressions with Variables { class ListBufferOps[A:Manifest](x: Rep[mutable.ListBuffer[A]]) { diff --git a/src/common/ListOps.scala b/src/common/ListOps.scala index e3ab5d61..51508f7c 100644 --- a/src/common/ListOps.scala +++ b/src/common/ListOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal.GenericNestedCodegen +import scala.lms.internal.GenericNestedCodegen import scala.reflect.SourceContext trait ListOps extends Variables { diff --git a/src/common/LivenessOpt.scala b/src/common/LivenessOpt.scala index fffdcb5c..0ec49082 100644 --- a/src/common/LivenessOpt.scala +++ b/src/common/LivenessOpt.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal.NestedBlockTraversal +import scala.lms.internal.NestedBlockTraversal import scala.collection.mutable diff --git a/src/common/LoopFusionOpt.scala b/src/common/LoopFusionOpt.scala index c7134767..379c51a1 100644 --- a/src/common/LoopFusionOpt.scala +++ b/src/common/LoopFusionOpt.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import internal.CodeMotion diff --git a/src/common/Loops.scala b/src/common/Loops.scala index 9eddaabe..1509ee44 100644 --- a/src/common/Loops.scala +++ b/src/common/Loops.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.virtualization.lms.internal.{FatBlockTraversal,GenericNestedCodegen,GenericFatCodegen} +import scala.lms.internal.{FatBlockTraversal,GenericNestedCodegen,GenericFatCodegen} import scala.reflect.SourceContext trait Loops extends Base { // no surface constructs for now diff --git a/src/common/MathOps.scala b/src/common/MathOps.scala index fe53e007..ce0d75aa 100755 --- a/src/common/MathOps.scala +++ b/src/common/MathOps.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter diff --git a/src/common/MiscOps.scala b/src/common/MiscOps.scala index 25c87af1..a1ace074 100644 --- a/src/common/MiscOps.scala +++ b/src/common/MiscOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal._ +import scala.lms.internal._ import scala.reflect.SourceContext trait MiscOps extends Base { diff --git a/src/common/MultiMap.scala b/src/common/MultiMap.scala index 67ff6174..2f40c5b8 100644 --- a/src/common/MultiMap.scala +++ b/src/common/MultiMap.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal._ +import scala.lms.internal._ import scala.collection.mutable.{HashMap,Set} import scala.reflect.SourceContext @@ -115,7 +115,7 @@ trait ScalaGenHashMultiMapOpt extends GenericNestedCodegen with ScalaGenEffect { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case m@HashMultiMapNew(size, spkey, spvalue) => { // Sanity check - //if (m.mV != manifest[Set[scala.virtualization.lms.common.DynamicRecord]]) + //if (m.mV != manifest[Set[scala.lms.common.DynamicRecord]]) // throw new RuntimeException("ScalaGenHashMultiMapOpt can only be used with sets of DynamicRecords (you provided " + remap(m.mV)) val value = if (spvalue != "") spvalue else remap(m.mV) emitValDef(sym, "new Array[" + value + "](" + size + ")") diff --git a/src/common/NumericOps.scala b/src/common/NumericOps.scala index 80a109a3..19b1b5e4 100644 --- a/src/common/NumericOps.scala +++ b/src/common/NumericOps.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter diff --git a/src/common/ObjectOps.scala b/src/common/ObjectOps.scala index c306d58e..170fbb6a 100644 --- a/src/common/ObjectOps.scala +++ b/src/common/ObjectOps.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.util.OverloadHack -import scala.virtualization.lms.internal.{GenerationFailedException} +import scala.lms.util.OverloadHack +import scala.lms.internal.{GenerationFailedException} import scala.reflect.SourceContext trait ObjectOps extends Variables with OverloadHack { diff --git a/src/common/OrderingOps.scala b/src/common/OrderingOps.scala index 7829dedd..3b784472 100644 --- a/src/common/OrderingOps.scala +++ b/src/common/OrderingOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.util.OverloadHack +import scala.lms.util.OverloadHack import scala.reflect.SourceContext trait OrderingOps extends Base with Variables with OverloadHack { diff --git a/src/common/Packages.scala b/src/common/Packages.scala index 5ec6d417..62af7d2f 100644 --- a/src/common/Packages.scala +++ b/src/common/Packages.scala @@ -1,7 +1,7 @@ -package scala.virtualization.lms +package scala.lms package common -import scala.virtualization.lms.common._ +import scala.lms.common._ /** * IR: this is the front-end that defines what operations are available in user applications. Backends can share diff --git a/src/common/PrimitiveOps.scala b/src/common/PrimitiveOps.scala index 9e65f24a..b02c5b10 100644 --- a/src/common/PrimitiveOps.scala +++ b/src/common/PrimitiveOps.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.util.OverloadHack +import scala.lms.util.OverloadHack import scala.reflect.SourceContext trait LiftPrimitives { diff --git a/src/common/RangeOps.scala b/src/common/RangeOps.scala index 4532cf93..c79688c0 100644 --- a/src/common/RangeOps.scala +++ b/src/common/RangeOps.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException} +import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException} import scala.reflect.SourceContext trait RangeOps extends Base { diff --git a/src/common/SeqOps.scala b/src/common/SeqOps.scala index 89d5cf37..e60810ca 100644 --- a/src/common/SeqOps.scala +++ b/src/common/SeqOps.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter diff --git a/src/common/SetOps.scala b/src/common/SetOps.scala index 9444ce09..6b2ce191 100644 --- a/src/common/SetOps.scala +++ b/src/common/SetOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal._ +import scala.lms.internal._ import scala.collection.mutable.Set import scala.reflect.SourceContext diff --git a/src/common/SimpleDateFormatOps.scala b/src/common/SimpleDateFormatOps.scala index ca3fb56b..fe8f9461 100644 --- a/src/common/SimpleDateFormatOps.scala +++ b/src/common/SimpleDateFormatOps.scala @@ -1,7 +1,7 @@ -package scala.virtualization.lms +package scala.lms package common -import scala.virtualization.lms.common._ +import scala.lms.common._ import scala.reflect.SourceContext import java.util.Date import java.text.SimpleDateFormat diff --git a/src/common/SimplifyTransform.scala b/src/common/SimplifyTransform.scala index 18c10b34..a737402e 100644 --- a/src/common/SimplifyTransform.scala +++ b/src/common/SimplifyTransform.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import scala.reflect.SourceContext diff --git a/src/common/SplitEffects.scala b/src/common/SplitEffects.scala index 55de8bb2..56488857 100644 --- a/src/common/SplitEffects.scala +++ b/src/common/SplitEffects.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.virtualization.lms.internal.{GenericNestedCodegen, GenericFatCodegen, GenerationFailedException} +import scala.lms.internal.{GenericNestedCodegen, GenericFatCodegen, GenerationFailedException} trait SplitEffectsExpFat extends IfThenElseFatExp with WhileExp with PreviousIterationDummyExp { this: BooleanOpsExp with EqualExpBridge => diff --git a/src/common/StaticData.scala b/src/common/StaticData.scala index 819cceb7..936f11df 100644 --- a/src/common/StaticData.scala +++ b/src/common/StaticData.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal.GenericNestedCodegen +import scala.lms.internal.GenericNestedCodegen import scala.reflect.SourceContext trait StaticData extends Base { diff --git a/src/common/StringOps.scala b/src/common/StringOps.scala index 5d3acffc..d225a044 100644 --- a/src/common/StringOps.scala +++ b/src/common/StringOps.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.util.OverloadHack -import scala.virtualization.lms.internal.{GenerationFailedException,CNestedCodegen} +import scala.lms.util.OverloadHack +import scala.lms.internal.{GenerationFailedException,CNestedCodegen} import scala.reflect.SourceContext trait LiftString { diff --git a/src/common/Structs.scala b/src/common/Structs.scala index 16d38f69..2a879a6e 100644 --- a/src/common/Structs.scala +++ b/src/common/Structs.scala @@ -1,10 +1,10 @@ -package scala.virtualization.lms +package scala.lms package common -import scala.virtualization.lms.common._ +import scala.lms.common._ -import scala.virtualization.lms.util.OverloadHack -import scala.virtualization.lms.internal.{GenericNestedCodegen, GenericFatCodegen} +import scala.lms.util.OverloadHack +import scala.lms.internal.{GenericNestedCodegen, GenericFatCodegen} import scala.reflect.{SourceContext, RefinedManifest} import java.io.{StringWriter,PrintWriter} import scala.language.dynamics diff --git a/src/common/SynchronizedArrayBufferOps.scala b/src/common/SynchronizedArrayBufferOps.scala index 5acd75ea..01b3fe94 100644 --- a/src/common/SynchronizedArrayBufferOps.scala +++ b/src/common/SynchronizedArrayBufferOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal.GenericNestedCodegen +import scala.lms.internal.GenericNestedCodegen import collection.mutable.ArrayBuffer import scala.reflect.SourceContext diff --git a/src/common/TreeSet.scala b/src/common/TreeSet.scala index 7027aec8..84b56c5d 100644 --- a/src/common/TreeSet.scala +++ b/src/common/TreeSet.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms.common +package scala.lms.common import scala.collection.mutable import scala.reflect.SourceContext -import scala.virtualization.lms.internal._ +import scala.lms.internal._ trait TreeSet extends Base with Variables with Pointer { diff --git a/src/common/TupleOps.scala b/src/common/TupleOps.scala index 11e31258..13089b8c 100644 --- a/src/common/TupleOps.scala +++ b/src/common/TupleOps.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package common -import scala.virtualization.lms.common._ -import scala.virtualization.lms.internal.GenericCodegen +import scala.lms.common._ +import scala.lms.internal.GenericCodegen import scala.reflect.SourceContext import java.io.PrintWriter diff --git a/src/common/Unchecked.scala b/src/common/Unchecked.scala index db4b80de..aa8af092 100644 --- a/src/common/Unchecked.scala +++ b/src/common/Unchecked.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter diff --git a/src/common/UninlinedFunctions.scala b/src/common/UninlinedFunctions.scala index 39a85d9e..5f97df6a 100644 --- a/src/common/UninlinedFunctions.scala +++ b/src/common/UninlinedFunctions.scala @@ -1,10 +1,10 @@ -/*package scala.virtualization.lms +/*package scala.lms package common import java.io.PrintWriter import java.io.StringWriter -import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException} -import scala.virtualization.lms.util.ClosureCompare +import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException} +import scala.lms.util.ClosureCompare import scala.reflect.SourceContext diff --git a/src/common/Variables.scala b/src/common/Variables.scala index 8c30dfec..8244ce5a 100755 --- a/src/common/Variables.scala +++ b/src/common/Variables.scala @@ -1,10 +1,10 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter import scala.reflect.SourceContext import scala.collection.mutable -import scala.virtualization.lms.util.OverloadHack +import scala.lms.util.OverloadHack import scala.reflect.SourceContext trait LiftVariables extends Base { diff --git a/src/common/While.scala b/src/common/While.scala index e4089346..c34e5be4 100644 --- a/src/common/While.scala +++ b/src/common/While.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal.GenericNestedCodegen -import scala.virtualization.lms.internal.CNestedCodegen +import scala.lms.internal.GenericNestedCodegen +import scala.lms.internal.CNestedCodegen import scala.reflect.SourceContext trait While extends Base { diff --git a/src/internal/BlockTraversal.scala b/src/internal/BlockTraversal.scala index dcf3b651..13560a0c 100644 --- a/src/internal/BlockTraversal.scala +++ b/src/internal/BlockTraversal.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import util.GraphUtil diff --git a/src/internal/CCodegen.scala b/src/internal/CCodegen.scala index 6380b96a..25fa2c59 100644 --- a/src/internal/CCodegen.scala +++ b/src/internal/CCodegen.scala @@ -1,7 +1,7 @@ -package scala.virtualization.lms +package scala.lms package internal -import scala.virtualization.lms.common.{Base,BaseExp} +import scala.lms.common.{Base,BaseExp} import java.io.{FileWriter, StringWriter, PrintWriter, File} import java.util.ArrayList import collection.mutable.{ListBuffer, ArrayBuffer, LinkedList, HashMap, ListMap, HashSet, Map => MMap} diff --git a/src/internal/CLikeCodegen.scala b/src/internal/CLikeCodegen.scala index b24da551..64f5ac78 100644 --- a/src/internal/CLikeCodegen.scala +++ b/src/internal/CLikeCodegen.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import java.io.PrintWriter diff --git a/src/internal/CodeMotion.scala b/src/internal/CodeMotion.scala index 503d8e4d..6f7aa17c 100644 --- a/src/internal/CodeMotion.scala +++ b/src/internal/CodeMotion.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import util.GraphUtil diff --git a/src/internal/Config.scala b/src/internal/Config.scala index ea067e92..54845976 100644 --- a/src/internal/Config.scala +++ b/src/internal/Config.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal object Config { diff --git a/src/internal/CudaCodegen.scala b/src/internal/CudaCodegen.scala index c3bdbdb7..42440843 100644 --- a/src/internal/CudaCodegen.scala +++ b/src/internal/CudaCodegen.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import java.io.{FileWriter, StringWriter, PrintWriter, File} diff --git a/src/internal/Effects.scala b/src/internal/Effects.scala index 7274bb5f..93c73c0e 100644 --- a/src/internal/Effects.scala +++ b/src/internal/Effects.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import scala.reflect.SourceContext diff --git a/src/internal/Exceptions.scala b/src/internal/Exceptions.scala index c367c0a5..a5774163 100644 --- a/src/internal/Exceptions.scala +++ b/src/internal/Exceptions.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal class GenerationFailedException(msg: String) extends Exception(msg) \ No newline at end of file diff --git a/src/internal/Expressions.scala b/src/internal/Expressions.scala index 841b80df..a88ff522 100644 --- a/src/internal/Expressions.scala +++ b/src/internal/Expressions.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import scala.reflect.SourceContext diff --git a/src/internal/ExtendedExpressions.scala b/src/internal/ExtendedExpressions.scala index 5e4450cf..ceefd75d 100644 --- a/src/internal/ExtendedExpressions.scala +++ b/src/internal/ExtendedExpressions.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import scala.reflect.SourceContext diff --git a/src/internal/FatCodegen.scala b/src/internal/FatCodegen.scala index cc1d2eee..0588dded 100644 --- a/src/internal/FatCodegen.scala +++ b/src/internal/FatCodegen.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import util.GraphUtil diff --git a/src/internal/FatExpressions.scala b/src/internal/FatExpressions.scala index b875d6b2..3181e999 100644 --- a/src/internal/FatExpressions.scala +++ b/src/internal/FatExpressions.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal trait FatExpressions extends Expressions { diff --git a/src/internal/FatScheduling.scala b/src/internal/FatScheduling.scala index 0783cf72..b1d3eae4 100644 --- a/src/internal/FatScheduling.scala +++ b/src/internal/FatScheduling.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import util.GraphUtil diff --git a/src/internal/FatTraversal.scala b/src/internal/FatTraversal.scala index b5a1c29f..a3ef6107 100644 --- a/src/internal/FatTraversal.scala +++ b/src/internal/FatTraversal.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import util.GraphUtil diff --git a/src/internal/GPUCodegen.scala b/src/internal/GPUCodegen.scala index c1d7c169..6769fdc3 100644 --- a/src/internal/GPUCodegen.scala +++ b/src/internal/GPUCodegen.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import java.io.{StringWriter, PrintWriter, File} diff --git a/src/internal/GenericCodegen.scala b/src/internal/GenericCodegen.scala index 6e5f7201..ada9810b 100644 --- a/src/internal/GenericCodegen.scala +++ b/src/internal/GenericCodegen.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import util.GraphUtil diff --git a/src/internal/GraphVizDependencyGraphExport.scala b/src/internal/GraphVizDependencyGraphExport.scala index 8da94fc5..6cf6fc28 100644 --- a/src/internal/GraphVizDependencyGraphExport.scala +++ b/src/internal/GraphVizDependencyGraphExport.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package internal import java.io.{File, FileWriter, PrintWriter} -import scala.virtualization.lms.util.ReflectionUtil +import scala.lms.util.ReflectionUtil import scala.reflect.SourceContext /** diff --git a/src/internal/GraphVizExport.scala b/src/internal/GraphVizExport.scala index fb11b876..a01ee214 100644 --- a/src/internal/GraphVizExport.scala +++ b/src/internal/GraphVizExport.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import java.io.{PrintWriter, FileOutputStream} diff --git a/src/internal/OpenCLCodegen.scala b/src/internal/OpenCLCodegen.scala index 7ec7b862..545d7c48 100755 --- a/src/internal/OpenCLCodegen.scala +++ b/src/internal/OpenCLCodegen.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import java.io.{FileWriter, StringWriter, PrintWriter, File} diff --git a/src/internal/ScalaCodegen.scala b/src/internal/ScalaCodegen.scala index d1e2f3bc..d084556f 100644 --- a/src/internal/ScalaCodegen.scala +++ b/src/internal/ScalaCodegen.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import java.io.{File, FileWriter, PrintWriter} diff --git a/src/internal/ScalaCompile.scala b/src/internal/ScalaCompile.scala index 5d8a5639..eeea9667 100644 --- a/src/internal/ScalaCompile.scala +++ b/src/internal/ScalaCompile.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package internal import java.io.{StringWriter, PrintWriter} -import scala.virtualization.lms.util._ +import scala.lms.util._ import scala.sys.process._ import scala.tools.nsc._ diff --git a/src/internal/ScalaConciseCodegen.scala b/src/internal/ScalaConciseCodegen.scala index 87e95c53..26ada79b 100644 --- a/src/internal/ScalaConciseCodegen.scala +++ b/src/internal/ScalaConciseCodegen.scala @@ -1,8 +1,8 @@ -package scala.virtualization.lms +package scala.lms package internal import java.io.{File, FileWriter, PrintWriter} -import scala.virtualization.lms.util.ReflectionUtil +import scala.lms.util.ReflectionUtil import scala.reflect.SourceContext /** diff --git a/src/internal/Scheduling.scala b/src/internal/Scheduling.scala index 7f9bfa8a..f6dbea64 100644 --- a/src/internal/Scheduling.scala +++ b/src/internal/Scheduling.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import util.GraphUtil diff --git a/src/internal/SymMetaDataFixerTransform.scala b/src/internal/SymMetaDataFixerTransform.scala index 32982645..1ce58761 100644 --- a/src/internal/SymMetaDataFixerTransform.scala +++ b/src/internal/SymMetaDataFixerTransform.scala @@ -1,7 +1,7 @@ -package scala.virtualization.lms +package scala.lms package internal -import scala.virtualization.lms.util.ReflectionUtil +import scala.lms.util.ReflectionUtil /** * There are some meta-data added to Sym using infix diff --git a/src/internal/Transforming.scala b/src/internal/Transforming.scala index c22a956c..329c5cb0 100644 --- a/src/internal/Transforming.scala +++ b/src/internal/Transforming.scala @@ -1,10 +1,10 @@ -package scala.virtualization.lms +package scala.lms package internal import util.OverloadHack import scala.collection.{immutable,mutable} import scala.reflect.SourceContext -import scala.virtualization.lms.common.WorklistTransformer +import scala.lms.common.WorklistTransformer trait AbstractTransformer { val IR: Expressions with Blocks with OverloadHack diff --git a/src/internal/Traversal.scala b/src/internal/Traversal.scala index 090134a6..db39a7de 100644 --- a/src/internal/Traversal.scala +++ b/src/internal/Traversal.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal import util.GraphUtil diff --git a/src/internal/Utils.scala b/src/internal/Utils.scala index 3086c04f..7736176f 100644 --- a/src/internal/Utils.scala +++ b/src/internal/Utils.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package internal // TODO: add logging, etc. diff --git a/src/util/ClosureCompare.scala b/src/util/ClosureCompare.scala index 16a0344f..a1bfe6cc 100644 --- a/src/util/ClosureCompare.scala +++ b/src/util/ClosureCompare.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package util import java.io._ diff --git a/src/util/GencodeCleaner.scala b/src/util/GencodeCleaner.scala index 8f914ab1..0205b4d8 100644 --- a/src/util/GencodeCleaner.scala +++ b/src/util/GencodeCleaner.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms.util +package scala.lms.util import java.util.regex.Pattern import scala.collection.mutable.ListBuffer diff --git a/src/util/GraphUtil.scala b/src/util/GraphUtil.scala index dd774ab2..96324b71 100644 --- a/src/util/GraphUtil.scala +++ b/src/util/GraphUtil.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package util import scala.collection.mutable.Map diff --git a/src/util/OverloadHack.scala b/src/util/OverloadHack.scala index 04f80b35..00cbe582 100644 --- a/src/util/OverloadHack.scala +++ b/src/util/OverloadHack.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package util // hack to appease erasure diff --git a/src/util/ReflectionUtil.scala b/src/util/ReflectionUtil.scala index b270780c..f6cee792 100644 --- a/src/util/ReflectionUtil.scala +++ b/src/util/ReflectionUtil.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package util /** diff --git a/src/util/Timing.scala b/src/util/Timing.scala index 680a4b4f..ae37c57c 100644 --- a/src/util/Timing.scala +++ b/src/util/Timing.scala @@ -1,9 +1,9 @@ -package scala.virtualization.lms +package scala.lms package util import scala.reflect.{SourceContext, RefinedManifest} -import scala.virtualization.lms.common._ -import scala.virtualization.lms.internal._ +import scala.lms.common._ +import scala.lms.internal._ trait Timing extends Base { def timeGeneratedCode[A: Manifest](f: => Rep[A], msg: Rep[String] = unit("")): Rep[A] diff --git a/test-out/epfl/test13-interpret2.check b/test-out/epfl/test13-interpret2.check index bf27b950..b44c2b1f 100644 --- a/test-out/epfl/test13-interpret2.check +++ b/test-out/epfl/test13-interpret2.check @@ -2,12 +2,12 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(85) /***************************************** Emitting Generated Code *******************************************/ -class staged0(px2:scala.virtualization.lms.common.Compile,px3:Object,px4:Object,px1:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px8:Object,px9:Object,px7:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px13:Object,px14:Object,px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px17:Object,px18:Object,px22:Object,px23:Object,px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px27:Object,px28:Object,px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px32:Object,px33:Object,px31:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px37:Object,px38:Object,px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px42:Object,px43:Object,px41:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px46:Object,px47:Object,px51:Object,px52:Object,px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px56:Object,px57:Object,px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px61:Object,px62:Object,px60:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px66:Object,px67:Object,px65:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px71:Object,px72:Object,px70:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px75:Object,px76:Object,px80:Object,px81:Object,px79:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged0(px2:scala.lms.common.Compile,px3:Object,px4:Object,px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px8:Object,px9:Object,px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px13:Object,px14:Object,px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px17:Object,px18:Object,px22:Object,px23:Object,px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px27:Object,px28:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px32:Object,px33:Object,px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px37:Object,px38:Object,px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px42:Object,px43:Object,px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px46:Object,px47:Object,px51:Object,px52:Object,px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px56:Object,px57:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px61:Object,px62:Object,px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px66:Object,px67:Object,px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px71:Object,px72:Object,px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px75:Object,px76:Object,px80:Object,px81:Object,px79:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x0:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { -val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x3 = px3 // static data: val x4 = px4 // static data: -val x5 = new scala.virtualization.lms.epfl.test13.RFun { +val x5 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x3.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -19,7 +19,7 @@ val x1 = px1 // static data: RCell(dyn - ConstN(0)) val x6 = x1.set(x5) val x8 = px8 // static data: val x9 = px9 // static data: -val x10 = new scala.virtualization.lms.epfl.test13.RFun { +val x10 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x8.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -31,7 +31,7 @@ val x7 = px7 // static data: RCell(dyn - AssignN(x,ConstN(0))) val x11 = x7.set(x10) val x13 = px13 // static data: val x14 = px14 // static data: -val x15 = new scala.virtualization.lms.epfl.test13.RFun { +val x15 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x13.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -43,7 +43,7 @@ val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x16 = x12.set(x15) val x17 = px17 // static data: val x18 = px18 // static data: -val x19 = new scala.virtualization.lms.epfl.test13.RFun { +val x19 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x17.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -54,7 +54,7 @@ def execInt(f: HM): Int = fInt(f) val x20 = x12.set(x19) val x22 = px22 // static data: val x23 = px23 // static data: -val x24 = new scala.virtualization.lms.epfl.test13.RFun { +val x24 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x22.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -66,7 +66,7 @@ val x21 = px21 // static data: RCell(dyn - ConstN(-1)) val x25 = x21.set(x24) val x27 = px27 // static data: val x28 = px28 // static data: -val x29 = new scala.virtualization.lms.epfl.test13.RFun { +val x29 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x27.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -78,7 +78,7 @@ val x26 = px26 // static data: RCell(dyn - AddN(LookupN(n),ConstN(-1))) val x30 = x26.set(x29) val x32 = px32 // static data: val x33 = px33 // static data: -val x34 = new scala.virtualization.lms.epfl.test13.RFun { +val x34 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x32.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -90,7 +90,7 @@ val x31 = px31 // static data: RCell(dyn - AssignN(n,AddN(LookupN(n),ConstN(-1)) val x35 = x31.set(x34) val x37 = px37 // static data: val x38 = px38 // static data: -val x39 = new scala.virtualization.lms.epfl.test13.RFun { +val x39 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x37.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -102,7 +102,7 @@ val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x40 = x36.set(x39) val x42 = px42 // static data: val x43 = px43 // static data: -val x44 = new scala.virtualization.lms.epfl.test13.RFun { +val x44 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x42.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -114,7 +114,7 @@ val x41 = px41 // static data: RCell(dyn - LookupN(a)) val x45 = x41.set(x44) val x46 = px46 // static data: val x47 = px47 // static data: -val x48 = new scala.virtualization.lms.epfl.test13.RFun { +val x48 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x46.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -125,7 +125,7 @@ def execInt(f: HM): Int = fInt(f) val x49 = x12.set(x48) val x51 = px51 // static data: val x52 = px52 // static data: -val x53 = new scala.virtualization.lms.epfl.test13.RFun { +val x53 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x51.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -137,7 +137,7 @@ val x50 = px50 // static data: RCell(dyn - AppN(LookupN(a),LookupN(n))) val x54 = x50.set(x53) val x56 = px56 // static data: val x57 = px57 // static data: -val x58 = new scala.virtualization.lms.epfl.test13.RFun { +val x58 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x56.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -149,7 +149,7 @@ val x55 = px55 // static data: RCell(dyn - AddN(LookupN(x),AppN(LookupN(a),Looku val x59 = x55.set(x58) val x61 = px61 // static data: val x62 = px62 // static data: -val x63 = new scala.virtualization.lms.epfl.test13.RFun { +val x63 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x61.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -161,7 +161,7 @@ val x60 = px60 // static data: RCell(dyn - AssignN(x,AddN(LookupN(x),AppN(Lookup val x64 = x60.set(x63) val x66 = px66 // static data: val x67 = px67 // static data: -val x68 = new scala.virtualization.lms.epfl.test13.RFun { +val x68 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x66.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -173,7 +173,7 @@ val x65 = px65 // static data: RCell(dyn - SeqN(List(AssignN(n,AddN(LookupN(n),C val x69 = x65.set(x68) val x71 = px71 // static data: val x72 = px72 // static data: -val x73 = new scala.virtualization.lms.epfl.test13.RFun { +val x73 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x71.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -185,7 +185,7 @@ val x70 = px70 // static data: RCell(dyn - WhileN(LookupN(n),SeqN(List(AssignN(n val x74 = x70.set(x73) val x75 = px75 // static data: val x76 = px76 // static data: -val x77 = new scala.virtualization.lms.epfl.test13.RFun { +val x77 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x75.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -196,7 +196,7 @@ def execInt(f: HM): Int = fInt(f) val x78 = x36.set(x77) val x80 = px80 // static data: val x81 = px81 // static data: -val x82 = new scala.virtualization.lms.epfl.test13.RFun { +val x82 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x80.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -250,7 +250,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(94) /***************************************** Emitting Generated Code *******************************************/ -class staged3(px1:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged3(px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x91:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x1 = px1 // static data: RCell(dyn - ConstN(0)) val x92 = x1.value @@ -268,7 +268,7 @@ at Sym(98)=Reflect(HashMapUpdate(Sym(96),Const(x),Sym(97)),Summary(false,false,f /***************************************** Emitting Generated Code *******************************************/ -class staged4(px1:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged4(px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x96:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x1 = px1 // static data: RCell(dyn - ConstN(0)) val x92 = x1.value @@ -373,7 +373,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(134 /***************************************** Emitting Generated Code *******************************************/ -class staged11(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px2:scala.virtualization.lms.common.Compile,px124:Object,px125:Object,px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged11(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px124:Object,px125:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x115:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value @@ -390,10 +390,10 @@ x121 val x134 = if (x122) { val x123 = println("spec-add-int: AddN(LookupN(n),ConstN(-1))") -val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x124 = px124 // static data: val x125 = px125 // static data: -val x126 = new scala.virtualization.lms.epfl.test13.RFun { +val x126 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x124.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -421,7 +421,7 @@ x134 /***************************************** Emitting Generated Code *******************************************/ -class staged12(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px2:scala.virtualization.lms.common.Compile,px143:Object,px144:Object,px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged12(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px143:Object,px144:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x136:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value @@ -438,10 +438,10 @@ x140 val x153 = if (x141) { val x142 = println("spec-add-int: AddN(LookupN(n),ConstN(-1))") -val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x143 = px143 // static data: val x144 = px144 // static data: -val x145 = new scala.virtualization.lms.epfl.test13.RFun { +val x145 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x143.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -473,7 +473,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(159 /***************************************** Emitting Generated Code *******************************************/ -class staged13(px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged13(px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x156:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x26 = px26 // static data: RCell(dyn - AddN(LookupN(n),ConstN(-1))) val x157 = x26.value @@ -491,7 +491,7 @@ at Sym(163)=Reflect(HashMapUpdate(Sym(161),Const(n),Sym(162)),Summary(false,fals /***************************************** Emitting Generated Code *******************************************/ -class staged14(px26:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged14(px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x161:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x26 = px26 // static data: RCell(dyn - AddN(LookupN(n),ConstN(-1))) val x157 = x26.value @@ -596,7 +596,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(186 /***************************************** Emitting Generated Code *******************************************/ -class staged21(px41:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged21(px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x181:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x41 = px41 // static data: RCell(dyn - LookupN(a)) val x182 = x41.value @@ -616,7 +616,7 @@ x186 /***************************************** Emitting Generated Code *******************************************/ -class staged22(px41:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged22(px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x188:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x41 = px41 // static data: RCell(dyn - LookupN(a)) val x182 = x41.value @@ -638,7 +638,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(214 /***************************************** Emitting Generated Code *******************************************/ -class staged23(px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px2:scala.virtualization.lms.common.Compile,px204:Object,px205:Object,px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged23(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px204:Object,px205:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x195:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value @@ -655,10 +655,10 @@ x201 val x214 = if (x202) { val x203 = println("spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))") -val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x204 = px204 // static data: val x205 = px205 // static data: -val x206 = new scala.virtualization.lms.epfl.test13.RFun { +val x206 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x204.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -686,7 +686,7 @@ x214 /***************************************** Emitting Generated Code *******************************************/ -class staged24(px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px2:scala.virtualization.lms.common.Compile,px223:Object,px224:Object,px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged24(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px223:Object,px224:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x216:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value @@ -703,10 +703,10 @@ x220 val x233 = if (x221) { val x222 = println("spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))") -val x2 = px2 // static data: IR:scala.virtualization.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 +val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x223 = px223 // static data: val x224 = px224 // static data: -val x225 = new scala.virtualization.lms.epfl.test13.RFun { +val x225 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] type HM = scala.collection.mutable.HashMap[String,Any] val fAny = x2.compile(x223.asInstanceOf[Rep[HM]=>Rep[Any]]) @@ -738,7 +738,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(239 /***************************************** Emitting Generated Code *******************************************/ -class staged25(px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged25(px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x236:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x55 = px55 // static data: RCell(dyn - AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))) val x237 = x55.value @@ -756,7 +756,7 @@ at Sym(243)=Reflect(HashMapUpdate(Sym(241),Const(x),Sym(242)),Summary(false,fals /***************************************** Emitting Generated Code *******************************************/ -class staged26(px55:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged26(px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x241:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x55 = px55 // static data: RCell(dyn - AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))) val x237 = x55.value @@ -774,7 +774,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(250 /***************************************** Emitting Generated Code *******************************************/ -class staged27(px31:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px60:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged27(px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x246:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x31 = px31 // static data: RCell(dyn - AssignN(n,AddN(LookupN(n),ConstN(-1)))) val x247 = x31.value @@ -792,7 +792,7 @@ x250 /***************************************** Emitting Generated Code *******************************************/ -class staged28(px31:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px60:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged28(px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x252:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x31 = px31 // static data: RCell(dyn - AssignN(n,AddN(LookupN(n),ConstN(-1)))) val x247 = x31.value @@ -812,7 +812,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(264 /***************************************** Emitting Generated Code *******************************************/ -class staged29(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px65:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged29(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x257:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value @@ -836,7 +836,7 @@ x264 /***************************************** Emitting Generated Code *******************************************/ -class staged30(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px65:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged30(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x266:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value @@ -891,7 +891,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(285 /***************************************** Emitting Generated Code *******************************************/ -class staged33(px7:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px70:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged33(px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x280:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x7 = px7 // static data: RCell(dyn - AssignN(x,ConstN(0))) val x281 = x7.value @@ -912,7 +912,7 @@ x285 /***************************************** Emitting Generated Code *******************************************/ -class staged34(px7:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px70:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged34(px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x287:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x7 = px7 // static data: RCell(dyn - AssignN(x,ConstN(0))) val x281 = x7.value @@ -936,7 +936,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(296 /***************************************** Emitting Generated Code *******************************************/ -class staged35(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged35(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x293:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value @@ -955,7 +955,7 @@ x296 /***************************************** Emitting Generated Code *******************************************/ -class staged36(px12:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px21:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged36(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x298:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value @@ -976,7 +976,7 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(306 /***************************************** Emitting Generated Code *******************************************/ -class staged37(px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged37(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x303:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value @@ -995,7 +995,7 @@ x306 /***************************************** Emitting Generated Code *******************************************/ -class staged38(px36:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun],px50:scala.virtualization.lms.epfl.test13.RCell[scala.virtualization.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { +class staged38(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { def apply(x308:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value diff --git a/test-out/epfl/test13-interpret3.check b/test-out/epfl/test13-interpret3.check index 4fa0fe35..5ec81a5e 100644 --- a/test-out/epfl/test13-interpret3.check +++ b/test-out/epfl/test13-interpret3.check @@ -1,11 +1,11 @@ call with arg Map(n -> 256, a -> SomethingElse) (re) compiling -read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) sym Sym(3) +read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) sym Sym(3) -- Sym(2) -read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) sym Sym(7) +read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) sym Sym(7) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(2),Const(n)) -read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) +read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(29),Summary(true,true,false,false,false,List(),List(),List(Sym(3)),List()),List(Sym(29))) @@ -18,23 +18,23 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(51) /***************************************** Emitting Generated Code *******************************************/ -class staged39(px3:scala.virtualization.lms.epfl.test13.RCell[Object],px5:Object,px7:scala.virtualization.lms.epfl.test13.RCell[Object],px9:Object,px12:scala.virtualization.lms.epfl.test13.RCell[Object],px14:Object,px16:Any,px21:Object,px31:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[scala.collection.mutable.HashMap[java.lang.String, Any], Any]],px33:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px40:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px47:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { +class staged39(px3:scala.lms.epfl.test13.RCell[Object],px5:Object,px7:scala.lms.epfl.test13.RCell[Object],px9:Object,px12:scala.lms.epfl.test13.RCell[Object],px14:Object,px16:Any,px21:Object,px31:scala.lms.epfl.test13.RCell[scala.Function1[scala.collection.mutable.HashMap[java.lang.String, Any], Any]],px33:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px40:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px47:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { def apply(x0:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { var x1 = x0 val x2 = x1 -val x3 = px3 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) +val x3 = px3 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) val x4 = x3.value -val x5 = px5 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$24@XXX +val x5 = px5 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$24@XXX val x6 = x4 == x5 val x51 = if (x6) { -val x7 = px7 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) +val x7 = px7 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) val x8 = x7.value -val x9 = px9 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$28@XXX +val x9 = px9 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$28@XXX val x10 = x8 == x9 val x44 = if (x10) { -val x12 = px12 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) +val x12 = px12 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) val x13 = x12.value -val x14 = px14 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$30@XXX +val x14 = px14 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$30@XXX val x15 = x13 == x14 val x37 = if (x15) { val x11 = x2("n") @@ -47,8 +47,8 @@ x18 } else false val x29 = if (x19) { -println("spec-add-int: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX") -val x21 = px21 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$25@XXX +println("spec-add-int: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX") +val x21 = px21 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$25@XXX x3.set(x21) val x23 = x11.asInstanceOf[Int] val x24 = x16.asInstanceOf[Int] @@ -92,14 +92,14 @@ x51 End of Generated Code *******************************************/ -spec-add-int: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX +spec-add-int: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX 255 call with arg Map(n -> 256, a -> SomethingElse) -- Sym(2) -read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) sym Sym(6) +read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) sym Sym(6) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(2),Const(n)) -read value RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) +read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(23),Summary(true,true,false,false,false,List(),List(),List(Sym(19)),List(Sym(19))),List(Sym(20), Sym(22), Sym(23))) @@ -109,16 +109,16 @@ warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(32) /***************************************** Emitting Generated Code *******************************************/ -class staged40(px6:scala.virtualization.lms.epfl.test13.RCell[Object],px8:Object,px12:scala.virtualization.lms.epfl.test13.RCell[Object],px14:Object,px2:scala.collection.mutable.HashMap[java.lang.String, Any],px16:Any,px19:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[scala.collection.mutable.HashMap[java.lang.String, Any], Any]],px21:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px28:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((Unit)=>(Any)) { +class staged40(px6:scala.lms.epfl.test13.RCell[Object],px8:Object,px12:scala.lms.epfl.test13.RCell[Object],px14:Object,px2:scala.collection.mutable.HashMap[java.lang.String, Any],px16:Any,px19:scala.lms.epfl.test13.RCell[scala.Function1[scala.collection.mutable.HashMap[java.lang.String, Any], Any]],px21:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px28:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((Unit)=>(Any)) { def apply(x5:Unit): Any = { -val x6 = px6 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) +val x6 = px6 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) val x7 = x6.value -val x8 = px8 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$28@XXX +val x8 = px8 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$28@XXX val x9 = x7 == x8 val x32 = if (x9) { -val x12 = px12 // static data: RCell(dyn - FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) +val x12 = px12 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) val x13 = x12.value -val x14 = px14 // static data: FUN:scala.virtualization.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$30@XXX +val x14 = px14 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$30@XXX val x15 = x13 == x14 val x25 = if (x15) { val x2 = px2 // static data: Map(n -> 256, a -> SomethingElse) diff --git a/test-out/epfl/test13-stable1.check b/test-out/epfl/test13-stable1.check index 0c2b800f..106568b8 100644 --- a/test-out/epfl/test13-stable1.check +++ b/test-out/epfl/test13-stable1.check @@ -1,7 +1,7 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged0(px3:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Int, Int]],px5:scala.virtualization.lms.epfl.test13.RCell[Int]) extends ((Int)=>(Int)) { +class staged0(px3:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Int, Int]],px5:scala.lms.epfl.test13.RCell[Int]) extends ((Int)=>(Int)) { def apply(x0:Int): Int = { val x1 = x0 + 1 val x2 = x0 * 2 diff --git a/test-out/epfl/test13-stable2.check b/test-out/epfl/test13-stable2.check index e26a7174..e30c9737 100644 --- a/test-out/epfl/test13-stable2.check +++ b/test-out/epfl/test13-stable2.check @@ -4,7 +4,7 @@ read value RCell(stable) sym Sym(3) /***************************************** Emitting Generated Code *******************************************/ -class staged4(px3:scala.virtualization.lms.epfl.test13.RCell[Int],px5:Int,px9:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px11:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { +class staged4(px3:scala.lms.epfl.test13.RCell[Int],px5:Int,px9:scala.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px11:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { def apply(x0:Int): Int = { val x3 = px3 // static data: RCell(stable) val x4 = x3.value @@ -58,7 +58,7 @@ read value RCell(stable) sym Sym(11) /***************************************** Emitting Generated Code *******************************************/ -class staged6(px11:scala.virtualization.lms.epfl.test13.RCell[Int],px13:Int,px17:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px19:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { +class staged6(px11:scala.lms.epfl.test13.RCell[Int],px13:Int,px17:scala.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px19:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { def apply(x8:Int): Int = { val x11 = px11 // static data: RCell(stable) val x12 = x11.value diff --git a/test-out/epfl/test14-queries2.check b/test-out/epfl/test14-queries2.check index 6375b403..91a28575 100644 --- a/test-out/epfl/test14-queries2.check +++ b/test-out/epfl/test14-queries2.check @@ -1,7 +1,7 @@ /***************************************** Emitting Generated Code *******************************************/ -import scala.virtualization.lms.epfl.test14.Schema +import scala.lms.epfl.test14.Schema class staged0 extends ((Unit)=>(Unit)) { def apply(x0:Unit): Unit = { println("rangeFromNames(\"Edna\",\"Bert\"):") diff --git a/test-out/epfl/test14-queries3.check b/test-out/epfl/test14-queries3.check index 19d0c2e2..4adf8171 100644 --- a/test-out/epfl/test14-queries3.check +++ b/test-out/epfl/test14-queries3.check @@ -1,7 +1,7 @@ /***************************************** Emitting Generated Code *******************************************/ -import scala.virtualization.lms.epfl.test14.Schema +import scala.lms.epfl.test14.Schema class staged1 extends ((Unit)=>(Unit)) { def apply(x0:Unit): Unit = { println("expertise(\"abstract\"):") diff --git a/test-out/epfl/test14-queries4.check b/test-out/epfl/test14-queries4.check index ee531905..4265c25d 100644 --- a/test-out/epfl/test14-queries4.check +++ b/test-out/epfl/test14-queries4.check @@ -1,7 +1,7 @@ /***************************************** Emitting Generated Code *******************************************/ -import scala.virtualization.lms.epfl.test14.Schema +import scala.lms.epfl.test14.Schema class staged2 extends ((Unit)=>(Unit)) { def apply(x0:Unit): Unit = { println("expertise2(\"abstract\"):") diff --git a/test-out/epfl/test3-match1-dot.check b/test-out/epfl/test3-match1-dot.check index 6b9096ba..6f7647a5 100644 --- a/test-out/epfl/test3-match1-dot.check +++ b/test-out/epfl/test3-match1-dot.check @@ -1,6 +1,6 @@ digraph G { "Sym(2)" [ -label="Sym(2) \n Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))" +label="Sym(2) \n Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))" shape=box color=red ] @@ -18,7 +18,7 @@ shape=box "Sym(2)" -> "Sym(4)" [color=red] "Sym(3)" -> "Sym(4)" [color=red] "Sym(6)" [ -label="Sym(6) \n Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))" +label="Sym(6) \n Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))" shape=box color=red ] diff --git a/test-out/epfl/test3-match1.check b/test-out/epfl/test3-match1.check index 41c00225..3c189f90 100644 --- a/test-out/epfl/test3-match1.check +++ b/test-out/epfl/test3-match1.check @@ -1,9 +1,9 @@ TP(Sym(1),Lambda()) -TP(Sym(2),Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))) +TP(Sym(2),Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))) TP(Sym(3),Test(Sym(2),7)) TP(Sym(4),Reify(Const(yes),List(Sym(2), Sym(3)))) TP(Sym(5),Lambda()) -TP(Sym(6),Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))) +TP(Sym(6),Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))) TP(Sym(7),Reify(Const(maybe),List(Sym(6)))) TP(Sym(8),Lambda()) TP(Sym(9),OrElse(List(Sym(4), Sym(7), Pure(Const(no))))) diff --git a/test-out/epfl/test3-match2-dot.check b/test-out/epfl/test3-match2-dot.check index b60aa5fe..1f98dd52 100644 --- a/test-out/epfl/test3-match2-dot.check +++ b/test-out/epfl/test3-match2-dot.check @@ -1,6 +1,6 @@ digraph G { "Sym(2)" [ -label="Sym(2) \n Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))" +label="Sym(2) \n Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))" shape=box color=red ] diff --git a/test-out/epfl/test3-match2.check b/test-out/epfl/test3-match2.check index 2870b929..ae4c40b7 100644 --- a/test-out/epfl/test3-match2.check +++ b/test-out/epfl/test3-match2.check @@ -1,5 +1,5 @@ TP(Sym(1),Lambda()) -TP(Sym(2),Deconstruct(class scala.virtualization.lms.epfl.test3.MatchProg$Success,Sym(0))) +TP(Sym(2),Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))) TP(Sym(3),Test(Sym(2),7)) TP(Sym(4),Reify(Const(yes),List(Sym(2), Sym(3)))) TP(Sym(5),Lambda()) diff --git a/test-out/epfl/test3-parse1-dot.check b/test-out/epfl/test3-parse1-dot.check index f7faef93..3cf8efdb 100644 --- a/test-out/epfl/test3-parse1-dot.check +++ b/test-out/epfl/test3-parse1-dot.check @@ -22,7 +22,7 @@ shape=box ] "Sym(2)" -> "Sym(4)" "Sym(6)" [ -label="Sym(6) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(4))" +label="Sym(6) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(4))" shape=box ] "Sym(4)" -> "Sym(6)" @@ -39,7 +39,7 @@ shape=box ] "Sym(7)" -> "Sym(9)" "Sym(11)" [ -label="Sym(11) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(9))" +label="Sym(11) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(9))" shape=box color=red ] @@ -67,7 +67,7 @@ shape=box ] "Sym(13)" -> "Sym(15)" "Sym(17)" [ -label="Sym(17) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(15))" +label="Sym(17) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(15))" shape=box ] "Sym(15)" -> "Sym(17)" @@ -95,7 +95,7 @@ shape=box ] "Sym(21)" -> "Sym(23)" "Sym(25)" [ -label="Sym(25) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(23))" +label="Sym(25) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(23))" shape=box color=red ] @@ -123,7 +123,7 @@ shape=box ] "Sym(27)" -> "Sym(29)" "Sym(31)" [ -label="Sym(31) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(29))" +label="Sym(31) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(29))" shape=box ] "Sym(29)" -> "Sym(31)" @@ -151,7 +151,7 @@ shape=box ] "Sym(35)" -> "Sym(37)" "Sym(39)" [ -label="Sym(39) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(37))" +label="Sym(39) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(37))" shape=box color=red ] @@ -179,7 +179,7 @@ shape=box ] "Sym(41)" -> "Sym(43)" "Sym(45)" [ -label="Sym(45) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(43))" +label="Sym(45) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(43))" shape=box ] "Sym(43)" -> "Sym(45)" @@ -207,7 +207,7 @@ shape=box ] "Sym(49)" -> "Sym(51)" "Sym(53)" [ -label="Sym(53) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(51))" +label="Sym(53) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(51))" shape=box color=red ] @@ -235,7 +235,7 @@ shape=box ] "Sym(55)" -> "Sym(57)" "Sym(59)" [ -label="Sym(59) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(57))" +label="Sym(59) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(57))" shape=box ] "Sym(57)" -> "Sym(59)" @@ -263,7 +263,7 @@ shape=box ] "Sym(63)" -> "Sym(65)" "Sym(67)" [ -label="Sym(67) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(65))" +label="Sym(67) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(65))" shape=box color=red ] @@ -291,7 +291,7 @@ shape=box ] "Sym(69)" -> "Sym(71)" "Sym(73)" [ -label="Sym(73) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(71))" +label="Sym(73) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(71))" shape=box ] "Sym(71)" -> "Sym(73)" @@ -308,7 +308,7 @@ shape=box ] "Sym(74)" -> "Sym(76)" "Sym(78)" [ -label="Sym(78) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(76))" +label="Sym(78) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(76))" shape=box color=red ] @@ -336,7 +336,7 @@ shape=box ] "Sym(80)" -> "Sym(82)" "Sym(84)" [ -label="Sym(84) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(82))" +label="Sym(84) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(82))" shape=box ] "Sym(82)" -> "Sym(84)" @@ -353,7 +353,7 @@ shape=box ] "Sym(85)" -> "Sym(87)" "Sym(89)" [ -label="Sym(89) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(87))" +label="Sym(89) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(87))" shape=box color=red ] @@ -381,7 +381,7 @@ shape=box ] "Sym(91)" -> "Sym(93)" "Sym(95)" [ -label="Sym(95) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(93))" +label="Sym(95) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(93))" shape=box ] "Sym(93)" -> "Sym(95)" @@ -409,7 +409,7 @@ shape=box ] "Sym(99)" -> "Sym(101)" "Sym(103)" [ -label="Sym(103) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(101))" +label="Sym(103) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(101))" shape=box color=red ] @@ -437,7 +437,7 @@ shape=box ] "Sym(105)" -> "Sym(107)" "Sym(109)" [ -label="Sym(109) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(107))" +label="Sym(109) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(107))" shape=box ] "Sym(107)" -> "Sym(109)" @@ -465,7 +465,7 @@ shape=box ] "Sym(113)" -> "Sym(115)" "Sym(117)" [ -label="Sym(117) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(115))" +label="Sym(117) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(115))" shape=box color=red ] @@ -493,7 +493,7 @@ shape=box ] "Sym(119)" -> "Sym(121)" "Sym(123)" [ -label="Sym(123) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(121))" +label="Sym(123) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(121))" shape=box ] "Sym(121)" -> "Sym(123)" @@ -521,7 +521,7 @@ shape=box ] "Sym(127)" -> "Sym(129)" "Sym(131)" [ -label="Sym(131) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(129))" +label="Sym(131) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(129))" shape=box color=red ] @@ -549,7 +549,7 @@ shape=box ] "Sym(133)" -> "Sym(135)" "Sym(137)" [ -label="Sym(137) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(135))" +label="Sym(137) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(135))" shape=box ] "Sym(135)" -> "Sym(137)" @@ -599,7 +599,7 @@ shape=box ] "Sym(147)" -> "Sym(149)" "Sym(151)" [ -label="Sym(151) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(149))" +label="Sym(151) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(149))" shape=box color=red ] @@ -633,7 +633,7 @@ shape=box ] "Sym(155)" -> "Sym(157)" "Sym(159)" [ -label="Sym(159) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(157))" +label="Sym(159) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(157))" shape=box ] "Sym(157)" -> "Sym(159)" @@ -650,7 +650,7 @@ shape=box ] "Sym(160)" -> "Sym(162)" "Sym(164)" [ -label="Sym(164) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(162))" +label="Sym(164) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(162))" shape=box color=red ] @@ -678,7 +678,7 @@ shape=box ] "Sym(166)" -> "Sym(168)" "Sym(170)" [ -label="Sym(170) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(168))" +label="Sym(170) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(168))" shape=box ] "Sym(168)" -> "Sym(170)" @@ -706,7 +706,7 @@ shape=box ] "Sym(174)" -> "Sym(176)" "Sym(178)" [ -label="Sym(178) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(176))" +label="Sym(178) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(176))" shape=box color=red ] @@ -734,7 +734,7 @@ shape=box ] "Sym(180)" -> "Sym(182)" "Sym(184)" [ -label="Sym(184) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(182))" +label="Sym(184) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(182))" shape=box ] "Sym(182)" -> "Sym(184)" @@ -762,7 +762,7 @@ shape=box ] "Sym(188)" -> "Sym(190)" "Sym(192)" [ -label="Sym(192) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(190))" +label="Sym(192) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(190))" shape=box color=red ] @@ -790,7 +790,7 @@ shape=box ] "Sym(194)" -> "Sym(196)" "Sym(198)" [ -label="Sym(198) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(196))" +label="Sym(198) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(196))" shape=box ] "Sym(196)" -> "Sym(198)" @@ -818,7 +818,7 @@ shape=box ] "Sym(202)" -> "Sym(204)" "Sym(206)" [ -label="Sym(206) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(204))" +label="Sym(206) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(204))" shape=box color=red ] @@ -846,7 +846,7 @@ shape=box ] "Sym(208)" -> "Sym(210)" "Sym(212)" [ -label="Sym(212) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(210))" +label="Sym(212) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(210))" shape=box ] "Sym(210)" -> "Sym(212)" @@ -874,7 +874,7 @@ shape=box ] "Sym(216)" -> "Sym(218)" "Sym(220)" [ -label="Sym(220) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(218))" +label="Sym(220) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(218))" shape=box color=red ] @@ -902,7 +902,7 @@ shape=box ] "Sym(222)" -> "Sym(224)" "Sym(226)" [ -label="Sym(226) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(224))" +label="Sym(226) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(224))" shape=box ] "Sym(224)" -> "Sym(226)" @@ -919,7 +919,7 @@ shape=box ] "Sym(227)" -> "Sym(229)" "Sym(231)" [ -label="Sym(231) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(229))" +label="Sym(231) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(229))" shape=box color=red ] @@ -947,7 +947,7 @@ shape=box ] "Sym(233)" -> "Sym(235)" "Sym(237)" [ -label="Sym(237) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(235))" +label="Sym(237) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(235))" shape=box ] "Sym(235)" -> "Sym(237)" @@ -964,7 +964,7 @@ shape=box ] "Sym(238)" -> "Sym(240)" "Sym(242)" [ -label="Sym(242) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(240))" +label="Sym(242) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(240))" shape=box color=red ] @@ -992,7 +992,7 @@ shape=box ] "Sym(244)" -> "Sym(246)" "Sym(248)" [ -label="Sym(248) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(246))" +label="Sym(248) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(246))" shape=box ] "Sym(246)" -> "Sym(248)" @@ -1020,7 +1020,7 @@ shape=box ] "Sym(252)" -> "Sym(254)" "Sym(256)" [ -label="Sym(256) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(254))" +label="Sym(256) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(254))" shape=box color=red ] @@ -1048,7 +1048,7 @@ shape=box ] "Sym(258)" -> "Sym(260)" "Sym(262)" [ -label="Sym(262) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(260))" +label="Sym(262) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(260))" shape=box ] "Sym(260)" -> "Sym(262)" @@ -1076,7 +1076,7 @@ shape=box ] "Sym(266)" -> "Sym(268)" "Sym(270)" [ -label="Sym(270) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(268))" +label="Sym(270) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(268))" shape=box color=red ] @@ -1104,7 +1104,7 @@ shape=box ] "Sym(272)" -> "Sym(274)" "Sym(276)" [ -label="Sym(276) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(274))" +label="Sym(276) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(274))" shape=box ] "Sym(274)" -> "Sym(276)" @@ -1132,7 +1132,7 @@ shape=box ] "Sym(280)" -> "Sym(282)" "Sym(284)" [ -label="Sym(284) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(282))" +label="Sym(284) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(282))" shape=box color=red ] @@ -1160,7 +1160,7 @@ shape=box ] "Sym(286)" -> "Sym(288)" "Sym(290)" [ -label="Sym(290) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(288))" +label="Sym(290) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(288))" shape=box ] "Sym(288)" -> "Sym(290)" diff --git a/test-out/epfl/test3-parse1.check b/test-out/epfl/test3-parse1.check index da101b6c..f363b82a 100644 --- a/test-out/epfl/test3-parse1.check +++ b/test-out/epfl/test3-parse1.check @@ -3,18 +3,18 @@ TP(Sym(2),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(0))) TP(Sym(3),First(Sym(2))) TP(Sym(4),Second(Sym(2))) TP(Sym(5),Test(Sym(3),s)) -TP(Sym(6),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(4))) +TP(Sym(6),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(4))) TP(Sym(7),Reify(Sym(6),List(Sym(2), Sym(5)))) TP(Sym(8),Lambda()) TP(Sym(9),OrElse(List(Sym(7), Pure(Const(Failure()))))) TP(Sym(10),Lambda()) -TP(Sym(11),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(9))) +TP(Sym(11),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(9))) TP(Sym(12),Lambda()) TP(Sym(13),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(11))) TP(Sym(14),First(Sym(13))) TP(Sym(15),Second(Sym(13))) TP(Sym(16),Test(Sym(14),c)) -TP(Sym(17),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(15))) +TP(Sym(17),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(15))) TP(Sym(18),Reify(Sym(17),List(Sym(13), Sym(16)))) TP(Sym(19),Lambda()) TP(Sym(20),OrElse(List(Sym(18), Pure(Const(Failure()))))) @@ -22,13 +22,13 @@ TP(Sym(21),Reify(Sym(20),List(Sym(11)))) TP(Sym(22),Lambda()) TP(Sym(23),OrElse(List(Sym(21), Pure(Const(Failure()))))) TP(Sym(24),Lambda()) -TP(Sym(25),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(23))) +TP(Sym(25),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(23))) TP(Sym(26),Lambda()) TP(Sym(27),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(25))) TP(Sym(28),First(Sym(27))) TP(Sym(29),Second(Sym(27))) TP(Sym(30),Test(Sym(28),a)) -TP(Sym(31),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(29))) +TP(Sym(31),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(29))) TP(Sym(32),Reify(Sym(31),List(Sym(27), Sym(30)))) TP(Sym(33),Lambda()) TP(Sym(34),OrElse(List(Sym(32), Pure(Const(Failure()))))) @@ -36,13 +36,13 @@ TP(Sym(35),Reify(Sym(34),List(Sym(25)))) TP(Sym(36),Lambda()) TP(Sym(37),OrElse(List(Sym(35), Pure(Const(Failure()))))) TP(Sym(38),Lambda()) -TP(Sym(39),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(37))) +TP(Sym(39),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(37))) TP(Sym(40),Lambda()) TP(Sym(41),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(39))) TP(Sym(42),First(Sym(41))) TP(Sym(43),Second(Sym(41))) TP(Sym(44),Test(Sym(42),l)) -TP(Sym(45),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(43))) +TP(Sym(45),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(43))) TP(Sym(46),Reify(Sym(45),List(Sym(41), Sym(44)))) TP(Sym(47),Lambda()) TP(Sym(48),OrElse(List(Sym(46), Pure(Const(Failure()))))) @@ -50,13 +50,13 @@ TP(Sym(49),Reify(Sym(48),List(Sym(39)))) TP(Sym(50),Lambda()) TP(Sym(51),OrElse(List(Sym(49), Pure(Const(Failure()))))) TP(Sym(52),Lambda()) -TP(Sym(53),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(51))) +TP(Sym(53),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(51))) TP(Sym(54),Lambda()) TP(Sym(55),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(53))) TP(Sym(56),First(Sym(55))) TP(Sym(57),Second(Sym(55))) TP(Sym(58),Test(Sym(56),a)) -TP(Sym(59),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(57))) +TP(Sym(59),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(57))) TP(Sym(60),Reify(Sym(59),List(Sym(55), Sym(58)))) TP(Sym(61),Lambda()) TP(Sym(62),OrElse(List(Sym(60), Pure(Const(Failure()))))) @@ -64,35 +64,35 @@ TP(Sym(63),Reify(Sym(62),List(Sym(53)))) TP(Sym(64),Lambda()) TP(Sym(65),OrElse(List(Sym(63), Pure(Const(Failure()))))) TP(Sym(66),Lambda()) -TP(Sym(67),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(65))) +TP(Sym(67),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(65))) TP(Sym(68),Lambda()) TP(Sym(69),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(67))) TP(Sym(70),First(Sym(69))) TP(Sym(71),Second(Sym(69))) TP(Sym(72),Test(Sym(70), )) -TP(Sym(73),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(71))) +TP(Sym(73),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(71))) TP(Sym(74),Reify(Sym(73),List(Sym(69), Sym(72)))) TP(Sym(75),Lambda()) TP(Sym(76),OrElse(List(Sym(74), Pure(Const(Failure()))))) TP(Sym(77),Lambda()) -TP(Sym(78),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(76))) +TP(Sym(78),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(76))) TP(Sym(79),Lambda()) TP(Sym(80),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(78))) TP(Sym(81),First(Sym(80))) TP(Sym(82),Second(Sym(80))) TP(Sym(83),Test(Sym(81),r)) -TP(Sym(84),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(82))) +TP(Sym(84),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(82))) TP(Sym(85),Reify(Sym(84),List(Sym(80), Sym(83)))) TP(Sym(86),Lambda()) TP(Sym(87),OrElse(List(Sym(85), Pure(Const(Failure()))))) TP(Sym(88),Lambda()) -TP(Sym(89),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(87))) +TP(Sym(89),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(87))) TP(Sym(90),Lambda()) TP(Sym(91),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(89))) TP(Sym(92),First(Sym(91))) TP(Sym(93),Second(Sym(91))) TP(Sym(94),Test(Sym(92),u)) -TP(Sym(95),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(93))) +TP(Sym(95),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(93))) TP(Sym(96),Reify(Sym(95),List(Sym(91), Sym(94)))) TP(Sym(97),Lambda()) TP(Sym(98),OrElse(List(Sym(96), Pure(Const(Failure()))))) @@ -100,13 +100,13 @@ TP(Sym(99),Reify(Sym(98),List(Sym(89)))) TP(Sym(100),Lambda()) TP(Sym(101),OrElse(List(Sym(99), Pure(Const(Failure()))))) TP(Sym(102),Lambda()) -TP(Sym(103),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(101))) +TP(Sym(103),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(101))) TP(Sym(104),Lambda()) TP(Sym(105),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(103))) TP(Sym(106),First(Sym(105))) TP(Sym(107),Second(Sym(105))) TP(Sym(108),Test(Sym(106),l)) -TP(Sym(109),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(107))) +TP(Sym(109),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(107))) TP(Sym(110),Reify(Sym(109),List(Sym(105), Sym(108)))) TP(Sym(111),Lambda()) TP(Sym(112),OrElse(List(Sym(110), Pure(Const(Failure()))))) @@ -114,13 +114,13 @@ TP(Sym(113),Reify(Sym(112),List(Sym(103)))) TP(Sym(114),Lambda()) TP(Sym(115),OrElse(List(Sym(113), Pure(Const(Failure()))))) TP(Sym(116),Lambda()) -TP(Sym(117),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(115))) +TP(Sym(117),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(115))) TP(Sym(118),Lambda()) TP(Sym(119),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(117))) TP(Sym(120),First(Sym(119))) TP(Sym(121),Second(Sym(119))) TP(Sym(122),Test(Sym(120),e)) -TP(Sym(123),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(121))) +TP(Sym(123),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(121))) TP(Sym(124),Reify(Sym(123),List(Sym(119), Sym(122)))) TP(Sym(125),Lambda()) TP(Sym(126),OrElse(List(Sym(124), Pure(Const(Failure()))))) @@ -128,13 +128,13 @@ TP(Sym(127),Reify(Sym(126),List(Sym(117)))) TP(Sym(128),Lambda()) TP(Sym(129),OrElse(List(Sym(127), Pure(Const(Failure()))))) TP(Sym(130),Lambda()) -TP(Sym(131),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(129))) +TP(Sym(131),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(129))) TP(Sym(132),Lambda()) TP(Sym(133),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(131))) TP(Sym(134),First(Sym(133))) TP(Sym(135),Second(Sym(133))) TP(Sym(136),Test(Sym(134),s)) -TP(Sym(137),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(135))) +TP(Sym(137),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(135))) TP(Sym(138),Reify(Sym(137),List(Sym(133), Sym(136)))) TP(Sym(139),Lambda()) TP(Sym(140),OrElse(List(Sym(138), Pure(Const(Failure()))))) @@ -148,7 +148,7 @@ TP(Sym(147),Reify(Sym(146),List(Sym(67)))) TP(Sym(148),Lambda()) TP(Sym(149),OrElse(List(Sym(147), Pure(Const(Failure()))))) TP(Sym(150),Lambda()) -TP(Sym(151),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(149))) +TP(Sym(151),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(149))) TP(Sym(152),Reify(Sym(149),List(Sym(151)))) TP(Sym(153),Lambda()) TP(Sym(154),Lambda()) @@ -156,18 +156,18 @@ TP(Sym(155),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(0))) TP(Sym(156),First(Sym(155))) TP(Sym(157),Second(Sym(155))) TP(Sym(158),Test(Sym(156),s)) -TP(Sym(159),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(157))) +TP(Sym(159),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(157))) TP(Sym(160),Reify(Sym(159),List(Sym(155), Sym(158)))) TP(Sym(161),Lambda()) TP(Sym(162),OrElse(List(Sym(160), Pure(Const(Failure()))))) TP(Sym(163),Lambda()) -TP(Sym(164),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(162))) +TP(Sym(164),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(162))) TP(Sym(165),Lambda()) TP(Sym(166),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(164))) TP(Sym(167),First(Sym(166))) TP(Sym(168),Second(Sym(166))) TP(Sym(169),Test(Sym(167),c)) -TP(Sym(170),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(168))) +TP(Sym(170),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(168))) TP(Sym(171),Reify(Sym(170),List(Sym(166), Sym(169)))) TP(Sym(172),Lambda()) TP(Sym(173),OrElse(List(Sym(171), Pure(Const(Failure()))))) @@ -175,13 +175,13 @@ TP(Sym(174),Reify(Sym(173),List(Sym(164)))) TP(Sym(175),Lambda()) TP(Sym(176),OrElse(List(Sym(174), Pure(Const(Failure()))))) TP(Sym(177),Lambda()) -TP(Sym(178),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(176))) +TP(Sym(178),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(176))) TP(Sym(179),Lambda()) TP(Sym(180),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(178))) TP(Sym(181),First(Sym(180))) TP(Sym(182),Second(Sym(180))) TP(Sym(183),Test(Sym(181),a)) -TP(Sym(184),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(182))) +TP(Sym(184),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(182))) TP(Sym(185),Reify(Sym(184),List(Sym(180), Sym(183)))) TP(Sym(186),Lambda()) TP(Sym(187),OrElse(List(Sym(185), Pure(Const(Failure()))))) @@ -189,13 +189,13 @@ TP(Sym(188),Reify(Sym(187),List(Sym(178)))) TP(Sym(189),Lambda()) TP(Sym(190),OrElse(List(Sym(188), Pure(Const(Failure()))))) TP(Sym(191),Lambda()) -TP(Sym(192),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(190))) +TP(Sym(192),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(190))) TP(Sym(193),Lambda()) TP(Sym(194),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(192))) TP(Sym(195),First(Sym(194))) TP(Sym(196),Second(Sym(194))) TP(Sym(197),Test(Sym(195),l)) -TP(Sym(198),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(196))) +TP(Sym(198),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(196))) TP(Sym(199),Reify(Sym(198),List(Sym(194), Sym(197)))) TP(Sym(200),Lambda()) TP(Sym(201),OrElse(List(Sym(199), Pure(Const(Failure()))))) @@ -203,13 +203,13 @@ TP(Sym(202),Reify(Sym(201),List(Sym(192)))) TP(Sym(203),Lambda()) TP(Sym(204),OrElse(List(Sym(202), Pure(Const(Failure()))))) TP(Sym(205),Lambda()) -TP(Sym(206),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(204))) +TP(Sym(206),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(204))) TP(Sym(207),Lambda()) TP(Sym(208),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(206))) TP(Sym(209),First(Sym(208))) TP(Sym(210),Second(Sym(208))) TP(Sym(211),Test(Sym(209),a)) -TP(Sym(212),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(210))) +TP(Sym(212),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(210))) TP(Sym(213),Reify(Sym(212),List(Sym(208), Sym(211)))) TP(Sym(214),Lambda()) TP(Sym(215),OrElse(List(Sym(213), Pure(Const(Failure()))))) @@ -217,35 +217,35 @@ TP(Sym(216),Reify(Sym(215),List(Sym(206)))) TP(Sym(217),Lambda()) TP(Sym(218),OrElse(List(Sym(216), Pure(Const(Failure()))))) TP(Sym(219),Lambda()) -TP(Sym(220),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(218))) +TP(Sym(220),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(218))) TP(Sym(221),Lambda()) TP(Sym(222),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(220))) TP(Sym(223),First(Sym(222))) TP(Sym(224),Second(Sym(222))) TP(Sym(225),Test(Sym(223), )) -TP(Sym(226),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(224))) +TP(Sym(226),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(224))) TP(Sym(227),Reify(Sym(226),List(Sym(222), Sym(225)))) TP(Sym(228),Lambda()) TP(Sym(229),OrElse(List(Sym(227), Pure(Const(Failure()))))) TP(Sym(230),Lambda()) -TP(Sym(231),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(229))) +TP(Sym(231),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(229))) TP(Sym(232),Lambda()) TP(Sym(233),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(231))) TP(Sym(234),First(Sym(233))) TP(Sym(235),Second(Sym(233))) TP(Sym(236),Test(Sym(234),r)) -TP(Sym(237),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(235))) +TP(Sym(237),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(235))) TP(Sym(238),Reify(Sym(237),List(Sym(233), Sym(236)))) TP(Sym(239),Lambda()) TP(Sym(240),OrElse(List(Sym(238), Pure(Const(Failure()))))) TP(Sym(241),Lambda()) -TP(Sym(242),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(240))) +TP(Sym(242),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(240))) TP(Sym(243),Lambda()) TP(Sym(244),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(242))) TP(Sym(245),First(Sym(244))) TP(Sym(246),Second(Sym(244))) TP(Sym(247),Test(Sym(245),o)) -TP(Sym(248),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(246))) +TP(Sym(248),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(246))) TP(Sym(249),Reify(Sym(248),List(Sym(244), Sym(247)))) TP(Sym(250),Lambda()) TP(Sym(251),OrElse(List(Sym(249), Pure(Const(Failure()))))) @@ -253,13 +253,13 @@ TP(Sym(252),Reify(Sym(251),List(Sym(242)))) TP(Sym(253),Lambda()) TP(Sym(254),OrElse(List(Sym(252), Pure(Const(Failure()))))) TP(Sym(255),Lambda()) -TP(Sym(256),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(254))) +TP(Sym(256),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(254))) TP(Sym(257),Lambda()) TP(Sym(258),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(256))) TP(Sym(259),First(Sym(258))) TP(Sym(260),Second(Sym(258))) TP(Sym(261),Test(Sym(259),c)) -TP(Sym(262),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(260))) +TP(Sym(262),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(260))) TP(Sym(263),Reify(Sym(262),List(Sym(258), Sym(261)))) TP(Sym(264),Lambda()) TP(Sym(265),OrElse(List(Sym(263), Pure(Const(Failure()))))) @@ -267,13 +267,13 @@ TP(Sym(266),Reify(Sym(265),List(Sym(256)))) TP(Sym(267),Lambda()) TP(Sym(268),OrElse(List(Sym(266), Pure(Const(Failure()))))) TP(Sym(269),Lambda()) -TP(Sym(270),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(268))) +TP(Sym(270),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(268))) TP(Sym(271),Lambda()) TP(Sym(272),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(270))) TP(Sym(273),First(Sym(272))) TP(Sym(274),Second(Sym(272))) TP(Sym(275),Test(Sym(273),k)) -TP(Sym(276),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(274))) +TP(Sym(276),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(274))) TP(Sym(277),Reify(Sym(276),List(Sym(272), Sym(275)))) TP(Sym(278),Lambda()) TP(Sym(279),OrElse(List(Sym(277), Pure(Const(Failure()))))) @@ -281,13 +281,13 @@ TP(Sym(280),Reify(Sym(279),List(Sym(270)))) TP(Sym(281),Lambda()) TP(Sym(282),OrElse(List(Sym(280), Pure(Const(Failure()))))) TP(Sym(283),Lambda()) -TP(Sym(284),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(282))) +TP(Sym(284),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(282))) TP(Sym(285),Lambda()) TP(Sym(286),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(284))) TP(Sym(287),First(Sym(286))) TP(Sym(288),Second(Sym(286))) TP(Sym(289),Test(Sym(287),s)) -TP(Sym(290),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(288))) +TP(Sym(290),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(288))) TP(Sym(291),Reify(Sym(290),List(Sym(286), Sym(289)))) TP(Sym(292),Lambda()) TP(Sym(293),OrElse(List(Sym(291), Pure(Const(Failure()))))) diff --git a/test-out/epfl/test3-parse2-dot.check b/test-out/epfl/test3-parse2-dot.check index 6a67f4a4..00b355a4 100644 --- a/test-out/epfl/test3-parse2-dot.check +++ b/test-out/epfl/test3-parse2-dot.check @@ -22,7 +22,7 @@ shape=box ] "Sym(2)" -> "Sym(4)" "Sym(6)" [ -label="Sym(6) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(4))" +label="Sym(6) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(4))" shape=box ] "Sym(4)" -> "Sym(6)" @@ -39,7 +39,7 @@ shape=box ] "Sym(7)" -> "Sym(9)" "Sym(11)" [ -label="Sym(11) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(9))" +label="Sym(11) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(9))" shape=box color=red ] @@ -67,7 +67,7 @@ shape=box ] "Sym(13)" -> "Sym(15)" "Sym(17)" [ -label="Sym(17) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(15))" +label="Sym(17) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(15))" shape=box ] "Sym(15)" -> "Sym(17)" @@ -95,7 +95,7 @@ shape=box ] "Sym(21)" -> "Sym(23)" "Sym(25)" [ -label="Sym(25) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(23))" +label="Sym(25) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(23))" shape=box color=red ] @@ -123,7 +123,7 @@ shape=box ] "Sym(27)" -> "Sym(29)" "Sym(31)" [ -label="Sym(31) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(29))" +label="Sym(31) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(29))" shape=box ] "Sym(29)" -> "Sym(31)" @@ -151,7 +151,7 @@ shape=box ] "Sym(35)" -> "Sym(37)" "Sym(39)" [ -label="Sym(39) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(37))" +label="Sym(39) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(37))" shape=box color=red ] @@ -179,7 +179,7 @@ shape=box ] "Sym(41)" -> "Sym(43)" "Sym(45)" [ -label="Sym(45) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(43))" +label="Sym(45) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(43))" shape=box ] "Sym(43)" -> "Sym(45)" @@ -207,7 +207,7 @@ shape=box ] "Sym(49)" -> "Sym(51)" "Sym(53)" [ -label="Sym(53) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(51))" +label="Sym(53) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(51))" shape=box color=red ] @@ -235,7 +235,7 @@ shape=box ] "Sym(55)" -> "Sym(57)" "Sym(59)" [ -label="Sym(59) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(57))" +label="Sym(59) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(57))" shape=box ] "Sym(57)" -> "Sym(59)" @@ -263,7 +263,7 @@ shape=box ] "Sym(63)" -> "Sym(65)" "Sym(67)" [ -label="Sym(67) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(65))" +label="Sym(67) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(65))" shape=box color=red ] @@ -291,7 +291,7 @@ shape=box ] "Sym(69)" -> "Sym(71)" "Sym(73)" [ -label="Sym(73) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(71))" +label="Sym(73) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(71))" shape=box ] "Sym(71)" -> "Sym(73)" @@ -308,7 +308,7 @@ shape=box ] "Sym(74)" -> "Sym(76)" "Sym(78)" [ -label="Sym(78) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(76))" +label="Sym(78) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(76))" shape=box color=red ] @@ -336,7 +336,7 @@ shape=box ] "Sym(80)" -> "Sym(82)" "Sym(84)" [ -label="Sym(84) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(82))" +label="Sym(84) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(82))" shape=box ] "Sym(82)" -> "Sym(84)" @@ -353,7 +353,7 @@ shape=box ] "Sym(85)" -> "Sym(87)" "Sym(89)" [ -label="Sym(89) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(87))" +label="Sym(89) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(87))" shape=box color=red ] @@ -381,7 +381,7 @@ shape=box ] "Sym(91)" -> "Sym(93)" "Sym(95)" [ -label="Sym(95) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(93))" +label="Sym(95) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(93))" shape=box ] "Sym(93)" -> "Sym(95)" @@ -409,7 +409,7 @@ shape=box ] "Sym(99)" -> "Sym(101)" "Sym(103)" [ -label="Sym(103) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(101))" +label="Sym(103) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(101))" shape=box color=red ] @@ -437,7 +437,7 @@ shape=box ] "Sym(105)" -> "Sym(107)" "Sym(109)" [ -label="Sym(109) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(107))" +label="Sym(109) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(107))" shape=box ] "Sym(107)" -> "Sym(109)" @@ -465,7 +465,7 @@ shape=box ] "Sym(113)" -> "Sym(115)" "Sym(117)" [ -label="Sym(117) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(115))" +label="Sym(117) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(115))" shape=box color=red ] @@ -493,7 +493,7 @@ shape=box ] "Sym(119)" -> "Sym(121)" "Sym(123)" [ -label="Sym(123) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(121))" +label="Sym(123) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(121))" shape=box ] "Sym(121)" -> "Sym(123)" @@ -521,7 +521,7 @@ shape=box ] "Sym(127)" -> "Sym(129)" "Sym(131)" [ -label="Sym(131) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(129))" +label="Sym(131) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(129))" shape=box color=red ] @@ -549,7 +549,7 @@ shape=box ] "Sym(133)" -> "Sym(135)" "Sym(137)" [ -label="Sym(137) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(135))" +label="Sym(137) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(135))" shape=box ] "Sym(135)" -> "Sym(137)" @@ -599,7 +599,7 @@ shape=box ] "Sym(147)" -> "Sym(149)" "Sym(151)" [ -label="Sym(151) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(149))" +label="Sym(151) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(149))" shape=box color=red ] @@ -640,7 +640,7 @@ shape=box ] "Sym(184)" -> "Sym(186)" "Sym(188)" [ -label="Sym(188) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(186))" +label="Sym(188) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(186))" shape=box color=red ] @@ -668,7 +668,7 @@ shape=box ] "Sym(190)" -> "Sym(192)" "Sym(194)" [ -label="Sym(194) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(192))" +label="Sym(194) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(192))" shape=box ] "Sym(192)" -> "Sym(194)" @@ -696,7 +696,7 @@ shape=box ] "Sym(198)" -> "Sym(200)" "Sym(202)" [ -label="Sym(202) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(200))" +label="Sym(202) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(200))" shape=box color=red ] @@ -724,7 +724,7 @@ shape=box ] "Sym(204)" -> "Sym(206)" "Sym(208)" [ -label="Sym(208) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(206))" +label="Sym(208) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(206))" shape=box ] "Sym(206)" -> "Sym(208)" @@ -752,7 +752,7 @@ shape=box ] "Sym(212)" -> "Sym(214)" "Sym(216)" [ -label="Sym(216) \n Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(214))" +label="Sym(216) \n Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(214))" shape=box color=red ] @@ -780,7 +780,7 @@ shape=box ] "Sym(218)" -> "Sym(220)" "Sym(222)" [ -label="Sym(222) \n Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(220))" +label="Sym(222) \n Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(220))" shape=box ] "Sym(220)" -> "Sym(222)" diff --git a/test-out/epfl/test3-parse2.check b/test-out/epfl/test3-parse2.check index 7a248fcd..67b0c299 100644 --- a/test-out/epfl/test3-parse2.check +++ b/test-out/epfl/test3-parse2.check @@ -3,18 +3,18 @@ TP(Sym(2),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(0))) TP(Sym(3),First(Sym(2))) TP(Sym(4),Second(Sym(2))) TP(Sym(5),Test(Sym(3),s)) -TP(Sym(6),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(4))) +TP(Sym(6),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(4))) TP(Sym(7),Reify(Sym(6),List(Sym(2), Sym(5)))) TP(Sym(8),Lambda()) TP(Sym(9),OrElse(List(Sym(7), Pure(Const(Failure()))))) TP(Sym(10),Lambda()) -TP(Sym(11),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(9))) +TP(Sym(11),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(9))) TP(Sym(12),Lambda()) TP(Sym(13),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(11))) TP(Sym(14),First(Sym(13))) TP(Sym(15),Second(Sym(13))) TP(Sym(16),Test(Sym(14),c)) -TP(Sym(17),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(15))) +TP(Sym(17),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(15))) TP(Sym(18),Reify(Sym(17),List(Sym(13), Sym(16)))) TP(Sym(19),Lambda()) TP(Sym(20),OrElse(List(Sym(18), Pure(Const(Failure()))))) @@ -22,13 +22,13 @@ TP(Sym(21),Reify(Sym(20),List(Sym(11)))) TP(Sym(22),Lambda()) TP(Sym(23),OrElse(List(Sym(21), Pure(Const(Failure()))))) TP(Sym(24),Lambda()) -TP(Sym(25),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(23))) +TP(Sym(25),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(23))) TP(Sym(26),Lambda()) TP(Sym(27),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(25))) TP(Sym(28),First(Sym(27))) TP(Sym(29),Second(Sym(27))) TP(Sym(30),Test(Sym(28),a)) -TP(Sym(31),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(29))) +TP(Sym(31),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(29))) TP(Sym(32),Reify(Sym(31),List(Sym(27), Sym(30)))) TP(Sym(33),Lambda()) TP(Sym(34),OrElse(List(Sym(32), Pure(Const(Failure()))))) @@ -36,13 +36,13 @@ TP(Sym(35),Reify(Sym(34),List(Sym(25)))) TP(Sym(36),Lambda()) TP(Sym(37),OrElse(List(Sym(35), Pure(Const(Failure()))))) TP(Sym(38),Lambda()) -TP(Sym(39),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(37))) +TP(Sym(39),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(37))) TP(Sym(40),Lambda()) TP(Sym(41),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(39))) TP(Sym(42),First(Sym(41))) TP(Sym(43),Second(Sym(41))) TP(Sym(44),Test(Sym(42),l)) -TP(Sym(45),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(43))) +TP(Sym(45),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(43))) TP(Sym(46),Reify(Sym(45),List(Sym(41), Sym(44)))) TP(Sym(47),Lambda()) TP(Sym(48),OrElse(List(Sym(46), Pure(Const(Failure()))))) @@ -50,13 +50,13 @@ TP(Sym(49),Reify(Sym(48),List(Sym(39)))) TP(Sym(50),Lambda()) TP(Sym(51),OrElse(List(Sym(49), Pure(Const(Failure()))))) TP(Sym(52),Lambda()) -TP(Sym(53),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(51))) +TP(Sym(53),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(51))) TP(Sym(54),Lambda()) TP(Sym(55),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(53))) TP(Sym(56),First(Sym(55))) TP(Sym(57),Second(Sym(55))) TP(Sym(58),Test(Sym(56),a)) -TP(Sym(59),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(57))) +TP(Sym(59),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(57))) TP(Sym(60),Reify(Sym(59),List(Sym(55), Sym(58)))) TP(Sym(61),Lambda()) TP(Sym(62),OrElse(List(Sym(60), Pure(Const(Failure()))))) @@ -64,35 +64,35 @@ TP(Sym(63),Reify(Sym(62),List(Sym(53)))) TP(Sym(64),Lambda()) TP(Sym(65),OrElse(List(Sym(63), Pure(Const(Failure()))))) TP(Sym(66),Lambda()) -TP(Sym(67),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(65))) +TP(Sym(67),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(65))) TP(Sym(68),Lambda()) TP(Sym(69),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(67))) TP(Sym(70),First(Sym(69))) TP(Sym(71),Second(Sym(69))) TP(Sym(72),Test(Sym(70), )) -TP(Sym(73),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(71))) +TP(Sym(73),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(71))) TP(Sym(74),Reify(Sym(73),List(Sym(69), Sym(72)))) TP(Sym(75),Lambda()) TP(Sym(76),OrElse(List(Sym(74), Pure(Const(Failure()))))) TP(Sym(77),Lambda()) -TP(Sym(78),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(76))) +TP(Sym(78),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(76))) TP(Sym(79),Lambda()) TP(Sym(80),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(78))) TP(Sym(81),First(Sym(80))) TP(Sym(82),Second(Sym(80))) TP(Sym(83),Test(Sym(81),r)) -TP(Sym(84),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(82))) +TP(Sym(84),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(82))) TP(Sym(85),Reify(Sym(84),List(Sym(80), Sym(83)))) TP(Sym(86),Lambda()) TP(Sym(87),OrElse(List(Sym(85), Pure(Const(Failure()))))) TP(Sym(88),Lambda()) -TP(Sym(89),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(87))) +TP(Sym(89),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(87))) TP(Sym(90),Lambda()) TP(Sym(91),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(89))) TP(Sym(92),First(Sym(91))) TP(Sym(93),Second(Sym(91))) TP(Sym(94),Test(Sym(92),u)) -TP(Sym(95),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(93))) +TP(Sym(95),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(93))) TP(Sym(96),Reify(Sym(95),List(Sym(91), Sym(94)))) TP(Sym(97),Lambda()) TP(Sym(98),OrElse(List(Sym(96), Pure(Const(Failure()))))) @@ -100,13 +100,13 @@ TP(Sym(99),Reify(Sym(98),List(Sym(89)))) TP(Sym(100),Lambda()) TP(Sym(101),OrElse(List(Sym(99), Pure(Const(Failure()))))) TP(Sym(102),Lambda()) -TP(Sym(103),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(101))) +TP(Sym(103),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(101))) TP(Sym(104),Lambda()) TP(Sym(105),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(103))) TP(Sym(106),First(Sym(105))) TP(Sym(107),Second(Sym(105))) TP(Sym(108),Test(Sym(106),l)) -TP(Sym(109),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(107))) +TP(Sym(109),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(107))) TP(Sym(110),Reify(Sym(109),List(Sym(105), Sym(108)))) TP(Sym(111),Lambda()) TP(Sym(112),OrElse(List(Sym(110), Pure(Const(Failure()))))) @@ -114,13 +114,13 @@ TP(Sym(113),Reify(Sym(112),List(Sym(103)))) TP(Sym(114),Lambda()) TP(Sym(115),OrElse(List(Sym(113), Pure(Const(Failure()))))) TP(Sym(116),Lambda()) -TP(Sym(117),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(115))) +TP(Sym(117),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(115))) TP(Sym(118),Lambda()) TP(Sym(119),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(117))) TP(Sym(120),First(Sym(119))) TP(Sym(121),Second(Sym(119))) TP(Sym(122),Test(Sym(120),e)) -TP(Sym(123),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(121))) +TP(Sym(123),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(121))) TP(Sym(124),Reify(Sym(123),List(Sym(119), Sym(122)))) TP(Sym(125),Lambda()) TP(Sym(126),OrElse(List(Sym(124), Pure(Const(Failure()))))) @@ -128,13 +128,13 @@ TP(Sym(127),Reify(Sym(126),List(Sym(117)))) TP(Sym(128),Lambda()) TP(Sym(129),OrElse(List(Sym(127), Pure(Const(Failure()))))) TP(Sym(130),Lambda()) -TP(Sym(131),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(129))) +TP(Sym(131),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(129))) TP(Sym(132),Lambda()) TP(Sym(133),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(131))) TP(Sym(134),First(Sym(133))) TP(Sym(135),Second(Sym(133))) TP(Sym(136),Test(Sym(134),s)) -TP(Sym(137),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(135))) +TP(Sym(137),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(135))) TP(Sym(138),Reify(Sym(137),List(Sym(133), Sym(136)))) TP(Sym(139),Lambda()) TP(Sym(140),OrElse(List(Sym(138), Pure(Const(Failure()))))) @@ -148,7 +148,7 @@ TP(Sym(147),Reify(Sym(146),List(Sym(67)))) TP(Sym(148),Lambda()) TP(Sym(149),OrElse(List(Sym(147), Pure(Const(Failure()))))) TP(Sym(150),Lambda()) -TP(Sym(151),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(149))) +TP(Sym(151),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(149))) TP(Sym(152),Reify(Sym(149),List(Sym(151)))) TP(Sym(153),Lambda()) TP(Sym(154),Lambda()) @@ -185,13 +185,13 @@ TP(Sym(184),Reify(Sym(183),List(Sym(89)))) TP(Sym(185),Lambda()) TP(Sym(186),OrElse(List(Sym(184), Pure(Const(Failure()))))) TP(Sym(187),Lambda()) -TP(Sym(188),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(186))) +TP(Sym(188),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(186))) TP(Sym(189),Lambda()) TP(Sym(190),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(188))) TP(Sym(191),First(Sym(190))) TP(Sym(192),Second(Sym(190))) TP(Sym(193),Test(Sym(191),c)) -TP(Sym(194),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(192))) +TP(Sym(194),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(192))) TP(Sym(195),Reify(Sym(194),List(Sym(190), Sym(193)))) TP(Sym(196),Lambda()) TP(Sym(197),OrElse(List(Sym(195), Pure(Const(Failure()))))) @@ -199,13 +199,13 @@ TP(Sym(198),Reify(Sym(197),List(Sym(188)))) TP(Sym(199),Lambda()) TP(Sym(200),OrElse(List(Sym(198), Pure(Const(Failure()))))) TP(Sym(201),Lambda()) -TP(Sym(202),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(200))) +TP(Sym(202),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(200))) TP(Sym(203),Lambda()) TP(Sym(204),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(202))) TP(Sym(205),First(Sym(204))) TP(Sym(206),Second(Sym(204))) TP(Sym(207),Test(Sym(205),k)) -TP(Sym(208),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(206))) +TP(Sym(208),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(206))) TP(Sym(209),Reify(Sym(208),List(Sym(204), Sym(207)))) TP(Sym(210),Lambda()) TP(Sym(211),OrElse(List(Sym(209), Pure(Const(Failure()))))) @@ -213,13 +213,13 @@ TP(Sym(212),Reify(Sym(211),List(Sym(202)))) TP(Sym(213),Lambda()) TP(Sym(214),OrElse(List(Sym(212), Pure(Const(Failure()))))) TP(Sym(215),Lambda()) -TP(Sym(216),Deconstruct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(214))) +TP(Sym(216),Deconstruct(class scala.lms.epfl.test3.Parsers$Success,Sym(214))) TP(Sym(217),Lambda()) TP(Sym(218),Deconstruct(class scala.collection.immutable.$colon$colon,Sym(216))) TP(Sym(219),First(Sym(218))) TP(Sym(220),Second(Sym(218))) TP(Sym(221),Test(Sym(219),s)) -TP(Sym(222),Construct(class scala.virtualization.lms.epfl.test3.Parsers$Success,Sym(220))) +TP(Sym(222),Construct(class scala.lms.epfl.test3.Parsers$Success,Sym(220))) TP(Sym(223),Reify(Sym(222),List(Sym(218), Sym(221)))) TP(Sym(224),Lambda()) TP(Sym(225),OrElse(List(Sym(223), Pure(Const(Failure()))))) diff --git a/test-out/epfl/test4-counter1.check b/test-out/epfl/test4-counter1.check index 37311313..2d38202a 100644 --- a/test-out/epfl/test4-counter1.check +++ b/test-out/epfl/test4-counter1.check @@ -1,9 +1,9 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x1 = null.asInstanceOf[scala.Function1[Double, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x1 = null.asInstanceOf[scala.Function1[Double, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x1 = {x2: (Double) => val x3 = List(x2) val x4 = {x5: (Char) => @@ -12,7 +12,7 @@ val x7 = x6+1.0 val x8 = x1(x7) x8 } -val x9 = scala.virtualization.lms.epfl.test4.Automaton(x3,x4) +val x9 = scala.lms.epfl.test4.Automaton(x3,x4) x9 } val x10 = x1(0.0) diff --git a/test-out/epfl/test4-counter2.check b/test-out/epfl/test4-counter2.check index bf161253..8e9c8120 100644 --- a/test-out/epfl/test4-counter2.check +++ b/test-out/epfl/test4-counter2.check @@ -1,10 +1,10 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { var x59 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.collection.immutable.List[Char], scala.collection.immutable.List[Char]], scala.Tuple2[scala.collection.immutable.List[Char], scala.collection.immutable.List[Char]]]] -var x7 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.Tuple2[scala.Tuple2[scala.Tuple2[Double, scala.Tuple2[Double, Double]], Double], Double], scala.collection.immutable.List[Char]], scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x7 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.Tuple2[scala.Tuple2[scala.Tuple2[Double, scala.Tuple2[Double, Double]], Double], Double], scala.collection.immutable.List[Char]], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x59 = {x60: (scala.Tuple2[scala.collection.immutable.List[Char], scala.collection.immutable.List[Char]]) => val x61 = x60._1 val x63 = x61.isEmpty @@ -113,7 +113,7 @@ val x76 = (x57,x75) val x77 = x7(x76) x77 } -val x78 = scala.virtualization.lms.epfl.test4.Automaton(x23,x24) +val x78 = scala.lms.epfl.test4.Automaton(x23,x24) x78 } val x1 = List() diff --git a/test-out/epfl/test4-fac3.check b/test-out/epfl/test4-fac3.check index 48083712..c74d3aa0 100644 --- a/test-out/epfl/test4-fac3.check +++ b/test-out/epfl/test4-fac3.check @@ -1,4 +1,4 @@ --- hit recursion: class scala.virtualization.lms.epfl.test3.MatchingExtractorsExp$$anonfun$liftAlt$1$1 Sym(5) <- Sym(0) +-- hit recursion: class scala.lms.epfl.test3.MatchingExtractorsExp$$anonfun$liftAlt$1$1 Sym(5) <- Sym(0) TP(Sym(1),Lambda()) TP(Sym(2),Test(Sym(0),0.0)) TP(Sym(3),Reify(Const(1.0),List(Sym(2)))) diff --git a/test-out/epfl/test4-matchernew1.check b/test-out/epfl/test4-matchernew1.check index ec085db7..abaac6a6 100644 --- a/test-out/epfl/test4-matchernew1.check +++ b/test-out/epfl/test4-matchernew1.check @@ -1,15 +1,15 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x10 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x1 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x17 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x4 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x13 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x7 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x11 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x10 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x1 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x17 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x4 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x13 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x7 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x11 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] x1 = {x2: (Char) => val x3 = x2 == 'A' val x18 = if (x3) { @@ -43,10 +43,10 @@ x14 } x15 } -x10 = scala.virtualization.lms.epfl.test4.Automaton(List(),x1) +x10 = scala.lms.epfl.test4.Automaton(List(),x1) x11 = x10.copy(out = "found"::x10.out) -x13 = scala.virtualization.lms.epfl.test4.Automaton(List(),x7) -x17 = scala.virtualization.lms.epfl.test4.Automaton(List(),x4) +x13 = scala.lms.epfl.test4.Automaton(List(),x7) +x17 = scala.lms.epfl.test4.Automaton(List(),x4) x10 } } diff --git a/test-out/epfl/test4-matchernew1b.check b/test-out/epfl/test4-matchernew1b.check index afd393bb..edb5980f 100644 --- a/test-out/epfl/test4-matchernew1b.check +++ b/test-out/epfl/test4-matchernew1b.check @@ -1,15 +1,15 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x12 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x1 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x17 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x4 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x10 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] -var x7 = null.asInstanceOf[scala.Function1[Char, scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -var x13 = null.asInstanceOf[scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x12 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x1 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x17 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x4 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x10 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] +var x7 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x13 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] x1 = {x2: (Char) => val x3 = x2 == 'A' val x18 = if (x3) { @@ -43,10 +43,10 @@ x14 } x15 } -x10 = scala.virtualization.lms.epfl.test4.Automaton(List(),x7) -x12 = scala.virtualization.lms.epfl.test4.Automaton(List(),x1) +x10 = scala.lms.epfl.test4.Automaton(List(),x7) +x12 = scala.lms.epfl.test4.Automaton(List(),x1) x13 = x12.copy(out = "found"::x12.out) -x17 = scala.virtualization.lms.epfl.test4.Automaton(List(),x4) +x17 = scala.lms.epfl.test4.Automaton(List(),x4) x12 } } diff --git a/test-out/epfl/test4-matchernew2.check b/test-out/epfl/test4-matchernew2.check index b5c1e2d9..1f8d885a 100644 --- a/test-out/epfl/test4-matchernew2.check +++ b/test-out/epfl/test4-matchernew2.check @@ -1,21 +1,21 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x23 = null.asInstanceOf[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] -var x22 = null.asInstanceOf[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] -var x20 = null.asInstanceOf[scala.Function1[Char, scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]]] -var x24 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]], scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x23 = null.asInstanceOf[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] +var x22 = null.asInstanceOf[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] +var x20 = null.asInstanceOf[scala.Function1[Char, scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]]] +var x24 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x20 = {x21: (Char) => x23 } -x22 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x20)) +x22 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x20)) val x12 = List() val x10 = {x11: (Char) => x12 } -val x13 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(1),x10)) +val x13 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(1),x10)) val x7 = {x8: (Char) => val x9 = x8 == 'B' val x14 = if (x9) { @@ -25,7 +25,7 @@ x12 } x14 } -val x15 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x7)) +val x15 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x7)) val x1 = {x2: (Char) => val x3 = x2 == 'A' val x18 = if (x3) { @@ -38,23 +38,23 @@ x12 } x16 } -val x17 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x4)) +val x17 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x4)) x17 } else { x12 } x18 } -val x19 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x1)) +val x19 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x1)) x23 = x19 ::: x22 -x24 = {x25: (scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]) => +x24 = {x25: (scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]) => val x26 = x25.flatMap(_.out) val x27 = {x28: (Char) => val x29 = x25.flatMap(_.next.apply(x28)) val x30 = x24(x29) x30 } -val x31 = scala.virtualization.lms.epfl.test4.Automaton(x26,x27) +val x31 = scala.lms.epfl.test4.Automaton(x26,x27) x31 } val x32 = x24(x23) diff --git a/test-out/epfl/test4-matchernew2b.check b/test-out/epfl/test4-matchernew2b.check index 709f0c79..dc9b0f02 100644 --- a/test-out/epfl/test4-matchernew2b.check +++ b/test-out/epfl/test4-matchernew2b.check @@ -1,21 +1,21 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x23 = null.asInstanceOf[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] -var x22 = null.asInstanceOf[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] -var x20 = null.asInstanceOf[scala.Function1[Char, scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]]] -var x24 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]], scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +var x23 = null.asInstanceOf[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] +var x22 = null.asInstanceOf[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]] +var x20 = null.asInstanceOf[scala.Function1[Char, scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]]] +var x24 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x20 = {x21: (Char) => x23 } -x22 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x20)) +x22 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x20)) val x12 = List() val x10 = {x11: (Char) => x12 } -val x13 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(1),x10)) +val x13 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(1),x10)) val x7 = {x8: (Char) => val x9 = x8 == 'B' val x14 = if (x9) { @@ -25,7 +25,7 @@ x12 } x14 } -val x15 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x7)) +val x15 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x7)) val x1 = {x2: (Char) => val x3 = x2 == 'A' val x18 = if (x3) { @@ -38,23 +38,23 @@ x12 } x16 } -val x17 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x4)) +val x17 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x4)) x17 } else { x12 } x18 } -val x19 = List(scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x1)) +val x19 = List(scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]](List(),x1)) x23 = x22 ::: x19 -x24 = {x25: (scala.collection.immutable.List[scala.virtualization.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]) => +x24 = {x25: (scala.collection.immutable.List[scala.lms.epfl.test4.NAutomaton[Char, scala.collection.immutable.List[Any]]]) => val x26 = x25.flatMap(_.out) val x27 = {x28: (Char) => val x29 = x25.flatMap(_.next.apply(x28)) val x30 = x24(x29) x30 } -val x31 = scala.virtualization.lms.epfl.test4.Automaton(x26,x27) +val x31 = scala.lms.epfl.test4.Automaton(x26,x27) x31 } val x32 = x24(x23) diff --git a/test-out/epfl/test4-stream1.check b/test-out/epfl/test4-stream1.check index d009dc79..36ed6636 100644 --- a/test-out/epfl/test4-stream1.check +++ b/test-out/epfl/test4-stream1.check @@ -1,12 +1,12 @@ /***************************************** Emitting Generated Code *******************************************/ -class Match extends ((Unit)=>(scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { -def apply(x0:Unit): scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { +class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { +def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { var x1 = null.asInstanceOf[scala.Function1[Double, Double]] var x33 = null.asInstanceOf[scala.Function1[Double, Double]] var x19 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.Tuple2[Double, Double], scala.collection.immutable.List[scala.Tuple2[Double, Double]]], scala.Tuple2[scala.Tuple2[Double, Double], scala.collection.immutable.List[scala.Tuple2[Double, Double]]]]] -var x12 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.Tuple2[Double, Double]], scala.virtualization.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x12 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.Tuple2[Double, Double]], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x1 = {x2: (Double) => val x4 = x2%2 == 0 val x5 = if (x4) { @@ -93,7 +93,7 @@ val x51 = x49._2 val x52 = x12(x51) x52 } -val x53 = scala.virtualization.lms.epfl.test4.Automaton(x14,x15) +val x53 = scala.lms.epfl.test4.Automaton(x14,x15) x53 } val x11 = List() diff --git a/test-out/epfl/test6-vectors.check b/test-out/epfl/test6-vectors.check index 3d70389e..ac83d53f 100644 --- a/test-out/epfl/test6-vectors.check +++ b/test-out/epfl/test6-vectors.check @@ -4,10 +4,10 @@ *******************************************/ class Test extends ((Unit)=>(Array[Double])) { def apply(x0:Unit): Array[Double] = { -val x1 = scala.virtualization.lms.epfl.test6.VectorOps.random(7) -val x3 = scala.virtualization.lms.epfl.test6.VectorOps.random(7) +val x1 = scala.lms.epfl.test6.VectorOps.random(7) +val x3 = scala.lms.epfl.test6.VectorOps.random(7) val x4 = (x1,x3) -val x5 = scala.virtualization.lms.epfl.test6.VectorOps.plus(x4) +val x5 = scala.lms.epfl.test6.VectorOps.plus(x4) x5 } } diff --git a/test-src/epfl/FileDiffSuite.scala b/test-src/epfl/FileDiffSuite.scala index 4066dbc3..5a120ed7 100644 --- a/test-src/epfl/FileDiffSuite.scala +++ b/test-src/epfl/FileDiffSuite.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl import java.io.{PrintStream,File,FileInputStream,FileOutputStream,ByteArrayOutputStream} diff --git a/test-src/epfl/test1-arith/Arith.scala b/test-src/epfl/test1-arith/Arith.scala index 5e4a2446..ba1d7a91 100644 --- a/test-src/epfl/test1-arith/Arith.scala +++ b/test-src/epfl/test1-arith/Arith.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test1 diff --git a/test-src/epfl/test1-arith/Arrays.scala b/test-src/epfl/test1-arith/Arrays.scala index 23a6e7bf..edd66c03 100644 --- a/test-src/epfl/test1-arith/Arrays.scala +++ b/test-src/epfl/test1-arith/Arrays.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test1 diff --git a/test-src/epfl/test1-arith/Relat.scala b/test-src/epfl/test1-arith/Relat.scala index d4c5c51b..6fd8bfed 100644 --- a/test-src/epfl/test1-arith/Relat.scala +++ b/test-src/epfl/test1-arith/Relat.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test1 diff --git a/test-src/epfl/test1-arith/TestConstCSE.scala b/test-src/epfl/test1-arith/TestConstCSE.scala index 54db25c4..d0ab1edd 100644 --- a/test-src/epfl/test1-arith/TestConstCSE.scala +++ b/test-src/epfl/test1-arith/TestConstCSE.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test1 diff --git a/test-src/epfl/test1-arith/TestNumeric.scala b/test-src/epfl/test1-arith/TestNumeric.scala index a062b660..1fc29e55 100644 --- a/test-src/epfl/test1-arith/TestNumeric.scala +++ b/test-src/epfl/test1-arith/TestNumeric.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test1 diff --git a/test-src/epfl/test1-arith/Trig.scala b/test-src/epfl/test1-arith/Trig.scala index ff001fff..863263de 100644 --- a/test-src/epfl/test1-arith/Trig.scala +++ b/test-src/epfl/test1-arith/Trig.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test1 diff --git a/test-src/epfl/test14-scratch/TestCGen.scala b/test-src/epfl/test14-scratch/TestCGen.scala index 30e12844..59ca787a 100644 --- a/test-src/epfl/test14-scratch/TestCGen.scala +++ b/test-src/epfl/test14-scratch/TestCGen.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test14 diff --git a/test-src/epfl/test2-fft/DisableOpts.scala b/test-src/epfl/test2-fft/DisableOpts.scala index 093e7fa9..bdcffe04 100644 --- a/test-src/epfl/test2-fft/DisableOpts.scala +++ b/test-src/epfl/test2-fft/DisableOpts.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test2 diff --git a/test-src/epfl/test2-fft/TestFFT.scala b/test-src/epfl/test2-fft/TestFFT.scala index 22ce9ea0..63037a33 100644 --- a/test-src/epfl/test2-fft/TestFFT.scala +++ b/test-src/epfl/test2-fft/TestFFT.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test2 diff --git a/test-src/epfl/test2-fft/TestPower.scala b/test-src/epfl/test2-fft/TestPower.scala index 12a7bc05..4aec3072 100644 --- a/test-src/epfl/test2-fft/TestPower.scala +++ b/test-src/epfl/test2-fft/TestPower.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test2 diff --git a/test-src/epfl/test2-fft/TestSort.scala b/test-src/epfl/test2-fft/TestSort.scala index 708f90c5..d8d1de98 100644 --- a/test-src/epfl/test2-fft/TestSort.scala +++ b/test-src/epfl/test2-fft/TestSort.scala @@ -1,4 +1,4 @@ -package scala.virtualization.lms +package scala.lms package epfl package test2 From 6162f9a6ae2259c5ace0c0a4ff3f2620ead80112 Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Sun, 18 Dec 2016 16:26:21 -0500 Subject: [PATCH 03/10] changeset from dev-par-reg branch --- src/common/NumericOps.scala | 2 + src/common/OPMOps.scala | 75 ++++++++++++++++++++ src/common/RangeOps.scala | 133 +++++++++++++++++++++++------------- src/common/StringOps.scala | 2 +- src/internal/Effects.scala | 30 ++++---- 5 files changed, 177 insertions(+), 65 deletions(-) create mode 100644 src/common/OPMOps.scala diff --git a/src/common/NumericOps.scala b/src/common/NumericOps.scala index 19b1b5e4..5c2024e1 100644 --- a/src/common/NumericOps.scala +++ b/src/common/NumericOps.scala @@ -86,6 +86,8 @@ trait NumericOpsExpOpt extends NumericOpsExp { } override def numeric_divide[T:Numeric:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Exp[T] = (lhs,rhs) match { // CAVEAT: Numeric doesn't have .div, Fractional has + case (Const(x), Const(y)) if manifest[T] == manifest[Int] => super.numeric_divide(lhs, rhs) + case (Const(x), Const(y)) if manifest[T] == manifest[Long] => super.numeric_divide(lhs, rhs) case (Const(x), Const(y)) => Const(implicitly[Numeric[T]].asInstanceOf[Fractional[T]].div(x,y)) case _ => super.numeric_divide(lhs,rhs) } diff --git a/src/common/OPMOps.scala b/src/common/OPMOps.scala new file mode 100644 index 00000000..2b3c35e3 --- /dev/null +++ b/src/common/OPMOps.scala @@ -0,0 +1,75 @@ + +package scala.virtualization.lms +package common + +import java.io.PrintWriter + +import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException} +import scala.reflect.SourceContext + +trait OMPOps extends Base { + def parallel_region(b: => Rep[Unit]): Rep[Unit] + def critical_region(b: => Rep[Unit]): Rep[Unit] +} + +trait OMPOpsExp extends OMPOps { + + case class ParallelRegion(b: Block[Unit]) extends Def[Unit] + def parallel_region(b: => Exp[Unit]): Exp[Unit] = { + val br = reifyEffects(b) + reflectEffect(ParallelRegion(br)) + } + + case class CriticalRegion(b: Block[Unit]) extends Def[Unit] + def critical_region(b: => Exp[Unit]): Exp[Unit] = { + val br = reifyEffects(b) + reflectEffect(CriticalRegion(br)) + } + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case ParallelRegion(b) => effectSyms(b) + case CriticalRegion(b) => effectSyms(b) + case _ => super.boundSyms(e) + } + + override def syms(e: Any): List[Sym[Any]] = e match { + case ParallelRegion(body) => syms(body) + case CriticalRegion(body) => syms(body) + case _ => super.syms(e) + } + + override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { + case ParallelRegion(body) => freqHot(body) + case CriticalRegion(body) => freqHot(body) + case _ => super.symsFreq(e) + } + +} + +trait BaseGenOMPOps extends GenericNestedCodegen { + val IR: OMPOpsExp + import IR._ +} + +trait ScalaGenOMPOps extends ScalaGenEffect with BaseGenOMPOps { + +} + +trait CGenOMPOps extends CGenEffect with BaseGenOMPOps{ + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ParallelRegion(body) => + gen"""#pragma omp parallel + |{ + |${nestedBlock(body)} + |}""" + case CriticalRegion(body) => + gen"""#pragma omp critical + |{ + |${nestedBlock(body)} + |}""" + case _ => super.emitNode(sym, rhs) + } +} + diff --git a/src/common/RangeOps.scala b/src/common/RangeOps.scala index c79688c0..bc39deb9 100644 --- a/src/common/RangeOps.scala +++ b/src/common/RangeOps.scala @@ -14,9 +14,9 @@ trait RangeOps extends Base { } implicit class lrangeOpsCls(r: Rep[LongRange]) { def foreach(f: Rep[Long] => Rep[Unit])(implicit pos: SourceContext) = lrange_foreach(r, f) + def parforeach(f: Rep[Long] => Rep[Unit])(implicit pos: SourceContext) = lrange_par_foreach(r, f) } - def infix_until(start: Rep[Int], end: Rep[Int])(implicit pos: SourceContext) = range_until(start,end) def infix_until(start: Rep[Long], end: Rep[Long])(implicit pos: SourceContext, o: Overloaded1) = lrange_until(start,end) def infix_start(r: Rep[Range])(implicit pos: SourceContext) = range_start(r) @@ -37,6 +37,12 @@ trait RangeOps extends Base { def lrange_step(r: Rep[LongRange])(implicit pos: SourceContext) : Rep[Long] def lrange_end(r: Rep[LongRange])(implicit pos: SourceContext) : Rep[Long] def lrange_foreach(r: Rep[LongRange], f: (Rep[Long]) => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] + + def lrange_par_until(start: Rep[Long], end: Rep[Long])(implicit pos: SourceContext): Rep[LongRange] + def lrange_par_start(r: Rep[LongRange])(implicit pos: SourceContext) : Rep[Long] + def lrange_par_step(r: Rep[LongRange])(implicit pos: SourceContext) : Rep[Long] + def lrange_par_end(r: Rep[LongRange])(implicit pos: SourceContext) : Rep[Long] + def lrange_par_foreach(r: Rep[LongRange], f: (Rep[Long]) => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] } trait RangeOpsExp extends RangeOps with FunctionsExp { @@ -52,14 +58,35 @@ trait RangeOpsExp extends RangeOps with FunctionsExp { case class LongRangeEnd(r: Exp[LongRange]) extends Def[Long] case class LongRangeForeach(start: Exp[Long], end: Exp[Long], i: Sym[Long], body: Block[Unit]) extends Def[Unit] + case class LongParUntil(start: Exp[Long], end: Exp[Long]) extends Def[LongRange] + case class LongRangeParStart(r: Exp[LongRange]) extends Def[Long] + case class LongRangeParStep(r: Exp[LongRange]) extends Def[Long] + case class LongRangeParEnd(r: Exp[LongRange]) extends Def[Long] + case class LongRangeParForeach(start: Exp[Long], end: Exp[Long], i: Sym[Long], body: Block[Unit]) extends Def[Unit] + + def lrange_par_until(start: Exp[Long], end: Exp[Long])(implicit pos: SourceContext) : Exp[LongRange] = LongParUntil(start, end) + def lrange_par_start(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = r match { + case Def(LongParUntil(start, end)) => start + case _ => LongRangeParStart(r) + } + def lrange_par_step(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = LongRangeParStep(r) + def lrange_par_end(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = r match { + case Def(LongParUntil(start, end)) => end + case _ => LongRangeParEnd(r) + } + def lrange_par_foreach(r: Exp[LongRange], block: Exp[Long] => Exp[Unit])(implicit pos: SourceContext): Exp[Unit] = { + val i = fresh[Long] + val a = reifyEffects(block(i)) + reflectEffect(LongRangeParForeach(r.start, r.end, i, a), summarizeEffects(a).star) + } def range_until(start: Exp[Int], end: Exp[Int])(implicit pos: SourceContext) : Exp[Range] = Until(start, end) - def range_start(r: Exp[Range])(implicit pos: SourceContext) : Exp[Int] = r match { + def range_start(r: Exp[Range])(implicit pos: SourceContext) : Exp[Int] = r match { case Def(Until(start, end)) => start case _ => RangeStart(r) } def range_step(r: Exp[Range])(implicit pos: SourceContext) : Exp[Int] = RangeStep(r) - def range_end(r: Exp[Range])(implicit pos: SourceContext) : Exp[Int] = r match { + def range_end(r: Exp[Range])(implicit pos: SourceContext) : Exp[Int] = r match { case Def(Until(start, end)) => end case _ => RangeEnd(r) } @@ -70,12 +97,12 @@ trait RangeOpsExp extends RangeOps with FunctionsExp { } def lrange_until(start: Exp[Long], end: Exp[Long])(implicit pos: SourceContext) : Exp[LongRange] = LongUntil(start, end) - def lrange_start(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = r match { + def lrange_start(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = r match { case Def(LongUntil(start, end)) => start case _ => LongRangeStart(r) } def lrange_step(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = LongRangeStep(r) - def lrange_end(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = r match { + def lrange_end(r: Exp[LongRange])(implicit pos: SourceContext) : Exp[Long] = r match { case Def(LongUntil(start, end)) => end case _ => LongRangeEnd(r) } @@ -83,11 +110,12 @@ trait RangeOpsExp extends RangeOps with FunctionsExp { val i = fresh[Long] val a = reifyEffects(block(i)) reflectEffect(LongRangeForeach(r.start, r.end, i, a), summarizeEffects(a).star) - } - + } + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { case Reflect(RangeForeach(s,e,i,b), u, es) => reflectMirrored(Reflect(RangeForeach(f(s),f(e),f(i).asInstanceOf[Sym[Int]],f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) case Reflect(LongRangeForeach(s,e,i,b), u, es) => reflectMirrored(Reflect(LongRangeForeach(f(s),f(e),f(i).asInstanceOf[Sym[Long]],f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(LongRangeParForeach(s,e,i,b), u, es) => reflectMirrored(Reflect(LongRangeParForeach(f(s),f(e),f(i).asInstanceOf[Sym[Long]],f(b)), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] @@ -95,22 +123,24 @@ trait RangeOpsExp extends RangeOps with FunctionsExp { override def syms(e: Any): List[Sym[Any]] = e match { case RangeForeach(start, end, i, body) => syms(start):::syms(end):::syms(body) case LongRangeForeach(start, end, i, body) => syms(start):::syms(end):::syms(body) + case LongRangeParForeach(start, end, i, body) => syms(start):::syms(end):::syms(body) case _ => super.syms(e) } override def boundSyms(e: Any): List[Sym[Any]] = e match { case RangeForeach(start, end, i, y) => i :: effectSyms(y) case LongRangeForeach(start, end, i, y) => i :: effectSyms(y) + case LongRangeParForeach(start, end, i, y) => i :: effectSyms(y) case _ => super.boundSyms(e) } override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { case RangeForeach(start, end, i, body) => freqNormal(start):::freqNormal(end):::freqHot(body) case LongRangeForeach(start, end, i, body) => freqNormal(start):::freqNormal(end):::freqHot(body) + case LongRangeParForeach(start, end, i, body) => freqNormal(start):::freqNormal(end):::freqHot(body) case _ => super.symsFreq(e) } - } trait BaseGenRangeOps extends GenericNestedCodegen { @@ -132,7 +162,7 @@ trait ScalaGenRangeOps extends ScalaGenEffect with BaseGenRangeOps { stream.println(quote(getBlockResult(body))) stream.println("}") } - */ + */ case RangeForeach(start, end, i, body) => { // do not need to print unit result @@ -140,8 +170,8 @@ trait ScalaGenRangeOps extends ScalaGenEffect with BaseGenRangeOps { gen"var $i : Int = $start" emitValDef(sym, src"while ($i < $end) {") gen"""${nestedBlock(body)} - |$i = $i + 1 - |}""" + |$i = $i + 1 + |}""" } case _ => super.emitNode(sym, rhs) @@ -154,28 +184,28 @@ trait CudaGenRangeOps extends CudaGenEffect with BaseGenRangeOps { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case Until(start, end) => - gen"""${addTab()}int ${sym}_start = $start; - |${addTab()}int ${sym}_end = $end;""" - // Do nothing: will be handled by RangeForeach + gen"""${addTab()}int ${sym}_start = $start; + |${addTab()}int ${sym}_end = $end;""" + // Do nothing: will be handled by RangeForeach - // TODO: What if the range is not continuous integer set? + // TODO: What if the range is not continuous integer set? case RangeForeach(start, end, i, body) => { /* - //var freeVars = buildScheduleForResult(body).filter(scope.contains(_)).map(_.sym) - val freeVars = getFreeVarBlock(body,List(i.asInstanceOf[Sym[Any]])) - // Add the variables of range to the free variable list if necessary - var paramList = freeVars - //val Until(startIdx,endIdx) = findDefinition(r.asInstanceOf[Sym[Range]]).map(_.rhs).get.asInstanceOf[Until] - if(start.isInstanceOf[Sym[Any]]) paramList = start.asInstanceOf[Sym[Any]] :: paramList - if(end.isInstanceOf[Sym[Any]]) paramList = end.asInstanceOf[Sym[Any]] :: paramList - paramList = paramList.distinct - val paramListStr = paramList.map(ele=>remap(ele.tp) + " " + quote(ele)).mkString(", ") - */ - gen"${addTab()}for(int $i=$start; $i < $end; $i++) {" - tabWidth += 1 - emitBlock(body) - tabWidth -= 1 - gen"${addTab()}}" + //var freeVars = buildScheduleForResult(body).filter(scope.contains(_)).map(_.sym) + val freeVars = getFreeVarBlock(body,List(i.asInstanceOf[Sym[Any]])) + // Add the variables of range to the free variable list if necessary + var paramList = freeVars + //val Until(startIdx,endIdx) = findDefinition(r.asInstanceOf[Sym[Range]]).map(_.rhs).get.asInstanceOf[Until] + if(start.isInstanceOf[Sym[Any]]) paramList = start.asInstanceOf[Sym[Any]] :: paramList + if(end.isInstanceOf[Sym[Any]]) paramList = end.asInstanceOf[Sym[Any]] :: paramList + paramList = paramList.distinct + val paramListStr = paramList.map(ele=>remap(ele.tp) + " " + quote(ele)).mkString(", ") + */ + gen"${addTab()}for(int $i=$start; $i < $end; $i++) {" + tabWidth += 1 + emitBlock(body) + tabWidth -= 1 + gen"${addTab()}}" } case _ => super.emitNode(sym, rhs) } @@ -190,8 +220,8 @@ trait OpenCLGenRangeOps extends OpenCLGenEffect with BaseGenRangeOps { throw new GenerationFailedException("OpenCLGenRangeOps: Range vector is not supported") case RangeForeach(start, end, i, body) => gen"""for(int $i=$start; $i < $end; $i++) { - |${nestedBlock(body)} - |}""" + |${nestedBlock(body)} + |}""" case _ => super.emitNode(sym, rhs) } @@ -200,15 +230,15 @@ trait OpenCLGenRangeOps extends OpenCLGenEffect with BaseGenRangeOps { trait CGenRangeOps extends CGenEffect with BaseGenRangeOps { val IR: RangeOpsExp import IR._ - + override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { case RangeForeach(start, end, i, body) => { - LIRTraversal(body) - sym.atPhase(LIRLowering) { - val b = LIRLowering(body) - val be = summarizeEffects(b) - reflectEffect(RangeForeach(LIRLowering(start), LIRLowering(end), i, b), be.star).asInstanceOf[Exp[T]] - } + LIRTraversal(body) + sym.atPhase(LIRLowering) { + val b = LIRLowering(body) + val be = summarizeEffects(b) + reflectEffect(RangeForeach(LIRLowering(start), LIRLowering(end), i, b), be.star).asInstanceOf[Exp[T]] + } } case _ => super.lowerNode(sym, rhs) } @@ -217,19 +247,24 @@ trait CGenRangeOps extends CGenEffect with BaseGenRangeOps { case Until(start, end) => throw new GenerationFailedException("CGenRangeOps: Range vector is not supported") case RangeForeach(start, end, i, body) => - // Some compilers don't like the initialization inside for - stream.println(remap(i.tp) + " " + quote(i) + ";") + // Some compilers don't like the initialization inside for + stream.println(remap(i.tp) + " " + quote(i) + ";") gen"""for($i=$start; $i < $end; $i++) { - |${nestedBlock(body)} - |}""" + |${nestedBlock(body)} + |}""" case LongRangeForeach(start, end, i, body) => - // Some compilers don't like the initialization inside for - stream.println(remap(i.tp) + " " + quote(i) + ";") + // Some compilers don't like the initialization inside for + stream.println(remap(i.tp) + " " + quote(i) + ";") gen"""for($i=$start; $i < $end; $i++) { - |${nestedBlock(body)} - |}""" - - + |${nestedBlock(body)} + |}""" + case LongRangeParForeach(start, end, i, body) => + // Some compilers don't like the initialization inside for + stream.println(remap(i.tp) + " " + quote(i) + ";") + stream.println("#pragma omp parallel for private(" + quote(i) + ")") + gen"""for($i=$start; $i < $end; $i++) { + |${nestedBlock(body)} + |}""" case _ => super.emitNode(sym, rhs) } } diff --git a/src/common/StringOps.scala b/src/common/StringOps.scala index d225a044..5b9083a8 100644 --- a/src/common/StringOps.scala +++ b/src/common/StringOps.scala @@ -230,7 +230,7 @@ trait CGenStringOps extends CGenBase with CNestedCodegen { stream.println("if (" + quote(sym) + " < 0) " + quote(sym) + " = -1;") case StringSubstringWithEndIndex(s, beginIndex, endIndex) => emitValDef(sym, src"malloc($endIndex - $beginIndex + 1); memcpy(" + quote(sym) + "," + quote(s) + src", $endIndex - $beginIndex);" ) - //stream.println(src"char " + quote(sym) + src"[$endIndex - $beginIndex + 1]; memcpy(" + quote(sym) + "," + quote(s) + src", $endIndex - $beginIndex);") + // stream.println(src"char " + quote(sym) + src"[$endIndex - $beginIndex + 1]; memcpy(" + quote(sym) + "," + quote(s) + src", $endIndex - $beginIndex);") UNSAFE case StringTrim(s) => throw new GenerationFailedException("CGenStringOps: StringTrim not implemented yet") case StringSplit(s, sep) => throw new GenerationFailedException("CGenStringOps: StringSplit not implemented yet") case _ => super.emitNode(sym, rhs) diff --git a/src/internal/Effects.scala b/src/internal/Effects.scala index 93c73c0e..ffe40f7e 100644 --- a/src/internal/Effects.scala +++ b/src/internal/Effects.scala @@ -401,15 +401,15 @@ trait Effects extends Expressions with Blocks with Utils { * system!). Initial solution was to override the case where context == * null, however this breaks test4-fac4 (reflectEffect when not needed). */ - if (context == null) { + /*if (context == null) { context = Nil - if (mustPure(u)) super.toAtom(x) - else { - val z = fresh[A] - val zd = Reflect(x,u,null) - createReflectDefinition(z, zd) - } - } else if (mustPure(u)) super.toAtom(x) else { + if (mustPure(u)) super.toAtom(x) + else { + val z = fresh[A] + val zd = Reflect(x,u,null) + createReflectDefinition(z, zd) + } + } else*/ if (mustPure(u)) super.toAtom(x) else { checkContext() // NOTE: reflecting mutable stuff *during mirroring* doesn't work right now. @@ -429,13 +429,13 @@ trait Effects extends Expressions with Blocks with Utils { } else { val z = fresh[A](List(pos)) // make sure all writes go to allocs - if (Config.verbosity >= 1) { - for (w <- u.mayWrite if !isWritableSym(w)) { - printerr("error: write to non-mutable " + w + " -> " + findDefinition(w)) - printerr("at " + z + "=" + zd) - printsrc("in " + quotePos(z)) - } - } + if (Config.verbosity >= 1) { + for (w <- u.mayWrite if !isWritableSym(w)) { + printerr("error: write to non-mutable " + w + " -> " + findDefinition(w)) + printerr("at " + z + "=" + zd) + printsrc("in " + quotePos(z)) + } + } // prevent sharing between mutable objects / disallow mutable escape for non read-only operations // make sure no mutable object becomes part of mutable result (in case of allocation) // or is written to another mutable object (in case of write) From c8e2ea12a2455216c677ee15fa1461a80b9395fd Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Mon, 19 Dec 2016 22:47:48 -0500 Subject: [PATCH 04/10] rough cleanup of common --- src/common/ArrayBufferOps.scala | 249 +---------- src/common/Base.scala | 30 +- src/common/CastingOps.scala | 13 +- src/common/Compile.scala | 9 +- src/common/DSLOps.scala | 13 +- src/common/DateOps.scala | 89 ---- src/common/DynamicRecord.scala | 397 ----------------- src/common/Equal.scala | 52 +-- src/common/ExceptionOps.scala | 28 +- src/common/ForwardTransformer.scala | 8 +- src/common/FractionalOps.scala | 28 +- src/common/GregorianCalendarOps.scala | 56 --- src/common/HashCodeOps.scala | 38 -- src/common/Iterator.scala | 58 --- src/common/ListBuffer.scala | 96 ----- src/common/LivenessOpt.scala | 11 +- src/common/LoopFusionOpt.scala | 2 +- src/common/Loops.scala | 11 +- src/common/MathOps.scala | 106 +++-- src/common/MiscOps.scala | 62 +-- src/common/MultiMap.scala | 158 ------- src/common/NumericOps.scala | 9 +- src/common/ObjectOps.scala | 36 +- src/common/OrderingOps.scala | 201 ++++++--- src/common/PrimitiveOps.scala | 598 +++++++++++++++++++++----- src/common/SetOps.scala | 150 ++----- src/common/SimpleDateFormatOps.scala | 58 --- src/common/SimplifyTransform.scala | 151 +++---- src/common/SplitEffects.scala | 3 + src/common/TreeSet.scala | 126 ------ src/common/TupleOps.scala | 300 ++----------- src/common/UninlinedFunctions.scala | 299 ------------- 32 files changed, 1015 insertions(+), 2430 deletions(-) delete mode 100644 src/common/DateOps.scala delete mode 100644 src/common/DynamicRecord.scala delete mode 100644 src/common/GregorianCalendarOps.scala delete mode 100644 src/common/HashCodeOps.scala delete mode 100644 src/common/Iterator.scala delete mode 100644 src/common/ListBuffer.scala delete mode 100644 src/common/MultiMap.scala delete mode 100644 src/common/SimpleDateFormatOps.scala delete mode 100644 src/common/TreeSet.scala delete mode 100644 src/common/UninlinedFunctions.scala diff --git a/src/common/ArrayBufferOps.scala b/src/common/ArrayBufferOps.scala index f8ab7920..55be988a 100644 --- a/src/common/ArrayBufferOps.scala +++ b/src/common/ArrayBufferOps.scala @@ -8,31 +8,24 @@ import scala.lms.internal.GenericNestedCodegen import collection.mutable.ArrayBuffer import scala.reflect.SourceContext -trait ArrayBufferOps extends Base with Variables { +trait ArrayBufferOps extends Base { object ArrayBuffer { def apply[A:Manifest](xs: Rep[A]*) = arraybuffer_new(xs) } implicit def repToArrayBufferOps[A:Manifest](l: Rep[ArrayBuffer[A]]) = new ArrayBufferOpsCls(l) - implicit def varToArrayBufferOps[A:Manifest](l: Var[ArrayBuffer[A]]) = new ArrayBufferOpsCls(readVar(l)) class ArrayBufferOpsCls[A:Manifest](l: Rep[ArrayBuffer[A]]) { - def apply(e: Rep[Int])(implicit pos: SourceContext) = arraybuffer_apply(l,e) - def append(e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l,e) - def -=(e: Rep[Int])(implicit pos: SourceContext) = arraybuffer_remove(l,e) + def +=(e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l,e) def mkString(sep: Rep[String] = unit(""))(implicit pos: SourceContext) = arraybuffer_mkstring(l,sep) - def foreach(block: Rep[A] => Rep[Unit])(implicit pos: SourceContext) = arraybuffer_foreach(l, block) + def append(l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l,e) + def clear() = arraybuffer_clear(l) def toArray(implicit pos: SourceContext) = arraybuffer_toarray(l) def toSeq(implicit pos: SourceContext) = arraybuffer_toseq(l) - def size(implicit pos: SourceContext) = arraybuffer_size(l) - def clear(implicit pos: SourceContext) = arraybuffer_clear(l) - def indexWhere(f: Rep[A] => Rep[Boolean])(implicit pos: SourceContext) = arraybuffer_indexwhere(l,f) - def minBy[B:Manifest](f: Rep[A] => Rep[B])(implicit pos: SourceContext) = arraybuffer_minBy(l,f) - def foldLeft[B:Manifest](z: Rep[B])(f: (Rep[B], Rep[A]) => Rep[B]) = arraybuffer_foldLeft(l, z)(f) } -// def infix_+=[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l, e) + def infix_+=[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l, e) /* when mixed in with OptiML, one of these infix operations causes an NPE in the scala-virtualized compiler */ //TR: still the case? /* @@ -42,134 +35,48 @@ trait ArrayBufferOps extends Base with Variables { def infix_toArray[A:Manifest](l: Rep[ArrayBuffer[A]])(implicit pos: SourceContext) = arraybuffer_toarray(l) def infix_toSeq[A:Manifest](l: Rep[ArrayBuffer[A]])(implicit pos: SourceContext) = arraybuffer_toseq(l) */ - def arraybuffer_new[A:Manifest](xs: Seq[Rep[A]])(implicit pos: SourceContext): Rep[ArrayBuffer[A]] - def arraybuffer_apply[A:Manifest](l: Rep[ArrayBuffer[A]], i: Rep[Int])(implicit pos: SourceContext): Rep[A] - def arraybuffer_append[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext): Rep[Unit] - def arraybuffer_remove[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[Int])(implicit pos: SourceContext): Rep[Unit] + def arraybuffer_mkstring[A:Manifest](l: Rep[ArrayBuffer[A]], sep: Rep[String])(implicit pos: SourceContext): Rep[String] - def arraybuffer_foreach[A:Manifest](x: Rep[ArrayBuffer[A]], block: Rep[A] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] + def arraybuffer_append[A:Manifest](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext): Rep[Unit] + def arraybuffer_new[A:Manifest](xs: Seq[Rep[A]])(implicit pos: SourceContext): Rep[ArrayBuffer[A]] + def arraybuffer_clear[A:Manifest](l: Rep[ArrayBuffer[A]]): Rep[Unit] def arraybuffer_toarray[A:Manifest](x: Rep[ArrayBuffer[A]])(implicit pos: SourceContext): Rep[Array[A]] def arraybuffer_toseq[A:Manifest](x: Rep[ArrayBuffer[A]])(implicit pos: SourceContext): Rep[Seq[A]] - def arraybuffer_size[A:Manifest](x: Rep[ArrayBuffer[A]])(implicit pos: SourceContext): Rep[Int] - def arraybuffer_clear[A:Manifest](x: Rep[ArrayBuffer[A]])(implicit pos: SourceContext): Rep[Unit] - def arraybuffer_indexwhere[A:Manifest](x: Rep[ArrayBuffer[A]], block: Rep[A] => Rep[Boolean])(implicit pos: SourceContext): Rep[Int] - def arraybuffer_minBy[A:Manifest,B:Manifest](x: Rep[ArrayBuffer[A]], f: Rep[A] => Rep[B])(implicit pos: SourceContext): Rep[A] - def arraybuffer_foldLeft[A:Manifest,B:Manifest](x: Rep[ArrayBuffer[A]], z: Rep[B])(f: (Rep[B], Rep[A]) => Rep[B]): Rep[B] } -trait ArrayBufferOpsExp extends ArrayBufferOps with EffectExp with VariablesExp with FunctionsExp { +trait ArrayBufferOpsExp extends ArrayBufferOps with EffectExp { case class ArrayBufferNew[A:Manifest](xs: Seq[Exp[A]]) extends Def[ArrayBuffer[A]] { val mA = manifest[A] } - case class ArrayBufferApply[A:Manifest](x: Exp[ArrayBuffer[A]], e: Exp[Int]) extends Def[A] { - val mA = manifest[A] - } - case class ArrayBufferAppend[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[A]) extends Def[Unit] { - val mA = manifest[A] - } - case class ArrayBufferRemove[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[Int]) extends Def[Unit] { - val mA = manifest[A] - } case class ArrayBufferMkString[A:Manifest](l: Exp[ArrayBuffer[A]], sep: Exp[String]) extends Def[String] - case class ArrayBufferForeach[A:Manifest](a: Exp[ArrayBuffer[A]], x: Sym[A], block: Block[Unit]) extends Def[Unit] + case class ArrayBufferAppend[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[A]) extends Def[Unit] + case class ArrayBufferClear[A:Manifest](l: Exp[ArrayBuffer[A]]) extends Def[Unit] case class ArrayBufferToArray[A:Manifest](x: Exp[ArrayBuffer[A]]) extends Def[Array[A]] case class ArrayBufferToSeq[A:Manifest](x: Exp[ArrayBuffer[A]]) extends Def[Seq[A]] - case class ArrayBufferSize[A:Manifest](x: Exp[ArrayBuffer[A]]) extends Def[Int] { - val mA = manifest[A] - } - case class ArrayBufferClear[A:Manifest](x: Exp[ArrayBuffer[A]]) extends Def[Unit] - case class ArrayBufferIndexWhere[A:Manifest](a: Exp[ArrayBuffer[A]], k: Sym[A], block: Block[Boolean]) extends Def[Int] { - val mA = manifest[A] - val idx = fresh[Int]; val elem = fresh[A] // Used in the c code generation - } - case class ArrayBufferMinBy[A:Manifest,B:Manifest](a: Exp[ArrayBuffer[A]], x: Sym[A], block: Block[B]) extends Def[A] { - val mA = manifest[A] - val mB = manifest[B] - val idx = fresh[Int]; val min = fresh[B] // Used in the c code generation - } - case class ArrayBufferFoldLeft[A:Manifest,B:Manifest](a: Exp[ArrayBuffer[A]], z: Exp[B], i: Sym[B], e: Sym[A], block: Block[B]) extends Def[B] { - val mA = manifest[A] - val mB = manifest[B] - val idx = fresh[Int] // Used in the c code generation - } def arraybuffer_new[A:Manifest](xs: Seq[Exp[A]])(implicit pos: SourceContext) = reflectMutable(ArrayBufferNew(xs)) - def arraybuffer_apply[A:Manifest](l: Rep[ArrayBuffer[A]], i: Rep[Int])(implicit pos: SourceContext) = ArrayBufferApply(l,i) - def arraybuffer_append[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[A])(implicit pos: SourceContext) = reflectWrite(l)(ArrayBufferAppend(l, e)) - def arraybuffer_remove[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[Int])(implicit pos: SourceContext) = reflectWrite(l)(ArrayBufferRemove(l, e)) def arraybuffer_mkstring[A:Manifest](l: Exp[ArrayBuffer[A]], sep: Exp[String])(implicit pos: SourceContext) = ArrayBufferMkString(l, sep) - def arraybuffer_foreach[A:Manifest](x: Exp[ArrayBuffer[A]], block: Rep[A] => Rep[Unit])(implicit pos: SourceContext) = { - val k = fresh[A] - val b = reifyEffects(block(k)) - reflectEffect(ArrayBufferForeach(x, k, b), summarizeEffects(b).star) - } + def arraybuffer_append[A:Manifest](l: Exp[ArrayBuffer[A]], e: Exp[A])(implicit pos: SourceContext) = reflectWrite(l)(ArrayBufferAppend(l, e)) + def arraybuffer_clear[A:Manifest](l: Exp[ArrayBuffer[A]]) = reflectWrite(l)(ArrayBufferClear(l)) def arraybuffer_toarray[A:Manifest](x: Exp[ArrayBuffer[A]])(implicit pos: SourceContext) = ArrayBufferToArray(x) def arraybuffer_toseq[A:Manifest](x: Exp[ArrayBuffer[A]])(implicit pos: SourceContext) = ArrayBufferToSeq(x) - def arraybuffer_size[A:Manifest](x: Exp[ArrayBuffer[A]])(implicit pos: SourceContext) = ArrayBufferSize(x) - def arraybuffer_clear[A:Manifest](x: Exp[ArrayBuffer[A]])(implicit pos: SourceContext) = ArrayBufferClear(x) - def arraybuffer_indexwhere[A:Manifest](x: Exp[ArrayBuffer[A]], block: Rep[A] => Rep[Boolean])(implicit pos: SourceContext) = { - val k = fresh[A] - val b = reifyEffects(block(k)) - reflectEffect(ArrayBufferIndexWhere(x, k, b), summarizeEffects(b).star) - } - def arraybuffer_minBy[A:Manifest,B:Manifest](x: Exp[ArrayBuffer[A]], f: Rep[A] => Rep[B])(implicit pos: SourceContext) = { - val k = fresh[A] - val b = reifyEffects(f(k)) - reflectEffect(ArrayBufferMinBy(x, k, b)(manifest[A],manifest[B]), summarizeEffects(b).star) - } - def arraybuffer_foldLeft[A:Manifest,B:Manifest](x: Exp[ArrayBuffer[A]], z: Exp[B])(f: (Exp[B], Exp[A]) => Exp[B]) = { - val e = fresh[A] - val i = fresh[B] - val b = reifyEffects(f(i,e)) - reflectEffect(ArrayBufferFoldLeft(x,z,i,e,b), summarizeEffects(b).star) - } ////////////// // mirroring - /*override def mirrorDef[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Def[A] = (e match { + override def mirrorDef[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Def[A] = (e match { case ArrayBufferMkString(l,r) => ArrayBufferMkString(f(l),f(r)) case ArrayBufferAppend(l,r) => ArrayBufferAppend(f(l),f(r)) case _ => super.mirrorDef(e,f) - }).asInstanceOf[Def[A]] // why??*/ + }).asInstanceOf[Def[A]] // why?? +/* override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case Reflect(a@ArrayBufferNew(b), u, es) => reflectMirrored(Reflect(ArrayBufferNew(f(b))(a.mA), mapOver(f,u), f(es))) - case Reflect(a@ArrayBufferAppend(ar,v), u, es) => reflectMirrored(Reflect(ArrayBufferAppend(f(ar),f(v))(a.mA), mapOver(f,u), f(es))) - case Reflect(a@ArrayBufferApply(ar,v), u, es) => reflectMirrored(Reflect(ArrayBufferApply(f(ar),f(v))(a.mA), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(a@ArrayBufferToArray(ar), u, es) => reflectMirrored(Reflect(ArrayBufferToArray(f(ar)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(a@ArrayBufferRemove(ar,v), u, es) => reflectMirrored(Reflect(ArrayBufferRemove(f(ar),f(v))(a.mA), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(a@ArrayBufferSize(ar), u, es) => reflectMirrored(Reflect(ArrayBufferSize(f(ar))(a.mA), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(a@ArrayBufferIndexWhere(m,k,v), u, es) => reflectMirrored(Reflect(ArrayBufferIndexWhere(f(m),k,f(v))(a.mA), mapOver(f,u), f(es))) - case Reflect(a@ArrayBufferMinBy(m,k,v), u, es) => - reflectMirrored(Reflect(ArrayBufferMinBy(f(m).asInstanceOf[Exp[scala.collection.mutable.ArrayBuffer[A]]],k,f(v))(a.mA.asInstanceOf[Manifest[A]],a.mB), mapOver(f,u), f(es))) - case Reflect(afl@ArrayBufferFoldLeft(a,z,i,e,b), u, es) => - reflectMirrored(Reflect(ArrayBufferFoldLeft(f(a),f(z),i,e,f(b))(afl.mA,afl.mB.asInstanceOf[Manifest[A]]), mapOver(f,u), f(es))) + case Reflect(ArrayBufferMkString(l,r), u, es) => reflectMirrored(Reflect(ArrayBufferMkString(f(l),f(r)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(ArrayBufferAppend(l,r), u, es) => reflectMirrored(Reflect(ArrayBufferAppend(f(l),f(r)), mapOver(f,u), f(es)))(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] // why?? - - override def syms(e: Any): List[Sym[Any]] = e match { - case ArrayBufferForeach(m, k, v) => syms(m):::syms(v) - case ArrayBufferMinBy(m, k, v) => syms(m):::syms(v) - case ArrayBufferFoldLeft(m, z, i, e, v) => syms(m):::syms(v) - case _ => super.syms(e) - } - - override def boundSyms(e: Any): List[Sym[Any]] = e match { - case ArrayBufferForeach(m, k, v) => k :: effectSyms(v) - case ArrayBufferIndexWhere(m, k, v) => k :: effectSyms(m) ::: effectSyms(v) - case ArrayBufferMinBy(m, k, v) => k :: effectSyms(v) - case ArrayBufferFoldLeft(m, z, i, e, v) => i :: e :: effectSyms(v) - case _ => super.boundSyms(e) - } - - override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { - case ArrayBufferForeach(m, k, v) => freqNormal(m) ::: freqHot(v) - case ArrayBufferMinBy(m, k, v) => freqNormal(m) ::: freqHot(v) - case ArrayBufferFoldLeft(m, z, i, e, v) => freqNormal(m) ::: freqHot(v) - case _ => super.symsFreq(e) - } - +*/ } trait BaseGenArrayBufferOps extends GenericNestedCodegen { @@ -182,37 +89,12 @@ trait ScalaGenArrayBufferOps extends BaseGenArrayBufferOps with ScalaGenEffect { import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case a@ArrayBufferApply(x, i) => emitValDef(sym, quote(x) + "(" + quote(i) + ")") - case a@ArrayBufferNew(xs) => - emitValDef(sym, "scala.collection.mutable.ArrayBuffer[" + remap(a.mA) + "](" + (xs map quote).mkString(",") + ")") + case a@ArrayBufferNew(xs) => emitValDef(sym, src"scala.collection.mutable.ArrayBuffer[${a.mA}](${(xs map {quote}).mkString(",")})") case ArrayBufferMkString(l, sep) => emitValDef(sym, src"$l.mkString($sep)") case ArrayBufferAppend(l, e) => emitValDef(sym, src"$l += $e") - case ArrayBufferForeach(l, e, b) => - emitValDef(sym, quote(l) + ".foreach(" + quote(e) + "=> {") - emitBlock(b) - emitBlockResult(b) - stream.println("})") - case ArrayBufferRemove(l, e) => emitValDef(sym, src"$l.remove($e)") + case ArrayBufferClear(l) => emitValDef(sym, src"$l.clear()") case ArrayBufferToArray(x) => emitValDef(sym, src"$x.toArray") case ArrayBufferToSeq(x) => emitValDef(sym, src"$x.toSeq") - case ArrayBufferSize(x) => emitValDef(sym, src"$x.size") - case ArrayBufferClear(x) => emitValDef(sym, src"$x.clear") - case ArrayBufferIndexWhere(l, e, b) => - emitValDef(sym, quote(l) + ".indexWhere(" + quote(e) + "=> {") - emitBlock(b) - emitBlockResult(b) - stream.println("})") - case ArrayBufferMinBy(l, e, b) => - emitValDef(sym, quote(l) + ".minBy(" + quote(e) + "=> {") - emitBlock(b) - emitBlockResult(b) - stream.println("})") - case ArrayBufferFoldLeft(l, z, i, e, b) => - emitValDef(i, quote(z)) - emitValDef(sym, quote(l) + ".foldLeft(" + quote(i) + ")((" + quote(i) + "," + quote(e) + ") => {") - emitBlock(b) - emitBlockResult(b) - stream.println("})") case _ => super.emitNode(sym, rhs) } } @@ -221,59 +103,8 @@ trait CLikeGenArrayBufferOps extends BaseGenArrayBufferOps with CLikeGenBase { val IR: ArrayBufferOpsExp import IR._ - override def remap[A](m: Manifest[A]) = m match { - case s if s <:< manifest[ArrayBuffer[Any]] => "GArray*" - case _ => super.remap(m) - } - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { - case a@ArrayBufferNew(xs) => - emitValDef(sym, "g_array_new(NULL, TRUE, sizeof(" + remap(a.mA) + "))") - case a@ArrayBufferApply(x, i) => - emitValDef(sym, "g_array_index(" + quote(x) + "," + remap(a.mA) + ", " + quote(i) + ")") - case ArrayBufferAppend(l, e) => - emitValDef(sym, "g_array_append_val(" + quote(l) + "," + quote(e) + ")") - case ArrayBufferSize(x) => emitValDef(sym, quote(x) + "->len") - case iw@ArrayBufferIndexWhere(a, e, b) => - // TODO: Yannis: This could be done much better through lowering. Volunteers ? :-) - emitValDef(iw.idx, "0") - emitValDef(sym, "-1") - stream.println("for (;" + quote(iw.idx) + "<" + quote(a) + "->len;" + quote(iw.idx) + "+=1) {") - emitValDef(e, "g_array_index(" + quote(a) + "," + remap(iw.mA) + "," + quote(iw.idx) + ");") - emitBlock(b) - stream.println("if (" + quote(getBlockResult(b)) + " == true) {") - stream.println(quote(sym) + " = " + quote(iw.idx) + ";") - stream.println("break;") - stream.println("}") - stream.println("}") - case mb@ArrayBufferMinBy(a,e,b) => - // TODO: Yannis: This as well could be done much better through lowering. Volunteers ? :-) - // Set minimum to first element - emitValDef(e, "g_array_index(" + quote(a) + "," + remap(mb.mA) + ", 0);") - emitBlock(b) - emitValDef(mb.min, quote(getBlockResult(b))) - emitValDef(sym, quote(e)) - // Iterate rest elements and update min if necessary - emitValDef(mb.idx, "1") - stream.println("for (;" + quote(mb.idx) + "<" + quote(a) + "->len;" + quote(mb.idx) + "+=1) {") - emitValDef(e, "g_array_index(" + quote(a) + "," + remap(mb.mA) + "," + quote(mb.idx) + ");") - emitBlock(b) - stream.println("if (" + quote(getBlockResult(b)) + " < " + quote(mb.min) + ") {") - stream.println(quote(sym) + " = " + quote(e) + ";") - stream.println("}") - stream.println("}") - case afl@ArrayBufferFoldLeft(a,z,i,e,b) => - // TODO: Yannis: And finally the same goes here -- this could be done much better through lowering. Volunteers ? :-) - emitValDef(i, quote(z)) - emitValDef(afl.idx, "0") - stream.println("for (;" + quote(afl.idx) + "<" + quote(a) + "->len;" + quote(afl.idx) + "+=1) {") - emitValDef(e, "g_array_index(" + quote(a) + "," + remap(afl.mA) + "," + quote(afl.idx) + ");") - emitBlock(b) - stream.println(quote(i) + " = " + quote(getBlockResult(b)) + ";") - stream.println("}") - emitValDef(sym,quote(i)) - case abr@ArrayBufferRemove(a,idx) => stream.println("g_array_remove_index(" + quote(a) + "," + quote(idx) + ");") case _ => super.emitNode(sym, rhs) } } @@ -281,39 +112,5 @@ trait CLikeGenArrayBufferOps extends BaseGenArrayBufferOps with CLikeGenBase { trait CudaGenArrayBufferOps extends CudaGenEffect with CLikeGenArrayBufferOps trait OpenCLGenArrayBufferOps extends OpenCLGenEffect with CLikeGenArrayBufferOps -trait CGenArrayBufferOps extends CGenEffect with CLikeGenArrayBufferOps { - val IR: ArrayBufferOpsExp - import IR._ - - override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { - case a@ArrayBufferNew(xs) => sym.atPhase(LIRLowering) { arraybuffer_new(xs)(a.mA,implicitly[SourceContext]).asInstanceOf[Exp[A]] } - case aba@ArrayBufferApply(a,e) => sym.atPhase(LIRLowering) { - val lar = LIRLowering(a) - arraybuffer_apply(lar,LIRLowering(e))(aba.mA,implicitly[SourceContext]).asInstanceOf[Exp[A]] - } - case abr@ArrayBufferRemove(a,idx) => sym.atPhase(LIRLowering) { - val lar = LIRLowering(a) - arraybuffer_remove(lar,LIRLowering(idx))(abr.mA,implicitly[SourceContext]).asInstanceOf[Exp[A]] - } - case iw@ArrayBufferIndexWhere(a,k,c) => - LIRTraversal(c) - sym.atPhase(LIRLowering) { - val lar = LIRLowering(a) - reflectEffect(ArrayBufferIndexWhere(lar,k,LIRLowering(c))(iw.mA)).asInstanceOf[Exp[A]] - } - case mb@ArrayBufferMinBy(a,k,c) => - LIRTraversal(c) - sym.atPhase(LIRLowering) { - val lar = LIRLowering(a).asInstanceOf[Exp[scala.collection.mutable.ArrayBuffer[A]]] - reflectEffect(ArrayBufferMinBy(lar,k,LIRLowering(c))(mb.mA.asInstanceOf[Manifest[A]],mb.mB)).asInstanceOf[Exp[A]] - } - case afl@ArrayBufferFoldLeft(a,z,i,e,b) => - LIRTraversal(b) - sym.atPhase(LIRLowering) { - val lar = LIRLowering(a).asInstanceOf[Exp[scala.collection.mutable.ArrayBuffer[Any]]] - reflectEffect(ArrayBufferFoldLeft(lar,LIRLowering(z),i,e,LIRLowering(b))(afl.mA,afl.mB.asInstanceOf[Manifest[A]])).asInstanceOf[Exp[A]] - } - case _ => super.lowerNode(sym,rhs) - } -} +trait CGenArrayBufferOps extends CGenEffect with CLikeGenArrayBufferOps diff --git a/src/common/Base.scala b/src/common/Base.scala index 714cd6fc..f389beb9 100644 --- a/src/common/Base.scala +++ b/src/common/Base.scala @@ -17,12 +17,12 @@ trait LiftAll extends Base { * * @since 0.1 */ -trait Base extends EmbeddedControls with LoweringTransform { +trait Base extends EmbeddedControls { type API <: Base type Rep[+T] - def unit[T:Manifest](x: T): Rep[T] + protected def unit[T:Manifest](x: T): Rep[T] // always lift Unit and Null (for now) implicit def unitToRepUnit(x: Unit) = unit(x) @@ -37,20 +37,11 @@ trait Base extends EmbeddedControls with LoweringTransform { trait BaseExp extends Base with Expressions with Blocks with Transforming { type Rep[+T] = Exp[T] - def unit[T:Manifest](x: T) = Const(x) + protected def unit[T:Manifest](x: T) = Const(x) } -trait BlockExp extends BaseExp +trait BlockExp extends BaseExp with Blocks -/* -trait BlockExp extends BaseExp with Blocks { - - implicit object CanTransformBlock extends CanTransform[Block] { - def transform[A](x: Block[A], t: Transformer): Block[A] = Block(t(x.res)) - } - -} -*/ trait EffectExp extends BaseExp with Effects { @@ -66,17 +57,8 @@ trait EffectExp extends BaseExp with Effects { } override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = e match { -/* - case Reflect(x, u, es) => - reifyEffects { - context = f(es) - mirror(x) - } - -*/ -// case Reflect(Print(x), u, es) => Reflect(Print(f(x)), es map (e => f(e))) case Reflect(x, u, es) => reflectMirrored(mirrorDef(e,f).asInstanceOf[Reflect[A]]) - case Reify(x, u, es) => Reify(f(x), mapOver(f,u), f(es)) //TODO: u + case Reify(x, u, es) => Reify(f(x), mapOver(f,u), f(es)) case _ => super.mirror(e,f) } @@ -85,7 +67,7 @@ trait EffectExp extends BaseExp with Effects { trait BaseFatExp extends BaseExp with FatExpressions with FatTransforming -// The traits below provide an interface to codegen so that client do +// The traits below provide an interface to codegen so that clients do // not need to depend on internal._ trait ScalaGenBase extends ScalaCodegen diff --git a/src/common/CastingOps.scala b/src/common/CastingOps.scala index 4675fd82..58d3edfe 100644 --- a/src/common/CastingOps.scala +++ b/src/common/CastingOps.scala @@ -18,20 +18,21 @@ trait CastingOps extends Variables with OverloadHack { } def rep_isinstanceof[A,B](lhs: Rep[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Rep[Boolean] - def rep_asinstanceof[A,B](lhs: Rep[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Rep[B] + def rep_asinstanceof[A,B:Manifest](lhs: Rep[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Rep[B] } -trait CastingOpsExp extends CastingOps with BaseExp { +trait CastingOpsExp extends CastingOps with BaseExp with EffectExp { this: ImplicitOps => case class RepIsInstanceOf[A,B](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B]) extends Def[Boolean] - case class RepAsInstanceOf[A,B](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B]) extends Def[B] + case class RepAsInstanceOf[A,B:Manifest](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B]) extends Def[B] def rep_isinstanceof[A,B](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) = RepIsInstanceOf(lhs,mA,mB) - def rep_asinstanceof[A,B](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Exp[B] = toAtom(RepAsInstanceOf(lhs,mA,mB))(mB,pos) + def rep_asinstanceof[A,B:Manifest](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Exp[B] = toAtom(RepAsInstanceOf(lhs,mA,mB))(mB,pos) override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case RepAsInstanceOf(lhs, mA, mB) => rep_asinstanceof(f(lhs), mA,mB) + case RepAsInstanceOf(lhs, mA, mB) => rep_asinstanceof(f(lhs),mA,mB)(mtype(mB),pos) + case Reflect(e@RepAsInstanceOf(lhs, mA, mB), u, es) => reflectMirrored(Reflect(RepAsInstanceOf(f(lhs),mA,mB)(mtype(mB)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] } @@ -54,7 +55,7 @@ trait CLikeGenCastingOps extends CLikeGenBase { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { //case RepIsInstanceOf(x,mA,mB) => //TODO: How? - case RepAsInstanceOf(x,mA,mB) => emitValDef(sym, src"($mB) $x") + case RepAsInstanceOf(x,mA,mB) => emitValDef(sym, "(%s) %s".format(remapWithRef(mB),quote(x))) case _ => super.emitNode(sym, rhs) } } diff --git a/src/common/Compile.scala b/src/common/Compile.scala index 7391636c..879d8344 100644 --- a/src/common/Compile.scala +++ b/src/common/Compile.scala @@ -5,11 +5,10 @@ import internal.ScalaCompile trait Compile extends Base { - def compile1[A,B](f: Rep[A] => Rep[B])(implicit mA: Manifest[A], mB: Manifest[B]): A=>B - // Needed for backwards compatibility of tests after renaming compile to - // compile1 for a unified naming scheme - def compile[A,B](f: Rep[A] => Rep[B])(implicit mA: Manifest[A], mB: Manifest[B]) = compile1[A,B](f) + def compile[A,B](f: Rep[A] => Rep[B])(implicit mA: Manifest[A], mB: Manifest[B]): A=>B } -trait CompileScala extends Compile with BaseExp with ScalaCompile +trait CompileScala extends Compile with BaseExp with ScalaCompile { + +} diff --git a/src/common/DSLOps.scala b/src/common/DSLOps.scala index 541b330d..254674cb 100644 --- a/src/common/DSLOps.scala +++ b/src/common/DSLOps.scala @@ -27,15 +27,10 @@ trait ScalaGenDSLOps extends ScalaGenEffect with BaseGenDSLOps { override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case op: DSLOp[_] => val b = op.representation - val strWriter = new java.io.StringWriter - val localStream = new PrintWriter(strWriter); - withStream(localStream) { - gen"""{ - |${nestedBlock(b)} - |$b - |}""" - } - emitValDef(sym, strWriter.toString) + gen"""val $sym = { + |${nestedBlock(b)} + |$b + |}""" case _ => super.emitNode(sym, rhs) } diff --git a/src/common/DateOps.scala b/src/common/DateOps.scala deleted file mode 100644 index 4ca96799..00000000 --- a/src/common/DateOps.scala +++ /dev/null @@ -1,89 +0,0 @@ -package scala.lms -package common - -import scala.lms.common._ -import scala.lms.internal.CNestedCodegen -import scala.reflect.SourceContext -import java.util.Date - -/** - * Lifter Classes for Date - */ -trait DateOps extends Base { - - class DateOpsCls(x: Rep[Date]) { - def getTime(): Rep[Long] = dtGetTime(x) - def getYear(): Rep[Long] = dtGetYear(x) - } - - implicit def date2DateOpsCls(x: Rep[Date]): DateOpsCls = new DateOpsCls(x) - def newDate(): Rep[Date] - def newDate(x: Rep[Long]): Rep[Date] - def dtGetTime(x: Rep[Date]): Rep[Long] - def dtGetYear(x: Rep[Date]): Rep[Long] - def getDateAsString(x: Rep[Long]): Rep[String] -} - -trait DateExp extends DateOps with BaseExp { - - case class DtGetTime(x: Exp[Date]) extends Def[Long] - case class DtGetYear(x: Exp[Date]) extends Def[Long] - case class NewDate(x: Exp[Long]) extends Def[Date] - case class GetDateAsString(x: Exp[Long]) extends Def[String] - - def newDate(): Exp[Date] = NewDate(null) - def newDate(x: Rep[Long]): Exp[Date] = NewDate(x) - def dtGetTime(x: Exp[Date]): Exp[Long] = DtGetTime(x) - def dtGetYear(x: Exp[Date]): Exp[Long] = DtGetYear(x) - def getDateAsString(x: Rep[Long]) = GetDateAsString(x) - - ////////////// - // mirroring - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case NewDate(x) => newDate(x) - case DtGetTime(x) => dtGetTime(f(x)) - case DtGetYear(x) => dtGetYear(f(x)) - case GetDateAsString(x) => getDateAsString(f(x)) - case _ => super.mirror(e,f) - }).asInstanceOf[Exp[A]] // why?? -} - -trait DateExpOpt extends DateExp { - override def dtGetTime(x: Exp[Date]): Exp[Long] = x match { - case Const(x) => unit(x.getTime) - case _ => super.dtGetTime(x) - } -} - -trait ScalaGenDate extends ScalaGenBase { - val IR: DateExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case NewDate(x) => emitValDef(sym, "new java.util.Date(" + { if (x!=null) quote(x) } + ")") - case DtGetTime(x) => emitValDef(sym, quote(x) + ".getTime()"); - case DtGetYear(x) => emitValDef(sym, quote(x) + ".getYear() + 1900"); - case GetDateAsString(x) => emitValDef(sym, "new java.util.Date(" + { if (x!=null) quote(x) } + ").toString") - case _ => super.emitNode(sym, rhs) - } -} - -trait CGenDate extends CGenBase with CNestedCodegen { - val IR: DateExp - import IR._ - - override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { - case NewDate(x) => sym.atPhase(LIRLowering) { LIRLowering(x).asInstanceOf[Exp[T]] } - case _ => super.lowerNode(sym,rhs) - } - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case NewDate(x) => stream.println("long " + quote(sym) + " = " + quote(x) + "; // date") - case DtGetYear(x) => - emitValDef(sym, quote(x) + "/10000") - case gd@GetDateAsString(x) => - emitValDef(sym, getMemoryAllocString("9", "char")) - stream.println("snprintf(" + quote(sym) + ", 9, \"%lu\", " + quote(x) + ");") - case _ => super.emitNode(sym, rhs) - } -} diff --git a/src/common/DynamicRecord.scala b/src/common/DynamicRecord.scala deleted file mode 100644 index 995f4037..00000000 --- a/src/common/DynamicRecord.scala +++ /dev/null @@ -1,397 +0,0 @@ -/*package scala.lms -package common - -import java.io._ -import reflect.ClassManifest -import scala.collection.mutable.HashMap -import scala.lms.internal._ -import scala.lms.util._ -import scala.reflect.SourceContext - -object DynamicRecordsMap extends Serializable { - // We want to be able to call the scala compiler without generating code - var mapInitialized: Boolean = false; - var dataPath: String = null; - var registeredDynamicRecords: HashMap[String, List[(String, Class[_])]] = null - - // Helpers for printing information - def getNames(recname: String) = { - registeredDynamicRecords(recname).map(x => x._1).mkString("|") - } - - def initialize(rootFolder: String) = { - if (mapInitialized) - throw new RuntimeException("DynamicRecordsMap already initialized"); - mapInitialized = true - dataPath = rootFolder - registeredDynamicRecords = new HashMap[String, List[(String, Class[_])]] - } - -} - -object DynamicRecordEffectsMap { - val effectsMap = new collection.mutable.HashMap[(String,String), Any]() -} - -trait DynamicRecord extends Base with Serializable with VariablesExp { - - object NewDynamicRecord { - def apply[T:Manifest](n: String, reuse: Boolean = false) = newDynamicRecord(n, reuse) - } - - class DynamicRecordOps(x: Rep[DynamicRecord]) { - def get(field: Rep[Any]) = dynamicRecordGet(x, field) - def set(field: Rep[Any], value: Rep[Any]) = dynamicRecordSet(x, field, value) - def foreach(f: Rep[DynamicRecord] => Rep[Unit]) = dynamicRecordForEach(x,f) - } - implicit def varDynamicType2dynamicRecordOps(x: Var[DynamicRecord]) = new DynamicRecordOps(readVar(x)) - implicit def varDynamicType2dynamicRecord(x: Var[DynamicRecord]) = readVar(x) - implicit def dynamicRecord2dynamicRecordOps(x: Rep[DynamicRecord]) = new DynamicRecordOps(x) - implicit def dynamicRecord2RepdynamicRecordOps(x: DynamicRecord) = new DynamicRecordOps(unit(x)) - - def newDynamicRecord(name: String, reuse: Boolean = false): Rep[DynamicRecord] - def dynamicRecordGet(x: Rep[DynamicRecord], field: Rep[Any]): Rep[Any] - def dynamicRecordSet(x: Rep[DynamicRecord], field: Rep[Any], value: Rep[Any]): Rep[Unit] - def dynamicRecordForEach(x: Rep[DynamicRecord], f: Rep[DynamicRecord] => Rep[Unit]): Rep[Unit] - val NullDynamicRecord = unit(null).asInstanceOf[Rep[DynamicRecord]] -} - -trait DynamicRecordExp extends DynamicRecord with BaseExp with EffectExp { - case class NewDynamicRecordObj(n: String) extends Def[DynamicRecord] - case class DynamicRecordGet(x: Rep[DynamicRecord], field: Rep[Any]) extends Def[Any] - case class DynamicRecordSet(x: Rep[DynamicRecord], field: Rep[Any], value: Rep[Any]) extends Def[Unit] - case class DynamicRecordForEach(l: Rep[DynamicRecord], x: Sym[DynamicRecord], block: Block[Unit]) extends Def[Unit] - - def newDynamicRecord(name: String, reuse: Boolean = false) = - if (reuse) NewDynamicRecordObj(name) else reflectMutable(NewDynamicRecordObj(name)) - - def dynamicRecordGet(x: Rep[DynamicRecord], field: Rep[Any]) = { - val key = (x.toString, field.toString) - DynamicRecordEffectsMap.effectsMap.get(key) match { - case Some(e) => e.asInstanceOf[Sym[_]] - case None => { - val rE = reflectWrite(x)(DynamicRecordGet(x, field)) - DynamicRecordEffectsMap.effectsMap += key -> rE - rE - } - } - } - - def dynamicRecordSet(x: Rep[DynamicRecord], field: Rep[Any], value: Rep[Any]) = { - val key = (x.toString, field.toString) - // Forces new gets that follow to re-read the entry. - val e = DynamicRecordEffectsMap.effectsMap.remove(key) - reflectEffect(DynamicRecordSet(x,field,value)) - } - - def dynamicRecordForEach(x: Rep[DynamicRecord], f: Exp[DynamicRecord] => Exp[Unit])={ - val a = fresh[DynamicRecord] - val b = reifyEffects(f(a)) - reflectEffect(DynamicRecordForEach(x, a, b), summarizeEffects(b).star) - } - - override def syms(e: Any): List[Sym[Any]] = e match { - case DynamicRecordForEach(a, x, body) => syms(a):::syms(body) - case _ => super.syms(e) - } - - override def boundSyms(e: Any): List[Sym[Any]] = e match { - case DynamicRecordForEach(a, x, body) => x :: effectSyms(body) - case _ => super.boundSyms(e) - } - - override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { - case DynamicRecordForEach(a, x, body) => freqNormal(a):::freqHot(body) - case _ => super.symsFreq(e) - } -} - -trait ScalaGenDynamicRecord extends ScalaGenBase with GenericNestedCodegen { - val IR: DynamicRecordExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { - rhs match { - case NewDynamicRecordObj(x) => emitValDef(sym, "new " + x + "()") - case DynamicRecordGet(x, field) => emitValDef(sym, quote(x) + "." + quote(field).replaceAll("\"","")) - case DynamicRecordSet(x, field, value) => - stream.println(quote(x) + "." + quote(field).replaceAll("\"","") + " = " + quote(value)) - case DynamicRecordForEach(x, init, block) => - stream.println("val x" + sym.toString.replace("Sym(","").replace(")","") + " = {") - stream.println("\tvar " + quote(init) + "=" + quote(x)) - stream.println("\twhile (" + quote(init) + " != null) {") - emitBlock(block) - stream.println("\t\t" + quote(init) + "=" + quote(init) + ".next") - stream.println("\t}") - stream.println("}") - - case _ => super.emitNode(sym, rhs) - } - } - - override def emitDataStructures(out: PrintWriter) { - DynamicRecordsMap.registeredDynamicRecords.foreach( - rec => writeRecord(out, rec._1, rec._2) - ) - //DynamicRecordsMap.registeredDynamicRecords.clear - } - - def writeRecord(out: PrintWriter, className: String, attrs: List[(String, Class[_])]) { - out.print("class " + className + " extends Serializable" +" {\n") - for ((p1,p2) <- attrs) { - val str = { - if (ClassManifest.fromClass(p2) == classManifest[Array[Byte]]) - "Array[Byte]" - else - p2.toString.replaceAll("class ","").replaceAll("int", "scala.Int").replaceAll("double","scala.Double").replaceAll("char", "Char").replaceAll("long", "scala.Long") - } - out.print("private[this] final var _" + p1 + ": " + str + " = null.asInstanceOf[" + str + "];\n") - out.println("@inline final def " + p1 + " = _" + p1) - out.println("@inline final def " + p1 + "_=(x:" + str + ") = _" + p1 + " = x ") - } - out.println("@transient var next: " + className + " = null ") - // Custom toString function - out.print("override def toString() = {\n\"\"+") - out.print( (for ((p1,p2) <- attrs) yield - if (ClassManifest.fromClass(p2) == classManifest[Array[Byte]]) "new String(" + p1 + ")" - else if (p1.contains("DATE")) "{new java.util.Date(" + p1 + ")}" - else p1 - ).mkString("+\"|\"+") ) - out.print("}\n"); - // Custom serialization/deserialization routines - out.println("@throws(classOf[java.io.IOException])") - out.println("private def writeObject(out: java.io.ObjectOutputStream): Unit = {") - for ((p1,p2) <- attrs) { - ClassManifest.fromClass(p2) match { - case m if m <:< classManifest[scala.Int] => out.println("out.writeInt(" + p1 + ")") - case m if m <:< classManifest[scala.Double] => out.println("out.writeDouble(" + p1 + ")") - case m if m <:< classManifest[scala.Char] => out.println("out.writeChar(" + p1 + ")") - case m if m <:< classManifest[scala.Long] => out.println("out.writeLong(" + p1 + ")") - case m if m <:< classManifest[java.lang.String] => out.println("out.writeUTF(" + p1 + ")") - case m if m == classManifest[Array[Byte]] => { - out.println("out.writeInt(" + p1 +".length)") - out.println("out.write(" + p1 + ")") - } - case _ => out.println("out.writeObject(" + p1 + ")") - } - } - out.println("}") - out.println("@throws(classOf[java.io.IOException])") - out.println("private def readObject(in: java.io.ObjectInputStream): Unit = {") - out.println("var length: Int = 0"); - for ((p1,p2) <- attrs) { - ClassManifest.fromClass(p2) match { - case m if m <:< classManifest[scala.Int] => out.println(p1 + " = in.readInt()") - case m if m <:< classManifest[scala.Double] => out.println(p1 + " = in.readDouble()") - case m if m <:< classManifest[scala.Char] => out.println(p1 + " = in.readChar()") - case m if m <:< classManifest[scala.Long] => out.println(p1 + " = in.readLong()") - case m if m <:< classManifest[java.lang.String] => out.println(p1 + " = in.readUTF()") - case m if m == classManifest[Array[Byte]] => { - out.println(p1 + " = new Array[Byte](in.readInt())") - out.println("in.read(" + p1 + ", 0, " + p1 + ".length)") - } - case _ => out.println(p1 + " = in.readObject().asInstanceOf[" + p2.toString.replaceAll("class ","") + "]") - } - } - out.println("}") - out.println("}") // End of class - out.flush - } - - def newDynamicRecordType(name: String, attrs: List[(String, Class[_])]) { - if (DynamicRecordsMap.registeredDynamicRecords.get(name) == None) { - // Register for first use - DynamicRecordsMap.registeredDynamicRecords += (name -> attrs) - // Write to file (for persistence) - val filename = DynamicRecordsMap.dataPath + name + ".scala" - val writer = new PrintWriter(new java.io.File(filename)) - writeRecord(writer, name, attrs) - writer.close() - } - } - -} - -trait CGenDynamicRecord extends CGenBase with GenericNestedCodegen { - val IR: DynamicRecordExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { - rhs match { - case NewDynamicRecordObj(x) => allocStruct(sym, x, stream) - case DynamicRecordGet(x, field) => emitValDef(sym, quote(x) + "->" + quote(field).replaceAll("\"","")) - case DynamicRecordSet(x, field, value) => - stream.println(quote(x) + "->" + quote(field).replaceAll("\"","") + " = " + quote(value) + ";") - case DynamicRecordForEach(x, init, block) => - stream.println("val x" + sym.toString.replace("Sym(","").replace(")","") + " = {") - stream.println("\tvar " + quote(init) + "=" + quote(x)) - stream.println("\twhile (" + quote(init) + " != null) {") - emitBlock(block) - stream.println("\t\t" + quote(init) + "=" + quote(init) + ".next") - stream.println("\t}") - stream.println("}") - case _ => super.emitNode(sym, rhs) - } - } - - override def emitDataStructures(out: PrintWriter) { - DynamicRecordsMap.registeredDynamicRecords.foreach( - rec => writeRecord(out, rec._1, rec._2) - ) - //DynamicRecordsMap.registeredDynamicRecords.clear - } - - def writeRecord(out: PrintWriter, className: String, attrs: List[(String, Class[_])]) { - out.print("struct " + className + " {\n") - for ((p1,p2) <- attrs) out.print(remapInternal(scala.reflect.ClassManifestFactory.fromClass(p2).toString) + " " + p1 + ";\n") - out.println("struct " + className + "* next;") - out.print("};\n") - out.flush - } - - def newDynamicRecordType(name: String, attrs: List[(String, Class[_])]) { - if (DynamicRecordsMap.registeredDynamicRecords.get(name) == None) { - // Register for first use - DynamicRecordsMap.registeredDynamicRecords += (name -> attrs) - val filename = DynamicRecordsMap.dataPath + name + ".c" - val writer = new PrintWriter(new java.io.File(filename)) - writeRecord(writer, name, attrs) - } - } -} - -// HASHMAP -trait DynamicRecordHashMap extends Base with HashMapOps with Variables { - implicit def dRecHashMapToRepHashMapOps[K:Manifest,V:Manifest](m: HashMap[K,V]) = new dynamicRecordHashMapOpsCls[K,V](unit(m)) - implicit def dRecrepHashMapToHashMapOps[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) = new dynamicRecordHashMapOpsCls[K,V](m) - implicit def dRecvarrepHashMapToHashMapOps[K:Manifest,V:Manifest](m: Var[HashMap[K,V]]) = new dynamicRecordHashMapOpsCls[K,V](readVar(m)) - - class dynamicRecordHashMapOpsCls[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) { - def apply(k: Rep[K])(implicit pos: SourceContext) = hashmap_apply(m, k) - def size(implicit pos: SourceContext) = hashmap_size(m) - def removeHead(implicit pos:SourceContext) = hashmap_removehead(m) - def getOrElseUpdate(k: Rep[K], v: => Rep[V], h: Rep[DynamicRecord] => Rep[Int] = null, e: (Rep[DynamicRecord],Rep[DynamicRecord])=>Rep[Boolean]=null)(implicit pos: SourceContext) = hashmap_getorelseupdate[K,V](m,k,v,h,e) - def mkString(delimiter: Rep[String]) = hashmap_mkString(m, delimiter) - } - - override def hashmap_new[K:Manifest,V:Manifest](specializedKey: String = "", specializedValue: String = "")(implicit pos: SourceContext) : Rep[HashMap[K,V]] - override def hashmap_apply[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K])(implicit pos: SourceContext): Rep[V] - override def hashmap_size[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Int] - override def hashmap_removehead[K: Manifest, V: Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[(K,V)] - def hashmap_getorelseupdate[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: => Rep[V], h: Rep[DynamicRecord] => Rep[Int] = null, e: (Rep[DynamicRecord],Rep[DynamicRecord])=>Rep[Boolean] = null)(implicit pos: SourceContext): Rep[V] - override def hashmap_mkString[K: Manifest, V: Manifest](m: Rep[HashMap[K,V]], v: Rep[String])(implicit pos: SourceContext): Rep[String] -} - -trait DynamicRecordHashMapExp extends DynamicRecordHashMap with EffectExp with HashMapOpsExp with DynamicRecordExp { - abstract class DynamicRecordHashMapDef[K:Manifest,V:Manifest,R:Manifest] extends Def[R] { - val mK = manifest[K] - val mV = manifest[V] - } - case class DynamicRecordHashMapNew[K:Manifest,V:Manifest](specializedKey: String = "", specializedValue: String ="") extends DynamicRecordHashMapDef[K,V,HashMap[K,V]] - case class DynamicRecordHashMapApply[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K]) extends DynamicRecordHashMapDef[K,V,V] - case class DynamicRecordHashMapSize[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends DynamicRecordHashMapDef[K,V,Int] - case class DynamicRecordHashMapRemoveHead[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends DynamicRecordHashMapDef[K,V,(K,V)] - case class DynamicRecordHashMapGetOrElseUpdate[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], v: Block[V], h: Block[Int], e: Block[Boolean], d: Sym[DynamicRecord]) extends DynamicRecordHashMapDef[K,V,V] - case class DynamicRecordHashMapMkString[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], v:Rep[String]) extends DynamicRecordHashMapDef[K,V,String] - - override def hashmap_new[K:Manifest,V:Manifest](specializedKey: String = "", specializedValue: String = "")(implicit pos: SourceContext) = reflectMutable(DynamicRecordHashMapNew[K,V](specializedKey, specializedValue)) - override def hashmap_apply[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K])(implicit pos: SourceContext) = DynamicRecordHashMapApply(m,k) - override def hashmap_size[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = DynamicRecordHashMapSize(m) - override def hashmap_removehead[K: Manifest, V: Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = reflectWrite(m)(DynamicRecordHashMapRemoveHead(m)) - def hashmap_getorelseupdate[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: => Exp[V], h: Exp[DynamicRecord] => Exp[Int] = null, e: (Exp[DynamicRecord],Exp[DynamicRecord])=>Exp[Boolean] = null)(implicit pos: SourceContext) = { - val b = reifyEffects(v) - val f = reifyEffects(h(k.asInstanceOf[Rep[DynamicRecord]])) - val ff = fresh[DynamicRecord] - val g = reifyEffects(e(k.asInstanceOf[Rep[DynamicRecord]],ff)) - reflectWrite(m)(DynamicRecordHashMapGetOrElseUpdate(m,k,b,f,g,ff)) - } - override def hashmap_mkString[K: Manifest, V: Manifest](m: Rep[HashMap[K,V]], v: Rep[String])(implicit pos: SourceContext) = reflectEffect(DynamicRecordHashMapMkString(m, v)) - - //override def syms(p: Any): List[Sym[Any]] = p match { - // case HashMapGetOrElseUpdate(m, k, v,h,e) => syms(m):::syms(v) - // case _ => super.syms(p) - //} - - override def boundSyms(p: Any): List[Sym[Any]] = p match { - case DynamicRecordHashMapGetOrElseUpdate(m, k, v,h,e,d) => effectSyms(h) ::: effectSyms(v) ::: effectSyms(e) - case _ => super.boundSyms(p) - } - - //override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { - // case HashMapGetOrElseUpdate(m, k, v,h,e) => freqNormal(m) ::: freqHot(v) - // case _ => super.symsFreq(e) - //} -} - -trait ScalaGenDynamicRecordHashMap extends ScalaGenBase with GenericNestedCodegen with ScalaGenEffect { - val IR: DynamicRecordHashMapExp - import IR._ - - def quoteSizeSymbol(m: Exp[_]): String = { - val sizeSymbol = findInitSymbol(m) - "__" + quote(sizeSymbol) + "Size" - } - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case m@DynamicRecordHashMapNew(spkey, spvalue) => { - val key = if (spkey != "") spkey else remap(m.mK) - val value = if (spvalue != "") spvalue else remap(m.mV) - stream.println("var " + quote(sym) + " = new Array[" + value + "](16)") - stream.println("var __" + quote(sym) + "Size = 0") - } - case DynamicRecordHashMapSize(m) => emitValDef(sym, quoteSizeSymbol(m)) - case DynamicRecordHashMapRemoveHead(m) => { - stream.println("val " + quote(sym) + "= {") - stream.println("var __idx = 0") - stream.println("var __elem = " + quote(m) + "(__idx)") - stream.println("while (__elem == null && __idx < " + quote(m) + ".length) {") - stream.println("__idx = __idx + 1") - stream.println("__elem = " + quote(m) + "(__idx)") - stream.println("}") - stream.println(quote(m) + "(__idx) = __elem.next") - stream.println(quoteSizeSymbol(m) + " -= 1") - stream.println("(__elem, __elem)") - stream.println("}") - } - case DynamicRecordHashMapGetOrElseUpdate(m,k,v,h,e,d) => { - stream.println("val ones = " + quote(m) + ".length - 1") - stream.println("var bc = ones") - stream.println("bc = bc - ((bc >>> 1) & 0x55555555);") - stream.println("bc = (bc & 0x33333333) + ((bc >>> 2) & 0x33333333);") - stream.println("bc = (bc + (bc >>> 4)) & 0x0f0f0f0f;") - stream.println("bc = bc + (bc >>> 8);") - stream.println("bc = bc + (bc >>> 16);") - stream.println("bc = bc & 0x3f;") - emitBlock(h) - stream.println("var hc = " + quote(getBlockResult(h)) + " * 0x9e3775cd") - stream.println("hc = ((hc >>> 24) ) |") - stream.println(" ((hc >> 8) & 0xFF00) |") - stream.println(" ((hc << 8) & 0xFF0000) |") - stream.println(" ((hc << 24));") - stream.println("hc = hc * 0x9e3775cd") - stream.println("val rotation = bc % 32") - stream.println("val improved = (hc >>> rotation) | (hc << (32 - rotation))") - stream.println("val h = (improved >> (32 - bc)) & ones") - stream.println("var e = " + quote(m) + "(h)") - stream.println("while (e != null && !{") - val savedStream = stream - val newSource = new StringWriter() - stream = new PrintWriter(newSource) - emitBlock(e) - stream = savedStream - val outStream = newSource.toString.replaceAll(quote(d), "e") - stream.println(outStream) - emitBlockResult(e) - stream.println("}) e = e.next") - stream.println("var " + quote(sym) + " = e") - stream.println("if (e eq null) {") - emitBlock(v) - stream.println(quote(sym) + " = " + quote(getBlockResult(v))) - stream.println(quote(sym) + ".next = " + quote(m) + "(h)") - stream.println(quote(m) + "(h) = " + quote(sym)) - stream.println(quoteSizeSymbol(m) + " = " + quoteSizeSymbol(m) + " + 1") - stream.println("}") - } - case _ => super.emitNode(sym, rhs) - } -}*/ diff --git a/src/common/Equal.scala b/src/common/Equal.scala index 92092e8c..15b2407f 100644 --- a/src/common/Equal.scala +++ b/src/common/Equal.scala @@ -4,7 +4,6 @@ package common import java.io.PrintWriter import scala.lms.util.OverloadHack import scala.reflect.SourceContext -import scala.lms.internal.CNestedCodegen trait LiftEquals extends Base { this: Equal => @@ -64,7 +63,7 @@ trait EqualExpBridge extends BaseExp { trait EqualExp extends Equal with EqualExpBridge with VariablesExp -trait EqualExpBridgeOpt extends EqualExp { +trait EqualExpBridgeOpt extends EqualExpBridge { override def equals[A:Manifest,B:Manifest](a: Rep[A], b: Rep[B])(implicit pos: SourceContext): Rep[Boolean] = if (a == b) Const(true) else (a,b) match { case (Const(a),Const(b)) => Const(a == b) case _ => super.equals(a,b) @@ -80,41 +79,26 @@ trait EqualExpOpt extends EqualExp with EqualExpBridgeOpt trait ScalaGenEqual extends ScalaGenBase { - val IR: EqualExp + val IR: EqualExpBridge import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case Equal(a,b) => - if (a.tp == manifest[Array[Byte]] || b.tp == manifest[Array[Byte]]) - emitValDef(sym, src"java.util.Arrays.equals($a,$b)") - else emitValDef(sym, src"$a == $b") - case NotEqual(a,b) => - if (a.tp == manifest[Array[Byte]] || b.tp == manifest[Array[Byte]]) - emitValDef(sym, src"!java.util.Arrays.equals($a,$b)") - else emitValDef(sym, src"$a != $b") + case Equal(a,b) => emitValDef(sym, src"$a == $b") + case NotEqual(a,b) => emitValDef(sym, src"$a != $b") case _ => super.emitNode(sym, rhs) } } trait CLikeGenEqual extends CLikeGenBase { - val IR: EqualExp + val IR: EqualExpBridge import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { case Equal(a,b) => - if (b.tp == manifest[Array[Byte]] || b.tp == manifest[String]) - // Hm... is this generic enough? it implicitly introduces a "lowering" for accessing - // the array field of the implicitly lowered array. - // TR: disabled! - //emitValDef(sym, "strcmp(" + quote(a) + "->array," + quote(b) + ") == 0;") - emitValDef(sym, "tpch_strcmp(" + quote(a) + "," + quote(b) + ") == 0;") - else emitValDef(sym, src"$a == $b") + emitValDef(sym, src"$a == $b") case NotEqual(a,b) => - if (b.tp == manifest[Array[Byte]] || b.tp == manifest[String]) - //emitValDef(sym, "strcmp(" + quote(a) + "->array," + quote(b) + ") != 0;") - emitValDef(sym, "tpch_strcmp(" + quote(a) + "," + quote(b) + ") != 0;") - else emitValDef(sym, src"$a != $b") + emitValDef(sym, src"$a != $b") case _ => super.emitNode(sym, rhs) } } @@ -122,14 +106,22 @@ trait CLikeGenEqual extends CLikeGenBase { trait CudaGenEqual extends CudaGenBase with CLikeGenEqual trait OpenCLGenEqual extends OpenCLGenBase with CLikeGenEqual -trait CGenEqual extends CGenBase with CLikeGenEqual with CNestedCodegen { - val IR: EqualExp + +trait CGenEqual extends CGenBase with CLikeGenEqual { + val IR: EqualExpBridge import IR._ - override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { - case Equal(lhs,rhs) => sym.atPhase(LIRLowering) { - reflectEffect(Equal(LIRLowering(lhs),LIRLowering(rhs))).asInstanceOf[Exp[A]] - } - case _ => super.lowerNode(sym,rhs) + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case Equal(a,b) if(remap(a.tp) == "string" && remap(b.tp) == "string") => + emitValDef(sym, quote(a) + ".compare(" + quote(b) + ") == 0") + case Equal(a,b) if (!isPrimitiveType(a.tp) && !isPrimitiveType(b.tp) && (remap(a.tp) == remap(b.tp))) => + emitValDef(sym, quote(a) + "->equals(" + quote(b) + ")") + case NotEqual(a,b) if(remap(a.tp) == "string" && remap(b.tp) == "string") => + emitValDef(sym, quote(a) + ".compare(" + quote(b) + ") != 0") + case NotEqual(a,b) if (!isPrimitiveType(a.tp) && !isPrimitiveType(b.tp) && (remap(a.tp) == remap(b.tp))) => + emitValDef(sym, "!" + quote(a) + "->equals(" + quote(b) + ")") + case _ => super.emitNode(sym, rhs) + } } } diff --git a/src/common/ExceptionOps.scala b/src/common/ExceptionOps.scala index 224f0b8f..f67e0231 100644 --- a/src/common/ExceptionOps.scala +++ b/src/common/ExceptionOps.scala @@ -20,7 +20,7 @@ trait ExceptionOpsExp extends ExceptionOps with EffectExp { def throw_exception(m: Exp[String]) = reflectEffect(ThrowException(m), Global()) override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case Reflect(ThrowException(s), u, es) => reflectMirrored(Reflect(ThrowException(f(s)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(ThrowException(s), u, es) => reflectMirrored(Reflect(ThrowException(f(s)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] } @@ -35,3 +35,29 @@ trait ScalaGenExceptionOps extends ScalaGenBase { } } +trait CLikeGenExceptionOps extends CLikeGenBase { + val IR: ExceptionOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ThrowException(m) => + stream.println("printf(" + quote(m) + ".c_str());") + stream.println("assert(false);") + case _ => super.emitNode(sym, rhs) + } +} + +trait CGenExceptionOps extends CGenBase with CLikeGenExceptionOps +trait CudaGenExceptionOps extends CudaGenBase with CLikeGenExceptionOps { + val IR: ExceptionOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ThrowException(m) => + stream.println("printf(" + quote(m) + ");") + stream.println("assert(false);") + case _ => super.emitNode(sym, rhs) + } +} +//OpenCL does not support printf within a kernel +//trait OpenCLGenExceptionOps extends OpenCLGenBase with CLikeGenExceptionOps diff --git a/src/common/ForwardTransformer.scala b/src/common/ForwardTransformer.scala index 9a035ad4..3485de86 100644 --- a/src/common/ForwardTransformer.scala +++ b/src/common/ForwardTransformer.scala @@ -3,10 +3,9 @@ package common import scala.collection.{immutable,mutable} import scala.reflect.SourceContext -import scala.lms.internal.{Effects, FatTransforming, AbstractSubstTransformer, FatBlockTraversal} trait ForwardTransformer extends internal.AbstractSubstTransformer with internal.FatBlockTraversal { self => - val IR: FatTransforming with Effects //LoopsFatExp with IfThenElseFatExp + val IR: BaseFatExp with EffectExp //LoopsFatExp with IfThenElseFatExp import IR._ def transformBlock[A:Manifest](block: Block[A]): Block[A] = { @@ -32,8 +31,7 @@ trait ForwardTransformer extends internal.AbstractSubstTransformer with internal // // but we'd rather have x15 = x9 + x14 override def apply[A](x: Exp[A]): Exp[A] = subst.get(x) match { - case Some(y) => y.asInstanceOf[Exp[A]] - case _ => x + case Some(y) => y.asInstanceOf[Exp[A]] case _ => x } override def reflectBlock[A](block: Block[A]): Exp[A] = { @@ -136,6 +134,7 @@ trait RecursiveTransformer extends ForwardTransformer { self => trait WorklistTransformer extends ForwardTransformer { // need backward version, too? + val IR: LoopsFatExp with IfThenElseFatExp import IR._ var curSubst: Map[Sym[Any],() => Exp[Any]] = Map.empty var nextSubst: Map[Sym[Any],() => Exp[Any]] = Map.empty @@ -169,4 +168,5 @@ trait WorklistTransformer extends ForwardTransformer { // need backward version, super.transformStm(stm) } } + } diff --git a/src/common/FractionalOps.scala b/src/common/FractionalOps.scala index 3ed56e75..e7ea08f3 100644 --- a/src/common/FractionalOps.scala +++ b/src/common/FractionalOps.scala @@ -3,7 +3,6 @@ package common import java.io.PrintWriter import scala.reflect.SourceContext -import scala.lms.internal.GenericNestedCodegen trait FractionalOps extends ImplicitOps { def infix_/[A,T](lhs: Rep[T], rhs: Rep[A])(implicit c: A => T, f: Fractional[T], mA: Manifest[A], mT: Manifest[T], pos: SourceContext) = fractional_divide(lhs,implicit_convert[A,T](rhs)) @@ -11,21 +10,17 @@ trait FractionalOps extends ImplicitOps { def fractional_divide[T:Fractional:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] } -trait FractionalOpsExp extends FractionalOps with ImplicitOpsExp { +trait FractionalOpsExp extends FractionalOps with ImplicitOpsExp with EffectExp { - case class FractionalDivide[T:Fractional:Manifest](lhs: Exp[T], rhs: Exp[T]) extends Def[T] { - val mT = manifest[T] - val fr = implicitly[Fractional[T]] - } + case class FractionalDivide[T](lhs: Exp[T], rhs: Exp[T])(implicit val f: Fractional[T], val mT: Manifest[T]) extends Def[T] def fractional_divide[T:Fractional:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext) : Rep[T] = FractionalDivide(lhs, rhs) - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { - e match { - case fd@FractionalDivide(lhs, rhs) => FractionalDivide(f(lhs),f(rhs))(fd.fr.asInstanceOf[Fractional[A]],manifest[A]) - case _ => super.mirror(e,f) - } - } + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case e@FractionalDivide(a,b) => fractional_divide(f(a),f(b))(e.f.asInstanceOf[Fractional[A]],mtype(e.mT),pos) + case Reflect(e@FractionalDivide(a,b), u, es) => reflectMirrored(Reflect(FractionalDivide(f(a),f(b))(e.f.asInstanceOf[Fractional[A]],mtype(e.mT)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] } trait ScalaGenFractionalOps extends ScalaGenBase { @@ -53,11 +48,4 @@ trait CLikeGenFractionalOps extends CLikeGenBase { trait CudaGenFractionalOps extends CudaGenBase with CLikeGenFractionalOps trait OpenCLGenFractionalOps extends OpenCLGenBase with CLikeGenFractionalOps -trait CGenFractionalOps extends CGenBase with CLikeGenFractionalOps with GenericNestedCodegen { - val IR: FractionalOpsExp - import IR._ - override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { - case fd@FractionalDivide(a,b) => fractional_divide(LIRLowering(a), LIRLowering(b))(fd.fr.asInstanceOf[Fractional[A]],manifest[A],implicitly[SourceContext]) - case _ => super.lowerNode(sym,rhs) - } -} +trait CGenFractionalOps extends CGenBase with CLikeGenFractionalOps diff --git a/src/common/GregorianCalendarOps.scala b/src/common/GregorianCalendarOps.scala deleted file mode 100644 index 7c0f278e..00000000 --- a/src/common/GregorianCalendarOps.scala +++ /dev/null @@ -1,56 +0,0 @@ -package scala.lms -package common - -import scala.lms.common._ -import scala.reflect.SourceContext -import java.util.Date -import java.util.GregorianCalendar - -/** - * Lifter Classes for GregorianCalendar - */ -trait GregorianCalendarOps extends Base { - - class GregorianCalendarOpsCls(x: Rep[GregorianCalendar]) { - def getTime(): Rep[Date] = gcGetTime(x) - } - - implicit def date2GregorianCalendarOpsCls(x: Rep[GregorianCalendar]): GregorianCalendarOpsCls = new GregorianCalendarOpsCls(x) - def newGregorianCalendar(y: Rep[Int], m: Rep[Int], d: Rep[Int]): Rep[GregorianCalendar] - def gcGetTime(x: Rep[GregorianCalendar]): Rep[Date] -} - -trait GregorianCalendarExp extends GregorianCalendarOps with BaseExp { - - case class NewGregorianCalendar(y: Exp[Int], m: Exp[Int], d: Exp[Int]) extends Def[GregorianCalendar] - case class GcGetTime(x: Exp[GregorianCalendar]) extends Def[Date] - - def newGregorianCalendar(y: Exp[Int], m: Exp[Int], d: Exp[Int]): Exp[GregorianCalendar] = NewGregorianCalendar(y, m, d) - def gcGetTime(x: Exp[GregorianCalendar]): Exp[Date] = GcGetTime(x) - - ////////////// - // mirroring - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case NewGregorianCalendar(y,m,d) => newGregorianCalendar(f(y),f(m),f(d)) - case GcGetTime(x) => gcGetTime(f(x)) - case _ => super.mirror(e,f) - }).asInstanceOf[Exp[A]] // why?? -} - -trait GregorianCalendarExpOpt extends GregorianCalendarExp { - override def gcGetTime(x: Exp[GregorianCalendar]): Exp[Date] = x match { - case Const(x) => unit(x.getTime) - case _ => super.gcGetTime(x) - } -} - -trait ScalaGenGregorianCalendar extends ScalaGenBase { - val IR: GregorianCalendarExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case NewGregorianCalendar(y, m, d) => emitValDef(sym, "new GregorianCalendar(" + quote(y) + ", " + quote(m) + ", " + quote(d) + ")") - case GcGetTime(x) => emitValDef(sym, quote(x) + ".getTime()"); - case _ => super.emitNode(sym, rhs) - } -} \ No newline at end of file diff --git a/src/common/HashCodeOps.scala b/src/common/HashCodeOps.scala deleted file mode 100644 index b9270d14..00000000 --- a/src/common/HashCodeOps.scala +++ /dev/null @@ -1,38 +0,0 @@ -package scala.lms -package common - -import scala.lms.util._ -import scala.lms.internal._ - -trait HashCodeOps extends Base { - def __hashCode(x: Rep[Any]): Rep[Int] -} - -trait HashCodeOpsExp extends BaseExp with EffectExp { - case class HashCode(x: Rep[Any]) extends Def[Int] - def __hashCode(x: Rep[Any]) = reflectEffect(HashCode(x)) -} - -trait ScalaGenHashCodeOps extends ScalaGenBase { - val IR: HashCodeOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { - rhs match { - case HashCode(x) => emitValDef(sym, quote(x) + ".hashCode") - case _ => super.emitNode(sym, rhs) - } - } -} - -trait CGenHashCodeOps extends CGenBase { - val IR: HashCodeOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { - rhs match { - case HashCode(x) => emitValDef(sym, "(int)" + quote(x)) - case _ => super.emitNode(sym, rhs) - } - } -} diff --git a/src/common/Iterator.scala b/src/common/Iterator.scala deleted file mode 100644 index 4b0d9e9b..00000000 --- a/src/common/Iterator.scala +++ /dev/null @@ -1,58 +0,0 @@ -package scala.lms.common - -import scala.lms.internal._ - -trait Iterator extends Base with Variables { - class IteratorOps[A: Manifest](x: Rep[scala.Iterator[A]]) { - def hasNext() = iteratorHasNext(x) - def next() = iteratorNext(x) - def isEmpty() = iteratorIsEmpty(x) - def size() = iteratorSize(x) // Usefull for debugging but consumes all elements - def head() = iteratorHead(x) - } - - implicit def Iter2IteratorOps[A: Manifest](x: Rep[scala.Iterator[A]]) = new IteratorOps[A](x) - implicit def varIterToIteratorOps[A: Manifest](x: Var[scala.Iterator[A]]) = new IteratorOps[A](readVar(x)) - implicit def BufIter2IteratorOps[A: Manifest](x: Rep[scala.BufferedIterator[A]]) = new IteratorOps[A](x) - implicit def varBufIterToIteratorOps[A: Manifest](x: Var[scala.BufferedIterator[A]]) = new IteratorOps[A](readVar(x)) - - def iteratorHasNext[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[Boolean] - def iteratorNext[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[A] - def iteratorIsEmpty[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[Boolean] - def iteratorSize[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[Int] - def iteratorHead[A: Manifest](x: Rep[scala.Iterator[A]]): Rep[A] -} - -trait IteratorExp extends Iterator with BaseExp with Effects /*with VariablesExp*/ { - case class IteratorHasNext[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[Boolean] - case class IteratorNext[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[A] - case class IteratorIsEmpty[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[Boolean] - case class IteratorSize[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[Int] - case class IteratorHead[A: Manifest](x: Rep[scala.Iterator[A]]) extends Def[A] - - def iteratorHasNext[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorHasNext[A](x)) - def iteratorNext[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorNext[A](x)) - def iteratorIsEmpty[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorIsEmpty[A](x)) - def iteratorSize[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorSize[A](x)) - def iteratorHead[A: Manifest](x: Rep[scala.Iterator[A]]) = reflectEffect(IteratorHead[A](x)) -} - -trait ScalaGenIterator extends ScalaGenBase { - val IR: IteratorExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case IteratorHasNext(x) => - emitValDef(sym, quote(x) + ".hasNext") - case IteratorNext(x) => - emitValDef(sym, quote(x) + ".next") - case IteratorIsEmpty(x) => - emitValDef(sym, quote(x) + ".isEmpty") - case IteratorSize(x) => - emitValDef(sym, quote(x) + ".length") - // Note that this will throw an error at runtime if x is Iterator instead of BufferedIterator - case IteratorHead(x) => - emitValDef(sym, quote(x) + ".head") - case _ => super.emitNode(sym, rhs) - } -} diff --git a/src/common/ListBuffer.scala b/src/common/ListBuffer.scala deleted file mode 100644 index 18eaaaa7..00000000 --- a/src/common/ListBuffer.scala +++ /dev/null @@ -1,96 +0,0 @@ -package scala.lms.common - -import scala.collection.mutable -import scala.lms.internal._ - -trait ListBuffer extends Base with Expressions with Variables { - class ListBufferOps[A:Manifest](x: Rep[mutable.ListBuffer[A]]) { - def +=(v: Rep[Any]) = listBufferAdd(x, v) - def remove(v: Rep[Int]) = listBufferRemove(x, v) - def size() = listBufferSize(x) - def head() = listBufferHead(x) - def mkString(v: Rep[String]) = listBufferMkString(x,v) - def foreach[B: Manifest](f: Rep[A] => Rep[B]) = listBufferforeach[A,B](x, f) - } - - implicit def listBuffer2listBufferOps[A:Manifest](x: Rep[mutable.ListBuffer[A]]) = new ListBufferOps(x) - implicit def varlistBuffer2listBufferOps[A:Manifest](x: Var[mutable.ListBuffer[A]]) = new ListBufferOps(readVar(x)) - - def newListBuffer[A:Manifest](): Rep[mutable.ListBuffer[A]] - def listBufferAdd[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Any]): Rep[Unit] - def listBufferRemove[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Int]): Rep[A] - def listBufferSize[A:Manifest](x: Rep[mutable.ListBuffer[A]]): Rep[Int] - def listBufferHead[A:Manifest](x: Rep[mutable.ListBuffer[A]]): Rep[Any] - def listBufferMkString[A:Manifest](x: Rep[mutable.ListBuffer[A]], y: Rep[String]): Rep[String] - def listBufferforeach[A:Manifest, B:Manifest](x: Rep[mutable.ListBuffer[A]], f: Rep[A] => Rep[B]): Rep[Unit] -} - -trait ListBufferExp extends ListBuffer with BaseExp with EffectExp with Effects { - case class ListBufferAdd[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Any]) extends Def[Unit] - case class ListBufferRemove[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Int]) extends Def[A] - case class ListBufferSize[A:Manifest](x: Rep[mutable.ListBuffer[A]]) extends Def[Int] - case class ListBufferHead[A:Manifest](x: Rep[mutable.ListBuffer[A]]) extends Def[Any] - case class NewListBuffer[A:Manifest]() extends Def[mutable.ListBuffer[A]] { - val m = manifest[A] - } - case class ListmkString[A:Manifest](x: Rep[mutable.ListBuffer[A]], y: Rep[String]) extends Def[String] - case class ListBufferForeach[A:Manifest, B:Manifest](l: Exp[mutable.ListBuffer[A]], x: Sym[A], block: Block[B]) extends Def[Unit] - - def newListBuffer[A:Manifest]() = reflectEffect(NewListBuffer[A]()) - def listBufferAdd[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Any]): Rep[Unit] = reflectEffect(ListBufferAdd(x,v)) - def listBufferRemove[A:Manifest](x: Rep[mutable.ListBuffer[A]], v: Rep[Int]): Rep[A] = reflectEffect(ListBufferRemove(x,v)) - def listBufferSize[A:Manifest](x: Rep[mutable.ListBuffer[A]]) = reflectEffect(ListBufferSize(x)) - def listBufferHead[A:Manifest](x: Rep[mutable.ListBuffer[A]]) = reflectEffect(ListBufferHead(x)) - def listBufferMkString[A:Manifest](x: Rep[mutable.ListBuffer[A]], y: Rep[String]) = ListmkString(x,y) - def listBufferforeach[A:Manifest, B:Manifest](x: Rep[mutable.ListBuffer[A]], f: Rep[A] => Rep[B]) = { - val a = fresh[A] - val b = reifyEffects(f(a)) - reflectEffect(ListBufferForeach(x, a, b), summarizeEffects(b).star) - } - - override def syms(e: Any): List[Sym[Any]] = e match { - case ListBufferForeach(a, x, body) => syms(a):::syms(body) - case _ => super.syms(e) - } - - override def boundSyms(e: Any): List[Sym[Any]] = e match { - case ListBufferForeach(a, x, body) => x :: effectSyms(body) - case _ => super.boundSyms(e) - } - - override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { - case ListBufferForeach(a, x, body) => freqNormal(a):::freqHot(body) - case _ => super.symsFreq(e) - } -} - -trait ScalaGenListBuffer extends ScalaGenBase with ScalaNestedCodegen { - val IR: ListBufferExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case l@NewListBuffer() => - emitValDef(sym, "new scala.collection.mutable.ListBuffer[" + remap(l.m) + "]") - case ListBufferAdd(x,v) => emitValDef(sym, quote(x) + " += " + quote(v)) - case ListBufferRemove(x,v) => emitValDef(sym, quote(x) + ".remove(" + quote(v) + ")") - case ListBufferSize(x) => emitValDef(sym, quote(x) + ".size") - case ListBufferHead(x) => emitValDef(sym, quote(x) + ".head") - case ListmkString(x,v) => emitValDef(sym, quote(x) + ".mkString(" + quote(v) + ")") - case ListBufferForeach(l,x,blk) => { - stream.println("val " + quote(sym) + " = " + quote(l) + ".foreach { "+ quote(x) + " => ") - emitBlock(blk) - stream.println(quote(getBlockResult(blk))) - stream.println("}") - } - case _ => super.emitNode(sym, rhs) - } -} - -trait CGenListBuffer extends CGenBase with CNestedCodegen { - val IR: ListBufferExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case _ => super.emitNode(sym, rhs) - } -} diff --git a/src/common/LivenessOpt.scala b/src/common/LivenessOpt.scala index 0ec49082..d966d61e 100644 --- a/src/common/LivenessOpt.scala +++ b/src/common/LivenessOpt.scala @@ -62,6 +62,8 @@ trait DefUseAnalysis extends NestedBlockTraversal { val saveDefUseMap = defUseMap defUseMap + printlog("gathering def-use info for block " + result) + var pairs = List[(Exp[Any],Exp[Any])]() for (TP(sym, rhs) <- innerScope) { @@ -70,9 +72,12 @@ trait DefUseAnalysis extends NestedBlockTraversal { } } - if (saveDefUseMap ne null) - defUseMap = pairs.groupBy(_._1).map(p => (p._1, saveDefUseMap.getOrElse(p._1, Set()) ++ p._2.map(_._2))) - else + if (saveDefUseMap ne null) { + defUseMap = pairs.groupBy(_._1).map(p => (p._1, p._2.map(_._2).toSet)) + for ((k,vs) <- saveDefUseMap) { + defUseMap += (k -> (saveDefUseMap(k) ++ defUseMap.getOrElse(k, Set()))) + } + } else defUseMap = pairs.groupBy(_._1).map(p => (p._1, p._2.map(_._2).toSet)) body diff --git a/src/common/LoopFusionOpt.scala b/src/common/LoopFusionOpt.scala index 379c51a1..cb2087df 100644 --- a/src/common/LoopFusionOpt.scala +++ b/src/common/LoopFusionOpt.scala @@ -405,7 +405,7 @@ trait LoopFusionCore extends internal.FatScheduling with CodeMotion with Simplif val fusedNeg = preNeg flatMap { s1 => postNeg map { s2 => (s1,s2) } } WtableNeg = (fusedNeg ++ WtableNeg).distinct - case _ => partitionsOut = b::partitionsOut + case None => partitionsOut = b::partitionsOut } } diff --git a/src/common/Loops.scala b/src/common/Loops.scala index 1509ee44..4f1b83b4 100644 --- a/src/common/Loops.scala +++ b/src/common/Loops.scala @@ -4,7 +4,6 @@ package common import java.io.PrintWriter import scala.reflect.SourceContext import scala.lms.internal.{FatBlockTraversal,GenericNestedCodegen,GenericFatCodegen} -import scala.reflect.SourceContext trait Loops extends Base { // no surface constructs for now @@ -17,10 +16,10 @@ trait LoopsExp extends Loops with BaseExp with EffectExp { val v: Sym[Int] val body: Def[A] } - + case class SimpleLoop[A](val size: Exp[Int], val v: Sym[Int], val body: Def[A]) extends AbstractLoop[A] - def simpleLoop[A:Manifest](size: Exp[Int], v: Sym[Int], body: Def[A]): Exp[A] = SimpleLoop(size, v, body) + def simpleLoop[A:Manifest](size: Exp[Int], v: Sym[Int], body: Def[A])(implicit pos: SourceContext): Exp[A] = SimpleLoop(size, v, body) override def syms(e: Any): List[Sym[Any]] = e match { @@ -49,6 +48,7 @@ trait LoopsExp extends Loops with BaseExp with EffectExp { override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { case SimpleLoop(s,v,body: Def[A]) => simpleLoop(f(s),f(v).asInstanceOf[Sym[Int]],mirrorFatDef(body,f)) + case Reflect(SimpleLoop(s,v,body: Def[A]), u, es) if u == Control() => reflectMirrored(Reflect(SimpleLoop(f(s),f(v).asInstanceOf[Sym[Int]],mirrorFatDef(body,f)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] // why?? @@ -176,6 +176,9 @@ trait ScalaGenLoopsFat extends ScalaGenLoops with ScalaGenFat with BaseGenLoopsF trait CLikeGenLoops extends CLikeGenBase with BaseGenLoops trait CLikeGenLoopsFat extends CLikeGenLoops with CLikeGenFat with BaseGenLoopsFat +trait CGenLoops extends CGenBase with CLikeGenLoops +trait CGenLoopsFat extends CGenLoops with CGenFat with CLikeGenLoopsFat + trait GPUGenLoops extends GPUGenBase with CLikeGenLoops trait GPUGenLoopsFat extends GPUGenLoops with GPUGenFat with CLikeGenLoopsFat @@ -183,4 +186,4 @@ trait CudaGenLoops extends CudaGenBase with GPUGenLoops trait CudaGenLoopsFat extends CudaGenLoops with CudaGenFat with GPUGenLoopsFat trait OpenCLGenLoops extends OpenCLGenBase with GPUGenLoops -trait OpenCLGenLoopsFat extends OpenCLGenLoops with OpenCLGenFat with GPUGenLoopsFat \ No newline at end of file +trait OpenCLGenLoopsFat extends OpenCLGenLoops with OpenCLGenFat with GPUGenLoopsFat diff --git a/src/common/MathOps.scala b/src/common/MathOps.scala index ce0d75aa..580ca10e 100755 --- a/src/common/MathOps.scala +++ b/src/common/MathOps.scala @@ -12,17 +12,23 @@ trait MathOps extends Base { def floor(x: Rep[Double])(implicit pos: SourceContext) = math_floor(x) def exp(x: Rep[Double])(implicit pos: SourceContext) = math_exp(x) def log(x: Rep[Double])(implicit pos: SourceContext) = math_log(x) + def log10(x: Rep[Double])(implicit ctx: SourceContext) = math_log10(x) def sqrt(x: Rep[Double])(implicit pos: SourceContext) = math_sqrt(x) def sin(x: Rep[Double])(implicit pos: SourceContext) = math_sin(x) + def sinh(x: Rep[Double])(implicit ctx: SourceContext) = math_sinh(x) + def asin(x: Rep[Double])(implicit ctx: SourceContext) = math_asin(x) def cos(x: Rep[Double])(implicit pos: SourceContext) = math_cos(x) + def cosh(x: Rep[Double])(implicit ctx: SourceContext) = math_cosh(x) def acos(x: Rep[Double])(implicit pos: SourceContext) = math_acos(x) + def tan(x: Rep[Double])(implicit ctx: SourceContext) = math_tan(x) + def tanh(x: Rep[Double])(implicit ctx: SourceContext) = math_tanh(x) def atan(x: Rep[Double])(implicit pos: SourceContext) = math_atan(x) def atan2(x: Rep[Double], y: Rep[Double])(implicit pos: SourceContext) = math_atan2(x,y) def pow(x: Rep[Double], y: Rep[Double])(implicit pos: SourceContext) = math_pow(x,y) def abs[A:Manifest:Numeric](x: Rep[A])(implicit pos: SourceContext) = math_abs(x) def max[A:Manifest:Numeric](x: Rep[A], y: Rep[A])(implicit pos: SourceContext) = math_max(x,y) def min[A:Manifest:Numeric](x: Rep[A], y: Rep[A])(implicit pos: SourceContext) = math_min(x,y) - def Pi(implicit pos: SourceContext) = math_pi + def Pi(implicit pos: SourceContext) = 3.141592653589793238462643383279502884197169 def E(implicit pos: SourceContext) = math_e } @@ -30,10 +36,16 @@ trait MathOps extends Base { def math_floor(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_exp(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_log(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] + def math_log10(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] def math_sqrt(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_sin(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] + def math_sinh(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] + def math_asin(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] def math_cos(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] + def math_cosh(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] def math_acos(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] + def math_tan(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] + def math_tanh(x: Rep[Double])(implicit ctx: SourceContext): Rep[Double] def math_atan(x: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_atan2(x: Rep[Double], y: Rep[Double])(implicit pos: SourceContext) : Rep[Double] def math_pow(x: Rep[Double], y: Rep[Double])(implicit pos: SourceContext): Rep[Double] @@ -49,10 +61,16 @@ trait MathOpsExp extends MathOps with EffectExp { case class MathFloor(x: Exp[Double]) extends Def[Double] case class MathExp(x: Exp[Double]) extends Def[Double] case class MathLog(x: Exp[Double]) extends Def[Double] + case class MathLog10(x: Exp[Double]) extends Def[Double] case class MathSqrt(x: Exp[Double]) extends Def[Double] case class MathSin(x: Exp[Double]) extends Def[Double] + case class MathSinh(x: Exp[Double]) extends Def[Double] + case class MathAsin(x: Exp[Double]) extends Def[Double] case class MathCos(x: Exp[Double]) extends Def[Double] + case class MathCosh(x: Exp[Double]) extends Def[Double] case class MathAcos(x: Exp[Double]) extends Def[Double] + case class MathTan(x: Exp[Double]) extends Def[Double] + case class MathTanh(x: Exp[Double]) extends Def[Double] case class MathAtan(x: Exp[Double]) extends Def[Double] case class MathAtan2(x: Exp[Double], y: Exp[Double]) extends Def[Double] case class MathPow(x: Exp[Double], y: Exp[Double]) extends Def[Double] @@ -66,10 +84,16 @@ trait MathOpsExp extends MathOps with EffectExp { def math_floor(x: Exp[Double])(implicit pos: SourceContext) = MathFloor(x) def math_exp(x: Exp[Double])(implicit pos: SourceContext) = MathExp(x) def math_log(x: Exp[Double])(implicit pos: SourceContext) = MathLog(x) + def math_log10(x: Exp[Double])(implicit ctx: SourceContext) = MathLog10(x) def math_sqrt(x: Exp[Double])(implicit pos: SourceContext) = MathSqrt(x) def math_sin(x: Exp[Double])(implicit pos: SourceContext) = MathSin(x) + def math_sinh(x: Exp[Double])(implicit ctx: SourceContext) = MathSinh(x) + def math_asin(x: Exp[Double])(implicit ctx: SourceContext) = MathAsin(x) def math_cos(x: Exp[Double])(implicit pos: SourceContext) = MathCos(x) + def math_cosh(x: Exp[Double])(implicit ctx: SourceContext) = MathCosh(x) def math_acos(x: Exp[Double])(implicit pos: SourceContext) = MathAcos(x) + def math_tan(x: Exp[Double])(implicit ctx: SourceContext) = MathTan(x) + def math_tanh(x: Exp[Double])(implicit ctx: SourceContext) = MathTanh(x) def math_atan(x: Exp[Double])(implicit pos: SourceContext) = MathAtan(x) def math_atan2(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = MathAtan2(x,y) def math_pow(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = MathPow(x,y) @@ -77,7 +101,7 @@ trait MathOpsExp extends MathOps with EffectExp { def math_max[A:Manifest:Numeric](x: Exp[A], y: Exp[A])(implicit pos: SourceContext) = MathMax(x, y) def math_min[A:Manifest:Numeric](x: Exp[A], y: Exp[A])(implicit pos: SourceContext) = MathMin(x, y) def math_pi(implicit pos: SourceContext) = MathPi() - def math_e(implicit pos: SourceContext) = MathE() + def math_e(implicit pos: SourceContext) = MathE() override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = ({ implicit var a: Numeric[A] = null // hack!! need to store it in Def instances?? @@ -95,20 +119,32 @@ trait MathOpsExp extends MathOps with EffectExp { case MathAtan2(x,y) => math_atan2(f(x),f(y)) case MathMin(x,y) => math_min(f(x),f(y)) case MathMax(x,y) => math_max(f(x),f(y)) + case MathLog10(x) => math_log10(f(x)) + case MathSinh(x) => math_sinh(f(x)) + case MathAsin(x) => math_asin(f(x)) + case MathCosh(x) => math_cosh(f(x)) + case MathTan(x) => math_tan(f(x)) + case MathTanh(x) => math_tanh(f(x)) - case Reflect(MathCeil(x), u, es) => reflectMirrored(Reflect(MathCeil(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathFloor(x), u, es) => reflectMirrored(Reflect(MathFloor(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathExp(x), u, es) => reflectMirrored(Reflect(MathExp(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathPow(x,y), u, es) => reflectMirrored(Reflect(MathPow(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathAbs(x), u, es) => reflectMirrored(Reflect(MathAbs(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathSin(x), u, es) => reflectMirrored(Reflect(MathSin(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathCos(x), u, es) => reflectMirrored(Reflect(MathCos(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathAcos(x), u, es) => reflectMirrored(Reflect(MathAcos(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathLog(x), u, es) => reflectMirrored(Reflect(MathLog(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathSqrt(x), u, es) => reflectMirrored(Reflect(MathSqrt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathAtan2(x,y), u, es) => reflectMirrored(Reflect(MathAtan2(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathMin(x,y), u, es) => reflectMirrored(Reflect(MathMin(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(MathMax(x,y), u, es) => reflectMirrored(Reflect(MathMax(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(MathCeil(x), u, es) => reflectMirrored(Reflect(MathCeil(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathFloor(x), u, es) => reflectMirrored(Reflect(MathFloor(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathExp(x), u, es) => reflectMirrored(Reflect(MathExp(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathPow(x,y), u, es) => reflectMirrored(Reflect(MathPow(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathAbs(x), u, es) => reflectMirrored(Reflect(MathAbs(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathSin(x), u, es) => reflectMirrored(Reflect(MathSin(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathCos(x), u, es) => reflectMirrored(Reflect(MathCos(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathAcos(x), u, es) => reflectMirrored(Reflect(MathAcos(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathLog(x), u, es) => reflectMirrored(Reflect(MathLog(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathSqrt(x), u, es) => reflectMirrored(Reflect(MathSqrt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathAtan2(x,y), u, es) => reflectMirrored(Reflect(MathAtan2(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathMin(x,y), u, es) => reflectMirrored(Reflect(MathMin(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathMax(x,y), u, es) => reflectMirrored(Reflect(MathMax(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathLog10(x), u, es) => reflectMirrored(Reflect(MathLog10(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathSinh(x), u, es) => reflectMirrored(Reflect(MathSinh(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathAsin(x), u, es) => reflectMirrored(Reflect(MathAsin(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathCosh(x), u, es) => reflectMirrored(Reflect(MathCosh(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathTan(x), u, es) => reflectMirrored(Reflect(MathTan(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(MathTanh(x), u, es) => reflectMirrored(Reflect(MathTanh(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) } @@ -126,15 +162,21 @@ trait ScalaGenMathOps extends BaseGenMathOps with ScalaGenEffect { val IR: MathOpsExp import IR._ - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { // TODO: use java.lang.Math etc... + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case MathCeil(x) => emitValDef(sym, src"java.lang.Math.ceil($x)") case MathFloor(x) => emitValDef(sym, src"java.lang.Math.floor($x)") case MathExp(x) => emitValDef(sym, src"java.lang.Math.exp($x)") case MathLog(x) => emitValDef(sym, src"java.lang.Math.log($x)") + case MathLog10(x) => emitValDef(sym, src"java.lang.Math.log10($x)") case MathSqrt(x) => emitValDef(sym, src"java.lang.Math.sqrt($x)") case MathSin(x) => emitValDef(sym, src"java.lang.Math.sin($x)") + case MathSinh(x) => emitValDef(sym, "java.lang.Math.sinh($x)") + case MathAsin(x) => emitValDef(sym, "java.lang.Math.asin($x)") case MathCos(x) => emitValDef(sym, src"java.lang.Math.cos($x)") + case MathCosh(x) => emitValDef(sym, "java.lang.Math.cosh($x)") case MathAcos(x) => emitValDef(sym, src"java.lang.Math.acos($x)") + case MathTan(x) => emitValDef(sym, "java.lang.Math.tan($x)") + case MathTanh(x) => emitValDef(sym, "java.lang.Math.tanh($x)") case MathAtan(x) => emitValDef(sym, src"java.lang.Math.atan($x)") case MathAtan2(x,y) => emitValDef(sym, src"java.lang.Math.atan2($x, $y)") case MathPow(x,y) => emitValDef(sym, src"java.lang.Math.pow($x,$y)") @@ -142,7 +184,7 @@ trait ScalaGenMathOps extends BaseGenMathOps with ScalaGenEffect { case MathMax(x,y) => emitValDef(sym, src"java.lang.Math.max($x, $y)") case MathMin(x,y) => emitValDef(sym, src"java.lang.Math.min($x, $y)") case MathPi() => emitValDef(sym, "java.lang.Math.PI") - case MathE() => emitValDef(sym, "java.lang.Math.E") + case MathE() => emitValDef(sym, "java.lang.Math.E") case _ => super.emitNode(sym, rhs) } } @@ -173,9 +215,7 @@ trait ScalaGenMathOpsApacheCommons extends ScalaGenMathOps { } - - -trait CudaGenMathOps extends BaseGenMathOps with CudaGenEffect { +trait CLikeGenMathOps extends BaseGenMathOps with CLikeGenEffect { val IR: MathOpsExp import IR._ @@ -198,36 +238,42 @@ trait CudaGenMathOps extends BaseGenMathOps with CudaGenEffect { case MathMin(x,y) if(remap(sym.tp))=="float" => emitValDef(sym, src"fmin($x, $y)") case MathMin(x,y) if(remap(sym.tp))=="double" => emitValDef(sym, src"fmin($x, $y)") case MathMin(x,y) if(remap(sym.tp))=="int" => emitValDef(sym, src"min($x, $y)") + case _ => super.emitNode(sym, rhs) + } +} + + +trait CudaGenMathOps extends CLikeGenMathOps with CudaGenEffect { + val IR: MathOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case MathPi() => emitValDef(sym, "CUDART_PI_F") case MathE() => emitValDef(sym, "2.7182818284f") case _ => super.emitNode(sym, rhs) } } -trait OpenCLGenMathOps extends BaseGenMathOps with OpenCLGenEffect { +trait OpenCLGenMathOps extends CLikeGenMathOps with OpenCLGenEffect { val IR: MathOpsExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case MathCeil(x) => emitValDef(sym, src"ceil($x)") - case MathFloor(x) => emitValDef(sym, src"floor($x)") - case MathExp(x) => emitValDef(sym, src"exp($x)") - case MathLog(x) => emitValDef(sym, src"log($x)") - case MathSqrt(x) => emitValDef(sym, src"sqrt($x)") - case MathAbs(x) => emitValDef(sym, src"abs($x)") + case MathPi() => emitValDef(sym, "M_PI") + case MathE() => emitValDef(sym, "M_E") case MathMax(x,y) => emitValDef(sym, src"max($x, $y)") case MathMin(x,y) => emitValDef(sym, src"min($x, $y)") case _ => super.emitNode(sym, rhs) } } -trait CGenMathOps extends BaseGenMathOps with CGenEffect { +trait CGenMathOps extends CLikeGenMathOps with CGenEffect { val IR: MathOpsExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case MathSin(x) if(remap(sym.tp)=="double") => emitValDef(sym, src"sin($x)") - case MathPi() if(remap(sym.tp)=="double") => emitValDef(sym, "M_PI") + case MathPi() => emitValDef(sym, "M_PI") + case MathE() => emitValDef(sym, "M_E") case _ => super.emitNode(sym, rhs) } diff --git a/src/common/MiscOps.scala b/src/common/MiscOps.scala index a1ace074..5deca961 100644 --- a/src/common/MiscOps.scala +++ b/src/common/MiscOps.scala @@ -36,7 +36,6 @@ trait MiscOpsExp extends MiscOps with EffectExp { def print(x: Exp[Any])(implicit pos: SourceContext) = reflectEffect(Print(x)) // TODO: simple effect def println(x: Exp[Any])(implicit pos: SourceContext) = reflectEffect(PrintLn(x)) // TODO: simple effect def printf(f: String, x: Rep[Any]*)(implicit pos: SourceContext): Rep[Unit] = reflectEffect(PrintF(f, x.toList)) - def printf(f: String, x: List[Rep[Any]])(implicit pos: SourceContext): Rep[Unit] = reflectEffect(PrintF(f, x)) def exit(s: Exp[Int])(implicit pos: SourceContext) = reflectEffect(Exit(s)) def error(s: Exp[String])(implicit pos: SourceContext) = reflectEffect(Error(s)) def returnL(x: Exp[Any])(implicit pos: SourceContext) = { @@ -46,12 +45,12 @@ trait MiscOpsExp extends MiscOps with EffectExp { } override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case Reflect(Error(x), u, es) => reflectMirrored(Reflect(Error(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(Print(x), u, es) => reflectMirrored(Reflect(Print(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(PrintLn(x), u, es) => reflectMirrored(Reflect(PrintLn(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(PrintF(fm,x), u, es) => reflectMirrored(Reflect(PrintF(fm,f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(Exit(x), u, es) => reflectMirrored(Reflect(Exit(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(Return(x), u, es) => reflectMirrored(Reflect(Return(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(Error(x), u, es) => reflectMirrored(Reflect(Error(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(Print(x), u, es) => reflectMirrored(Reflect(Print(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(PrintLn(x), u, es) => reflectMirrored(Reflect(PrintLn(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(PrintF(fm,x), u, es) => reflectMirrored(Reflect(PrintF(fm,f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(Exit(x), u, es) => reflectMirrored(Reflect(Exit(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(Return(x), u, es) => reflectMirrored(Reflect(Return(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] } @@ -61,35 +60,46 @@ trait ScalaGenMiscOps extends ScalaGenEffect { import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case PrintF(f,xs) => - stream.print("printf(\"\"\"" + f.replace("\\n","\n") + "\"\"\"") - if (xs.size != 0) stream.print(xs.map(x => quote(x)).mkString(",",",","")) - stream.println(")") - case PrintLn(s) => gen"println($s)" - case Print(s) => gen"print($s)" - case Exit(a) => gen"exit($a)" - case Return(x) => gen"return $x" - case Error(s) => gen"error($s)" + case PrintF(f,xs) => emitValDef(sym, src"printf(${f::xs})") + case PrintLn(s) => emitValDef(sym, src"println($s)") + case Print(s) => emitValDef(sym, src"print($s)") + case Exit(a) => emitValDef(sym, src"exit($a)") + case Return(x) => emitValDef(sym, src"return $x") + case Error(s) => emitValDef(sym, src"error($s)") case _ => super.emitNode(sym, rhs) } } -trait CGenMiscOps extends CGenEffect with GenericNestedCodegen { +trait CGenMiscOps extends CGenEffect { val IR: MiscOpsExp import IR._ - -/* override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { - //TR case PrintLn(x) => sym.atPhase(LIRLowering) { println(LIRLowering(x)).asInstanceOf[Exp[A]] } - case _ => super.lowerNode(sym, rhs) + + def format(s: Exp[Any]): String = { + remap(s.tp) match { + case "uint16_t" => "%c" + case "bool" | "int8_t" | "int16_t" | "int32_t" => "%d" + case "int64_t" => "%ld" + case "float" | "double" => "%f" + case "string" => "%s" + case _ => throw new GenerationFailedException("CGenMiscOps: cannot print type " + remap(s.tp)) + } + } + + def quoteRawString(s: Exp[Any]): String = { + remap(s.tp) match { + case "string" => quote(s) + ".c_str()" + case _ => quote(s) + } } -*/ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case PrintF(f,xs) => gen"printf(${Const(f:String)::xs});" - case PrintLn(s) => gen"""printf("%s\n",$s);""" - case Print(s) => gen"""printf("%s",$s);""" - case Exit(a) => gen"exit($a);" + case PrintF(f,x) => stream.println("printf(" + ((Const(f:String)::x).map(quoteRawString)).mkString(",") + ");") + case PrintLn(s) => stream.println("printf(\"" + format(s) + "\\n\"," + quoteRawString(s) + ");") + case Print(s) => stream.println("printf(\"" + format(s) + "\"," + quoteRawString(s) + ");") + case Exit(a) => stream.println("exit(" + quote(a) + ");") + case Return(x) => stream.println("return " + quote(x) + ";") + case Error(s) => stream.println("error(-1,0,\"%s\"," + quote(s) + ");") case _ => super.emitNode(sym, rhs) } } diff --git a/src/common/MultiMap.scala b/src/common/MultiMap.scala deleted file mode 100644 index 2f40c5b8..00000000 --- a/src/common/MultiMap.scala +++ /dev/null @@ -1,158 +0,0 @@ -package scala.lms -package common - -import java.io.PrintWriter -import scala.lms.internal._ -import scala.collection.mutable.{HashMap,Set} -import scala.reflect.SourceContext - -trait HashMultiMapOps extends Base with Variables { - object HashMultiMap { - def apply[K:Manifest,V:Manifest](size: Long = 0, specializedKey: String = "", specializedValue:String = "")(implicit pos: SourceContext) = hashmultimap_new[K,V](size, specializedKey, specializedValue) - } - - implicit def HashMultiMapToRepHashMapOps[K:Manifest,V:Manifest](m: HashMap[K,Set[V]]) = new hashMultiMapOpsCls(unit(m)) - implicit def repHashMultiMapToHashMapOps[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]]) = new hashMultiMapOpsCls(m) - implicit def varrepHashMultiMapToHashMapOps[K:Manifest,V:Manifest](m: Var[HashMap[K,Set[V]]]) = new hashMultiMapOpsCls(readVar(m)) - - class hashMultiMapOpsCls[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]]) { - def apply(k: Rep[K])(implicit pos: SourceContext) = hashmultimap_apply(m, k) - def update(k: Rep[K], v: Rep[V])(implicit pos: SourceContext) = hashmultimap_update(m,k,v) - def contains(k: Rep[K])(implicit pos: SourceContext) = hashmultimap_contains(m, k) - def foreach(block: Rep[(K,Set[V])] => Rep[Unit])(implicit pos: SourceContext) = hashmultimap_foreach(m, block) - def mkString(delimiter: Rep[String]) = hashmultimap_mkString(m, delimiter) - def getOrElseEmpty(k: Rep[K])(implicit pos: SourceContext) = hashmultimap_getorelseempty(m,k) - def remove(k: Rep[K], v: Rep[V])(implicit pos: SourceContext) = hashmultimap_remove(m,k,v) - } - - def hashmultimap_new[K:Manifest,V:Manifest](size: Long = 0, specializedKey: String = "", specializedValue: String = "")(implicit pos: SourceContext) : Rep[HashMap[K,Set[V]]] - def hashmultimap_apply[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K])(implicit pos: SourceContext): Rep[Set[V]] - def hashmultimap_update[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext): Rep[Unit] - def hashmultimap_contains[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], i: Rep[K])(implicit pos: SourceContext): Rep[Boolean] - def hashmultimap_foreach[K:Manifest,V:Manifest](x: Rep[HashMap[K,Set[V]]], block: Rep[(K,Set[V])] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] - def hashmultimap_mkString[K: Manifest, V: Manifest](m: Rep[HashMap[K,Set[V]]], v: Rep[String])(implicit pos: SourceContext): Rep[String] - def hashmultimap_getorelseempty[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K])(implicit pos: SourceContext): Rep[Set[V]] - def hashmultimap_remove[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext): Rep[Unit] -} - -trait HashMultiMapOpsExp extends HashMultiMapOps with EffectExp { - abstract class HashMultiMapDef[K:Manifest,V:Manifest,R:Manifest] extends Def[R] { - val mK = manifest[K] - val mV = manifest[V] - } - case class HashMultiMapNew[K:Manifest,V:Manifest](size: Long = 0, specializedKey: String = "", specializedValue: String ="") extends HashMultiMapDef[K,Set[V],HashMap[K,Set[V]]] - case class HashMultiMapApply[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K]) extends HashMultiMapDef[K,V,Set[V]] - case class HashMultiMapUpdate[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K], v: Exp[V]) extends HashMultiMapDef[K,V,Unit] - case class HashMultiMapContains[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], i: Exp[K]) extends HashMultiMapDef[K,V,Boolean] - case class HashMultiMapForeach[K:Manifest, V:Manifest](a: Exp[HashMap[K,Set[V]]], x: Sym[(K,Set[V])], block: Block[Unit]) extends Def[Unit] - case class HashMultiMapMkString[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], v:Rep[String]) extends HashMultiMapDef[K,V,String] - case class HashMultiMapGetOrElseEmpty[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K]) extends HashMultiMapDef[K,V,Set[V]] - case class HashMultiMapRemove[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K], v: Exp[V]) extends HashMultiMapDef[K,V,Unit] - - def hashmultimap_new[K:Manifest,V:Manifest](size: Long = 0, specializedKey: String = "", specializedValue: String = "")(implicit pos: SourceContext) = reflectEffect(HashMultiMapNew[K,V](size, specializedKey, specializedValue)) - def hashmultimap_apply[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K])(implicit pos: SourceContext) = reflectEffect(HashMultiMapApply[K,V](m,k)) - def hashmultimap_update[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], k: Exp[K], v: Exp[V])(implicit pos: SourceContext) = reflectEffect(HashMultiMapUpdate[K,V](m,k,v)) - def hashmultimap_contains[K:Manifest,V:Manifest](m: Exp[HashMap[K,Set[V]]], i: Exp[K])(implicit pos: SourceContext) = HashMultiMapContains(m, i) - def hashmultimap_foreach[K:Manifest,V:Manifest](x: Rep[HashMap[K,Set[V]]], block: Rep[(K,Set[V])] => Rep[Unit])(implicit pos: SourceContext) = { - val k = fresh[(K,Set[V])] - val b = reifyEffects(block(k)) - reflectEffect(HashMultiMapForeach(x, k, b), summarizeEffects(b).star) - } - def hashmultimap_mkString[K: Manifest, V: Manifest](m: Rep[HashMap[K,Set[V]]], v: Rep[String])(implicit pos: SourceContext) = reflectEffect(HashMultiMapMkString(m, v)) - def hashmultimap_getorelseempty[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K])(implicit pos: SourceContext) = reflectEffect(HashMultiMapGetOrElseEmpty(m,k)) - def hashmultimap_remove[K:Manifest,V:Manifest](m: Rep[HashMap[K,Set[V]]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext) = reflectEffect(HashMultiMapRemove(m,k,v)) - - override def syms(e: Any): List[Sym[Any]] = e match { - case HashMultiMapForeach(a, x, body) => syms(a):::syms(body) - case _ => super.syms(e) - } - - override def boundSyms(e: Any): List[Sym[Any]] = e match { - case HashMultiMapForeach(a, x, body) => x :: effectSyms(body) - case _ => super.boundSyms(e) - } - - override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { - case HashMultiMapForeach(a, x, body) => freqNormal(a):::freqHot(body) - case _ => super.symsFreq(e) - } - - -} - -trait ScalaGenHashMultiMap extends GenericNestedCodegen with ScalaGenEffect { - val IR: HashMultiMapOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case m@HashMultiMapNew(size, spkey, spvalue) => { - val key = if (spkey != "") spkey else remap(m.mK) - val value = if (spvalue != "") spvalue else remap(m.mV) - emitValDef(sym, "new collection.mutable.HashMap[" + key + ", " + value + "]() with scala.collection.mutable.MultiMap[" + key + "," + value.replace("scala.collection.mutable.Set[","").replace("]","") + "]") - } - case HashMultiMapApply(m,k) => emitValDef(sym, quote(m) + "(" + quote(k) + ")") - case HashMultiMapGetOrElseEmpty(m,k) => emitValDef(sym, quote(m) + ".getOrElse(" + quote(k) + ", scala.collection.mutable.Set.empty)") - case HashMultiMapUpdate(m,k,v) => emitValDef(sym, quote(m) + ".addBinding(" + quote(k) + "," + quote(v) + ")") - case HashMultiMapContains(m,i) => emitValDef(sym, quote(m) + ".contains(" + quote(i) + ")") - case HashMultiMapForeach(m,k,v) => emitValDef(sym, quote(m) + ".foreach(" + quote(k) + "=>{") - emitBlock(v) - emitBlockResult(v) - stream.println("})") - case HashMultiMapMkString(m,k) => emitValDef(sym, quote(m) + ".mkString(" + quote(k) + ")") - case HashMultiMapRemove(m,k,v) => emitValDef(sym, quote(m) + "(" + quote(k) + ").remove(" + quote(v) +")") - case _ => super.emitNode(sym, rhs) - } -} - -trait ScalaGenHashMultiMapOpt extends GenericNestedCodegen with ScalaGenEffect { - val IR: HashMultiMapOpsExp - import IR._ - - def emitKeyModulo[K: Manifest, V: Manifest](m: Rep[HashMap[K, Set[V]]], k: Rep[K]) = { - quote(k) + "%" + quote(m) + ".length" - } - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case m@HashMultiMapNew(size, spkey, spvalue) => { - // Sanity check - //if (m.mV != manifest[Set[scala.lms.common.DynamicRecord]]) - // throw new RuntimeException("ScalaGenHashMultiMapOpt can only be used with sets of DynamicRecords (you provided " + remap(m.mV)) - val value = if (spvalue != "") spvalue else remap(m.mV) - emitValDef(sym, "new Array[" + value + "](" + size + ")") - } - case HashMultiMapApply(m,k) => { - stream.println("val " + quote(sym) + " = " + quote(m) + "(" + emitKeyModulo(m,k) + ")") - } - case HashMultiMapUpdate(m,k,v) => { - stream.println("\nval x" + sym.toString.replace("Sym(","").replace(")","") + " = {") - stream.println("\tval __elem = " + quote(m) + "(" + emitKeyModulo(m,k) + ")") - stream.println("\tif (__elem == null) " + quote(m) + "(" + emitKeyModulo(m,k) + ") = " + quote(v)) - stream.println("\telse {") - stream.println("\t\t" + quote(v) + ".next = __elem") - stream.println("\t\t" + quote(m) + "(" + emitKeyModulo(m,k) + ") = " + quote(v)) - stream.println("\t}") - stream.println("}") - } - case HashMultiMapContains(m,k) => { - stream.println("val " + quote(sym) + " = " + quote(m) + "(" + emitKeyModulo(m,k) + ") != null") - } - case HashMultiMapGetOrElseEmpty(m,k) => - // Note: here you get back a null if you have no elements ("the else") but we handle - // this case in the for-each function in the dynamic record (which should be used to - // iterate over the values in a way similar to the normal multimap) - stream.println("val " + quote(sym) + " = " + quote(m) + "(" + emitKeyModulo(m,k) + ")") - case HashMultiMapMkString(m,k) => emitValDef(sym, quote(m) + ".mkString(" + emitKeyModulo(m,k) + ")") - case HashMultiMapRemove(m,k,v) => { - stream.println("\tvar __elem = " + quote(m) + "(" + emitKeyModulo(m,k) + ")") - stream.println("\tvar __prevelem = __elem; __prevelem = null;") - stream.println("\twhile ((__elem != null) && (__elem.equals(" + quote(v) + ") == false)) {") - stream.println("\t\t__prevelem = __elem") - stream.println("\t\t__elem = __elem.next") - stream.println("}") - stream.println("\tif (__elem == null) throw new RuntimeException(\"Element to be removed not found\")") - stream.println("\telse if (__prevelem != null) __prevelem.next = __elem.next") - stream.println("\telse " + quote(m) + "(" + emitKeyModulo(m,k) + ") = __elem.next") - } - case _ => super.emitNode(sym, rhs) - } -} diff --git a/src/common/NumericOps.scala b/src/common/NumericOps.scala index 5c2024e1..f5e33575 100644 --- a/src/common/NumericOps.scala +++ b/src/common/NumericOps.scala @@ -11,6 +11,7 @@ trait LiftNumeric { } trait NumericOps extends Variables { + this: PrimitiveOps => // workaround for infix not working with manifests implicit def numericToNumericOps[T:Numeric:Manifest](n: T) = new NumericOpsCls(unit(n)) @@ -25,9 +26,6 @@ trait NumericOps extends Variables { def /(rhs: Rep[T])(implicit pos: SourceContext) = numeric_divide(lhs,rhs) } - //def infix_+[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T]) = numeric_plus(lhs,rhs) - //def infix_-[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T]) = numeric_minus(lhs,rhs) - //def infix_*[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T]) = numeric_times(lhs,rhs) def numeric_plus[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] def numeric_minus[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] def numeric_times[T:Numeric:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] @@ -38,6 +36,8 @@ trait NumericOps extends Variables { } trait NumericOpsExp extends NumericOps with VariablesExp with BaseFatExp { + this: PrimitiveOpsExp => + abstract class DefMN[A:Manifest:Numeric] extends Def[A] { def mev = manifest[A] def aev = implicitly[Numeric[A]] @@ -65,6 +65,7 @@ trait NumericOpsExp extends NumericOps with VariablesExp with BaseFatExp { trait NumericOpsExpOpt extends NumericOpsExp { + this: PrimitiveOpsExp => override def numeric_plus[T:Numeric:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Exp[T] = (lhs,rhs) match { case (Const(x), Const(y)) => Const(implicitly[Numeric[T]].plus(x,y)) @@ -86,8 +87,6 @@ trait NumericOpsExpOpt extends NumericOpsExp { } override def numeric_divide[T:Numeric:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Exp[T] = (lhs,rhs) match { // CAVEAT: Numeric doesn't have .div, Fractional has - case (Const(x), Const(y)) if manifest[T] == manifest[Int] => super.numeric_divide(lhs, rhs) - case (Const(x), Const(y)) if manifest[T] == manifest[Long] => super.numeric_divide(lhs, rhs) case (Const(x), Const(y)) => Const(implicitly[Numeric[T]].asInstanceOf[Fractional[T]].div(x,y)) case _ => super.numeric_divide(lhs,rhs) } diff --git a/src/common/ObjectOps.scala b/src/common/ObjectOps.scala index 170fbb6a..8b9355f4 100644 --- a/src/common/ObjectOps.scala +++ b/src/common/ObjectOps.scala @@ -7,23 +7,18 @@ import scala.lms.internal.{GenerationFailedException} import scala.reflect.SourceContext trait ObjectOps extends Variables with OverloadHack { - //def infix_toString(lhs: Rep[Any])(implicit pos: SourceContext) = object_tostring(lhs) + def infix_toString(lhs: Rep[Any])(implicit pos: SourceContext) = object_tostring(lhs) def infix_ToString(lhs: Rep[Any])(implicit pos: SourceContext) = object_tostring(lhs) - //def infix_hashCode(lhs: Rep[Any])(implicit pos: SourceContext) = object_hashcode(lhs) - //def infix_##(lhs: Rep[Any])(implicit pos: SourceContext) = object_hashcode(lhs) - def infix_HashCode(lhs: Rep[Any])(implicit pos: SourceContext) = object_hashcode(lhs) def infix_unsafeImmutable[A:Manifest](lhs: Rep[A])(implicit pos: SourceContext) = object_unsafe_immutable(lhs) def infix_unsafeMutable[A:Manifest](lhs: Rep[A])(implicit pos: SourceContext) = object_unsafe_mutable(lhs) def object_tostring(lhs: Rep[Any])(implicit pos: SourceContext): Rep[String] - def object_hashcode(lhs: Rep[Any])(implicit pos: SourceContext): Rep[Int] def object_unsafe_immutable[A:Manifest](lhs: Rep[A])(implicit pos: SourceContext): Rep[A] def object_unsafe_mutable[A:Manifest](lhs: Rep[A])(implicit pos: SourceContext): Rep[A] } trait ObjectOpsExp extends ObjectOps with VariablesExp { case class ObjectToString(o: Exp[Any]) extends Def[String] - case class ObjectHashCode(o: Exp[Any]) extends Def[Int] case class ObjectUnsafeImmutable[A:Manifest](o: Exp[A]) extends Def[A] { val m = manifest[A] } @@ -32,7 +27,6 @@ trait ObjectOpsExp extends ObjectOps with VariablesExp { } def object_tostring(lhs: Exp[Any])(implicit pos: SourceContext) = ObjectToString(lhs) - def object_hashcode(lhs: Exp[Any])(implicit pos: SourceContext) = ObjectHashCode(lhs) def object_unsafe_immutable[A:Manifest](lhs: Exp[A])(implicit pos: SourceContext) = lhs match { // INVESTIGATE: there was an issue where Const(0).unsafeImmutable == Const(0.0). How is this possible? CSE with primitive widening? case c@Const(x) => c @@ -46,9 +40,8 @@ trait ObjectOpsExp extends ObjectOps with VariablesExp { override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { case e@ObjectUnsafeImmutable(a) => object_unsafe_immutable(f(a))(mtype(e.m),pos) case e@ObjectToString(a) => object_tostring(f(a)) - case e@ObjectHashCode(a) => object_hashcode(f(a)) - case Reflect(e@ObjectUnsafeImmutable(a), u, es) => reflectMirrored(Reflect(ObjectUnsafeImmutable(f(a))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@ObjectUnsafeMutable(a), u, es) => reflectMirrored(Reflect(ObjectUnsafeMutable(f(a))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case Reflect(e@ObjectUnsafeImmutable(a), u, es) => reflectMirrored(Reflect(ObjectUnsafeImmutable(f(a))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@ObjectUnsafeMutable(a), u, es) => reflectMirrored(Reflect(ObjectUnsafeMutable(f(a))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] @@ -86,23 +79,36 @@ trait ObjectOpsExpOpt extends ObjectOpsExp { trait ScalaGenObjectOps extends ScalaGenBase { val IR: ObjectOpsExp import IR._ - + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case ObjectToString(lhs) => emitValDef(sym, src"($lhs).toString()") - case ObjectHashCode(lhs) => emitValDef(sym, src"($lhs).##") case ObjectUnsafeImmutable(x) => emitValDef(sym, src"$x// unsafe immutable") case ObjectUnsafeMutable(x) => emitValDef(sym, src"$x// unsafe mutable") case _ => super.emitNode(sym, rhs) } } +trait GPUGenObjectOps extends GPUGenBase { + val IR: ObjectOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ObjectUnsafeImmutable(x) => + emitValDef(sym, quote(x) + "; // unsafe immutable") + emitPtrDef(sym, x) + case ObjectUnsafeMutable(x) => + emitValDef(sym, quote(x) + "; // unsafe mutable") + emitPtrDef(sym, x) + case _ => super.emitNode(sym, rhs) + } +} + trait CLikeGenObjectOps extends CLikeGenBase { val IR: ObjectOpsExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ObjectToString(lhs) => emitValDef(sym, src"($lhs).toString()") - case ObjectHashCode(lhs) => emitValDef(sym, src"($lhs).##") + case ObjectToString(x) => emitValDef(sym, src"($x).toString()") case ObjectUnsafeImmutable(x) => emitValDef(sym, src"$x; // unsafe immutable") case ObjectUnsafeMutable(x) => emitValDef(sym, src"$x; // unsafe mutable") case _ => super.emitNode(sym, rhs) @@ -111,4 +117,4 @@ trait CLikeGenObjectOps extends CLikeGenBase { trait CudaGenObjectOps extends CudaGenBase with CLikeGenObjectOps trait OpenCLGenObjectOps extends OpenCLGenBase with CLikeGenObjectOps -trait CGenObjectOps extends CGenBase with CLikeGenObjectOps +trait CGenObjectOps extends CGenBase with CLikeGenObjectOps diff --git a/src/common/OrderingOps.scala b/src/common/OrderingOps.scala index 3b784472..b7e99694 100644 --- a/src/common/OrderingOps.scala +++ b/src/common/OrderingOps.scala @@ -10,52 +10,35 @@ trait OrderingOps extends Base with Variables with OverloadHack { implicit def orderingToOrderingOps[T:Ordering:Manifest](n: T) = new OrderingOpsCls(unit(n)) implicit def repOrderingToOrderingOps[T:Ordering:Manifest](n: Rep[T]) = new OrderingOpsCls(n) implicit def varOrderingToOrderingOps[T:Ordering:Manifest](n: Var[T]) = new OrderingOpsCls(readVar(n)) - implicit val x: Ordering[Array[Byte]] = null - implicit val y: Ordering[Rep[Array[Byte]]] = null class OrderingOpsCls[T:Ordering:Manifest](lhs: Rep[T]){ - def <(rhs: Rep[T])(implicit pos: SourceContext) = ordering_lt[T](lhs, rhs) - def <=(rhs: Rep[T])(implicit pos: SourceContext) = ordering_lteq[T](lhs, rhs) - def >(rhs: Rep[T])(implicit pos: SourceContext) = ordering_gt[T](lhs, rhs) - def >=(rhs: Rep[T])(implicit pos: SourceContext) = ordering_gteq[T](lhs, rhs) - def equiv(rhs: Rep[T])(implicit pos: SourceContext) = ordering_equiv[T](lhs, rhs) - def max(rhs: Rep[T])(implicit pos: SourceContext) = ordering_max[T](lhs, rhs) - def min(rhs: Rep[T])(implicit pos: SourceContext) = ordering_min[T](lhs, rhs) - - def <[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_lt[T](lhs, c(rhs)) - def <=[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_lteq[T](lhs, c(rhs)) - def >[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_gt[T](lhs, c(rhs)) - def >=[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_gteq[T](lhs, c(rhs)) - def equiv[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_equiv[T](lhs, c(rhs)) - def max[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_max[T](lhs, c(rhs)) - def min[B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_min[T](lhs, c(rhs)) - - // We need these methods, e.g. when we are comparing a Double (on rhs) with a Long (on lhs) - // But, they will not solve the problem, because it will happen again other way around! - // def <[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_lt[B](c(lhs), rhs) - // def <=[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_lteq[B](c(lhs), rhs) - // def >[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_gt[B](c(lhs), rhs) - // def >=[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_gteq[B](c(lhs), rhs) - // def equiv[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_equiv[B](c(lhs), rhs) - // def max[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_max[B](c(lhs), rhs) - // def min[B:Ordering:Manifest](rhs: Rep[B])(implicit c: Rep[T] => Rep[B], pos: SourceContext) = ordering_min[B](c(lhs), rhs) + def < (rhs: Rep[T])(implicit pos: SourceContext) = ordering_lt(lhs, rhs) + def <= (rhs: Rep[T])(implicit pos: SourceContext) = ordering_lteq(lhs, rhs) + def > (rhs: Rep[T])(implicit pos: SourceContext) = ordering_gt(lhs, rhs) + def >= (rhs: Rep[T])(implicit pos: SourceContext) = ordering_gteq(lhs, rhs) + def equiv (rhs: Rep[T])(implicit pos: SourceContext) = ordering_equiv(lhs, rhs) + def max (rhs: Rep[T])(implicit pos: SourceContext) = ordering_max(lhs, rhs) + def min (rhs: Rep[T])(implicit pos: SourceContext) = ordering_min(lhs, rhs) + def compare (rhs: Rep[T])(implicit pos: SourceContext) = ordering_compare(lhs, rhs) + + def < [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_lt(lhs, c(rhs)) + def <= [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_lteq(lhs, c(rhs)) + def > [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_gt(lhs, c(rhs)) + def >= [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_gteq(lhs, c(rhs)) + def equiv [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_equiv(lhs, c(rhs)) + def max [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_max(lhs, c(rhs)) + def min [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_min(lhs, c(rhs)) + def compare [B](rhs: B)(implicit c: B => Rep[T], pos: SourceContext) = ordering_compare(lhs, c(rhs)) } -// def infix_<[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_lt(lhs,c(rhs)) -// def infix_<=[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_lteq(lhs,c(rhs)) -// def infix_>[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_gt(lhs,c(rhs)) -// def infix_>=[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_gteq(lhs,c(rhs)) -// def infix_equiv[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_equiv(lhs,c(rhs)) -// def infix_max[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_max(lhs,c(rhs)) -// def infix_min[T,B](lhs: Rep[T], rhs: B)(implicit o: Ordering[T], c: B => Rep[T], mT: Manifest[T]) = ordering_min(lhs,c(rhs)) - - def ordering_lt[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_lteq[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_gt[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_gteq[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_equiv[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] - def ordering_max[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] - def ordering_min[T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] + def ordering_lt [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_lteq [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_gt [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_gteq [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_equiv [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Boolean] + def ordering_max [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] + def ordering_min [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] + def ordering_compare [T:Ordering:Manifest](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[Int] } @@ -64,48 +47,124 @@ trait OrderingOpsExp extends OrderingOps with VariablesExp { def mev = manifest[T] def aev = implicitly[Ordering[T]] } - case class OrderingLT[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingLTEQ[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingGT[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingGTEQ[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingEquiv[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] - case class OrderingMax[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,T] - case class OrderingMin[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,T] - - def ordering_lt[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingLT(lhs,rhs) - def ordering_lteq[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingLTEQ(lhs,rhs) - def ordering_gt[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingGT(lhs,rhs) - def ordering_gteq[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingGTEQ(lhs,rhs) - def ordering_equiv[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingEquiv(lhs,rhs) - def ordering_max[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = OrderingMax(lhs,rhs) - def ordering_min[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = OrderingMin(lhs,rhs) - - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { - (e match { - case e@OrderingLT(a,b) => ordering_lt(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingLTEQ(a,b) => ordering_lteq(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingGT(a,b) => ordering_gt(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingGTEQ(a,b) => ordering_gteq(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingEquiv(a,b) => ordering_equiv(f(a),f(b))(e.aev,e.mev,pos) - case e@OrderingMax(a,b) => ordering_max(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev),pos) - case e@OrderingMin(a,b) => ordering_min(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev),pos) + case class OrderingLT [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingLTEQ [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingGT [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingGTEQ [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingEquiv [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Boolean] + case class OrderingMax [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,T] + case class OrderingMin [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,T] + case class OrderingCompare [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T]) extends DefMN[T,Int] + + def ordering_lt [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingLT(lhs,rhs) + def ordering_lteq [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingLTEQ(lhs,rhs) + def ordering_gt [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingGT(lhs,rhs) + def ordering_gteq [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingGTEQ(lhs,rhs) + def ordering_equiv [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = OrderingEquiv(lhs,rhs) + def ordering_max [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = OrderingMax(lhs,rhs) + def ordering_min [T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = OrderingMin(lhs,rhs) + def ordering_compare[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Int] = OrderingCompare(lhs,rhs) + + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case e@OrderingLT(a,b) => ordering_lt(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingLTEQ(a,b) => ordering_lteq(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingGT(a,b) => ordering_gt(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingGTEQ(a,b) => ordering_gteq(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingEquiv(a,b) => ordering_equiv(f(a),f(b))(e.aev,e.mev,pos) + case e@OrderingMax(a,b) => ordering_max(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev),pos) + case e@OrderingMin(a,b) => ordering_min(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev),pos) + case e@OrderingCompare(a,b) => ordering_compare(f(a),f(b))(e.aev,e.mev,pos) + case Reflect(e@OrderingLT(a,b), u, es) => reflectMirrored(Reflect(OrderingLT(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@OrderingLTEQ(a,b), u, es) => reflectMirrored(Reflect(OrderingLTEQ(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@OrderingGT(a,b), u, es) => reflectMirrored(Reflect(OrderingGT(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@OrderingGTEQ(a,b), u, es) => reflectMirrored(Reflect(OrderingGTEQ(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@OrderingEquiv(a,b), u, es) => reflectMirrored(Reflect(OrderingEquiv(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@OrderingMax(a,b), u, es) => reflectMirrored(Reflect(OrderingMax(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@OrderingMin(a,b), u, es) => reflectMirrored(Reflect(OrderingMin(f(a),f(b))(e.aev.asInstanceOf[Ordering[A]],mtype(e.mev)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@OrderingCompare(a,b), u, es) => reflectMirrored(Reflect(OrderingCompare(f(a),f(b))(e.aev,e.mev), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e, f) - }).asInstanceOf[Exp[A]] + }).asInstanceOf[Exp[A]] +} + +/** + * @author Alen Stojanov (astojanov@inf.ethz.ch) + */ +trait OrderingOpsExpOpt extends OrderingOpsExp { + + override def ordering_lt[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { + case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].lt(a, b)) + case (a, b) if a.equals(b) => Const(false) + case _ => super.ordering_lt(lhs, rhs) + } + + override def ordering_lteq[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { + case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].lteq(a, b)) + case (a, b) if a.equals(b) => Const(true) + case _ => super.ordering_lteq(lhs, rhs) + } + + override def ordering_gt[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { + case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].gt(a, b)) + case (a, b) if a.equals(b) => Const(false) + case _ => super.ordering_gt(lhs, rhs) + } + + override def ordering_gteq[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { + case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].gteq(a, b)) + case (a, b) if a.equals(b) => Const(true) + case _ => super.ordering_gteq(lhs, rhs) + } + + override def ordering_equiv[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Boolean] = (lhs, rhs) match { + case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].equiv(a, b)) + case (a, b) if a.equals(b) => Const(true) + case _ => super.ordering_equiv(lhs, rhs) + } + + override def ordering_max[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = (lhs, rhs) match { + case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].max(a, b)) + case (a, b) if a.equals(b) => a + case _ => super.ordering_max(lhs, rhs) + } + + override def ordering_min[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[T] = (lhs, rhs) match { + case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].min(a, b)) + case (a, b) if a.equals(b) => a + case _ => super.ordering_min(lhs, rhs) } + + override def ordering_compare[T:Ordering:Manifest](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext): Rep[Int] = (lhs, rhs) match { + case (Const(a), Const(b)) => Const(implicitly[Ordering[T]].compare(a, b)) + case (a, b) if a.equals(b) => Const[Int](0) + case _ => super.ordering_compare(lhs, rhs) + } + } + trait ScalaGenOrderingOps extends ScalaGenBase { val IR: OrderingOpsExp import IR._ override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case lt@OrderingLT(a,b) => emitValDef(sym, src"$a < $b") + case OrderingLT(a,b) => emitValDef(sym, src"$a < $b") case OrderingLTEQ(a,b) => emitValDef(sym, src"$a <= $b") case OrderingGT(a,b) => emitValDef(sym, src"$a > $b") case OrderingGTEQ(a,b) => emitValDef(sym, src"$a >= $b") case OrderingEquiv(a,b) => emitValDef(sym, src"$a equiv $b") case OrderingMax(a,b) => emitValDef(sym, src"$a max $b") case OrderingMin(a,b) => emitValDef(sym, src"$a min $b") + case c@OrderingCompare(a,b) => c.mev match { + case m if m == Manifest.Int => emitValDef(sym, "java.lang.Integer.compare("+quote(a)+","+quote(b)+")") + case m if m == Manifest.Long => emitValDef(sym, "java.lang.Long.compare("+quote(a)+","+quote(b)+")") + case m if m == Manifest.Double => emitValDef(sym, "java.lang.Double.compare("+quote(a)+","+quote(b)+")") + case m if m == Manifest.Float => emitValDef(sym, "java.lang.Float.compare("+quote(a)+","+quote(b)+")") + case m if m == Manifest.Boolean => emitValDef(sym, "java.lang.Boolean.compare("+quote(a)+","+quote(b)+")") + case m if m == Manifest.Byte => emitValDef(sym, "java.lang.Byte.compare("+quote(a)+","+quote(b)+")") + case m if m == Manifest.Char => emitValDef(sym, "java.lang.Character.compare("+quote(a)+","+quote(b)+")") + case m if m == Manifest.Short => emitValDef(sym, "java.lang.Short.compare("+quote(a)+","+quote(b)+")") + case _ => emitValDef(sym, quote(a) + " compare " + quote(b)) + } case _ => super.emitNode(sym, rhs) } } @@ -117,7 +176,7 @@ trait CLikeGenOrderingOps extends CLikeGenBase { // TODO: Add MIN/MAX macro needs to C-like header file override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { - case lt@OrderingLT(a,b) => + case OrderingLT(a,b) => emitValDef(sym, src"$a < $b") case OrderingLTEQ(a,b) => emitValDef(sym, src"$a <= $b") @@ -128,8 +187,10 @@ trait CLikeGenOrderingOps extends CLikeGenBase { case OrderingEquiv(a,b) => emitValDef(sym, src"$a == $b") case OrderingMax(a,b) => + //emitValDef(sym, quote(a) + ">" + quote(b) + "?" + quote(a) + ":" + quote(b)) emitValDef(sym, src"MAX($a, $b)") case OrderingMin(a,b) => + //emitValDef(sym, quote(a) + "<" + quote(b) + "?" + quote(a) + ":" + quote(b)) emitValDef(sym, src"MIN($a, $b)") case _ => super.emitNode(sym, rhs) } diff --git a/src/common/PrimitiveOps.scala b/src/common/PrimitiveOps.scala index b02c5b10..710a6280 100644 --- a/src/common/PrimitiveOps.scala +++ b/src/common/PrimitiveOps.scala @@ -10,7 +10,6 @@ trait LiftPrimitives { this: PrimitiveOps => implicit def intToRepInt(x: Int) = unit(x) - implicit def longToRepLong(x: Long) = unit(x) implicit def floatToRepFloat(x: Float) = unit(x) implicit def doubleToRepDouble(x: Double) = unit(x) @@ -32,16 +31,133 @@ trait PrimitiveOps extends Variables with OverloadHack { /** * Primitive conversions */ - implicit def repIntToRepDouble(x: Rep[Int]): Rep[Double] = implicit_convert[Int,Double](x) - implicit def repIntToRepFloat(x: Rep[Int]): Rep[Float] = implicit_convert[Int,Float](x) - implicit def repFloatToRepDouble(x: Rep[Float]): Rep[Double] = implicit_convert[Float,Double](x) + implicit def repIntToRepDouble(x: Rep[Int]): Rep[Double] = x.toDouble + implicit def repIntToRepFloat(x: Rep[Int]): Rep[Float] = x.toFloat + implicit def repFloatToRepDouble(x: Rep[Float]): Rep[Double] = x.toDouble + + + /** + * Enumerate all combinations of primitive math. + * Avoids certain fragile behavior, including compiler crashes and some erroneous or inaccessible type errors. + */ + def infix_-(lhs: Int, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Int] = int_minus(unit(lhs), rhs) + def infix_-(lhs: Int, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_minus(unit(lhs), rhs) + def infix_-(lhs: Int, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_minus(unit(lhs), rhs) + def infix_-(lhs: Float, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Float] = float_minus(unit(lhs),rhs) + def infix_-(lhs: Float, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_minus(unit(lhs), rhs) + def infix_-(lhs: Float, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_minus(unit(lhs), rhs) + def infix_-(lhs: Double, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Double] = double_minus(unit(lhs),rhs) + def infix_-(lhs: Double, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Double] = double_minus(unit(lhs),rhs) + def infix_-(lhs: Double, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_minus(unit(lhs),rhs) + def infix_-(lhs: Rep[Int], rhs: Int)(implicit ctx: SourceContext): Rep[Int] = int_minus(lhs, unit(rhs)) + def infix_-(lhs: Rep[Int], rhs: Double)(implicit ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) + def infix_-(lhs: Rep[Int], rhs: Float)(implicit ctx: SourceContext): Rep[Float] = float_minus(lhs, unit(rhs)) + def infix_-(lhs: Rep[Float], rhs: Int)(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_minus(lhs, unit(rhs)) + def infix_-(lhs: Rep[Float], rhs: Float)(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_minus(lhs, unit(rhs)) + def infix_-(lhs: Rep[Float], rhs: Double)(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) + def infix_-(lhs: Rep[Double], rhs: Int)(implicit o: Overloaded4, ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) + def infix_-(lhs: Rep[Double], rhs: Float)(implicit o: Overloaded5, ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) + def infix_-(lhs: Rep[Double], rhs: Double)(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_minus(lhs, unit(rhs)) + def infix_-(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, ctx: SourceContext): Rep[Int] = int_minus(lhs, rhs) + def infix_-(lhs: Rep[Int], rhs: Rep[Float])(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_minus(repIntToRepFloat(lhs), rhs) + def infix_-(lhs: Rep[Int], rhs: Rep[Double])(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_minus(repIntToRepDouble(lhs), rhs) + def infix_-(lhs: Rep[Float], rhs: Rep[Int])(implicit o: Overloaded4, ctx: SourceContext): Rep[Float] = float_minus(lhs,repIntToRepFloat(rhs)) + def infix_-(lhs: Rep[Float], rhs: Rep[Float])(implicit o: Overloaded5, ctx: SourceContext): Rep[Float] = float_minus(lhs, rhs) + def infix_-(lhs: Rep[Float], rhs: Rep[Double])(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_minus(repFloatToRepDouble(lhs), rhs) + def infix_-(lhs: Rep[Double], rhs: Rep[Int])(implicit o: Overloaded7, ctx: SourceContext): Rep[Double] = double_minus(lhs,repIntToRepDouble(rhs)) + def infix_-(lhs: Rep[Double], rhs: Rep[Float])(implicit o: Overloaded8, ctx: SourceContext): Rep[Double] = double_minus(lhs,repFloatToRepDouble(rhs)) + def infix_-(lhs: Rep[Double], rhs: Rep[Double])(implicit o: Overloaded9, ctx: SourceContext): Rep[Double] = double_minus(lhs,rhs) + + def infix_+(lhs: Int, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Int] = int_plus(unit(lhs), rhs) + def infix_+(lhs: Int, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_plus(unit(lhs), rhs) + def infix_+(lhs: Int, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_plus(unit(lhs), rhs) + def infix_+(lhs: Float, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Float] = float_plus(unit(lhs),rhs) + def infix_+(lhs: Float, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_plus(unit(lhs), rhs) + def infix_+(lhs: Float, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_plus(unit(lhs), rhs) + def infix_+(lhs: Double, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Double] = double_plus(unit(lhs),rhs) + def infix_+(lhs: Double, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Double] = double_plus(unit(lhs),rhs) + def infix_+(lhs: Double, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_plus(unit(lhs),rhs) + def infix_+(lhs: Rep[Int], rhs: Int)(implicit ctx: SourceContext): Rep[Int] = int_plus(lhs, unit(rhs)) + def infix_+(lhs: Rep[Int], rhs: Double)(implicit ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) + def infix_+(lhs: Rep[Int], rhs: Float)(implicit ctx: SourceContext): Rep[Float] = float_plus(lhs, unit(rhs)) + def infix_+(lhs: Rep[Float], rhs: Int)(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_plus(lhs, unit(rhs)) + def infix_+(lhs: Rep[Float], rhs: Float)(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_plus(lhs, unit(rhs)) + def infix_+(lhs: Rep[Float], rhs: Double)(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) + def infix_+(lhs: Rep[Double], rhs: Int)(implicit o: Overloaded4, ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) + def infix_+(lhs: Rep[Double], rhs: Float)(implicit o: Overloaded5, ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) + def infix_+(lhs: Rep[Double], rhs: Double)(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_plus(lhs, unit(rhs)) + def infix_+(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded15, ctx: SourceContext): Rep[Int] = int_plus(lhs, rhs) + def infix_+(lhs: Rep[Int], rhs: Rep[Float])(implicit o: Overloaded16, ctx: SourceContext): Rep[Float] = float_plus(repIntToRepFloat(lhs), rhs) + def infix_+(lhs: Rep[Int], rhs: Rep[Double])(implicit o: Overloaded17, ctx: SourceContext): Rep[Double] = double_plus(repIntToRepDouble(lhs), rhs) + def infix_+(lhs: Rep[Float], rhs: Rep[Int])(implicit o: Overloaded18, ctx: SourceContext): Rep[Float] = float_plus(lhs,repIntToRepFloat(rhs)) + def infix_+(lhs: Rep[Float], rhs: Rep[Float])(implicit o: Overloaded19, ctx: SourceContext): Rep[Float] = float_plus(lhs, rhs) + def infix_+(lhs: Rep[Float], rhs: Rep[Double])(implicit o: Overloaded20, ctx: SourceContext): Rep[Double] = double_plus(repFloatToRepDouble(lhs), rhs) + def infix_+(lhs: Rep[Double], rhs: Rep[Int])(implicit o: Overloaded21, ctx: SourceContext): Rep[Double] = double_plus(lhs,repIntToRepDouble(rhs)) + def infix_+(lhs: Rep[Double], rhs: Rep[Float])(implicit o: Overloaded22, ctx: SourceContext): Rep[Double] = double_plus(lhs,repFloatToRepDouble(rhs)) + def infix_+(lhs: Rep[Double], rhs: Rep[Double])(implicit o: Overloaded23, ctx: SourceContext): Rep[Double] = double_plus(lhs,rhs) + + def infix_*(lhs: Int, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Int] = int_times(unit(lhs), rhs) + def infix_*(lhs: Int, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_times(unit(lhs), rhs) + def infix_*(lhs: Int, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_times(unit(lhs), rhs) + def infix_*(lhs: Float, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Float] = float_times(unit(lhs),rhs) + def infix_*(lhs: Float, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_times(unit(lhs), rhs) + def infix_*(lhs: Float, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_times(unit(lhs), rhs) + def infix_*(lhs: Double, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Double] = double_times(unit(lhs),rhs) + def infix_*(lhs: Double, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Double] = double_times(unit(lhs),rhs) + def infix_*(lhs: Double, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_times(unit(lhs),rhs) + def infix_*(lhs: Rep[Int], rhs: Int)(implicit ctx: SourceContext): Rep[Int] = int_times(lhs, unit(rhs)) + def infix_*(lhs: Rep[Int], rhs: Double)(implicit ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) + def infix_*(lhs: Rep[Int], rhs: Float)(implicit ctx: SourceContext): Rep[Float] = float_times(lhs, unit(rhs)) + def infix_*(lhs: Rep[Float], rhs: Int)(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_times(lhs, unit(rhs)) + def infix_*(lhs: Rep[Float], rhs: Float)(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_times(lhs, unit(rhs)) + def infix_*(lhs: Rep[Float], rhs: Double)(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) + def infix_*(lhs: Rep[Double], rhs: Int)(implicit o: Overloaded4, ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) + def infix_*(lhs: Rep[Double], rhs: Float)(implicit o: Overloaded5, ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) + def infix_*(lhs: Rep[Double], rhs: Double)(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_times(lhs, unit(rhs)) + def infix_*(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, ctx: SourceContext): Rep[Int] = int_times(lhs, rhs) + def infix_*(lhs: Rep[Int], rhs: Rep[Float])(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_times(repIntToRepFloat(lhs), rhs) + def infix_*(lhs: Rep[Int], rhs: Rep[Double])(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_times(repIntToRepDouble(lhs), rhs) + def infix_*(lhs: Rep[Float], rhs: Rep[Int])(implicit o: Overloaded4, ctx: SourceContext): Rep[Float] = float_times(lhs,repIntToRepFloat(rhs)) + def infix_*(lhs: Rep[Float], rhs: Rep[Float])(implicit o: Overloaded5, ctx: SourceContext): Rep[Float] = float_times(lhs, rhs) + def infix_*(lhs: Rep[Float], rhs: Rep[Double])(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_times(repFloatToRepDouble(lhs), rhs) + def infix_*(lhs: Rep[Double], rhs: Rep[Int])(implicit o: Overloaded7, ctx: SourceContext): Rep[Double] = double_times(lhs,repIntToRepDouble(rhs)) + def infix_*(lhs: Rep[Double], rhs: Rep[Float])(implicit o: Overloaded8, ctx: SourceContext): Rep[Double] = double_times(lhs,repFloatToRepDouble(rhs)) + def infix_*(lhs: Rep[Double], rhs: Rep[Double])(implicit o: Overloaded9, ctx: SourceContext): Rep[Double] = double_times(lhs,rhs) + + def infix_/(lhs: Int, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Int] = int_divide(unit(lhs), rhs) + def infix_/(lhs: Int, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_divide(unit(lhs), rhs) + def infix_/(lhs: Int, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_divide(unit(lhs), rhs) + def infix_/(lhs: Float, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Float] = float_divide(unit(lhs),rhs) + def infix_/(lhs: Float, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_divide(unit(lhs), rhs) + def infix_/(lhs: Float, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_divide(unit(lhs), rhs) + def infix_/(lhs: Double, rhs: Rep[Int])(implicit ctx: SourceContext): Rep[Double] = double_divide(unit(lhs),rhs) + def infix_/(lhs: Double, rhs: Rep[Float])(implicit o: Overloaded1, ctx: SourceContext): Rep[Double] = double_divide(unit(lhs),rhs) + def infix_/(lhs: Double, rhs: Rep[Double])(implicit o: Overloaded2, ctx: SourceContext): Rep[Double] = double_divide(unit(lhs),rhs) + def infix_/(lhs: Rep[Int], rhs: Int)(implicit ctx: SourceContext): Rep[Int] = int_divide(lhs, unit(rhs)) + def infix_/(lhs: Rep[Int], rhs: Double)(implicit ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) + def infix_/(lhs: Rep[Int], rhs: Float)(implicit ctx: SourceContext): Rep[Float] = float_divide(lhs, unit(rhs)) + def infix_/(lhs: Rep[Float], rhs: Int)(implicit o: Overloaded1, ctx: SourceContext): Rep[Float] = float_divide(lhs, unit(rhs)) + def infix_/(lhs: Rep[Float], rhs: Float)(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_divide(lhs, unit(rhs)) + def infix_/(lhs: Rep[Float], rhs: Double)(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) + def infix_/(lhs: Rep[Double], rhs: Int)(implicit o: Overloaded4, ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) + def infix_/(lhs: Rep[Double], rhs: Float)(implicit o: Overloaded5, ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) + def infix_/(lhs: Rep[Double], rhs: Double)(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_divide(lhs, unit(rhs)) + def infix_/(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, ctx: SourceContext): Rep[Int] = int_divide(lhs, rhs) + def infix_/(lhs: Rep[Int], rhs: Rep[Float])(implicit o: Overloaded2, ctx: SourceContext): Rep[Float] = float_divide(repIntToRepFloat(lhs), rhs) + def infix_/(lhs: Rep[Int], rhs: Rep[Double])(implicit o: Overloaded3, ctx: SourceContext): Rep[Double] = double_divide(repIntToRepDouble(lhs), rhs) + def infix_/(lhs: Rep[Float], rhs: Rep[Int])(implicit o: Overloaded4, ctx: SourceContext): Rep[Float] = float_divide(lhs,repIntToRepFloat(rhs)) + def infix_/(lhs: Rep[Float], rhs: Rep[Float])(implicit o: Overloaded5, ctx: SourceContext): Rep[Float] = float_divide(lhs, rhs) + def infix_/(lhs: Rep[Float], rhs: Rep[Double])(implicit o: Overloaded6, ctx: SourceContext): Rep[Double] = double_divide(repFloatToRepDouble(lhs), rhs) + def infix_/(lhs: Rep[Double], rhs: Rep[Int])(implicit o: Overloaded7, ctx: SourceContext): Rep[Double] = double_divide(lhs,repIntToRepDouble(rhs)) + def infix_/(lhs: Rep[Double], rhs: Rep[Float])(implicit o: Overloaded8, ctx: SourceContext): Rep[Double] = double_divide(lhs,repFloatToRepDouble(rhs)) + def infix_/(lhs: Rep[Double], rhs: Rep[Double])(implicit o: Overloaded9, ctx: SourceContext): Rep[Double] = double_divide(lhs,rhs) /** * Double */ - implicit def doubleToDoubleOps(n: Double) = new DoubleOpsCls(unit(n)) - implicit def repDoubleToDoubleOps(n: Rep[Double]) = new DoubleOpsCls(n) - implicit def varDoubleToDoubleOps(n: Var[Double]) = new DoubleOpsCls(readVar(n)) + implicit def doubleToDoubleOps(n: Double): DoubleOpsCls = new DoubleOpsCls(unit(n)) + implicit def repDoubleToDoubleOps(n: Rep[Double]): DoubleOpsCls = new DoubleOpsCls(n) + implicit def varDoubleToDoubleOps(n: Var[Double]): DoubleOpsCls = new DoubleOpsCls(readVar(n)) object Double { def parseDouble(s: Rep[String])(implicit pos: SourceContext) = obj_double_parse_double(s) @@ -53,6 +169,8 @@ trait PrimitiveOps extends Variables with OverloadHack { class DoubleOpsCls(lhs: Rep[Double]){ def floatValue()(implicit pos: SourceContext) = double_float_value(lhs) + def toInt(implicit pos: SourceContext) = double_to_int(lhs) + def toFloat(implicit pos: SourceContext) = double_to_float(lhs) } def obj_double_parse_double(s: Rep[String])(implicit pos: SourceContext): Rep[Double] @@ -61,11 +179,34 @@ trait PrimitiveOps extends Variables with OverloadHack { def obj_double_min_value(implicit pos: SourceContext): Rep[Double] def obj_double_max_value(implicit pos: SourceContext): Rep[Double] def double_float_value(lhs: Rep[Double])(implicit pos: SourceContext): Rep[Float] + def double_plus(lhs: Rep[Double], rhs: Rep[Double])(implicit pos: SourceContext): Rep[Double] + def double_minus(lhs: Rep[Double], rhs: Rep[Double])(implicit pos: SourceContext): Rep[Double] + def double_times(lhs: Rep[Double], rhs: Rep[Double])(implicit pos: SourceContext): Rep[Double] + def double_divide(lhs: Rep[Double], rhs: Rep[Double])(implicit pos: SourceContext): Rep[Double] + def double_to_int(lhs: Rep[Double])(implicit pos: SourceContext): Rep[Int] + def double_to_float(lhs: Rep[Double])(implicit pos: SourceContext): Rep[Float] + + /** + * Float + */ + object Float { + def parseFloat(s: Rep[String])(implicit pos: SourceContext) = obj_float_parse_float(s) + } + def infix_toInt(lhs: Rep[Float])(implicit o: Overloaded1, pos: SourceContext): Rep[Int] = float_to_int(lhs) + def infix_toDouble(lhs: Rep[Float])(implicit o: Overloaded1, pos: SourceContext): Rep[Double] = float_to_double(lhs) + + def obj_float_parse_float(s: Rep[String])(implicit pos: SourceContext): Rep[Float] + def float_plus(lhs: Rep[Float], rhs: Rep[Float])(implicit pos: SourceContext): Rep[Float] + def float_minus(lhs: Rep[Float], rhs: Rep[Float])(implicit pos: SourceContext): Rep[Float] + def float_times(lhs: Rep[Float], rhs: Rep[Float])(implicit pos: SourceContext): Rep[Float] + def float_divide(lhs: Rep[Float], rhs: Rep[Float])(implicit pos: SourceContext): Rep[Float] + def float_to_int(lhs: Rep[Float])(implicit pos: SourceContext): Rep[Int] + def float_to_double(lhs: Rep[Float])(implicit pos: SourceContext): Rep[Double] + /** * Int */ - object Integer { def parseInt(s: Rep[String])(implicit pos: SourceContext) = obj_integer_parse_int(s) } @@ -75,9 +216,9 @@ trait PrimitiveOps extends Variables with OverloadHack { def MinValue(implicit pos: SourceContext) = obj_int_min_value } - implicit def intToIntOps(n: Int) = new IntOpsCls(unit(n)) - implicit def repIntToIntOps(n: Rep[Int]) = new IntOpsCls(n) - implicit def varIntToIntOps(n: Var[Int]) = new IntOpsCls(readVar(n)) + implicit def intToIntOps(n: Int): IntOpsCls = new IntOpsCls(unit(n)) + implicit def repIntToIntOps(n: Rep[Int]): IntOpsCls = new IntOpsCls(n) + implicit def varIntToIntOps(n: Var[Int]): IntOpsCls = new IntOpsCls(readVar(n)) class IntOpsCls(lhs: Rep[Int]){ // TODO (tiark): either of these cause scalac to crash @@ -88,19 +229,28 @@ trait PrimitiveOps extends Variables with OverloadHack { def doubleValue()(implicit pos: SourceContext) = int_double_value(lhs) def unary_~()(implicit pos: SourceContext) = int_bitwise_not(lhs) def toLong(implicit pos: SourceContext) = int_tolong(lhs) + def toDouble(implicit pos: SourceContext) = int_to_double(lhs) + def toFloat(implicit pos: SourceContext) = int_to_float(lhs) } - //def infix_/(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_divide(lhs, rhs) //TR triggers bug in Scala-Virtualized 2.10.0 M7 together with Delite ArithOps - def infix_%(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_mod(lhs, rhs) - def infix_&(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_binaryand(lhs, rhs) - def infix_|(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_binaryor(lhs, rhs) - def infix_^(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext) = int_binaryxor(lhs, rhs) + + def infix_%(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_mod(lhs, rhs) + def infix_&(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_binaryand(lhs, rhs) + def infix_|(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_binaryor(lhs, rhs) + def infix_^(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_binaryxor(lhs, rhs) + def infix_<<(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_leftshift(lhs, rhs) + def infix_>>(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_rightshiftarith(lhs, rhs) + def infix_>>>(lhs: Rep[Int], rhs: Rep[Int])(implicit o: Overloaded1, pos: SourceContext) = int_rightshiftlogical(lhs, rhs) def obj_integer_parse_int(s: Rep[String])(implicit pos: SourceContext): Rep[Int] def obj_int_max_value(implicit pos: SourceContext): Rep[Int] def obj_int_min_value(implicit pos: SourceContext): Rep[Int] - def int_divide_frac[A:Manifest:Fractional](lhs: Rep[Int], rhs: Rep[A])(implicit pos: SourceContext): Rep[A] + def int_plus(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] + def int_minus(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] + def int_times(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] + // def int_divide_frac[A:Manifest:Fractional](lhs: Rep[Int], rhs: Rep[A])(implicit pos: SourceContext): Rep[A] def int_divide(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] + def int_mod(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] def int_binaryor(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] def int_binaryand(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] @@ -109,43 +259,38 @@ trait PrimitiveOps extends Variables with OverloadHack { def int_double_value(lhs: Rep[Int])(implicit pos: SourceContext): Rep[Double] def int_bitwise_not(lhs: Rep[Int])(implicit pos: SourceContext) : Rep[Int] def int_tolong(lhs: Rep[Int])(implicit pos: SourceContext) : Rep[Long] - + def int_to_float(lhs: Rep[Int])(implicit pos: SourceContext) : Rep[Float] + def int_to_double(lhs: Rep[Int])(implicit pos: SourceContext) : Rep[Double] + def int_leftshift(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] + def int_rightshiftarith(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] + def int_rightshiftlogical(lhs: Rep[Int], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Int] + /** * Long */ - def infix_%(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_mod(lhs, rhs) - def infix_&(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_binaryand(lhs, rhs) - def infix_|(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_binaryor(lhs, rhs) - def infix_^(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_binaryxor(lhs, rhs) - def infix_<<(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext) = long_shiftleft(lhs, rhs) - def infix_>>(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext) = long_shiftright(lhs, rhs) - def infix_>>>(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext) = long_shiftright_unsigned(lhs, rhs) - def infix_toInt(lhs: Rep[Long])(implicit o: Overloaded1, pos: SourceContext) = long_toint(lhs) + object Long { + def parseLong(s: Rep[String])(implicit pos: SourceContext) = obj_long_parse_long(s) + } + + def infix_%(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_mod(lhs, rhs) + def infix_&(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_binaryand(lhs, rhs) + def infix_|(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_binaryor(lhs, rhs) + def infix_<<(lhs: Rep[Long], rhs: Rep[Int])(implicit o: Overloaded2, pos: SourceContext) = long_shiftleft(lhs, rhs) + def infix_>>>(lhs: Rep[Long], rhs: Rep[Int])(implicit o: Overloaded2, pos: SourceContext) = long_shiftright_unsigned(lhs, rhs) + def infix_toInt(lhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_toint(lhs) + def obj_long_parse_long(s: Rep[String])(implicit pos: SourceContext): Rep[Long] def long_mod(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long] def long_binaryand(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long] def long_binaryor(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long] - def long_binaryxor(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long] def long_shiftleft(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Long] - def long_shiftright(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Long] def long_shiftright_unsigned(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Long] def long_toint(lhs: Rep[Long])(implicit pos: SourceContext): Rep[Int] - - /** - * Character - */ - def infix_-(lhs: Rep[Character], rhs: Rep[Character])(implicit pos: SourceContext, o: Overloaded1) = char_minus(lhs, rhs) - def char_minus(lhs: Rep[Character], rhs: Rep[Character])(implicit pos: SourceContext): Rep[Int] - - /** - * Byte - */ - def infix_-(lhs: Rep[Byte], rhs: Rep[Byte])(implicit pos: SourceContext, o: Overloaded2) = char_minus(lhs.asInstanceOf[Rep[Character]], rhs.asInstanceOf[Rep[Character]]) } -trait PrimitiveOpsExp extends PrimitiveOps with BaseExp { +trait PrimitiveOpsExp extends PrimitiveOps with EffectExp { this: ImplicitOps => - + /** * Double */ @@ -155,6 +300,12 @@ trait PrimitiveOpsExp extends PrimitiveOps with BaseExp { case class ObjDoubleMinValue() extends Def[Double] case class ObjDoubleMaxValue() extends Def[Double] case class DoubleFloatValue(lhs: Exp[Double]) extends Def[Float] + case class DoubleToInt(lhs: Exp[Double]) extends Def[Int] + case class DoubleToFloat(lhs: Exp[Double]) extends Def[Float] + case class DoublePlus(lhs: Exp[Double], rhs: Exp[Double]) extends Def[Double] + case class DoubleMinus(lhs: Exp[Double], rhs: Exp[Double]) extends Def[Double] + case class DoubleTimes(lhs: Exp[Double], rhs: Exp[Double]) extends Def[Double] + case class DoubleDivide(lhs: Exp[Double], rhs: Exp[Double]) extends Def[Double] def obj_double_parse_double(s: Exp[String])(implicit pos: SourceContext) = ObjDoubleParseDouble(s) def obj_double_positive_infinity(implicit pos: SourceContext) = ObjDoublePositiveInfinity() @@ -162,28 +313,80 @@ trait PrimitiveOpsExp extends PrimitiveOps with BaseExp { def obj_double_min_value(implicit pos: SourceContext) = ObjDoubleMinValue() def obj_double_max_value(implicit pos: SourceContext) = ObjDoubleMaxValue() def double_float_value(lhs: Exp[Double])(implicit pos: SourceContext) = DoubleFloatValue(lhs) + def double_to_int(lhs: Exp[Double])(implicit pos: SourceContext) = DoubleToInt(lhs) + def double_to_float(lhs: Exp[Double])(implicit pos: SourceContext) = DoubleToFloat(lhs) + def double_plus(lhs: Exp[Double], rhs: Exp[Double])(implicit pos: SourceContext) : Exp[Double] = DoublePlus(lhs,rhs) + def double_minus(lhs: Exp[Double], rhs: Exp[Double])(implicit pos: SourceContext) : Exp[Double] = DoubleMinus(lhs,rhs) + def double_times(lhs: Exp[Double], rhs: Exp[Double])(implicit pos: SourceContext) : Exp[Double] = DoubleTimes(lhs,rhs) + def double_divide(lhs: Exp[Double], rhs: Exp[Double])(implicit pos: SourceContext) : Exp[Double] = DoubleDivide(lhs,rhs) + /** + * Float + */ + case class ObjFloatParseFloat(s: Exp[String]) extends Def[Float] + case class FloatToInt(lhs: Exp[Float]) extends Def[Int] + case class FloatToDouble(lhs: Exp[Float]) extends Def[Double] + case class FloatPlus(lhs: Exp[Float], rhs: Exp[Float]) extends Def[Float] + case class FloatMinus(lhs: Exp[Float], rhs: Exp[Float]) extends Def[Float] + case class FloatTimes(lhs: Exp[Float], rhs: Exp[Float]) extends Def[Float] + case class FloatDivide(lhs: Exp[Float], rhs: Exp[Float]) extends Def[Float] + + def obj_float_parse_float(s: Exp[String])(implicit pos: SourceContext) = ObjFloatParseFloat(s) + def float_to_int(lhs: Exp[Float])(implicit pos: SourceContext) = FloatToInt(lhs) + def float_to_double(lhs: Exp[Float])(implicit pos: SourceContext) = FloatToDouble(lhs) + def float_plus(lhs: Exp[Float], rhs: Exp[Float])(implicit pos: SourceContext) : Exp[Float] = FloatPlus(lhs,rhs) + def float_minus(lhs: Exp[Float], rhs: Exp[Float])(implicit pos: SourceContext) : Exp[Float] = FloatMinus(lhs,rhs) + def float_times(lhs: Exp[Float], rhs: Exp[Float])(implicit pos: SourceContext) : Exp[Float] = FloatTimes(lhs,rhs) + def float_divide(lhs: Exp[Float], rhs: Exp[Float])(implicit pos: SourceContext) : Exp[Float] = FloatDivide(lhs,rhs) + /** * Int */ case class ObjIntegerParseInt(s: Exp[String]) extends Def[Int] case class ObjIntMaxValue() extends Def[Int] case class ObjIntMinValue() extends Def[Int] - case class IntDivideFrac[A:Manifest:Fractional](lhs: Exp[Int], rhs: Exp[A]) extends Def[A] + case class IntPlus(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] + case class IntMinus(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] + case class IntTimes(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] + // case class IntDivideFrac[A:Manifest:Fractional](lhs: Exp[Int], rhs: Exp[A]) extends Def[A] case class IntDivide(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntMod(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntBinaryOr(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntBinaryAnd(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntBinaryXor(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] + case class IntShiftLeft(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] + case class IntShiftRightArith(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] + case class IntShiftRightLogical(lhs: Exp[Int], rhs: Exp[Int]) extends Def[Int] case class IntDoubleValue(lhs: Exp[Int]) extends Def[Double] case class IntFloatValue(lhs: Exp[Int]) extends Def[Float] case class IntBitwiseNot(lhs: Exp[Int]) extends Def[Int] case class IntToLong(lhs: Exp[Int]) extends Def[Long] + case class IntToFloat(lhs: Exp[Int]) extends Def[Float] + case class IntToDouble(lhs: Exp[Int]) extends Def[Double] def obj_integer_parse_int(s: Rep[String])(implicit pos: SourceContext) = ObjIntegerParseInt(s) def obj_int_max_value(implicit pos: SourceContext) = ObjIntMaxValue() def obj_int_min_value(implicit pos: SourceContext) = ObjIntMinValue() - def int_divide_frac[A:Manifest:Fractional](lhs: Exp[Int], rhs: Exp[A])(implicit pos: SourceContext) : Exp[A] = IntDivideFrac(lhs, rhs) + def int_plus(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs, rhs) match { + case (Const(0), r) => r + case (l, Const(0)) => l + case (Const(x), Const(y)) => Const(x+y) + case _ => IntPlus(lhs,rhs) + } + def int_minus(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs, rhs) match { + case (l, Const(0)) => l + case (Const(x), Const(y)) => Const(x-y) + case _ => IntMinus(lhs, rhs) + } + def int_times(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs, rhs) match { + case (l@Const(0), r) => l + case (l, r@Const(0)) => r + case (Const(1), r) => r + case (l, Const(1)) => l + case (Const(x), Const(y)) => Const(x*y) + case _ => IntTimes(lhs, rhs) + } + // def int_divide_frac[A:Manifest:Fractional](lhs: Exp[Int], rhs: Exp[A])(implicit pos: SourceContext) : Exp[A] = IntDivideFrac(lhs, rhs) def int_divide(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = IntDivide(lhs, rhs) def int_mod(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntMod(lhs, rhs) def int_binaryor(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntBinaryOr(lhs, rhs) @@ -193,64 +396,175 @@ trait PrimitiveOpsExp extends PrimitiveOps with BaseExp { def int_float_value(lhs: Exp[Int])(implicit pos: SourceContext) = IntFloatValue(lhs) def int_bitwise_not(lhs: Exp[Int])(implicit pos: SourceContext) = IntBitwiseNot(lhs) def int_tolong(lhs: Exp[Int])(implicit pos: SourceContext) = IntToLong(lhs) - + def int_to_float(lhs: Exp[Int])(implicit pos: SourceContext) = IntToFloat(lhs) + def int_to_double(lhs: Exp[Int])(implicit pos: SourceContext) = IntToDouble(lhs) + def int_leftshift(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntShiftLeft(lhs, rhs) + def int_rightshiftarith(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntShiftRightArith(lhs, rhs) + def int_rightshiftlogical(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) = IntShiftRightLogical(lhs, rhs) + + /** * Long */ - case class LongMod(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] + case class ObjLongParseLong(s: Exp[String]) extends Def[Long] case class LongBinaryOr(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] - case class LongBinaryXor(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] case class LongBinaryAnd(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] case class LongShiftLeft(lhs: Exp[Long], rhs: Exp[Int]) extends Def[Long] - case class LongShiftRight(lhs: Exp[Long], rhs: Exp[Int]) extends Def[Long] case class LongShiftRightUnsigned(lhs: Exp[Long], rhs: Exp[Int]) extends Def[Long] case class LongToInt(lhs: Exp[Long]) extends Def[Int] + case class LongMod(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long] - def long_mod(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongMod(lhs, rhs) + def obj_long_parse_long(s: Exp[String])(implicit pos: SourceContext) = ObjLongParseLong(s) def long_binaryor(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryOr(lhs,rhs) - def long_binaryxor(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryXor(lhs,rhs) - def long_binaryand(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryAnd(lhs,rhs) + def long_binaryand(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryAnd(lhs,rhs) def long_shiftleft(lhs: Exp[Long], rhs: Exp[Int])(implicit pos: SourceContext) = LongShiftLeft(lhs,rhs) - def long_shiftright(lhs: Exp[Long], rhs: Exp[Int])(implicit pos: SourceContext) = LongShiftRight(lhs,rhs) def long_shiftright_unsigned(lhs: Exp[Long], rhs: Exp[Int])(implicit pos: SourceContext) = LongShiftRightUnsigned(lhs,rhs) def long_toint(lhs: Exp[Long])(implicit pos: SourceContext) = LongToInt(lhs) + def long_mod(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongMod(lhs, rhs) - /** - * Character - */ - case class CharMinus(lhs: Exp[Character], rhs: Exp[Character]) extends Def[Int] - def char_minus(lhs: Exp[Character], rhs: Exp[Character])(implicit pos: SourceContext) = CharMinus(lhs, rhs) - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = ({ implicit var a: Numeric[A] = null // hack!! need to store it in Def instances?? e match { case ObjDoubleParseDouble(x) => obj_double_parse_double(f(x)) case ObjDoublePositiveInfinity() => obj_double_positive_infinity + case ObjDoubleNegativeInfinity() => obj_double_negative_infinity + case ObjDoubleMinValue() => obj_double_min_value + case ObjDoubleMaxValue() => obj_double_max_value case DoubleFloatValue(x) => double_float_value(f(x)) + case DoubleToInt(x) => double_to_int(f(x)) + case DoubleToFloat(x) => double_to_float(f(x)) + case DoublePlus(x,y) => double_plus(f(x),f(y)) + case DoubleMinus(x,y) => double_minus(f(x),f(y)) + case DoubleTimes(x,y) => double_times(f(x),f(y)) + case DoubleDivide(x,y) => double_divide(f(x),f(y)) + case ObjFloatParseFloat(x) => obj_float_parse_float(f(x)) + case FloatToInt(x) => float_to_int(f(x)) + case FloatToDouble(x) => float_to_double(f(x)) + case FloatPlus(x,y) => float_plus(f(x),f(y)) + case FloatMinus(x,y) => float_minus(f(x),f(y)) + case FloatTimes(x,y) => float_times(f(x),f(y)) + case FloatDivide(x,y) => float_divide(f(x),f(y)) case ObjIntegerParseInt(x) => obj_integer_parse_int(f(x)) + case ObjIntMaxValue() => obj_int_max_value + case ObjIntMinValue() => obj_int_min_value case IntDoubleValue(x) => int_double_value(f(x)) case IntFloatValue(x) => int_float_value(f(x)) case IntBitwiseNot(x) => int_bitwise_not(f(x)) + case IntPlus(x,y) => int_plus(f(x),f(y)) + case IntMinus(x,y) => int_minus(f(x),f(y)) + case IntTimes(x,y) => int_times(f(x),f(y)) case IntDivide(x,y) => int_divide(f(x),f(y)) case IntMod(x,y) => int_mod(f(x),f(y)) - case IntBinaryOr(x,y) => int_binaryand(f(x),f(y)) - case IntBinaryXor(x,y) => int_binaryand(f(x),f(y)) + case IntBinaryOr(x,y) => int_binaryor(f(x),f(y)) case IntBinaryAnd(x,y) => int_binaryand(f(x),f(y)) + case IntBinaryXor(x,y) => int_binaryxor(f(x),f(y)) case IntToLong(x) => int_tolong(f(x)) - case LongShiftLeft(x,y) => long_shiftleft(f(x),f(y)) - case LongShiftRight(x,y) => long_shiftright(f(x),f(y)) + case IntToFloat(x) => int_to_float(f(x)) + case IntToDouble(x) => int_to_double(f(x)) + case IntShiftLeft(x,y) => int_leftshift(f(x),f(y)) + case IntShiftRightLogical(x,y) => int_rightshiftlogical(f(x),f(y)) + case IntShiftRightArith(x,y) => int_rightshiftarith(f(x),f(y)) + case ObjLongParseLong(x) => obj_long_parse_long(f(x)) case LongMod(x,y) => long_mod(f(x),f(y)) - case LongBinaryOr(x,y) => long_binaryand(f(x),f(y)) - case LongBinaryXor(x,y) => long_binaryand(f(x),f(y)) + case LongShiftLeft(x,y) => long_shiftleft(f(x),f(y)) + case LongBinaryOr(x,y) => long_binaryor(f(x),f(y)) case LongBinaryAnd(x,y) => long_binaryand(f(x),f(y)) case LongToInt(x) => long_toint(f(x)) case LongShiftRightUnsigned(x,y) => long_shiftright_unsigned(f(x),f(y)) - case CharMinus(x,y) => char_minus(f(x),f(y)) + + case Reflect(ObjDoubleParseDouble(x), u, es) => reflectMirrored(Reflect(ObjDoubleParseDouble(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(ObjDoublePositiveInfinity(), u, es) => reflectMirrored(Reflect(ObjDoublePositiveInfinity(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(ObjDoubleNegativeInfinity(), u, es) => reflectMirrored(Reflect(ObjDoubleNegativeInfinity(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(ObjDoubleMinValue(), u, es) => reflectMirrored(Reflect(ObjDoubleMinValue(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(ObjDoubleMaxValue(), u, es) => reflectMirrored(Reflect(ObjDoubleMaxValue(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(DoubleFloatValue(x), u, es) => reflectMirrored(Reflect(DoubleFloatValue(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(DoubleToInt(x), u, es) => reflectMirrored(Reflect(DoubleToInt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(DoubleToFloat(x), u, es) => reflectMirrored(Reflect(DoubleToFloat(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(DoublePlus(x,y), u, es) => reflectMirrored(Reflect(DoublePlus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(DoubleMinus(x,y), u, es) => reflectMirrored(Reflect(DoubleMinus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(DoubleTimes(x,y), u, es) => reflectMirrored(Reflect(DoubleTimes(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(DoubleDivide(x,y), u, es) => reflectMirrored(Reflect(DoubleDivide(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(FloatToInt(x), u, es) => reflectMirrored(Reflect(FloatToInt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(FloatToDouble(x), u, es) => reflectMirrored(Reflect(FloatToDouble(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(FloatPlus(x,y), u, es) => reflectMirrored(Reflect(FloatPlus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(FloatMinus(x,y), u, es) => reflectMirrored(Reflect(FloatMinus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(FloatTimes(x,y), u, es) => reflectMirrored(Reflect(FloatTimes(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(FloatDivide(x,y), u, es) => reflectMirrored(Reflect(FloatDivide(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(ObjIntegerParseInt(x), u, es) => reflectMirrored(Reflect(ObjIntegerParseInt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(ObjIntMinValue(), u, es) => reflectMirrored(Reflect(ObjIntMinValue(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(ObjIntMaxValue(), u, es) => reflectMirrored(Reflect(ObjIntMaxValue(), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntDoubleValue(x), u, es) => reflectMirrored(Reflect(IntDoubleValue(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntFloatValue(x), u, es) => reflectMirrored(Reflect(IntFloatValue(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntBitwiseNot(x), u, es) => reflectMirrored(Reflect(IntBitwiseNot(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntPlus(x,y), u, es) => reflectMirrored(Reflect(IntPlus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntMinus(x,y), u, es) => reflectMirrored(Reflect(IntMinus(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntTimes(x,y), u, es) => reflectMirrored(Reflect(IntTimes(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntDivide(x,y), u, es) => reflectMirrored(Reflect(IntDivide(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntMod(x,y), u, es) => reflectMirrored(Reflect(IntMod(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntBinaryOr(x,y), u, es) => reflectMirrored(Reflect(IntBinaryOr(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntBinaryAnd(x,y), u, es) => reflectMirrored(Reflect(IntBinaryAnd(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntBinaryXor(x,y), u, es) => reflectMirrored(Reflect(IntBinaryXor(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntToLong(x), u, es) => reflectMirrored(Reflect(IntToLong(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntToFloat(x), u, es) => reflectMirrored(Reflect(IntToFloat(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntToDouble(x), u, es) => reflectMirrored(Reflect(IntToDouble(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntShiftLeft(x,y), u, es) => reflectMirrored(Reflect(IntShiftLeft(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntShiftRightLogical(x,y), u, es) => reflectMirrored(Reflect(IntShiftRightLogical(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(IntShiftRightArith(x,y), u, es) => reflectMirrored(Reflect(IntShiftRightArith(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(LongMod(x,y), u, es) => reflectMirrored(Reflect(LongMod(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(LongShiftLeft(x,y), u, es) => reflectMirrored(Reflect(LongShiftLeft(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(LongShiftRightUnsigned(x,y), u, es) => reflectMirrored(Reflect(LongShiftRightUnsigned(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(LongBinaryOr(x,y), u, es) => reflectMirrored(Reflect(LongBinaryOr(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(LongBinaryAnd(x,y), u, es) => reflectMirrored(Reflect(LongBinaryAnd(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(LongToInt(x), u, es) => reflectMirrored(Reflect(LongToInt(f(x)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) } }).asInstanceOf[Exp[A]] } +trait PrimitiveOpsExpOpt extends PrimitiveOpsExp { + override def int_plus(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs,rhs) match { + case (Const(a),Const(b)) => unit(a+b) + case (Const(0),b) => b + case (a,Const(0)) => a + case _ => super.int_plus(lhs,rhs) + } + override def int_minus(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs,rhs) match { + case (Const(a),Const(b)) => unit(a-b) + case (a,Const(0)) => a + case (Def(IntPlus(llhs,lrhs)), rhs) if lrhs.equals(rhs) => llhs + case _ => super.int_minus(lhs,rhs) + } + override def int_times(lhs: Exp[Int], rhs: Exp[Int])(implicit pos: SourceContext) : Exp[Int] = (lhs,rhs) match { + case (Const(a),Const(b)) => unit(a*b) + case (Const(0),b) => Const(0) + case (Const(1),b) => b + case (a,Const(0)) => Const(0) + case (a,Const(1)) => a + case _ => super.int_times(lhs,rhs) + } + override def int_to_float(lhs: Rep[Int])(implicit pos: SourceContext): Rep[Float] = lhs match { + case Const(x) => Const(x.toFloat) + case _ => super.int_to_float(lhs) + } + + override def int_to_double(lhs: Rep[Int])(implicit pos: SourceContext): Rep[Double] = lhs match { + case Const(x) => Const(x.toDouble) + case _ => super.int_to_double(lhs) + } + + override def float_to_double(lhs: Rep[Float])(implicit pos: SourceContext): Rep[Double] = lhs match { + case Const(x) => Const(x.toDouble) + case Def(IntToFloat(x)) => int_to_double(x) + case _ => super.float_to_double(lhs) + } + + override def double_to_int(lhs: Rep[Double])(implicit pos: SourceContext): Rep[Int] = lhs match { + case Const(x) => Const(x.toInt) + case Def(IntToDouble(x)) => x + case _ => super.double_to_int(lhs) + } +} + trait ScalaGenPrimitiveOps extends ScalaGenBase { val IR: PrimitiveOpsExp import IR._ @@ -261,28 +575,48 @@ trait ScalaGenPrimitiveOps extends ScalaGenBase { case ObjDoubleNegativeInfinity() => emitValDef(sym, "scala.Double.NegativeInfinity") case ObjDoubleMinValue() => emitValDef(sym, "scala.Double.MinValue") case ObjDoubleMaxValue() => emitValDef(sym, "scala.Double.MaxValue") - case DoubleFloatValue(lhs) => emitValDef(sym, src"$lhs.floatValue()") - case ObjIntegerParseInt(s) => emitValDef(sym, src"java.lang.Integer.parseInt($s)") + case DoubleFloatValue(lhs) => emitValDef(sym, quote(lhs) + ".floatValue()") + case DoublePlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) + case DoubleMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) + case DoubleTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) + case DoubleDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) + case DoubleToInt(lhs) => emitValDef(sym, quote(lhs) + ".toInt") + case DoubleToFloat(lhs) => emitValDef(sym, quote(lhs) + ".toFloat") + case ObjFloatParseFloat(s) => emitValDef(sym, "java.lang.Float.parseFloat(" + quote(s) + ")") + case FloatToInt(lhs) => emitValDef(sym, quote(lhs) + ".toInt") + case FloatToDouble(lhs) => emitValDef(sym, quote(lhs) + ".toDouble") + case FloatPlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) + case FloatMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) + case FloatTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) + case FloatDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) + case ObjIntegerParseInt(s) => emitValDef(sym, "java.lang.Integer.parseInt(" + quote(s) + ")") case ObjIntMaxValue() => emitValDef(sym, "scala.Int.MaxValue") - case ObjIntMinValue() => emitValDef(sym, "scala.Int.MinValue") - case IntDivideFrac(lhs,rhs) => emitValDef(sym, src"$lhs / $rhs") - case IntDivide(lhs,rhs) => emitValDef(sym, src"$lhs / $rhs") - case IntMod(lhs,rhs) => emitValDef(sym, src"$lhs % $rhs") - case IntBinaryOr(lhs,rhs) => emitValDef(sym, src"$lhs | $rhs") - case IntBinaryAnd(lhs,rhs) => emitValDef(sym, src"$lhs & $rhs") - case IntBinaryXor(lhs,rhs) => emitValDef(sym, src"$lhs ^ $rhs") - case IntDoubleValue(lhs) => emitValDef(sym, src"$lhs.doubleValue()") - case IntFloatValue(lhs) => emitValDef(sym, src"$lhs.floatValue()") - case IntBitwiseNot(lhs) => emitValDef(sym, src"~$lhs") - case IntToLong(lhs) => emitValDef(sym, src"$lhs.toLong") - case LongBinaryOr(lhs,rhs) => emitValDef(sym, src"$lhs | $rhs") - case LongBinaryXor(lhs,rhs) => emitValDef(sym, src"$lhs ^ $rhs") - case LongBinaryAnd(lhs,rhs) => emitValDef(sym, src"$lhs & $rhs") - case LongShiftLeft(lhs,rhs) => emitValDef(sym, src"$lhs << $rhs") - case LongShiftRight(lhs,rhs) => emitValDef(sym, src"$lhs >> $rhs") - case LongShiftRightUnsigned(lhs,rhs) => emitValDef(sym, src"$lhs >>> $rhs") - case LongToInt(lhs) => emitValDef(sym, src"$lhs.toInt") - case CharMinus(lhs,rhs) => emitValDef(sym, src"$lhs - $rhs") + case ObjIntMinValue() => emitValDef(sym, "scala.Int.MinValue") + case IntPlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) + case IntMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) + case IntTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) + // case IntDivideFrac(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) + case IntDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) + case IntMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs)) + case IntBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs)) + case IntBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs)) + case IntBinaryXor(lhs,rhs) => emitValDef(sym, quote(lhs) + " ^ " + quote(rhs)) + case IntShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs)) + case IntShiftRightArith(lhs, rhs) => emitValDef(sym, quote(lhs) + " >> " + quote(rhs)) + case IntShiftRightLogical(lhs, rhs) => emitValDef(sym, quote(lhs) + " >>> " + quote(rhs)) + case IntDoubleValue(lhs) => emitValDef(sym, quote(lhs) + ".doubleValue()") + case IntFloatValue(lhs) => emitValDef(sym, quote(lhs) + ".floatValue()") + case IntBitwiseNot(lhs) => emitValDef(sym, "~" + quote(lhs)) + case IntToLong(lhs) => emitValDef(sym, quote(lhs) + ".toLong") + case IntToFloat(lhs) => emitValDef(sym, quote(lhs) + ".toFloat") + case IntToDouble(lhs) => emitValDef(sym, quote(lhs) + ".toDouble") + case ObjLongParseLong(s) => emitValDef(sym, "java.lang.Long.parseLong(" + quote(s) + ")") + case LongMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs)) + case LongBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs)) + case LongBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs)) + case LongShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs)) + case LongShiftRightUnsigned(lhs,rhs) => emitValDef(sym, quote(lhs) + " >>> " + quote(rhs)) + case LongToInt(lhs) => emitValDef(sym, quote(lhs) + ".toInt") case _ => super.emitNode(sym, rhs) } } @@ -291,35 +625,83 @@ trait CLikeGenPrimitiveOps extends CLikeGenBase { val IR: PrimitiveOpsExp import IR._ - //TODO: stdlib.h needs to be included in the common header file override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { - //case ObjDoubleParseDouble(s) => emitValDef(sym, "atof(" + quote(s) + ")") - case ObjDoublePositiveInfinity() => emitValDef(sym, "DBL_MAX") - //case ObjDoubleMinValue() => emitValDef(sym, "scala.Double.MinValue") - case DoubleFloatValue(lhs) => emitValDef(sym, src"(float)$lhs") - //case ObjIntegerParseInt(s) => emitValDef(sym, "java.lang.Integer.parseInt(" + quote(s) + ")") - //case ObjIntMaxValue() => emitValDef(sym, "scala.Int.MaxValue") - case IntDivideFrac(lhs,rhs) => emitValDef(sym, src"$lhs / $rhs") - case IntDivide(lhs,rhs) => emitValDef(sym, src"$lhs / $rhs") - case IntMod(lhs,rhs) => emitValDef(sym, src"$lhs % $rhs") - case IntBinaryOr(lhs,rhs) => emitValDef(sym, src"$lhs | $rhs") - case IntBinaryAnd(lhs,rhs) => emitValDef(sym, src"$lhs & $rhs") - case IntDoubleValue(lhs) => emitValDef(sym, src"(double)$lhs") - case LongMod(lhs,rhs) => emitValDef(sym, src"$lhs % $rhs") - case LongToInt(lhs) => emitValDef(sym, src"(int)$lhs") - case LongBinaryOr(lhs,rhs) => emitValDef(sym, src"$lhs | $rhs") - case LongBinaryAnd(lhs,rhs) => emitValDef(sym, src"$lhs & $rhs") - case CharMinus(lhs,rhs) => emitValDef(sym, src"$lhs - $rhs") - case LongShiftLeft(lhs,rhs) => emitValDef(sym, src"$lhs << $rhs") - case LongShiftRight(lhs,rhs) => emitValDef(sym, src"$lhs >> $rhs") - case LongShiftRightUnsigned(lhs,rhs) => emitValDef(sym, src"$lhs >>> $rhs") + case ObjDoubleParseDouble(s) => emitValDef(sym, "strtod(" + quote(s) + ",NULL)") + case ObjDoubleMinValue() => emitValDef(sym, "DBL_MIN") + case ObjDoubleMaxValue() => emitValDef(sym, "DBL_MAX") + case DoubleFloatValue(lhs) => emitValDef(sym, "(float)"+quote(lhs)) + case DoublePlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) + case DoubleMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) + case DoubleTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) + case DoubleDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) + case DoubleToInt(lhs) => emitValDef(sym, "(int32_t)" + quote(lhs)) + case DoubleToFloat(lhs) => emitValDef(sym, "(float)" + quote(lhs)) + case ObjFloatParseFloat(s) => emitValDef(sym, "strtof(" + quote(s) + ".c_str(),NULL)") + case FloatToInt(lhs) => emitValDef(sym, "(int32_t)" + quote(lhs)) + case FloatToDouble(lhs) => emitValDef(sym, "(double)" + quote(lhs)) + case FloatPlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) + case FloatMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) + case FloatTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) + case FloatDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) + case ObjIntegerParseInt(s) => emitValDef(sym, "atoi(" + quote(s) + ".c_str())") + case ObjIntMaxValue() => emitValDef(sym, "INT_MAX") + case ObjIntMinValue() => emitValDef(sym, "INT_MIN") + case IntPlus(lhs,rhs) => emitValDef(sym, quote(lhs) + " + " + quote(rhs)) + case IntMinus(lhs,rhs) => emitValDef(sym, quote(lhs) + " - " + quote(rhs)) + case IntTimes(lhs,rhs) => emitValDef(sym, quote(lhs) + " * " + quote(rhs)) + // case IntDivideFrac(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) + case IntDivide(lhs,rhs) => emitValDef(sym, quote(lhs) + " / " + quote(rhs)) + case IntMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs)) + case IntBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs)) + case IntBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs)) + case IntBinaryXor(lhs,rhs) => emitValDef(sym, quote(lhs) + " ^ " + quote(rhs)) + case IntShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs)) + case IntShiftRightArith(lhs, rhs) => emitValDef(sym, quote(lhs) + " >> " + quote(rhs)) + case IntShiftRightLogical(lhs, rhs) => emitValDef(sym, "(uint32_t)" + quote(lhs) + " >> " + quote(rhs)) + case IntDoubleValue(lhs) => emitValDef(sym, "(double)"+quote(lhs)) + case IntFloatValue(lhs) => emitValDef(sym, "(float)"+quote(lhs)) + case IntBitwiseNot(lhs) => emitValDef(sym, "~" + quote(lhs)) + case IntToLong(lhs) => emitValDef(sym, "(int64_t)"+quote(lhs)) + case IntToFloat(lhs) => emitValDef(sym, "(float)"+quote(lhs)) + case IntToDouble(lhs) => emitValDef(sym, "(double)"+quote(lhs)) + case ObjLongParseLong(s) => emitValDef(sym, "strtod(" + quote(s) + ".c_str(),NULL)") + case LongMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs)) + case LongBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs)) + case LongBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs)) + case LongShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs)) + case LongShiftRightUnsigned(lhs,rhs) => emitValDef(sym, "(uint64_t)" + quote(lhs) + " >> " + quote(rhs)) + case LongToInt(lhs) => emitValDef(sym, "(int32_t)"+quote(lhs)) + case _ => super.emitNode(sym, rhs) + } + } +} + +trait CudaGenPrimitiveOps extends CudaGenBase with CLikeGenPrimitiveOps { + val IR: PrimitiveOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case ObjDoublePositiveInfinity() => emitValDef(sym, "__longlong_as_double(0x7ff0000000000000ULL)") + case ObjDoubleNegativeInfinity() => emitValDef(sym, "__longlong_as_double(0xfff0000000000000ULL)") case _ => super.emitNode(sym, rhs) } } } -trait CudaGenPrimitiveOps extends CudaGenBase with CLikeGenPrimitiveOps trait OpenCLGenPrimitiveOps extends OpenCLGenBase with CLikeGenPrimitiveOps -trait CGenPrimitiveOps extends CGenBase with CLikeGenPrimitiveOps + +trait CGenPrimitiveOps extends CGenBase with CLikeGenPrimitiveOps { + val IR: PrimitiveOpsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { + rhs match { + case ObjDoublePositiveInfinity() => emitValDef(sym, "INFINITY") + case ObjDoubleNegativeInfinity() => emitValDef(sym, "-INFINITY") + case _ => super.emitNode(sym, rhs) + } + } +} diff --git a/src/common/SetOps.scala b/src/common/SetOps.scala index 6b2ce191..c965a092 100644 --- a/src/common/SetOps.scala +++ b/src/common/SetOps.scala @@ -6,14 +6,12 @@ import scala.lms.internal._ import scala.collection.mutable.Set import scala.reflect.SourceContext -trait SetOps extends Base with Variables { +trait SetOps extends Base { object Set { def apply[A:Manifest](xs: Rep[A]*)(implicit pos: SourceContext) = set_new[A](xs) - def empty = set_empty() } implicit def repSetToSetOps[A:Manifest](v: Rep[Set[A]]) = new setOpsCls(v) - implicit def varSetToSetOps[A:Manifest](v: Var[Set[A]]) = new setOpsCls(readVar(v)) class setOpsCls[A:Manifest](s: Rep[Set[A]]) { def contains(i: Rep[A])(implicit pos: SourceContext) = set_contains(s, i) @@ -23,92 +21,39 @@ trait SetOps extends Base with Variables { def clear()(implicit pos: SourceContext) = set_clear(s) def toSeq(implicit pos: SourceContext) = set_toseq(s) def toArray(implicit pos: SourceContext) = set_toarray(s) - def map[B:Manifest](f: Rep[A] => Rep[B]) = set_map(s,f) - def foreach(block: Rep[A] => Rep[Unit])(implicit pos: SourceContext) = set_foreach(s, block) - def head(implicit pos: SourceContext) = set_head(s) } def set_new[A:Manifest](xs: Seq[Rep[A]])(implicit pos: SourceContext) : Rep[Set[A]] def set_contains[A:Manifest](s: Rep[Set[A]], i: Rep[A])(implicit pos: SourceContext) : Rep[Boolean] def set_add[A:Manifest](s: Rep[Set[A]], i: Rep[A])(implicit pos: SourceContext) : Rep[Unit] - def set_remove[A:Manifest](s: Rep[Set[A]], i: Rep[A])(implicit pos: SourceContext) : Rep[Boolean] + def set_remove[A:Manifest](s: Rep[Set[A]], i: Rep[A])(implicit pos: SourceContext) : Rep[Unit] def set_size[A:Manifest](s: Rep[Set[A]])(implicit pos: SourceContext) : Rep[Int] - def set_map[A:Manifest,B:Manifest](a: Rep[Set[A]], f: Rep[A] => Rep[B]): Rep[Set[B]] def set_clear[A:Manifest](s: Rep[Set[A]])(implicit pos: SourceContext) : Rep[Unit] def set_toseq[A:Manifest](s: Rep[Set[A]])(implicit pos: SourceContext): Rep[Seq[A]] def set_toarray[A:Manifest](s: Rep[Set[A]])(implicit pos: SourceContext): Rep[Array[A]] - def set_foreach[T:Manifest](x: Rep[Set[T]], block: Rep[T] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] - def set_empty[T:Manifest]() : Rep[Set[T]] - def set_head[T:Manifest](m: Rep[Set[T]])(implicit pos: SourceContext): Rep[T] } trait SetOpsExp extends SetOps with ArrayOps with EffectExp { case class SetNew[A:Manifest](xs: Seq[Exp[A]], mA: Manifest[A]) extends Def[Set[A]] case class SetContains[A:Manifest](s: Exp[Set[A]], i: Exp[A]) extends Def[Boolean] case class SetAdd[A:Manifest](s: Exp[Set[A]], i: Exp[A]) extends Def[Unit] - case class SetRemove[A:Manifest](s: Exp[Set[A]], i: Exp[A]) extends Def[Boolean] { - val m = manifest[A] - } + case class SetRemove[A:Manifest](s: Exp[Set[A]], i: Exp[A]) extends Def[Unit] case class SetSize[A:Manifest](s: Exp[Set[A]]) extends Def[Int] case class SetClear[A:Manifest](s: Exp[Set[A]]) extends Def[Unit] case class SetToSeq[A:Manifest](s: Exp[Set[A]]) extends Def[Seq[A]] - case class SetToArray[A:Manifest](s: Exp[Set[A]]) extends Def[Array[A]] - case class SetMap[A:Manifest,B:Manifest](a: Exp[Set[A]], x: Sym[A], block: Block[B]) extends Def[Set[B]] - case class SetForeach[T](a: Exp[Set[T]], x: Sym[T], block: Block[Unit]) extends Def[Unit] - case class SetEmpty[T:Manifest]() extends Def[Set[T]] { - val m = manifest[T] - } - case class SetHead[T:Manifest](s: Exp[Set[T]]) extends Def[T] { - val m = manifest[T] + case class SetToArray[A:Manifest](s: Exp[Set[A]]) extends Def[Array[A]] { + //val array = unit(manifest[A].newArray(0)) + val array = NewArray[A](s.size) } def set_new[A:Manifest](xs: Seq[Exp[A]])(implicit pos: SourceContext) = reflectMutable(SetNew(xs, manifest[A])) def set_contains[A:Manifest](s: Exp[Set[A]], i: Exp[A])(implicit pos: SourceContext) = SetContains(s, i) def set_add[A:Manifest](s: Exp[Set[A]], i: Exp[A])(implicit pos: SourceContext) = reflectWrite(s)(SetAdd(s, i)) - def set_remove[A:Manifest](s: Exp[Set[A]], i: Exp[A])(implicit pos: SourceContext) = reflectEffect(SetRemove(s, i)) + def set_remove[A:Manifest](s: Exp[Set[A]], i: Exp[A])(implicit pos: SourceContext) = reflectWrite(s)(SetRemove(s, i)) def set_size[A:Manifest](s: Exp[Set[A]])(implicit pos: SourceContext) = SetSize(s) def set_clear[A:Manifest](s: Exp[Set[A]])(implicit pos: SourceContext) = reflectWrite(s)(SetClear(s)) def set_toseq[A:Manifest](s: Exp[Set[A]])(implicit pos: SourceContext) = SetToSeq(s) def set_toarray[A:Manifest](s: Exp[Set[A]])(implicit pos: SourceContext) = SetToArray(s) - def set_foreach[T:Manifest](a: Exp[Set[T]], block: Exp[T] => Exp[Unit])(implicit pos: SourceContext): Exp[Unit] = { - val x = fresh[T] - val b = reifyEffects(block(x)) - reflectEffect(SetForeach(a, x, b), summarizeEffects(b).star) - } - def set_map[A:Manifest,B:Manifest](a: Exp[Set[A]], f: Exp[A] => Exp[B]) = { - val x = fresh[A] - val b = reifyEffects(f(x)) - reflectEffect(SetMap(a, x, b), summarizeEffects(b)) - } - def set_empty[T:Manifest]() = reflectEffect(SetEmpty()) - def set_head[T:Manifest](s: Exp[Set[T]])(implicit pos: SourceContext) = reflectEffect(SetHead(s)) - - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { - (e match { - case Reflect(st@SetHead(s), u, es) => reflectMirrored(Reflect(SetHead(f(s))(st.m), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(st@SetRemove(s,el), u, es) => reflectMirrored(Reflect(SetRemove(f(s),f(el))(st.m), mapOver(f,u), f(es)))(mtype(manifest[A])) - case _ => super.mirror(e,f) - }).asInstanceOf[Exp[A]] // why?? - } - - override def syms(e: Any): List[Sym[Any]] = e match { - case SetForeach(a, x, body) => syms(a):::syms(body) - case SetMap(a, x, body) => syms(a):::syms(body) - case _ => super.syms(e) - } - - override def boundSyms(e: Any): List[Sym[Any]] = e match { - case SetForeach(a, x, body) => x :: effectSyms(body) - case SetMap(a, x, body) => x :: effectSyms(body) - case _ => super.boundSyms(e) - } - - override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { - case SetForeach(a, x, body) => freqNormal(a):::freqHot(body) - case SetMap(a, x, body) => freqNormal(a):::freqHot(body) - case _ => super.symsFreq(e) - } - } trait BaseGenSetOps extends GenericNestedCodegen { @@ -120,7 +65,7 @@ trait BaseGenSetOps extends GenericNestedCodegen { trait ScalaGenSetOps extends BaseGenSetOps with ScalaGenEffect { val IR: SetOpsExp import IR._ - + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case SetNew(xs, mA) => emitValDef(sym, src"collection.mutable.HashSet[$mA](" + (xs map {quote}).mkString(",") + ")") case SetContains(s,i) => emitValDef(sym, src"$s.contains($i)") @@ -129,76 +74,31 @@ trait ScalaGenSetOps extends BaseGenSetOps with ScalaGenEffect { case SetSize(s) => emitValDef(sym, src"$s.size") case SetClear(s) => emitValDef(sym, src"$s.clear()") case SetToSeq(s) => emitValDef(sym, src"$s.toSeq") - case n@SetToArray(s) => emitValDef(sym, quote(s) + ".toArray") - case SetForeach(a,x,block) => - emitValDef(sym, src"$a.foreach{") - gen"""$x => - |${nestedBlock(block)} - |$block - |}""" - case SetMap(a,x,block) => - emitValDef(sym, src"$a.map{") - gen"""$x => - |${nestedBlock(block)} - |$block + case n@SetToArray(s) => //emitValDef(sym, quote(s) + ".toArray") + gen"""// workaround for refinedManifest problem + |val $sym = { + |val out = $n.array + |val in = $s.toSeq + |var i = 0 + |while (i < in.length) { + |out(i) = in(i) + |i += 1 + |} + |out |}""" - case SetEmpty() => emitValDef(sym, "scala.collection.mutable.HashSet.empty") - case SetHead(s) => emitValDef(sym, src"$s.head") case _ => super.emitNode(sym, rhs) } } trait CLikeGenSetOps extends BaseGenSetOps with CLikeCodegen { val IR: SetOpsExp - import IR._ + import IR._ + +// override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { +// case _ => super.emitNode(sym, rhs) +// } } trait CudaGenSetOps extends CudaGenEffect with CLikeGenSetOps trait OpenCLGenSetOps extends OpenCLGenEffect with CLikeGenSetOps - -trait CGenSetOps extends CGenEffect with CNestedCodegen { - val IR: SetOpsExp - import IR._ - - override def remap[A](m: Manifest[A]) = m match { - case s if m <:< manifest[Set[Any]] => "GList**" - case _ => super.remap(m) - } - - override def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = { - if (sym.tp <:< manifest[Variable[Set[Any]]]) - stream.println(remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") - else super.emitVarDef(sym,rhs) - } - - override def emitValDef(sym: Sym[Any], rhs: String): Unit = { - if (sym.tp <:< manifest[Set[Any]]) { - stream.println(remap(sym.tp) + " " + quote(sym) + " = " + getMemoryAllocString("1", "GList*") + ";"); - stream.println("*" + quote(sym) + " = " + rhs + ";") - } - else super.emitValDef(sym,rhs) - } - - override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { - case sh@SetHead(s) => sym.atPhase(LIRLowering) { - val ls = LIRLowering(s) - set_head(ls.asInstanceOf[Exp[Set[Any]]])(remapManifest(fresh(sh.m))(sh.m).asInstanceOf[Manifest[Any]],implicitly[SourceContext]).asInstanceOf[Exp[A]] - } - case _ => super.lowerNode(sym,rhs) - } - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case SetHead(s) => { - //NOTE: TODO: I do not like this -- find a better way - if (sym.tp == manifest[Int] || sym.tp == manifest[Double]) - emitValDef(sym, src"GPOINTER_TO_INT(g_list_first(*$s)->data)") - else emitValDef(sym, src"g_list_first(*$s)->data;") - } - case SetRemove(s,e) => - //NOTE: TODO: I do not like this -- find a better way - if (e.tp == manifest[Int] || e.tp == manifest[Double]) - stream.println(src"*$s = g_list_remove(*$s,GINT_TO_POINTER($e));") - else stream.println(src"*$s = g_list_remove(*$s,$e);") - case _ => super.emitNode(sym, rhs) - } -} +trait CGenSetOps extends CGenEffect with CLikeGenSetOps diff --git a/src/common/SimpleDateFormatOps.scala b/src/common/SimpleDateFormatOps.scala deleted file mode 100644 index fe8f9461..00000000 --- a/src/common/SimpleDateFormatOps.scala +++ /dev/null @@ -1,58 +0,0 @@ -package scala.lms -package common - -import scala.lms.common._ -import scala.reflect.SourceContext -import java.util.Date -import java.text.SimpleDateFormat - -/** - * Lifter Classes for SimpleDateFormat - */ -trait SimpleDateFormatOps extends Base { - - class SimpleDateFormatOpsCls(x: Rep[SimpleDateFormat]) { - def format(d: Rep[Date]): Rep[String] = sdfFormat(x, d) - def parse(s: Rep[String]): Rep[Date] = sdfParse(x, s) - } - - implicit def date2SimpleDateFormatOpsCls(x: Rep[SimpleDateFormat]): SimpleDateFormatOpsCls = new SimpleDateFormatOpsCls(x) - def newSimpleDateFormat(format: Rep[String]): Rep[SimpleDateFormat] - def sdfFormat(x: Rep[SimpleDateFormat], d: Rep[Date]): Rep[String] - def sdfParse(x: Rep[SimpleDateFormat], s: Rep[String]): Rep[Date] -} - -trait SimpleDateFormatExp extends SimpleDateFormatOps with BaseExp { - - case class SdfFormat(x: Exp[SimpleDateFormat], d: Exp[Date]) extends Def[String] - case class SdfParse(x: Exp[SimpleDateFormat], s: Exp[String]) extends Def[Date] - case class NewSimpleDateFormat(format: Exp[String]) extends Def[SimpleDateFormat] - - def newSimpleDateFormat(format: Exp[String]): Exp[SimpleDateFormat] = NewSimpleDateFormat(format) - def sdfFormat(x: Exp[SimpleDateFormat], d: Exp[Date]) = SdfFormat(x, d) - def sdfParse(x: Exp[SimpleDateFormat], s: Exp[String]) = SdfParse(x, s) - - ////////////// - // mirroring - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case NewSimpleDateFormat(format) => newSimpleDateFormat(f(format)) - case SdfFormat(x, d) => sdfFormat(f(x), f(d)) - case SdfParse(x, s) => sdfParse(f(x), f(s)) - case _ => super.mirror(e,f) - }).asInstanceOf[Exp[A]] // why?? -} - -trait SimpleDateFormatExpOpt extends SimpleDateFormatExp { -} - -trait ScalaGenSimpleDateFormat extends ScalaGenBase { - val IR: SimpleDateFormatExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case NewSimpleDateFormat(fmt) => emitValDef(sym, "new java.text.SimpleDateFormat(%s)".format(quote(fmt))) - case SdfFormat(x, d) => emitValDef(sym, "%s.format(%s)".format(quote(x),quote(d))); - case SdfParse(x, s) => emitValDef(sym, "%s.parse(%s)".format(quote(x),quote(s))); - case _ => super.emitNode(sym, rhs) - } -} \ No newline at end of file diff --git a/src/common/SimplifyTransform.scala b/src/common/SimplifyTransform.scala index a737402e..6d4387ad 100644 --- a/src/common/SimplifyTransform.scala +++ b/src/common/SimplifyTransform.scala @@ -96,81 +96,86 @@ trait SimplifyTransform extends internal.FatScheduling { } // TODO: generalize, abstract out SimpleFatXX types - def transformAll(scope: List[Stm], t: SubstTransformer): List[Stm] = scope flatMap { - case TP(sym, rhs) => - transformOne(sym, rhs, t) match { - case s: Sym[Any] => (scope.find(_.lhs contains s) orElse findDefinition(s)).toList // check scope before target graph - case _ => Nil - } - case TTP(lhs, mhs, SimpleFatIfThenElse(c,as,bs)) => - // alternate strategy: transform thin def, then fatten again (a little detour) - printdbg("need to transform rhs of fat if/then/else: " + lhs + ", if " + c + " then " + as + " else " + bs) - val lhs2 = (lhs zip mhs).map { case (s,r) => transformOne(s, r, t) }.distinct.asInstanceOf[List[Sym[Any]]] - val mhs2 = lhs2.map(s => findDefinition(s).get.defines(s).get) - // TBD: we're mirroring the defs in mhs, creating new stms - // we don't really want new stms: if the defs are just abstract descriptions we only want them updated - - // this means we'll have both a TP and a TTP defining the same sym in globalDefs --> bad! - // not quite so fast, chances are the TTP's never make it into globalDefs (no toAtom call)!!! - - if (lhs != lhs2) { - val missing = Nil//(lhs2.map(s => findDefinition(s).get) diff innerScope) - printdbg("lhs changed! will add to innerScope: "+missing.mkString(",")) - //innerScope = innerScope ::: missing - } + def transformAll(scope: List[Stm], t: SubstTransformer): List[Stm] = { + val scopeIndex = new java.util.IdentityHashMap[Sym[Any],Stm] + for (stm <- scope; s <- stm.lhs) scopeIndex.put(s,stm) + + scope flatMap { + case TP(sym, rhs) => + transformOne(sym, rhs, t) match { + case s: Sym[Any] => (Option(scopeIndex.get(s)) orElse findDefinition(s)).toList // check scope before target graph + case _ => Nil + } + case TTP(lhs, mhs, SimpleFatIfThenElse(c,as,bs)) => + // alternate strategy: transform thin def, then fatten again (a little detour) + printdbg("need to transform rhs of fat if/then/else: " + lhs + ", if " + c + " then " + as + " else " + bs) + val lhs2 = (lhs zip mhs).map { case (s,r) => transformOne(s, r, t) }.distinct.asInstanceOf[List[Sym[Any]]] + val mhs2 = lhs2.map(s => findDefinition(s).get.defines(s).get) + // TBD: we're mirroring the defs in mhs, creating new stms + // we don't really want new stms: if the defs are just abstract descriptions we only want them updated + + // this means we'll have both a TP and a TTP defining the same sym in globalDefs --> bad! + // not quite so fast, chances are the TTP's never make it into globalDefs (no toAtom call)!!! + + if (lhs != lhs2) { + val missing = Nil//(lhs2.map(s => findDefinition(s).get) diff innerScope) + printdbg("lhs changed! will add to innerScope: "+missing.mkString(",")) + //innerScope = innerScope ::: missing + } - def infix_toIf(d: Def[Any]) = d match { - case l: AbstractIfThenElse[_] => l - case Reflect(l: AbstractIfThenElse[_], _, _) => l - } - val cond2 = if (lhs != lhs2) mhs2.map (_.toIf.cond) reduceLeft { (s1,s2) => assert(s1==s2,"conditions don't agree: "+s1+","+s2); s1 } - else t(c) - val as2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toIf.thenp))) - else (lhs zip as)) map { case (s,r) => transformIfBody(s,r,t) } - val bs2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toIf.elsep))) - else (lhs zip bs)) map { case (s,r) => transformIfBody(s,r,t) } - - printdbg("came up with: " + lhs2 + ", if " + cond2 + " then " + as2 + " else " + bs2 + " with subst " + t.subst.mkString(",")) - List(TTP(lhs2, mhs2, SimpleFatIfThenElse(cond2,as2,bs2))) - - case TTP(lhs, mhs, SimpleFatLoop(s,x,rhs)) => - // alternate strategy: transform thin def, then fatten again (a little detour) - printdbg("need to transform rhs of fat loop: " + lhs + ", " + rhs) - val lhs2 = (lhs zip mhs).map { case (s,r) => transformOne(s, r, t) }.distinct.asInstanceOf[List[Sym[Any]]] - val mhs2 = lhs2.map(s => findDefinition(s).get.defines(s).get) - if (lhs != lhs2) { - val missing = (lhs2.map(s => findDefinition(s).get) diff scope/*innerScope*/) - printdbg("lhs changed! will add to innerScope: "+missing.mkString(",")) - //innerScope = innerScope ::: missing - } - //val shape2 = if (lhs != lhs2) lhs2.map { case Def(SimpleLoop(s,_,_)) => s } reduceLeft { (s1,s2) => assert(s1==s2,"shapes don't agree: "+s1+","+s2); s1 } - def infix_toLoop(d: Def[Any]) = d match { - case l: AbstractLoop[_] => l - case Reflect(l: AbstractLoop[_], _, _) => l - } - val shape2 = if (lhs != lhs2) mhs2.map (_.toLoop.size) reduceLeft { (s1,s2) => assert(s1==s2,"shapes don't agree: "+s1+","+s2); s1 } - else t(s) - val rhs2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toLoop.body))) - else (lhs zip rhs)) map { case (s,r) => transformLoopBody(s,r,t) } - -/* //update innerScope -- change definition of lhs2 in place (necessary?) - innerScope = innerScope map { - case TP(l,_) if lhs2 contains l => TP(l, SimpleLoop(shape2,t(x).asInstanceOf[Sym[Int]],rhs2(lhs2.indexOf(l)))) - case d => d - }*/ - - printdbg("came up with: " + lhs2 + ", " + rhs2 + " with subst " + t.subst.mkString(",")) - List(TTP(lhs2, mhs2, SimpleFatLoop(shape2,t(x).asInstanceOf[Sym[Int]],rhs2))) - // still problem: VectorSum(a,b) = SimpleLoop(i, ReduceElem(f(i))) - // might need to translate f(i), but looking up VectorSum will not be changed at all!!! - // --> change rhs nonetheless??? + def infix_toIf(d: Def[Any]) = d match { + case l: AbstractIfThenElse[_] => l + case Reflect(l: AbstractIfThenElse[_], _, _) => l + } + val cond2 = if (lhs != lhs2) mhs2.map (_.toIf.cond) reduceLeft { (s1,s2) => assert(s1==s2,"conditions don't agree: "+s1+","+s2); s1 } + else t(c) + val as2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toIf.thenp))) + else (lhs zip as)) map { case (s,r) => transformIfBody(s,r,t) } + val bs2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toIf.elsep))) + else (lhs zip bs)) map { case (s,r) => transformIfBody(s,r,t) } -/* - // potential problem here: calling toAtom on a SimpleCollect (which does not have any symbol so far!) - val lhs2 = (lhs zip rhs).map(p=>transformOne(p._1,p._2,t)).map { case s: Sym[Any] => s }.distinct.asInstanceOf[List[Sym[Any]]] - val rhs2 = lhs2 map (findDefinition(_).get.rhs) //FIXME: will lookup old sym (ie VectorTrans) in case of AbstractCollect - List(TTP(lhs2, SimpleFatLoop(t(s),t(x).asInstanceOf[Sym[Int]],rhs2))) -*/ + printdbg("came up with: " + lhs2 + ", if " + cond2 + " then " + as2 + " else " + bs2 + " with subst " + t.subst.mkString(",")) + List(TTP(lhs2, mhs2, SimpleFatIfThenElse(cond2,as2,bs2))) + + case TTP(lhs, mhs, SimpleFatLoop(s,x,rhs)) => + // alternate strategy: transform thin def, then fatten again (a little detour) + printdbg("need to transform rhs of fat loop: " + lhs + ", " + rhs) + val lhs2 = (lhs zip mhs).map { case (s,r) => transformOne(s, r, t) }.distinct.asInstanceOf[List[Sym[Any]]] + val mhs2 = lhs2.map(s => findDefinition(s).get.defines(s).get) + if (lhs != lhs2) { + val missing = (lhs2.map(s => findDefinition(s).get) diff scope/*innerScope*/) + printdbg("lhs changed! will add to innerScope: "+missing.mkString(",")) + //innerScope = innerScope ::: missing + } + //val shape2 = if (lhs != lhs2) lhs2.map { case Def(SimpleLoop(s,_,_)) => s } reduceLeft { (s1,s2) => assert(s1==s2,"shapes don't agree: "+s1+","+s2); s1 } + def infix_toLoop(d: Def[Any]) = d match { + case l: AbstractLoop[_] => l + case Reflect(l: AbstractLoop[_], _, _) => l + } + val shape2 = if (lhs != lhs2) mhs2.map (_.toLoop.size) reduceLeft { (s1,s2) => assert(s1==s2,"shapes don't agree: "+s1+","+s2); s1 } + else t(s) + val rhs2 = (if (lhs != lhs2) (lhs2 zip (mhs2 map (_.toLoop.body))) + else (lhs zip rhs)) map { case (s,r) => transformLoopBody(s,r,t) } + + /* //update innerScope -- change definition of lhs2 in place (necessary?) + innerScope = innerScope map { + case TP(l,_) if lhs2 contains l => TP(l, SimpleLoop(shape2,t(x).asInstanceOf[Sym[Int]],rhs2(lhs2.indexOf(l)))) + case d => d + }*/ + + printdbg("came up with: " + lhs2 + ", " + rhs2 + " with subst " + t.subst.mkString(",")) + List(TTP(lhs2, mhs2, SimpleFatLoop(shape2,t(x).asInstanceOf[Sym[Int]],rhs2))) + // still problem: VectorSum(a,b) = SimpleLoop(i, ReduceElem(f(i))) + // might need to translate f(i), but looking up VectorSum will not be changed at all!!! + // --> change rhs nonetheless??? + + /* + // potential problem here: calling toAtom on a SimpleCollect (which does not have any symbol so far!) + val lhs2 = (lhs zip rhs).map(p=>transformOne(p._1,p._2,t)).map { case s: Sym[Any] => s }.distinct.asInstanceOf[List[Sym[Any]]] + val rhs2 = lhs2 map (findDefinition(_).get.rhs) //FIXME: will lookup old sym (ie VectorTrans) in case of AbstractCollect + List(TTP(lhs2, SimpleFatLoop(t(s),t(x).asInstanceOf[Sym[Int]],rhs2))) + */ + } } def transformAllFully(currentScope0: List[Stm], result0: List[Exp[Any]], t: SubstTransformer): (List[Stm], List[Exp[Any]]) = { diff --git a/src/common/SplitEffects.scala b/src/common/SplitEffects.scala index 56488857..162cabfe 100644 --- a/src/common/SplitEffects.scala +++ b/src/common/SplitEffects.scala @@ -17,6 +17,9 @@ trait SplitEffectsExpFat extends IfThenElseFatExp with WhileExp with PreviousIte // TODO: SimpleLoops + // FIXME: wo do not account for mutable objectes allocated in a loop + // (see test8-speculative6) + override def reflectEffectInternal[A:Manifest](x: Def[A], u: Summary)(implicit pos: SourceContext): Exp[A] = x match { case IfThenElse(cond, thenp, elsep) => val affected = (u.mayRead ++ u.mayWrite).distinct diff --git a/src/common/TreeSet.scala b/src/common/TreeSet.scala deleted file mode 100644 index 84b56c5d..00000000 --- a/src/common/TreeSet.scala +++ /dev/null @@ -1,126 +0,0 @@ -package scala.lms.common - -import scala.collection.mutable -import scala.reflect.SourceContext -import scala.lms.internal._ - -trait TreeSet extends Base with Variables with Pointer { - - object TreeSet { - def apply[M:Manifest](f: (Rep[M],Rep[M]) => Rep[Int])(implicit pos: SourceContext) = - newTreeSet[M](f) - } - - class TreeSetOps[M: Manifest](x: Rep[mutable.TreeSet[M]]) { - def insert(y: Rep[M]) = treeSetAdd[M](x,y) - def -=(y: Rep[M]) = treeSetRemove[M](x,y) - def head() = treeSetHead[M](x) - def size() = treeSetSize[M](x) - } - implicit def TreeSet2TreeSetOps[M: Manifest](x: Rep[mutable.TreeSet[M]]) = new TreeSetOps(x) - implicit def varTreeSet2TreeSetOps[M: Manifest](x: Var[mutable.TreeSet[M]]) = new TreeSetOps(readVar(x)) - - def newTreeSet[M: Manifest](x: (Rep[M],Rep[M])=>Rep[Int]): Rep[mutable.TreeSet[M]] - def treeSetAdd[M: Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]): Rep[Unit] - def treeSetRemove[M: Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]): Rep[Unit] - def treeSetHead[M: Manifest](x: Rep[mutable.TreeSet[M]]): Rep[M] - def treeSetSize[M: Manifest](x: Rep[mutable.TreeSet[M]]): Rep[Int] -} - -trait TreeSetExp extends TreeSet with BaseExp with Effects with FunctionsExp with PointerExp { - case class NewTreeSet[M: Manifest](x: Block[Int], o1: Sym[M], o2: Sym[M]) extends Def[mutable.TreeSet[M]] { val m = manifest[M] } - case class TreeSetAdd[M:Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]) extends Def[Unit] { val m = manifest[M] } - case class TreeSetRemove[M:Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]) extends Def[Unit] { val m = manifest[M] } - case class TreeSetHead[M:Manifest](x: Rep[mutable.TreeSet[M]]) extends Def[M] { val m = manifest[M] } - case class TreeSetSize[M:Manifest](x: Rep[mutable.TreeSet[M]]) extends Def[Int] { val m = manifest[M] } - - def newTreeSet[M: Manifest](x: (Exp[M],Exp[M])=>Exp[Int]) = { - val m = manifest[M] - val o1 = fresh[M] - val o2 = fresh[M] - val f = reifyEffects(x(o1,o2)) - reflectEffect(NewTreeSet[M](f, o1, o2), summarizeEffects(f).star) - } - def treeSetAdd[M: Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]): Rep[Unit] = reflectEffect(TreeSetAdd[M](x,s)) - def treeSetRemove[M: Manifest](x: Rep[mutable.TreeSet[M]], s: Rep[M]): Rep[Unit] = reflectEffect(TreeSetRemove[M](x,s)) - def treeSetHead[M: Manifest](x: Rep[mutable.TreeSet[M]]): Rep[M] = reflectEffect(TreeSetHead[M](x)) - def treeSetSize[M: Manifest](x: Rep[mutable.TreeSet[M]]) = reflectEffect(TreeSetSize[M](x)) - - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { - (e match { - case e@NewTreeSet(func,o1,o2) => reflectEffect(NewTreeSet(f(func),o1,o2)(e.m)) - case Reflect(e@TreeSetSize(t), u, es) => reflectMirrored(Reflect(TreeSetSize(f(t))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@TreeSetAdd(t,el), u, es) => reflectMirrored(Reflect(TreeSetAdd(f(t),f(el))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@TreeSetHead(t), u, es) => reflectMirrored(Reflect(TreeSetHead(f(t))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@TreeSetRemove(t,el), u, es) => reflectMirrored(Reflect(TreeSetRemove(f(t),f(el))(e.m), mapOver(f,u), f(es)))(mtype(manifest[A])) - case _ => super.mirror(e,f) - }).asInstanceOf[Exp[A]] // why?? - } - - override def boundSyms(e: Any): List[Sym[Any]] = e match { - case NewTreeSet(x,o1,o2) => o1::o2::effectSyms(x) - case _ => super.boundSyms(e) - } -} - -trait ScalaGenTreeSet extends ScalaGenBase with GenericNestedCodegen { - val IR: TreeSetExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case t@NewTreeSet(f,o1,o2) => { - val treeType = remap(t.m)//.replace("Array[","ArrayOf").replace("]","") - emitValDef(sym, "new scala.collection.mutable.TreeSet[" + treeType + "]()(") - stream.println("new Ordering[" + treeType + "] {") - stream.println(" def compare(" + quote(o1) + ": " + treeType + ", " + quote(o2) +": " + treeType + ") = { ") - emitBlock(f) - stream.println(quote(getBlockResult(f))) - stream.println("}})") - } - case TreeSetAdd(x,s) => emitValDef(sym, quote(x) + "+=" + quote(s)) - case TreeSetRemove(x,s) => emitValDef(sym, quote(x) + "-=" + quote(s)) - case TreeSetHead(x) => emitValDef(sym, quote(x) + ".head") - case TreeSetSize(x) => emitValDef(sym, quote(x) + ".size") - case _ => super.emitNode(sym, rhs) - } -} - -trait CGenTreeSet extends CGenBase with GenericNestedCodegen with CGenPointer { - val IR: TreeSetExp - import IR._ - - override def remap[A](m: Manifest[A]) = m match { - case s if m <:< manifest[mutable.TreeSet[Any]] => "GTree*" - case _ => super.remap(m) - } - - override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { - case NewTreeSet(f,s1,s2) => - LIRTraversal(f) - sym.atPhase(LIRLowering) { - reflectEffect(NewTreeSet(LIRLowering(f),s1,s2)).asInstanceOf[Exp[T]] - } - case _ => super.lowerNode(sym,rhs) - } - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case t@NewTreeSet(f,s1,s2) => - val ucf = uninlinedFunc2(s2,s1,f) - emitValDef(sym, "g_tree_new((GCompareFunc)" + quote(ucf) + ");") - case TreeSetAdd(x,s) => - emitValDef(sym, "g_tree_insert(" + quote(x) + "," + quote(s) + "," + quote(s) + ");") - case TreeSetSize(x) => emitValDef(sym, "g_tree_nnodes(" + quote(x) + ")") - case h@TreeSetHead(x) => { - def func[A,B](s1: Exp[A], s2: Exp[A], s3: Exp[B]): Exp[Int] = { - pointer_assign(s3,s2) - unit(0) - } - val ptr = getPointerManifest(h.m) - val ucf = uninlinedFunc3(func)(h.m,h.m,ptr.asInstanceOf[Manifest[Any]],manifest[Int]) - emitValDef(sym, "NULL") - stream.println("g_tree_foreach(" + quote(x) + ", (GTraverseFunc)" + quote(ucf) + ", &" + quote(sym) + ");") - } - case TreeSetRemove(x,s) => stream.println("g_tree_remove(" + quote(x) + "," + quote(s) + ");") - case _ => super.emitNode(sym, rhs) - } -} diff --git a/src/common/TupleOps.scala b/src/common/TupleOps.scala index 13089b8c..b8e6564d 100644 --- a/src/common/TupleOps.scala +++ b/src/common/TupleOps.scala @@ -1,19 +1,11 @@ package scala.lms package common -import scala.lms.common._ import scala.lms.internal.GenericCodegen -import scala.reflect.SourceContext - import java.io.PrintWriter - -/** - * Taken char-for-char from the delite-develop branch of lms - */ +import scala.reflect.SourceContext trait TupleOps extends Base { - val tuple_elems: Seq[String] - implicit def make_tuple2[A:Manifest,B:Manifest](t: (Rep[A], Rep[B]))(implicit pos: SourceContext) : Rep[(A,B)] implicit def make_tuple3[A:Manifest,B:Manifest,C:Manifest](t: (Rep[A], Rep[B], Rep[C]))(implicit pos: SourceContext) : Rep[(A,B,C)] implicit def make_tuple4[A:Manifest,B:Manifest,C:Manifest,D:Manifest](t: (Rep[A], Rep[B], Rep[C], Rep[D]))(implicit pos: SourceContext) : Rep[(A,B,C,D)] @@ -45,281 +37,49 @@ trait TupleOps extends Base { def tuple5_get3[C:Manifest](t: Rep[(_,_,C,_,_)])(implicit pos: SourceContext) : Rep[C] def tuple5_get4[D:Manifest](t: Rep[(_,_,_,D,_)])(implicit pos: SourceContext) : Rep[D] def tuple5_get5[E:Manifest](t: Rep[(_,_,_,_,E)])(implicit pos: SourceContext) : Rep[E] - def hashTuple2(t: Rep[(_,_)]): Rep[Int] - def compareTuple2(t1: Rep[(_,_)], t2: Rep[(_,_)]): Rep[Boolean] - def hashTuple3(t: Rep[(_,_,_)]): Rep[Int] - def compareTuple3(t1: Rep[(_,_,_)], t2: Rep[(_,_,_)]): Rep[Boolean] - def hashTuple5(t: Rep[(_,_,_,_,_)]): Rep[Int] - def compareTuple5(t1: Rep[(_,_,_,_,_)], t2: Rep[(_,_,_,_,_)]): Rep[Boolean] } -object TupleOpsGenType { var isCGen: scala.Boolean = false } - trait TupleOpsExp extends TupleOps with StructExpOpt { - case class ETuple2[A:Manifest,B:Manifest](_1: Exp[A],_2: Exp[B]) extends Def[(A,B)] { - val m1 = manifest[A] - val m2 = manifest[B] - } - case class ETuple3[A:Manifest,B:Manifest,C:Manifest](_1: Exp[A],_2: Exp[B],_3: Exp[C]) extends Def[(A,B,C)] { - val m1 = manifest[A] - val m2 = manifest[B] - val m3 = manifest[C] - } - case class ETuple4[A:Manifest,B:Manifest,C:Manifest,D:Manifest](_1: Exp[A],_2: Exp[B],_3: Exp[C],_4: Exp[D]) extends Def[(A,B,C,D)] { - val m1 = manifest[A] - val m2 = manifest[B] - val m3 = manifest[C] - val m4 = manifest[D] - } - case class ETuple5[A:Manifest,B:Manifest,C:Manifest,D:Manifest,E:Manifest](_1: Exp[A],_2: Exp[B],_3: Exp[C],_4: Exp[D],_5: Exp[E]) extends Def[(A,B,C,D,E)] { - val m1 = manifest[A] - val m2 = manifest[B] - val m3 = manifest[C] - val m4 = manifest[D] - val m5 = manifest[E] - } - - val tuple_elems: Seq[String] = List("_1", "_2", "_3", "_4", "_5") - - implicit def make_tuple2[A:Manifest,B:Manifest](t: (Exp[A],Exp[B]))(implicit pos: SourceContext) : Exp[(A,B)] = { - if (TupleOpsGenType.isCGen) struct(classTag[(A,B)], tuple_elems(0) -> t._1, tuple_elems(1) -> t._2) - else ETuple2(t._1, t._2) - } - implicit def make_tuple3[A:Manifest,B:Manifest,C:Manifest](t: (Exp[A],Exp[B],Exp[C]))(implicit pos: SourceContext) : Exp[(A,B,C)] = { - if (TupleOpsGenType.isCGen) struct(classTag[(A,B,C)], tuple_elems(0) -> t._1, tuple_elems(1) -> t._2, tuple_elems(2) -> t._3) - else ETuple3(t._1, t._2, t._3) - } - implicit def make_tuple4[A:Manifest,B:Manifest,C:Manifest,D:Manifest](t: (Exp[A],Exp[B],Exp[C],Exp[D]))(implicit pos: SourceContext) : Exp[(A,B,C,D)] = { - if (TupleOpsGenType.isCGen) struct(classTag[(A,B,C,D)], tuple_elems(0) -> t._1, tuple_elems(1) -> t._2, tuple_elems(2) -> t._3, tuple_elems(3) -> t._4) - else ETuple4(t._1, t._2, t._3, t._4) - } - implicit def make_tuple5[A:Manifest,B:Manifest,C:Manifest,D:Manifest,E:Manifest](t: (Exp[A],Exp[B],Exp[C],Exp[D],Exp[E]))(implicit pos: SourceContext) : Exp[(A,B,C,D,E)] = { - if (TupleOpsGenType.isCGen) struct(classTag[(A,B,C,D,E)], tuple_elems(0) -> t._1, tuple_elems(1) -> t._2, tuple_elems(2) -> t._3, tuple_elems(3) -> t._4, tuple_elems(4) -> t._5) - else ETuple5(t._1, t._2, t._3, t._4, t._5) - } - - def hashTuple2(t: Rep[(_,_)]): Rep[Int] = reflectEffect(HashTuple2(t)) - def compareTuple2(t1: Rep[(_,_)], t2: Rep[(_,_)]): Rep[Boolean] = reflectEffect(CompareTuple2(t1,t2)) - def hashTuple3(t: Rep[(_,_,_)]): Rep[Int] = reflectEffect(HashTuple3(t)) - def compareTuple3(t1: Rep[(_,_,_)], t2: Rep[(_,_,_)]): Rep[Boolean] = reflectEffect(CompareTuple3(t1,t2)) - def hashTuple5(t: Rep[(_,_,_,_,_)]): Rep[Int] = reflectEffect(HashTuple5(t)) - def compareTuple5(t1: Rep[(_,_,_,_,_)], t2: Rep[(_,_,_,_,_)]): Rep[Boolean] = reflectEffect(CompareTuple5(t1,t2)) - case class Tuple2Access1[A:Manifest](t: Exp[(A,_)]) extends Def[A] { val m = manifest[A] } - case class Tuple2Access2[B:Manifest](t: Exp[(_,B)]) extends Def[B] { val m = manifest[B] } - case class Tuple3Access1[A:Manifest](t: Exp[(A,_,_)]) extends Def[A] { val m = manifest[A] } - case class Tuple3Access2[B:Manifest](t: Exp[(_,B,_)]) extends Def[B] { val m = manifest[B] } - case class Tuple3Access3[C:Manifest](t: Exp[(_,_,C)]) extends Def[C] { val m = manifest[C] } - case class Tuple4Access1[A:Manifest](t: Exp[(A,_,_,_)]) extends Def[A] { val m = manifest[A] } - case class Tuple4Access2[B:Manifest](t: Exp[(_,B,_,_)]) extends Def[B] { val m = manifest[B] } - case class Tuple4Access3[C:Manifest](t: Exp[(_,_,C,_)]) extends Def[C] { val m = manifest[C] } - case class Tuple4Access4[D:Manifest](t: Exp[(_,_,_,D)]) extends Def[D] { val m = manifest[D] } - case class Tuple5Access1[A:Manifest](t: Exp[(A,_,_,_,_)]) extends Def[A] { val m = manifest[A] } - case class Tuple5Access2[B:Manifest](t: Exp[(_,B,_,_,_)]) extends Def[B] { val m = manifest[B] } - case class Tuple5Access3[C:Manifest](t: Exp[(_,_,C,_,_)]) extends Def[C] { val m = manifest[C] } - case class Tuple5Access4[D:Manifest](t: Exp[(_,_,_,D,_)]) extends Def[D] { val m = manifest[D] } - case class Tuple5Access5[E:Manifest](t: Exp[(_,_,_,_,E)]) extends Def[E] { val m = manifest[E] } - case class HashTuple2(t: Exp[(_,_)]) extends Def[Int] - case class CompareTuple2(t1: Exp[(_,_)], t2: Exp[(_,_)]) extends Def[Boolean] - case class HashTuple3(t: Exp[(_,_,_)]) extends Def[Int] - case class CompareTuple3(t1: Exp[(_,_,_)], t2: Exp[(_,_,_)]) extends Def[Boolean] - case class HashTuple5(t: Exp[(_,_,_,_,_)]) extends Def[Int] - case class CompareTuple5(t1: Exp[(_,_,_,_,_)], t2: Exp[(_,_,_,_,_)]) extends Def[Boolean] + implicit def make_tuple2[A:Manifest,B:Manifest](t: (Exp[A],Exp[B]))(implicit pos: SourceContext) : Exp[(A,B)] = struct(classTag[(A,B)], "_1" -> t._1, "_2" -> t._2) + implicit def make_tuple3[A:Manifest,B:Manifest,C:Manifest](t: (Exp[A],Exp[B],Exp[C]))(implicit pos: SourceContext) : Exp[(A,B,C)] = struct(classTag[(A,B,C)], "_1" -> t._1, "_2" -> t._2, "_3" -> t._3) + implicit def make_tuple4[A:Manifest,B:Manifest,C:Manifest,D:Manifest](t: (Exp[A],Exp[B],Exp[C],Exp[D]))(implicit pos: SourceContext) : Exp[(A,B,C,D)] = struct(classTag[(A,B,C,D)], "_1" -> t._1, "_2" -> t._2, "_3" -> t._3, "_4" -> t._4) + implicit def make_tuple5[A:Manifest,B:Manifest,C:Manifest,D:Manifest,E:Manifest](t: (Exp[A],Exp[B],Exp[C],Exp[D],Exp[E]))(implicit pos: SourceContext) : Exp[(A,B,C,D,E)] = struct(classTag[(A,B,C,D,E)], "_1" -> t._1, "_2" -> t._2, "_3" -> t._3, "_4" -> t._4, "_5" -> t._5) - def tuple2_get1[A:Manifest](t: Exp[(A,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple2(a,b)) => a - case _ => - field[A](t, tuple_elems(0)) - } - def tuple2_get2[B:Manifest](t: Exp[(_,B)])(implicit pos: SourceContext) = t match { - case Def(ETuple2(a,b)) => b - case _ => - field[B](t, tuple_elems(1)) - } + def tuple2_get1[A:Manifest](t: Exp[(A,_)])(implicit pos: SourceContext) = field[A](t, "_1") + def tuple2_get2[B:Manifest](t: Exp[(_,B)])(implicit pos: SourceContext) = field[B](t, "_2") - def tuple3_get1[A:Manifest](t: Exp[(A,_,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple3(a,b,c)) => a - case _ => - field[A](t, tuple_elems(0)) - } - def tuple3_get2[B:Manifest](t: Exp[(_,B,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple3(a,b,c)) => b - case _ => - field[B](t, tuple_elems(1)) - } - def tuple3_get3[C:Manifest](t: Exp[(_,_,C)])(implicit pos: SourceContext) = t match { - case Def(ETuple3(a,b,c)) => c - case _ => - field[C](t, tuple_elems(2)) - } + def tuple3_get1[A:Manifest](t: Exp[(A,_,_)])(implicit pos: SourceContext) = field[A](t, "_1") + def tuple3_get2[B:Manifest](t: Exp[(_,B,_)])(implicit pos: SourceContext) = field[B](t, "_2") + def tuple3_get3[C:Manifest](t: Exp[(_,_,C)])(implicit pos: SourceContext) = field[C](t, "_3") - def tuple4_get1[A:Manifest](t: Exp[(A,_,_,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple4(a,b,c,d)) => a - case _ => - field[A](t, tuple_elems(0)) - } - def tuple4_get2[B:Manifest](t: Exp[(_,B,_,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple4(a,b,c,d)) => b - case _ => - field[B](t, tuple_elems(1)) - } - def tuple4_get3[C:Manifest](t: Exp[(_,_,C,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple4(a,b,c,d)) => c - case _ => - field[C](t, tuple_elems(2)) - } - def tuple4_get4[D:Manifest](t: Exp[(_,_,_,D)])(implicit pos: SourceContext) = t match { - case Def(ETuple4(a,b,c,d)) => d - case _ => - field[D](t, tuple_elems(3)) - } + def tuple4_get1[A:Manifest](t: Exp[(A,_,_,_)])(implicit pos: SourceContext) = field[A](t, "_1") + def tuple4_get2[B:Manifest](t: Exp[(_,B,_,_)])(implicit pos: SourceContext) = field[B](t, "_2") + def tuple4_get3[C:Manifest](t: Exp[(_,_,C,_)])(implicit pos: SourceContext) = field[C](t, "_3") + def tuple4_get4[D:Manifest](t: Exp[(_,_,_,D)])(implicit pos: SourceContext) = field[D](t, "_4") - def tuple5_get1[A:Manifest](t: Exp[(A,_,_,_,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple5(a,b,c,d,e)) => a - case _ => - field[A](t, tuple_elems(0)) - } - def tuple5_get2[B:Manifest](t: Exp[(_,B,_,_,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple5(a,b,c,d,e)) => b - case _ => - field[B](t, tuple_elems(1)) - } - def tuple5_get3[C:Manifest](t: Exp[(_,_,C,_,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple5(a,b,c,d,e)) => c - case _ => - field[C](t, tuple_elems(2)) - } - def tuple5_get4[D:Manifest](t: Exp[(_,_,_,D,_)])(implicit pos: SourceContext) = t match { - case Def(ETuple5(a,b,c,d,e)) => d - case _ => - field[D](t, tuple_elems(3)) - } - def tuple5_get5[E:Manifest](t: Exp[(_,_,_,_,E)])(implicit pos: SourceContext) = t match { - case Def(ETuple5(a,b,c,d,e)) => e - case _ => - field[E](t, tuple_elems(4)) - } + def tuple5_get1[A:Manifest](t: Exp[(A,_,_,_,_)])(implicit pos: SourceContext) = field[A](t, "_1") + def tuple5_get2[B:Manifest](t: Exp[(_,B,_,_,_)])(implicit pos: SourceContext) = field[B](t, "_2") + def tuple5_get3[C:Manifest](t: Exp[(_,_,C,_,_)])(implicit pos: SourceContext) = field[C](t, "_3") + def tuple5_get4[D:Manifest](t: Exp[(_,_,_,D,_)])(implicit pos: SourceContext) = field[D](t, "_4") + def tuple5_get5[E:Manifest](t: Exp[(_,_,_,_,E)])(implicit pos: SourceContext) = field[E](t, "_5") object Both { def unapply[T](x:T):Some[(T,T)] = Some((x,x)) } - - override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case e@ETuple2(a,b) => make_tuple2(f(a),f(b))(e.m1,e.m2,pos) - case e@Tuple2Access1(t) => tuple2_get1(f(t))(mtype(e.m),pos) - case e@Tuple2Access2(t) => tuple2_get2(f(t))(mtype(e.m),pos) - case Reflect(e@Tuple2Access1(t), u, es) => reflectMirrored(Reflect(Tuple2Access1(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple2Access2(t), u, es) => reflectMirrored(Reflect(Tuple2Access2(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - - case e@ETuple3(a,b,c) => make_tuple3(f(a),f(b),f(c))(e.m1,e.m2,e.m3,pos) - case e@Tuple3Access1(t) => tuple3_get1(f(t))(mtype(e.m),pos) - case e@Tuple3Access2(t) => tuple3_get2(f(t))(mtype(e.m),pos) - case e@Tuple3Access3(t) => tuple3_get3(f(t))(mtype(e.m),pos) - case Reflect(e@Tuple3Access1(t), u, es) => reflectMirrored(Reflect(Tuple3Access1(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple3Access2(t), u, es) => reflectMirrored(Reflect(Tuple3Access2(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple3Access3(t), u, es) => reflectMirrored(Reflect(Tuple3Access3(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - - case e@ETuple4(a,b,c,d) => make_tuple4(f(a),f(b),f(c),f(d))(e.m1,e.m2,e.m3,e.m4,pos) - case e@Tuple4Access1(t) => tuple4_get1(f(t))(mtype(e.m),pos) - case e@Tuple4Access2(t) => tuple4_get2(f(t))(mtype(e.m),pos) - case e@Tuple4Access3(t) => tuple4_get3(f(t))(mtype(e.m),pos) - case e@Tuple4Access4(t) => tuple4_get4(f(t))(mtype(e.m),pos) - case Reflect(e@Tuple4Access1(t), u, es) => reflectMirrored(Reflect(Tuple4Access1(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple4Access2(t), u, es) => reflectMirrored(Reflect(Tuple4Access2(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple4Access3(t), u, es) => reflectMirrored(Reflect(Tuple4Access3(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple4Access4(t), u, es) => reflectMirrored(Reflect(Tuple4Access4(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - - case e@ETuple5(a,b,c,d,g) => make_tuple5(f(a),f(b),f(c),f(d),f(g))(e.m1,e.m2,e.m3,e.m4,e.m5,pos) - case e@Tuple5Access1(t) => tuple5_get1(f(t))(mtype(e.m),pos) - case e@Tuple5Access2(t) => tuple5_get2(f(t))(mtype(e.m),pos) - case e@Tuple5Access3(t) => tuple5_get3(f(t))(mtype(e.m),pos) - case e@Tuple5Access4(t) => tuple5_get4(f(t))(mtype(e.m),pos) - case e@Tuple5Access5(t) => tuple5_get5(f(t))(mtype(e.m),pos) - case Reflect(e@Tuple5Access1(t), u, es) => reflectMirrored(Reflect(Tuple5Access1(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple5Access2(t), u, es) => reflectMirrored(Reflect(Tuple5Access2(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple5Access3(t), u, es) => reflectMirrored(Reflect(Tuple5Access3(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple5Access4(t), u, es) => reflectMirrored(Reflect(Tuple5Access4(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@Tuple5Access5(t), u, es) => reflectMirrored(Reflect(Tuple5Access5(f(t))(mtype(e.m)), mapOver(f,u), f(es)))(mtype(manifest[A])) - - case _ => super.mirror(e,f) - }).asInstanceOf[Exp[A]] -} - -trait TupleGenBase extends GenericCodegen with BaseGenStruct { val IR: TupleOpsExp } - -trait ScalaGenTupleOps extends ScalaGenBase with TupleGenBase { - val IR: TupleOpsExp - import IR._ - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case ETuple2(a,b) => - emitValDef(sym, src"($a,$b)") - case Tuple2Access1(t) => emitValDef(sym, src"$t._1") - case Tuple2Access2(t) => emitValDef(sym, src"$t._2") - - case ETuple3(a,b,c) => - emitValDef(sym, src"($a,$b,$c)") - case Tuple3Access1(t) => emitValDef(sym, src"$t._1") - case Tuple3Access2(t) => emitValDef(sym, src"$t._2") - case Tuple3Access3(t) => emitValDef(sym, src"$t._3") - - case ETuple4(a,b,c,d) => - emitValDef(sym, src"($a,$b,$c,$d)") - case Tuple4Access1(t) => emitValDef(sym, src"$t._1") - case Tuple4Access2(t) => emitValDef(sym, src"$t._2") - case Tuple4Access3(t) => emitValDef(sym, src"$t._3") - case Tuple4Access4(t) => emitValDef(sym, src"$t._4") - - case ETuple5(a,b,c,d,e) => - emitValDef(sym, src"($a,$b,$c,$d,$e)") - case Tuple5Access1(t) => emitValDef(sym, src"$t._1") - case Tuple5Access2(t) => emitValDef(sym, src"$t._2") - case Tuple5Access3(t) => emitValDef(sym, src"$t._3") - case Tuple5Access4(t) => emitValDef(sym, src"$t._4") - case Tuple5Access5(t) => emitValDef(sym, src"$t._5") - - case _ => super.emitNode(sym, rhs) - } - - -/* override def remap[A](m: Manifest[A]) = m.runtimeClass.getSimpleName match { - case "Tuple2" => "Tuple2" + m.typeArguments.foldLeft("")((x,y) => x + remap(y).toString).replace("Array[","ArrayOf").replace("]","") - case "Tuple3" => "Tuple3" + m.typeArguments.foldLeft("")((x,y) => x + remap(y).toString).replace("Array[","ArrayOf").replace("]","") - case "Tuple4" => "Tuple4" + m.typeArguments.foldLeft("")((x,y) => x + remap(y).toString).replace("Array[","ArrayOf").replace("]","") - case "Tuple5" => "Tuple5" + m.typeArguments.foldLeft("")((x,y) => x + remap(y).toString).replace("Array[","ArrayOf").replace("]","") - case _ => super.remap(m) - }*/ } -trait CGenTupleOps extends CGenBase with TupleGenBase with CGenStruct { +trait TupleGenBase extends GenericCodegen with BaseGenStruct { val IR: TupleOpsExp - import IR._ - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case HashTuple2(t) => emitValDef(sym, "(int)" + quote(t) + "->_1 + (int)" + quote(t) + "->_2;") - case CompareTuple2(t1,t2) => emitValDef(sym, quote(t1) + "->_1 == " + quote(t2) + "->_1 && " + quote(t1) + "->_2 == " + quote(t2) + "->_2;") - case HashTuple3(t) => emitValDef(sym, "(int)" + quote(t) + "->_1 + (int)" + quote(t) + "->_2 + (int)" + quote(t) + "->_3;") - case CompareTuple3(t1,t2) => emitValDef(sym, quote(t1) + "->_1 == " + quote(t2) + "->_1 && " + quote(t1) + "->_2 == " + quote(t2) + "->_2 && " + quote(t1) + "->_3 == " + quote(t2) + "->_3;") - case HashTuple5(t) => emitValDef(sym, "(int)" + quote(t) + "->_1 + (int)" + quote(t) + "->_2 + (int)" + quote(t) + "->_3 + (int)" + quote(t) + "->_4 + (int)" + quote(t) + "->_5;") - case CompareTuple5(t1,t2) => emitValDef(sym, quote(t1) + "->_1 == " + quote(t2) + "->_1 && " + quote(t1) + "->_2 == " + quote(t2) + "->_2 && " + quote(t1) + "->_3 == " + quote(t2) + "->_3 && " + quote(t1) + "->_4 == " + quote(t2) + "->_4 && " + quote(t1) + "->_5 == " + quote(t2) + "->_5;") - case _ => super.emitNode(sym, rhs) - } - - override def remap[A](m: Manifest[A]) = m.runtimeClass.getSimpleName match { - case "Tuple2" => - val elems = IR.tuple_elems.take(2) zip m.typeArguments - IR.registerStruct(IR.structName(m), elems) - IR.structName(m) + "*" - case "Tuple3" => - val elems = IR.tuple_elems.take(3) zip m.typeArguments - IR.registerStruct(IR.structName(m), elems) - IR.structName(m) + "*" - case "Tuple4" => - val elems = IR.tuple_elems.take(4) zip m.typeArguments - IR.registerStruct(IR.structName(m), elems) - IR.structName(m) + "*" - case "Tuple5" => - val elems = IR.tuple_elems.take(5) zip m.typeArguments - IR.registerStruct(IR.structName(m), elems) - IR.structName(m) + "*" + override def remap[A](m: Manifest[A]) = m.erasure.getSimpleName match { + case "Tuple2" => IR.structName(m) + case "Tuple3" => IR.structName(m) + case "Tuple4" => IR.structName(m) + case "Tuple5" => IR.structName(m) case _ => super.remap(m) } } + +trait ScalaGenTupleOps extends ScalaGenBase with TupleGenBase with ScalaGenStruct { val IR: TupleOpsExp } +trait CGenTupleOps extends CGenBase with TupleGenBase with CGenStruct +trait CudaGenTupleOps extends CudaGenBase with TupleGenBase with CudaGenStruct +trait OpenCLGenTupleOps extends OpenCLGenBase with TupleGenBase with OpenCLGenStruct diff --git a/src/common/UninlinedFunctions.scala b/src/common/UninlinedFunctions.scala deleted file mode 100644 index 5f97df6a..00000000 --- a/src/common/UninlinedFunctions.scala +++ /dev/null @@ -1,299 +0,0 @@ -/*package scala.lms -package common - -import java.io.PrintWriter -import java.io.StringWriter -import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException} -import scala.lms.util.ClosureCompare - -import scala.reflect.SourceContext - -trait UninlinedFunctions extends Base { - implicit def toUninlinedFuncOps0[B:Manifest](fun: Rep[()=>B]) = new UninlinedFuncOps0(fun) - implicit def toUninlinedFuncOps1[A:Manifest,B:Manifest](fun: Rep[A=>B]) = new UninlinedFuncOps1(fun) - implicit def toUninlinedFuncOps2[A1:Manifest,A2:Manifest,B:Manifest](fun: Rep[(A1,A2)=>B]) = new UninlinedFuncOps2(fun) - - class UninlinedFuncOps0[B:Manifest](f: Rep[()=>B]) { - def apply()(implicit pos: SourceContext): Rep[B] = uninlinedFuncApply(f) - } - class UninlinedFuncOps1[A:Manifest,B:Manifest](f: Rep[A=>B]) { - def apply(x: Rep[A])(implicit pos: SourceContext): Rep[B] = uninlinedFuncApply(f,x) - } - class UninlinedFuncOps2[A1:Manifest,A2:Manifest,B:Manifest](f: Rep[(A1,A2)=>B]) { - def apply(x: Rep[A1], y: Rep[A2])(implicit pos: SourceContext): Rep[B] = uninlinedFuncApply(f,x,y) - } - - def createUninlinedFunc0[B:Manifest](fun: () => Rep[B], dRet: String = "", si: () => Rep[Unit] = null)(implicit pos: SourceContext): Rep[()=>B] - def createUninlinedFunc1[A:Manifest,B:Manifest](fun: Rep[A] => Rep[B], argType: String = "", dRet: String = "", si: () => Rep[Unit] = null)(implicit pos: SourceContext): Rep[A=>B] - def createUninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](fun: (Rep[A1],Rep[A2]) => Rep[B], argType: String = "", argType2: String = "", dRet: String = "", si: () => Rep[Unit] = null)(implicit pos: SourceContext): Rep[(A1,A2)=>B] - def uninlinedFuncApply[B:Manifest](fun: Rep[() => B])(implicit pos: SourceContext): Rep[B] - def uninlinedFuncApply[A:Manifest,B:Manifest](fun: Rep[A => B], arg: Rep[A])(implicit pos: SourceContext): Rep[B] - def uninlinedFuncApply[A1:Manifest,A2:Manifest,B:Manifest](fun: Rep[(A1,A2)=>B], arg: Rep[A1], arg2: Rep[A2])(implicit pos: SourceContext): Rep[B] -} - -trait UninlinedFunctionsExp extends UninlinedFunctions with BaseExp with EffectExp { - val functionList0 = new scala.collection.mutable.ListBuffer[UninlinedFunc0[_]]() - val functionList1 = new scala.collection.mutable.ListBuffer[UninlinedFunc1[_,_]]() - val functionList2 = new scala.collection.mutable.ListBuffer[UninlinedFunc2[_,_,_]]() - - // UninlinedFunc generates nothing, but is saved in the list and is later printed in the preamble - // of the file of the generated code - case class UninlinedFunc0[B:Manifest](f: () => Exp[B], y:Sym[B], dRet:String = "", si: () => Exp[Unit]) extends Def[()=>B] - case class UninlinedFunc1[A:Manifest,B:Manifest](f: Exp[A] => Exp[B], x: Sym[A], y:Sym[B], dynamicType: String, dRet:String = "", si: () => Exp[Unit]) extends Def[A=>B] - case class UninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](f: (Exp[A1],Exp[A2]) => Exp[B], x: Sym[A1], y: Sym[A2], z: Sym[B], argType: String = "", argType2: String = "", dRet:String = "", si: () => Exp[Unit]) extends Def[(A1,A2)=>B] - case class UninlinedFuncApply0[B:Manifest](f: Exp[() => B]) extends Def[B] - case class UninlinedFuncApply1[A:Manifest,B:Manifest](f: Exp[A => B], arg: Exp[A]) extends Def[B] - case class UninlinedFuncApply2[A1:Manifest,A2:Manifest,B:Manifest](f: Exp[(A1,A2) => B], arg: Exp[A1], arg2: Exp[A2]) extends Def[B] - - // si stands for State Initializer - override def createUninlinedFunc0[B:Manifest](f: () => Exp[B], dRet: String = "", si: () => Exp[Unit] = null)(implicit pos: SourceContext): Exp[()=>B] = { - val res = fresh[B] // overcomes the fact that the list has B = Any - val l = UninlinedFunc0(f, res, dRet, si) - functionList0 += l - l - } - override def createUninlinedFunc1[A:Manifest,B:Manifest](f: Exp[A] => Exp[B], argType: String = "", dRet: String = "", si: () => Exp[Unit] = null)(implicit pos: SourceContext): Exp[A=>B] = { - val e = fresh[A] - val res = fresh[B] // overcomes the fact that the list has B = Any - val l = UninlinedFunc1(f, e, res, argType, dRet, si) - functionList1 += l - l - } - override def createUninlinedFunc2[A1:Manifest,A2:Manifest,B:Manifest](f: (Exp[A1],Exp[A2]) => Exp[B], argType: String = "", argType2: String = "", dRet: String = "", si: () => Exp[Unit] = null)(implicit pos: SourceContext): Exp[(A1,A2)=>B] = { - val e1 = fresh[A1] - val e2 = fresh[A2] - val res = fresh[B] // overcomes the fact that the list has B = Any - val l = UninlinedFunc2(f, e1, e2, res, argType, argType2, dRet, si) - functionList2 += l - l - } - - def uninlinedFuncApply[B:Manifest](f: Exp[()=>B])(implicit pos: SourceContext): Exp[B] = { - reflectEffect(UninlinedFuncApply0(f)) - } - def uninlinedFuncApply[A:Manifest,B:Manifest](f: Exp[A=>B], x: Exp[A])(implicit pos: SourceContext): Exp[B] = { - reflectEffect(UninlinedFuncApply1(f, x)) - } - def uninlinedFuncApply[A1:Manifest,A2:Manifest,B:Manifest](f: Exp[(A1,A2)=>B], x1: Exp[A1], x2: Exp[A2])(implicit pos: SourceContext): Exp[B] = { - reflectEffect(UninlinedFuncApply2(f, x1, x2)) - } -} - -trait ScalaGenUninlinedFunctions extends ScalaGenEffect { - val IR: UninlinedFunctionsExp - import IR._ - - var emitEnabled: Boolean = false - - private def printState(si: () => Exp[Unit]) { - // Print state if si is set - if (si != null) { - val state = reifyEffects(si()) - emitBlock(state) - } - } - - private def argsToStr(e: List[Sym[Any]], argTypes: List[String]) = { - val z = e zip argTypes - z.map(x => { - if (quote(x._1) != "") quote(x._1) + ": " + x._2 - else "x" + x._1.toString.replace("Sym(","").replace(")","") + ": " + x._2 - }).mkString(",") - } - - private def printUninlinedFuncBody[T:Manifest](b: Block[T]) { - emitBlock(b) - stream.println(quote(getBlockResult(b))) - stream.println("}") - stream.println("}") - stream.println() - } - - private def getArgTypes(syms: List[Sym[Any]], args: String*) = { - val z = syms zip args.toList - z.map(x => if (x._2 != "") x._2 else remap(x._1.tp)) - } - - private def getReturnType(res: Sym[Any], dRet: String) = if (dRet != "") dRet else remap(res.tp) - - override def emitFileHeader() = { - emitEnabled = true - functionList0.foreach(func => traverseStm(findDefinition(func).get)) - functionList1.foreach(func => traverseStm(findDefinition(func).get)) - functionList2.foreach(func => traverseStm(findDefinition(func).get)) - emitEnabled = false - functionList0.clear - functionList1.clear - functionList2.clear - } - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case UninlinedFunc0(fun, res, dRet, si) => { - if (emitEnabled) { - val retType = getReturnType(res, dRet) - stream.println("object " + quote(sym) - + " extends (()=>" + retType +") {") - emitEnabled = false - printState(si) - // Now print function - val f = reifyEffects(fun()) - stream.println("def apply(): " + retType + " = {") - printUninlinedFuncBody(f) - emitEnabled = true - } - } - case UninlinedFunc1(fun, e, res, argType, dRet, si) => { - if (emitEnabled) { - val syms = List(e) - val argTypes = getArgTypes(syms, argType) - val retType = getReturnType(res, dRet) - stream.println("object " + quote(sym) - + " extends ((" + argTypes.mkString(",") + ")=>" + retType +") {") - emitEnabled = false - printState(si) - // Now print function - stream.println("def apply(" + argsToStr(syms, argTypes) + "): " + retType + " = {") - printUninlinedFuncBody(reifyEffects(fun(e))) - emitEnabled = true - } - } - case UninlinedFunc2(fun, e1, e2, res, argType, argType2, dRet, si) => { - if (emitEnabled) { - val syms = List(e1,e2) - val argTypes = getArgTypes(syms,argType,argType2) - val retType = getReturnType(res, dRet) - stream.println("object " + quote(sym) - + " extends ((" + argTypes.mkString(",") + ")=>" + retType +") {") - emitEnabled = false - printState(si) - // Now print function - stream.println("def apply(" + argsToStr(syms, argTypes) + "): " + retType + " = {") - printUninlinedFuncBody(reifyEffects(fun(e1,e2))) - emitEnabled = true - } - } - case UninlinedFuncApply0(fun) => - emitValDef(sym, quote(fun) + "()") - case UninlinedFuncApply1(fun, arg) => - emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") - case UninlinedFuncApply2(fun, arg, arg2) => - emitValDef(sym, quote(fun) + "(" + quote(arg) + ", " + quote(arg2) + ")") - - case _ => super.emitNode(sym, rhs) - } -} - -trait CGenUninlinedFunctions extends CGenEffect { - val IR: UninlinedFunctionsExp - import IR._ - - var emitEnabled: Boolean = false - - private def printState(si: () => Exp[Unit]) { - // Print state if si is set - if (si != null) { - val state = reifyEffects(si()) - emitBlock(state) - } - } - - private def argsToStr(e: List[Sym[Any]], argTypes: List[String]) = { - val z = e zip argTypes - z.map(x => { - if (quote(x._1) != "") x._2 + " " + quote(x._1) - else x._2 + " x" + x._1.toString.replace("Sym(","").replace(")","") - }).mkString(",") - } - - private def printUninlinedFuncBody[T:Manifest](b: Block[T]) = { - val sw = new StringWriter() - val pw = new PrintWriter(sw) - withStream(pw) { - emitBlock(b) - stream.println("return " + quote(getBlockResult(b)) + ";") - stream.println("}") - stream.println() - } - sw.toString - } - - private def getArgTypes(syms: List[Sym[Any]], args: String*) = { - val z = syms zip args.toList - z.map(x => if (x._2 != "") x._2 else remap(x._1.tp)) - } - - private def getReturnType(res: Sym[Any], dRet: String) = if (dRet != "") dRet else remap(res.tp) - - override def emitFileHeader() = { - emitEnabled = true - functionList0.foreach(func => traverseStm(findDefinition(func).get)) - functionList1.foreach(func => traverseStm(findDefinition(func).get)) - functionList2.foreach(func => traverseStm(findDefinition(func).get)) - emitEnabled = false - functionList0.clear - functionList1.clear - functionList2.clear - } - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case UninlinedFunc0(fun, res, dRet, si) => { - if (emitEnabled) { - val retType = getReturnType(res, dRet) - stream.println("object " + quote(sym) - + " extends (()=>" + retType +") {") - emitEnabled = false - printState(si) - // Now print function - stream.println("def apply(): " + retType + " = {") - printUninlinedFuncBody(reifyEffects(fun())) - emitEnabled = true - } - } - case UninlinedFunc1(fun, e, res, argType, dRet, si) => { - if (emitEnabled) { - val syms = List(e) - val argTypes = getArgTypes(syms, argType) - val retType = getReturnType(res, dRet) - emitEnabled = false - printState(si) - // Now print function - val argStr = argsToStr(syms, argTypes) - val header = retType + " " + quote(sym) + "(" + argStr + ") {\n" - var str = header + printUninlinedFuncBody(reifyEffects(fun(e))) - if (e.tp == manifest[Tuple2[Any,Any]]) { - str = str.replace(quote(e) + "._1", "key").replace(quote(e) + "._2", "value") - str = str.replace(argStr,"void* key, void* value") - } - stream.println(str) - emitEnabled = true - } - } - case UninlinedFunc2(fun, e1, e2, res, argType, argType2, dRet, si) => { - if (emitEnabled) { - val syms = List(e1,e2) - val argTypes = getArgTypes(syms,argType,argType2) - val retType = getReturnType(res, dRet) - emitEnabled = false - printState(si) - // Now print function - stream.println(retType + " " + quote(sym) + "(" + argsToStr(syms, argTypes) + ") {") - var str = printUninlinedFuncBody(reifyEffects(fun(e1,e2))) - // HACK -- STUPID GLIB! - if (argType.contains("**")) { - str = str.replace(quote(e1),"(*" + quote(e1) + ")") - str = str.replace(quote(e2),"(*" + quote(e2) + ")") - } - stream.println(str) - emitEnabled = true - } - } - case UninlinedFuncApply0(fun) => - emitValDef(sym, quote(fun) + "()") - case UninlinedFuncApply1(fun, arg) => - emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") - case UninlinedFuncApply2(fun, arg, arg2) => - emitValDef(sym, quote(fun) + "(" + quote(arg) + ", " + quote(arg2) + ")") - - case _ => super.emitNode(sym, rhs) - } -}*/ From f0a797c7da3c44b3d54393f9e73f03cac0851859 Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Mon, 19 Dec 2016 22:49:54 -0500 Subject: [PATCH 05/10] HashMapOps --- src/common/HashMapOps.scala | 266 ++++++------------------------------ 1 file changed, 39 insertions(+), 227 deletions(-) diff --git a/src/common/HashMapOps.scala b/src/common/HashMapOps.scala index f425616d..a0db7999 100644 --- a/src/common/HashMapOps.scala +++ b/src/common/HashMapOps.scala @@ -2,21 +2,17 @@ package scala.lms package common import java.io.PrintWriter -import java.io.StringWriter import scala.lms.internal._ -import scala.collection.mutable.{HashMap,Set} +import scala.collection.mutable.Set +import java.util.HashMap import scala.reflect.SourceContext -trait HashMapOps extends Base with Variables with TupleOps { +trait HashMapOps extends Base { object HashMap { def apply[K:Manifest,V:Manifest]()(implicit pos: SourceContext) = hashmap_new[K,V]() - def apply[K:Manifest,V:Manifest](hash: Rep[K] => Rep[Int], equals: (Rep[K],Rep[K])=>Rep[Boolean])(implicit pos: SourceContext) = - hashmap_new[K,V](hash, equals) } - - implicit def HashMapToRepHashMapOps[K:Manifest,V:Manifest](m: HashMap[K,V]) = new hashmapOpsCls[K,V](unit(m)) - implicit def repHashMapToHashMapOps[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) = new hashmapOpsCls[K,V](m) - implicit def varrepHashMapToHashMapOps[K:Manifest,V:Manifest](m: Var[HashMap[K,V]]) = new hashmapOpsCls[K,V](readVar(m)) + + implicit def repHashMapToHashMapOps[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) = new hashmapOpsCls(m) class hashmapOpsCls[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]]) { def apply(k: Rep[K])(implicit pos: SourceContext) = hashmap_apply(m, k) @@ -24,152 +20,67 @@ trait HashMapOps extends Base with Variables with TupleOps { def contains(k: Rep[K])(implicit pos: SourceContext) = hashmap_contains(m, k) def size(implicit pos: SourceContext) = hashmap_size(m) def values(implicit pos: SourceContext) = hashmap_values(m) - def map[B:Manifest](f: Rep[(K,V)] => Rep[B]) = hashmap_map(m,f) - def foreach(block: Rep[(K,V)] => Rep[Unit])(implicit pos: SourceContext) = hashmap_foreach(m, block) def clear()(implicit pos: SourceContext) = hashmap_clear(m) def keySet(implicit pos: SourceContext) = hashmap_keyset(m) def keys(implicit pos: SourceContext) = hashmap_keys(m) - def head(implicit pos: SourceContext) = hashmap_head(m) - def removeHead(implicit pos:SourceContext) = hashmap_removehead(m) - def getOrElseUpdate(k: Rep[K], v: => Rep[V])(implicit pos: SourceContext) = hashmap_getorelseupdate[K,V](m,k,v) - def remove(v: Rep[K])(implicit pos:SourceContext) = hashmap_remove[K,V](m,v) - def mkString(delimiter: Rep[String]) = hashmap_mkString(m, delimiter) } - def hashmap_new[K:Manifest,V:Manifest]() : Rep[HashMap[K,V]] - def hashmap_new[K:Manifest,V:Manifest](hash: Rep[K] => Rep[Int], equals: (Rep[K],Rep[K])=>Rep[Boolean]) : Rep[HashMap[K,V]] + def hashmap_new[K:Manifest,V:Manifest]()(implicit pos: SourceContext) : Rep[HashMap[K,V]] def hashmap_apply[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K])(implicit pos: SourceContext): Rep[V] def hashmap_update[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext): Rep[Unit] def hashmap_unsafe_update[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: Rep[V])(implicit pos: SourceContext): Rep[Unit] def hashmap_contains[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], i: Rep[K])(implicit pos: SourceContext): Rep[Boolean] def hashmap_size[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Int] def hashmap_values[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Iterable[V]] - def hashmap_map[K:Manifest,V:Manifest,B:Manifest](m: Rep[HashMap[K,V]], f: Rep[(K,V)]=>Rep[B]): Rep[HashMap[K,B]] - def hashmap_foreach[K:Manifest,V:Manifest](x: Rep[HashMap[K,V]], block: Rep[(K,V)] => Rep[Unit])(implicit pos: SourceContext): Rep[Unit] def hashmap_clear[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Unit] def hashmap_keyset[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Set[K]] def hashmap_keys[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[Iterable[K]] - def hashmap_head[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[(K,V)] - def hashmap_removehead[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext): Rep[(K,V)] - def hashmap_remove[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], v: Rep[K])(implicit pos: SourceContext): Rep[V] - def hashmap_getorelseupdate[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K], v: => Rep[V])(implicit pos: SourceContext): Rep[V] - def hashmap_mkString[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], v: Rep[String])(implicit pos: SourceContext): Rep[String] } -trait HashMapOpsExp extends HashMapOps with EffectExp with TupleOpsExp with FunctionsExp with ArrayOps with IfThenElseExp with EqualExp { +trait HashMapOpsExp extends HashMapOps with EffectExp { abstract class HashMapDef[K:Manifest,V:Manifest,R:Manifest] extends Def[R] { val mK = manifest[K] val mV = manifest[V] } case class HashMapNew[K:Manifest,V:Manifest]() extends HashMapDef[K,V,HashMap[K,V]] - case class HashMapExtendedNew[K:Manifest,V:Manifest](k: Sym[K], hf:Block[Int], v1: Sym[K], v2: Sym[K], ef: Block[Boolean]) extends HashMapDef[K,V,HashMap[K,V]] case class HashMapApply[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K]) extends HashMapDef[K,V,V] case class HashMapUpdate[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], v: Exp[V]) extends HashMapDef[K,V,Unit] case class HashMapContains[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], i: Exp[K]) extends HashMapDef[K,V,Boolean] case class HashMapSize[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Int] case class HashMapValues[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Iterable[V]] - case class HashMapMap[K:Manifest,V:Manifest,B:Manifest](m: Exp[HashMap[K,V]], s: Sym[(K,V)], v:Block[B]) extends HashMapDef[K,V,HashMap[K,B]] - case class HashMapForeach[K:Manifest, V:Manifest](a: Exp[HashMap[K,V]], x: Sym[(K,V)], block: Block[Unit]) extends Def[Unit] case class HashMapClear[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Unit] case class HashMapKeySet[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Set[K]] case class HashMapKeys[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,Iterable[K]] - case class HashMapHead[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]]) extends HashMapDef[K,V,(K,V)] - case class HashMapRemoveHead[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], s: Sym[V]) extends HashMapDef[K,V,(K,V)] - // We assume that the element to be removed exists for sure for simplicitly - case class HashMapRemove[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], v:Rep[K]) extends HashMapDef[K,V,V] { - val ccc = manifest[V] - } - case class HashMapGetOrElseUpdate[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], vl: Block[V]) extends HashMapDef[K,V,V] with IfThenElseExp - case class HashMapMkString[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], v:Rep[String]) extends HashMapDef[K,V,String] - def hashmap_new[K:Manifest,V:Manifest]() = reflectMutable(HashMapNew[K,V]()) - def hashmap_new[K:Manifest,V:Manifest](hash: Exp[K] => Exp[Int], equals: (Exp[K],Exp[K])=>Exp[Boolean]) = { - val k = fresh[K] - val v1 = fresh[K] - val v2 = fresh[K] - val hf = reifyEffects(hash(k)) - val ef = reifyEffects(equals(v1,v2)) - reflectMutable(HashMapExtendedNew[K,V](k,hf,v1,v2,ef)) - } + def hashmap_new[K:Manifest,V:Manifest]()(implicit pos: SourceContext) = reflectMutable(HashMapNew[K,V]()) def hashmap_apply[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K])(implicit pos: SourceContext) = HashMapApply(m,k) def hashmap_update[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], v: Exp[V])(implicit pos: SourceContext) = reflectWrite(m)(HashMapUpdate(m,k,v)) def hashmap_unsafe_update[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], k: Exp[K], v: Exp[V])(implicit pos: SourceContext) = reflectEffect(HashMapUpdate(m,k,v)) def hashmap_contains[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]], i: Exp[K])(implicit pos: SourceContext) = HashMapContains(m, i) - def hashmap_size[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = reflectEffect(HashMapSize(m)) + def hashmap_size[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = HashMapSize(m) def hashmap_values[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = HashMapValues(m) - def hashmap_map[K:Manifest,V:Manifest,B:Manifest](m: Rep[HashMap[K,V]], f: Rep[(K,V)]=>Rep[B]) = { - val a = fresh[Tuple2[K,V]] - val b = reifyEffects(f(a)) - reflectEffect(HashMapMap(m, a, b))//, summarizeEffects(b).star) - } - def hashmap_foreach[K:Manifest,V:Manifest](x: Rep[HashMap[K,V]], block: Rep[(K,V)] => Rep[Unit])(implicit pos: SourceContext) = { - val k = fresh[(K,V)] - val b = reifyEffects(block(k)) - reflectEffect(HashMapForeach(x, k, b), summarizeEffects(b).star) - } - def hashmap_clear[K:Manifest,V:Manifest](m: Exp[HashMap[K,V]])(implicit pos: SourceContext) = reflectWrite(m)(HashMapClear(m)) - def hashmap_keyset[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = reflectEffect(HashMapKeySet(m)) + def hashmap_keyset[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = HashMapKeySet(m) def hashmap_keys[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = HashMapKeys(m) - def hashmap_head[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = { - reflectEffect(HashMapHead(m)) - } - def hashmap_removehead[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]])(implicit pos: SourceContext) = { - val s = fresh[V] - reflectEffect(HashMapRemoveHead(m,s)) - } - def hashmap_remove[K:Manifest, V:Manifest](m: Rep[HashMap[K,V]], k: Rep[K])(implicit pos: SourceContext) = reflectEffect(HashMapRemove[K,V](m,k)) - def hashmap_getorelseupdate[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], k: Exp[K], v: => Exp[V])(implicit pos: SourceContext) = { - val b = reifyEffects(v) - reflectEffect(HashMapGetOrElseUpdate[K,V](m,k,b), summarizeEffects(b).star) - } - def hashmap_mkString[K:Manifest,V:Manifest](m: Rep[HashMap[K,V]], v: Rep[String])(implicit pos: SourceContext) = reflectEffect(HashMapMkString(m, v)) override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = { (e match { case e@HashMapApply(m,k) => hashmap_apply(f(m),f(k))(e.mK,e.mV,pos) - case e@HashMapRemove(m,k) => hashmap_remove(f(m),f(k))(e.mK,e.mV,pos) case e@HashMapKeys(m) => hashmap_keys(f(m))(e.mK,e.mV,pos) - case e@HashMapKeySet(m) => hashmap_keyset(f(m))(e.mK,e.mV,pos) case e@HashMapValues(m) => hashmap_values(f(m))(e.mK,e.mV,pos) case e@HashMapContains(m,k) => hashmap_contains(f(m),f(k))(e.mK,e.mV,pos) - case Reflect(e@HashMapApply(m,k), u, es) => reflectMirrored(Reflect(HashMapApply(f(m),f(k))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@HashMapKeys(m), u, es) => reflectMirrored(Reflect(HashMapKeys(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@HashMapKeySet(m), u, es) => reflectMirrored(Reflect(HashMapKeySet(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@HashMapValues(m), u, es) => reflectMirrored(Reflect(HashMapValues(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@HashMapSize(m), u, es) => reflectMirrored(Reflect(HashMapSize(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@HashMapRemove(m,el), u, es) => reflectMirrored(Reflect(HashMapRemove(f(m),f(el))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@HashMapContains(m,k), u, es) => reflectMirrored(Reflect(HashMapContains(f(m),f(k))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@HashMapNew(), u, es) => reflectMirrored(Reflect(HashMapNew()(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) - case Reflect(e@HashMapUpdate(m,k,v), u, es) => reflectMirrored(Reflect(HashMapUpdate(f(m),f(k),f(v))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A])) -// case Reflect(HashMapExtendedNew(k,hf,v1,v2,ef), u, es) => reflectMirrored(Reflect(HashMapExtendedNew(k,f(hf),v1,v2,f(ef)), mapOver(f,u), f(es))) -// case Reflect(HashMapGetOrElseUpdate(m,k,v), u, es) => reflectMirrored(Reflect(HashMapGetOrElseUpdate(f(m).asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],f(k),f(v)), mapOver(f,u), f(es)))(mtype(manifest[A])) + case e@HashMapSize(m) => hashmap_size(f(m))(e.mK,e.mV,pos) + case Reflect(e@HashMapApply(m,k), u, es) => reflectMirrored(Reflect(HashMapApply(f(m),f(k))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@HashMapKeys(m), u, es) => reflectMirrored(Reflect(HashMapKeys(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@HashMapValues(m), u, es) => reflectMirrored(Reflect(HashMapValues(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@HashMapContains(m,k), u, es) => reflectMirrored(Reflect(HashMapContains(f(m),f(k))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@HashMapSize(m), u, es) => reflectMirrored(Reflect(HashMapSize(f(m))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@HashMapNew(), u, es) => reflectMirrored(Reflect(HashMapNew()(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case Reflect(e@HashMapUpdate(m,k,v), u, es) => reflectMirrored(Reflect(HashMapUpdate(f(m),f(k),f(v))(e.mK,e.mV), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] // why?? } - override def syms(e: Any): List[Sym[Any]] = e match { - case HashMapMap(m, k, v) => syms(m):::syms(v) - case HashMapForeach(m, k, v) => syms(m):::syms(v) - case HashMapExtendedNew(k,hf,v1,v2,ef) => syms(k):::syms(hf):::syms(v1):::syms(v2):::syms(ef) - case _ => super.syms(e) - } - - override def boundSyms(e: Any): List[Sym[Any]] = e match { - case HashMapGetOrElseUpdate(m, k, v) => effectSyms(k) ::: effectSyms(m) ::: effectSyms(v) - case HashMapMap(m, k, v) => k :: effectSyms(v) - case HashMapForeach(m, k, v) => k :: effectSyms(v) - case HashMapUpdate(m,k,v) => effectSyms(k) ::: effectSyms(m) ::: effectSyms(v) - case HashMapExtendedNew(k,hf,v1,v2,ef) => k :: v1 :: v2 :: effectSyms(hf) ::: effectSyms(ef) - case _ => super.boundSyms(e) - } - - override def symsFreq(e: Any): List[(Sym[Any], Double)] = e match { - case HashMapMap(m, k, v) => freqNormal(m) ::: freqHot(v) - case HashMapForeach(m, k, v) => freqNormal(m) ::: freqHot(v) - case _ => super.symsFreq(e) - } - } trait BaseGenHashMapOps extends GenericNestedCodegen { @@ -182,142 +93,43 @@ trait ScalaGenHashMapOps extends BaseGenHashMapOps with ScalaGenEffect { val IR: HashMapOpsExp import IR._ + // TODO: have two versions for generating Scala/Java versions + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case m@HashMapNew() => emitValDef(sym, src"new scala.collection.mutable.HashMap[${m.mK},${m.mV}]()") - case m@HashMapExtendedNew(k,hf,v1,v2,ef) => - emitValDef(sym, src"new scala.collection.mutable.HashMap[${m.mK},${m.mV}]() {") - stream.println("override def elemHashCode(" + quote(k) + ": " + remap(m.mK) + ") = {") - emitBlock(hf) - emitBlockResult(hf) - stream.println("}") - stream.println("override def elemEquals(" + quote(v1) + ": " + remap(m.mK) + ", " + quote(v2) + ": " + remap(m.mK) + ") = {") - emitBlock(ef) - emitBlockResult(ef) - stream.println("}") - stream.println("}") + case m@HashMapNew() => emitValDef(sym, "new java.util.HashMap[" + remap(m.mK) + "," + remap(m.mV) + "]()") + case HashMapApply(m,k) => emitValDef(sym, quote(m) + ".get(" + quote(k) + ")") + case HashMapUpdate(m,k,v) => emitValDef(sym, quote(m) + ".put(" + quote(k) + ", " + quote(v) + ")") + case HashMapContains(m,i) => emitValDef(sym, quote(m) + ".containsKey(" + quote(i) + ")") + case HashMapSize(m) => emitValDef(sym, quote(m) + ".size") + case HashMapValues(m) => emitValDef(sym, "scala.collection.JavaConverters.collectionAsScalaIterableConverter("+quote(m)+".values).asScala") + case HashMapClear(m) => emitValDef(sym, quote(m) + ".clear()") + case HashMapKeySet(m) => emitValDef(sym, "scala.collection.JavaConverters.asScalaSetConverter("+quote(m)+".keySet).asScala") + case HashMapKeys(m) => emitValDef(sym, "scala.collection.JavaConverters.asScalaSetConverter("+quote(m)+".keySet).asScala.toIterable") + case _ => super.emitNode(sym, rhs) + } +/* + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case m@HashMapNew() => emitValDef(sym, src"collection.mutable.HashMap[${m.mK},${m.mV}]()") case HashMapApply(m,k) => emitValDef(sym, src"$m($k)") case HashMapUpdate(m,k,v) => emitValDef(sym, src"$m($k) = $v") case HashMapContains(m,i) => emitValDef(sym, src"$m.contains($i)") case HashMapSize(m) => emitValDef(sym, src"$m.size") case HashMapValues(m) => emitValDef(sym, src"$m.values") case HashMapClear(m) => emitValDef(sym, src"$m.clear()") - case HashMapKeySet(m) => emitValDef(sym, src"collection.mutable.Set($m.keySet.toSeq:_*)") + case HashMapKeySet(m) => emitValDef(sym, src"$m.keySet") case HashMapKeys(m) => emitValDef(sym, src"$m.keys") - case HashMapHead(m) => emitValDef(sym, src"$m.head") - case HashMapRemoveHead(m,s) => { - emitValDef(s, src"$m.head") - gen"$m -= $s._1" - emitValDef(sym, quote(s)) - } - // We assume that the element to be removed exists for sure for simplicitly - case HashMapRemove(m,k) => emitValDef(sym, src"$m.remove($k).get") - case HashMapMap(m,k,v) => { - emitValDef(sym, quote(m) + ".map(" + quote(k) + "=> {") - emitBlock(v) - emitBlockResult(v) - stream.println("})") - } - case HashMapForeach(m,k,v) => { - emitValDef(sym, quote(m) + ".foreach(" + quote(k) + "=> {") - emitBlock(v) - emitBlockResult(v) - stream.println("})") - } - case HashMapGetOrElseUpdate(m,k,v) => { - emitValDef(sym, quote(m) + ".getOrElseUpdate(" + quote(k) + ",{") - emitBlock(v) - emitBlockResult(v) - stream.println("})") - } - case HashMapMkString(m,k) => emitValDef(sym, src"$m.mkString($k)") case _ => super.emitNode(sym, rhs) } +*/ } trait CLikeGenHashMapOps extends BaseGenHashMapOps with CLikeCodegen { val IR: HashMapOpsExp import IR._ - override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { - case m@HashMapExtendedNew(k,hf,v1,v2,ef) => - LIRTraversal(hf) - LIRTraversal(ef) - sym.atPhase(LIRLowering) { - val lhf = LIRLowering(hf) - val lef = LIRLowering(ef) - val nvt = remapManifest(fresh(m.mV)) - val lkM = remapManifest(fresh(m.mK))(m.mK) - k.tp = lkM - v1.tp = lkM - v2.tp = lkM - reflectMutable(HashMapExtendedNew(k,lhf,v1,v2,lef)(m.mK,nvt)).asInstanceOf[Exp[A]] - } - case ma@HashMapApply(m,k) => - sym.atPhase(LIRLowering) { - reflectEffect(HashMapApply(LIRLowering(m).asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],LIRLowering(k))).asInstanceOf[Exp[A]] - } - case gu@HashMapGetOrElseUpdate(m,k,v) => - LIRTraversal(v) - sym.atPhase(LIRLowering) { - val vb = LIRLowering(v) - val hm = LIRLowering(m) - val nvt = remapManifest(fresh(vb.tp)) - val c = hashmap_apply(hm.asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],LIRLowering(k))(gu.mK,nvt.asInstanceOf[Manifest[A]],implicitly[SourceContext]) - val cc = reflectEffect(IfThenElse ((c == unit(null)), vb, Block(c))) - __ifThenElse ((cc != c), hashmap_update(hm.asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],LIRLowering(k),cc), ()) - cc.asInstanceOf[Exp[A]] - } - case ks@HashMapKeySet(m) => sym.atPhase(LIRLowering) { - hashmap_keyset(LIRLowering(m))(remapManifest(fresh(ks.mK))(ks.mK).asInstanceOf[Manifest[Any]],ks.mV,implicitly[SourceContext]).asInstanceOf[Exp[A]] - } - case r@HashMapRemove(m,k) => { - sym.atPhase(LIRLowering) { - val hm = LIRLowering(m) - val nvt = remapManifest(fresh(r.ccc))(r.ccc) - val c = hashmap_apply(hm.asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]],LIRLowering(k))(r.mK,nvt.asInstanceOf[Manifest[A]],implicitly[SourceContext]) - hashmap_remove(hm.asInstanceOf[Exp[scala.collection.mutable.HashMap[Any,A]]], LIRLowering(k)) - c.asInstanceOf[Exp[A]] - } - } - case _ => super.lowerNode(sym,rhs) - } - - override def remap[A](m: Manifest[A]) = m match { - case s if m <:< manifest[scala.collection.mutable.HashMap[Any,Any]] => "GHashTable *" - case _ => super.remap(m) - } - - def remapKeyIfPrimitive(k: Exp[Any]) = k.tp match { - case s if s == manifest[Int] || s == manifest[Double] || s == manifest[Long] => "GINT_TO_POINTER(" + quote(k) + ")" - case _ => quote(k) - } - - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case m@HashMapNew() => { - m.mK match { - case s if s == manifest[java.lang.String] => - emitValDef(sym, "g_hash_table_new(g_str_hash, g_str_equal)") - case s if s == manifest[Int] || s == manifest[Double] || s == manifest[Long] => - emitValDef(sym, "g_hash_table_new(g_direct_hash, g_direct_equal)") - case _ => throw new Exception("Unknown primitive type " + m.mK + " for CCodegen of HashMapNew.") - } - } - case m@HashMapExtendedNew(k,hf,v1,v2,ef) => { - val uhf = uninlinedFunc1(k,hf) - val uef = uninlinedFunc2(v1,v2,ef) - emitValDef(sym, "g_hash_table_new((GHashFunc)" + quote(uhf) + ",(GEqualFunc)" + quote(uef) + ")") - } - case HashMapSize(m) => emitValDef(sym, "g_hash_table_size(" + quote(m) + ");") - case HashMapApply(m,k) => emitValDef(sym, "g_hash_table_lookup(" + quote(m) + "," + remapKeyIfPrimitive(k) + ");"); - case HashMapUpdate(m,k,v) => stream.println("g_hash_table_insert(" + quote(m) + "," + remapKeyIfPrimitive(k) + "," + quote(v) + ");"); - case HashMapKeySet(m) => emitValDef(sym, "g_hash_table_get_keys(" + quote(m) + ")") - case HashMapRemove(m,k) => - emitValDef(sym, "g_hash_table_lookup(" + quote(m) + "," + remapKeyIfPrimitive(k) + ");"); - stream.println("g_hash_table_remove(" + quote(m) + "," + remapKeyIfPrimitive(k) + ");"); - case HashMapClear(m) => stream.println("g_hash_table_remove_all(" + quote(m) + ");") - case HashMapContains(m,k) => emitValDef(sym, "g_hash_table_lookup(" + quote(m) + "," + remapKeyIfPrimitive(k) + ") != NULL") - case _ => super.emitNode(sym, rhs) - } +// override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { +// case _ => super.emitNode(sym, rhs) +// } } trait CudaGenHashMapOps extends CudaGenEffect with CLikeGenHashMapOps From 6554ff0768acba0ff97ca9ec05947cb0b216b557 Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Mon, 19 Dec 2016 22:51:06 -0500 Subject: [PATCH 06/10] StaticData --- src/common/StaticData.scala | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/common/StaticData.scala b/src/common/StaticData.scala index 936f11df..a622c633 100644 --- a/src/common/StaticData.scala +++ b/src/common/StaticData.scala @@ -13,13 +13,24 @@ trait StaticDataExp extends EffectExp { case class StaticData[T](x: T) extends Def[T] def staticData[T:Manifest](x: T): Exp[T] = StaticData(x) + // StaticData doesn't play well with control dependencies.. looks like we somehow lose updates + override implicit def toAtom[T:Manifest](d: Def[T])(implicit pos: SourceContext) = d match { + case StaticData(x) if addControlDeps => + val save = conditionalScope + conditionalScope = false + val z = super.toAtom(d) + conditionalScope = save + z + case _ => super.toAtom(d) + } + override def isWritableSym[A](w: Sym[A]): Boolean = findDefinition(w) match { case Some(TP(_, StaticData(_))) => true case _ => super.isWritableSym(w) } override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { - case StaticData(x) => staticData(x)(mtype(manifest[A])) + case StaticData(x) => staticData(x)(mtype(manifest[A])) case _ => super.mirror(e,f) }).asInstanceOf[Exp[A]] } @@ -55,12 +66,21 @@ trait BaseGenStaticData extends GenericNestedCodegen { trait ScalaGenStaticData extends ScalaGenEffect with BaseGenStaticData { val IR: StaticDataExp import IR._ - + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { - case StaticData(x) => + case StaticData(x) => emitValDef(sym, "p"+quote(sym) + " // static data: " + (x match { case x: Array[_] => "Array("+x.mkString(",")+")" case _ => x })) case _ => super.emitNode(sym, rhs) } - } +trait CGenStaticData extends CGenEffect with BaseGenStaticData { + val IR: StaticDataExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case StaticData(x) => + emitValDef(sym, /*"p"+quote(sym)*/ (x match { case x: Array[_] => "("+remap(sym.tp.typeArguments(0))+"[]){"+x.map(v=>quote(Const[Any](v))).mkString(",")+"}" case _ => quote(Const(x)) })) + case _ => super.emitNode(sym, rhs) + } +} From 406e8a179b60f4e3674a9ada6e25fc7cb6edd88b Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Mon, 19 Dec 2016 23:04:01 -0500 Subject: [PATCH 07/10] internal and test-out --- src/internal/AccModel.scala | 62 + src/internal/BlockTraversal.scala | 1 + src/internal/CodeMotion.scala | 11 +- src/internal/Config.scala | 16 +- src/internal/CppHostTransfer.scala | 301 +++++ src/internal/CudaCodegen.scala | 210 +--- src/internal/CudaDeviceTransfer.scala | 134 +++ src/internal/FatCodegen.scala | 4 +- src/internal/GPUCodegen.scala | 603 +++------- src/internal/OpenCLCodegen.scala | 233 +--- test-out/epfl/test10-effects1.check | 7 +- test-out/epfl/test10-effects2.check | 11 +- test-out/epfl/test10-effects3.check | 11 +- test-out/epfl/test10-effects4.check | 7 +- test-out/epfl/test10-misc1.check | 8 +- test-out/epfl/test10-misc2.check | 24 +- test-out/epfl/test10-misc3.check | 66 +- test-out/epfl/test10-misc4.check | 66 +- test-out/epfl/test10-misc5.check | 66 +- test-out/epfl/test10-transform1.check | 8 +- test-out/epfl/test10-transform2.check | 34 +- test-out/epfl/test10-transform3.check | 66 +- test-out/epfl/test10-transformrec3.check | 46 +- test-out/epfl/test10-worklist1.check | 18 +- test-out/epfl/test10-worklist2.check | 6 +- test-out/epfl/test10-worklist21.check | 14 +- test-out/epfl/test10-worklist22.check | 6 +- test-out/epfl/test10-worklist23.check | 14 +- test-out/epfl/test10-worklist3.check | 16 +- test-out/epfl/test11-hmm1.check | 17 +- test-out/epfl/test11-hmm2.check | 23 +- test-out/epfl/test11-stencil0.check | 7 +- test-out/epfl/test11-stencil1.check | 47 +- test-out/epfl/test11-stencil2a.check | 7 +- test-out/epfl/test11-stencil2b.check | 53 +- test-out/epfl/test11-stencil3a.check | 7 +- test-out/epfl/test11-stencil3b.check | 95 +- test-out/epfl/test12-array-seq-creation.check | 6 +- test-out/epfl/test12-map-flatmap-filter.check | 3 - test-out/epfl/test13-interpret2.check | 345 +++--- test-out/epfl/test13-interpret3.check | 82 +- test-out/epfl/test13-stable1.check | 12 +- test-out/epfl/test13-stable2.check | 30 +- test-out/epfl/test13-unstage1.check | 12 +- test-out/epfl/test14-cgen1.check | 15 +- test-out/epfl/test14-cgen2.check | 25 +- test-out/epfl/test14-cgen3.check | 37 +- test-out/epfl/test14-dataop1.check | 27 +- test-out/epfl/test14-dataop2.check | 70 +- test-out/epfl/test14-dataop3.check | 220 ++++ test-out/epfl/test14-queries2.check | 34 +- test-out/epfl/test14-queries3.check | 24 +- test-out/epfl/test14-queries4.check | 28 +- test-out/epfl/test2-fft3.check | 1 + test-out/epfl/test2-power.check | 1 + test-out/epfl/test2-sort1-dot.check | 303 +++++ test-out/epfl/test2-sort1.check | 49 + test-out/epfl/test4-counter1.check | 1 + test-out/epfl/test4-counter2.check | 91 +- test-out/epfl/test4-matchernew1.check | 23 +- test-out/epfl/test4-matchernew1b.check | 23 +- test-out/epfl/test4-matchernew2.check | 1 + test-out/epfl/test4-matchernew2b.check | 1 + test-out/epfl/test4-stream1.check | 53 +- test-out/epfl/test5-conditional.check | 25 +- test-out/epfl/test5-conditional.html.check | 12 +- test-out/epfl/test5-functions.check | 37 +- test-out/epfl/test5-functionsrecursive.check | 12 +- test-out/epfl/test5-funretfun.check | 4 +- test-out/epfl/test5-twoargsfun.check | 2 +- test-out/epfl/test6-vectors.check | 2 + test-out/epfl/test7-codemotion1.check | 2 +- test-out/epfl/test7-codemotion2.check | 2 +- test-out/epfl/test7-codemotion3.check | 6 +- test-out/epfl/test7-codemotion4.check | 5 +- test-out/epfl/test7-codemotion5.check | 3 +- test-out/epfl/test7-codemotion6.check | 8 +- test-out/epfl/test7-fusion1.check | 5 +- test-out/epfl/test7-fusion2.check | 21 +- test-out/epfl/test7-fusion21.check | 9 +- test-out/epfl/test7-fusion22.check | 15 +- test-out/epfl/test7-fusion23.check | 45 +- test-out/epfl/test7-fusion24.check | 7 +- test-out/epfl/test7-fusion3.check | 5 +- test-out/epfl/test7-fusion4.check | 7 +- test-out/epfl/test7-lambdalift1.check | 2 +- test-out/epfl/test7-liveness1.check | 3 +- test-out/epfl/test7-liveness2.check | 3 +- test-out/epfl/test8-mutation1.check | 9 +- test-out/epfl/test8-mutation1b.check | 7 +- test-out/epfl/test8-mutation2.check | 11 +- test-out/epfl/test8-mutation3.check | 11 +- test-out/epfl/test8-mutation3b.check | 11 +- test-out/epfl/test8-mutation4.check | 11 +- test-out/epfl/test8-mutation4b.check | 13 +- test-out/epfl/test8-mutation4c.check | 7 +- test-out/epfl/test8-mutation5.check | 13 +- test-out/epfl/test8-mutation6.check | 15 +- test-out/epfl/test8-mutation7.check | 13 +- test-out/epfl/test8-speculative1.check | 6 +- test-out/epfl/test8-speculative1b.check | 4 +- test-out/epfl/test8-speculative1c.check | 8 +- test-out/epfl/test8-speculative1d.check | 8 +- test-out/epfl/test8-speculative3.check | 14 +- test-out/epfl/test8-speculative3b.check | 14 +- test-out/epfl/test8-speculative4.check | 6 +- test-out/epfl/test8-speculative5.check | 12 +- test-out/epfl/test8-speculative6.check | 114 ++ test-out/epfl/test9-amb1a.check | 91 +- test-out/epfl/test9-amb1b.check | 43 +- test-out/epfl/test9-amb2a.check | 1025 +++++++++-------- test-out/epfl/test9-amb2b.check | 289 ++--- test-out/epfl/test9-cps1.check | 11 +- test-out/epfl/test9-cps2.check | 11 +- test-out/epfl/test9-csp1.check | 4 +- test-out/epfl/test9-csp2.check | 8 +- test-out/epfl/test9-struct1.check | 12 +- test-out/epfl/test9-struct2.check | 19 +- test-out/epfl/test9-struct2b.check | 25 +- test-out/epfl/test9-struct3.check | 9 +- test-out/epfl/test9-struct4.check | 11 +- test-out/epfl/test9-struct5.check | 19 + test-out/epfl/test9-struct6.check | 17 + 123 files changed, 3362 insertions(+), 2623 deletions(-) create mode 100644 src/internal/AccModel.scala create mode 100644 src/internal/CppHostTransfer.scala create mode 100644 src/internal/CudaDeviceTransfer.scala create mode 100644 test-out/epfl/test14-dataop3.check create mode 100644 test-out/epfl/test2-sort1-dot.check create mode 100644 test-out/epfl/test2-sort1.check create mode 100644 test-out/epfl/test8-speculative6.check create mode 100644 test-out/epfl/test9-struct5.check create mode 100644 test-out/epfl/test9-struct6.check diff --git a/src/internal/AccModel.scala b/src/internal/AccModel.scala new file mode 100644 index 00000000..0a810e30 --- /dev/null +++ b/src/internal/AccModel.scala @@ -0,0 +1,62 @@ +package scala.lms.internal + +trait AbstractHostTransfer { + this: GenericCodegen => + + val IR: Expressions + import IR._ + + def emitSend(tp: Manifest[_], peer: Targets.Value): (String,String) + def emitRecv(tp: Manifest[_], peer: Targets.Value): (String,String) + def emitSendView(tp: Manifest[_], peer: Targets.Value): (String,String) + def emitRecvView(tp: Manifest[_], peer: Targets.Value): (String,String) + def emitSendUpdate(tp: Manifest[_], peer: Targets.Value): (String,String) + def emitRecvUpdate(tp: Manifest[_], peer: Targets.Value): (String,String) +} + +trait AbstractDeviceTransfer { + this: GenericCodegen => + + val IR: Expressions + import IR._ + + def emitSendSlave(tp: Manifest[_]) : (String,String) + def emitRecvSlave(tp: Manifest[_]) : (String,String) + //def emitSendViewSlave(tp: Manifest[_]) : (String,String) + //def emitRecvViewSlave(tp: Manifest[_]) : (String,String) + def emitSendUpdateSlave(tp: Manifest[_]) : (String,String) + def emitRecvUpdateSlave(tp: Manifest[_]) : (String,String) + + //def allocOutput(newSym: Sym[_], sym: Sym[_], reset: Boolean = false) : Unit +} + +object Targets extends Enumeration { + + //TODO: Get rid of JVM target, or make an hierarchy + val JVM = Value("jvm") + val Scala = Value("scala") + val Cpp = Value("cpp") + val Cuda = Value("cuda") + val OpenCL = Value("opencl") + + def apply(s: String): Value = s.toLowerCase() match { + case "jvm" => JVM + case "scala" => Scala + case "cpp" => Cpp + case "cuda" => Cuda + case "opencl" => OpenCL + case _ => throw new IllegalArgumentException("unsupported target: " + s) + } + + def getHostTarget(target: Value): Targets.Value = { + target match { + case Targets.Scala => Targets.Scala + case Targets.Cpp => Targets.Cpp + case Targets.Cuda => Targets.Cpp + case Targets.OpenCL => Targets.Cpp + case _ => throw new IllegalArgumentException("Cannot find a host target for target " + target) + } + } + + implicit def targettostring(target: Targets.Value): String = target.toString +} diff --git a/src/internal/BlockTraversal.scala b/src/internal/BlockTraversal.scala index 13560a0c..960e4b85 100644 --- a/src/internal/BlockTraversal.scala +++ b/src/internal/BlockTraversal.scala @@ -130,3 +130,4 @@ trait NestedBlockTraversal extends BlockTraversal with NestedGraphTraversal { super.reset } } + diff --git a/src/internal/CodeMotion.scala b/src/internal/CodeMotion.scala index 6f7aa17c..e8bb5247 100644 --- a/src/internal/CodeMotion.scala +++ b/src/internal/CodeMotion.scala @@ -98,11 +98,12 @@ trait CodeMotion extends Scheduling { // sanity check to make sure all effects are accounted for result foreach { - case LocalDef(TP(_, Reify(x, u, effects))) => - val acteffects = levelScope.flatMap(_.lhs) filter (effects contains _) - if (effects.toSet != acteffects.toSet) { - val actual = levelScope.filter(_.lhs exists (effects contains _)) - val expected = effects.map(d=>/*fatten*/(findDefinition(d.asInstanceOf[Sym[Any]]).get)) + case LocalDef(TP(_, Reify(x, u, effects))) => + val observable = if (addControlDeps) effects.filterNot(controlDep) else effects + val acteffects = levelScope.flatMap(_.lhs) filter (observable contains _) + if (observable.toSet != acteffects.toSet) { + val actual = levelScope.filter(_.lhs exists (observable contains _)) + val expected = observable.map(d=>/*fatten*/(findDefinition(d.asInstanceOf[Sym[Any]]).get)) val missing = expected filterNot (actual contains _) val printfn = if (missing.isEmpty) printlog _ else printerr _ printfn("error: violated ordering of effects") diff --git a/src/internal/Config.scala b/src/internal/Config.scala index 54845976..3727162b 100644 --- a/src/internal/Config.scala +++ b/src/internal/Config.scala @@ -1,7 +1,17 @@ package scala.lms package internal -object Config { - var verbosity = System.getProperty("lms.verbosity","0").toInt - var sourceinfo = System.getProperty("lms.sourceinfo","0").toInt +trait Config { + val verbosity = System.getProperty("lms.verbosity","0").toInt + val sourceinfo = System.getProperty("lms.sourceinfo","0").toInt + val addControlDeps = System.getProperty("lms.controldeps","true").toBoolean + + // memory management type for C++ target (refcnt or gc) + val cppMemMgr = System.getProperty("lms.cpp.memmgr","malloc") + + // explicit return type of lambda functions (allows recursive functions but is less generic) + val cppExplicitFunRet = System.getProperty("lms.cpp.explicitFunRet","true") + + // auto return value of if-else expressions (allows type deduction on if-then-else expressions) + val cppIfElseAutoRet = System.getProperty("lms.cpp.ifElseAutoRet","false") } diff --git a/src/internal/CppHostTransfer.scala b/src/internal/CppHostTransfer.scala new file mode 100644 index 00000000..22f36297 --- /dev/null +++ b/src/internal/CppHostTransfer.scala @@ -0,0 +1,301 @@ +package scala.lms.internal + +trait CppHostTransfer extends AbstractHostTransfer { + this: CLikeCodegen => + + val IR: Expressions + import IR._ + + // NOTE: strings are in general treated as primitive types to avoid the memory management, + // but for transfer functions strings must be treated separately from primitive types + + def emitSend(tp: Manifest[_], peer: Targets.Value): (String,String) = { + if (peer == Targets.JVM) { + if (remap(tp) == "string") { + val out = new StringBuilder + val signature = "jobject sendCPPtoJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("return env->NewStringUTF(sym.c_str());\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "%s sendCPPtoJVM_%s(JNIEnv *env, %s sym)".format(JNIType(tp),mangledName(remapHost(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\treturn (%s)sym;\n".format(JNIType(tp))) + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "jobject sendCPPtoJVM_%s(JNIEnv *env, %s *sym)".format(mangledName(remapHost(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn NULL;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) + } + } + else if (peer == Targets.Cpp) { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + } + + def emitRecv(tp: Manifest[_], peer: Targets.Value): (String,String) = { + if (peer == Targets.JVM) { + if (remap(tp) == "string") { + val out = new StringBuilder + val signature = "%s recvCPPfromJVM_%s(JNIEnv *env, jobject obj)".format(remapHost(tp),mangledName(remapHost(tp))) + out.append(signature + " {\n") + out.append("\tconst char *str = env->GetStringUTFChars((jstring)obj,NULL);\n") + //TODO: check if this copy is necessary + out.append("\tchar *str2 = (char *)malloc((1+strlen(str))*sizeof(char));\n") + out.append("\tstrcpy(str2,str);\n") + out.append("\tstring sym(str2);\n") + out.append("\tenv->ReleaseStringUTFChars((jstring)obj,str);") + out.append("\treturn sym;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "%s recvCPPfromJVM_%s(JNIEnv *env, %s sym)".format(remap(tp),mangledName(remapHost(tp)),JNIType(tp)) + out.append(signature + " {\n") + out.append("\treturn (%s)sym;\n".format(remap(tp))) + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "%s *recvCPPfromJVM_%s(JNIEnv *env, jobject obj)".format(remapHost(tp),mangledName(remapHost(tp))) + out.append(signature + " {\n") + out.append("\t%s *sym = new %s();\n".format(remapHost(tp),remapHost(tp))) + out.append("\treturn sym;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) + } + } + else if (peer == Targets.Cpp) { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + } + + def emitSendView(tp: Manifest[_], peer: Targets.Value): (String,String) = { + if (peer == Targets.JVM) { + if (remap(tp) == "string") { + val out = new StringBuilder + val signature = "jobject sendViewCPPtoJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remapHost(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn NULL;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "%s sendViewCPPtoJVM_%s(JNIEnv *env, %s sym)".format(JNIType(tp),mangledName(remapHost(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn (%s)sym;\n".format(JNIType(tp))) + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "jobject sendViewCPPtoJVM_%s(JNIEnv *env, %s *sym)".format(mangledName(remapHost(tp)),remapHost(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn NULL;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) + } + } + else if (peer == Targets.Cpp) { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + } + + def emitRecvView(tp: Manifest[_], peer: Targets.Value): (String,String) = { + if (peer == Targets.JVM) { + if (remap(tp) == "string") { + val out = new StringBuilder + val signature = "%s recvViewCPPfromJVM_%s(JNIEnv *env, jobject *obj)".format(remapHost(tp),mangledName(remapHost(tp))) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn NULL;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "%s recvViewCPPfromJVM_%s(JNIEnv *env, %s sym)".format(remap(tp),mangledName(remapHost(tp)),JNIType(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn (%s)sym;\n".format(remap(tp))) + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "%s *recvViewCPPfromJVM_%s(JNIEnv *env, jobject *obj)".format(remapHost(tp),mangledName(remapHost(tp))) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn NULL;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) + } + } + else if (peer == Targets.Cpp) { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + } + + def emitSendUpdate(tp: Manifest[_], peer: Targets.Value): (String,String) = { + if (peer == Targets.JVM) { + if(isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "void sendUpdateCPPtoJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "void sendUpdateCPPtoJVM_%s(JNIEnv *env, jobject obj, %s *sym)".format(mangledName(remapHost(tp)),remapHost(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (remap(tp) == "string") { + val out = new StringBuilder + val signature = "void sendUpdateCPPtoJVM_%s(JNIEnv *env, jobject obj, %s sym)".format(mangledName(remapHost(tp)),remapHost(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) + } + } + else if (peer == Targets.Cpp) { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + } + + def emitRecvUpdate(tp: Manifest[_], peer: Targets.Value): (String,String) = { + if (peer == Targets.JVM) { + if (remap(tp) == "string") { + val out = new StringBuilder + val signature = "void recvUpdateCPPfromJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if(isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "void recvUpdateCPPfromJVM_%s(JNIEnv *env, %s sym)".format(mangledName(remapHost(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "void recvUpdateCPPfromJVM_%s(JNIEnv *env, jobject obj, %s *sym)".format(mangledName(remapHost(tp)),remapHost(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown type " + tp.toString) + } + } + else if (peer == Targets.Cpp) { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + else { + throw new GenerationFailedException("CppHostTransfer: Unknown peer " + peer.toString) + } + } + + def JNIType[A](m: Manifest[A]) : String = { + remap(m) match { + case "bool" => "jboolean" + case "int8_t" => "jbyte" + case "uint16_t" => "jchar" + case "int16_t" => "jshort" + case "int32_t" => "jint" + case "int64_t" => "jlong" + case "float" => "jfloat" + case "double" => "jdouble" + case _ => "jobject"//all other types are objects + } + } + + def remapToJNI[A](m: Manifest[A]) : String = { + remap(m) match { + case "bool" => "Boolean" + case "int8_t" => "Byte" + case "uint16_t" => "Char" + case "int16_t" => "Short" + case "int32_t" => "Int" + case "int64_t" => "Long" + case "float" => "Float" + case "double" => "Double" + case _ => "Object" + } + } + + def JNITypeDescriptor[A](m: Manifest[A]) : String = JNITypeDescriptor(m.toString) + def JNITypeDescriptor(tp: String): String = tp match { + case "Boolean" => "Z" + case "Byte" => "B" + case "Char" => "C" + case "Short" => "S" + case "Int" => "I" + case "Long" => "J" + case "Float" => "F" + case "Double" => "D" + case array if array.startsWith("Array[") => "[" + JNITypeDescriptor(array.slice(6,array.length-1)) + case _ => { //all other types are objects + var objectType = tp.replace('.','/') + if (objectType.indexOf('[') != -1) objectType = objectType.substring(0, objectType.indexOf('[')) //erasure + "L"+objectType+";" //'L' + fully qualified type + ';' + } + //case _ => throw new GenerationFailedException("Undefined JNI type") + } + +} diff --git a/src/internal/CudaCodegen.scala b/src/internal/CudaCodegen.scala index 42440843..7bc505b9 100644 --- a/src/internal/CudaCodegen.scala +++ b/src/internal/CudaCodegen.scala @@ -2,131 +2,46 @@ package scala.lms package internal import java.io.{FileWriter, StringWriter, PrintWriter, File} -import java.util.ArrayList -import collection.mutable.{ListBuffer, ArrayBuffer, LinkedList, HashMap, ListMap, HashSet} -import collection.mutable.{Map => MMap} import collection.immutable.List._ -trait CudaCodegen extends GPUCodegen { +trait CudaCodegen extends GPUCodegen with CppHostTransfer with CudaDeviceTransfer { val IR: Expressions import IR._ + override def deviceTarget: Targets.Value = Targets.Cuda + override def kernelFileExt = "cu" override def toString = "cuda" override def devFuncPrefix = "__device__" - - override def initializeGenerator(buildDir:String, args: Array[String], _analysisResults: MMap[String,Any]): Unit = { - + + override def initializeGenerator(buildDir:String, args: Array[String]): Unit = { val outDir = new File(buildDir) outDir.mkdirs - helperFuncIdx = 0 - helperFuncString = new StringBuilder - hstream = new PrintWriter(new FileWriter(buildDir + "helperFuncs.cu")) - helperFuncHdrStream = new PrintWriter(new FileWriter(buildDir + "helperFuncs.h")) - //headerStream = new PrintWriter(new FileWriter(buildDir + "dsl.h")) + actRecordStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "actRecords.h")) + + helperFuncStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.cu")) + helperFuncStream.print("#include \"" + deviceTarget + "helperFuncs.h\"\n") + + typesStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "types.h")) + typesStream.flush + //TODO: Put all the DELITE APIs declarations somewhere - hstream.print("#include \"helperFuncs.h\"\n") - helperFuncHdrStream.print(getDSLHeaders) - helperFuncHdrStream.print("#include \n") - helperFuncHdrStream.print("#include \n") - helperFuncHdrStream.print("#include \n\n") - helperFuncHdrStream.print("#define CHAR short\n") - helperFuncHdrStream.print("#define jCHAR jshort\n") - helperFuncHdrStream.print("#include \"DeliteCuda.h\"\n") - helperFuncHdrStream.print("#include \"DeliteArray.h\"\n") - super.initializeGenerator(buildDir, args, _analysisResults) - } + headerStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.h")) + headerStream.println("#include ") + headerStream.println("#include ") + headerStream.println("#include ") + headerStream.println("#include ") + headerStream.println("#include ") + headerStream.println("#include ") + headerStream.println("#include \"" + deviceTarget + "types.h\"") + headerStream.println(getDataStructureHeaders()) + headerStream.println("#include \"" + deviceTarget + "actRecords.h\"") - // TODO: Move to Delite? - def copyInputHtoD(sym: Sym[Any]) : String = { - checkGPUableType(sym.tp) - remap(sym.tp) match { - case "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeiteArray" | "DeliteArray" | "DeliteArray" => - val out = new StringBuilder - val typeArg = sym.tp.typeArguments.head - val numBytesStr = "length * sizeof(%s)".format(remap(typeArg)) - out.append("\tint length = env->GetArrayLength((j%sArray)obj);\n".format(remapToJNI(typeArg).toLowerCase)) - out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)obj,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) - out.append("\t%s *%s = new %s(length);\n".format(remap(sym.tp),quote(sym),remap(sym.tp))) - out.append("\t%s *hostPtr;\n".format(remap(typeArg))) - out.append("\tDeliteCudaMallocHost((void**)&hostPtr,%s);\n".format(numBytesStr)) - out.append("\tmemcpy(hostPtr, dataPtr, %s);\n".format(numBytesStr)) - out.append("\tDeliteCudaMemcpyHtoDAsync(%s->data, hostPtr, %s);\n".format(quote(sym),numBytesStr)) - out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)obj, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) - out.append("\treturn %s;\n".format(quote(sym))) - out.toString - case _ => throw new Exception("CudaGen: copyInputHtoD(sym) : Cannot copy to GPU device (%s)".format(remap(sym.tp))) - } - } - - def copyOutputDtoH(sym: Sym[Any]) : String = { - checkGPUableType(sym.tp) - if (isPrimitiveType(sym.tp)) { - val out = new StringBuilder - out.append("\t%s *ptr;\n".format(remap(sym.tp))) - out.append("\tDeliteCudaMallocHost((void**)&ptr,sizeof(%s));\n".format(remap(sym.tp))) - out.append("\tDeliteCudaMemcpyDtoHAsync(ptr, %s, sizeof(%s));\n".format(quote(sym),remap(sym.tp))) - out.append("\treturn *ptr;\n") - out.toString - } - else { - remap(sym.tp) match { - case "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeiteArray" | "DeliteArray" | "DeliteArray" => - val out = new StringBuilder - val typeArg = sym.tp.typeArguments.head - val numBytesStr = "%s.length * sizeof(%s)".format(quote(sym),remap(typeArg)) - out.append("\tj%sArray arr = env->New%sArray(%s.length);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg),quote(sym))) - out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)arr,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) - out.append("\t%s *hostPtr;\n".format(remap(typeArg))) - out.append("\tDeliteCudaMallocHost((void**)&hostPtr,%s);\n".format(numBytesStr)) - out.append("\tDeliteCudaMemcpyDtoHAsync(hostPtr, %s.data, %s);\n".format(quote(sym),numBytesStr)) - out.append("\tmemcpy(dataPtr, hostPtr, %s);\n".format(numBytesStr)) - out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)arr, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) - out.append("\treturn arr;\n") - out.toString - case _ => throw new Exception("CudaGen: copyOutputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) - } - } - } - - def copyMutableInputDtoH(sym: Sym[Any]) : String = { - checkGPUableType(sym.tp) - remap(sym.tp) match { - case "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeliteArray" | "DeiteArray" | "DeliteArray" | "DeliteArray" => - val out = new StringBuilder - val typeArg = sym.tp.typeArguments.head - val numBytesStr = "length * sizeof(%s)".format(remap(typeArg)) - out.append("\tint length = %s.length;\n".format(quote(sym))) - out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)obj,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) - out.append("\t%s *hostPtr;\n".format(remap(typeArg))) - out.append("\tDeliteCudaMallocHost((void**)&hostPtr,%s);\n".format(numBytesStr)) - out.append("\tDeliteCudaMemcpyDtoHAsync(hostPtr, %s.data, %s);\n".format(quote(sym),numBytesStr)) - out.append("\tmemcpy(dataPtr, hostPtr, %s);\n".format(numBytesStr)) - out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)obj, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) - out.toString - case _ => throw new Exception("CudaGen: copyMutableInputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) - } - } - - //TODO: Remove below methods - def allocOutput(newSym: Sym[_], sym: Sym[_], reset: Boolean = false) : Unit = { - throw new GenerationFailedException("CudaGen: allocOutput(newSym, sym) : Cannot allocate GPU memory (%s)".format(remap(sym.tp))) - } - def allocReference(newSym: Sym[Any], sym: Sym[Any]) : Unit = { - throw new GenerationFailedException("CudaGen: allocReference(newSym, sym) : Cannot allocate GPU memory (%s)".format(remap(sym.tp))) - } - - def positionMultDimInputs(sym: Sym[Any]) : String = { - throw new GenerationFailedException("CudaGen: positionMultDimInputs(sym) : Cannot reposition GPU memory (%s)".format(remap(sym.tp))) - } - - def cloneObject(sym: Sym[Any], src: Sym[Any]) : String = { - throw new GenerationFailedException("CudaGen: cloneObject(sym)") + super.initializeGenerator(buildDir, args) } def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, out: PrintWriter) = { - val sB = remap(manifest[A]) withStream(out) { @@ -150,88 +65,15 @@ trait CudaCodegen extends GPUCodegen { Nil } -/* - //TODO: is sym of type Any or Variable[Any] ? - def emitConstDef(sym: Sym[Any], rhs: emitK): Unit = { - stream.print("const ") - emitVarDef(sym, rhs) - } -*/ - - def emitValDef(sym: Sym[Any], rhs: String): Unit = { - stream.println(addTab() + remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") - } - - def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = { - stream.println(addTab()+ remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") - } - - def emitAssignment(sym: Sym[Any], lhs:String, rhs: String): Unit = { - stream.println(addTab() + " " + lhs + " = " + rhs + ";") - } - } // TODO: do we need this for each target? trait CudaNestedCodegen extends CLikeNestedCodegen with CudaCodegen { - val IR: Expressions with Effects with LoweringTransform + val IR: Expressions with Effects import IR._ - - def CudaConsts(x:Exp[Any], s:String): String = { - s match { - case "Infinity" => "std::numeric_limits<%s>::max()".format(remap(x.tp)) - case _ => s - } - } - - override def quote(x: Exp[Any]) = x match { // TODO: quirk! - case Const(s: String) => "\""+s+"\"" - case Const(s: Char) => "'"+s+"'" - case Const(null) => "NULL" - case Const(z) => CudaConsts(x, z.toString) - case Sym(-1) => "_" - case _ => super.quote(x) - } - } trait CudaFatCodegen extends CLikeFatCodegen with CudaCodegen { - val IR: Expressions with Effects with FatExpressions with LoweringTransform + val IR: Expressions with Effects with FatExpressions import IR._ - - def emitMultiLoopCond(sym: Sym[Any], funcs:List[Block[Any]], idx: Sym[Int], postfix: String="", stream:PrintWriter):(String,List[Exp[Any]]) = { - isNestedNode = true - devFuncIdx += 1 - val currIdx = devFuncIdx - val tempString = new StringWriter - val tempStream = new PrintWriter(tempString, true) - val header = new StringWriter - val footer = new StringWriter - - val currentTab = tabWidth - tabWidth = 1 - withStream(tempStream) { - emitFatBlock(funcs) - } - tabWidth = currentTab - - val inputs = getFreeVarBlock(Block(Combine(funcs.map(getBlockResultFull))),Nil).filterNot(quote(_)==quote(idx)).distinct - val paramStr = (inputs++List(idx)).map(ele=>remap(ele.tp)+" "+quote(ele)).mkString(",") - header.append(devFuncPrefix + " bool dev_%s(%s) {\n".format(postfix,paramStr)) - footer.append("\treturn %s;\n".format(funcs.map(f=>quote(getBlockResult(f))).mkString("&&"))) - footer.append("}\n") - stream.print(header) - stream.print(tempString) - stream.print(footer) - - //Register Metadata for loop function - val lf = metaData.loopFuncs.getOrElse(sym,new LoopFunc) - lf.hasCond = true - lf.loopCondInputs = inputs.map(quote) - metaData.loopFuncs.put(sym,lf) - isNestedNode = false - - ("dev_"+currIdx,inputs) - } - } diff --git a/src/internal/CudaDeviceTransfer.scala b/src/internal/CudaDeviceTransfer.scala new file mode 100644 index 00000000..3fd2bd73 --- /dev/null +++ b/src/internal/CudaDeviceTransfer.scala @@ -0,0 +1,134 @@ +package scala.lms.internal + +/* Defines Cuda specific device transfer functions */ +trait CudaDeviceTransfer extends AbstractDeviceTransfer { + this: CudaCodegen => + + val IR: Expressions + import IR._ + + + def emitSendSlave(tp: Manifest[_]): (String,String) = { + if (isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "%s sendCuda_%s(%s sym)".format(remap(tp),mangledName(remap(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\treturn sym;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "%s *sendCuda_%s(%s *sym)".format(remap(tp),mangledName(remap(tp)),remapHost(tp)) + out.append(signature + " {\n") + out.append("\t%s *sym_dev = new %s();\n".format(remap(tp),remap(tp))) + out.append("\treturn sym_dev;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + tp.toString) + } + } + + def emitRecvSlave(tp: Manifest[_]): (String,String) = { + if (isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "%s recvCuda_%s(%s *sym_dev)".format(remap(tp),mangledName(remap(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\t%s *hostPtr;\n".format(remap(tp))) + out.append("\tDeliteCudaMallocHost((void**)&hostPtr,sizeof(%s));\n".format(remap(tp))) + out.append("\tDeliteCudaMemcpyDtoHAsync(hostPtr, sym_dev, sizeof(%s));\n".format(remap(tp))) + out.append("\treturn *hostPtr;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "%s *recvCuda_%s(%s *sym_dev)".format(remapHost(tp),mangledName(remap(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\t%s *sym = new %s();\n".format(remapHost(tp),remapHost(tp))) + out.append("\treturn sym;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + tp.toString) + } + } +/* + def emitSendViewSlave(sym: Sym[Any]): (String,String) = { + if (isPrimitiveType(sym.tp)) { + val out = new StringBuilder + val signature = "%s sendViewCuda_%s(%s %s)".format(remap(sym.tp),quote(sym),remap(sym.tp),quote(sym)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn %s;\n".format(quote(sym))) + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + sym.tp.toString) + } + } + + def emitRecvViewSlave(sym: Sym[Any]): (String,String) = { + if (isPrimitiveType(sym.tp)) { + val out = new StringBuilder + val signature = "%s recvViewCuda_%s(%s %s)".format(remap(sym.tp),quote(sym),remap(sym.tp),quote(sym)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn %s;\n".format(quote(sym))) + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + sym.tp.toString) + } + } +*/ + def emitSendUpdateSlave(tp: Manifest[_]): (String,String) = { + if(isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "void sendUpdateCuda_%s(%s sym)".format(mangledName(remap(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "void sendUpdateCuda_%s(%s *sym_dev, %s *sym)".format(mangledName(remap(tp)),remap(tp),remapHost(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + tp.toString) + } + } + + def emitRecvUpdateSlave(tp: Manifest[_]): (String,String) = { + if(isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "void recvUpdateCuda_%s(%s sym)".format(mangledName(remap(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else if (tp.erasure == classOf[List[Any]]) { + val out = new StringBuilder + val signature = "void recvUpdateCuda_%s(%s *sym_dev, %s *sym)".format(mangledName(remap(tp)),remap(tp),remapHost(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("CudaDeviceTransfer: Unknown type " + tp.toString) + } + } + +} diff --git a/src/internal/FatCodegen.scala b/src/internal/FatCodegen.scala index 0588dded..497d3f5d 100644 --- a/src/internal/FatCodegen.scala +++ b/src/internal/FatCodegen.scala @@ -5,7 +5,7 @@ import util.GraphUtil import java.io.{File, PrintWriter} trait GenericFatCodegen extends GenericNestedCodegen with FatBlockTraversal { - val IR: Expressions with Effects with FatExpressions with LoweringTransform + val IR: Expressions with Effects with FatExpressions import IR._ @@ -31,4 +31,4 @@ trait GenericFatCodegen extends GenericNestedCodegen with FatBlockTraversal { emitBlock(Block(Combine(rhs.map(getBlockResultFull)))) // TODO: find another way } -} +} \ No newline at end of file diff --git a/src/internal/GPUCodegen.scala b/src/internal/GPUCodegen.scala index 6769fdc3..4ed86ad7 100644 --- a/src/internal/GPUCodegen.scala +++ b/src/internal/GPUCodegen.scala @@ -2,217 +2,80 @@ package scala.lms package internal import java.io.{StringWriter, PrintWriter, File} -import collection.mutable.{ArrayBuffer, HashMap, ListMap, HashSet} import collection.immutable.List._ import scala.reflect.SourceContext +import collection.mutable.{HashMap, HashSet, ArrayBuffer, ListMap, ListBuffer} -trait GPUCodegen extends CLikeCodegen { +trait GPUCodegen extends CLikeCodegen with AbstractHostTransfer with AbstractDeviceTransfer { val IR: Expressions import IR._ - /* Kernel input / output symbols */ - private var kernelInputs: List[Sym[Any]] = null - private var kernelOutputs: List[Sym[Any]] = null - def getKernelInputs = kernelInputs - def setKernelInputs(syms: List[Sym[Any]]): Unit = { kernelInputs = syms } - def getKernelOutputs = kernelOutputs - def setKernelOutputs(syms: List[Sym[Any]]): Unit = { kernelOutputs = syms } - def getKernelTemps = metaData.temps.toList.reverse.map(ele => ele._1) - def devFuncPrefix = "" + // Prefix string for device functions on the target GPU programming model (e.g., __device__ for CUDA) + def devFuncPrefix:String = "" - /* For using GPU local variables */ - final class GPUOptimizer { - // Map (collection,idx) -> localVar - var collToVar: HashMap[(Sym[Any],String),String] = HashMap[(Sym[Any],String),String]() - // Map variable symbol -> set of aliased symbols - var varToSet: HashMap[String,HashSet[String]] = HashMap[String,HashSet[String]]() - - /* - //TODO: deal with aliased collection - def hasLocalVar(coll:Sym[Any], idx: String): Boolean = { - var hit = false - for (i <- varToSet(idx)) { - if (collToVar contains (coll,i)) - hit = true - } - hit - } - def getLocalVar(coll:Sym[Any], idx: String): String = { - assert(hasLocalVar(coll,idx)) - for (i <- varToSet(idx) if (collToVar contains (coll,i))) { - return collToVar.get(coll,i).get - } - } - def registerAlias(sym:String,aliased:String) { - if (varToSet contains aliased) { - val set = varToSet.get(aliased).get - set.add(sym) - varToSet.put(sym,set) - } - else if (varToSet contains sym) { - val set = varToSet.get(sym).get - set.add(aliased) - varToSet.put(aliased,set) - } - else { - val set = HashSet[String](sym,aliased) - varToSet.put(sym,set) - varToSet.put(aliased,set) - } - println("resitested alias: %s = %s".format(sym,aliased)) - } - */ - //def registerLocalVarArith(sym:String, ) - //def registerLocalVar(key:(Sym[Any],String), value:String) { - // collToVar.put(key,value) - //} - } - var optimizer: GPUOptimizer = null - - /* Indicates current dimension of work threads */ - /* - var currDim = 0 - val xDimList = ListBuffer[String]() - val yDimList = ListBuffer[String]() - def getCurrDimStr():String = currDim match { - case 0 => throw new RuntimeException("GPUGen: Cannot get current dimension string when the dimension is 0.") - case 1 => "idxX" - //case 2 => "idxY" - case _ => throw new GenerationFailedException("GPUGen: Maximum 2 dimensions for GPU kernels.") - } - def getPrevDimStr():String = currDim match { - case 0 => throw new RuntimeException("GPUGen: Cannot get previous dimension string when the dimension is 0.") - case 1 => throw new RuntimeException("GPUGen: Cannot get previous dimension string when the dimension is 1.") - case 2 => "idxX" - //case 3 => "idxY" - case _ => throw new GenerationFailedException("GPUGen: Maximum 1 dimensions for GPU kernels.") - } - def getNextDimStr():String = currDim match { - case 0 => "idxX" - //case 1 => throw new RuntimeException("GPUGen: Cannot get next dimension string when the dimension is 1.") - case _ => throw new GenerationFailedException("GPUGen: Maximum 1 dimensions for GPU kernels.") - } - def setCurrDimLength(length: String) { - currDim match { - case 0 => throw new RuntimeException("GPUGen: Cannot set dimension length when the dimension is 0.") - case 1 => xDimList += length - //case 2 => yDimList += length - case _ => throw new GenerationFailedException("GPUGen: Maximum 1 dimensions for GPU kernels.") - } - } - val multDimInputs = ListBuffer[Sym[Any]]() - */ - - var helperFuncIdx = 0 - val kernelsList = ArrayBuffer[Exp[Any]]() - val helperFuncsList = ArrayBuffer[String]() - - var tabWidth:Int = 0 + // List of kernels and helper functions emitted so far (not to emit the same thing multiple times) + private val kernelsList = ArrayBuffer[Exp[Any]]() + protected val helperFuncList = ArrayBuffer[String]() + + // Current tab location for pretty printing + protected var tabWidth:Int = 0 def addTab():String = "\t"*tabWidth - var forceParallel = false - - var helperFuncString:StringBuilder = null - var hstream: PrintWriter = null - var helperFuncHdrStream: PrintWriter = null - //var devFuncString:StringBuilder = null var devFuncIdx = 0 - //var devStream: PrintWriter = null - //var headerStream: PrintWriter = null - var isGPUable:Boolean = false - var processingHelperFunc: Boolean = false var isNestedNode: Boolean = false - - def emitMultiLoopFunc(func:Block[Any], postfix: String, lastInputs: List[Sym[Any]], stream:PrintWriter): List[String] = { - isNestedNode = true - val tempString = new StringWriter - val tempStream = new PrintWriter(tempString, true) - val header = new StringWriter - val footer = new StringWriter - - val currentTab = tabWidth - tabWidth = 1 - withStream(tempStream) { - emitBlock(func) - } - tabWidth = currentTab - - val inputs = getFreeVarBlock(func,lastInputs).distinct - val paramStr = (inputs++lastInputs).map(ele=>remap(ele.tp)+" "+quote(ele)).mkString(",") - - header.append(devFuncPrefix + " %s dev_%s(%s) {\n".format(remap(getBlockResult(func).tp),postfix,paramStr)) - if(remap(getBlockResult(func).tp) != "void") - footer.append("\treturn %s;\n".format(quote(getBlockResult(func)))) - footer.append("}\n") - stream.print(header) - stream.print(tempString) - stream.print(footer) - - /* - if(loopType=="FOREACH") { - val tr = metaData.outputs.getOrElse(sym,new TransferFunc) - tr.funcHtoD = "" - tr.argsFuncHtoD = List() - tr.funcDtoH = "" - tr.argsFuncDtoH = List() - metaData.outputs.put(sym,tr) - } - */ - isNestedNode = false - inputs.map(quote(_)) + var outerLoopSize: Exp[Int] = null + var outerLoopSym: Exp[Int] = null + + //TODO: Get rid of this variable + protected var inVars = List[Sym[Any]]() + protected val boundMap = HashMap[Exp[Int],Exp[Int]]() + private val ptrSymSet = HashSet[Sym[Any]]() + + // GPU currently does not use reference types + override def remapWithRef[A](m: Manifest[A]): String = remap(m) + + protected def registerTempAlloc(sym:Sym[Any], tp:Manifest[Any], size:Exp[Int]):String = { + metaData.temps prepend TempAlloc(quote(sym)+"_temp",remap(tp),quote(size)) + quote(sym) + "_temp" } - // MetaData override def hasMetaData: Boolean = true override def getMetaData: String = metaData.toString var metaData: GPUMetaData = null - final class LoopFunc { - var tpe: String = "" - var hasCond: Boolean = false - var loopFuncInputs: List[String] = Nil - var loopFuncInputs_2: List[String] = Nil - var loopFuncOutputType: String = "" - var loopFuncOutputType_2: String = "" - var loopCondInputs: List[String] = Nil - var loopReduceInputs: List[String] = Nil - var loopReduceInputs_2: List[String] = Nil - var loopReduceParInputs: List[String] = Nil - var loopReduceParInputs_2: List[String] = Nil - var loopZeroInputs: List[String] = Nil - var loopZeroInputs_2: List[String] = Nil + final class LoopElem(val elemType: String, val types: Map[String,String]) { + val funcs = new HashMap[String,List[String]]() // Mapping of function name to the argument list override def toString: String = { - "\"" + tpe + "\"," + hasCond + ",[" + loopFuncInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopFuncInputs_2.map(i => "\""+ i +"\"").mkString(",") + "]" + - ",\"" + loopFuncOutputType + "\",\"" + loopFuncOutputType_2 + "\",[" + loopCondInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopReduceInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopReduceInputs_2.map(i => "\""+ i +"\"").mkString(",") + "]" + - ",[" + loopReduceParInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopReduceParInputs_2.map(i => "\""+ i +"\"").mkString(",") + "]" + - ",[" + loopZeroInputs.map(i => "\""+ i +"\"").mkString(",") + "],[" + loopZeroInputs_2.map(i => "\""+ i +"\"").mkString(",") + "]" + "{\"elemType\":\"" + + elemType + + "\",\"types\":" + + types.map(t => "\"" + t._1 + "\":\"" + t._2 + "\"").mkString("{",",","}") + + ",\"funcs\":" + + funcs.map(f => "\"" + f._1 + "\":[" + f._2.map(i => "\"" + i + "\"").mkString(",") + "]").mkString("{",",","}") + + "}" } } - final class TransferFunc { - var funcHtoD:String = "" - var argsFuncHtoD:List[Sym[Any]] = Nil - var funcDtoH:String = "" - var argsFuncDtoH:List[Sym[Any]] = Nil - //override def toString: String = { } - } + + case class TempAlloc(sym: String, tp: String, size:String) - final class GPUMetaData { - val inputs: ListMap[Sym[Any],TransferFunc] = ListMap() - val outputs: ListMap[Sym[Any],TransferFunc] = ListMap() - val temps: ListMap[Sym[Any],TransferFunc] = ListMap() + final class GPUMetaData(val kernelInputs: List[Sym[Any]], val auxMeta: ListBuffer[(String,Any)]) { + //val inputs: ListMap[Sym[Any],TransferFunc] = ListMap() + val outputs: ListMap[Sym[Any],LoopElem] = ListMap() + val temps: ListBuffer[TempAlloc] = ListBuffer() var gpuLibCall: String = "" - var loopFuncs: ListMap[Sym[Any],LoopFunc] = ListMap() override def toString: String = { val out = new StringBuilder out.append("{") //if (kernelFileExt == "cu") { - out.append("\"gpuInputs\":["+getKernelInputs.filter(in=>isObjectType(in.tp)).map(in=>"{\""+quote(in)+"\":[\""+remap(in.tp)+"\"]}").mkString(",")+"],") - out.append("\"gpuOutputs\":["+outputs.toList.reverse.map(out=>"{\""+quote(out._1)+"\":[\""+remap(out._1.tp)+"\",["+ out._2.argsFuncHtoD.map("\""+quote(_)+"\"").mkString(",")+"],"+loopFuncs.getOrElse(out._1,new LoopFunc).toString+"]}").mkString(",")+"]") + // out.append("\"gpuInputs\":["+kernelInputs.filter(in => !isPrimitiveType(in.tp)).map(in=>"{\""+quote(in)+"\":[\""+remap(in.tp)+"\"]}").mkString(",")+"],") + out.append("\"gpuOutputs\":{"+outputs.map(o => "\""+quote(o._1)+"\":"+o._2.toString).mkString(",")+"},") + out.append("\"gpuTemps\":["+temps.map(t=>"{\""+t.sym+"\":[\""+t.tp+"\",\""+t.size+"\"]}").mkString(",")+"],") + out.append("\"aux\":{"+auxMeta.map(m => "\"" + m._1 + "\":" + m._2.toString).mkString(",")+"}") //} //else { //opencl // out.append("\"gpuInputs\":["+getKernelInputs.filter(in=>isObjectType(in.Type)).map(in=>"{\""+quote(in)+"\":[\""+remap(in.Type)+"\",{"+unpackObject(in).map(f => "\"%s\":\"%s\"".format(f._1,remap(f._2)).replaceAll("__global ","")).mkString(",")+"}]}").mkString(",")+"],") @@ -224,35 +87,13 @@ trait GPUCodegen extends CLikeCodegen { } } - // Exception Handler function - override def exceptionHandler(e: Exception, outFile:File, kstream:PrintWriter): Unit = { - super.exceptionHandler(e, outFile, kstream) - // TODO: Need to cleanup some data structures - } - override def kernelInit(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultIsVar: Boolean): Unit = { - // Set kernel input and output symbols - setKernelInputs(vals) - setKernelOutputs(syms) + inVars = vars + boundMap.clear + ptrSymSet.clear - // Conditions for not generating GPU kernels (may be relaxed later) - //for (sym <- syms) { - // if((!isObjectType(sym.Type)) && (remap(sym.Type)!="void")) throw new GenerationFailedException("GPUGen: Not GPUable output type : %s".format(remap(sym.Type))) - //} - if((vars.length > 0) || (resultIsVar)) throw new GenerationFailedException("GPUGen: Not GPUable input/output types: Variable") - - // Initialize global variables - //useLocalVar = false - //GPUVarMap.clear - //optimizer = new GPUOptimizer - - //currDim = 0 - //xDimList.clear - //yDimList.clear - //multDimInputs.clear - - helperFuncString.clear - metaData = new GPUMetaData + //helperFuncString.clear + metaData = new GPUMetaData(vals, new ListBuffer[(String,Any)]()) tabWidth = 1 isGPUable = false processingHelperFunc = false @@ -262,13 +103,8 @@ trait GPUCodegen extends CLikeCodegen { override def emitKernelHeader(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { if (external) { // CUDA library ops use a C wrapper, so should be generated as a C kernel - stream.println(getDSLHeaders) - super.emitKernelHeader(syms, getKernelOutputs ::: vals, vars, resultType, resultIsVar, external) - return + super.emitKernelHeader(syms, syms ::: vals, vars, resultType, resultIsVar, external) } - val out = new StringBuilder - out.append(getDSLHeaders) - stream.print(out.toString) } override def emitKernelFooter(syms: List[Sym[Any]], vals: List[Sym[Any]], vars: List[Sym[Any]], resultType: String, resultIsVar: Boolean, external: Boolean): Unit = { @@ -282,255 +118,101 @@ trait GPUCodegen extends CLikeCodegen { // should probably be refactored... tabWidth -= 1 - // Emit input copy helper functions for object type inputs - for(v <- vals if isObjectType(v.tp)) { - helperFuncString.append(emitCopyInputHtoD(v, syms, copyInputHtoD(v))) - helperFuncString.append(emitCopyMutableInputDtoH(v, syms, copyMutableInputDtoH(v))) - } + dsTypesList ++= (syms++vals++vars).map(s => (s.tp,remap(s.tp))) // Print helper functions to file stream - hstream.print(helperFuncString) - hstream.flush - helperFuncHdrStream.flush - //headerStream.flush - } - - def registerKernel(syms: List[Sym[Any]]) { - isGPUable = true - if(kernelsList.intersect(syms).isEmpty) { - //headerStream.println("#include \"%s.%s\"".format(syms.map(quote).mkString(""),kernelFileExt)) - kernelsList ++= syms - } + helperFuncStream.flush + headerStream.flush + actRecordStream.flush + typesStream.flush } - override def remap[A](m: Manifest[A]) : String = { - checkGPUableType(m) - if (m.erasure == classOf[Variable[AnyVal]]) - remap(m.typeArguments.head) - else { - m.toString match { - case "Boolean" => "bool" - case "Byte" => "char" - case "Char" => "CHAR" - case "Short" => "short" - case "Int" => "int" - case "Long" => "long" - case "Float" => "float" - case "Double" => "double" - case "Unit" => "void" - case _ => throw new Exception("GPUGen: remap(m) : GPUable Type %s does not have mapping table.".format(m.toString)) + override def emitTransferFunctions() { + for ((tp,name) <- dsTypesList) { + // Emit input copy helper functions for object type inputs + //TODO: For now just iterate over all possible hosts, but later we can pick one depending on the input target + try { + val (recvHeader, recvSource) = emitRecv(tp, Targets.JVM) + if (!helperFuncList.contains(recvHeader)) { + headerStream.println(recvHeader) + helperFuncStream.println(recvSource) + helperFuncList.append(recvHeader) + } + val (recvViewHeader, recvViewSource) = emitRecvView(tp, Targets.JVM) + if (!helperFuncList.contains(recvViewHeader)) { + headerStream.println(recvViewHeader) + helperFuncStream.println(recvViewSource) + helperFuncList.append(recvViewHeader) + } + val (sendUpdateHeader, sendUpdateSource) = emitSendUpdate(tp, Targets.JVM) + if (!helperFuncList.contains(sendUpdateHeader)) { + headerStream.println(sendUpdateHeader) + helperFuncStream.println(sendUpdateSource) + helperFuncList.append(sendUpdateHeader) + } + val (recvUpdateHeader, recvUpdateSource) = emitRecvUpdate(tp, Targets.JVM) + if (!helperFuncList.contains(recvUpdateHeader)) { + headerStream.println(recvUpdateHeader) + helperFuncStream.println(recvUpdateSource) + helperFuncList.append(recvUpdateHeader) + } + val (sendSlaveHeader, sendSlaveSource) = emitSendSlave(tp) + if (!helperFuncList.contains(sendSlaveHeader)) { + headerStream.println(sendSlaveHeader) + helperFuncStream.println(sendSlaveSource) + helperFuncList.append(sendSlaveHeader) + } + val (sendUpdateSlaveHeader, sendUpdateSlaveSource) = emitSendUpdateSlave(tp) + if (!helperFuncList.contains(sendUpdateSlaveHeader)) { + headerStream.println(sendUpdateSlaveHeader) + helperFuncStream.println(sendUpdateSlaveSource) + helperFuncList.append(sendUpdateSlaveHeader) + } + val (recvUpdateSlaveHeader, recvUpdateSlaveSource) = emitRecvUpdateSlave(tp) + if (!helperFuncList.contains(recvUpdateSlaveHeader)) { + headerStream.println(recvUpdateSlaveHeader) + helperFuncStream.println(recvUpdateSlaveSource) + helperFuncList.append(recvUpdateSlaveHeader) + } + + // Emit output copy helper functions for object type inputs + val (sendHeader, sendSource) = emitSend(tp, Targets.JVM) + if (!helperFuncList.contains(sendHeader)) { + headerStream.println(sendHeader) + helperFuncStream.println(sendSource) + helperFuncList.append(sendHeader) + } + val (sendViewHeader, sendViewSource) = emitSendView(tp, Targets.JVM) + if (!helperFuncList.contains(sendViewHeader)) { + headerStream.println(sendViewHeader) + helperFuncStream.println(sendViewSource) + helperFuncList.append(sendViewHeader) + } + val (recvSlaveHeader, recvSlaveSource) = emitRecvSlave(tp) + if (!helperFuncList.contains(recvSlaveHeader)) { + headerStream.println(recvSlaveHeader) + helperFuncStream.println(recvSlaveSource) + helperFuncList.append(recvSlaveHeader) + } } - } - } - - def isPrimitiveType[A](m: Manifest[A]) : Boolean = { - m.toString match { - case "Boolean" | "Byte" | "Char" | "Short" | "Int" | "Long" | "Float" | "Double" => true - case _ => false - } - } - - def isVariableType[A](m: Manifest[A]) : Boolean = { - if(m.erasure == classOf[Variable[AnyVal]]) true - else false - } - - // Check the type and generate Exception if the type is not GPUable - def checkGPUableType[A](m: Manifest[A]) : Unit = { - if(!isGPUableType(m)) - throw new GenerationFailedException("GPUGen: Type %s is not a GPUable Type.".format(m.toString)) - } - - // All the types supported by GPU Generation - def isGPUableType[A](m : Manifest[A]) : Boolean = { - if(!isObjectType(m) && !isPrimitiveType(m) && !isVoidType(m) && !isVariableType(m)) - false - else - true - } - - def unpackObject[A](sym: Sym[Any]) : Map[String,Manifest[_]] = remap(sym.tp) match { - case _ => throw new GenerationFailedException("GPUCodegen: Type %s cannot be unpacked.".format(sym.tp.toString)) - } - - def copyInputHtoD(sym: Sym[Any]) : String - def copyOutputDtoH(sym: Sym[Any]) : String - def copyMutableInputDtoH(sym: Sym[Any]) : String - def allocOutput(newSym: Sym[_], sym: Sym[_], reset: Boolean = false) : Unit - def allocReference(newSym: Sym[Any], sym: Sym[Any]) : Unit - def positionMultDimInputs(sym: Sym[Any]) : String - def cloneObject(sym: Sym[Any], src: Sym[Any]) : String - - - /******************************************************* - * Methods below are for emitting helper functions - *******************************************************/ - // TODO: Change the metadata function names - - // For object type inputs, allocate GPU memory and copy from CPU to GPU. - def emitCopyInputHtoD(sym: Sym[Any], ksym: List[Sym[Any]], contents: String) : String = { - val out = new StringBuilder - val funcName = "copyInputHtoD_%s_%s".format(ksym.map(quote).mkString(""),quote(sym)) - if(isObjectType(sym.tp) && !helperFuncsList.contains(funcName)) { - helperFuncsList += funcName - out.append("%s *%s(JNIEnv *env, jobject obj)".format(remap(sym.tp),funcName)) - helperFuncHdrStream.append(out.toString + ";\n") - out.append("{\n") - out.append(contents) - out.append("}\n") - out.toString - } - else "" - } - - // For mutable inputs, copy the mutated datastructure from GPU to CPU after the kernel is terminated - def emitCopyMutableInputDtoH(sym: Sym[Any], ksym: List[Sym[Any]], contents: String): String = { - val out = new StringBuilder - val funcName = "copyMutableInputDtoH_%s_%s".format(ksym.map(quote).mkString(""),quote(sym)) - if(isObjectType(sym.tp) && !helperFuncsList.contains(funcName)) { - helperFuncsList += funcName - out.append("void %s(JNIEnv *env, jobject obj, %s *%s_ptr)".format(funcName,remap(sym.tp),quote(sym))) - helperFuncHdrStream.append(out.toString + ";\n") - out.append("{\n") - out.append("%s %s = *(%s_ptr);\n".format(remap(sym.tp),quote(sym),quote(sym))) - out.append(contents) - out.append("}\n") - out.toString - } - else "" - } - - def emitAllocOutput(sym: Sym[Any], ksym: List[Sym[Any]], contents: String, args: List[Sym[Any]], aV: Sym[Any]): String = { - val out = new StringBuilder - val funcName = "allocFunc_%s".format(quote(sym)) - if(helperFuncsList contains funcName) return "" - helperFuncsList += funcName - - if(!isPrimitiveType(sym.tp)) { - val paramStr = args.map(ele => - if(isPrimitiveType(ele.tp)) remap(ele.tp) + " " + quote(ele) - else remap(ele.tp) + " *" + quote(ele) + "_ptr" - ).mkString(",") - val derefParams = args.map(ele=> - if(isPrimitiveType(ele.tp)) "" - else "\t%s %s = *(%s_ptr);\n".format(remap(ele.tp),quote(ele),quote(ele)) - ).mkString("") - out.append("%s *%s(%s %s)".format(remap(sym.tp), funcName, paramStr, if(args.nonEmpty) ",int size" else "int size")) - helperFuncHdrStream.append(out.toString + ";\n") - out.append("{\n") - out.append(derefParams) - //out.append("\t%s *%s_ptr = new %s(size);\n".format(remap(aV.tp),quote(aV),remap(aV.tp))) - //out.append("\t%s %s = *%s_ptr;\n".format(remap(aV.tp),quote(aV),quote(aV))) - out.append(contents) - out.append("}\n") - out.toString - } - else { - out.append("%s *%s(void)".format(remap(sym.tp),funcName)) - helperFuncHdrStream.append(out.toString + ";\n") - out.append("{\n") - out.append(contents) - out.append("}\n") - out.toString - } - } - - def emitCopyOutputDtoH(sym: Sym[Any], ksym: List[Sym[Any]], contents: String): String = { - val out = new StringBuilder - val funcName = "copyOutputDtoH_%s".format(quote(sym)) - if(helperFuncsList contains funcName) return "" - helperFuncsList += funcName - - if(isObjectType(sym.tp)) { - out.append("jobject %s(JNIEnv *env,%s)".format(funcName,remap(sym.tp)+" *"+quote(sym)+"_ptr")) - helperFuncHdrStream.append(out.toString + ";\n") - out.append("{\n") - out.append("\t%s %s = *(%s_ptr);\n".format(remap(sym.tp),quote(sym),quote(sym))) - out.append(contents) - out.append("}\n") - out.toString - } - else { - out.append("%s %s(JNIEnv *env,%s)".format(remap(sym.tp),funcName,remap(sym.tp)+" *"+quote(sym))) - helperFuncHdrStream.append(out.toString + ";\n") - out.append("{\n") - out.append(contents) - out.append("}\n") - out.toString - } - } - - /* emitAllocFunc method emits code for allocating the output memory of a kernel, - and copying it to CPU memory with allocation of new object in CPU */ - //TODO: Separate output and temporary allocations - def emitAllocFunc(sym:Sym[Any], allocFunc:Block[Any], aV:Sym[Any]=null, size:Exp[Any]=null) { - processingHelperFunc = true - val tempString = new StringWriter - val tempString2 = new StringWriter - val tempStream = new PrintWriter(tempString,true) - - // Get free variables (exclude the arrayVariable) - val inputs = if(allocFunc==null) Nil - else getFreeVarBlock(allocFunc,List(aV)) - - // Register metadata - val tr = metaData.outputs.getOrElse(sym,new TransferFunc) - tr.argsFuncHtoD = inputs - metaData.outputs.put(sym,tr) - - // Get the body (string) of the allocation function in tempString - if(allocFunc!=null) { - withStream(tempStream) { - emitBlock(allocFunc) + catch { + case e: GenerationFailedException => + helperFuncStream.flush + headerStream.flush + case e: Exception => throw(e) } - tempString.append("\treturn %s_ptr;\n".format(quote(getBlockResult(allocFunc)))) - } - else { - tempString.append("\treturn %s_ptr;\n".format(quote(sym))) } - // Emit the full allocation function - val allocOutputStr = emitAllocOutput(sym, null, tempString.toString, inputs, aV) - - // Generate copy (D->H) helper function - tempString2.append(copyOutputDtoH(sym)) - val copyOutputStr = emitCopyOutputDtoH(sym, null, tempString2.toString) - - // Write to helper function string - helperFuncString.append(allocOutputStr) - helperFuncString.append(copyOutputStr) - - processingHelperFunc = false + helperFuncStream.flush + headerStream.flush } - def emitAllocFuncPrimitive(sym:Sym[Any]) { - processingHelperFunc = true - assert(isPrimitiveType(sym.tp)) - - val tempString = new StringWriter - val tempString2 = new StringWriter - - // Register metadata - val tr = metaData.outputs.getOrElse(sym,new TransferFunc) - tr.argsFuncHtoD = Nil - metaData.outputs.put(sym,tr) - - tempString.append("\t%s *ptr;\n".format(remap(sym.tp))) - tempString.append("\tDeliteCudaMalloc((void**)&ptr, sizeof(%s));\n".format(remap(sym.tp))) - tempString.append("\treturn ptr;\n") - - // Emit the full allocation function - val allocOutputStr = emitAllocOutput(sym, null, tempString.toString, null, null) - - // Generate copy (D->H) helper function - tempString2.append(copyOutputDtoH(sym)) - val copyOutputStr = emitCopyOutputDtoH(sym, null, tempString2.toString) - - // Write to helper function string - helperFuncString.append(allocOutputStr) - helperFuncString.append(copyOutputStr) - - processingHelperFunc = false + def registerKernel(syms: List[Sym[Any]]) { + isGPUable = true + if(kernelsList.intersect(syms).isEmpty) { + //headerStream.println("#include \"%s.%s\"".format(syms.map(quote).mkString(""),kernelFileExt)) + kernelsList ++= syms + } } def checkGPUAlloc(sym: Sym[Any]) { @@ -558,4 +240,21 @@ trait GPUCodegen extends CLikeCodegen { println(msg) println("Stack Trace: " + quotePos(sym)) } + + def clearPtrDef() = ptrSymSet.clear + + def registerPtrDef(sym: Sym[Any]): Unit = ptrSymSet.add(sym) + + def emitPtrDef(sym: Sym[Any], rhs: Exp[Any]): Unit = { + if(processingHelperFunc && !isPrimitiveType(sym.tp)) { + rhs match { + case s@Sym(_) => + if(!ptrSymSet.contains(s)) throw new GenerationFailedException("Ptr is not defined for " + quote(s)) + emitValDef(quote(sym) + "_ptr", sym.tp, quote(rhs) + "_ptr") + registerPtrDef(s) + case _ => throw new GenerationFailedException("Ptr is not defined for " + quote(rhs)) + } + } + } + } diff --git a/src/internal/OpenCLCodegen.scala b/src/internal/OpenCLCodegen.scala index 545d7c48..321cd47f 100755 --- a/src/internal/OpenCLCodegen.scala +++ b/src/internal/OpenCLCodegen.scala @@ -4,165 +4,40 @@ package internal import java.io.{FileWriter, StringWriter, PrintWriter, File} import java.util.ArrayList import collection.mutable.{ListBuffer, ArrayBuffer, LinkedList, HashMap} -import collection.mutable.{Map => MMap} import collection.immutable.List._ -trait OpenCLCodegen extends GPUCodegen { +trait OpenCLCodegen extends GPUCodegen with CppHostTransfer with OpenCLDeviceTransfer { val IR: Expressions import IR._ + override def deviceTarget: Targets.Value = Targets.OpenCL + override def kernelFileExt = "cl" override def toString = "opencl" - override def initializeGenerator(buildDir:String, args: Array[String], _analysisResults: MMap[String,Any]): Unit = { + override def initializeGenerator(buildDir:String, args: Array[String]): Unit = { val outDir = new File(buildDir) outDir.mkdirs - helperFuncIdx = 0 - helperFuncString = new StringBuilder - hstream = new PrintWriter(new FileWriter(buildDir + "helperFuncs.cpp")) - helperFuncHdrStream = new PrintWriter(new FileWriter(buildDir + "helperFuncs.h")) + helperFuncStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.cpp")) + helperFuncStream.println("#include \"" + deviceTarget + "helperFuncs.h\"") + typesStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "types.h")) + //TODO: Put all the DELITE APIs declarations somewhere - hstream.print("#include \"helperFuncs.h\"\n") - helperFuncHdrStream.print(getDSLHeaders) - helperFuncHdrStream.print("#include \n") - helperFuncHdrStream.print("#include \n") - helperFuncHdrStream.print("#include \n\n") - helperFuncHdrStream.print("#define CHAR short\n") - helperFuncHdrStream.print("#define jCHAR jshort\n") - helperFuncHdrStream.print("#include \"DeliteOpenCL.h\"\n") - helperFuncHdrStream.print("#include \"DeliteArray.h\"\n") - - super.initializeGenerator(buildDir, args, _analysisResults) - } - - /* - override def isObjectType[A](m: Manifest[A]) : Boolean = { - m.toString match { - case "scala.collection.immutable.List[Int]" => true - //TODO: ObjectTypes needs to be able to broken down, but array does not have to be. - //TODO: What we need to do is to distinguish between passable types or not to the opencl kernel - case "Array[Int]" | "Array[Long]" | "Array[Float]" | "Array[Double]" | "Array[Boolean]" => true - case _ => super.isObjectType(m) - } - } - */ - - /* - override def remap[A](m: Manifest[A]) : String = { - checkGPUableType(m) - if (m.erasure == classOf[Variable[AnyVal]]) - remap(m.typeArguments.head) - else { - m.toString match { - case "Int" => "int" - case "Long" => "long" - case "Float" => "float" - case "Double" => "double" - case "Boolean" => "char" - case "Unit" => "void" - case "scala.Tuple2[Int,Float]" => "Tuple2_Int_Float" - case "scala.collection.immutable.List[Int]" => "OpenCLIntList" //TODO: Use C++ list - //TODO: When retrieving the type arguments of array from Manifest works, then below can be simplified - //case "Array[Int]" | "Array[Long]" | "Array[Float]" | "Array[Double]" | "Array[Boolean]" => remap(m.typeArguments(0)) + " *" - //TODO: Is it appropriate to put global here? - case "Array[Int]" => "__global int *" - case "Array[Long]" => "__global long *" - case "Array[Float]" => "__global float *" - case "Array[Double]" => "__global double *" - case "Array[Boolean]" => "__global char *" - case _ => throw new Exception("OpenCLGen: remap(m) : GPUable Type %s does not have mapping table.".format(m.toString)) - } - } - } - */ - - /* - override def unpackObject[A](sym: Sym[Any]) : Map[String,Manifest[_]] = remap(sym.Type) match { - case "OpenCLIntList" => Map("length"->Manifest.Int) //TODO: How to initialize the data array type for the list? - case _ => throw new GenerationFailedException("OpenCLGen: Type %s cannot be unpacked.".format(sym.Type.toString)) - } - */ - - // TODO: Move to Delite? - def copyInputHtoD(sym: Sym[Any]) : String = { - checkGPUableType(sym.tp) - remap(sym.tp) match { - case "DeliteArray_bool" | "DeliteArray_char" | "DeliteArray_CHAR" | "DeliteArray_short" | "DeliteArray_int" | "DeiteArray_long" | "DeliteArray_float" | "DeliteArray_double" => - val out = new StringBuilder - val typeArg = sym.tp.typeArguments.head - val numBytesStr = "length * sizeof(%s)".format(remap(typeArg)) - out.append("\tint length = env->GetArrayLength((j%sArray)obj);\n".format(remapToJNI(typeArg).toLowerCase)) - out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)obj,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) - out.append("\t%s *%s = new %s(length);\n".format(remap(sym.tp),quote(sym),remap(sym.tp))) - out.append("\tDeliteOpenCLMemcpyHtoDAsync(%s->data, dataPtr, %s);\n".format(quote(sym),numBytesStr)) - out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)obj, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) - out.append("\treturn %s;\n".format(quote(sym))) - out.toString - case _ => throw new Exception("OpenCLGen: copyInputHtoD(sym) : Cannot copy to GPU device (%s)".format(remap(sym.tp))) - } - } - - def copyOutputDtoH(sym: Sym[Any]) : String = { - checkGPUableType(sym.tp) - if (isPrimitiveType(sym.tp)) { - val out = new StringBuilder - out.append("\t%s data;\n".format(remap(sym.tp))) - out.append("\tDeliteOpenCLMemcpyDtoHAsync(&data, %s, sizeof(%s));\n".format(quote(sym),remap(sym.tp))) - out.append("\treturn data;\n") - out.toString - } - else { - remap(sym.tp) match { - case "DeliteArray_bool" | "DeliteArray_char" | "DeliteArray_CHAR" | "DeliteArray_short" | "DeliteArray_int" | "DeiteArray_long" | "DeliteArray_float" | "DeliteArray_double" => - val out = new StringBuilder - val typeArg = sym.tp.typeArguments.head - val numBytesStr = "%s.length * sizeof(%s)".format(quote(sym),remap(typeArg)) - out.append("\tj%sArray arr = env->New%sArray(%s.length);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg),quote(sym))) - out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)arr,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) - out.append("\tDeliteOpenCLMemcpyDtoHAsync(dataPtr, %s.data, %s);\n".format(quote(sym),numBytesStr)) - out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)arr, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) - out.append("\treturn arr;\n") - out.toString - case _ => throw new Exception("OpenCLGen: copyOutputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) - } - } - } - - def copyMutableInputDtoH(sym: Sym[Any]) : String = { - checkGPUableType(sym.tp) - remap(sym.tp) match { - case "DeliteArray_bool" | "DeliteArray_char" | "DeliteArray_CHAR" | "DeliteArray_short" | "DeliteArray_int" | "DeiteArray_long" | "DeliteArray_float" | "DeliteArray_double" => - val out = new StringBuilder - val typeArg = sym.tp.typeArguments.head - val numBytesStr = "length * sizeof(%s)".format(remap(typeArg)) - out.append("\tint length = %s.length;\n".format(quote(sym))) - out.append("\tj%s *dataPtr = (j%s *)env->GetPrimitiveArrayCritical((j%sArray)obj,0);\n".format(remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase,remapToJNI(typeArg).toLowerCase)) - out.append("\tDeliteOpenCLMemcpyDtoHAsync(dataPtr, %s.data, %s);\n".format(quote(sym),numBytesStr)) - out.append("\tenv->ReleasePrimitiveArrayCritical((j%sArray)obj, dataPtr, 0);\n".format(remapToJNI(typeArg).toLowerCase)) - out.toString - case _ => throw new Exception("OpenCLGen: copyMutableInputDtoH(sym) : Cannot copy from GPU device (%s)".format(remap(sym.tp))) - } - } - - //TODO: Remove below methods - def allocOutput(newSym: Sym[_], sym: Sym[_], reset: Boolean = false) : Unit = { - throw new GenerationFailedException("OpenCLGen: allocOutput(newSym, sym) : Cannot allocate GPU memory (%s)".format(remap(sym.tp))) - } - def allocReference(newSym: Sym[Any], sym: Sym[Any]) : Unit = { - throw new GenerationFailedException("OpenCLGen: allocReference(newSym, sym) : Cannot allocate GPU memory (%s)".format(remap(sym.tp))) - } - - def positionMultDimInputs(sym: Sym[Any]) : String = { - throw new GenerationFailedException("OpenCLGen: positionMultDimInputs(sym) : Cannot reposition GPU memory (%s)".format(remap(sym.tp))) - - } - - def cloneObject(sym: Sym[Any], src: Sym[Any]) : String = { - throw new GenerationFailedException("OpenCLGen: cloneObject(sym)") + headerStream = new PrintWriter(new FileWriter(buildDir + deviceTarget + "helperFuncs.h")) + headerStream.println("#include ") + headerStream.println("#include ") + headerStream.println("#include ") + headerStream.println("#include ") + headerStream.println("#include \"DeliteOpenCL.h\"") + headerStream.println("#include \"" + deviceTarget + "types.h\"") + headerStream.println(getDataStructureHeaders()) + + super.initializeGenerator(buildDir, args) } def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], className: String, out: PrintWriter) = { + val sB = manifest[A].toString withStream(out) { @@ -186,80 +61,16 @@ trait OpenCLCodegen extends GPUCodegen { Nil } - def emitValDef(sym: Sym[Any], rhs: String): Unit = { - stream.println(addTab() + remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") - } - - def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = { - stream.println(addTab()+ remap(sym.tp) + " " + quote(sym) + " = " + rhs + ";") - } - - def emitAssignment(sym: Sym[Any], lhs:String, rhs: String): Unit = { - stream.println(addTab() + " " + lhs + " = " + rhs + ";") - } - } // TODO: do we need this for each target? trait OpenCLNestedCodegen extends CLikeNestedCodegen with OpenCLCodegen { - val IR: Expressions with Effects with LoweringTransform + val IR: Expressions with Effects import IR._ - - def OpenCLConsts(x:Exp[Any], s:String): String = { - s match { - case "Infinity" => "std::numeric_limits<%s>::max()".format(remap(x.tp)) - case _ => s - } - } - - override def quote(x: Exp[Any]) = x match { // TODO: quirk! - case Const(s: String) => "\""+s+"\"" - case Const(s: Char) => "'"+s+"'" - case Const(null) => "NULL" - case Const(z) => OpenCLConsts(x, z.toString) - case Sym(-1) => "_" - case _ => super.quote(x) - } } trait OpenCLFatCodegen extends CLikeFatCodegen with OpenCLCodegen { - val IR: Expressions with Effects with FatExpressions with LoweringTransform - import IR._ - - def emitMultiLoopCond(sym: Sym[Any], funcs:List[Block[Any]], idx: Sym[Int], postfix: String="", stream:PrintWriter):(String,List[Exp[Any]]) = { - isNestedNode = true - devFuncIdx += 1 - val currIdx = devFuncIdx - val tempString = new StringWriter - val tempStream = new PrintWriter(tempString, true) - val header = new StringWriter - val footer = new StringWriter - - val currentTab = tabWidth - tabWidth = 1 - withStream(tempStream) { - emitFatBlock(funcs) - } - tabWidth = currentTab - - val inputs = getFreeVarBlock(Block(Combine(funcs.map(getBlockResultFull))),Nil).filterNot(quote(_)==quote(idx)).distinct - val paramStr = (inputs++List(idx)).map(ele=>remap(ele.tp)+" "+quote(ele)).mkString(",") - header.append("bool dev_%s(%s) {\n".format(postfix,paramStr)) - footer.append("\treturn %s;\n".format(funcs.map(f=>quote(getBlockResult(f))).mkString("&&"))) - footer.append("}\n") - stream.print(header) - stream.print(tempString) - stream.print(footer) - - //Register Metadata for loop function - val lf = metaData.loopFuncs.getOrElse(sym,new LoopFunc) - lf.hasCond = true - lf.loopCondInputs = inputs.map(quote) - metaData.loopFuncs.put(sym,lf) - isNestedNode = false - - ("dev_"+currIdx,inputs) - } - + val IR: Expressions with Effects with FatExpressions + import IR._ } diff --git a/test-out/epfl/test10-effects1.check b/test-out/epfl/test10-effects1.check index a9df5c5f..fab9aa63 100644 --- a/test-out/epfl/test10-effects1.check +++ b/test-out/epfl/test10-effects1.check @@ -1,5 +1,5 @@ killing: List(Sym(1))/List(Sym(1), Sym(2)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) -**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(3),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2)))), TP(Sym(5),Mutate(Sym(2),Sym(3))), TP(Sym(6),VectorApply(Sym(5),Const(0))), TP(Sym(7),Reflect(Print(Sym(6)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())), TP(Sym(8),Reify(Sym(7),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(7))))) +**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(3),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2)))), TP(Sym(5),Mutate(Sym(2),Sym(3))), TP(Sym(6),VectorApply(Sym(5),Const(0))), TP(Sym(7),Reflect(Print(Sym(6)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(8),Reify(Sym(7),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(7))))) /***************************************** Emitting Generated Code *******************************************/ @@ -9,11 +9,12 @@ val x1 = VectorZeros(Const(100)) val x2 = VectorLiteral(List(Sym(1))) // begin multi // soft deps: x1,x2 -VectorUpdate(Sym(1),Const(5),Const(7.0)) +val x3 = VectorUpdate(Sym(1),Const(5),Const(7.0)) val x5 = x2 // mutated by x3 // end multi val x6 = VectorApply(Sym(5),Const(0)) -println(x6) +val x7 = println(x6) +x7 } } /***************************************** diff --git a/test-out/epfl/test10-effects2.check b/test-out/epfl/test10-effects2.check index 43c1d4d6..c5d02d2c 100644 --- a/test-out/epfl/test10-effects2.check +++ b/test-out/epfl/test10-effects2.check @@ -1,25 +1,26 @@ cse: Sym(2) -> Sym(1) killing: List(Sym(1))/List(Sym(1), Sym(2), Sym(3), Sym(4)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) -**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(3),VectorLiteral(List(Sym(1)))), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(8),Mutate(Sym(3),Sym(5))), TP(Sym(10),VectorApply(Sym(8),Const(0))), TP(Sym(12),Reflect(Print(Sym(10)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())), TP(Sym(2),Copy(Sym(1))), TP(Sym(4),VectorLiteral(List(Sym(2)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(11),VectorApply(Sym(9),Const(0))), TP(Sym(13),Reflect(Print(Sym(11)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))), TP(Sym(14),Reify(Sym(13),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12), Sym(13))))) +**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(3),VectorLiteral(List(Sym(1)))), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(8),Mutate(Sym(3),Sym(5))), TP(Sym(10),VectorApply(Sym(8),Const(0))), TP(Sym(12),Reflect(Print(Sym(10)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(2),Copy(Sym(1))), TP(Sym(4),VectorLiteral(List(Sym(2)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(11),VectorApply(Sym(9),Const(0))), TP(Sym(13),Reflect(Print(Sym(11)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))), TP(Sym(14),Reify(Sym(13),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12), Sym(13))))) /***************************************** Emitting Generated Code *******************************************/ class Test extends ((Int)=>(Unit)) { def apply(x0:Int): Unit = { val x1 = VectorZeros(Const(100)) -val x2 = x1.clone val x3 = VectorLiteral(List(Sym(1))) +val x2 = x1.clone val x4 = VectorLiteral(List(Sym(2))) // begin multi // soft deps: x1,x2,x3,x4 -VectorUpdate(Sym(1),Const(5),Const(7.0)) +val x5 = VectorUpdate(Sym(1),Const(5),Const(7.0)) val x8 = x3 // mutated by x5 val x9 = x4 // mutated by x5 // end multi val x10 = VectorApply(Sym(8),Const(0)) -println(x10) +val x12 = println(x10) val x11 = VectorApply(Sym(9),Const(0)) -println(x11) +val x13 = println(x11) +x13 } } /***************************************** diff --git a/test-out/epfl/test10-effects3.check b/test-out/epfl/test10-effects3.check index 37ddf772..35d7e4f4 100644 --- a/test-out/epfl/test10-effects3.check +++ b/test-out/epfl/test10-effects3.check @@ -1,6 +1,6 @@ cse: Sym(2) -> Sym(1) killing: List(Sym(1))/List(Sym(1), Sym(2), Sym(3), Sym(4)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) -**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),Copy(Sym(1))), TP(Sym(3),VectorLiteral(List(Sym(2)))), TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(10),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(4)))), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(9), Sym(10))))) +**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),Copy(Sym(1))), TP(Sym(3),VectorLiteral(List(Sym(2)))), TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(10),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(4)))), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(9), Sym(10))))) /***************************************** Emitting Generated Code *******************************************/ @@ -9,13 +9,14 @@ def apply(x0:Int): Unit = { val x1 = VectorZeros(Const(100)) val x2 = x1.clone val x3 = VectorLiteral(List(Sym(2))) -println(x3) +val x4 = println(x3) // begin multi -// soft deps: x1,x2,x3, -VectorUpdate(Sym(1),Const(5),Const(7.0)) +// soft deps: x1,x2,x3,x4 +val x5 = VectorUpdate(Sym(1),Const(5),Const(7.0)) val x9 = x4 // mutated by x5 // end multi -println(x3) +val x10 = println(x3) +x10 } } /***************************************** diff --git a/test-out/epfl/test10-effects4.check b/test-out/epfl/test10-effects4.check index a8711169..888b08a3 100644 --- a/test-out/epfl/test10-effects4.check +++ b/test-out/epfl/test10-effects4.check @@ -1,6 +1,6 @@ cse: Sym(3) -> Sym(2) killing: List(Sym(1))/List(Sym(1), Sym(2), Sym(3)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) -**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(4),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3)))), TP(Sym(6),Mutate(Sym(2),Sym(4))), TP(Sym(8),VectorApply(Sym(6),Const(0))), TP(Sym(10),Reflect(Print(Sym(8)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10))))) +**fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(4),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3)))), TP(Sym(6),Mutate(Sym(2),Sym(4))), TP(Sym(8),VectorApply(Sym(6),Const(0))), TP(Sym(10),Reflect(Print(Sym(8)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10))))) /***************************************** Emitting Generated Code *******************************************/ @@ -10,11 +10,12 @@ val x1 = VectorZeros(Const(100)) val x2 = VectorLiteral(List(Sym(1))) // begin multi // soft deps: x1,x2,x3 -VectorUpdate(Sym(1),Const(5),Const(7.0)) +val x4 = VectorUpdate(Sym(1),Const(5),Const(7.0)) val x6 = x2 // mutated by x4 // end multi val x8 = VectorApply(Sym(6),Const(0)) -println(x8) +val x10 = println(x8) +x10 } } /***************************************** diff --git a/test-out/epfl/test10-misc1.check b/test-out/epfl/test10-misc1.check index ddc360ad..1f9c7d9e 100644 --- a/test-out/epfl/test10-misc1.check +++ b/test-out/epfl/test10-misc1.check @@ -2,18 +2,18 @@ TP(Sym(1),VectorZeros(Const(100))) TP(Sym(2),VectorPlus(Sym(1),Sym(1))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(4)))) +TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(4)))) -- before transformation val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -println(x3) +val x4 = println(x3) replacing TP(Sym(2),VectorPlus(Sym(1),Sym(1))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(2),Sym(1)) -println(x3) +val x4 = println(x3) -- done diff --git a/test-out/epfl/test10-misc2.check b/test-out/epfl/test10-misc2.check index aba09082..59b395fd 100644 --- a/test-out/epfl/test10-misc2.check +++ b/test-out/epfl/test10-misc2.check @@ -4,30 +4,30 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -- before transformation val x4 = x0 == 0 -if (x4) { +val x10 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x6 = println(x5) +x6 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x8 = println(x5) +x8 } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) error: java.lang.AssertionError: assertion failed: already defined: List(TP(Sym(3),VectorPlus(Sym(2),Sym(1)))) for List(TP(Sym(3),VectorPlus(Sym(1),Sym(2)))) -- done diff --git a/test-out/epfl/test10-misc3.check b/test-out/epfl/test10-misc3.check index f306cc6f..d2fd9788 100644 --- a/test-out/epfl/test10-misc3.check +++ b/test-out/epfl/test10-misc3.check @@ -4,91 +4,91 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) TP(Sym(11),Equal(Sym(0),Const(1))) -TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))) -TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(14)))) -TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) +TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))) +TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(14)))) +TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) -- before transformation val x4 = x0 == 0 -if (x4) { +val x10 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x6 = println(x5) +x6 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x8 = println(x5) +x8 } val x11 = x0 == 1 -if (x11) { +val x16 = if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x12 = println(x5) +x12 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x14 = println(x5) +x14 } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) *** conflict TP(Sym(3),VectorPlus(Sym(1),Sym(2))) *** conflict TP(Sym(5),VectorLength(Sym(18))) -encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) *** conflict TP(Sym(3),VectorPlus(Sym(1),Sym(2))) *** conflict TP(Sym(5),VectorLength(Sym(20))) -- after transformation val x4 = x0 == 0 -if (x4) { +val x10 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(2),Sym(1)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x6 = println(x5) +x6 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(1),Sym(2)) val x19 = VectorLength(Sym(18)) -println(x19) - +val x8 = println(x19) +x8 } val x11 = x0 == 1 -if (x11) { +val x16 = if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(2),Sym(1)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x12 = println(x5) +x12 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x20 = VectorPlus(Sym(1),Sym(2)) val x21 = VectorLength(Sym(20)) -println(x21) - +val x14 = println(x21) +x14 } // note how the last else branch lost sharing of common subexpressions // this is because NestedBlockTransformer does not go through findOrCreateDefinition diff --git a/test-out/epfl/test10-misc4.check b/test-out/epfl/test10-misc4.check index 0a03bb01..34efd0a0 100644 --- a/test-out/epfl/test10-misc4.check +++ b/test-out/epfl/test10-misc4.check @@ -4,87 +4,87 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) TP(Sym(11),Equal(Sym(0),Const(1))) -TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))) -TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(14)))) -TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) +TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))) +TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(14)))) +TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) -- before transformation val x4 = x0 == 0 -if (x4) { +val x10 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x6 = println(x5) +x6 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x8 = println(x5) +x8 } val x11 = x0 == 1 -if (x11) { +val x16 = if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x12 = println(x5) +x12 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x14 = println(x5) +x14 } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x18 = x0 == 0 -if (x18) { +val x29 = if (x18) { val x19 = VectorZeros(Const(100)) val x20 = VectorZeros(Const(50)) val x21 = VectorPlus(Sym(20),Sym(19)) val x22 = VectorLength(Sym(21)) -println(x22) - +val x23 = println(x22) +x23 } else { val x19 = VectorZeros(Const(100)) val x20 = VectorZeros(Const(50)) val x25 = VectorPlus(Sym(19),Sym(20)) val x26 = VectorLength(Sym(25)) -println(x26) - +val x27 = println(x26) +x27 } val x30 = x0 == 1 -if (x30) { +val x35 = if (x30) { val x19 = VectorZeros(Const(100)) val x20 = VectorZeros(Const(50)) val x21 = VectorPlus(Sym(20),Sym(19)) val x22 = VectorLength(Sym(21)) -println(x22) - +val x31 = println(x22) +x31 } else { val x19 = VectorZeros(Const(100)) val x20 = VectorZeros(Const(50)) val x25 = VectorPlus(Sym(19),Sym(20)) val x26 = VectorLength(Sym(25)) -println(x26) - +val x33 = println(x26) +x33 } // note how the else branches share symbols for expressions again (cf misc3) // but we have created new identifiers for everything. diff --git a/test-out/epfl/test10-misc5.check b/test-out/epfl/test10-misc5.check index 8c23577b..056fdbbe 100644 --- a/test-out/epfl/test10-misc5.check +++ b/test-out/epfl/test10-misc5.check @@ -4,87 +4,87 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) TP(Sym(11),Equal(Sym(0),Const(1))) -TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))) -TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(14)))) -TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) +TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))) +TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(14)))) +TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) -- before transformation val x4 = x0 == 0 -if (x4) { +val x10 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x6 = println(x5) +x6 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x8 = println(x5) +x8 } val x11 = x0 == 1 -if (x11) { +val x16 = if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x12 = println(x5) +x12 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x14 = println(x5) +x14 } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x4 = x0 == 0 -if (x4) { +val x22 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(2),Sym(1)) val x19 = VectorLength(Sym(18)) -println(x19) - +val x20 = println(x19) +x20 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x8 = println(x5) +x8 } val x11 = x0 == 1 -if (x11) { +val x27 = if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(2),Sym(1)) val x19 = VectorLength(Sym(18)) -println(x19) - +val x23 = println(x19) +x23 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x25 = println(x5) +x25 } // trying to retain more expressions from original program. // not resetting graph inbetween runs and smarter pruning of statements based on their inputs. diff --git a/test-out/epfl/test10-transform1.check b/test-out/epfl/test10-transform1.check index a73470ec..2047ac70 100644 --- a/test-out/epfl/test10-transform1.check +++ b/test-out/epfl/test10-transform1.check @@ -2,16 +2,16 @@ TP(Sym(1),VectorZeros(Const(100))) TP(Sym(2),VectorPlus(Sym(1),Sym(1))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(4)))) +TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(4)))) -- before transformation val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -println(x3) +val x4 = println(x3) -- after transformation val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -println(x3) +val x6 = println(x3) -- done diff --git a/test-out/epfl/test10-transform2.check b/test-out/epfl/test10-transform2.check index 658feb5b..db0776a9 100644 --- a/test-out/epfl/test10-transform2.check +++ b/test-out/epfl/test10-transform2.check @@ -4,46 +4,46 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -- before transformation val x4 = x0 == 0 -if (x4) { +val x10 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x6 = println(x5) +x6 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x8 = println(x5) +x8 } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x4 = x0 == 0 -if (x4) { +val x18 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x12 = VectorPlus(Sym(2),Sym(1)) val x13 = VectorLength(Sym(12)) -println(x13) - +val x14 = println(x13) +x14 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x16 = println(x5) +x16 } -- done diff --git a/test-out/epfl/test10-transform3.check b/test-out/epfl/test10-transform3.check index ecdbb20c..1f3aecb2 100644 --- a/test-out/epfl/test10-transform3.check +++ b/test-out/epfl/test10-transform3.check @@ -4,86 +4,86 @@ TP(Sym(2),VectorZeros(Const(50))) TP(Sym(3),VectorPlus(Sym(1),Sym(2))) TP(Sym(4),Equal(Sym(0),Const(0))) TP(Sym(5),VectorLength(Sym(3))) -TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(6)))) -TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) -TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(8)))) -TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) +TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) +TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) +TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) TP(Sym(11),Equal(Sym(0),Const(1))) -TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(12)))) -TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(14)))) -TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) -TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) +TP(Sym(12),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(13),Reify(Sym(12),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))) +TP(Sym(14),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(15),Reify(Sym(14),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(14)))) +TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +TP(Sym(17),Reify(Sym(16),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10), Sym(16)))) -- before transformation val x4 = x0 == 0 -if (x4) { +val x10 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x6 = println(x5) +x6 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x8 = println(x5) +x8 } val x11 = x0 == 1 -if (x11) { +val x16 = if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x12 = println(x5) +x12 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x14 = println(x5) +x14 } -encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,List(),List(),List(),List()),List())) +encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(10)))) +encountering if then else TP(Sym(16),Reflect(IfThenElse(Sym(11),Block(Sym(13)),Block(Sym(15))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) -- after transformation val x4 = x0 == 0 -if (x4) { +val x24 = if (x4) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(2),Sym(1)) val x19 = VectorLength(Sym(18)) -println(x19) - +val x20 = println(x19) +x20 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x22 = println(x5) +x22 } val x11 = x0 == 1 -if (x11) { +val x29 = if (x11) { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x18 = VectorPlus(Sym(2),Sym(1)) val x19 = VectorLength(Sym(18)) -println(x19) - +val x25 = println(x19) +x25 } else { val x1 = VectorZeros(Const(100)) val x2 = VectorZeros(Const(50)) val x3 = VectorPlus(Sym(1),Sym(2)) val x5 = VectorLength(Sym(3)) -println(x5) - +val x27 = println(x5) +x27 } -- done diff --git a/test-out/epfl/test10-transformrec3.check b/test-out/epfl/test10-transformrec3.check index d2e8d047..79b60e7c 100644 --- a/test-out/epfl/test10-transformrec3.check +++ b/test-out/epfl/test10-transformrec3.check @@ -1,6 +1,11 @@ -- before transformation var x1 = null.asInstanceOf[scala.Function1[Double, Double]] var x4 = null.asInstanceOf[scala.Function1[Double, Double]] +x4 = {x5: (Double) => +val x6 = x5-1.0 +val x7 = x1(x6) +x7 +} x1 = {x2: (Double) => val x3 = x2 == 0 val x10 = if (x3) { @@ -12,49 +17,44 @@ x9 } x10 } -x4 = {x5: (Double) => -val x6 = x5-1.0 -val x7 = x1(x6) -x7 -} val x11 = x1(x0) -- after null transformation var x12 = null.asInstanceOf[scala.Function1[Double, Double]] var x13 = null.asInstanceOf[scala.Function1[Double, Double]] +x13 = {x5: (Double) => +val x6 = x5-1.0 +val x14 = x12(x6) +x14 +} x12 = {x2: (Double) => val x3 = x2 == 0 -val x16 = if (x3) { +val x18 = if (x3) { 1.0 } else { -val x14 = x13(x2) -val x15 = x2*x14 -x15 -} -x16 +val x16 = x13(x2) +val x17 = x2*x16 +x17 } -x13 = {x5: (Double) => -val x6 = x5-1.0 -val x18 = x12(x6) x18 } val x20 = x12(x0) -- after transformation var x21 = null.asInstanceOf[scala.Function1[Double, Double]] var x22 = null.asInstanceOf[scala.Function1[Double, Double]] +x22 = /*2*/{x5: (Double) => +val x6 = x5-1.0 +val x23 = x21(x6) +x23 +} x21 = /*2*/{x2: (Double) => val x3 = x2 == 0 -val x25 = if (x3) { +val x27 = if (x3) { 1.0 } else { -val x23 = x22(x2) -val x24 = x2*x23 -x24 -} -x25 +val x25 = x22(x2) +val x26 = x2*x25 +x26 } -x22 = /*2*/{x5: (Double) => -val x6 = x5-1.0 -val x27 = x21(x6) x27 } val x29 = x21(x0) diff --git a/test-out/epfl/test10-worklist1.check b/test-out/epfl/test10-worklist1.check index 73ba82ff..96996f9d 100644 --- a/test-out/epfl/test10-worklist1.check +++ b/test-out/epfl/test10-worklist1.check @@ -7,12 +7,12 @@ register replacement for Sym(3) val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -println(x3) +val x4 = println(x3) ### next install replacement for Sym(1) install replacement for Sym(2) -toAtom transform Field(Sym(1),length,Int) List(Sym(1)) -> List(Sym(8)) +toAtom transform FieldApply(Sym(1),length) List(Sym(1)) -> List(Sym(8)) toAtom transform VectorApply(Sym(1),Sym(9)) List(Sym(1), Sym(9)) -> List(Sym(8), Sym(9)) register replacement for Sym(10) discarding, already have a replacement for Sym(10) @@ -20,7 +20,7 @@ toAtom transform VectorApply(Sym(1),Sym(9)) List(Sym(1), Sym(9)) -> List(Sym(8), discarding, already have a replacement for Sym(10) discarding, already have a replacement for Sym(10) install replacement for Sym(3) -toAtom transform Field(Sym(1),length,Int) List(Sym(1)) -> List(Sym(8)) +toAtom transform FieldApply(Sym(1),length) List(Sym(1)) -> List(Sym(8)) toAtom transform VectorApply(Sym(1),Sym(14)) List(Sym(1), Sym(14)) -> List(Sym(8), Sym(14)) register replacement for Sym(15) discarding, already have a replacement for Sym(15) @@ -31,21 +31,21 @@ discarding, already have a replacement for Sym(16) val x7 = LoopArray(100) { x6 => 0.0 } -val x8 = new { val data = x7; val length = 100 } +val x8 = new VectorDouble(x7,100) val x12 = LoopArray(100) { x9 => val x10 = VectorApply(Sym(8),Sym(9)) val x11 = x10+x10 x11 } -val x13 = new { val data = x12; val length = 100 } +val x13 = new VectorDouble(x12,100) val x18 = LoopArray(100) { x14 => val x15 = VectorApply(Sym(8),Sym(14)) val x16 = VectorApply(Sym(13),Sym(14)) val x17 = x15+x16 x17 } -val x19 = new { val data = x18; val length = 100 } -println(x19) +val x19 = new VectorDouble(x18,100) +val x20 = println(x19) ### next install replacement for Sym(10) @@ -69,5 +69,5 @@ val x32 = x28.apply(x30) val x33 = x31+x32 x33 } -val x35 = new { val data = x34; val length = 100 } -println(x35) +val x35 = new VectorDouble(x34,100) +val x36 = println(x35) diff --git a/test-out/epfl/test10-worklist2.check b/test-out/epfl/test10-worklist2.check index 421f7e0f..954d9d12 100644 --- a/test-out/epfl/test10-worklist2.check +++ b/test-out/epfl/test10-worklist2.check @@ -2,7 +2,7 @@ register replacement for Sym(1) --- code --- val x1 = VectorZeros(Const(100)) -println(x1) +val x3 = println(x1) ### next install replacement for Sym(1) @@ -10,5 +10,5 @@ install replacement for Sym(1) val x6 = LoopArray(100) { x5 => 0.0 } -val x7 = new { val data = x6; val length = 100 } -println(x7) +val x7 = new VectorDouble(x6,100) +val x8 = println(x7) diff --git a/test-out/epfl/test10-worklist21.check b/test-out/epfl/test10-worklist21.check index 1bf13c51..0b2cdb5e 100644 --- a/test-out/epfl/test10-worklist21.check +++ b/test-out/epfl/test10-worklist21.check @@ -6,7 +6,7 @@ register replacement for Sym(3) val x1 = VectorZeros(Const(100)) val x2 = VectorPlus(Sym(1),Sym(1)) val x3 = VectorPlus(Sym(1),Sym(2)) -println(x3) +val x4 = println(x3) ### next install replacement for Sym(1) @@ -20,22 +20,22 @@ register replacement for Sym(17) val x7 = LoopArray(100) { x6 => 0.0 } -val x8 = new { val data = x7; val length = 100 } +val x8 = new VectorDouble(x7,100) val x9 = VectorLength(Sym(8)) val x13 = LoopArray(x9) { x10 => val x11 = VectorApply(Sym(8),Sym(10)) val x12 = x11+x11 x12 } -val x14 = new { val data = x13; val length = x9 } +val x14 = new VectorDouble(x13,x9) val x19 = LoopArray(x9) { x15 => val x16 = VectorApply(Sym(8),Sym(15)) val x17 = VectorApply(Sym(14),Sym(15)) val x18 = x16+x17 x18 } -val x20 = new { val data = x19; val length = x9 } -println(x20) +val x20 = new VectorDouble(x19,x9) +val x21 = println(x20) ### next install replacement for Sym(9) @@ -57,5 +57,5 @@ val x33 = x29.apply(x31) val x34 = x32+x33 x34 } -val x36 = new { val data = x35; val length = 100 } -println(x36) +val x36 = new VectorDouble(x35,100) +val x37 = println(x36) diff --git a/test-out/epfl/test10-worklist22.check b/test-out/epfl/test10-worklist22.check index 421f7e0f..954d9d12 100644 --- a/test-out/epfl/test10-worklist22.check +++ b/test-out/epfl/test10-worklist22.check @@ -2,7 +2,7 @@ register replacement for Sym(1) --- code --- val x1 = VectorZeros(Const(100)) -println(x1) +val x3 = println(x1) ### next install replacement for Sym(1) @@ -10,5 +10,5 @@ install replacement for Sym(1) val x6 = LoopArray(100) { x5 => 0.0 } -val x7 = new { val data = x6; val length = 100 } -println(x7) +val x7 = new VectorDouble(x6,100) +val x8 = println(x7) diff --git a/test-out/epfl/test10-worklist23.check b/test-out/epfl/test10-worklist23.check index 9dbb62d9..92db0f06 100644 --- a/test-out/epfl/test10-worklist23.check +++ b/test-out/epfl/test10-worklist23.check @@ -12,7 +12,7 @@ val x2 = VectorZeros(Const(50)) x2 } val x5 = VectorPlus(Sym(4),Sym(1)) -println(x5) +val x6 = println(x5) ### next install replacement for Sym(1) @@ -35,17 +35,17 @@ val x12 = LoopArray(50) { x11 => } (x12,50) } -val x17 = new { val data = x15; val length = x16 } +val x17 = new VectorDouble(x15,x16) val x18 = VectorLength(Sym(17)) -val x10 = new { val data = x9; val length = 100 } +val x10 = new VectorDouble(x9,100) val x23 = LoopArray(x18) { x19 => val x20 = VectorApply(Sym(17),Sym(19)) val x21 = VectorApply(Sym(10),Sym(19)) val x22 = x20+x21 x22 } -val x24 = new { val data = x23; val length = x18 } -println(x24) +val x24 = new VectorDouble(x23,x18) +val x25 = println(x24) ### next install replacement for Sym(18) @@ -71,5 +71,5 @@ val x36 = x28.apply(x34) val x37 = x35+x36 x37 } -val x39 = new { val data = x38; val length = x16 } -println(x39) +val x39 = new VectorDouble(x38,x16) +val x40 = println(x39) diff --git a/test-out/epfl/test10-worklist3.check b/test-out/epfl/test10-worklist3.check index 17248480..33e430bb 100644 --- a/test-out/epfl/test10-worklist3.check +++ b/test-out/epfl/test10-worklist3.check @@ -13,13 +13,13 @@ val x2 = VectorZeros(Const(50)) x2 } val x5 = VectorPlus(Sym(4),Sym(1)) -println(x5) +val x6 = println(x5) ### next install replacement for Sym(1) install replacement for Sym(2) install replacement for Sym(5) -toAtom transform Field(Sym(4),length,Int) List(Sym(4)) -> List(Sym(17)) +toAtom transform FieldApply(Sym(4),length) List(Sym(4)) -> List(Sym(17)) toAtom transform VectorApply(Sym(4),Sym(18)) List(Sym(4), Sym(18)) -> List(Sym(17), Sym(18)) register replacement for Sym(19) discarding, already have a replacement for Sym(19) @@ -40,16 +40,16 @@ val x12 = LoopArray(50) { x11 => } (50,x12) } -val x17 = new { val data = x15; val length = x16 } -val x10 = new { val data = x9; val length = 100 } +val x17 = new VectorDouble(x15,x16) +val x10 = new VectorDouble(x9,100) val x22 = LoopArray(x16) { x18 => val x19 = VectorApply(Sym(17),Sym(18)) val x20 = VectorApply(Sym(10),Sym(18)) val x21 = x19+x20 x21 } -val x23 = new { val data = x22; val length = x16 } -println(x23) +val x23 = new VectorDouble(x22,x16) +val x24 = println(x23) ### next install replacement for Sym(19) @@ -76,5 +76,5 @@ val x35 = x27.apply(x33) val x36 = x34+x35 x36 } -val x38 = new { val data = x37; val length = x16 } -println(x38) +val x38 = new VectorDouble(x37,x16) +val x39 = println(x38) diff --git a/test-out/epfl/test11-hmm1.check b/test-out/epfl/test11-hmm1.check index 883b4269..21d18001 100644 --- a/test-out/epfl/test11-hmm1.check +++ b/test-out/epfl/test11-hmm1.check @@ -7,42 +7,43 @@ val x1 = new Array[Int](5) val x2 = x1(0) val x3 = x0(0) val x4 = x2 + x3 -x1(0) = x4 +val x5 = x1(0) = x4 val x6 = x0(3) val x7 = x4 + x6 -x1(0) = x7 +val x8 = x1(0) = x7 val x9 = x1(1) val x10 = x0(2) val x11 = x9 + x10 -x1(1) = x11 +val x12 = x1(1) = x11 val x13 = x1(2) val x14 = x0(1) val x15 = x13 + x14 -x1(2) = x15 +val x16 = x1(2) = x15 val x20 = px20 // static data: Array(0,0,1,1,1) var x18 : Int = 0 -while (x18 < 5) { +val x27 = while (x18 < 5) { val x19 = x1(3) val x21 = x20(x18) val x22 = x0(x18) val x23 = x21 * x22 val x24 = x19 + x23 -x1(3) = x24 +val x25 = x1(3) = x24 x18 = x18 + 1 } val x28 = x1(4) val x29 = x28 + x10 -x1(4) = x29 +val x30 = x1(4) = x29 val x31 = x0(4) val x32 = x29 + x31 -x1(4) = x32 +val x33 = x1(4) = x32 x1 } } /***************************************** End of Generated Code *******************************************/ +compilation: ok 1 5 1 diff --git a/test-out/epfl/test11-hmm2.check b/test-out/epfl/test11-hmm2.check index 12d98e4f..89b4d5a6 100644 --- a/test-out/epfl/test11-hmm2.check +++ b/test-out/epfl/test11-hmm2.check @@ -7,45 +7,46 @@ val x1 = new Array[Int](5) val x2 = x1(0) val x4 = x0(0) val x5 = x2 + x4 -x1(0) = x5 +val x6 = x1(0) = x5 val x9 = x0(3) val x10 = x5 + x9 -x1(0) = x10 +val x11 = x1(0) = x10 val x13 = x1(1) -x1(1) = x13 +val x15 = x1(1) = x13 val x8 = x0(2) val x16 = x13 + x8 -x1(1) = x16 +val x17 = x1(1) = x16 val x18 = x1(2) -x1(2) = x18 +val x20 = x1(2) = x18 val x7 = x0(1) val x21 = x18 + x7 -x1(2) = x21 +val x22 = x1(2) = x21 val x26 = px26 // static data: Array(0,0,1,1,1) var x24 : Int = 0 -while (x24 < 5) { +val x33 = while (x24 < 5) { val x25 = x1(3) val x27 = x26(x24) val x28 = x0(x24) val x29 = x27 * x28 val x30 = x25 + x29 -x1(3) = x30 +val x31 = x1(3) = x30 x24 = x24 + 1 } val x34 = x1(4) -x1(4) = x34 +val x36 = x1(4) = x34 val x37 = x34 + x8 -x1(4) = x37 +val x38 = x1(4) = x37 val x12 = x0(4) val x39 = x37 + x12 -x1(4) = x39 +val x40 = x1(4) = x39 x1 } } /***************************************** End of Generated Code *******************************************/ +compilation: ok 1 5 1 diff --git a/test-out/epfl/test11-stencil0.check b/test-out/epfl/test11-stencil0.check index 52e31b80..c81f7b67 100644 --- a/test-out/epfl/test11-stencil0.check +++ b/test-out/epfl/test11-stencil0.check @@ -1,11 +1,11 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged0 extends ((Array[Double])=>(Array[Double])) { +class staged$0 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = new Array[Double](20) var x3 : Int = 0 -while (x3 < 20) { +val x14 = while (x3 < 20) { val x4 = x3.doubleValue() val x5 = 2.0 * x4 val x6 = x5 + 3.0 @@ -14,7 +14,7 @@ val x8 = x7.doubleValue() val x9 = 2.0 * x8 val x10 = x9 + 3.0 val x11 = x6 + x10 -x1(x3) = x11 +val x12 = x1(x3) = x11 x3 = x3 + 1 } @@ -25,6 +25,7 @@ x1 End of Generated Code *******************************************/ +compilation: ok 8.0 12.0 16.0 diff --git a/test-out/epfl/test11-stencil1.check b/test-out/epfl/test11-stencil1.check index b6aa9fd6..2162c64b 100644 --- a/test-out/epfl/test11-stencil1.check +++ b/test-out/epfl/test11-stencil1.check @@ -1,28 +1,28 @@ Map(Sym(10) -> Sym(16), Sym(4) -> Sym(8), Sym(6) -> Sym(12), Sym(7) -> Sym(13), Sym(11) -> Sym(17), Sym(3) -> Sym(7), Sym(5) -> Sym(9), Sym(8) -> Sym(14), Sym(9) -> Sym(15), Sym(2) -> Sym(6)) r0: TP(Sym(3),IntDoubleValue(Sym(2))) -TP(Sym(4),NumericTimes(Const(2.0),Sym(3))) -TP(Sym(5),NumericPlus(Sym(4),Const(3.0))) -TP(Sym(6),NumericPlus(Sym(2),Const(1))) +TP(Sym(4),DoubleTimes(Const(2.0),Sym(3))) +TP(Sym(5),DoublePlus(Sym(4),Const(3.0))) +TP(Sym(6),IntPlus(Sym(2),Const(1))) TP(Sym(7),IntDoubleValue(Sym(6))) -TP(Sym(8),NumericTimes(Const(2.0),Sym(7))) -TP(Sym(9),NumericPlus(Sym(8),Const(3.0))) -TP(Sym(10),NumericPlus(Sym(5),Sym(9))) -TP(Sym(11),Reflect(ArrayUpdate(Sym(1),Sym(2),Sym(10)),Summary(false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) +TP(Sym(8),DoubleTimes(Const(2.0),Sym(7))) +TP(Sym(9),DoublePlus(Sym(8),Const(3.0))) +TP(Sym(10),DoublePlus(Sym(5),Sym(9))) +TP(Sym(11),Reflect(ArrayUpdate(Sym(1),Sym(2),Sym(10)),Summary(false,false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) r1: -TP(Sym(12),NumericPlus(Sym(2),Const(2))) +TP(Sym(12),IntPlus(Sym(2),Const(2))) TP(Sym(13),IntDoubleValue(Sym(12))) -TP(Sym(14),NumericTimes(Const(2.0),Sym(13))) -TP(Sym(15),NumericPlus(Sym(14),Const(3.0))) -TP(Sym(16),NumericPlus(Sym(9),Sym(15))) -TP(Sym(17),Reflect(ArrayUpdate(Sym(1),Sym(6),Sym(16)),Summary(false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) +TP(Sym(14),DoubleTimes(Const(2.0),Sym(13))) +TP(Sym(15),DoublePlus(Sym(14),Const(3.0))) +TP(Sym(16),DoublePlus(Sym(9),Sym(15))) +TP(Sym(17),Reflect(ArrayUpdate(Sym(1),Sym(6),Sym(16)),Summary(false,false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) r2: -TP(Sym(18),NumericPlus(Sym(2),Const(3))) +TP(Sym(18),IntPlus(Sym(2),Const(3))) TP(Sym(19),IntDoubleValue(Sym(18))) -TP(Sym(20),NumericTimes(Const(2.0),Sym(19))) -TP(Sym(21),NumericPlus(Sym(20),Const(3.0))) -TP(Sym(22),NumericPlus(Sym(15),Sym(21))) -TP(Sym(23),Reflect(ArrayUpdate(Sym(1),Sym(12),Sym(22)),Summary(false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) +TP(Sym(20),DoubleTimes(Const(2.0),Sym(19))) +TP(Sym(21),DoublePlus(Sym(20),Const(3.0))) +TP(Sym(22),DoublePlus(Sym(15),Sym(21))) +TP(Sym(23),Reflect(ArrayUpdate(Sym(1),Sym(12),Sym(22)),Summary(false,false,false,false,false,false,List(Sym(1)),List(Sym(1)),List(Sym(1)),List(Sym(1))),List(Sym(1)))) Map(Sym(10) -> Sym(16), Sym(4) -> Sym(8), Sym(6) -> Sym(12), Sym(7) -> Sym(13), Sym(11) -> Sym(17), Sym(3) -> Sym(7), Sym(5) -> Sym(9), Sym(8) -> Sym(14), Sym(9) -> Sym(15), Sym(2) -> Sym(6)) overlap1: (Sym(9),Sym(15)) @@ -36,7 +36,7 @@ var writes: List((Sym(15),Const(())), (Sym(12),Const(()))) /***************************************** Emitting Generated Code *******************************************/ -class staged1 extends ((Array[Double])=>(Array[Double])) { +class staged$0 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = new Array[Double](20) val x24 = 0.doubleValue() @@ -46,11 +46,11 @@ val x27 = 1.doubleValue() val x28 = 2.0 * x27 val x29 = x28 + 3.0 val x30 = x26 + x29 -x1(0) = x30 -var x32 = x29 -var x33 = 1 +val x31 = x1(0) = x30 +var x32: Double = x29 +var x33: Int = 1 var x35 : Int = 1 -while (x35 < 20) { +val x48 = while (x35 < 20) { val x36 = x32 val x37 = x33 val x39 = x35 + 1 @@ -58,7 +58,7 @@ val x40 = x39.doubleValue() val x41 = 2.0 * x40 val x42 = x41 + 3.0 val x43 = x36 + x42 -x1(x37) = x43 +val x44 = x1(x37) = x43 x32 = x42 x33 = x39 @@ -71,6 +71,7 @@ x1 End of Generated Code *******************************************/ +compilation: ok 8.0 12.0 16.0 diff --git a/test-out/epfl/test11-stencil2a.check b/test-out/epfl/test11-stencil2a.check index 4a2c6d1e..c4eafdfc 100644 --- a/test-out/epfl/test11-stencil2a.check +++ b/test-out/epfl/test11-stencil2a.check @@ -1,13 +1,13 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged2 extends ((Array[Double])=>(Array[Double])) { +class staged$0 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = x0.length val x2 = new Array[Double](x1) val x3 = x1 - 1 var x5 : Int = 1 -while (x5 < x3) { +val x17 = while (x5 < x3) { val x6 = x0(x5) val x7 = x5 + 1 val x8 = x0(x7) @@ -17,7 +17,7 @@ val x11 = x5 - 1 val x12 = x0(x11) val x13 = x12 * x6 val x14 = x10 + x13 -x2(x5) = x14 +val x15 = x2(x5) = x14 x5 = x5 + 1 } @@ -28,6 +28,7 @@ x2 End of Generated Code *******************************************/ +compilation: ok 0.0 0.8800000000000001 0.96 diff --git a/test-out/epfl/test11-stencil2b.check b/test-out/epfl/test11-stencil2b.check index 228d7f25..e9ae88bd 100644 --- a/test-out/epfl/test11-stencil2b.check +++ b/test-out/epfl/test11-stencil2b.check @@ -1,29 +1,29 @@ Map(Sym(14) -> Sym(20), Sym(10) -> Sym(19), Sym(6) -> Sym(8), Sym(7) -> Sym(16), Sym(13) -> Sym(9), Sym(11) -> Sym(5), Sym(12) -> Sym(6), Sym(5) -> Sym(7), Sym(15) -> Sym(21), Sym(8) -> Sym(17), Sym(9) -> Sym(18)) r0: TP(Sym(6),ArrayApply(Sym(0),Sym(5))) -TP(Sym(7),NumericPlus(Sym(5),Const(1))) +TP(Sym(7),IntPlus(Sym(5),Const(1))) TP(Sym(8),ArrayApply(Sym(0),Sym(7))) -TP(Sym(9),NumericTimes(Sym(6),Sym(8))) -TP(Sym(10),NumericMinus(Sym(6),Sym(9))) -TP(Sym(11),NumericMinus(Sym(5),Const(1))) +TP(Sym(9),DoubleTimes(Sym(6),Sym(8))) +TP(Sym(10),DoubleMinus(Sym(6),Sym(9))) +TP(Sym(11),IntMinus(Sym(5),Const(1))) TP(Sym(12),ArrayApply(Sym(0),Sym(11))) -TP(Sym(13),NumericTimes(Sym(12),Sym(6))) -TP(Sym(14),NumericPlus(Sym(10),Sym(13))) -TP(Sym(15),Reflect(ArrayUpdate(Sym(2),Sym(5),Sym(14)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(13),DoubleTimes(Sym(12),Sym(6))) +TP(Sym(14),DoublePlus(Sym(10),Sym(13))) +TP(Sym(15),Reflect(ArrayUpdate(Sym(2),Sym(5),Sym(14)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) r1: -TP(Sym(16),NumericPlus(Sym(5),Const(2))) +TP(Sym(16),IntPlus(Sym(5),Const(2))) TP(Sym(17),ArrayApply(Sym(0),Sym(16))) -TP(Sym(18),NumericTimes(Sym(8),Sym(17))) -TP(Sym(19),NumericMinus(Sym(8),Sym(18))) -TP(Sym(20),NumericPlus(Sym(19),Sym(9))) -TP(Sym(21),Reflect(ArrayUpdate(Sym(2),Sym(7),Sym(20)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(18),DoubleTimes(Sym(8),Sym(17))) +TP(Sym(19),DoubleMinus(Sym(8),Sym(18))) +TP(Sym(20),DoublePlus(Sym(19),Sym(9))) +TP(Sym(21),Reflect(ArrayUpdate(Sym(2),Sym(7),Sym(20)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) r2: -TP(Sym(22),NumericPlus(Sym(5),Const(3))) +TP(Sym(22),IntPlus(Sym(5),Const(3))) TP(Sym(23),ArrayApply(Sym(0),Sym(22))) -TP(Sym(24),NumericTimes(Sym(17),Sym(23))) -TP(Sym(25),NumericMinus(Sym(17),Sym(24))) -TP(Sym(26),NumericPlus(Sym(25),Sym(18))) -TP(Sym(27),Reflect(ArrayUpdate(Sym(2),Sym(16),Sym(26)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(24),DoubleTimes(Sym(17),Sym(23))) +TP(Sym(25),DoubleMinus(Sym(17),Sym(24))) +TP(Sym(26),DoublePlus(Sym(25),Sym(18))) +TP(Sym(27),Reflect(ArrayUpdate(Sym(2),Sym(16),Sym(26)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) Map(Sym(14) -> Sym(20), Sym(10) -> Sym(19), Sym(6) -> Sym(8), Sym(7) -> Sym(16), Sym(13) -> Sym(9), Sym(11) -> Sym(5), Sym(12) -> Sym(6), Sym(5) -> Sym(7), Sym(15) -> Sym(21), Sym(8) -> Sym(17), Sym(9) -> Sym(18)) overlap1: (Sym(8),Sym(17)) @@ -38,13 +38,13 @@ var writes: List((Sym(17),Const(())), (Sym(18),Const(())), (Sym(16),Const(()))) /***************************************** Emitting Generated Code *******************************************/ -class staged3 extends ((Array[Double])=>(Array[Double])) { +class staged$0 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = x0.length val x2 = new Array[Double](x1) val x3 = x1 - 1 val x28 = x3 > 1 -if (x28) { +val x58 = if (x28) { val x29 = x0(1) val x30 = x0(2) val x31 = x29 * x30 @@ -52,12 +52,12 @@ val x32 = x29 - x31 val x33 = x0(0) val x34 = x33 * x29 val x35 = x32 + x34 -x2(1) = x35 -var x37 = x30 -var x38 = x31 -var x39 = 2 +val x36 = x2(1) = x35 +var x37: Double = x30 +var x38: Double = x31 +var x39: Int = 2 var x41 : Int = 2 -while (x41 < x3) { +val x56 = while (x41 < x3) { val x42 = x37 val x43 = x38 val x44 = x39 @@ -66,14 +66,14 @@ val x47 = x0(x46) val x48 = x42 * x47 val x49 = x42 - x48 val x50 = x49 + x43 -x2(x44) = x50 +val x51 = x2(x44) = x50 x37 = x47 x38 = x48 x39 = x46 x41 = x41 + 1 } - +x56 } else { () } @@ -84,6 +84,7 @@ x2 End of Generated Code *******************************************/ +compilation: ok 0.0 0.8800000000000001 0.96 diff --git a/test-out/epfl/test11-stencil3a.check b/test-out/epfl/test11-stencil3a.check index c25290ae..daab8c4f 100644 --- a/test-out/epfl/test11-stencil3a.check +++ b/test-out/epfl/test11-stencil3a.check @@ -1,13 +1,13 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged4 extends ((Array[Double])=>(Array[Double])) { +class staged$0 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = x0.length val x2 = new Array[Double](x1) val x3 = x1 - 2 var x5 : Int = 2 -while (x5 < x3) { +val x31 = while (x5 < x3) { val x6 = x0(x5) val x7 = x5 + 1 val x8 = x0(x7) @@ -31,7 +31,7 @@ val x25 = x24 * x12 val x26 = x22 + x25 val x27 = x26 * x14 val x28 = x21 + x27 -x2(x5) = x28 +val x29 = x2(x5) = x28 x5 = x5 + 1 } @@ -42,6 +42,7 @@ x2 End of Generated Code *******************************************/ +compilation: ok 0.0 0.0 0.8063999999999999 diff --git a/test-out/epfl/test11-stencil3b.check b/test-out/epfl/test11-stencil3b.check index 8bbc30b8..28163b4b 100644 --- a/test-out/epfl/test11-stencil3b.check +++ b/test-out/epfl/test11-stencil3b.check @@ -1,49 +1,49 @@ Map(Sym(14) -> Sym(19), Sym(10) -> Sym(18), Sym(17) -> Sym(32), Sym(24) -> Sym(12), Sym(6) -> Sym(8), Sym(20) -> Sym(35), Sym(7) -> Sym(15), Sym(27) -> Sym(20), Sym(13) -> Sym(9), Sym(11) -> Sym(5), Sym(12) -> Sym(6), Sym(5) -> Sym(7), Sym(19) -> Sym(34), Sym(23) -> Sym(11), Sym(15) -> Sym(30), Sym(8) -> Sym(16), Sym(9) -> Sym(17), Sym(21) -> Sym(36), Sym(28) -> Sym(37), Sym(16) -> Sym(31), Sym(18) -> Sym(33), Sym(26) -> Sym(14), Sym(29) -> Sym(38), Sym(25) -> Sym(13), Sym(22) -> Sym(10)) r0: TP(Sym(6),ArrayApply(Sym(0),Sym(5))) -TP(Sym(7),NumericPlus(Sym(5),Const(1))) +TP(Sym(7),IntPlus(Sym(5),Const(1))) TP(Sym(8),ArrayApply(Sym(0),Sym(7))) -TP(Sym(9),NumericTimes(Sym(6),Sym(8))) -TP(Sym(10),NumericMinus(Sym(6),Sym(9))) -TP(Sym(11),NumericMinus(Sym(5),Const(1))) +TP(Sym(9),DoubleTimes(Sym(6),Sym(8))) +TP(Sym(10),DoubleMinus(Sym(6),Sym(9))) +TP(Sym(11),IntMinus(Sym(5),Const(1))) TP(Sym(12),ArrayApply(Sym(0),Sym(11))) -TP(Sym(13),NumericTimes(Sym(12),Sym(6))) -TP(Sym(14),NumericPlus(Sym(10),Sym(13))) -TP(Sym(15),NumericPlus(Sym(5),Const(2))) +TP(Sym(13),DoubleTimes(Sym(12),Sym(6))) +TP(Sym(14),DoublePlus(Sym(10),Sym(13))) +TP(Sym(15),IntPlus(Sym(5),Const(2))) TP(Sym(16),ArrayApply(Sym(0),Sym(15))) -TP(Sym(17),NumericTimes(Sym(8),Sym(16))) -TP(Sym(18),NumericMinus(Sym(8),Sym(17))) -TP(Sym(19),NumericPlus(Sym(18),Sym(9))) -TP(Sym(20),NumericTimes(Sym(14),Sym(19))) -TP(Sym(21),NumericMinus(Sym(14),Sym(20))) -TP(Sym(22),NumericMinus(Sym(12),Sym(13))) -TP(Sym(23),NumericMinus(Sym(5),Const(2))) +TP(Sym(17),DoubleTimes(Sym(8),Sym(16))) +TP(Sym(18),DoubleMinus(Sym(8),Sym(17))) +TP(Sym(19),DoublePlus(Sym(18),Sym(9))) +TP(Sym(20),DoubleTimes(Sym(14),Sym(19))) +TP(Sym(21),DoubleMinus(Sym(14),Sym(20))) +TP(Sym(22),DoubleMinus(Sym(12),Sym(13))) +TP(Sym(23),IntMinus(Sym(5),Const(2))) TP(Sym(24),ArrayApply(Sym(0),Sym(23))) -TP(Sym(25),NumericTimes(Sym(24),Sym(12))) -TP(Sym(26),NumericPlus(Sym(22),Sym(25))) -TP(Sym(27),NumericTimes(Sym(26),Sym(14))) -TP(Sym(28),NumericPlus(Sym(21),Sym(27))) -TP(Sym(29),Reflect(ArrayUpdate(Sym(2),Sym(5),Sym(28)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(25),DoubleTimes(Sym(24),Sym(12))) +TP(Sym(26),DoublePlus(Sym(22),Sym(25))) +TP(Sym(27),DoubleTimes(Sym(26),Sym(14))) +TP(Sym(28),DoublePlus(Sym(21),Sym(27))) +TP(Sym(29),Reflect(ArrayUpdate(Sym(2),Sym(5),Sym(28)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) r1: -TP(Sym(30),NumericPlus(Sym(5),Const(3))) +TP(Sym(30),IntPlus(Sym(5),Const(3))) TP(Sym(31),ArrayApply(Sym(0),Sym(30))) -TP(Sym(32),NumericTimes(Sym(16),Sym(31))) -TP(Sym(33),NumericMinus(Sym(16),Sym(32))) -TP(Sym(34),NumericPlus(Sym(33),Sym(17))) -TP(Sym(35),NumericTimes(Sym(19),Sym(34))) -TP(Sym(36),NumericMinus(Sym(19),Sym(35))) -TP(Sym(37),NumericPlus(Sym(36),Sym(20))) -TP(Sym(38),Reflect(ArrayUpdate(Sym(2),Sym(7),Sym(37)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(32),DoubleTimes(Sym(16),Sym(31))) +TP(Sym(33),DoubleMinus(Sym(16),Sym(32))) +TP(Sym(34),DoublePlus(Sym(33),Sym(17))) +TP(Sym(35),DoubleTimes(Sym(19),Sym(34))) +TP(Sym(36),DoubleMinus(Sym(19),Sym(35))) +TP(Sym(37),DoublePlus(Sym(36),Sym(20))) +TP(Sym(38),Reflect(ArrayUpdate(Sym(2),Sym(7),Sym(37)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) r2: -TP(Sym(39),NumericPlus(Sym(5),Const(4))) +TP(Sym(39),IntPlus(Sym(5),Const(4))) TP(Sym(40),ArrayApply(Sym(0),Sym(39))) -TP(Sym(41),NumericTimes(Sym(31),Sym(40))) -TP(Sym(42),NumericMinus(Sym(31),Sym(41))) -TP(Sym(43),NumericPlus(Sym(42),Sym(32))) -TP(Sym(44),NumericTimes(Sym(34),Sym(43))) -TP(Sym(45),NumericMinus(Sym(34),Sym(44))) -TP(Sym(46),NumericPlus(Sym(45),Sym(35))) -TP(Sym(47),Reflect(ArrayUpdate(Sym(2),Sym(15),Sym(46)),Summary(false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) +TP(Sym(41),DoubleTimes(Sym(31),Sym(40))) +TP(Sym(42),DoubleMinus(Sym(31),Sym(41))) +TP(Sym(43),DoublePlus(Sym(42),Sym(32))) +TP(Sym(44),DoubleTimes(Sym(34),Sym(43))) +TP(Sym(45),DoubleMinus(Sym(34),Sym(44))) +TP(Sym(46),DoublePlus(Sym(45),Sym(35))) +TP(Sym(47),Reflect(ArrayUpdate(Sym(2),Sym(15),Sym(46)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(Sym(2)),List(Sym(2))),List(Sym(2)))) Map(Sym(14) -> Sym(19), Sym(10) -> Sym(18), Sym(17) -> Sym(32), Sym(24) -> Sym(12), Sym(6) -> Sym(8), Sym(20) -> Sym(35), Sym(7) -> Sym(15), Sym(27) -> Sym(20), Sym(13) -> Sym(9), Sym(11) -> Sym(5), Sym(12) -> Sym(6), Sym(5) -> Sym(7), Sym(19) -> Sym(34), Sym(23) -> Sym(11), Sym(15) -> Sym(30), Sym(8) -> Sym(16), Sym(9) -> Sym(17), Sym(21) -> Sym(36), Sym(28) -> Sym(37), Sym(16) -> Sym(31), Sym(18) -> Sym(33), Sym(26) -> Sym(14), Sym(29) -> Sym(38), Sym(25) -> Sym(13), Sym(22) -> Sym(10)) overlap1: (Sym(16),Sym(31)) @@ -62,13 +62,13 @@ var writes: List((Sym(31),Const(())), (Sym(32),Const(())), (Sym(34),Const(())), /***************************************** Emitting Generated Code *******************************************/ -class staged5 extends ((Array[Double])=>(Array[Double])) { +class staged$0 extends ((Array[Double])=>(Array[Double])) { def apply(x0:Array[Double]): Array[Double] = { val x1 = x0.length val x2 = new Array[Double](x1) val x3 = x1 - 2 val x48 = x3 > 2 -if (x48) { +val x102 = if (x48) { val x49 = x0(2) val x50 = x0(3) val x51 = x49 * x50 @@ -88,15 +88,15 @@ val x64 = x63 * x53 val x65 = x62 + x64 val x66 = x65 * x55 val x67 = x61 + x66 -x2(2) = x67 -var x69 = x56 -var x70 = x57 -var x71 = x59 -var x72 = x60 -var x73 = 3 -var x74 = 4 +val x68 = x2(2) = x67 +var x69: Double = x56 +var x70: Double = x57 +var x71: Double = x59 +var x72: Double = x60 +var x73: Int = 3 +var x74: Int = 4 var x76 : Int = 3 -while (x76 < x3) { +val x100 = while (x76 < x3) { val x77 = x69 val x78 = x70 val x79 = x71 @@ -111,7 +111,7 @@ val x88 = x87 + x78 val x89 = x79 * x88 val x90 = x79 - x89 val x91 = x90 + x80 -x2(x81) = x91 +val x92 = x2(x81) = x91 x69 = x85 x70 = x86 x71 = x88 @@ -121,7 +121,7 @@ x74 = x84 x76 = x76 + 1 } - +x100 } else { () } @@ -132,6 +132,7 @@ x2 End of Generated Code *******************************************/ +compilation: ok 0.0 0.0 0.8063999999999999 diff --git a/test-out/epfl/test12-array-seq-creation.check b/test-out/epfl/test12-array-seq-creation.check index 0ecf1b8d..90186aa4 100644 --- a/test-out/epfl/test12-array-seq-creation.check +++ b/test-out/epfl/test12-array-seq-creation.check @@ -5,7 +5,8 @@ class IntArrayCreation extends ((Int)=>(Unit)) { def apply(x0:Int): Unit = { val x1 = Array(1,2,3) val x2 = x1(0) -println(x2) +val x3 = println(x2) +x3 } } /***************************************** @@ -18,7 +19,8 @@ class CharArrayCreation extends ((Int)=>(Unit)) { def apply(x5:Int): Unit = { val x6 = Array('a','b','c') val x7 = x6(0) -println(x7) +val x8 = println(x7) +x8 } } /***************************************** diff --git a/test-out/epfl/test12-map-flatmap-filter.check b/test-out/epfl/test12-map-flatmap-filter.check index c0dc1299..56103dde 100644 --- a/test-out/epfl/test12-map-flatmap-filter.check +++ b/test-out/epfl/test12-map-flatmap-filter.check @@ -9,7 +9,6 @@ val x4 = x3 < 3 x4 } - val x9 = x0.flatMap { x1 => val x8 = x5.map { x6 => val x7 = x1 * x6 @@ -17,10 +16,8 @@ val x7 = x1 * x6 x7 } - x8 } - x9 } } diff --git a/test-out/epfl/test13-interpret2.check b/test-out/epfl/test13-interpret2.check index b44c2b1f..a0e6ee66 100644 --- a/test-out/epfl/test13-interpret2.check +++ b/test-out/epfl/test13-interpret2.check @@ -1,15 +1,15 @@ -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(85),Summary(true,true,false,false,false,List(),List(),List(Sym(1), Sym(7), Sym(12), Sym(21), Sym(26), Sym(31), Sym(36), Sym(41), Sym(50), Sym(55), Sym(60), Sym(65), Sym(70), Sym(79)),List(Sym(1), Sym(7), Sym(12), Sym(21), Sym(26), Sym(31), Sym(36), Sym(41), Sym(50), Sym(55), Sym(60), Sym(65), Sym(70), Sym(79))),List(Sym(5), Sym(6), Sym(10), Sym(11), Sym(15), Sym(16), Sym(19), Sym(20), Sym(24), Sym(25), Sym(29), Sym(30), Sym(34), Sym(35), Sym(39), Sym(40), Sym(44), Sym(45), Sym(48), Sym(49), Sym(53), Sym(54), Sym(58), Sym(59), Sym(63), Sym(64), Sym(68), Sym(69), Sym(73), Sym(74), Sym(77), Sym(78), Sym(82), Sym(83), Sym(85))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(85),Summary(true,true,false,false,false,false,List(),List(),List(Sym(1), Sym(7), Sym(12), Sym(21), Sym(26), Sym(31), Sym(36), Sym(41), Sym(50), Sym(55), Sym(60), Sym(65), Sym(70), Sym(79)),List(Sym(1), Sym(7), Sym(12), Sym(21), Sym(26), Sym(31), Sym(36), Sym(41), Sym(50), Sym(55), Sym(60), Sym(65), Sym(70), Sym(79))),List(Sym(5), Sym(6), Sym(10), Sym(11), Sym(15), Sym(16), Sym(19), Sym(20), Sym(24), Sym(25), Sym(29), Sym(30), Sym(34), Sym(35), Sym(39), Sym(40), Sym(44), Sym(45), Sym(48), Sym(49), Sym(53), Sym(54), Sym(58), Sym(59), Sym(63), Sym(64), Sym(68), Sym(69), Sym(73), Sym(74), Sym(77), Sym(78), Sym(82), Sym(83), Sym(85))) /***************************************** Emitting Generated Code *******************************************/ -class staged0(px2:scala.lms.common.Compile,px3:Object,px4:Object,px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px8:Object,px9:Object,px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px13:Object,px14:Object,px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px17:Object,px18:Object,px22:Object,px23:Object,px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px27:Object,px28:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px32:Object,px33:Object,px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px37:Object,px38:Object,px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px42:Object,px43:Object,px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px46:Object,px47:Object,px51:Object,px52:Object,px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px56:Object,px57:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px61:Object,px62:Object,px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px66:Object,px67:Object,px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px71:Object,px72:Object,px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px75:Object,px76:Object,px80:Object,px81:Object,px79:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x0:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$0(px2:scala.lms.common.Compile,px3:Object,px4:Object,px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px8:Object,px9:Object,px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px13:Object,px14:Object,px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px17:Object,px18:Object,px22:Object,px23:Object,px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px27:Object,px28:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px32:Object,px33:Object,px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px37:Object,px38:Object,px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px42:Object,px43:Object,px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px46:Object,px47:Object,px51:Object,px52:Object,px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px56:Object,px57:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px61:Object,px62:Object,px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px66:Object,px67:Object,px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px71:Object,px72:Object,px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px75:Object,px76:Object,px80:Object,px81:Object,px79:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x0:java.util.HashMap[java.lang.String, Any]): Any = { val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 val x3 = px3 // static data: val x4 = px4 // static data: val x5 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x3.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x4.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -21,7 +21,7 @@ val x8 = px8 // static data: val x9 = px9 // static data: val x10 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x8.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x9.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -33,7 +33,7 @@ val x13 = px13 // static data: val x14 = px14 // static data: val x15 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x13.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x14.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -45,7 +45,7 @@ val x17 = px17 // static data: val x18 = px18 // static data: val x19 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x17.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x18.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -56,7 +56,7 @@ val x22 = px22 // static data: val x23 = px23 // static data: val x24 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x22.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x23.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -68,7 +68,7 @@ val x27 = px27 // static data: val x28 = px28 // static data: val x29 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x27.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x28.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -80,7 +80,7 @@ val x32 = px32 // static data: val x33 = px33 // static data: val x34 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x32.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x33.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -92,7 +92,7 @@ val x37 = px37 // static data: val x38 = px38 // static data: val x39 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x37.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x38.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -104,7 +104,7 @@ val x42 = px42 // static data: val x43 = px43 // static data: val x44 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x42.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x43.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -116,7 +116,7 @@ val x46 = px46 // static data: val x47 = px47 // static data: val x48 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x46.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x47.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -127,7 +127,7 @@ val x51 = px51 // static data: val x52 = px52 // static data: val x53 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x51.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x52.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -139,7 +139,7 @@ val x56 = px56 // static data: val x57 = px57 // static data: val x58 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x56.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x57.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -151,7 +151,7 @@ val x61 = px61 // static data: val x62 = px62 // static data: val x63 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x61.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x62.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -163,7 +163,7 @@ val x66 = px66 // static data: val x67 = px67 // static data: val x68 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x66.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x67.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -175,7 +175,7 @@ val x71 = px71 // static data: val x72 = px72 // static data: val x73 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x71.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x72.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -187,7 +187,7 @@ val x75 = px75 // static data: val x76 = px76 // static data: val x77 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x75.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x76.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -198,7 +198,7 @@ val x80 = px80 // static data: val x81 = px81 // static data: val x82 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x80.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x81.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -215,12 +215,13 @@ x85 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any StaticData(0) /***************************************** Emitting Generated Code *******************************************/ -class staged1(px88:Any) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x87:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$1(px88:Any) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x87:java.util.HashMap[java.lang.String, Any]): Any = { val x88 = px88 // static data: 0 x88 } @@ -229,12 +230,13 @@ x88 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any StaticData(0) /***************************************** Emitting Generated Code *******************************************/ -class staged2(px88:Any) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x89:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$2(px88:Any) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x89:java.util.HashMap[java.lang.String, Any]): Int = { val x88 = px88 // static data: 0 val x90 = x88.asInstanceOf[Int] x90 @@ -244,18 +246,19 @@ x90 End of Generated Code *******************************************/ +compilation: ok error: write to non-mutable Sym(91) -> None -at Sym(94)=Reflect(HashMapUpdate(Sym(91),Const(x),Sym(93)),Summary(false,false,false,false,false,List(),List(),List(Sym(91)),List(Sym(91))),List()) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(94),Summary(true,true,false,false,false,List(),List(),List(Sym(91)),List(Sym(91))),List(Sym(93), Sym(94))) +at Sym(94)=Reflect(HashMapUpdate(Sym(91),Const(x),Sym(93)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(91)),List(Sym(91))),List()) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(94),Summary(true,true,false,false,false,false,List(),List(),List(Sym(91)),List(Sym(91))),List(Sym(93), Sym(94))) /***************************************** Emitting Generated Code *******************************************/ -class staged3(px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x91:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$3(px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x91:java.util.HashMap[java.lang.String, Any]): Any = { val x1 = px1 // static data: RCell(dyn - ConstN(0)) val x92 = x1.value val x93 = x92.exec(x91) -val x94 = x91("x") = x93 +val x94 = x91.put("x", x93) x94 } } @@ -263,17 +266,18 @@ x94 End of Generated Code *******************************************/ +compilation: ok error: write to non-mutable Sym(96) -> None -at Sym(98)=Reflect(HashMapUpdate(Sym(96),Const(x),Sym(97)),Summary(false,false,false,false,false,List(),List(),List(Sym(96)),List(Sym(96))),List()) +at Sym(98)=Reflect(HashMapUpdate(Sym(96),Const(x),Sym(97)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(96)),List(Sym(96))),List()) /***************************************** Emitting Generated Code *******************************************/ -class staged4(px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x96:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$4(px1:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x96:java.util.HashMap[java.lang.String, Any]): Int = { val x1 = px1 // static data: RCell(dyn - ConstN(0)) val x92 = x1.value val x97 = x92.exec(x96) -val x98 = x96("x") = x97 +val x98 = x96.put("x", x97) val x99 = x98.asInstanceOf[Int] x99 } @@ -282,13 +286,14 @@ x99 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(101),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged5 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x101:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { -val x102 = x101("n") +class staged$5 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x101:java.util.HashMap[java.lang.String, Any]): Any = { +val x102 = x101.get("n") x102 } } @@ -296,13 +301,14 @@ x102 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(103),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged6 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x103:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { -val x104 = x103("n") +class staged$6 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x103:java.util.HashMap[java.lang.String, Any]): Int = { +val x104 = x103.get("n") val x105 = x104.asInstanceOf[Int] x105 } @@ -311,13 +317,14 @@ x105 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(106),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged7 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x106:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { -val x107 = x106("n") +class staged$7 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x106:java.util.HashMap[java.lang.String, Any]): Any = { +val x107 = x106.get("n") x107 } } @@ -325,13 +332,14 @@ x107 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(108),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged8 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x108:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { -val x109 = x108("n") +class staged$8 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x108:java.util.HashMap[java.lang.String, Any]): Int = { +val x109 = x108.get("n") val x110 = x109.asInstanceOf[Int] x110 } @@ -340,12 +348,13 @@ x110 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) /***************************************** Emitting Generated Code *******************************************/ -class staged9(px112:Any) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x111:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$9(px112:Any) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x111:java.util.HashMap[java.lang.String, Any]): Any = { val x112 = px112 // static data: -1 x112 } @@ -354,12 +363,13 @@ x112 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) /***************************************** Emitting Generated Code *******************************************/ -class staged10(px112:Any) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x113:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$10(px112:Any) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x113:java.util.HashMap[java.lang.String, Any]): Int = { val x112 = px112 // static data: -1 val x114 = x112.asInstanceOf[Int] x114 @@ -369,12 +379,13 @@ x114 End of Generated Code *******************************************/ -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(134),Summary(true,true,false,false,false,List(),List(),List(Sym(26)),List()),List(Sym(117), Sym(119), Sym(134))) +compilation: ok +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(134),Summary(true,true,false,false,false,false,List(),List(),List(Sym(26)),List()),List(Sym(117), Sym(119), Sym(134))) /***************************************** Emitting Generated Code *******************************************/ -class staged11(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px124:Object,px125:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x115:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$11(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px124:Object,px125:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x115:java.util.HashMap[java.lang.String, Any]): Any = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x117 = x116.exec(x115) @@ -383,11 +394,7 @@ val x118 = x21.value val x119 = x118.exec(x115) val x120 = x117.isInstanceOf[Int] val x121 = x119.isInstanceOf[Int] -val x122 = if (x120 == true) { - -x121 -} else false - +val x122 = x120 && x121 val x134 = if (x122) { val x123 = println("spec-add-int: AddN(LookupN(n),ConstN(-1))") val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 @@ -395,7 +402,7 @@ val x124 = px124 // static data: val x125 = px125 // static data: val x126 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x124.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x125.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -418,11 +425,12 @@ x134 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged12(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px143:Object,px144:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x136:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$12(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px143:Object,px144:Object,px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x136:java.util.HashMap[java.lang.String, Any]): Int = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x137 = x116.exec(x136) @@ -431,11 +439,7 @@ val x118 = x21.value val x138 = x118.exec(x136) val x139 = x137.isInstanceOf[Int] val x140 = x138.isInstanceOf[Int] -val x141 = if (x139 == true) { - -x140 -} else false - +val x141 = x139 && x140 val x153 = if (x141) { val x142 = println("spec-add-int: AddN(LookupN(n),ConstN(-1))") val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 @@ -443,7 +447,7 @@ val x143 = px143 // static data: val x144 = px144 // static data: val x145 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x143.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x144.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -467,18 +471,19 @@ x154 End of Generated Code *******************************************/ +compilation: ok error: write to non-mutable Sym(156) -> None -at Sym(159)=Reflect(HashMapUpdate(Sym(156),Const(n),Sym(158)),Summary(false,false,false,false,false,List(),List(),List(Sym(156)),List(Sym(156))),List()) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(159),Summary(true,true,false,false,false,List(),List(),List(Sym(156)),List(Sym(156))),List(Sym(158), Sym(159))) +at Sym(159)=Reflect(HashMapUpdate(Sym(156),Const(n),Sym(158)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(156)),List(Sym(156))),List()) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(159),Summary(true,true,false,false,false,false,List(),List(),List(Sym(156)),List(Sym(156))),List(Sym(158), Sym(159))) /***************************************** Emitting Generated Code *******************************************/ -class staged13(px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x156:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$13(px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x156:java.util.HashMap[java.lang.String, Any]): Any = { val x26 = px26 // static data: RCell(dyn - AddN(LookupN(n),ConstN(-1))) val x157 = x26.value val x158 = x157.exec(x156) -val x159 = x156("n") = x158 +val x159 = x156.put("n", x158) x159 } } @@ -486,17 +491,18 @@ x159 End of Generated Code *******************************************/ +compilation: ok error: write to non-mutable Sym(161) -> None -at Sym(163)=Reflect(HashMapUpdate(Sym(161),Const(n),Sym(162)),Summary(false,false,false,false,false,List(),List(),List(Sym(161)),List(Sym(161))),List()) +at Sym(163)=Reflect(HashMapUpdate(Sym(161),Const(n),Sym(162)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(161)),List(Sym(161))),List()) /***************************************** Emitting Generated Code *******************************************/ -class staged14(px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x161:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$14(px26:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x161:java.util.HashMap[java.lang.String, Any]): Int = { val x26 = px26 // static data: RCell(dyn - AddN(LookupN(n),ConstN(-1))) val x157 = x26.value val x162 = x157.exec(x161) -val x163 = x161("n") = x162 +val x163 = x161.put("n", x162) val x164 = x163.asInstanceOf[Int] x164 } @@ -505,13 +511,14 @@ x164 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(166),Const(x)) /***************************************** Emitting Generated Code *******************************************/ -class staged15 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x166:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { -val x167 = x166("x") +class staged$15 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x166:java.util.HashMap[java.lang.String, Any]): Any = { +val x167 = x166.get("x") x167 } } @@ -519,13 +526,14 @@ x167 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(168),Const(x)) /***************************************** Emitting Generated Code *******************************************/ -class staged16 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x168:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { -val x169 = x168("x") +class staged$16 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x168:java.util.HashMap[java.lang.String, Any]): Int = { +val x169 = x168.get("x") val x170 = x169.asInstanceOf[Int] x170 } @@ -534,13 +542,14 @@ x170 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(171),Const(a)) /***************************************** Emitting Generated Code *******************************************/ -class staged17 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x171:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { -val x172 = x171("a") +class staged$17 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x171:java.util.HashMap[java.lang.String, Any]): Any = { +val x172 = x171.get("a") x172 } } @@ -548,13 +557,14 @@ x172 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(173),Const(a)) /***************************************** Emitting Generated Code *******************************************/ -class staged18 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x173:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { -val x174 = x173("a") +class staged$18 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x173:java.util.HashMap[java.lang.String, Any]): Int = { +val x174 = x173.get("a") val x175 = x174.asInstanceOf[Int] x175 } @@ -563,13 +573,14 @@ x175 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(176),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged19 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x176:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { -val x177 = x176("n") +class staged$19 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x176:java.util.HashMap[java.lang.String, Any]): Any = { +val x177 = x176.get("n") x177 } } @@ -577,13 +588,14 @@ x177 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(178),Const(n)) /***************************************** Emitting Generated Code *******************************************/ -class staged20 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x178:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { -val x179 = x178("n") +class staged$20 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x178:java.util.HashMap[java.lang.String, Any]): Int = { +val x179 = x178.get("n") val x180 = x179.asInstanceOf[Int] x180 } @@ -592,12 +604,13 @@ x180 End of Generated Code *******************************************/ -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(186),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(183), Sym(184))) +compilation: ok +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(186),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(183), Sym(184))) /***************************************** Emitting Generated Code *******************************************/ -class staged21(px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x181:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$21(px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x181:java.util.HashMap[java.lang.String, Any]): Any = { val x41 = px41 // static data: RCell(dyn - LookupN(a)) val x182 = x41.value val x183 = x182.exec(x181) @@ -613,11 +626,12 @@ x186 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged22(px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x188:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$22(px41:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x188:java.util.HashMap[java.lang.String, Any]): Int = { val x41 = px41 // static data: RCell(dyn - LookupN(a)) val x182 = x41.value val x189 = x182.exec(x188) @@ -634,12 +648,13 @@ x193 End of Generated Code *******************************************/ -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(214),Summary(true,true,false,false,false,List(),List(),List(Sym(55)),List()),List(Sym(197), Sym(199), Sym(214))) +compilation: ok +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(214),Summary(true,true,false,false,false,false,List(),List(),List(Sym(55)),List()),List(Sym(197), Sym(199), Sym(214))) /***************************************** Emitting Generated Code *******************************************/ -class staged23(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px204:Object,px205:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x195:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$23(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px204:Object,px205:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x195:java.util.HashMap[java.lang.String, Any]): Any = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value val x197 = x196.exec(x195) @@ -648,11 +663,7 @@ val x198 = x50.value val x199 = x198.exec(x195) val x200 = x197.isInstanceOf[Int] val x201 = x199.isInstanceOf[Int] -val x202 = if (x200 == true) { - -x201 -} else false - +val x202 = x200 && x201 val x214 = if (x202) { val x203 = println("spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))") val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 @@ -660,7 +671,7 @@ val x204 = px204 // static data: val x205 = px205 // static data: val x206 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x204.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x205.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -683,11 +694,12 @@ x214 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged24(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px223:Object,px224:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x216:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$24(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px2:scala.lms.common.Compile,px223:Object,px224:Object,px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x216:java.util.HashMap[java.lang.String, Any]): Int = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value val x217 = x196.exec(x216) @@ -696,11 +708,7 @@ val x198 = x50.value val x218 = x198.exec(x216) val x219 = x217.isInstanceOf[Int] val x220 = x218.isInstanceOf[Int] -val x221 = if (x219 == true) { - -x220 -} else false - +val x221 = x219 && x220 val x233 = if (x221) { val x222 = println("spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))") val x2 = px2 // static data: IR:scala.lms.epfl.test13.TestInterpret$$anonfun$testInterpret2$1$$anon$2 @@ -708,7 +716,7 @@ val x223 = px223 // static data: val x224 = px224 // static data: val x225 = new scala.lms.epfl.test13.RFun { type Rep[T] = x2.Rep[T] -type HM = scala.collection.mutable.HashMap[String,Any] +type HM = java.util.HashMap[String,Any] val fAny = x2.compile(x223.asInstanceOf[Rep[HM]=>Rep[Any]]) val fInt = x2.compile(x224.asInstanceOf[Rep[HM]=>Rep[Int]]) def exec(f: HM): Any = fAny(f) @@ -732,18 +740,19 @@ x234 End of Generated Code *******************************************/ +compilation: ok error: write to non-mutable Sym(236) -> None -at Sym(239)=Reflect(HashMapUpdate(Sym(236),Const(x),Sym(238)),Summary(false,false,false,false,false,List(),List(),List(Sym(236)),List(Sym(236))),List()) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(239),Summary(true,true,false,false,false,List(),List(),List(Sym(236)),List(Sym(236))),List(Sym(238), Sym(239))) +at Sym(239)=Reflect(HashMapUpdate(Sym(236),Const(x),Sym(238)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(236)),List(Sym(236))),List()) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(239),Summary(true,true,false,false,false,false,List(),List(),List(Sym(236)),List(Sym(236))),List(Sym(238), Sym(239))) /***************************************** Emitting Generated Code *******************************************/ -class staged25(px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x236:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$25(px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x236:java.util.HashMap[java.lang.String, Any]): Any = { val x55 = px55 // static data: RCell(dyn - AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))) val x237 = x55.value val x238 = x237.exec(x236) -val x239 = x236("x") = x238 +val x239 = x236.put("x", x238) x239 } } @@ -751,17 +760,18 @@ x239 End of Generated Code *******************************************/ +compilation: ok error: write to non-mutable Sym(241) -> None -at Sym(243)=Reflect(HashMapUpdate(Sym(241),Const(x),Sym(242)),Summary(false,false,false,false,false,List(),List(),List(Sym(241)),List(Sym(241))),List()) +at Sym(243)=Reflect(HashMapUpdate(Sym(241),Const(x),Sym(242)),Summary(false,false,false,false,false,false,List(),List(),List(Sym(241)),List(Sym(241))),List()) /***************************************** Emitting Generated Code *******************************************/ -class staged26(px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x241:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$26(px55:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x241:java.util.HashMap[java.lang.String, Any]): Int = { val x55 = px55 // static data: RCell(dyn - AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))) val x237 = x55.value val x242 = x237.exec(x241) -val x243 = x241("x") = x242 +val x243 = x241.put("x", x242) val x244 = x243.asInstanceOf[Int] x244 } @@ -770,12 +780,13 @@ x244 End of Generated Code *******************************************/ -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(250),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(248), Sym(250))) +compilation: ok +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(250),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(248), Sym(250))) /***************************************** Emitting Generated Code *******************************************/ -class staged27(px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x246:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$27(px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x246:java.util.HashMap[java.lang.String, Any]): Any = { val x31 = px31 // static data: RCell(dyn - AssignN(n,AddN(LookupN(n),ConstN(-1)))) val x247 = x31.value val x248 = x247.exec(x246) @@ -789,11 +800,12 @@ x250 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged28(px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x252:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$28(px31:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px60:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x252:java.util.HashMap[java.lang.String, Any]): Int = { val x31 = px31 // static data: RCell(dyn - AssignN(n,AddN(LookupN(n),ConstN(-1)))) val x247 = x31.value val x253 = x247.exec(x252) @@ -808,21 +820,20 @@ x255 End of Generated Code *******************************************/ -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(264),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(264))) +compilation: ok +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(264),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(264))) /***************************************** Emitting Generated Code *******************************************/ -class staged29(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x257:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$29(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x257:java.util.HashMap[java.lang.String, Any]): Any = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x65 = px65 // static data: RCell(dyn - SeqN(List(AssignN(n,AddN(LookupN(n),ConstN(-1))), AssignN(x,AddN(LookupN(x),AppN(LookupN(a),LookupN(n))))))) val x261 = x65.value -val x264 = while ({ -val x258 = x116.execInt(x257) +val x264 = while ({val x258 = x116.execInt(x257) val x259 = x258 != 0 -x259 -}) { +x259}) { val x262 = x261.exec(x257) () } @@ -833,20 +844,19 @@ x264 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged30(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x266:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$30(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px65:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x266:java.util.HashMap[java.lang.String, Any]): Int = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x65 = px65 // static data: RCell(dyn - SeqN(List(AssignN(n,AddN(LookupN(n),ConstN(-1))), AssignN(x,AddN(LookupN(x),AppN(LookupN(a),LookupN(n))))))) val x261 = x65.value -val x272 = while ({ -val x267 = x116.execInt(x266) +val x272 = while ({val x267 = x116.execInt(x266) val x268 = x267 != 0 -x268 -}) { +x268}) { val x270 = x261.exec(x266) () } @@ -858,13 +868,14 @@ x273 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(275),Const(x)) /***************************************** Emitting Generated Code *******************************************/ -class staged31 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x275:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { -val x276 = x275("x") +class staged$31 extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x275:java.util.HashMap[java.lang.String, Any]): Any = { +val x276 = x275.get("x") x276 } } @@ -872,13 +883,14 @@ x276 End of Generated Code *******************************************/ +compilation: ok warning: possible missing mtype call - toAtom with Def of type Any HashMapApply(Sym(277),Const(x)) /***************************************** Emitting Generated Code *******************************************/ -class staged32 extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x277:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { -val x278 = x277("x") +class staged$32 extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x277:java.util.HashMap[java.lang.String, Any]): Int = { +val x278 = x277.get("x") val x279 = x278.asInstanceOf[Int] x279 } @@ -887,12 +899,13 @@ x279 End of Generated Code *******************************************/ -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(285),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(282), Sym(284), Sym(285))) +compilation: ok +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(285),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(282), Sym(284), Sym(285))) /***************************************** Emitting Generated Code *******************************************/ -class staged33(px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x280:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$33(px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x280:java.util.HashMap[java.lang.String, Any]): Any = { val x7 = px7 // static data: RCell(dyn - AssignN(x,ConstN(0))) val x281 = x7.value val x282 = x281.exec(x280) @@ -909,11 +922,12 @@ x285 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged34(px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x287:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$34(px7:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px70:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x287:java.util.HashMap[java.lang.String, Any]): Int = { val x7 = px7 // static data: RCell(dyn - AssignN(x,ConstN(0))) val x281 = x7.value val x288 = x281.exec(x287) @@ -931,13 +945,14 @@ x291 End of Generated Code *******************************************/ +compilation: ok spec-add-int: AddN(LookupN(n),ConstN(-1)) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(296),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(294), Sym(295))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(296),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(294), Sym(295))) /***************************************** Emitting Generated Code *******************************************/ -class staged35(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x293:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$35(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x293:java.util.HashMap[java.lang.String, Any]): Any = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x294 = x116.execInt(x293) @@ -952,11 +967,12 @@ x296 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged36(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x298:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$36(px12:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px21:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x298:java.util.HashMap[java.lang.String, Any]): Int = { val x12 = px12 // static data: RCell(dyn - LookupN(n)) val x116 = x12.value val x299 = x116.execInt(x298) @@ -971,13 +987,14 @@ x301 End of Generated Code *******************************************/ +compilation: ok spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(306),Summary(true,true,false,false,false,List(),List(),List(),List()),List(Sym(304), Sym(305))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(306),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(304), Sym(305))) /***************************************** Emitting Generated Code *******************************************/ -class staged37(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x303:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { +class staged$37(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x303:java.util.HashMap[java.lang.String, Any]): Any = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value val x304 = x196.execInt(x303) @@ -992,11 +1009,12 @@ x306 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged38(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Int)) { -def apply(x308:scala.collection.mutable.HashMap[java.lang.String, Any]): Int = { +class staged$38(px36:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun],px50:scala.lms.epfl.test13.RCell[scala.lms.epfl.test13.RFun]) extends ((java.util.HashMap[java.lang.String, Any])=>(Int)) { +def apply(x308:java.util.HashMap[java.lang.String, Any]): Int = { val x36 = px36 // static data: RCell(dyn - LookupN(x)) val x196 = x36.value val x309 = x196.execInt(x308) @@ -1011,4 +1029,5 @@ x311 End of Generated Code *******************************************/ +compilation: ok 65280 diff --git a/test-out/epfl/test13-interpret3.check b/test-out/epfl/test13-interpret3.check index 5ec81a5e..faef1cd4 100644 --- a/test-out/epfl/test13-interpret3.check +++ b/test-out/epfl/test13-interpret3.check @@ -1,4 +1,4 @@ -call with arg Map(n -> 256, a -> SomethingElse) +call with arg {a=SomethingElse, n=256} (re) compiling read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) sym Sym(3) -- Sym(2) @@ -8,60 +8,56 @@ warning: possible missing mtype call - toAtom with Def of type Any HashMapApply( read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(29),Summary(true,true,false,false,false,List(),List(),List(Sym(3)),List()),List(Sym(29))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(35),Summary(true,true,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(32), Sym(34), Sym(35))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(37),Summary(true,true,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(37))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(42),Summary(true,true,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(39), Sym(41), Sym(42))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(44),Summary(true,true,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(44))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(49),Summary(true,true,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(46), Sym(48), Sym(49))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(51),Summary(true,true,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(1), Sym(2), Sym(51))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(29),Summary(true,true,false,false,false,false,List(),List(),List(Sym(3)),List()),List(Sym(29))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(35),Summary(true,true,false,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(32), Sym(34), Sym(35))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(37),Summary(true,true,false,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(37))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(42),Summary(true,true,false,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(39), Sym(41), Sym(42))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(44),Summary(true,true,false,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(44))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(49),Summary(true,true,false,false,false,false,List(),List(),List(Sym(31)),List(Sym(31))),List(Sym(46), Sym(48), Sym(49))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(51),Summary(true,true,false,false,false,false,List(),List(),List(Sym(3), Sym(31)),List()),List(Sym(1), Sym(2), Sym(51))) /***************************************** Emitting Generated Code *******************************************/ -class staged39(px3:scala.lms.epfl.test13.RCell[Object],px5:Object,px7:scala.lms.epfl.test13.RCell[Object],px9:Object,px12:scala.lms.epfl.test13.RCell[Object],px14:Object,px16:Any,px21:Object,px31:scala.lms.epfl.test13.RCell[scala.Function1[scala.collection.mutable.HashMap[java.lang.String, Any], Any]],px33:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px40:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px47:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((scala.collection.mutable.HashMap[java.lang.String, Any])=>(Any)) { -def apply(x0:scala.collection.mutable.HashMap[java.lang.String, Any]): Any = { -var x1 = x0 +class staged$0(px3:scala.lms.epfl.test13.RCell[Object],px5:Object,px7:scala.lms.epfl.test13.RCell[Object],px9:Object,px12:scala.lms.epfl.test13.RCell[Object],px14:Object,px16:Any,px21:Object,px31:scala.lms.epfl.test13.RCell[scala.Function1[java.util.HashMap[java.lang.String, Any], Any]],px33:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px40:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px47:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((java.util.HashMap[java.lang.String, Any])=>(Any)) { +def apply(x0:java.util.HashMap[java.lang.String, Any]): Any = { +var x1: java.util.HashMap[java.lang.String, Any] = x0 val x2 = x1 val x3 = px3 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX) val x4 = x3.value -val x5 = px5 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$24@XXX +val x5 = px5 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$23@XXX val x6 = x4 == x5 val x51 = if (x6) { val x7 = px7 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) val x8 = x7.value -val x9 = px9 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$28@XXX +val x9 = px9 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$27@XXX val x10 = x8 == x9 val x44 = if (x10) { val x12 = px12 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) val x13 = x12.value -val x14 = px14 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$30@XXX +val x14 = px14 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$29@XXX val x15 = x13 == x14 val x37 = if (x15) { -val x11 = x2("n") +val x11 = x2.get("n") val x17 = x11.isInstanceOf[Int] val x16 = px16 // static data: -1 val x18 = x16.isInstanceOf[Int] -val x19 = if (x17 == true) { - -x18 -} else false - +val x19 = x17 && x18 val x29 = if (x19) { -println("spec-add-int: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX") -val x21 = px21 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$25@XXX -x3.set(x21) +val x20 = println("spec-add-int: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX") +val x21 = px21 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN$$anon$24@XXX +val x22 = x3.set(x21) val x23 = x11.asInstanceOf[Int] val x24 = x16.asInstanceOf[Int] val x25 = x23 + x24 x25 } else { -println("GENERIC") - +val x27 = println("GENERIC") +x27 } x29 } else { val x31 = px31 // static data: RCell(code) -x31.set(null) +val x32 = x31.set(null) val x33 = px33 // static data: val x34 = x33.apply(List(x13, x2))// compile dynamic: fv = List(Sym(13), Sym(2)) val x35 = x34.apply(()) @@ -70,7 +66,7 @@ x35 x37 } else { val x31 = px31 // static data: RCell(code) -x31.set(null) +val x39 = x31.set(null) val x40 = px40 // static data: val x41 = x40.apply(List(x8, x2))// compile dynamic: fv = List(Sym(8), Sym(2)) val x42 = x41.apply(()) @@ -79,7 +75,7 @@ x42 x44 } else { val x31 = px31 // static data: RCell(code) -x31.set(null) +val x46 = x31.set(null) val x47 = px47 // static data: val x48 = x47.apply(List(x4, x2))// compile dynamic: fv = List(Sym(4), Sym(2)) val x49 = x48.apply(()) @@ -92,9 +88,10 @@ x51 End of Generated Code *******************************************/ +compilation: ok spec-add-int: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$AddN@XXX 255 -call with arg Map(n -> 256, a -> SomethingElse) +call with arg {a=SomethingElse, n=256} -- Sym(2) read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) sym Sym(6) -- Sym(2) @@ -102,27 +99,27 @@ warning: possible missing mtype call - toAtom with Def of type Any HashMapApply( read value RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) sym Sym(12) -- Sym(2) warning: possible missing mtype call - toAtom with Def of type Any StaticData(-1) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(23),Summary(true,true,false,false,false,List(),List(),List(Sym(19)),List(Sym(19))),List(Sym(20), Sym(22), Sym(23))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(25),Summary(true,false,false,false,false,List(),List(),List(Sym(19)),List()),List(Sym(25))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(30),Summary(true,true,false,false,false,List(),List(),List(Sym(19)),List(Sym(19))),List(Sym(27), Sym(29), Sym(30))) -warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(32),Summary(true,false,false,false,false,List(),List(),List(Sym(19)),List()),List(Sym(32))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(23),Summary(true,true,false,false,false,false,List(),List(),List(Sym(19)),List(Sym(19))),List(Sym(20), Sym(22), Sym(23))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(25),Summary(true,false,false,false,false,false,List(),List(),List(Sym(19)),List()),List(Sym(25))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(30),Summary(true,true,false,false,false,false,List(),List(),List(Sym(19)),List(Sym(19))),List(Sym(27), Sym(29), Sym(30))) +warning: possible missing mtype call - toAtom with Def of type Any Reify(Sym(32),Summary(true,false,false,false,false,false,List(),List(),List(Sym(19)),List()),List(Sym(32))) /***************************************** Emitting Generated Code *******************************************/ -class staged40(px6:scala.lms.epfl.test13.RCell[Object],px8:Object,px12:scala.lms.epfl.test13.RCell[Object],px14:Object,px2:scala.collection.mutable.HashMap[java.lang.String, Any],px16:Any,px19:scala.lms.epfl.test13.RCell[scala.Function1[scala.collection.mutable.HashMap[java.lang.String, Any], Any]],px21:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px28:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((Unit)=>(Any)) { +class staged$1(px6:scala.lms.epfl.test13.RCell[Object],px8:Object,px12:scala.lms.epfl.test13.RCell[Object],px14:Object,px2:java.util.HashMap[java.lang.String, Any],px16:Any,px19:scala.lms.epfl.test13.RCell[scala.Function1[java.util.HashMap[java.lang.String, Any], Any]],px21:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]],px28:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Any]]) extends ((Unit)=>(Any)) { def apply(x5:Unit): Any = { val x6 = px6 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN@XXX) val x7 = x6.value -val x8 = px8 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$28@XXX +val x8 = px8 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$LookupN$$anon$27@XXX val x9 = x7 == x8 val x32 = if (x9) { val x12 = px12 // static data: RCell(dyn - FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN@XXX) val x13 = x12.value -val x14 = px14 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$30@XXX +val x14 = px14 // static data: FUN:scala.lms.epfl.test13.TestInterpret$InterpretStagedReopt$ConstN$$anon$29@XXX val x15 = x13 == x14 val x25 = if (x15) { -val x2 = px2 // static data: Map(n -> 256, a -> SomethingElse) -val x10 = x2("n") +val x2 = px2 // static data: {a=SomethingElse, n=256} +val x10 = x2.get("n") val x11 = x10.asInstanceOf[Int] val x16 = px16 // static data: -1 val x17 = x16.asInstanceOf[Int] @@ -130,8 +127,8 @@ val x18 = x11 + x17 x18 } else { val x19 = px19 // static data: RCell(code) -x19.set(null) -val x2 = px2 // static data: Map(n -> 256, a -> SomethingElse) +val x20 = x19.set(null) +val x2 = px2 // static data: {a=SomethingElse, n=256} val x21 = px21 // static data: val x22 = x21.apply(List(x13, x2))// compile dynamic: fv = List(Sym(13), Sym(2)) val x23 = x22.apply(()) @@ -140,8 +137,8 @@ x23 x25 } else { val x19 = px19 // static data: RCell(code) -x19.set(null) -val x2 = px2 // static data: Map(n -> 256, a -> SomethingElse) +val x27 = x19.set(null) +val x2 = px2 // static data: {a=SomethingElse, n=256} val x28 = px28 // static data: val x29 = x28.apply(List(x7, x2))// compile dynamic: fv = List(Sym(7), Sym(2)) val x30 = x29.apply(()) @@ -154,4 +151,5 @@ x32 End of Generated Code *******************************************/ +compilation: ok 255 diff --git a/test-out/epfl/test13-stable1.check b/test-out/epfl/test13-stable1.check index 106568b8..492235b0 100644 --- a/test-out/epfl/test13-stable1.check +++ b/test-out/epfl/test13-stable1.check @@ -1,7 +1,7 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged0(px3:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Int, Int]],px5:scala.lms.epfl.test13.RCell[Int]) extends ((Int)=>(Int)) { +class staged$0(px3:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Int, Int]],px5:scala.lms.epfl.test13.RCell[Int]) extends ((Int)=>(Int)) { def apply(x0:Int): Int = { val x1 = x0 + 1 val x2 = x0 * 2 @@ -17,10 +17,11 @@ x7 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged1(px1:Int,px2:Int) extends ((Int)=>(Int)) { +class staged$1(px1:Int,px2:Int) extends ((Int)=>(Int)) { def apply(x3:Int): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -33,11 +34,12 @@ x5 End of Generated Code *******************************************/ +compilation: ok 28 /***************************************** Emitting Generated Code *******************************************/ -class staged2(px1:Int,px2:Int) extends ((Int)=>(Int)) { +class staged$2(px1:Int,px2:Int) extends ((Int)=>(Int)) { def apply(x3:Int): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -50,11 +52,12 @@ x5 End of Generated Code *******************************************/ +compilation: ok 140 /***************************************** Emitting Generated Code *******************************************/ -class staged3(px1:Int,px2:Int) extends ((Int)=>(Int)) { +class staged$3(px1:Int,px2:Int) extends ((Int)=>(Int)) { def apply(x3:Int): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -67,4 +70,5 @@ x5 End of Generated Code *******************************************/ +compilation: ok 56 diff --git a/test-out/epfl/test13-stable2.check b/test-out/epfl/test13-stable2.check index e30c9737..c6338b0e 100644 --- a/test-out/epfl/test13-stable2.check +++ b/test-out/epfl/test13-stable2.check @@ -4,41 +4,41 @@ read value RCell(stable) sym Sym(3) /***************************************** Emitting Generated Code *******************************************/ -class staged4(px3:scala.lms.epfl.test13.RCell[Int],px5:Int,px9:scala.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px11:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { +class staged$0(px3:scala.lms.epfl.test13.RCell[Int],px5:Int,px8:scala.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px10:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { def apply(x0:Int): Int = { val x3 = px3 // static data: RCell(stable) val x4 = x3.value val x5 = px5 // static data: 1 val x6 = x4 == x5 -val x15 = if (x6) { +val x14 = if (x6) { val x1 = x0 + 1 val x2 = x0 * 2 val x7 = x1 + x2 -val x8 = 1 * x7 -x8 +x7 } else { -val x9 = px9 // static data: RCell(code) -x9.set(null) +val x8 = px8 // static data: RCell(code) +val x9 = x8.set(null) val x1 = x0 + 1 val x2 = x0 * 2 -val x11 = px11 // static data: -val x12 = x11.apply(List(x4, x1, x2))// compile dynamic: fv = List(Sym(4), Sym(1), Sym(2)) -val x13 = x12.apply(()) -x13 +val x10 = px10 // static data: +val x11 = x10.apply(List(x4, x1, x2))// compile dynamic: fv = List(Sym(4), Sym(1), Sym(2)) +val x12 = x11.apply(()) +x12 } -x15 +x14 } } /***************************************** End of Generated Code *******************************************/ +compilation: ok 28 call with arg 9 /***************************************** Emitting Generated Code *******************************************/ -class staged5(px1:Int,px2:Int) extends ((Unit)=>(Int)) { +class staged$1(px1:Int,px2:Int) extends ((Unit)=>(Int)) { def apply(x5:Unit): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -51,6 +51,7 @@ x7 End of Generated Code *******************************************/ +compilation: ok 140 call with arg 9 (re) compiling @@ -58,7 +59,7 @@ read value RCell(stable) sym Sym(11) /***************************************** Emitting Generated Code *******************************************/ -class staged6(px11:scala.lms.epfl.test13.RCell[Int],px13:Int,px17:scala.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px19:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { +class staged$2(px11:scala.lms.epfl.test13.RCell[Int],px13:Int,px17:scala.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px19:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { def apply(x8:Int): Int = { val x11 = px11 // static data: RCell(stable) val x12 = x11.value @@ -72,7 +73,7 @@ val x16 = 2 * x15 x16 } else { val x17 = px17 // static data: RCell(code) -x17.set(null) +val x18 = x17.set(null) val x9 = x8 + 1 val x10 = x8 * 2 val x19 = px19 // static data: @@ -87,4 +88,5 @@ x23 End of Generated Code *******************************************/ +compilation: ok 56 diff --git a/test-out/epfl/test13-unstage1.check b/test-out/epfl/test13-unstage1.check index 05d189c1..d6a4a1e0 100644 --- a/test-out/epfl/test13-unstage1.check +++ b/test-out/epfl/test13-unstage1.check @@ -1,7 +1,7 @@ /***************************************** Emitting Generated Code *******************************************/ -class staged7(px4:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { +class staged$0(px4:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { def apply(x0:Int): Int = { val x1 = x0 + 1 val x2 = x0 * 2 @@ -16,10 +16,11 @@ x6 End of Generated Code *******************************************/ +compilation: ok /***************************************** Emitting Generated Code *******************************************/ -class staged8(px1:Int,px2:Int) extends ((Unit)=>(Int)) { +class staged$1(px1:Int,px2:Int) extends ((Unit)=>(Int)) { def apply(x4:Unit): Int = { val x1 = px1 // static data: 10 val x2 = px2 // static data: 18 @@ -32,11 +33,12 @@ x6 End of Generated Code *******************************************/ +compilation: ok 784 /***************************************** Emitting Generated Code *******************************************/ -class staged9(px1:Int,px2:Int) extends ((Unit)=>(Int)) { +class staged$2(px1:Int,px2:Int) extends ((Unit)=>(Int)) { def apply(x4:Unit): Int = { val x1 = px1 // static data: 4 val x2 = px2 // static data: 6 @@ -49,11 +51,12 @@ x6 End of Generated Code *******************************************/ +compilation: ok 100 /***************************************** Emitting Generated Code *******************************************/ -class staged10(px1:Int,px2:Int) extends ((Unit)=>(Int)) { +class staged$3(px1:Int,px2:Int) extends ((Unit)=>(Int)) { def apply(x4:Unit): Int = { val x1 = px1 // static data: 2 val x2 = px2 // static data: 2 @@ -66,4 +69,5 @@ x6 End of Generated Code *******************************************/ +compilation: ok 16 diff --git a/test-out/epfl/test14-cgen1.check b/test-out/epfl/test14-cgen1.check index 183c44d8..3e63396e 100644 --- a/test-out/epfl/test14-cgen1.check +++ b/test-out/epfl/test14-cgen1.check @@ -1,20 +1,21 @@ /* FILE: main.c */ -int main(int); +int32_t main(int32_t); /***************************************** Emitting C Generated Code *******************************************/ #include #include +#include #include -int main(int x0) { -int x1 = 0; +int32_t main(int32_t x0) { +int32_t x1 = 0; for (;;) { -int x2 = x1; +int32_t x2 = x1; bool x3 = x2 < 10; if (!x3) break; -int x5 = x1; -printf("Hello, world! %d\n",x5); // x6 -int x7 = x5 + 1; +int32_t x5 = x1; +printf(string("Hello, world! %d\n").c_str(),x5); +int32_t x7 = x5 + 1; x1 = x7; } return 0; diff --git a/test-out/epfl/test14-cgen2.check b/test-out/epfl/test14-cgen2.check index d4766343..7ccbff9f 100644 --- a/test-out/epfl/test14-cgen2.check +++ b/test-out/epfl/test14-cgen2.check @@ -1,29 +1,30 @@ /* FILE: main.c */ -int main(int); +int32_t main(int32_t); /***************************************** Emitting C Generated Code *******************************************/ #include #include +#include #include -int main(int x0) { -int x1(int x2,int x3) { -int x4 = x2; +int32_t main(int32_t x0) { +function x1 = [&](int32_t x2,int32_t x3) { +int32_t x4 = x2; bool x6 = x4 == 0; -int x12; +int32_t x12; if (x6) { x12 = 1; } else { -int x5 = x3; -int x7 = x4 - 1; -int x9 = x1(x7,x5); -int x10 = x4 * x9; +int32_t x5 = x3; +int32_t x7 = x4 - 1; +int32_t x9 = x1(x7,x5); +int32_t x10 = x4 * x9; x12 = x10; } return x12; -} -int x15 = x1(4,0); -printf("Hello, world! %d\n",x15); // x16 +}; +int32_t x15 = x1(4,0); +printf(string("Hello, world! %d\n").c_str(),x15); return 0; } /***************************************** diff --git a/test-out/epfl/test14-cgen3.check b/test-out/epfl/test14-cgen3.check index 7ada95dc..5453b5c0 100644 --- a/test-out/epfl/test14-cgen3.check +++ b/test-out/epfl/test14-cgen3.check @@ -1,51 +1,54 @@ /* FILE: test2.c */ -int test2(int); -int test1(int); -int main(int); +int32_t test2(int32_t); +int32_t test1(int32_t); +int32_t main(int32_t); /***************************************** Emitting C Generated Code *******************************************/ #include #include +#include #include -int test2(int x0) { -printf("Hello, world: test2\n"); // x1 +int32_t test2(int32_t x0) { +printf(string("Hello, world: test2\n").c_str()); return x0; } /***************************************** End of C Generated Code *******************************************/ /* FILE: test1.c */ -int test2(int); -int test1(int); -int main(int); +int32_t test2(int32_t); +int32_t test1(int32_t); +int32_t main(int32_t); /***************************************** Emitting C Generated Code *******************************************/ #include #include +#include #include -int test1(int x3) { -printf("Hello, world: test1\n"); // x4 -int x5 = test2(x3); +int32_t test1(int32_t x3) { +printf(string("Hello, world: test1\n").c_str()); +int32_t x5 = test2(x3); return x5; } /***************************************** End of C Generated Code *******************************************/ /* FILE: main.c */ -int test2(int); -int test1(int); -int main(int); +int32_t test2(int32_t); +int32_t test1(int32_t); +int32_t main(int32_t); /***************************************** Emitting C Generated Code *******************************************/ #include #include +#include #include -int main(int x7) { -printf("Hello, world: main\n"); // x8 -int x9 = test1(x7); +int32_t main(int32_t x7) { +printf(string("Hello, world: main\n").c_str()); +int32_t x9 = test1(x7); return x9; } /***************************************** diff --git a/test-out/epfl/test14-dataop1.check b/test-out/epfl/test14-dataop1.check index 678c8c26..16e7ea54 100644 --- a/test-out/epfl/test14-dataop1.check +++ b/test-out/epfl/test14-dataop1.check @@ -1,29 +1,30 @@ /* FILE: main.c */ -int main(int); +int32_t main(int32_t); /***************************************** Emitting C Generated Code *******************************************/ #include #include +#include #include -int main(int x0) { -int x5 = 0; -int* x1 = mmap('table_field1.dat') // XX TODO ; -int x4 = x1.length; -int* x2 = mmap('table_field2.dat') // XX TODO ; +int32_t main(int32_t x0) { +int32_t x5 = 0; +int* *x1 = mmap('table_field1.dat') // XX TODO ; +int32_t x4 = x1->length; +int* *x2 = mmap('table_field2.dat') // XX TODO ; for (;;) { -int x6 = x5; +int32_t x6 = x5; bool x7 = x6 < x4; if (x7) { -x5 = x5 + 1; +x5 += 1; } else { } if (!x7) break; -int x12 = x5; -int x14 = x2[x12]; -int x13 = x1[x12]; -int x16 = 2 * x13; -printf("foo: %d, bar: %d\n",x14,x16); // x17 +int32_t x12 = x5; +int32_t x14 = x2[x12]; +int32_t x13 = x1[x12]; +int32_t x16 = 2 * x13; +printf(string("foo: %d, bar: %d\n").c_str(),x14,x16); } return 0; } diff --git a/test-out/epfl/test14-dataop2.check b/test-out/epfl/test14-dataop2.check index f8d0107e..8286baba 100644 --- a/test-out/epfl/test14-dataop2.check +++ b/test-out/epfl/test14-dataop2.check @@ -1,60 +1,54 @@ /* FILE: main.c */ -int main(int); +int32_t main(int32_t); /***************************************** Emitting C Generated Code *******************************************/ #include #include +#include #include -int main(int x0) { -int x3 = 0; -int* x1 = mmap('table.dat') // XX TODO ; -int x2 = x1.length; +int32_t main(int32_t x0) { +int32_t x3 = 0; +int* *x1 = mmap('table.dat') // XX TODO ; +int32_t x2 = x1->length; for (;;) { -int x4 = x3; +int32_t x4 = x3; bool x5 = x4 < x2; if (x5) { -x3 = x3 + 3; +x3 += 3; } else { } bool x9 = x5; -int x10 = x3; -bool x11 = x10 < x2; -if (x11) { -x3 = x3 + 3; -} else { -} for (;;) { -bool x15 = x9; -bool x26; -if (x15) { -int x16 = x3; -int x19 = x16 + 1; -int x20 = x1[x19]; -bool x23 = x20 > 0; -bool x24 = !x23; -x26 = x24; +bool x10 = x9; +bool x20; +if (x10) { +int32_t x11 = x3; +int32_t x13 = x11 + 1; +int32_t x14 = x1[x13]; +bool x17 = x14 > 0; +bool x18 = !x17; +x20 = x18; } else { -x26 = false; +x20 = false; } -if (!x26) break; -int x28 = x3; -bool x29 = x28 < x2; -if (x29) { -x3 = x3 + 3; +if (!x20) break; +int32_t x22 = x3; +bool x23 = x22 < x2; +if (x23) { +x3 += 3; } else { } -x9 = x29; +x9 = x23; } -bool x36 = x9; -if (!x36) break; -int x38 = x3; -int x41 = x38 + 1; -int x42 = x1[x41]; -int x39 = x38 + 0; -int x40 = x1[x39]; -int x45 = 2 * x40; -printf("foo: %d, bar: %d\n",x42,x45); // x46 +bool x30 = x9; +if (!x30) break; +int32_t x32 = x3; +int32_t x34 = x32 + 1; +int32_t x35 = x1[x34]; +int32_t x33 = x1[x32]; +int32_t x38 = 2 * x33; +printf(string("foo: %d, bar: %d\n").c_str(),x35,x38); } return 0; } diff --git a/test-out/epfl/test14-dataop3.check b/test-out/epfl/test14-dataop3.check new file mode 100644 index 00000000..b7c8eb79 --- /dev/null +++ b/test-out/epfl/test14-dataop3.check @@ -0,0 +1,220 @@ +/* FILE: main.c */ +int32_t main(int32_t); +/***************************************** + Emitting C Generated Code +*******************************************/ +#include +#include +#include +#include +int32_t main(int32_t x0) { +int32_t x7 = 0; +int32_t x8 = 0; +int32_t x9 = 0; +bool x10 = false; +bool x11 = false; +int* *x1 = mmap('A.dat') // XX TODO ; +int32_t x2 = x1->length; +bool x12 = 0 < x2; +if (x12) { +x7 += 2; +} else { +} +x11 = x12; +int* *x3 = mmap('B.dat') // XX TODO ; +int32_t x4 = x3->length; +bool x17 = 0 < x4; +if (x17) { +x8 += 2; +} else { +} +x10 = x17; +int* *x5 = mmap('C.dat') // XX TODO ; +int32_t x6 = x5->length; +for (;;) { +bool x22 = true; +for (;;) { +bool x23 = x11; +bool x26; +if (x23) { +bool x24 = x22; +x26 = x24; +} else { +x26 = false; +} +if (!x26) break; +bool x28 = true; +for (;;) { +bool x29 = x10; +bool x32; +if (x29) { +bool x30 = x28; +x32 = x30; +} else { +x32 = false; +} +if (!x32) break; +int32_t x34 = x9; +bool x35 = x34 < x6; +if (x35) { +x9 += 2; +} else { +} +bool x39 = x35; +for (;;) { +bool x40 = x39; +bool x51; +if (x40) { +int32_t x41 = x8; +int32_t x45 = x9; +int32_t x43 = x41 + 1; +int32_t x44 = x3[x43]; +int32_t x46 = x5[x45]; +bool x49 = x44 != x46; +x51 = x49; +} else { +x51 = false; +} +if (!x51) break; +int32_t x53 = x9; +bool x54 = x53 < x6; +if (x54) { +x9 += 2; +} else { +} +x39 = x54; +} +bool x61 = x39; +bool x62 = !x61; +if (x62) { +int32_t x63 = x8; +bool x64 = x63 < x4; +if (x64) { +x8 += 2; +} else { +} +x10 = x64; +x9 = 0; +} else { +x28 = false; +} +} +bool x76 = x10; +bool x77 = x76; +for (;;) { +bool x78 = x77; +bool x93; +if (x78) { +int32_t x79 = x7; +int32_t x83 = x8; +int32_t x87 = x9; +int32_t x81 = x79 + 1; +int32_t x82 = x1[x81]; +int32_t x84 = x3[x83]; +bool x91 = x82 != x84; +x93 = x91; +} else { +x93 = false; +} +if (!x93) break; +bool x95 = true; +for (;;) { +bool x96 = x10; +bool x99; +if (x96) { +bool x97 = x95; +x99 = x97; +} else { +x99 = false; +} +if (!x99) break; +int32_t x101 = x9; +bool x102 = x101 < x6; +if (x102) { +x9 += 2; +} else { +} +bool x106 = x102; +for (;;) { +bool x107 = x106; +bool x118; +if (x107) { +int32_t x108 = x8; +int32_t x112 = x9; +int32_t x110 = x108 + 1; +int32_t x111 = x3[x110]; +int32_t x113 = x5[x112]; +bool x116 = x111 != x113; +x118 = x116; +} else { +x118 = false; +} +if (!x118) break; +int32_t x120 = x9; +bool x121 = x120 < x6; +if (x121) { +x9 += 2; +} else { +} +x106 = x121; +} +bool x128 = x106; +bool x129 = !x128; +if (x129) { +int32_t x130 = x8; +bool x131 = x130 < x4; +if (x131) { +x8 += 2; +} else { +} +x10 = x131; +x9 = 0; +} else { +x95 = false; +} +} +bool x143 = x10; +x77 = x143; +} +bool x147 = x77; +bool x148 = !x147; +if (x148) { +int32_t x149 = x7; +bool x150 = x149 < x2; +if (x150) { +x7 += 2; +} else { +} +x11 = x150; +x8 = 0; +if (x17) { +x8 += 2; +} else { +} +x10 = x17; +x9 = 0; +} else { +x22 = false; +} +} +bool x167 = x11; +if (!x167) break; +int32_t x169 = x7; +int32_t x173 = x8; +int32_t x177 = x9; +int32_t x170 = x1[x169]; +int32_t x171 = x169 + 1; +int32_t x172 = x1[x171]; +int32_t x174 = x3[x173]; +int32_t x175 = x173 + 1; +int32_t x176 = x3[x175]; +int32_t x178 = x5[x177]; +int32_t x179 = x177 + 1; +int32_t x180 = x5[x179]; +printf(string("a1: %d, a2: %d, b1: %d, b2: %d, c1: %d, c2: %d\n").c_str(),x170,x172,x174,x176,x178,x180); +} +return 0; +} +/***************************************** + End of C Generated Code +*******************************************/ diff --git a/test-out/epfl/test14-queries2.check b/test-out/epfl/test14-queries2.check index 91a28575..3f13fe95 100644 --- a/test-out/epfl/test14-queries2.check +++ b/test-out/epfl/test14-queries2.check @@ -1,10 +1,12 @@ +nVars=1000 +nVars=2000 /***************************************** Emitting Generated Code *******************************************/ import scala.lms.epfl.test14.Schema -class staged0 extends ((Unit)=>(Unit)) { +class staged$0 extends ((Unit)=>(Unit)) { def apply(x0:Unit): Unit = { -println("rangeFromNames(\"Edna\",\"Bert\"):") +val x2550 = println("rangeFromNames(\"Edna\",\"Bert\"):") val x617 = Schema.db.people.flatMap { x111 => val x616 = Schema.db.people.flatMap { x435 => val x615 = Schema.db.people.flatMap { x598 => @@ -17,25 +19,13 @@ val x602 = x598.age val x603 = x116 <= x602 val x441 = x435.age val x604 = x602 < x441 -val x605 = if (x603 == true) { - -x604 -} else false - -val x611 = if (x439 == true) { - -x605 -} else false - -val x613 = if (x113 == true) { - -x611 -} else false - +val x605 = x603 && x604 +val x611 = x439 && x605 +val x613 = x113 && x611 val x614 = if (x613) { -val x608 = x598.name -val x607 = new Schema.Record { val name = x608 } -val x609 = List(x607) +val x607 = x598.name +val x608 = new Schema.Record { val name = x607 } +val x609 = List(x608) x609 } else { val x19 = List() @@ -47,12 +37,14 @@ x615 } x616 } -println(x617) +val x2551 = println(x617) +x2551 } } /***************************************** End of Generated Code *******************************************/ +compilation: ok rangeFromNames("Edna","Bert"): List({name:Cora}, {name:Drew}, {name:Edna}) diff --git a/test-out/epfl/test14-queries3.check b/test-out/epfl/test14-queries3.check index 4adf8171..1526c97a 100644 --- a/test-out/epfl/test14-queries3.check +++ b/test-out/epfl/test14-queries3.check @@ -1,10 +1,12 @@ +nVars=1000 +nVars=2000 /***************************************** Emitting Generated Code *******************************************/ import scala.lms.epfl.test14.Schema -class staged1 extends ((Unit)=>(Unit)) { +class staged$0 extends ((Unit)=>(Unit)) { def apply(x0:Unit): Unit = { -println("expertise(\"abstract\"):") +val x2550 = println("expertise(\"abstract\"):") val x800 = Schema.org.departments.flatMap { x732 => val x792 = Schema.org.employees.flatMap { x763 => val x734 = x732.dpt @@ -16,11 +18,7 @@ val x777 = x776.emp val x778 = x767 == x777 val x779 = x776.tsk val x780 = x779 == "abstract" -val x781 = if (x778 == true) { - -x780 -} else false - +val x781 = x778 && x780 val x784 = if (x781) { val x661 = new Schema.Record { val ignore = () } val x688 = List(x661) @@ -32,11 +30,7 @@ x19 x784 } val x786 = x785.isEmpty -val x788 = if (x765 == true) { - -x786 -} else false - +val x788 = x765 && x786 val x791 = if (x788) { val x661 = new Schema.Record { val ignore = () } val x688 = List(x661) @@ -59,12 +53,16 @@ x19 } x799 } -println(x800) +val x2551 = println(x800) +x2551 } } /***************************************** End of Generated Code *******************************************/ +warning: there were 9 feature warnings; re-run with -feature for details +one warning found +compilation: ok expertise("abstract"): List({dpt:Quality}, {dpt:Research}) diff --git a/test-out/epfl/test14-queries4.check b/test-out/epfl/test14-queries4.check index 4265c25d..fa5b5c59 100644 --- a/test-out/epfl/test14-queries4.check +++ b/test-out/epfl/test14-queries4.check @@ -1,26 +1,24 @@ +nVars=1000 +nVars=2000 /***************************************** Emitting Generated Code *******************************************/ import scala.lms.epfl.test14.Schema -class staged2 extends ((Unit)=>(Unit)) { +class staged$0 extends ((Unit)=>(Unit)) { def apply(x0:Unit): Unit = { -println("expertise2(\"abstract\"):") +val x2550 = println("expertise2(\"abstract\"):") val x1147 = Schema.org.departments.flatMap { x991 => val x1140 = Schema.org.employees.flatMap { x1083 => val x993 = x991.dpt val x1084 = x1083.dpt val x1085 = x993 == x1084 val x1133 = Schema.org.tasks.flatMap { x1120 => -val x1089 = x1083.emp +val x1088 = x1083.emp val x1121 = x1120.emp -val x1122 = x1089 == x1121 +val x1122 = x1088 == x1121 val x1125 = x1120.tsk val x1128 = x1125 == "abstract" -val x1130 = if (x1122 == true) { - -x1128 -} else false - +val x1130 = x1122 && x1128 val x1132 = if (x1130) { val x661 = new Schema.Record { val ignore = () } val x688 = List(x661) @@ -32,11 +30,7 @@ x19 x1132 } val x1134 = x1133.isEmpty -val x1137 = if (x1085 == true) { - -x1134 -} else false - +val x1137 = x1085 && x1134 val x1139 = if (x1137) { val x661 = new Schema.Record { val ignore = () } val x688 = List(x661) @@ -59,12 +53,16 @@ x19 } x1146 } -println(x1147) +val x2551 = println(x1147) +x2551 } } /***************************************** End of Generated Code *******************************************/ +warning: there were 9 feature warnings; re-run with -feature for details +one warning found +compilation: ok expertise2("abstract"): List({dpt:Quality}, {dpt:Research}) diff --git a/test-out/epfl/test2-fft3.check b/test-out/epfl/test2-fft3.check index 35188b88..b25a3270 100644 --- a/test-out/epfl/test2-fft3.check +++ b/test-out/epfl/test2-fft3.check @@ -34,4 +34,5 @@ x27 /***************************************** End of Generated Code *******************************************/ +compilation: ok 6.0,0.0,-1.0,1.0,0.0,0.0,-1.0,-1.0 diff --git a/test-out/epfl/test2-power.check b/test-out/epfl/test2-power.check index 1304d6c4..e286c129 100644 --- a/test-out/epfl/test2-power.check +++ b/test-out/epfl/test2-power.check @@ -58,4 +58,5 @@ x3 /***************************************** End of Generated Code *******************************************/ +compilation: ok 16.0 diff --git a/test-out/epfl/test2-sort1-dot.check b/test-out/epfl/test2-sort1-dot.check new file mode 100644 index 00000000..9feb3b6c --- /dev/null +++ b/test-out/epfl/test2-sort1-dot.check @@ -0,0 +1,303 @@ +digraph G { +rankdir=LR +"Sym(8)" [ +label="Sym(8) \n Min(Sym(0),Sym(1))" +shape=box +] +"Sym(0)" -> "Sym(8)" +"Sym(1)" -> "Sym(8)" +"Sym(10)" [ +label="Sym(10) \n Min(Sym(2),Sym(3))" +shape=box +] +"Sym(2)" -> "Sym(10)" +"Sym(3)" -> "Sym(10)" +"Sym(12)" [ +label="Sym(12) \n Min(Sym(8),Sym(10))" +shape=box +] +"Sym(8)" -> "Sym(12)" +"Sym(10)" -> "Sym(12)" +"Sym(9)" [ +label="Sym(9) \n Max(Sym(0),Sym(1))" +shape=box +] +"Sym(0)" -> "Sym(9)" +"Sym(1)" -> "Sym(9)" +"Sym(11)" [ +label="Sym(11) \n Max(Sym(2),Sym(3))" +shape=box +] +"Sym(2)" -> "Sym(11)" +"Sym(3)" -> "Sym(11)" +"Sym(14)" [ +label="Sym(14) \n Min(Sym(9),Sym(11))" +shape=box +] +"Sym(9)" -> "Sym(14)" +"Sym(11)" -> "Sym(14)" +"Sym(16)" [ +label="Sym(16) \n Min(Sym(12),Sym(14))" +shape=box +] +"Sym(12)" -> "Sym(16)" +"Sym(14)" -> "Sym(16)" +"Sym(20)" [ +label="Sym(20) \n Min(Sym(4),Sym(5))" +shape=box +] +"Sym(4)" -> "Sym(20)" +"Sym(5)" -> "Sym(20)" +"Sym(22)" [ +label="Sym(22) \n Min(Sym(6),Sym(7))" +shape=box +] +"Sym(6)" -> "Sym(22)" +"Sym(7)" -> "Sym(22)" +"Sym(24)" [ +label="Sym(24) \n Min(Sym(20),Sym(22))" +shape=box +] +"Sym(20)" -> "Sym(24)" +"Sym(22)" -> "Sym(24)" +"Sym(21)" [ +label="Sym(21) \n Max(Sym(4),Sym(5))" +shape=box +] +"Sym(4)" -> "Sym(21)" +"Sym(5)" -> "Sym(21)" +"Sym(23)" [ +label="Sym(23) \n Max(Sym(6),Sym(7))" +shape=box +] +"Sym(6)" -> "Sym(23)" +"Sym(7)" -> "Sym(23)" +"Sym(26)" [ +label="Sym(26) \n Min(Sym(21),Sym(23))" +shape=box +] +"Sym(21)" -> "Sym(26)" +"Sym(23)" -> "Sym(26)" +"Sym(28)" [ +label="Sym(28) \n Min(Sym(24),Sym(26))" +shape=box +] +"Sym(24)" -> "Sym(28)" +"Sym(26)" -> "Sym(28)" +"Sym(32)" [ +label="Sym(32) \n Min(Sym(16),Sym(28))" +shape=box +] +"Sym(16)" -> "Sym(32)" +"Sym(28)" -> "Sym(32)" +"Sym(13)" [ +label="Sym(13) \n Max(Sym(8),Sym(10))" +shape=box +] +"Sym(8)" -> "Sym(13)" +"Sym(10)" -> "Sym(13)" +"Sym(15)" [ +label="Sym(15) \n Max(Sym(9),Sym(11))" +shape=box +] +"Sym(9)" -> "Sym(15)" +"Sym(11)" -> "Sym(15)" +"Sym(18)" [ +label="Sym(18) \n Min(Sym(13),Sym(15))" +shape=box +] +"Sym(13)" -> "Sym(18)" +"Sym(15)" -> "Sym(18)" +"Sym(25)" [ +label="Sym(25) \n Max(Sym(20),Sym(22))" +shape=box +] +"Sym(20)" -> "Sym(25)" +"Sym(22)" -> "Sym(25)" +"Sym(27)" [ +label="Sym(27) \n Max(Sym(21),Sym(23))" +shape=box +] +"Sym(21)" -> "Sym(27)" +"Sym(23)" -> "Sym(27)" +"Sym(30)" [ +label="Sym(30) \n Min(Sym(25),Sym(27))" +shape=box +] +"Sym(25)" -> "Sym(30)" +"Sym(27)" -> "Sym(30)" +"Sym(34)" [ +label="Sym(34) \n Min(Sym(18),Sym(30))" +shape=box +] +"Sym(18)" -> "Sym(34)" +"Sym(30)" -> "Sym(34)" +"Sym(36)" [ +label="Sym(36) \n Min(Sym(32),Sym(34))" +shape=box +] +"Sym(32)" -> "Sym(36)" +"Sym(34)" -> "Sym(36)" +"Sym(17)" [ +label="Sym(17) \n Max(Sym(12),Sym(14))" +shape=box +] +"Sym(12)" -> "Sym(17)" +"Sym(14)" -> "Sym(17)" +"Sym(29)" [ +label="Sym(29) \n Max(Sym(24),Sym(26))" +shape=box +] +"Sym(24)" -> "Sym(29)" +"Sym(26)" -> "Sym(29)" +"Sym(40)" [ +label="Sym(40) \n Min(Sym(17),Sym(29))" +shape=box +] +"Sym(17)" -> "Sym(40)" +"Sym(29)" -> "Sym(40)" +"Sym(19)" [ +label="Sym(19) \n Max(Sym(13),Sym(15))" +shape=box +] +"Sym(13)" -> "Sym(19)" +"Sym(15)" -> "Sym(19)" +"Sym(31)" [ +label="Sym(31) \n Max(Sym(25),Sym(27))" +shape=box +] +"Sym(25)" -> "Sym(31)" +"Sym(27)" -> "Sym(31)" +"Sym(42)" [ +label="Sym(42) \n Min(Sym(19),Sym(31))" +shape=box +] +"Sym(19)" -> "Sym(42)" +"Sym(31)" -> "Sym(42)" +"Sym(44)" [ +label="Sym(44) \n Min(Sym(40),Sym(42))" +shape=box +] +"Sym(40)" -> "Sym(44)" +"Sym(42)" -> "Sym(44)" +"Sym(48)" [ +label="Sym(48) \n Min(Sym(36),Sym(44))" +shape=box +] +"Sym(36)" -> "Sym(48)" +"Sym(44)" -> "Sym(48)" +"Sym(49)" [ +label="Sym(49) \n Max(Sym(36),Sym(44))" +shape=box +] +"Sym(36)" -> "Sym(49)" +"Sym(44)" -> "Sym(49)" +"Sym(37)" [ +label="Sym(37) \n Max(Sym(32),Sym(34))" +shape=box +] +"Sym(32)" -> "Sym(37)" +"Sym(34)" -> "Sym(37)" +"Sym(45)" [ +label="Sym(45) \n Max(Sym(40),Sym(42))" +shape=box +] +"Sym(40)" -> "Sym(45)" +"Sym(42)" -> "Sym(45)" +"Sym(50)" [ +label="Sym(50) \n Min(Sym(37),Sym(45))" +shape=box +] +"Sym(37)" -> "Sym(50)" +"Sym(45)" -> "Sym(50)" +"Sym(51)" [ +label="Sym(51) \n Max(Sym(37),Sym(45))" +shape=box +] +"Sym(37)" -> "Sym(51)" +"Sym(45)" -> "Sym(51)" +"Sym(33)" [ +label="Sym(33) \n Max(Sym(16),Sym(28))" +shape=box +] +"Sym(16)" -> "Sym(33)" +"Sym(28)" -> "Sym(33)" +"Sym(35)" [ +label="Sym(35) \n Max(Sym(18),Sym(30))" +shape=box +] +"Sym(18)" -> "Sym(35)" +"Sym(30)" -> "Sym(35)" +"Sym(38)" [ +label="Sym(38) \n Min(Sym(33),Sym(35))" +shape=box +] +"Sym(33)" -> "Sym(38)" +"Sym(35)" -> "Sym(38)" +"Sym(41)" [ +label="Sym(41) \n Max(Sym(17),Sym(29))" +shape=box +] +"Sym(17)" -> "Sym(41)" +"Sym(29)" -> "Sym(41)" +"Sym(43)" [ +label="Sym(43) \n Max(Sym(19),Sym(31))" +shape=box +] +"Sym(19)" -> "Sym(43)" +"Sym(31)" -> "Sym(43)" +"Sym(46)" [ +label="Sym(46) \n Min(Sym(41),Sym(43))" +shape=box +] +"Sym(41)" -> "Sym(46)" +"Sym(43)" -> "Sym(46)" +"Sym(52)" [ +label="Sym(52) \n Min(Sym(38),Sym(46))" +shape=box +] +"Sym(38)" -> "Sym(52)" +"Sym(46)" -> "Sym(52)" +"Sym(53)" [ +label="Sym(53) \n Max(Sym(38),Sym(46))" +shape=box +] +"Sym(38)" -> "Sym(53)" +"Sym(46)" -> "Sym(53)" +"Sym(39)" [ +label="Sym(39) \n Max(Sym(33),Sym(35))" +shape=box +] +"Sym(33)" -> "Sym(39)" +"Sym(35)" -> "Sym(39)" +"Sym(47)" [ +label="Sym(47) \n Max(Sym(41),Sym(43))" +shape=box +] +"Sym(41)" -> "Sym(47)" +"Sym(43)" -> "Sym(47)" +"Sym(54)" [ +label="Sym(54) \n Min(Sym(39),Sym(47))" +shape=box +] +"Sym(39)" -> "Sym(54)" +"Sym(47)" -> "Sym(54)" +"Sym(55)" [ +label="Sym(55) \n Max(Sym(39),Sym(47))" +shape=box +] +"Sym(39)" -> "Sym(55)" +"Sym(47)" -> "Sym(55)" +"Sym(56)" [ +label="Sym(56) \n Result(List(Sym(48), Sym(49), Sym(50), Sym(51), Sym(52), Sym(53), Sym(54), Sym(55)))" +shape=box +] +"Sym(48)" -> "Sym(56)" +"Sym(49)" -> "Sym(56)" +"Sym(50)" -> "Sym(56)" +"Sym(51)" -> "Sym(56)" +"Sym(52)" -> "Sym(56)" +"Sym(53)" -> "Sym(56)" +"Sym(54)" -> "Sym(56)" +"Sym(55)" -> "Sym(56)" +} diff --git a/test-out/epfl/test2-sort1.check b/test-out/epfl/test2-sort1.check new file mode 100644 index 00000000..0af4f15d --- /dev/null +++ b/test-out/epfl/test2-sort1.check @@ -0,0 +1,49 @@ +TP(Sym(8),Min(Sym(0),Sym(1))) +TP(Sym(9),Max(Sym(0),Sym(1))) +TP(Sym(10),Min(Sym(2),Sym(3))) +TP(Sym(11),Max(Sym(2),Sym(3))) +TP(Sym(12),Min(Sym(8),Sym(10))) +TP(Sym(13),Max(Sym(8),Sym(10))) +TP(Sym(14),Min(Sym(9),Sym(11))) +TP(Sym(15),Max(Sym(9),Sym(11))) +TP(Sym(16),Min(Sym(12),Sym(14))) +TP(Sym(17),Max(Sym(12),Sym(14))) +TP(Sym(18),Min(Sym(13),Sym(15))) +TP(Sym(19),Max(Sym(13),Sym(15))) +TP(Sym(20),Min(Sym(4),Sym(5))) +TP(Sym(21),Max(Sym(4),Sym(5))) +TP(Sym(22),Min(Sym(6),Sym(7))) +TP(Sym(23),Max(Sym(6),Sym(7))) +TP(Sym(24),Min(Sym(20),Sym(22))) +TP(Sym(25),Max(Sym(20),Sym(22))) +TP(Sym(26),Min(Sym(21),Sym(23))) +TP(Sym(27),Max(Sym(21),Sym(23))) +TP(Sym(28),Min(Sym(24),Sym(26))) +TP(Sym(29),Max(Sym(24),Sym(26))) +TP(Sym(30),Min(Sym(25),Sym(27))) +TP(Sym(31),Max(Sym(25),Sym(27))) +TP(Sym(32),Min(Sym(16),Sym(28))) +TP(Sym(33),Max(Sym(16),Sym(28))) +TP(Sym(34),Min(Sym(18),Sym(30))) +TP(Sym(35),Max(Sym(18),Sym(30))) +TP(Sym(36),Min(Sym(32),Sym(34))) +TP(Sym(37),Max(Sym(32),Sym(34))) +TP(Sym(38),Min(Sym(33),Sym(35))) +TP(Sym(39),Max(Sym(33),Sym(35))) +TP(Sym(40),Min(Sym(17),Sym(29))) +TP(Sym(41),Max(Sym(17),Sym(29))) +TP(Sym(42),Min(Sym(19),Sym(31))) +TP(Sym(43),Max(Sym(19),Sym(31))) +TP(Sym(44),Min(Sym(40),Sym(42))) +TP(Sym(45),Max(Sym(40),Sym(42))) +TP(Sym(46),Min(Sym(41),Sym(43))) +TP(Sym(47),Max(Sym(41),Sym(43))) +TP(Sym(48),Min(Sym(36),Sym(44))) +TP(Sym(49),Max(Sym(36),Sym(44))) +TP(Sym(50),Min(Sym(37),Sym(45))) +TP(Sym(51),Max(Sym(37),Sym(45))) +TP(Sym(52),Min(Sym(38),Sym(46))) +TP(Sym(53),Max(Sym(38),Sym(46))) +TP(Sym(54),Min(Sym(39),Sym(47))) +TP(Sym(55),Max(Sym(39),Sym(47))) +List(Sym(48), Sym(49), Sym(50), Sym(51), Sym(52), Sym(53), Sym(54), Sym(55)) diff --git a/test-out/epfl/test4-counter1.check b/test-out/epfl/test4-counter1.check index 2d38202a..3362f21d 100644 --- a/test-out/epfl/test4-counter1.check +++ b/test-out/epfl/test4-counter1.check @@ -22,6 +22,7 @@ x10 /***************************************** End of Generated Code *******************************************/ +compilation: ok idx: 0 out: List(0.0) char: X diff --git a/test-out/epfl/test4-counter2.check b/test-out/epfl/test4-counter2.check index 8e9c8120..92a61f0c 100644 --- a/test-out/epfl/test4-counter2.check +++ b/test-out/epfl/test4-counter2.check @@ -3,9 +3,9 @@ *******************************************/ class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { -var x59 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.collection.immutable.List[Char], scala.collection.immutable.List[Char]], scala.Tuple2[scala.collection.immutable.List[Char], scala.collection.immutable.List[Char]]]] -var x7 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.Tuple2[scala.Tuple2[scala.Tuple2[Double, scala.Tuple2[Double, Double]], Double], Double], scala.collection.immutable.List[Char]], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] -x59 = {x60: (scala.Tuple2[scala.collection.immutable.List[Char], scala.collection.immutable.List[Char]]) => +var x59 = null.asInstanceOf[scala.Function1[Tuple2ListCharListChar, Tuple2ListCharListChar]] +var x7 = null.asInstanceOf[scala.Function1[Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +x59 = {x60: (Tuple2ListCharListChar) => val x61 = x60._1 val x63 = x61.isEmpty val x65 = if (x63) { @@ -19,7 +19,7 @@ val x62 = x60._2 val x67 = x61.head val x68 = List(x67) val x69 = x62 ::: x68 -val x70 = (x66,x69) +val x70 = new Tuple2ListCharListChar(x66,x69) val x71 = x59(x70) x71 } else { @@ -27,7 +27,7 @@ x60 } x72 } -x7 = {x8: (scala.Tuple2[scala.Tuple2[scala.Tuple2[scala.Tuple2[Double, scala.Tuple2[Double, Double]], Double], Double], scala.collection.immutable.List[Char]]) => +x7 = {x8: (Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar) => val x10 = x8._2 val x9 = x8._1 val x12 = x9._2 @@ -37,10 +37,10 @@ val x13 = x11._1 val x15 = x13._1 val x16 = x13._2 val x18 = x16._2 -val x19 = (x15,x18) -val x20 = (x19,x14) -val x21 = (x20,x12) -val x22 = (x21,x10) +val x19 = new Tuple2DoubleDouble(x15,x18) +val x20 = new Tuple2Tuple2DoubleDoubleDouble(x19,x14) +val x21 = new Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(x20,x12) +val x22 = new Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(x21,x10) val x23 = List(x22) val x24 = {x25: (Char) => val x27 = x8 // x25 @@ -63,7 +63,7 @@ val x40 = x35._2 val x43 = x40+1.0 x43 } -val x45 = (0.0,x44) +val x45 = new Tuple2DoubleDouble(0.0,x44) (x37,x45) } else { val x28 = x27._1 @@ -74,10 +74,10 @@ val x35 = x32._2 val x40 = x35._2 val x39 = x35._1 val x46 = x39+1.0 -val x47 = (x46,x40) +val x47 = new Tuple2DoubleDouble(x46,x40) (x34,x47) } -val x49 = (x38,x48) +val x49 = new Tuple2DoubleTuple2DoubleDouble(x38,x48) val x50 = x25 == 'B' val x52 = if (x50) { val x28 = x27._1 @@ -91,7 +91,7 @@ val x30 = x28._1 val x33 = x30._2 x33 } -val x53 = (x49,x52) +val x53 = new Tuple2Tuple2DoubleTuple2DoubleDoubleDouble(x49,x52) val x54 = x25 == 'C' val x56 = if (x54) { val x28 = x27._1 @@ -103,13 +103,13 @@ val x28 = x27._1 val x31 = x28._2 x31 } -val x57 = (x53,x56) +val x57 = new Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDouble(x53,x56) val x26 = List(x25,x25,x25) val x29 = x27._2 -val x58 = (x26,x29) +val x58 = new Tuple2ListCharListChar(x26,x29) val x73 = x59(x58) val x75 = x73._2 -val x76 = (x57,x75) +val x76 = new Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar(x57,x75) val x77 = x7(x76) x77 } @@ -117,11 +117,11 @@ val x78 = scala.lms.epfl.test4.Automaton(x23,x24) x78 } val x1 = List() -val x2 = (0.0,0.0) -val x3 = (0.0,x2) -val x4 = (x3,0.0) -val x5 = (x4,0.0) -val x6 = (x5,x1) +val x2 = new Tuple2DoubleDouble(0.0,0.0) +val x3 = new Tuple2DoubleTuple2DoubleDouble(0.0,x2) +val x4 = new Tuple2Tuple2DoubleTuple2DoubleDoubleDouble(x3,0.0) +val x5 = new Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDouble(x4,0.0) +val x6 = new Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar(x5,x1) val x79 = x7(x6) x79 } @@ -129,47 +129,66 @@ x79 /***************************************** End of Generated Code *******************************************/ + +case class Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDouble(_1: Tuple2Tuple2DoubleTuple2DoubleDoubleDouble, _2: Double) + +case class Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(_1: Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble, _2: scala.collection.immutable.List[Char]) + +case class Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(_1: Tuple2Tuple2DoubleDoubleDouble, _2: Double) + +case class Tuple2DoubleTuple2DoubleDouble(_1: Double, _2: Tuple2DoubleDouble) + +case class Tuple2ListCharListChar(_1: scala.collection.immutable.List[Char], _2: scala.collection.immutable.List[Char]) + +case class Tuple2DoubleDouble(_1: Double, _2: Double) + +case class Tuple2Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDoubleListChar(_1: Tuple2Tuple2Tuple2DoubleTuple2DoubleDoubleDoubleDouble, _2: scala.collection.immutable.List[Char]) + +case class Tuple2Tuple2DoubleDoubleDouble(_1: Tuple2DoubleDouble, _2: Double) + +case class Tuple2Tuple2DoubleTuple2DoubleDoubleDouble(_1: Tuple2DoubleTuple2DoubleDouble, _2: Double) +compilation: ok idx: 0 -out: List(((((0.0,0.0),0.0),0.0),List())) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(0.0,0.0),0.0),0.0),List())) char: X idx: 1 -out: List(((((0.0,0.0),0.0),0.0),List(X, X, X))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(0.0,0.0),0.0),0.0),List(X, X, X))) char: A idx: 2 -out: List(((((1.0,1.0),0.0),0.0),List(X, X, X, A, A, A))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(1.0,1.0),0.0),0.0),List(X, X, X, A, A, A))) char: B idx: 3 -out: List(((((1.0,1.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(1.0,1.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B))) char: Z idx: 4 -out: List(((((1.0,1.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(1.0,1.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z))) char: A idx: 5 -out: List(((((2.0,2.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(2.0,2.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A))) char: A idx: 6 -out: List(((((3.0,2.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(3.0,2.0),1.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A))) char: B idx: 7 -out: List(((((3.0,2.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(3.0,2.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B))) char: W idx: 8 -out: List(((((3.0,2.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(3.0,2.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W))) char: A idx: 9 -out: List(((((4.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(4.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A))) char: A idx: 10 -out: List(((((5.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(5.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A))) char: A idx: 11 -out: List(((((6.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(6.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A))) char: A idx: 12 -out: List(((((7.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(7.0,3.0),2.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A))) char: B idx: 13 -out: List(((((7.0,3.0),3.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A, B, B, B))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(7.0,3.0),3.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A, B, B, B))) char: Q idx: 14 -out: List(((((7.0,3.0),3.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A, B, B, B, Q, Q, Q))) +out: List(Tuple2Tuple2Tuple2Tuple2DoubleDoubleDoubleDoubleListChar(Tuple2Tuple2Tuple2DoubleDoubleDoubleDouble(Tuple2Tuple2DoubleDoubleDouble(Tuple2DoubleDouble(7.0,3.0),3.0),0.0),List(X, X, X, A, A, A, B, B, B, Z, Z, Z, A, A, A, A, A, A, B, B, B, W, W, W, A, A, A, A, A, A, A, A, A, A, A, A, B, B, B, Q, Q, Q))) diff --git a/test-out/epfl/test4-matchernew1.check b/test-out/epfl/test4-matchernew1.check index abaac6a6..da550cf8 100644 --- a/test-out/epfl/test4-matchernew1.check +++ b/test-out/epfl/test4-matchernew1.check @@ -19,15 +19,8 @@ x10 } x18 } -x4 = {x5: (Char) => -val x6 = x5 == 'A' -val x16 = if (x6) { -x13 -} else { -x10 -} -x16 -} +x10 = scala.lms.epfl.test4.Automaton(List(),x1) +x11 = x10.copy(out = "found"::x10.out) x7 = {x8: (Char) => val x9 = x8 == 'B' val x15 = if (x9) { @@ -43,9 +36,16 @@ x14 } x15 } -x10 = scala.lms.epfl.test4.Automaton(List(),x1) -x11 = x10.copy(out = "found"::x10.out) x13 = scala.lms.epfl.test4.Automaton(List(),x7) +x4 = {x5: (Char) => +val x6 = x5 == 'A' +val x16 = if (x6) { +x13 +} else { +x10 +} +x16 +} x17 = scala.lms.epfl.test4.Automaton(List(),x4) x10 } @@ -53,6 +53,7 @@ x10 /***************************************** End of Generated Code *******************************************/ +compilation: ok idx: 0 out: List() char: X diff --git a/test-out/epfl/test4-matchernew1b.check b/test-out/epfl/test4-matchernew1b.check index edb5980f..829e37b5 100644 --- a/test-out/epfl/test4-matchernew1b.check +++ b/test-out/epfl/test4-matchernew1b.check @@ -19,15 +19,8 @@ x12 } x18 } -x4 = {x5: (Char) => -val x6 = x5 == 'A' -val x16 = if (x6) { -x10 -} else { -x12 -} -x16 -} +x12 = scala.lms.epfl.test4.Automaton(List(),x1) +x13 = x12.copy(out = "found"::x12.out) x7 = {x8: (Char) => val x9 = x8 == 'A' val x15 = if (x9) { @@ -44,8 +37,15 @@ x14 x15 } x10 = scala.lms.epfl.test4.Automaton(List(),x7) -x12 = scala.lms.epfl.test4.Automaton(List(),x1) -x13 = x12.copy(out = "found"::x12.out) +x4 = {x5: (Char) => +val x6 = x5 == 'A' +val x16 = if (x6) { +x10 +} else { +x12 +} +x16 +} x17 = scala.lms.epfl.test4.Automaton(List(),x4) x12 } @@ -53,6 +53,7 @@ x12 /***************************************** End of Generated Code *******************************************/ +compilation: ok idx: 0 out: List() char: X diff --git a/test-out/epfl/test4-matchernew2.check b/test-out/epfl/test4-matchernew2.check index 1f8d885a..d3f86295 100644 --- a/test-out/epfl/test4-matchernew2.check +++ b/test-out/epfl/test4-matchernew2.check @@ -64,6 +64,7 @@ x32 /***************************************** End of Generated Code *******************************************/ +compilation: ok idx: 0 out: List() char: X diff --git a/test-out/epfl/test4-matchernew2b.check b/test-out/epfl/test4-matchernew2b.check index dc9b0f02..74c9198c 100644 --- a/test-out/epfl/test4-matchernew2b.check +++ b/test-out/epfl/test4-matchernew2b.check @@ -64,6 +64,7 @@ x32 /***************************************** End of Generated Code *******************************************/ +compilation: ok idx: 0 out: List() char: X diff --git a/test-out/epfl/test4-stream1.check b/test-out/epfl/test4-stream1.check index 36ed6636..329e918d 100644 --- a/test-out/epfl/test4-stream1.check +++ b/test-out/epfl/test4-stream1.check @@ -5,8 +5,8 @@ class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collect def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { var x1 = null.asInstanceOf[scala.Function1[Double, Double]] var x33 = null.asInstanceOf[scala.Function1[Double, Double]] -var x19 = null.asInstanceOf[scala.Function1[scala.Tuple2[scala.Tuple2[Double, Double], scala.collection.immutable.List[scala.Tuple2[Double, Double]]], scala.Tuple2[scala.Tuple2[Double, Double], scala.collection.immutable.List[scala.Tuple2[Double, Double]]]]] -var x12 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[scala.Tuple2[Double, Double]], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] +var x19 = null.asInstanceOf[scala.Function1[Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble, Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble]] +var x12 = null.asInstanceOf[scala.Function1[scala.collection.immutable.List[Tuple2DoubleDouble], scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] x1 = {x2: (Double) => val x4 = x2%2 == 0 val x5 = if (x4) { @@ -24,8 +24,6 @@ x2 } x8 } -val x9 = x1(0.0) -val x10 = (0.0,x9) x33 = {x34: (Double) => val x36 = x34%2 == 0 val x37 = if (x36) { @@ -43,7 +41,7 @@ x34 } x40 } -x19 = {x20: (scala.Tuple2[scala.Tuple2[Double, Double], scala.collection.immutable.List[scala.Tuple2[Double, Double]]]) => +x19 = {x20: (Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble) => val x21 = x20._1 val x23 = x21._1 val x25 = x23 < 8.0 @@ -70,12 +68,12 @@ val x31 = x23+1.0 val x24 = x21._2 val x32 = x24+1.0 val x41 = x33(x32) -val x42 = (x31,x41) +val x42 = new Tuple2DoubleDouble(x31,x41) val x22 = x20._2 -val x43 = (x23,x24) +val x43 = new Tuple2DoubleDouble(x23,x24) val x44 = List(x43) val x45 = x22 ::: x44 -val x46 = (x42,x45) +val x46 = new Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble(x42,x45) val x47 = x19(x46) x47 } else { @@ -83,11 +81,13 @@ x20 } x48 } -x12 = {x13: (scala.collection.immutable.List[scala.Tuple2[Double, Double]]) => +val x9 = x1(0.0) +val x10 = new Tuple2DoubleDouble(0.0,x9) +x12 = {x13: (scala.collection.immutable.List[Tuple2DoubleDouble]) => val x14 = List(x13) val x15 = {x16: (Char) => val x17 = x13 // x16 -val x18 = (x10,x17) +val x18 = new Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble(x10,x17) val x49 = x19(x18) val x51 = x49._2 val x52 = x12(x51) @@ -104,47 +104,52 @@ x54 /***************************************** End of Generated Code *******************************************/ + +case class Tuple2Tuple2DoubleDoubleListTuple2DoubleDouble(_1: Tuple2DoubleDouble, _2: scala.collection.immutable.List[Tuple2DoubleDouble]) + +case class Tuple2DoubleDouble(_1: Double, _2: Double) +compilation: ok idx: 0 out: List(List()) char: X idx: 1 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: A idx: 2 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: B idx: 3 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: Z idx: 4 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: A idx: 5 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: A idx: 6 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: B idx: 7 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: W idx: 8 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: A idx: 9 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: A idx: 10 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: A idx: 11 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: A idx: 12 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: B idx: 13 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) char: Q idx: 14 -out: List(List((0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0), (0.0,0.0), (1.0,2.0), (2.0,4.0), (3.0,6.0))) +out: List(List(Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0), Tuple2DoubleDouble(0.0,0.0), Tuple2DoubleDouble(1.0,2.0), Tuple2DoubleDouble(2.0,4.0), Tuple2DoubleDouble(3.0,6.0))) diff --git a/test-out/epfl/test5-conditional.check b/test-out/epfl/test5-conditional.check index 5c04ffab..cf408c71 100644 --- a/test-out/epfl/test5-conditional.check +++ b/test-out/epfl/test5-conditional.check @@ -4,20 +4,20 @@ *******************************************/ class Test extends ((Double)=>(Double)) { def apply(x0:Double): Double = { -println("yoyo") +val x1 = println("yoyo") val x2 = x0 == x0 val x6 = x0+4.0 val x9 = if (x2) { -println("yoyo") -println("xxx") -println("yoyo") +val x3 = println("yoyo") +val x4 = println("xxx") +val x5 = println("yoyo") x6 } else { val x8 = x0+6.0 x8 } -println("yyy") -println("yoyo") +val x10 = println("yyy") +val x11 = println("yoyo") val x12 = x9+x6 x12 } @@ -25,6 +25,7 @@ x12 /***************************************** End of Generated Code *******************************************/ +compilation: ok yoyo yoyo xxx @@ -33,21 +34,21 @@ yyy yoyo 22.0 function main(x0) { -document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) +var x1 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) var x2 = x0==x0 var x6 = x0+4.0 var x9 if (x2) { -document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) -document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("xxx")) -document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) +var x3 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) +var x4 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("xxx")) +var x5 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) x9=x6 } else { var x8 = x0+6.0 x9=x8 } -document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yyy")) -document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) +var x10 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yyy")) +var x11 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) var x12 = x9+x6 return x12 } diff --git a/test-out/epfl/test5-conditional.html.check b/test-out/epfl/test5-conditional.html.check index 2dac1b60..85435a0f 100644 --- a/test-out/epfl/test5-conditional.html.check +++ b/test-out/epfl/test5-conditional.html.check @@ -1,18 +1,18 @@ Scala2JS") + stream.println("") + stream.flush + } + + def emitSource[A : Manifest](args: List[Sym[_]], body: Block[A], methName: String, out: PrintWriter) = { + withStream(out) { + stream.println("function "+methName+"("+args.map(quote).mkString(", ")+") {") + + emitBlock(body) + stream.println("return "+quote(getBlockResult(body))) + + stream.println("}") + } + Nil + } + def emitValDef(sym: Sym[Any], rhs: String): Unit = { + stream.println("var " + quote(sym) + " = " + rhs) + } +} + +trait JSNestedCodegen extends GenericNestedCodegen with JSCodegen { + import IR._ + +} + +trait JSGenBase extends JSCodegen { + val IR: BaseExp +} + +trait JSGenEffect extends JSNestedCodegen with JSGenBase { + val IR: EffectExp +} + + +trait JSGenIfThenElse extends BaseGenIfThenElse with JSGenEffect { // it's more or less generic... + val IR: IfThenElseExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case IfThenElse(c,a,b) => + stream.println("var " + quote(sym)) + stream.println("if (" + quote(c) + ") {") + emitBlock(a) + stream.println(quote(sym) + "=" + quote(getBlockResult(a))) + stream.println("} else {") + emitBlock(b) + stream.println(quote(sym) + "=" + quote(getBlockResult(b))) + stream.println("}") + case _ => super.emitNode(sym, rhs) + } +} + +trait JSGenArith extends JSGenBase { // TODO: define a generic one + val IR: ArithExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case Plus(a,b) => emitValDef(sym, "" + quote(a) + "+" + quote(b)) + case Minus(a,b) => emitValDef(sym, "" + quote(a) + "-" + quote(b)) + case Times(a,b) => emitValDef(sym, "" + quote(a) + "*" + quote(b)) + case Div(a,b) => emitValDef(sym, "" + quote(a) + "/" + quote(b)) + case _ => super.emitNode(sym, rhs) + } +} diff --git a/test-src/epfl/test5-js/TestConditional.scala b/test-src/epfl/test5-js/TestConditional.scala new file mode 100644 index 00000000..7eb3a935 --- /dev/null +++ b/test-src/epfl/test5-js/TestConditional.scala @@ -0,0 +1,130 @@ +package scala.lms +package epfl +package test5 + +import common._ +import test1._ + +import java.io.PrintWriter +import java.io.FileOutputStream + +trait JSGenEqual extends JSGenBase { + val IR: EqualExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case Equal(a,b) => emitValDef(sym, "" + quote(a) + "==" + quote(b)) + case _ => super.emitNode(sym, rhs) + } +} + + + +trait Print extends Base { + implicit def unit(s: String): Rep[String] + def print(s: Rep[Any]): Rep[Unit] +} + +trait PrintExp extends Print with EffectExp { + implicit def unit(s: String): Rep[String] = Const(s) + case class Print(s: Rep[Any]) extends Def[Unit] + def print(s: Rep[Any]) = reflectEffect(Print(s)) +} + +trait ScalaGenPrint extends ScalaGenEffect { + val IR: PrintExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case Print(s) => emitValDef(sym, "println(" + quote(s) + ")") + case _ => super.emitNode(sym, rhs) + } +} + +trait JSGenPrint extends JSGenEffect { + val IR: PrintExp + import IR._ + + // TODO: should have a function for this + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case Print(s) => emitValDef(sym, "document.body.appendChild(document.createElement(\"div\"))"+ + ".appendChild(document.createTextNode("+quote(s)+"))") + case _ => super.emitNode(sym, rhs) + } +} + + + +trait Dom extends Base { + // not used yet... + type DOMObjectInternal + type DOMObject = Rep[DOMObjectInternal] + def document: DOMObject + def infix_getElementById(s: Rep[String]) +} + + + + + +trait ConditionalProg { this: Arith with Equal with Print with IfThenElse => + + def test(x: Rep[Double]): Rep[Double] = { + + print("yoyo") + + val z = if (x == x) { + print("yoyo") + print("xxx") + print("yoyo") + (x+4) + } else { + (x+6) + } + + print("yyy") + print("yoyo") + + z + (x + 4) + } + +} + + + +class TestConditional extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test5-" + + def testConditional = { + withOutFile(prefix+"conditional") { + + println("-- begin") + + new ConditionalProg with ArithExpOpt with EqualExp with PrintExp + with IfThenElseExp with CompileScala { self => + val codegen = new ScalaGenIfThenElse with ScalaGenArith + with ScalaGenEqual with ScalaGenPrint { val IR: self.type = self } + + val f = (x: Rep[Double]) => test(x) + codegen.emitSource(f, "Test", new PrintWriter(System.out)) + val g = compile(f) + println(g(7)) + } + + new ConditionalProg with IfThenElseExp with ArithExpOpt with EqualExp + with PrintExp { self => + val codegen = new JSGenIfThenElse with JSGenArith + with JSGenEqual with JSGenPrint { val IR: self.type = self } + + val f = (x: Rep[Double]) => test(x) + codegen.emitSource(f, "main", new PrintWriter(System.out)) + codegen.emitHTMLPage(() => f(7), new PrintWriter(new FileOutputStream(prefix+"conditional.html"))) + } + + println("-- end") + } + assertFileEqualsCheck(prefix+"conditional") + assertFileEqualsCheck(prefix+"conditional.html") + } +} diff --git a/test-src/epfl/test5-js/TestFunctions.scala b/test-src/epfl/test5-js/TestFunctions.scala new file mode 100644 index 00000000..1e992132 --- /dev/null +++ b/test-src/epfl/test5-js/TestFunctions.scala @@ -0,0 +1,297 @@ +package scala.lms +package epfl +package test5 + +import common._ +import test1._ + +import java.io.PrintWriter +import java.io.FileOutputStream + +trait JSGenFunctions extends JSGenEffect with BaseGenFunctions { + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case Lambda(fun, x, y) => + stream.println("var " + quote(sym) + " = function(" + quote(x) + ") {") + emitBlock(y) + stream.println("return " + quote(getBlockResult(y))) + stream.println("}") + + case Apply(fun, arg) => + emitValDef(sym, quote(fun) + "(" + quote(arg) + ")") + + case _ => super.emitNode(sym, rhs) + } +} + +trait JSGenTupledFunctions extends JSGenFunctions { + val IR: TupledFunctionsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case Lambda(fun, UnboxedTuple(xs), y) => + stream.println("var " + quote(sym) + " = function" + xs.map(quote).mkString("(", ",", ")") + " {") + emitBlock(y) + stream.println("return " + quote(getBlockResult(y))) + stream.println("}") + + case Apply(fun, UnboxedTuple(args)) => + emitValDef(sym, quote(fun) + args.map(quote).mkString("(", ",", ")")) + + case _ => super.emitNode(sym, rhs) + } + + override def quote(x: Exp[Any]) : String = x match { + case UnboxedTuple(t) => + t.zipWithIndex.map({ case(el, i) => "_" + (i+1) + ":" + quote(el)}).mkString("{", ",", "}") + case _ => super.quote(x) + } +} + +trait JSGenStruct extends JSGenBase { + val IR: StructExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case Struct(tag, elems) => + registerStruct(structName(sym.tp), elems) + emitValDef(sym, "{__structName:" + structName(sym.tp) + "," + elems.map(e => e._1+":"+quote(e._2)).mkString(",") + "}") +// printlog("WARNING: emitting " + structName(sym.tp) + " struct " + quote(sym)) + case FieldApply(struct, index) => + emitValDef(sym, quote(struct) + "." + index) +// printlog("WARNING: emitting field access: " + quote(struct) + "." + index) + case FieldUpdate(struct, index, rhs) => + emitValDef(sym, quote(struct) + "." + index + " = " + quote(rhs)) +// printlog("WARNING: emitting field update: " + quote(struct) + "." + index) + case _ => super.emitNode(sym, rhs) + } +} + +trait JSGenTupleOps extends JSGenBase with JSGenStruct { + val IR: TupleOpsExp + import IR._ + +/* FIXME: now using structs to implement tuples + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ETuple2(a,b) => + emitValDef(sym, "{_1:"+ quote(a) + ",_2:" + quote(b) + "}") + case Tuple2Access1(t) => emitValDef(sym, quote(t) + "._1") + case Tuple2Access2(t) => emitValDef(sym, quote(t) + "._2") + + case _ => super.emitNode(sym, rhs) + } +*/ +} + +trait FunctionsProg { this: Print with Functions with IfThenElse with Equal => + def test(x: Rep[Any]): Rep[Any] = { + val f = fun { x : Rep[Any] => + print("foo") + x + } + f(f(x)) + } + + def test2(x: Rep[Double]): Rep[Double => Double] = + fun {(y: Rep[Double]) => if(y == x) unit(2 : Double) else y} +} + +trait FunctionsRecursiveProg { this: Arith with Print with Functions => + def test(x: Rep[Any]): Rep[Any] = { + val f = fun { x : Rep[Any] => + print("foo") + x + } + lazy val g : Rep[Any => Any] = fun { x => + print("bar") + g(x) + } + val h = fun { x : Rep[Any] => + print("baz") + 1 + } + h(g(f(f(x)))) + } +} + +trait TwoArgsFunProg { this: TupledFunctions => + def test(x: Rep[Double]): Rep[(Double, Double)] = { + val f = fun { (a : Rep[Double], b : Rep[Double]) => (b,a) } + f(f(x, x)) + } +} + +trait TupleFunProg { this: Arith with TupledFunctions => + def test (x: Rep[Double]): Rep[(Double, Double)] = { + val f = fun { t : Rep[(Double, Double)] => t } + f(1.0, x) + } +} + +trait NoArgFunProg { this: TupledFunctions => + def test (x: Rep[Any]): Rep[Any] = { + val f = fun { () => x } + f() + } +} + +trait TwoArgsRecursiveFunProg { this: TupledFunctions with Arith with Equal with IfThenElse => + def test(x: Rep[Double]): Rep[Double] = { + lazy val iter : Rep[((Double,Double)) => Double] = fun { (n, acc) => + if (n == 0) acc else iter(n-1, n*acc) + } + iter(x, unit(1.0)) + } +} + +trait SchedFunProg { this: Functions with Arith with Equal with IfThenElse => + def foo: Rep[Double => Double] = fun { a => + def iter : Rep[Double => Double] = fun { b => + if (b == 0) a + else iter(b-1) + } + iter(a) + } + + def test(x: Rep[Double]): Rep[Double] = { + foo(x) + } +} + +class TestFunctions extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test5-" + + def testFunctions = { + withOutFile(prefix+"functions") { + + println("-- begin") + + new FunctionsProg with PrintExp with FunctionsExp with IfThenElseExp with EqualExp{ self => + val codegen = new ScalaGenPrint with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenEqual{ val IR: self.type = self } + + val f = (x: Rep[Double]) => test(x) + codegen.emitSource(f, "Test", new PrintWriter(System.out)) + + val g = (x: Rep[Double]) => test2(x) + codegen.emitSource(g, "Test2", new PrintWriter(System.out)) + } + + new FunctionsProg with PrintExp with FunctionsExp with IfThenElseExp with EqualExp{ self => + val codegen = new JSGenPrint with JSGenFunctions with JSGenIfThenElse with JSGenEqual{ val IR: self.type = self } + + val f = (x: Rep[Double]) => test(x) + codegen.emitSource(f, "main", new PrintWriter(System.out)) + + val g = (x: Rep[Double]) => test2(x) + codegen.emitSource(g, "main2", new PrintWriter(System.out)) + } + + println("-- end") + } + assertFileEqualsCheck(prefix+"functions") + } + + def testFunRetFun = { + withOutFile(prefix+"funretfun") { + + println("-- begin") + + new FunctionsProg with PrintExp with FunctionsExp with IfThenElseExp with EqualExp{ self => + val codegen = new ScalaGenPrint with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenEqual{ + val IR: self.type = self + } + + val f = (x: Rep[Double]) => doLambda{(y: Rep[Int]) => test(x)} + codegen.emitSource(f, "Test", new PrintWriter(System.out)) + } + + new FunctionsProg with PrintExp with FunctionsExp with IfThenElseExp with EqualExp{ self => + val codegen = new JSGenPrint with JSGenFunctions with JSGenIfThenElse with JSGenEqual{ val IR: self.type = self } + + val f = (x: Rep[Double]) => doLambda{(y: Rep[Int]) => test(x)} + codegen.emitSource(f, "main", new PrintWriter(System.out)) + } + + println("-- end") + } + assertFileEqualsCheck(prefix+"funretfun") + } + + def testFunctionsRecursive = { + withOutFile(prefix+"functionsrecursive") { + + println("-- begin") + + new FunctionsRecursiveProg with ArithExpOpt with PrintExp with FunctionsRecursiveExp { self => + val codegen = new ScalaGenArith with ScalaGenPrint with ScalaGenFunctions { val IR: self.type = self } + + val f = (x: Rep[Double]) => test(x) + codegen.emitSource(f, "Test", new PrintWriter(System.out)) + } + + new FunctionsRecursiveProg with ArithExpOpt with PrintExp with FunctionsRecursiveExp { self => + val codegen = new JSGenArith with JSGenPrint with JSGenFunctions { val IR: self.type = self } + + val f = (x: Rep[Double]) => test(x) + codegen.emitSource(f, "main", new PrintWriter(System.out)) + } + + println("-- end") + } + assertFileEqualsCheck(prefix+"functionsrecursive") + } + + def testTwoArgsFun = { + withOutFile(prefix+"twoargsfun") { + new TwoArgsFunProg with TupledFunctionsExp { self => + val codegen = new JSGenTupledFunctions with JSGenTupleOps with GenericGenUnboxedTupleAccess { val IR: self.type = self } + codegen.emitSource(test _, "main", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"twoargsfun") + } + + def testTupleFun = { + withOutFile(prefix+"tuplefun") { + new TupleFunProg with ArithExp with TupledFunctionsExp { self => + val codegen = new JSGenTupledFunctions with JSGenTupleOps with GenericGenUnboxedTupleAccess { val IR: self.type = self } + codegen.emitSource(test _, "main", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"tuplefun") + } + + def testNoArgFun = { + withOutFile(prefix+"noargfun") { + new NoArgFunProg with TupledFunctionsRecursiveExp { self => + val codegen = new JSGenTupledFunctions with JSGenTupleOps with GenericGenUnboxedTupleAccess { val IR: self.type = self } + codegen.emitSource(test _, "main", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"noargfun") + } + + def testTwoArgsRecursiveFun = { + withOutFile(prefix+"twoargsrecfun") { + new TwoArgsRecursiveFunProg with TupledFunctionsRecursiveExp with ArithExpOpt with EqualExp with IfThenElseExp { self => + val codegen = new JSGenTupledFunctions with JSGenArith with JSGenEqual with JSGenIfThenElse with JSGenTupleOps with GenericGenUnboxedTupleAccess { val IR: self.type = self } + codegen.emitSource(test _, "main", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"twoargsrecfun") + } + + def testSchedFun = { + withOutFile(prefix+"schedfun") { + new SchedFunProg with FunctionsRecursiveExp with ArithExpOpt with EqualExp with IfThenElseExp { self => + val codegen = new JSGenFunctions with JSGenArith with JSGenEqual with JSGenIfThenElse { val IR: self.type = self } + val f = (x: Rep[Double]) => test(x) + codegen.emitSource(f, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"schedfun") + } + +} diff --git a/test-src/epfl/test6-layered/Test.scala b/test-src/epfl/test6-layered/Test.scala new file mode 100644 index 00000000..26a9654e --- /dev/null +++ b/test-src/epfl/test6-layered/Test.scala @@ -0,0 +1,239 @@ +package scala.lms +package epfl +package test6 + +import common._ +import test1._ + +import util.OverloadHack + +import java.io.PrintWriter +import java.io.FileOutputStream + + +trait Utils extends Base with OverloadHack { + + def infix_+(a: Rep[String], b: Rep[Any])(implicit x: Overloaded1): Rep[String] + def infix_+(a: Rep[Any], b: Rep[String])(implicit x: Overloaded2): Rep[String] + def infix_+(a: String, b: Rep[Any])(implicit x: Overloaded4): Rep[String] + def infix_+(a: Rep[Any], b: String)(implicit x: Overloaded5): Rep[String] + + implicit def unit(x:String): Rep[String] + implicit def unit(x:Int): Rep[Int] + +} + + +trait UtilExp extends BaseExp with Utils { + + implicit def unit(x:Int): Rep[Int] = Const(x) + implicit def unit(x:String): Rep[String] = Const(x) + + def infix_+(a: Rep[String], b: Rep[Any])(implicit x: Overloaded1): Rep[String] = StrCat(a,b) + def infix_+(a: Rep[Any], b: Rep[String])(implicit x: Overloaded2): Rep[String] = StrCat(a,b) + def infix_+(a: String, b: Rep[Any])(implicit x: Overloaded4): Rep[String] = StrCat(Const(a),b) + def infix_+(a: Rep[Any], b: String)(implicit x: Overloaded5): Rep[String] = StrCat(a,Const(b)) + + case class StrCat(a: Exp[Any],b: Exp[Any]) extends Def[String] + + case class Tup[A,B](a: Exp[A],b: Exp[B]) extends Def[(A,B)] + + case class External[A:Manifest](s: String, fmt_args: List[Exp[Any]] = List()) extends Exp[A] + +} + +trait ScalaGenUtil extends ScalaGenBase { + val IR: UtilExp + import IR._ + + // case External(s: String, args: List[Exp[Any]]) => s.format(args map (quote(_)) : _*) + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case StrCat(a,b) => + emitValDef(sym, quote(a) + ".toString + " + quote(b) + ".toString") + case Tup(a,b) => + emitValDef(sym, "("+ quote(a) + "," + quote(b) + ")") + case _ => super.emitNode(sym, rhs) + } + + override def quote(x: Exp[Any]) = x match { + case External(s: String, args: List[Exp[Any]]) => s.format(args map (quote(_)) : _*) + case _ => super.quote(x) + } + + +} + +trait Vectors extends Utils { + + type Vector + implicit def mV: Manifest[Vector] + + def ZeroVector(n: Rep[Int]): Rep[Vector] + def RandomVector(n: Rep[Int]): Rep[Vector] + def infix_+(a: Rep[Vector], b: Rep[Vector])(implicit x: Overloaded3): Rep[Vector] +} + +trait VectorsExp extends Vectors with BaseExp { this: VectorsImpl => + + // use Apply directly (instead of doApply) to signal that operations are pure + + def ZeroVector(n: Exp[Int]) = Apply(vectorZero, n) + def RandomVector(n: Exp[Int]) = doApply(vectorRandom, n) // random vectors are different... + + def infix_+(a: Exp[Vector], b: Exp[Vector])(implicit x: Overloaded3) = (a,b) match { + case (Def(ZeroVector(_)), b) => b + case (a, Def(ZeroVector(_))) => a + case _ => Apply(vectorPlus, toAtom(Tup(a, b))) + } + + class ApplyExtractor[A:Manifest,B:Manifest](f: Exp[A => B]) { + def apply(x: Exp[A]): Exp[B] = Apply(f,x) + def unapply(e: Def[B]): Option[Exp[A]] = e match { + case Apply(`f`, x: Exp[A]) => Some(x) + case _ => None + } + } + + object ZeroVector extends ApplyExtractor[Int,Vector](vectorZero) + +/* + object ZeroVector { + def unapply(e: Def[Vector]): Option[Exp[Int]] = e match { + case Apply(`vectorZero`, n: Exp[Int]) => Some(n) + case _ => + None + } + } +*/ + +} + + +trait VectorsImpl extends Vectors with FunctionsExp with UtilExp { + + val vectorZero: Exp[Int => Vector] + val vectorRandom: Exp[Int => Vector] + val vectorPlus: Exp[((Vector,Vector)) => Vector] + +} + + +trait VectorsImplExternal extends VectorsImpl { + + type Vector = Array[Double] + def mV = manifest[Array[Double]] + + val base = "scala.lms.epfl.test6.VectorOps.%s" + + // FIXME: using base + "zero" crashes the compiler! + + val vectorZero = External[Int => Vector](base format "zero") + val vectorRandom = External[Int => Vector](base format "random") + val vectorPlus = External[((Vector,Vector)) => Vector](base format "plus") + +} + +object VectorOps { + + def zero(n: Int) = new Array[Double](n) + def random(n: Int) = new Array[Double](n) + def plus(p: (Array[Double], Array[Double])) = p._1 + +} + + + +// possible future alternatives: + +trait VectorsImplConst extends VectorsImpl { + + type Vector = Array[Double] + def mV = manifest[Array[Double]] + + // kernels implementations as function-type constants + + val vectorZero = Const((n:Int) => new Array[Double](n)) + val vectorRandom = Const((n:Int) => new Array[Double](n)) // fill with random data... + val vectorPlus = Const((p:(Vector,Vector)) => p._1) // actually do the addition + +} + + +/* + +trait VectorImplInternal extends VectorImpl { + + trait Vector + + // kernels implemented as staged coded within lambdas + + val vectorZero = doLambda { x:Rep[Int] => ... } + val vectorRandom = doLambda { x:Rep[Int] => ... } + val vectorPlus = doLambda { x:Rep[(Vector,Vector)] => ... } + +} + +*/ + + +trait VectorsProg extends Vectors { + + def test(x: Rep[Unit]): Rep[Vector] = { + RandomVector(7) + (ZeroVector(7) + RandomVector(7)) + } + +} + +trait StringsProg extends Vectors { + + def test(x: Rep[Any]) = { + val s: Rep[Any] = "hi " + "yo " + x + " done" + s + } + +} + + + +class TestVectors extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test6-" + + def testVectors = { + withOutFile(prefix+"vectors") { + + println("-- begin") + + new VectorsProg with VectorsExp with VectorsImplExternal + with CompileScala { self => + val codegen = new ScalaGenFunctions with ScalaGenUtil { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + val g = compile(test) + println(g().mkString(",")) + } + + new StringsProg with VectorsExp with VectorsImplExternal + with CompileScala { self => + val codegen = new ScalaGenFunctions with ScalaGenUtil { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + val g = compile(test) + println(g(0)) + } + /* + new TestConditional with ArithExpOpt with EqualExp with PrintExp + with JSGenIfThenElse + with JSGenArith with JSGenEqual with JSGenPrint + { + val f = (x: Rep[Double]) => test(x) + emitJSSource(f, "main", new PrintWriter(System.out)) + emitHTMLPage(() => f(7), new PrintWriter(new FileOutputStream("test5.html"))) + } + + */ + println("-- end") + } + assertFileEqualsCheck(prefix+"vectors") + + } +} diff --git a/test-src/epfl/test7-analysis/Arrays.scala b/test-src/epfl/test7-analysis/Arrays.scala new file mode 100644 index 00000000..8f680cd8 --- /dev/null +++ b/test-src/epfl/test7-analysis/Arrays.scala @@ -0,0 +1,232 @@ +package scala.lms +package epfl +package test7 + +import common._ +import test1._ + +import internal.AbstractSubstTransformer + + +import util.OverloadHack +import scala.reflect.SourceContext +import java.io.{PrintWriter,StringWriter,FileOutputStream} + + + +trait ArrayLoops extends Loops with OverloadHack { + def array[T:Manifest](shape: Rep[Int])(f: Rep[Int] => Rep[T]): Rep[Array[T]] + def sum(shape: Rep[Int])(f: Rep[Int] => Rep[Double]): Rep[Double] // TODO: make reduce operation configurable! + def arrayIf[T:Manifest](shape: Rep[Int])(f: Rep[Int] => (Rep[Boolean],Rep[T])): Rep[Array[T]] + def sumIf(shape: Rep[Int])(f: Rep[Int] => (Rep[Boolean],Rep[Double])): Rep[Double] // TODO: make reduce operation configurable! + def flatten[T:Manifest](shape: Rep[Int])(f: Rep[Int] => Rep[Array[T]]): Rep[Array[T]] + + def infix_at[T:Manifest](a: Rep[Array[T]], i: Rep[Int]): Rep[T] + def infix_length[T:Manifest](a: Rep[Array[T]]): Rep[Int] +} + + +trait ArrayLoopsExp extends LoopsExp { + + case class ArrayElem[T](y: Block[T]) extends Def[Array[T]] + case class ReduceElem(y: Block[Double]) extends Def[Double] + + case class ArrayIfElem[T](c: Exp[Boolean], y: Block[T]) extends Def[Array[T]] + case class ReduceIfElem(c: Exp[Boolean], y: Block[Double]) extends Def[Double] + + case class FlattenElem[T](y: Block[Array[T]]) extends Def[Array[T]] + + case class ArrayIndex[T](a: Rep[Array[T]], i: Rep[Int]) extends Def[T] + case class ArrayLength[T](a: Rep[Array[T]]) extends Def[Int] + + def array[T:Manifest](shape: Rep[Int])(f: Rep[Int] => Rep[T]): Rep[Array[T]] = { + val x = fresh[Int] + val y = reifyEffects(f(x)) + simpleLoop(shape, x, ArrayElem(y)) + } + + def sum(shape: Rep[Int])(f: Rep[Int] => Rep[Double]): Rep[Double] = { + val x = fresh[Int] + val y = reifyEffects(f(x)) + simpleLoop(shape, x, ReduceElem(y)) + } + + def arrayIf[T:Manifest](shape: Rep[Int])(f: Rep[Int] => (Rep[Boolean],Rep[T])): Rep[Array[T]] = { + val x = fresh[Int] + //val (c,y) = f(x) + var c: Rep[Boolean] = null + val y = reifyEffects { val p = f(x); c = p._1; p._2 } + simpleLoop(shape, x, ArrayIfElem(c,y)) // TODO: simplify for const true/false + } + + def sumIf(shape: Rep[Int])(f: Rep[Int] => (Rep[Boolean],Rep[Double])): Rep[Double] = { + val x = fresh[Int] + //val (c,y) = f(x) + var c: Rep[Boolean] = null + val y = reifyEffects { val p = f(x); c = p._1; p._2 } + simpleLoop(shape, x, ReduceIfElem(c,y)) // TODO: simplify for const true/false + } + + def flatten[T:Manifest](shape: Rep[Int])(f: Rep[Int] => Rep[Array[T]]): Rep[Array[T]] = { + val x = fresh[Int] + val y = reifyEffects(f(x)) + simpleLoop(shape, x, FlattenElem(y)) + } + + + def infix_at[T:Manifest](a: Rep[Array[T]], i: Rep[Int]): Rep[T] = ArrayIndex(a, i) + + def infix_length[T:Manifest](a: Rep[Array[T]]): Rep[Int] = a match { + case Def(SimpleLoop(s, x, ArrayElem(y))) => s + case _ => ArrayLength(a) + } + + + override def boundSyms(e: Any): List[Sym[Any]] = e match { + case ArrayElem(y) => effectSyms(y) + case ReduceElem(y) => effectSyms(y) + case FlattenElem(y) => effectSyms(y) + case _ => super.boundSyms(e) + } + + + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case SimpleLoop(s,i, ArrayElem(y)) if f.hasContext => + array(f(s)) { j => f.asInstanceOf[AbstractSubstTransformer{val IR:ArrayLoopsExp.this.type}].withSubstScope(i -> j) { f.reflectBlock(y) } } + case ArrayIndex(a,i) => infix_at(f(a), f(i))(mtype(manifest[A])) + case ArrayLength(a) => infix_length(f(a))(mtype(manifest[A])) + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] + + override def mirrorFatDef[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Def[A] = (e match { + case ArrayElem(y) => ArrayElem(f(y)) + case ReduceElem(y) => ReduceElem(f(y)) + case ArrayIfElem(c,y) => ArrayIfElem(f(c),f(y)) + case ReduceIfElem(c,y) => ReduceIfElem(f(c),f(y)) + case _ => super.mirrorFatDef(e,f) + }).asInstanceOf[Def[A]] + + +} + +trait ArrayLoopsFatExp extends ArrayLoopsExp with LoopsFatExp + + + + +trait ScalaGenArrayLoops extends ScalaGenLoops { + val IR: ArrayLoopsExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case SimpleLoop(s,x,ArrayElem(y)) => + stream.println("val " + quote(sym) + " = LoopArray("+quote(s)+") { " + quote(x) + " => ") + emitBlock(y) + stream.println(quote(getBlockResult(y))) + stream.println("}") + case SimpleLoop(s,x,ReduceElem(y)) => + stream.println("val " + quote(sym) + " = LoopReduce("+quote(s)+") { " + quote(x) + " => ") + emitBlock(y) + stream.println(quote(getBlockResult(y))) + stream.println("}") + // TODO: conditional variants ... + case SimpleLoop(s,x,FlattenElem(y)) => + stream.println("val " + quote(sym) + " = LoopFlatten("+quote(s)+") { " + quote(x) + " => ") + emitBlock(y) + stream.println(quote(getBlockResult(y))) + stream.println("}") + case ArrayIndex(a,i) => + emitValDef(sym, quote(a) + ".apply(" + quote(i) + ")") + case ArrayLength(a) => + emitValDef(sym, quote(a) + ".length") + case _ => super.emitNode(sym, rhs) + } +} + +trait ScalaGenArrayLoopsFat extends ScalaGenArrayLoops with ScalaGenLoopsFat { + val IR: ArrayLoopsFatExp + import IR._ + + override def emitFatNode(sym: List[Sym[Any]], rhs: FatDef) = rhs match { + case SimpleFatLoop(s,x,rhs) => + for ((l,r) <- sym zip rhs) { + r match { + case ArrayElem(y) => + stream.println("var " + quote(l) + " = new Array[" + remap(getBlockResult(y).tp) + "]("+quote(s)+")") + case ReduceElem(y) => + stream.println("var " + quote(l) + ": " + remap(getBlockResult(y).tp) + " = 0") + case ArrayIfElem(c,y) => + stream.println("var " + quote(l) + " = new ArrayBuilder[" + remap(getBlockResult(y).tp) + "]") + case ReduceIfElem(c,y) => + stream.println("var " + quote(l) + ": " + remap(getBlockResult(y).tp) + " = 0") + case FlattenElem(y) => + stream.println("var " + quote(l) + " = new ArrayBuilder[" + remap(getBlockResult(y).tp) + "]") + } + } + val ii = x // was: x(i) +// stream.println("var " + quote(ii) + " = 0") +// stream.println("while ("+quote(ii)+" < "+quote(s)+") {") + stream.println("for ("+quote(ii)+" <- 0 until "+quote(s)+") {") +// for (jj <- x.drop(1)) { +// stream.println(quote(jj)+" = "+quote(ii)) +// } + emitFatBlock(syms(rhs).map(Block(_))) // TODO: check this + for ((l,r) <- sym zip rhs) { + r match { + case ArrayElem(y) => + stream.println(quote(l) + "("+quote(ii)+") = " + quote(getBlockResult(y))) + case ReduceElem(y) => + stream.println(quote(l) + " += " + quote(getBlockResult(y))) + case ArrayIfElem(c,y) => + stream.println("if ("+quote(/*getBlockResult*/(c))+") " + quote(l) + " += " + quote(getBlockResult(y))) + case ReduceIfElem(c,y) => + stream.println("if ("+quote(/*getBlockResult*/(c))+") " + quote(l) + " += " + quote(getBlockResult(y))) + case FlattenElem(y) => + stream.println(quote(l) + " ++= " + quote(getBlockResult(y))) + } + } +// stream.println(quote(ii)+" += 1") + stream.println("}") + case _ => super.emitFatNode(sym, rhs) + } +} + + + + + + + + +trait Arrays extends Base with OverloadHack { + def zeroes(n: Rep[Int]): Rep[Array[Int]] + def infix_update(a: Rep[Array[Int]], x: Rep[Int], v: Rep[Int]): Rep[Array[Int]] + def infix_+(a: Rep[Array[Int]], b: Rep[Array[Int]])(implicit o: Overloaded1): Rep[Array[Int]] +} + +trait ArraysExp extends Arrays with EffectExp { + case class ArrayZero(n: Rep[Int]) extends Def[Array[Int]] + case class ArrayUpdate(a: Rep[Array[Int]], x: Rep[Int], v: Rep[Int]) extends Def[Array[Int]] + case class ArrayPlus(a: Rep[Array[Int]], b: Rep[Array[Int]]) extends Def[Array[Int]] + def zeroes(n: Rep[Int]) = ArrayZero(n) + def infix_update(a: Rep[Array[Int]], x: Rep[Int], v: Rep[Int]) = ArrayUpdate(a,x,v) + def infix_+(a: Rep[Array[Int]], b: Rep[Array[Int]])(implicit o: Overloaded1) = ArrayPlus(a,b) +} + +trait ScalaGenArrays extends ScalaGenEffect { + val IR: ArraysExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ArrayZero(n) => + emitValDef(sym, "new Array[Int](" + quote(n) + ")") + case ArrayUpdate(a,x,v) => + emitValDef(sym, quote(a) +".clone()") + stream.println(quote(sym) + "(" + quote(x) + ") = " + quote(v)) + case ArrayPlus(a,b) => + emitValDef(sym, "new Array[Int](" + quote(a) + ".length)") + stream.println("arrayPlus("+ quote(sym) + "," + quote(a) + "," + quote(b) + ")") + case _ => super.emitNode(sym, rhs) + } +} + diff --git a/test-src/epfl/test7-analysis/TestAnalysis.scala b/test-src/epfl/test7-analysis/TestAnalysis.scala new file mode 100644 index 00000000..229fa653 --- /dev/null +++ b/test-src/epfl/test7-analysis/TestAnalysis.scala @@ -0,0 +1,228 @@ +package scala.lms +package epfl +package test7 + +import common._ +import test1._ + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} +import scala.reflect.SourceContext + +trait Print extends Base { + implicit def unit(s: String): Rep[String] + def print(s: Rep[Any]): Rep[Unit] +} + +trait PrintExp extends Print with EffectExp { + implicit def unit(s: String): Rep[String] = Const(s) + case class Print(s: Rep[Any]) extends Def[Unit] + def print(s: Rep[Any]) = reflectEffect(Print(s)) + override def mirrorDef[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Def[A] = (e match { + case Print(s) => Print(f(s)) + case _ => super.mirrorDef(e,f) + }).asInstanceOf[Def[A]] // why?? + override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { + case Reflect(Print(s), u, es) => reflectMirrored(Reflect(Print(f(s)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos) + case _ => super.mirror(e,f) + }).asInstanceOf[Exp[A]] // why?? +} + +trait ScalaGenPrint extends ScalaGenEffect { + val IR: PrintExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case Print(s) => emitValDef(sym, "println(" + quote(s) + ")") + case _ => super.emitNode(sym, rhs) + } +} + + + +/* + + TODO interesting cases: + + val y = if (c) { + val x = read() + write() + x + } else { + 0 + } + + ------ + + val a = Array.make(100) { i => + i * i + } + + val b = Array.make(100) { j => + val y = j * j + y * j + } + + val c = Array.reduce(100)(+) { k => + val z = a(k) + z * 3 + } + + translate to: (caveat: alpha convert j and k <- howto generalize?) + + step 0) flat schedule (strip dead code) + step 1) find things worthwhile to fuse (CAREFUL ABOUT NESTING!!) + step 2) alpha-convert (does algebraic opts + cse) + step 3) actual codegen + + val i = Reflect(InRange(100)) + val x1 = i * i + val a = Reify(Array.makeElem(x1), i) + val y1 = j * j + val y2 = y1 * j + val b = Array.make(100)(j,y2) + val z1 = a(k) // or: k*k + val z2 = z1 * 3 + val c = Array.reduce(100)(+)(k,z2) + + + + LoopFused(100) { i => + val x1 = i * i + val x2 = x1 * i + val x3 = x1 * 3 + export val a = Array.makeElem(x1) + export val b = Array.makeElem(x2) + export val c = Array.reduceElem(+,x3) + } + + val a,b,c = Array.fused { i => + val x1 = i * i + val x2 = x1 * i + val x3 = x1 * 3 + yieldMake(x1) + yieldMake(x2) + yieldReduce(+)(x1*3) + } + + var a = new Array(100) // might stack alloc, or reuse mem + var b = new Array(100) + var c = 0 + for (i <- 0 until 100) { + val x1 = i * i + val x2 = x1 * i + val x3 = x1 * 3 + a(i) = x1 + b(i) = x2 + c = c + x3 + } + + ------ + + Folding vs. Fusion: + + val a = Array(100) { ia => ia * 3 } + + val b = Array(100) { ib => a(ib) + 3 } // can fold or fuse + + val c = Array(100) { ic => a(ic + 3) } // can fold but not fuse! a(i+3) not available to c(i) + + val ac = Array(100) { iac => iac*3, (iac+3)*3 } // can fold but not fuse! a(i+3) not available to c(i) + val ac = Array(100) { iac => t = iac*3; t,t+9 } // will not be done!!! + + + + ------ + + Folding decisions are similar to inlining decisions. Might duplicate computations + (instead of reusing stored results). If the computations are small this is worthwile (see above), + otherwise not. + + We should be specific about inlining -> should we be specific about folding as well? + + After all, arrays are just cached function results (of partial functions, that is). + More exactly: partitioning of the domain into multiple function results (<- concat). + + -- + + idea: not everything should be hoisted out of loops. an array construction L1 might be + better folded into the loop L2 (removing the need for the intermediate array). however, + if L1 is very costly, it might be better to construct it explicitly. it might even + be worth to extract scalar subexpressions into arrays! + + val a = Array(100) { ia => val xa = gold(ia+1); xa * 4 } + val b = Array(100) { ib => val xb = gold(ib+2); xb * 3 } + + gold(ia) cannot be moved out. assume gold is expensive, so it might be worth doing + + val g = Array(100) { ig => gold(ig) } // g = Array(100)(gold) + val a = Array(100) { ia => val xa = g(ia+1); xa * 4 } // a = g.rotate(-1) *. scatter(100)(4) + val b = Array(100) { ib => val xb = g(ib+2); xb * 3 } // b = g.rotate(-2) *. scatter(100)(3) <- DEFINITELY inline scatter! + + (although we'd really want to fuse all three into one, the +1 and +2 don't allow parallel loop) + + currently we can do CSE only for scalar values. + + -- + + another option is to always array-ify things that depend on i: eta-expand, basically. + need to think some more about this. + + -- + + SAC: + folding: forward subsitute L1 into L2 if that is the only use of L1 + fusion: if data dependency hinders fusion of L1 and L2, forward substitute anyways. + other uses of L1 will be redirected to fused L1', so L1 goes away. + + Question: does that enable fusion of ALL loops with same generators? + "sets of generators .. sufficiently simple or similar to make fusion feasible" + + what about a(i+2) dependency? --> will cause duplicate work, no?? gold(i), gold(i+1) + what about fold(a) dep? not elem-wise access! would duplicate whole loop? + + --> assume for now only a(i) deps trigger forward subst! --> make sure not to pessimize + --> regular folding can also handle other indices, like a(i+j) + + + "fusion of two with-loops may prevent further fusion with a third with-loop" + + -- + + what about: traverse nodes from root (result) breadth first wise, with no interdep + at each level. then do maximal munch. + + not sure. + + -- + + SAC-style fusion: + + 1. try to bring loops closer together (by removing interdependent stuff) + 2. can fuse adjacent loops if L1 not in freevars(L2) + + -- + + Kennedy's line of work: it's probably not worth (much) fusing loops that do not share anything + + -- + + to find which loops can be fused: + - simple interdependencies are ok (i.e. A(i) where A is an Array and i is a loop var, or affine in the future) + - complex ones prevent fusion + need to distinguish the two! temporarily remove the simple ones --> only the others are left! + - if loops are unrelated (no interdeps) in the modified graph they can be fused! + - strongly connected components cannot be fused internally (they are sequential), only externally + - +*/ + + + +class TestAnalysis extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test7-" + + + +} diff --git a/test-src/epfl/test7-analysis/TestCodeMotion.scala b/test-src/epfl/test7-analysis/TestCodeMotion.scala new file mode 100644 index 00000000..1f6c3716 --- /dev/null +++ b/test-src/epfl/test7-analysis/TestCodeMotion.scala @@ -0,0 +1,252 @@ +package scala.lms +package epfl +package test7 + +import common._ +import test1._ + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} + + + +trait NestLambdaProg1 extends Arith with Functions with Print { // also used by TestLambdaLift + + def test(x: Rep[Unit]) = { + val f = doLambda { x: Rep[Double] => + val g = doLambda { y: Rep[Double] => + print("yo") + y + (unit(4.0) * unit(3.0)) + } + g + } + f + } + +} + +trait NestCondProg2 extends Arith with Functions with IfThenElse with Print { + + /* Previously this program exhibited behavior that is likely undesired in many + cases. The definition of f was moved *into* g and into the conditional. + The doLambda in the else branch would not be hoisted out of g either. + + Although there are situations where this particular kind of code motion + is an improvement (namely, if the probability of y == true is very low + and the else branch would be cheap). + */ + + + def test(x: Rep[Unit]) = { + val f = doLambda { x: Rep[Double] => 2 * x } + + val g = doLambda { y: Rep[Boolean] => + print("yo") + if (y) + f + else + doLambda { x: Rep[Double] => x + 1 } + } + g + } + +} + + +trait NestCondProg3 extends Arith with Functions with IfThenElse with Print { + + def test(x: Rep[Unit]) = { + val f = if (unit(true)) doLambda { x: Rep[Double] => 2 * x } else doLambda { x: Rep[Double] => 4 * x } + + val g = doLambda { y: Rep[Boolean] => + print("yo") + if (y) { + print("then") + f + } else { + print("else") + if (unit(false)) doLambda { x: Rep[Double] => x + 1 } else doLambda { x: Rep[Double] => x + 2 } + } + } + g + } + +} + +trait NestCondProg4 extends Arith with Functions with IfThenElse with Print { + + def test(x: Rep[Unit]) = { + val g = doLambda { y: Rep[Double] => + if (unit(true)) { + val x = y + 1.0 + print(x) + () + } else { + } + } + g + } + +} + + +trait NestCondProg5 extends Arith with Functions with IfThenElse with Print { + + def test(x: Rep[Unit]) = { + if (unit(true)) { + // should place 7 + 9 here + doLambda { y: Rep[Double] => + print(unit(7.0) + unit(9.0)) + } + } else { + } + } + +} + + +trait NestCondProg6 extends Arith with Functions with IfThenElse with Print { + + // FIXME: this one doesn't work yet!!! + + def test(x: Rep[Unit]) = { + val z = unit(7.0) + unit(9.0) // should move into the conditional (but isn't currently) + val x = if (unit(true)) { + print(z) + } else { + } + doLambda { y: Rep[Boolean] => + print(x) + } + } + +} + + +trait NestCondProg7 extends Arith with OrderingOps with Functions with IfThenElse with Print { + + def test(x: Rep[Unit]) = { + doLambda { y: Rep[Double] => + if (y < 100) { + val z = y + unit(9.0) // should stay inside conditional: + // apparently z was moved up because it is also used in the lambda (z+u) + doLambda { u: Rep[Double] => + z + u + } + } else { + } + } + } + +} + +/* +seems to be another incarnation of test6 + +trait NestCondProg8 extends Arith with OrderingOps with Functions with IfThenElse with Print { + + // FIXME + + def test(x: Rep[Unit]) = { + doLambda { y: Rep[Double] => + if (y < 100) { + val z = y + unit(9.0) // should stay inside conditional + z + unit(1.0) + } else { + val z = y + unit(9.0) // should stay inside conditional, although used again + z + unit(2.0) + } + } + } + +} +*/ + + +class TestCodemotion extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test7-" + + def testCodemotion1 = { + // test loop hoisting (should use loops but lambdas will do for now) + withOutFile(prefix+"codemotion1") { + new NestLambdaProg1 with ArithExp with FunctionsExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"codemotion1") + } + + def testCodemotion2 = { + // test loop hoisting (should use loops but lambdas will do for now) + withOutFile(prefix+"codemotion2") { + new NestCondProg2 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"codemotion2") + } + + def testCodemotion3 = { + // test loop hoisting (should use loops but lambdas will do for now) + withOutFile(prefix+"codemotion3") { + new NestCondProg3 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"codemotion3") + } + + def testCodemotion4 = { + // test loop hoisting (should use loops but lambdas will do for now) + withOutFile(prefix+"codemotion4") { + new NestCondProg4 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"codemotion4") + } + + def testCodemotion5 = { + // test loop hoisting (should use loops but lambdas will do for now) + withOutFile(prefix+"codemotion5") { + new NestCondProg5 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"codemotion5") + } + + def testCodemotion6 = { + // test loop hoisting (should use loops but lambdas will do for now) + withOutFile(prefix+"codemotion6") { + new NestCondProg6 with ArithExp with FunctionsExp with IfThenElseExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + println("// NOTE: generated code is not ideal yet (x1=7+9 should be moved inside conditional). see source for discussion.") + } + } + // PENDING TEST + // assertFileEqualsCheck(prefix+"codemotion6") + } + + def testCodemotion7 = { + // test loop hoisting (should use loops but lambdas will do for now) + withOutFile(prefix+"codemotion7") { + new NestCondProg7 with ArithExp with OrderingOpsExp with FunctionsExp with IfThenElseExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenOrderingOps with ScalaGenFunctions with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + println("// was a Delite issue (Scratchpad in optiml-beta).") + } + } + assertFileEqualsCheck(prefix+"codemotion7") + } + + +} diff --git a/test-src/epfl/test7-analysis/TestDB.scalax b/test-src/epfl/test7-analysis/TestDB.scalax new file mode 100644 index 00000000..ddac7830 --- /dev/null +++ b/test-src/epfl/test7-analysis/TestDB.scalax @@ -0,0 +1,114 @@ +package scala.lms +package epfl +package test7 + +import common._ +import test1._ + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} + + + +// trait NestLambdaProg extends Arith with Functions with Print +// --> from TestCodeMotion.scala + +trait DB extends Base { + + def field[A](a: Rep[Any], table: String, name: String): Rep[A] + +} + +trait DBExp extends DB with BaseExp { + + def field[A](a: Rep[Any], table: String, name: String): Rep[A] = error("arg") + +} + + + +trait DBProg extends Arith with Loops with Print with DB with OverloadHack { + + trait Facilities0 + trait Features0 + trait Meanings0 + + + type Facilities = Rep[Facilities0] + type Features = Rep[Features0] + type Meanings = Rep[Meanings0] + + case class Table[T](name: String) + + val Facilities: Rep[Table[Facilities0]] = Table[Facilities0]("Facilities") + val Features: Rep[Table[Features0]] = Table[Features0]("Facilities") + val Meanings: Rep[Table[Meanings0]] = Table[Meanings0]("Facilities") + + + implicit def table2ops[T](t: Rep[Table[T]]) = new { + def map[A](f: Rep[T] => Rep[A]): Rep[Table[A]] = error("boom!") + def filter(f: Rep[T] => Rep[Boolean]): Rep[Table[T]] = error("boom!") + def distinct(): Rep[Table[T]] = error("boom!") + def nonEmpty: Rep[Boolean] = error("boom!") + } + + def infix_fac(a: Facilities)(implicit z: Overloaded1): Rep[String] = field[String](a, "Facilities", "fac") + def infix_cat(a: Facilities): Rep[String] = field[String](a, "Facilities", "cat") + + def infix_fac(a: Features)(implicit z: Overloaded2): Rep[String] = field[String](a, "Features", "fac") + def infix_feature(a: Features)(implicit z: Overloaded1): Rep[String] = field[String](a, "Features", "feature") + + def infix_feature(a: Meanings)(implicit z: Overloaded2): Rep[String] = field[String](a, "Meanings", "meaning") + def infix_meaning(a: Meanings): Rep[String] = field[String](a, "Meanings", "feature") + + def infix_===(a: Rep[Any], b: Rep[Any]): Rep[Boolean] = error("boom!") + + + def test() = { + + def hasFeatures(fac: Facilities) = Features.filter(b => b.fac === fac).map(b => ()) + + def cats = Facilities.map (b => b.cat).distinct() + + for (a <- cats) yield { + + val facilities = Facilities.filter(d => d.cat === a) + + val features = Features.filter (b => facilities.filter(d => b.fac === d.fac).nonEmpty) + + val meanings = features.map (b => Meanings.filter (c => c.feature === b.feature)) + + (a, meanings) + } + + } + +} + + +class TestDB extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test7-" + + def testDB1 = { + withOutFile(prefix+"db1") { + new DBProg with DBExp with ArithExp with LoopsExp with PrintExp { self => + //val codegen = new ScalaGenArith with ScalaGenPrint { val IR: self.type = self } + //codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"db1") + } + + def testDB2 = { + withOutFile(prefix+"db2") { + new DBProg with DBExp with ArithExp with LoopsExp with PrintExp { self => + //val codegen = new ScalaGenArith with ScalaGenPrint { val IR: self.type = self } + //codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"db2") + } + +} diff --git a/test-src/epfl/test7-analysis/TestFusion.scala b/test-src/epfl/test7-analysis/TestFusion.scala new file mode 100644 index 00000000..e49120ff --- /dev/null +++ b/test-src/epfl/test7-analysis/TestFusion.scala @@ -0,0 +1,191 @@ +package scala.lms +package epfl +package test7 + +import common._ +import test1._ + +import util.OverloadHack +import scala.reflect.SourceContext + +import java.io.{PrintWriter,StringWriter,FileOutputStream} +import scala.reflect.SourceContext + + +trait ScalaGenFatArrayLoopsFusionOpt extends ScalaGenArrayLoopsFat with ScalaGenIfThenElseFat with LoopFusionOpt { + val IR: ArrayLoopsFatExp with IfThenElseFatExp + import IR._ + + override def unapplySimpleIndex(e: Def[Any]) = e match { + case ArrayIndex(a, i) => Some((a,i)) + case _ => super.unapplySimpleIndex(e) + } + override def unapplySimpleDomain(e: Def[Int]): Option[Exp[Any]] = e match { + case ArrayLength(a) => Some(a) + case _ => super.unapplySimpleDomain(e) + } + + override def unapplySimpleCollect(e: Def[Any]) = e match { + case ArrayElem(Block(a)) => Some(a) //TODO: block?? + case _ => super.unapplySimpleCollect(e) + } + + override def unapplySimpleCollectIf(e: Def[Any]) = e match { + case ArrayIfElem(c,Block(a)) => Some((a,List(c))) //TODO: block? + case _ => super.unapplySimpleCollectIf(e) + } + + override def applyAddCondition(e: Def[Any], c: List[Exp[Boolean]]) = e match { //TODO: should c be list or not? + case ArrayElem(a) if c.length == 1 => ArrayIfElem(c(0),a) + case ReduceElem(a) if c.length == 1 => ReduceIfElem(c(0),a) + case _ => super.applyAddCondition(e,c) + } + + + +} + + +// trait NestLambdaProg extends Arith with Functions with Print +// --> from TestCodeMotion.scala + +trait FusionProg extends Arith with ArrayLoops with Print { + + implicit def bla(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] + + def test(x: Rep[Unit]) = { + + val constant = array(100) { i => 1 } + + val linear = array(100) { i => 2*i } + + val affine = array(100) { i => constant.at(i) + linear.at(i) } + + def square(x: Rep[Double]) = x*x + def mean(x: Rep[Array[Double]]) = sum(x.length) { i => x.at(i) } / x.length + def variance(x: Rep[Array[Double]]) = sum(x.length) { i => square(x.at(i)) } / x.length - square(mean(x)) + + val data = affine + + val m = mean(data) + val v = variance(data) + + print(m) + print(v) + } + +} + +trait FusionProg2 extends Arith with ArrayLoops with Print with OrderingOps { + + implicit def bla(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] + + def test(x: Rep[Unit]) = { + + def filter[T:Manifest](x: Rep[Array[T]])(p: Rep[T] => Rep[Boolean]) = + arrayIf(x.length) { i => (p(x.at(i)), x.at(i)) } + + val range = array(100) { i => i } + + val odds = filter(range) { z => z > 50 } + + val res = sum(odds.length) { i => odds.at(i) } + + print(res) + } + +} + + + +/* + some thoughts on cse/gvn : + + - currently cse works fine for first-order, point-free things: + val x = a + b + val y = a + b + will always be represented internally as + val x = a + b + val y = x + + - if bound variables are involved, cse no longer works: + val a = array { i => 0 } + val b = array { i => 0 } + will create two separate objects: + val a = array { i0 => 0 } + val b = array { i1 => 0 } + the same holds for lambdas. + + - this is due to the choice of representing bound vars using fresh symbols. + alternatively we could use DeBruijn indices. + + however, some care would have to be taken in managing the indices: + val a = array { i => + val b = array { j => f(j) } + sum(b) + } + code motion will move b out of a ... but we know that only after looking at b's body + + - for now this is not really a problem because loop fusion will take + care of duplicate loops (effectively lifting scalar cse to array cse) + + - another solution (as done by delite) is to wrap array { i => 0 } + as ArrayZero(len) extends DeliteOP(array(len) { i => 0}). + here, cse will be done on the case class representation +*/ + + + +class TestFusion extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test7-" + + def testFusion1 = { + withOutFile(prefix+"fusion1") { + new FusionProg with ArithExp with ArrayLoopsExp with PrintExp { self => + val codegen = new ScalaGenArrayLoops with ScalaGenArith with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"fusion1") + } + + def testFusion2 = { + withOutFile(prefix+"fusion2") { + // LoopsExp2 with ArithExp with PrintExp with BaseFatExp + new FusionProg with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp { self => + override val verbosity = 1 + val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"fusion2") + } + + def testFusion3 = { + withOutFile(prefix+"fusion3") { + new FusionProg2 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => + override val verbosity = 1 + val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint + with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; + override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = false } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"fusion3") + } + + def testFusion4 = { + withOutFile(prefix+"fusion4") { + new FusionProg2 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => + override val verbosity = 1 + val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint + with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; + override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"fusion4") + } + +} diff --git a/test-src/epfl/test7-analysis/TestFusion2.scala b/test-src/epfl/test7-analysis/TestFusion2.scala new file mode 100644 index 00000000..e6d9e8ed --- /dev/null +++ b/test-src/epfl/test7-analysis/TestFusion2.scala @@ -0,0 +1,228 @@ +package scala.lms +package epfl +package test7 + +import common._ +import test1._ + +import util.OverloadHack +import scala.reflect.SourceContext + +import java.io.{PrintWriter,StringWriter,FileOutputStream} + + + + +trait FusionProg21 extends Arith with ArrayLoops with Print with OrderingOps { + + def infix_foo(x: Rep[Array[Double]]): Rep[Double] = x.at(0) + + def test(x: Rep[Unit]) = { + + // there was a bug were this would lead to a recursive schedule: + // as,bs are fused (no dependencies) + // cs,ds are fused (no dependencies) + // but there are cross deps ds->as, bs->cs ... + + val cs = array(100) { i => 9.0 } + + val as = array(50) { i => 3.0 } + val bs = array(50) { i => cs.foo } + + val ds = array(100) { i => as.foo } + + print(as) + print(bs) + print(cs) + print(ds) + } + +} + + +trait FusionProg22 extends Arith with ArrayLoops with Print with OrderingOps { + + def infix_foo(x: Rep[Array[Double]]): Rep[Double] = x.at(0) + + def test(x: Rep[Unit]) = { + + // test some nested loops - the inner ones should be moved to the top level and be fused there + + // previously this did not work completely: + // if an inner loop can be hoisted as a result of fusing two outer loops + // it would not be considered for outer-level fusion (Wloops is not recalculated) + // between iterations. + + // the question is how far this can be taken: fusion at the innermost level could + // cause a loop to be moved to the top level, in which case the top level would + // need to apply fusion all over again. + + + val as = array(100) { i => + array(50) { j => 1.0 } + } + + val bs = array(100) { i => + array(50) { j => 2.0 } + } + + val cs = array(100) { i => + sum(50) { j => 4.0 } + } + + val ds = array(100) { i => + val x = sum(50) { j => as.at(i).at(j) + bs.at(i).at(j) } // this one depends on i, cannot move up + val y = cs.at(i) + x + y + } + + print(as) + print(bs) + print(cs) + print(ds) + } + +} + + +trait FusionProg23 extends Arith with ArrayLoops with Print with OrderingOps { + + def infix_foo(x: Rep[Array[Double]]): Rep[Double] = x.at(0) + + def test(x: Rep[Unit]) = { + + // test some nested loops - this times they are tryly nested (inner ones depend on loop var) + + val as = array(100) { i => + array(i) { j => 1.0 } + } + + val bs = array(100) { i => + array(i) { j => 2.0 } + } + + val cs = array(100) { i => + sum(i) { j => 4.0 } + } + + val ds = array(100) { i => + val x = sum(i) { j => as.at(i).at(j) + bs.at(i).at(j) } + val y = cs.at(i) + x + y + } + + + print(as) + print(bs) + print(cs) + print(ds) + } + +} + + +trait FusionProg24 extends Arith with ArrayLoops with Print with OrderingOps { + + def infix_foo(x: Rep[Array[Double]]): Rep[Double] = x.at(0) + + def test(x: Rep[Unit]) = { + + // test some nested loops + + // there is a question related to DCE: we might have fused two loops early, + // and by some later fusion one of them becomes dead. + + // currently this is not handled because fusion goes from outermost inwards + + val as = array(200) { i => + 1.0 + } + + val bs = array(200) { i => + 2.0 + } + + val cs = array(100) { i => + array(i) { j => as.foo } + } + + val ds = array(100) { i => + array(i) { j => cs.at(i).at(j) - as.foo } + // this will become as.foo - as.foo = 0 --> i.e. as becomes dead but is already fused with bs, which is used... + } + + + //print(as) + print(bs) + //print(cs) + print(ds) + } + +} + + + + +class TestFusion2 extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test7-" + + def testFusion21 = { + withOutFile(prefix+"fusion21") { + new FusionProg21 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => + override val verbosity = 1 + val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint + with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; + override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"fusion21") + } + + def testFusion22 = { + withOutFile(prefix+"fusion22") { + new FusionProg22 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => + override val verbosity = 1 + val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint + with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; + override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"fusion22") + } + + def testFusion23 = { + withOutFile(prefix+"fusion23") { + new FusionProg23 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => + override val verbosity = 1 + val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint + with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; + override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"fusion23") + } + + def testFusion24 = { + withOutFile(prefix+"fusion24") { + new FusionProg24 with ArithExp with ArrayLoopsFatExp with IfThenElseFatExp with PrintExp with IfThenElseExp with OrderingOpsExp { self => + + override def infix_-(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = if (x == y) { + println("*** removing self subtraction " + x + " - " + y) + 0 + } else super.infix_-(x,y) // optimizations to trigger test behavior + + override val verbosity = 1 + val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenArith with ScalaGenPrint + with ScalaGenIfThenElse with ScalaGenOrderingOps { val IR: self.type = self; + override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + println("// NOTE: generated code is not ideal yet (x2 is never used). see source for discussion.") + } + } + assertFileEqualsCheck(prefix+"fusion24") + } +} diff --git a/test-src/epfl/test7-analysis/TestLambalift.scala b/test-src/epfl/test7-analysis/TestLambalift.scala new file mode 100644 index 00000000..69dda489 --- /dev/null +++ b/test-src/epfl/test7-analysis/TestLambalift.scala @@ -0,0 +1,134 @@ +package scala.lms +package epfl +package test7 + +import common._ +import test1._ + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} + +/* + TODO outstanding issues: + + - mutable variable need to be heap-allocated if referenced from within a closure + and stack allocated from within a nested function that is not a closure. + this can be done conservatively (always alloc ref cells on the heap). + but a better approach would be to heap- or stack-alloc only the necessary ones. + + - closures should not unnecessarily be heap-allocated as well (currently all + nested functions are closures and heap-allocated). + + this complicates the analysis for variables, as witnessed by scalac: + + def foo = { + var x = 0 + val f = (y:Int) => x = y + f(7) + } + + compiled with -optimize results in + + // methods + def foo(): Unit { + locals: variable x$1 + startBlock: 1 + blocks: [1] + + 1: + 1 NEW REF(class IntRef) + 1 DUP(REF(class IntRef)) + 1 CONSTANT(Constant(0)) + 1 CALL_METHOD scala.runtime.IntRef. (static-instance) + 1 STORE_LOCAL(variable x$1) + 1 SCOPE_ENTER variable x$1 + 1 SCOPE_ENTER value f + undef LOAD_LOCAL(variable x$1) + 1 CONSTANT(Constant(7)) + 1 STORE_FIELD variable elem (dynamic) + 1 SCOPE_EXIT variable x$1 + 1 SCOPE_EXIT value f + 1 RETURN(UNIT) + + } + + which still allocates the IntRef although the closure record is eliminated + and the code inlined. + + Phase ordering bites again! + +*/ + + + +class TestLambdalift extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test7-" + + def testLambdalift1 = { + // test lambda lifting + withOutFile(prefix+"lambdalift1") { + var classes: List[String] = Nil + + trait ScalaGenBla extends ScalaGenBase { + import IR._ + def emitFocused[A,B](name: String, params: List[Exp[Any]], x: Exp[A], y: Block[B], out: PrintWriter): Unit + } + + new NestLambdaProg1 with ArithExp with FunctionsExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenFunctions with ScalaGenPrint { + val IR: self.type = self + + /*def boundAndUsedInScope(x: Exp[Any], y: Exp[Any]): (List[Sym[Any]], List[Sym[Any]]) = { + val used = (syms(y):::innerScope.flatMap(t => syms(t.rhs))).distinct + val bound = (syms(x):::innerScope.flatMap(t => t.sym::boundSyms(t.rhs))).distinct + (bound, used) + } + def freeInScope(x: Exp[Any], y: Exp[Any]): List[Sym[Any]] = { + val (bound, used) = boundAndUsedInScope(x,y) + used diff bound + }*/ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case e@Lambda(fun, x, y) => + + focusBlock(y) { + var free = freeInScope(List(x),List(getBlockResultFull(y))) + + val sw = new StringWriter + codegenInner.emitFocused("Anonfun_"+quote(sym), free, x, y, new PrintWriter(sw)) + classes = sw.toString :: classes + + stream.println("val " + quote(sym) + " = new Anonfun_" + quote(sym) + "("+free.map(quote).mkString(",")+")") + } + + case _ => super.emitNode(sym, rhs) + } + } + val codegen2 = new ScalaGenBla with ScalaGenArith with ScalaGenFunctions with ScalaGenPrint { + val IR: self.type = self + + override def initialDefs = codegen.availableDefs + + def emitFocused[A,B](name: String, params: List[Exp[Any]], x: Exp[A], y: Block[B], out: PrintWriter) = { + // TODO: this is not valid Scala code. the types are missing. + withStream(out) { + stream.println("class "+name+"("+params.map(quote).mkString(",")+") {") + stream.println("def apply("+quote(x)+") = {") + traverseBlockFocused(y) + stream.println(quote(getBlockResult(y))) + stream.println("}") + stream.println("}") + } + } + } + val codegenInner: ScalaGenBla { val IR: self.type; type Block[+T] = self.Block[T] } = codegen2 + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + classes.foreach(println) + } + } + assertFileEqualsCheck(prefix+"lambdalift1") + } + +} diff --git a/test-src/epfl/test7-analysis/TestLiveness.scala b/test-src/epfl/test7-analysis/TestLiveness.scala new file mode 100644 index 00000000..3d2759a0 --- /dev/null +++ b/test-src/epfl/test7-analysis/TestLiveness.scala @@ -0,0 +1,150 @@ +package scala.lms +package epfl +package test7 + +import common._ +import test1._ + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} + +// very preliminary! + +trait Liveness extends internal.GenericNestedCodegen { + import IR._ + + var defuse: List[(Sym[Any],Sym[Any])] = Nil + + override def traverseBlockFocused[A](result: Block[A]): Unit = { + focusExactScope(result) { levelScope => + + // TODO: what is the intended behavior for uses in innerScope? + // this will likely depend on the node, i.e. ifThenElse vs. loop + + // a possible first step: handle only straightline code and mark + // everything used by innerScope as escaping (plus the result) + + def usesOf(s: Sym[Any]): List[TP[Any]] = levelScope.flatMap { + case TP(s1, Reify(rhs1,_,_)) => // reify nodes are eliminated, so we need to find all uses of the reified thing + if (syms(rhs1).contains(s)) usesOf(s1) else Nil + case d@TP(_, rhs1) => + if (syms(rhs1).contains(s)) List(d) else Nil + } + defuse = levelScope.flatMap { + case TP(sym, Reify(_,_,_)) => Nil + case TP(sym, rhs) => + usesOf(sym).map(d => (sym,d.sym):(Sym[Any],Sym[Any])) + } + + for (TP(sym, rhs) <- levelScope) { + emitNode(sym, rhs) + + rhs match { + case Reify(s, u, effects) => + case _ => + // remove everything only used here from defuse + // output dealloc for stuff that goes away + + val livebefore = defuse.map(_._1).distinct + defuse = defuse.filterNot(_._2 == sym) + val liveafter = defuse.map(_._1).distinct + val killed = livebefore diff liveafter + if (killed.nonEmpty) stream.println("// kill: " + killed.map(quote).mkString(", ")) + //stream.println("// def->use: " + defuse.map(p=>quote(p._1)+"->"+quote(p._2)).mkString(", ")) + } + + } + } + } + + +} + + +trait ScalaGenArraysLiveOpt extends ScalaGenArrays with Liveness { + val IR: ArraysExp + import IR._ + + def canKill(e: Exp[Any], u: Sym[Any]) = { + !defuse.exists(p => p._1 == e && p._2 != u) + } + + def tryKill(e: Exp[Any], u: Sym[Any]) = { + if (!defuse.exists(p => p._1 == e && p._2 != u)) { + defuse = defuse.filterNot(p => p._1 == e) + true + } else false + } + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ArrayZero(n) => + emitValDef(sym, "new Array[Int](" + quote(n) + ")") + case ArrayUpdate(a,x,v) => + if (tryKill(a, sym)) + emitValDef(sym, quote(a)) + else + emitValDef(sym, quote(a) +".clone()") + stream.println(quote(sym) + "(" + quote(x) + ") = " + quote(v)) + case ArrayPlus(a,b) => + if (tryKill(a, sym)) + emitValDef(sym, quote(a)) + else if (canKill(b, sym)) + emitValDef(sym, quote(b)) + else + emitValDef(sym, "new Array[Int](" + quote(a) + ".length)") + stream.println("arrayPlus("+ quote(sym) + "," + quote(a) + "," + quote(b) + ")") + case _ => super.emitNode(sym, rhs) + } +} + + + + +// trait NestLambdaProg extends Arith with Functions with Print +// --> from TestCodeMotion.scala + +trait LiveProg extends Arith with Arrays with Print { + + def test(x: Rep[Unit]) = { + val a = zeroes(100) // allocation + + val ab = a.update(7, 42) // in place, a not used below + + val abc = ab.update(2, 42) // not in place (will copy), b is used again + + val abd = ab.update(4, 42) // in place again + + val e = abc + abd // in place addition, dealloc one + + print(e) // dealloc the other one + } + +} + + +class TestLiveness extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test7-" + + def testLiveness1 = { + withOutFile(prefix+"liveness1") { + new LiveProg with ArithExp with ArraysExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenArrays with ScalaGenPrint with Liveness { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"liveness1") + } + + def testLiveness2 = { + withOutFile(prefix+"liveness2") { + new LiveProg with ArithExp with ArraysExp with PrintExp { self => + val codegen = new ScalaGenArith with ScalaGenArraysLiveOpt with ScalaGenPrint with Liveness { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"liveness2") + } + +} diff --git a/test-src/epfl/test8-effects/TestMutation.scala b/test-src/epfl/test8-effects/TestMutation.scala new file mode 100644 index 00000000..3909a5e8 --- /dev/null +++ b/test-src/epfl/test8-effects/TestMutation.scala @@ -0,0 +1,361 @@ +package scala.lms +package epfl +package test8 + +import common._ +import test1._ +import test7.{Print,PrintExp,ScalaGenPrint} +import test7.{ArrayLoops,ArrayLoopsExp,ScalaGenArrayLoops} + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} + + +/* + if there's a crash here during compilation, it's likely due to #4363 (need latest scala-virtualized for fix) +*/ + +trait ArrayMutation extends ArrayLoops { + + def infix_update[T:Manifest](a: Rep[Array[T]], i: Rep[Int], x: Rep[T]): Rep[Unit] + + def infix_mutable[T:Manifest](a: Rep[Array[T]]): Rep[Array[T]] + def infix_clone[T:Manifest](a: Rep[Array[T]]): Rep[Array[T]] + +} + + +trait ArrayMutationExp extends ArrayMutation with ArrayLoopsExp { + + case class ArrayUpdate[T](a: Rep[Array[T]], i: Rep[Int], x: Rep[T]) extends Def[Unit] + case class ArrayMutable[T](a: Rep[Array[T]]) extends Def[Array[T]] + case class ArrayClone[T](a: Rep[Array[T]]) extends Def[Array[T]] + + def infix_update[T:Manifest](a: Rep[Array[T]], i: Rep[Int], x: Rep[T]) = reflectWrite(a)(ArrayUpdate(a,i,x)) + + def infix_mutable[T:Manifest](a: Rep[Array[T]]) = reflectMutable(ArrayMutable(a)) + def infix_clone[T:Manifest](a: Rep[Array[T]]) = ArrayClone(a) + + override def aliasSyms(e: Any): List[Sym[Any]] = e match { + case SimpleLoop(s,i, ArrayElem(y)) => Nil + case SimpleLoop(s,i, ReduceElem(y)) => syms(y) // could also return zero value + case SimpleLoop(s,i, ArrayIfElem(c,y)) => Nil + case SimpleLoop(s,i, ReduceIfElem(c,y)) => syms(y) // could also return zero value + case ArrayIndex(a,i) => Nil + case ArrayLength(a) => Nil + case ArrayUpdate(a,i,x) => Nil // syms(a) <-- any use to return a? + case ArrayMutable(a) => Nil + case ArrayClone(a) => Nil + case _ => super.aliasSyms(e) + } + + override def containSyms(e: Any): List[Sym[Any]] = e match { + case SimpleLoop(s,i, ArrayElem(y)) => syms(y) + case SimpleLoop(s,i, ReduceElem(y)) => Nil + case SimpleLoop(s,i, ArrayIfElem(c,y)) => syms(y) + case SimpleLoop(s,i, ReduceIfElem(c,y)) => Nil + case ArrayIndex(a,i) => Nil + case ArrayLength(a) => Nil + case ArrayUpdate(a,i,x) => syms(x) + case ArrayMutable(a) => Nil + case ArrayClone(a) => Nil + case _ => super.containSyms(e) + } + + override def extractSyms(e: Any): List[Sym[Any]] = e match { + case SimpleLoop(s,i, ArrayElem(y)) => Nil + case SimpleLoop(s,i, ReduceElem(y)) => Nil + case SimpleLoop(s,i, ArrayIfElem(c,y)) => Nil + case SimpleLoop(s,i, ReduceIfElem(c,y)) => Nil + case ArrayIndex(a,i) => syms(a) + case ArrayLength(a) => Nil + case ArrayUpdate(a,i,x) => Nil + case ArrayMutable(a) => Nil + case ArrayClone(a) => Nil + case _ => super.extractSyms(e) + } + + override def copySyms(e: Any): List[Sym[Any]] = e match { + case SimpleLoop(s,i, ArrayElem(y)) => Nil + case SimpleLoop(s,i, ReduceElem(y)) => Nil + case SimpleLoop(s,i, ArrayIfElem(c,y)) => Nil + case SimpleLoop(s,i, ReduceIfElem(c,y)) => Nil + case ArrayIndex(a,i) => Nil + case ArrayLength(a) => Nil + case ArrayUpdate(a,i,x) => syms(a) + case ArrayMutable(a) => syms(a) + case ArrayClone(a) => syms(a) + case _ => super.copySyms(e) + } + + +} + +trait ScalaGenArrayMutation extends ScalaGenArrayLoops { + val IR: ArrayMutationExp + import IR._ + + override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { + case ArrayUpdate(a,i,x) => + emitValDef(sym, quote(a) + ".update(" + quote(i) + ", " + quote(x) + ")") + case ArrayMutable(a) => + emitValDef(sym, quote(a) + ".clone // mutable") + case ArrayClone(a) => + emitValDef(sym, quote(a) + ".clone") + case _ => super.emitNode(sym, rhs) + } +} + + + + + +class TestMutation extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test8-" + + trait DSL extends ArrayMutation with Arith with OrderingOps with Variables with IfThenElse with While with RangeOps with Print { + def zeros(l: Rep[Int]) = array(l) { i => 0 } + def mzeros(l: Rep[Int]) = zeros(l).mutable + def infix_toDouble(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] + + def test(x: Rep[Int]): Rep[Unit] + } + trait Impl extends DSL with ArrayMutationExp with ArithExp with OrderingOpsExp with VariablesExp + with IfThenElseExp with WhileExp with RangeOpsExp with PrintExp { self => + override val verbosity = 2 + val codegen = new ScalaGenArrayMutation with ScalaGenArith with ScalaGenOrderingOps + with ScalaGenVariables with ScalaGenIfThenElse with ScalaGenWhile with ScalaGenRangeOps + with ScalaGenPrint { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + + def testMutation1 = { + withOutFile(prefix+"mutation1") { + // a write operation must unambigously identify the object being mutated + trait Prog extends DSL { + def test(x: Rep[Int]) = { + val vector1 = mzeros(100) + val vector2 = mzeros(100) + val a = if (x > 7) vector1 else vector2 + + a.update(40,40) // error: not clear which object is mutated (vector1 or vector2) + + print(a.at(50)) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation1") + } + + def testMutation1b = { + withOutFile(prefix+"mutation1b") { + // a write operation must unambigously identify the object being mutated + trait Prog extends DSL { + def test(x: Rep[Int]) = { + val vector1 = mzeros(100) + val vector2 = mzeros(100) + val a = if (x > 7) vector1 else vector2 + + val a2 = a.mutable + a2.update(40,40) // ok: we have made a copy + + print(a2.at(50)) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation1b") + } + + def testMutation2 = { + withOutFile(prefix+"mutation2") { + // an operation that might read from mutable data v will be serialized with all writes to v + trait Prog extends DSL { + def test(x: Rep[Int]) = { + val vector1 = mzeros(100) + val vector2 = mzeros(100) + val a = if (x > 7) vector1 else vector2 + + val x0 = a.at(10) + + vector1.update(10,10) // must come after x0 + vector2.update(10,20) // must come after x0 + + val x1 = a.at(10) // must come after both writes, no cse with x0 + + print(x1-x0) // minus should not have effect dep + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation2") + } + + + def testMutation3 = { + withOutFile(prefix+"mutation3") { + // vars may not reference mutable objects + trait Prog extends DSL with LiftVariables { + def test(x: Rep[Int]) = { + var a = zeros(100) + val b = mzeros(100) + for (i <- 0 until b.length) { // this is also a curious case: range creation must not be reflected + val x1 = a.at(i) + b.update(i,8) + val x2 = a.at(i) // must be cse'd + a = b // error: here we learn that reads on a would need to be serialized with b but it's too late... + } + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation3") + } + + def testMutation3b = { + withOutFile(prefix+"mutation3b") { + // vars may not reference mutable objects + trait Prog extends DSL with LiftVariables { + def test(x: Rep[Int]) = { + var a = zeros(100) + val b = mzeros(100) + for (i <- 0 until b.length) { + val x1 = a.at(i) + b.update(i,8) + val x2 = a.at(i) // must be cse'd + a = b.clone // ok: making a copy + } + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation3b") + } + + def testMutation4 = { + withOutFile(prefix+"mutation4") { + // mutable objects cannot be nested + trait Prog extends DSL { + def test(x: Rep[Int]) = { + val a = mzeros(100) + val b = array(10) { i => a } // nested array + val b1 = b.mutable // error: internal arrays are mutable on their own + val x1 = b1.at(5).at(50) + print(x1) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation4") + } + + def testMutation4b = { + withOutFile(prefix+"mutation4b") { + // mutable objects cannot be nested + trait Prog extends DSL { + def test(x: Rep[Int]) = { + val a = mzeros(100) + val b = array(10) { i => a } // nested array + val b1 = b.clone + val b2 = b1.mutable // error: internal arrays are *still* mutable, despite shallow clone + val x1 = b2.at(5).at(50) + print(x1) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation4b") + } + + def testMutation4c = { + withOutFile(prefix+"mutation4c") { + // mutable objects cannot be nested + trait Prog extends DSL { + def test(x: Rep[Int]) = { + val a = mzeros(100) + val b = array(10) { i => a.clone } // nested array + val b1 = b.mutable // ok: internal arrays are immutable + val x1 = b1.at(5).at(50) + print(x1) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation4c") + } + + + def testMutation5 = { + withOutFile(prefix+"mutation5") { + // mutable objects cannot be nested + trait Prog extends DSL { + def test(x: Rep[Int]) = { + val a = zeros(100) + val b = array(10) { i => a } // nested array + val b1 = b.mutable + + val c = mzeros(20) + b1.update(4,a) // ok: insert immutable array + b1.update(5,c) // error: cannot insert mutable array + + c.update(50,50) + val x1 = b1.at(5).at(50) + print(x1) + } + } + + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation5") + } + + def testMutation6 = { + withOutFile(prefix+"mutation6") { + // mutate nested object (within an immutable one) + trait Prog extends DSL { + def test(x: Rep[Int]) = { + val a = mzeros(100) + val b = array(10) { i => a } // nested array + val u = array(10) { i => zeros(100) } + val c = if (x > 7) b else u + + val x1 = c.at(5).at(50) + + a.update(50,50) + + val x2 = c.at(5).at(50) // no cse, must serialize with update to a + + print(x2-x1) + } + } + + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation6") + } + + def testMutation7 = { + withOutFile(prefix+"mutation7") { + // local variables of primitive type + trait Prog extends DSL with LiftVariables { + def test(x0: Rep[Int]) = { + val x = x0.toDouble // avoid codegen for implicit convert + var c = 0.0 + while (c < x) { + c = c + 1 + } + if (c < x) + c = 8 + print(c) + } + } + + new Prog with Impl + } + assertFileEqualsCheck(prefix+"mutation7") + } + +} diff --git a/test-src/epfl/test8-effects/TestSpeculative.scala b/test-src/epfl/test8-effects/TestSpeculative.scala new file mode 100644 index 00000000..0706a138 --- /dev/null +++ b/test-src/epfl/test8-effects/TestSpeculative.scala @@ -0,0 +1,238 @@ +package scala.lms +package epfl +package test8 + +import common._ +import internal.{NestedBlockTraversal} +import test1._ +import test7.{Print,PrintExp,ScalaGenPrint} +import test7.{ArrayLoops,ArrayLoopsExp,ScalaGenArrayLoops} + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} +import scala.reflect.SourceContext + +class TestSpeculative extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test8-" + + trait DSL extends ArrayMutation with Arith with OrderingOps with BooleanOps with LiftVariables with IfThenElse with While with RangeOps with Print { + def zeros(l: Rep[Int]) = array(l) { i => 0 } + def mzeros(l: Rep[Int]) = zeros(l).mutable + def infix_toDouble(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] + + def test(x: Rep[Int]): Rep[Unit] + } + trait Impl extends DSL with ArrayMutationExp with ArithExp with OrderingOpsExpOpt with BooleanOpsExp + with EqualExpOpt with VariablesExpOpt + with IfThenElseExpOpt with WhileExpOptSpeculative with SplitEffectsExpFat with RangeOpsExp with PrintExp + with CompileScala { self => + override val verbosity = 1 + val codegen = new ScalaGenArrayMutation with ScalaGenArith with ScalaGenOrderingOps + with ScalaGenVariables with ScalaGenIfThenElseFat with ScalaGenWhileOptSpeculative with ScalaGenSplitEffects + with ScalaGenRangeOps with ScalaGenPrint /*with LivenessOpt*/ { val IR: self.type = self } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + val f = compile(test) + f(7) + } + + def testSpeculative1 = { + withOutFile(prefix+"speculative1") { + // test simple copy propagation through variable + trait Prog extends DSL { + def test(x: Rep[Int]) = { + var x = 7 + + if (x > 3) // should remove conditional + print(x) + else + print("no") + print(x) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"speculative1") + } + + def testSpeculative1b = { + withOutFile(prefix+"speculative1b") { + // test simple copy propagation through variable + trait Prog extends DSL { + def test(x: Rep[Int]) = { + var x = 7 + + if (x > 3) // should remove conditional + x = 5 + else + print("no") + + print(x) // should be const 5 + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"speculative1b") + } + + def testSpeculative1c = { + withOutFile(prefix+"speculative1c") { + // test simple copy propagation through variable + trait Prog extends DSL { + def test(y: Rep[Int]) = { + var x = 7 + + if (x > y) // cannot remove conditional + x = 5 + else + print("no") + + print(x) // should be var read + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"speculative1c") + } + + def testSpeculative1d = { + withOutFile(prefix+"speculative1d") { + // test simple copy propagation through variable + trait Prog extends DSL { + def test(y: Rep[Int]) = { + var x = 7 + var z = 9 // should remove z because it is never read + + if (x > y) { // cannot remove conditional + x = 5 + z = 12 // assignment should be removed, too + } else + print("no") + + print(x) // should be var read + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"speculative1d") + } + + + def testSpeculative3 = { + withOutFile(prefix+"speculative3") { + // test simple copy propagation through variable + trait Prog extends DSL { + def test(x: Rep[Int]) = { + var x = 7 + var c = 0.0 + while (c < 10) { + print(x) // should be const 7 + print(c) + var z = 2 // should remove var + c = c + 1 + print(z) // should be const 2 + } + print(x) // should be const 7 + print(c) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"speculative3") + } + + def testSpeculative3b = { + withOutFile(prefix+"speculative3b") { + // test simple copy propagation through variable + trait Prog extends DSL { + def test(x: Rep[Int]) = { + var x = 7 + var y = 4.0 // should remove + var c = 0.0 + while (c < 10) { + print(x) // should be const 7 + print(c) + var z = 2 // should remove var + c = c + 1 + print(z) // should be const 2 + y = y + 2 // should remove + } + print(x) // should be const 7 + print(c) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"speculative3b") + } + + def testSpeculative4 = { + withOutFile(prefix+"speculative4") { + // test simple copy propagation through variable + trait Prog extends DSL { + def test(x: Rep[Int]) = { + var c = 0.0 + while (c > 10) { + print("booooring!") + } + print("done") + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"speculative4") + } + + def testSpeculative5 = { + withOutFile(prefix+"speculative5") { + // test simple copy propagation through variable + trait Prog extends DSL { + def test(x: Rep[Int]) = { + var x = 7 + var c = 0.0 + while (c < 10) { + if (x < 10) + print("test") + else + x = c + print(x) + c += 1 + } + print(x) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"speculative5") + } + + // FIXME: this one breaks. Variable j is lifted to + // top scope because it is not part of the mayWrite + // summary of the inner loop. + def testSpeculative6 = { + withOutFile(prefix+"speculative6") { + // test simple copy propagation through variable + trait Prog extends DSL { + def test(x: Rep[Int]) = { + print("FIXME -- WRONG RESULT") + var i = 0 + while (i < 10) { + var j = 0 + while (j < 10) { + print("test") + print(i) + print(j) + j += 1 + } + i += 1 + } + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"speculative6") + } + + +} diff --git a/test-src/epfl/test9-experimental/TestCPS.scala b/test-src/epfl/test9-experimental/TestCPS.scala new file mode 100644 index 00000000..875c4c90 --- /dev/null +++ b/test-src/epfl/test9-experimental/TestCPS.scala @@ -0,0 +1,228 @@ +package scala.lms +package epfl +package test9 + +import common._ +import test1._ + +import test7.{Print,PrintExp,ScalaGenPrint} +import internal.ScalaCompile + +import scala.util.continuations._ + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} + + +trait CpsProg1 extends Arith with IfThenElse with Equal with Print with Compile { + + def choose[A:Manifest](x: Rep[Boolean]): Boolean @cps[Rep[A]] = shift { k: (Boolean => Rep[A]) => + if (x) + k(true) + else + k(false) + } + + def test(x: Rep[Boolean]): Rep[Unit] = { // recompile + reset { + val c = choose[Unit](x) + if (c) { + this.print("is true") + } else { + this.print("is false") + } + } + } + +} + +trait CpsProg2 extends Arith with IfThenElse with Equal with Print with Compile { + + def choose[A:Manifest](x: Rep[Boolean]): Boolean @cps[Rep[A]] = shift { k: (Boolean => Rep[A]) => + if (x) + k(true) + else + k(false) + } + + + def pickValue[A:Manifest](x: Rep[Boolean]): Rep[Int] @cps[Rep[A]] = { + val c = choose[A](x) + if (c) + unit(7) + else + unit(9) + } + + def test(x: Rep[Boolean]): Rep[Unit] = { // recompile + reset { + val z = pickValue[Unit](x) + this.print(z) + } + } + +} + + +trait AmbProg1 extends Arith with IfThenElse with Equal with Print with Compile { + + //def __ifThenElse[T:Manifest,U](cond: Rep[Boolean], thenp: => Rep[T]@cps[U], elsep: => Rep[T]@cps[U]): Rep[T]@cps[U] = cond match { case true => thenp case false => elsep } + + + // xs could be either Rep[List[T]] or List[Rep[T]] + // if List[Rep[T]], code paths could be duplicated or not... + + // this is the BAM variant of AMB: be careful, it can cause code explosion. + def amb[T](xs: List[Rep[T]]): Rep[T] @cps[Rep[Unit]] = shift { k => + xs foreach k + } + + def require(x: Rep[Boolean]): Rep[Unit] @cps[Rep[Unit]] = shift { k: (Rep[Unit]=>Rep[Unit]) => + if (x) k() else () + } + + + def test(x: Rep[Int]): Rep[Unit] = { + + reset { + val a = amb(List(unit(1),unit(2),x)) + val b = amb(List(unit(1),unit(2),unit(3))) + require(a == b) + this.print("found:") + this.print(a) + this.print(b) + } + + () +/* + def joins(s1:String, s2:String) = s1.endsWith(s2.substring(0,1)) + val w1 = amb(List("the","that","a")) + val w2 = amb(List("frog","elephant","thing")) + val w3 = amb(List("walked","treaded","grows")) + val w4 = amb(List("slowly","quickly")) + require(joins(w1,w2)) + require(joins(w2,w3)) + require(joins(w3,w4)) + yld(List(w1,w2,w3,w4)) + + // result: that thing grows slowly +*/ + +/* +val i = amb(low to high) +val j = amb(i to high) +val k = amb(j to high) +require(i*i + j*j == k*k) +yld((i,j,k)) + +//output using (low=1,high=20): +// (3,4,5) +// (5,12,13) +// (6,8,10) +// (8,15,17) +// (9,12,15) +// (12,16,20) +*/ + } +} + + +trait AmbProg2 extends AmbProg1 { + + override def test(x: Rep[Int]): Rep[Unit] = { + + reset { + val a = amb(List(unit(1),unit(2),unit(3),unit(4))) + val b = amb(List(unit(1),unit(2),unit(3),unit(4))) + val c = amb(List(unit(1),unit(2),unit(3),unit(4))) + require(a != b) + require(b != c) +// require(c != a) + + this.print("found:") + this.print(a) + this.print(b) + this.print(c) + } + + () + } + + +} + + + + +class TestCPS extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test9-" + + def testCps1 = { + withOutFile(prefix+"cps1") { + new CpsProg1 with ArithExp with EqualExp with IfThenElseExp with PrintExp with ScalaCompile { self => + val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + //override def compile + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"cps1") + } + + def testCps2 = { + withOutFile(prefix+"cps2") { + new CpsProg2 with ArithExp with EqualExp with IfThenElseExp with PrintExp with ScalaCompile { self => + val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + //override def compile + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"cps2") + } + + def testAmb1a = { + withOutFile(prefix+"amb1a") { + new AmbProg1 with ArithExp with EqualExp with IfThenElseExp with PrintExp with ScalaCompile { self => + val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + //override def compile + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"amb1a") + } + + def testAmb1b = { + withOutFile(prefix+"amb1b") { + new AmbProg1 with ArithExp with EqualExpOpt with IfThenElseExpOpt with BooleanOpsExp with PrintExp with ScalaCompile { self => + val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + //override def compile + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"amb1b") + } + + def testAmb2a = { + withOutFile(prefix+"amb2a") { + new AmbProg2 with ArithExp with EqualExp with IfThenElseExp with PrintExp with ScalaCompile { self => + val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + //override def compile + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"amb2a") + } + + def testAmb2b = { + withOutFile(prefix+"amb2b") { + new AmbProg2 with ArithExp with EqualExpOpt with IfThenElseExpOpt with BooleanOpsExp with PrintExp with ScalaCompile { self => + val codegen = new ScalaGenArith with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenPrint { val IR: self.type = self } + //override def compile + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + } + } + assertFileEqualsCheck(prefix+"amb2b") + } + +} diff --git a/test-src/epfl/test9-experimental/TestCrossStage.scala b/test-src/epfl/test9-experimental/TestCrossStage.scala new file mode 100644 index 00000000..c144eb20 --- /dev/null +++ b/test-src/epfl/test9-experimental/TestCrossStage.scala @@ -0,0 +1,84 @@ +package scala.lms +package epfl +package test9 + +import common._ +import internal.{ScalaCompile} +import test1._ +import test7.{Print,PrintExp,ScalaGenPrint} +import test7.{ArrayLoops,ArrayLoopsExp,ArrayLoopsFatExp,ScalaGenArrayLoops,ScalaGenFatArrayLoopsFusionOpt} + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} +import collection.mutable.ArrayBuffer + +class TestCrossStage extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test9-" + + trait DSL extends Functions with ArrayBufferOps with Arith with OrderingOps with Variables with LiftVariables with IfThenElse with RangeOps with Print { + def infix_toDouble(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] + def test(x: Rep[Int]): Rep[Unit] + + implicit def funToRep[T:Manifest,U:Manifest](x:T=>U): Rep[T=>U] + implicit def abToRep[T:Manifest](x:ArrayBuffer[T]): Rep[ArrayBuffer[T]] + } + + trait Impl extends DSL with StaticDataExp with FunctionsExp with ArrayBufferOpsExp with ArithExp with OrderingOpsExp with VariablesExp + with IfThenElseExp with RangeOpsExp with PrintExp with ScalaCompile { self => + + def funToRep[T:Manifest,U:Manifest](x:T=>U): Rep[T=>U] = staticData(x) + def abToRep[T:Manifest](x:ArrayBuffer[T]): Rep[ArrayBuffer[T]] = staticData(x) + + override val verbosity = 2 + val codegen = new ScalaGenStaticData with ScalaGenFunctions with ScalaGenArrayBufferOps with ScalaGenArith with ScalaGenOrderingOps + with ScalaGenVariables with ScalaGenIfThenElse with ScalaGenRangeOps + with ScalaGenPrint { + val IR: self.type = self + } + codegen.emitSource(test, "Test", new PrintWriter(System.out)) + println("-- running program") + val f = compile(test) + f(21) + } + + // don't know sharing dependencies between static data in general -- for now assume there is no sharing + + def testCrossStage1 = { + withOutFile(prefix+"csp1") { + val f = (x: Int) => println("this is external non-DSL code: " + (2*x)) + + trait Prog extends DSL { + def test(x: Rep[Int]) = { + + doApply(f, x) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"csp1") + } + + def testCrossStage2 = { + withOutFile(prefix+"csp2") { + val acc = new ArrayBuffer[Int] + + trait Prog extends DSL { + def test(x: Rep[Int]) = { +// Broke test compilation: +// array buffer switched to use implicis instead of +// infix methods and lifting did not kick in + acc += x + acc += x + print("done") + } + } + new Prog with Impl + + println("accumulated: " + acc.mkString(",")) + } + assertFileEqualsCheck(prefix+"csp2") + } + +} diff --git a/test-src/epfl/test9-experimental/TestStruct.scala b/test-src/epfl/test9-experimental/TestStruct.scala new file mode 100644 index 00000000..206f635e --- /dev/null +++ b/test-src/epfl/test9-experimental/TestStruct.scala @@ -0,0 +1,303 @@ +package scala.lms +package epfl +package test9 + +import common._ +import internal.{FatExpressions,GenericFatCodegen} + + +import test1._ +import test7.{Print,PrintExp,ScalaGenPrint} +import test7.{ArrayLoops,ArrayLoopsExp,ArrayLoopsFatExp,ScalaGenArrayLoops,ScalaGenFatArrayLoopsFusionOpt} +import scala.reflect.SourceContext + +import util.OverloadHack + +import java.io.{PrintWriter,StringWriter,FileOutputStream} + + +trait ComplexArith extends Arith with ComplexBase with OverloadHack { + + def infix_+(x: Rep[Complex], y: Rep[Complex])(implicit o: Overloaded1): Rep[Complex] = Complex(x.re + y.re, x.im + y.im) + def infix_-(x: Rep[Complex], y: Rep[Complex])(implicit o: Overloaded1): Rep[Complex] = Complex(x.re - y.re, x.im - y.im) + //def infix_*(x: Rep[Complex], y: Rep[Complex]): Rep[Complex] = Complex(x.re + y.re, x.im + y.im) + +} + +trait ComplexBase extends Arith with StructOps { + type Complex = Record { val re: Double; val im: Double } + def Complex(r: Rep[Double], i: Rep[Double]): Rep[Complex] = new Record { val re = r; val im = i } +} + +// ------ struct impl follows, will move to common once stable + +trait StructExpOptLoops extends StructExpOptCommon with ArrayLoopsExp { + + case class ArraySoaTag[T](base: StructTag[T], len: Exp[Int]) extends StructTag[T] + + override def simpleLoop[A:Manifest](size: Exp[Int], v: Sym[Int], body: Def[A])(implicit pos: SourceContext): Exp[A] = body match { + case ArrayElem(Block(Def(Struct(tag:StructTag[A], elems)))) => + struct[A](ArraySoaTag[A](tag,size), elems.map(p=>(p._1,simpleLoop(size, v, ArrayElem(Block(p._2)))(p._2.tp.arrayManifest, pos)))) + case ArrayElem(Block(Def(ArrayIndex(b,`v`)))) if infix_length(b) == size => b.asInstanceOf[Exp[A]] + // eta-reduce! <--- should live elsewhere, not specific to struct + // rewrite loop(a.length) { i => a(i) } to a + case _ => super.simpleLoop(size, v, body) + } + + + override def infix_at[T:Manifest](a: Rep[Array[T]], i: Rep[Int]): Rep[T] = a match { + case Def(Struct(ArraySoaTag(tag,len),elems: Iterable[(String,Rep[Array[T]])])) => + def unwrap[A](m:Manifest[Array[A]]): Manifest[A] = m.typeArguments match { + case a::_ => mtype(a) + case _ => + if (m.erasure.isArray) mtype(Manifest.classType(m.erasure.getComponentType)) + else { printerr("warning: expect type Array[A] but got "+m); mtype(manifest[Any]) } + } + struct[T](tag.asInstanceOf[StructTag[T]], elems.map(p=>(p._1,infix_at(p._2, i)(unwrap(p._2.tp))))) + case _ => super.infix_at(a,i) + } + + override def infix_length[T:Manifest](a: Rep[Array[T]]): Rep[Int] = a match { + case Def(Struct(ArraySoaTag(tag,len),elems)) => len + case _ => super.infix_length(a) + } + +} + +// ----- test cases + + +class TestStruct extends FileDiffSuite { + + val prefix = home + "test-out/epfl/test9-" + + trait DSL extends ComplexArith with ArrayLoops with Arith with OrderingOps with Variables with LiftVariables with IfThenElse with RangeOps with Print { + def infix_toDouble(x: Rep[Int]): Rep[Double] = x.asInstanceOf[Rep[Double]] + def test(x: Rep[Int]): Rep[Unit] + } + + trait Impl extends DSL with StructExp with ArrayLoopsExp with StructExpOptLoops with ArithExp with OrderingOpsExp with VariablesExp + with IfThenElseExp with RangeOpsExp with PrintExp { self => + override val verbosity = 1 + val codegen = new ScalaGenArrayLoops with ScalaGenStruct with ScalaGenArith with ScalaGenOrderingOps + with ScalaGenVariables with ScalaGenIfThenElse with ScalaGenRangeOps + with ScalaGenPrint { val IR: self.type = self } + + /*override def fresh[T:Manifest]: Sym[T] = Sym[T] { + if (nVars < 3) { + System.out.println(nVars) + (new Exception).printStackTrace + } + + nVars += 1; nVars -1 + }*/ + + { + val x = fresh[Int] + val y = reifyEffects(test(x)) + //globalDefs.foreach(Console.println _) + codegen.emitSource(List(x),y, "Test", new PrintWriter(System.out)) + codegen.emitDataStructures(new PrintWriter(System.out)) + } + } + + trait ImplFused extends DSL with StructExp with StructExpOptLoops with StructFatExpOptCommon with ArrayLoopsFatExp with ArithExp with OrderingOpsExp with VariablesExp + with IfThenElseExp with RangeOpsExp with PrintExp { self => + override val verbosity = 1 + val codegen = new ScalaGenFatArrayLoopsFusionOpt with ScalaGenFatStruct with ScalaGenArith with ScalaGenOrderingOps + with ScalaGenVariables with ScalaGenIfThenElse with ScalaGenRangeOps + with ScalaGenPrint { val IR: self.type = self; + override def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true } + { + val x = fresh[Int] + val y = reifyEffects(test(x)) + //globalDefs.foreach(Console.println _) + codegen.emitSource(List(x),y, "Test", new PrintWriter(System.out)) + codegen.emitDataStructures(new PrintWriter(System.out)) + } + } + + + + def testStruct1 = { + withOutFile(prefix+"struct1") { + // test variable splitting + trait Prog extends DSL { + def test(x: Rep[Int]) = { + var c = Complex(x.toDouble, 0) + c = c + Complex(0,x.toDouble) + print(c) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"struct1") + } + + def testStruct2 = { + withOutFile(prefix+"struct2") { + // test basic struct flattening (loops, variables, conditionals) + println("REMARK: this makes only sense with fat codegen (computation duplicated and some structs not removed otherwise)") + trait Prog extends DSL { + def test(x: Rep[Int]) = { + // split loops (rely on fusion, don't want to duplicate computation!) + + val vector1 = array(100) { i => Complex(i.toDouble, 0.0 - i.toDouble) } + val vector2 = array(100) { i => Complex(0.0 - i.toDouble, i.toDouble) } + + var vvar = vector2 + + // split conditionals (be careful about effects) + + val vector3 = if (x > 7) vector1 else vvar + + // conditional is reflected because it reads vvar -- effect ordering for split terms? + + vvar = vector1 + + print(vvar) + print(vector3) + } + } + new Prog with Impl + } + assertFileEqualsCheck(prefix+"struct2") + } + + def testStruct2b = { + withOutFile(prefix+"struct2b") { + // test basic struct flattening (loops, variables, conditionals) + trait Prog extends DSL { + def test(x: Rep[Int]) = { + // split loops (rely on fusion, don't want to duplicate computation!) + + val vector1 = array(100) { i => Complex(i.toDouble, 0.0 - i.toDouble) } + val vector2 = array(100) { i => Complex(0.0 - i.toDouble, i.toDouble) } + + var vvar = vector2 + + // split conditionals (be careful about effects) + + val vector3 = if (x > 7) { + print("foobar true") + vector1 + } else { + print("foobar false") + vvar + } + + vvar = vector1 + + print(vvar) + print(vector3) + } + } + new Prog with ImplFused + } + assertFileEqualsCheck(prefix+"struct2b") + } + + def testStruct3 = { + withOutFile(prefix+"struct3") { + // fuse conjugate computation with construction, essentially a no-op + trait Prog extends DSL { + def test(x: Rep[Int]) = { + + val vector1 = array(100) { i => Complex(i.toDouble, 0.0 - i.toDouble) } + + def conj(c: Rep[Complex]) = Complex(c.re, 0.0 - c.im) + def infix_map[A:Manifest,B:Manifest](c: Rep[Array[A]], f: Rep[A] => Rep[B]) = array(c.length) { i => f(c.at(i)) } + + val vector3 = vector1.map(conj) + + print(vector3) + } + } + new Prog with ImplFused { + // TODO: use a generic Opt trait instead of defining rewrites here... + override def infix_-(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = (x, y) match { + case (x, Def(Minus(Const(0.0),y))) => infix_+(x,y) + case _ => super.infix_-(x,y) + } + override def infix_+(x: Exp[Double], y: Exp[Double])(implicit pos: SourceContext) = (x, y) match { + case (Const(0.0), y) => y + case _ => super.infix_+(x,y) + } + } + } + assertFileEqualsCheck(prefix+"struct3") + } + + def testStruct4 = { + withOutFile(prefix+"struct4") { + trait Prog extends DSL { + // recognize that only imaginary part is modified, real part untouched + def test(x: Rep[Int]) = { + + val vector1 = array(100) { i => Complex(i.toDouble, 0.0 - i.toDouble) } + val vector2 = array(100) { i => Complex(0.0 - i.toDouble, i.toDouble) } + + def conj(c: Rep[Complex]) = Complex(c.re, 0.0 - c.im) + def infix_map[A:Manifest,B:Manifest](c: Rep[Array[A]], f: Rep[A] => Rep[B]) = array(c.length) { i => f(c.at(i)) } + + var vvar = vector1 // force access outside conditional, otherwise construction will be moved inside, defeating purpose of test + + // result of this conditional should be a *single* array + // containing the flattened im fields. re fields should be + // unconditional. + val vector3 = if (x > 7) { + vector1.map(conj) + } else { + vector1 + } + + print(vector3) + } + } + new Prog with ImplFused + } + assertFileEqualsCheck(prefix+"struct4") + } + + // Two classes are generated if the refined type’s fields have the same type but different names + def testStruct5 = { + withOutFile(prefix+"struct5") { + + trait Vectors extends StructOps { + type Vector2D = Record { val x: Double; val y: Double } + def Vector2D(px: Rep[Double], py: Rep[Double]): Rep[Vector2D] = new Record { val x = px; val y = py } + } + + trait Prog extends DSL with Vectors { + def test(x: Rep[Int]) = { + print(Vector2D(1, 2)) + print(Complex(3, 4)) + } + } + + new Prog with Impl + } + assertFileEqualsCheck(prefix+"struct5") + } + + // Only one class is generated if refined types are equivalent (their fields have the same names and types) + def testStruct6 = { + withOutFile(prefix+"struct6") { + + trait Complex2 extends Arith with StructOps { + type Complex2 = Record { val re: Double; val im: Double } + def Complex2(r: Rep[Double], i: Rep[Double]): Rep[Complex2] = new Record { val re = r; val im = i } + } + + trait Prog extends DSL with Complex2 { + def test(x: Rep[Int]) = { + print(Complex2(1, 2)) + print(Complex(3, 4)) + } + } + + new Prog with Impl + } + assertFileEqualsCheck(prefix+"struct6") + } +} From beb857b2baf496ea219c3d3c6da56e2191ca24ff Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Mon, 19 Dec 2016 23:42:13 -0500 Subject: [PATCH 09/10] OpenCLDeviceTransfer was missing --- src/internal/OpenCLDeviceTransfer.scala | 95 +++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/internal/OpenCLDeviceTransfer.scala diff --git a/src/internal/OpenCLDeviceTransfer.scala b/src/internal/OpenCLDeviceTransfer.scala new file mode 100644 index 00000000..88e9e6d2 --- /dev/null +++ b/src/internal/OpenCLDeviceTransfer.scala @@ -0,0 +1,95 @@ +package scala.lms.internal + +/* Defines OpenCL specific device transfer functions */ +trait OpenCLDeviceTransfer extends AbstractDeviceTransfer { + this: OpenCLCodegen => + + val IR: Expressions + import IR._ + + def emitSendSlave(tp: Manifest[_]): (String,String) = { + if (isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "%s sendOpenCL_%s(%s sym)".format(remap(tp),mangledName(remap(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\treturn sym;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + tp.toString) + } + } + + def emitRecvSlave(tp: Manifest[_]): (String,String) = { + if (isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "%s recvOpenCL_%s(%s sym)".format(remap(tp),mangledName(remap(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\treturn sym;\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + tp.toString) + } + } +/* + def emitSendViewSlave(sym: Sym[Any]): (String,String) = { + if (isPrimitiveType(sym.tp)) { + val out = new StringBuilder + val signature = "%s sendViewOpenCL_%s(%s %s)".format(remap(sym.tp),quote(sym),remap(sym.tp),quote(sym)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn %s;\n".format(quote(sym))) + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + sym.tp.toString) + } + } + + def emitRecvViewSlave(sym: Sym[Any]): (String,String) = { + if (isPrimitiveType(sym.tp)) { + val out = new StringBuilder + val signature = "%s recvViewOpenCL_%s(%s %s)".format(remap(sym.tp),quote(sym),remap(sym.tp),quote(sym)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("\treturn %s;\n".format(quote(sym))) + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + sym.tp.toString) + } + } +*/ + def emitSendUpdateSlave(tp: Manifest[_]): (String,String) = { + if(isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "void sendUpdateOpenCL_%s(%s sym)".format(mangledName(remap(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + tp.toString) + } + } + + def emitRecvUpdateSlave(tp: Manifest[_]): (String,String) = { + if(isPrimitiveType(tp)) { + val out = new StringBuilder + val signature = "void recvUpdateOpenCL_%s(%s sym)".format(mangledName(remap(tp)),remap(tp)) + out.append(signature + " {\n") + out.append("\tassert(false);\n") + out.append("}\n") + (signature+";\n", out.toString) + } + else { + throw new GenerationFailedException("OpenCLDeviceTransfer: Unknown type " + tp.toString) + } + } +} From 044a1e099c3e3ed1bda2ac76a40791f9908697ef Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Tue, 20 Dec 2016 00:51:30 -0500 Subject: [PATCH 10/10] some fixes --- src/common/ArrayOps.scala | 124 ---------------------------------- src/common/BooleanOps.scala | 21 +----- src/common/Functions.scala | 45 ------------ src/common/GeneratorOps.scala | 2 +- src/common/IfThenElse.scala | 14 ---- src/common/OPMOps.scala | 7 +- src/common/Packages.scala | 9 ++- src/common/RangeOps.scala | 12 ---- src/common/StringOps.scala | 9 --- src/common/Structs.scala | 119 -------------------------------- src/common/While.scala | 22 +----- 11 files changed, 10 insertions(+), 374 deletions(-) diff --git a/src/common/ArrayOps.scala b/src/common/ArrayOps.scala index 4f43ee1c..d38392a4 100644 --- a/src/common/ArrayOps.scala +++ b/src/common/ArrayOps.scala @@ -386,130 +386,6 @@ trait OpenCLGenArrayOps extends OpenCLGenBase with CLikeGenArrayOps trait CGenArrayOps extends CGenEffect with CGenStruct { val IR: ArrayOpsExp import IR._ - -/* - - override def remapManifest[T:Manifest](sym: Sym[T]): Manifest[_] = { - if (sym.tp.erasure.isArray) manifest[LoweredArray[T]] - else super.remapManifest(sym) - } - - override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { - case a@ArrayNew(n, sType) => { - sym.atPhase(LIRLowering) { - reflectEffect(SimpleStruct[LoweredArray[T]](ClassTag(structName(manifest[T])), Seq( - "array" -> reflectEffect(rhs), - "length" -> n - ))).asInstanceOf[Exp[T]] - } - } - case ArrayApply(a, n) => { - sym.atPhase(LIRLowering) { - val ar = field[Array[T]](LIRLowering(a), "array") - reflectEffect(ArrayApply(ar, LIRLowering(n))).asInstanceOf[Exp[T]] - } - } - case ArrayFilter(a,x,blk) => { - /* Not yet implemented, not needed so far (we take advantage of the final - '\0' character for array of bytes for all operations of importance) */ - sym.atPhase(LIRLowering) { - LIRLowering(a).asInstanceOf[Exp[T]] - } - } - case ArrayUpdate(a, n, y) => { - sym.atPhase(LIRLowering) { - val ar = field[Array[Any]](LIRLowering(a), "array") - reflectEffect(ArrayUpdate(ar, LIRLowering(n), LIRLowering(y))).asInstanceOf[Exp[T]] - } - } - case ar@ArrayLength(a) => - sym.atPhase(LIRLowering) { - field(LIRLowering(a),"length").asInstanceOf[Exp[T]] - } - case ArrayHash(a) => - sym.atPhase(LIRLowering) { - if (a.tp != manifest[Array[Byte]]) throw new Exception("Unknown manifest " + a.tp + " when lowering ArrayHash.") - val arr = field[Array[Byte]](LIRLowering(a),"array") - val arrlen = field(LIRLowering(a),"length").asInstanceOf[Rep[Int]] - var i = var_new[Int](unit(0)) - var h = var_new[Int](unit(0)) - __whileDo(i < arrlen && arr(i) != unit('\0'), { - h += arr(i) - i+=1 - }) - readVar(h).asInstanceOf[Exp[T]] - } - case ArrayCorresponds(a1,a2) => - sym.atPhase(LIRLowering) { - if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[Array[Byte]]) { - val arr2 = field[Array[Byte]](LIRLowering(a2),"array") - __equal(LIRLowering(a1),arr2).asInstanceOf[Exp[T]] - } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayCorresponds.") - } - case ArrayCompare(a1,a2) => - sym.atPhase(LIRLowering) { - if (a1.tp == manifest[Array[Byte]] && (a2.tp == manifest[Array[Byte]] || a2.tp.typeArguments(0) == manifest[Array[Byte]])) { - val arr1 = field[Array[Byte]](LIRLowering(a1),"array") - val arr2 = field[Array[Byte]](LIRLowering(a2),"array") - string_compareTo(arr1.asInstanceOf[Exp[String]],arr2.asInstanceOf[Exp[String]]).asInstanceOf[Exp[T]] - } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayCompare.") - } - case ArrayStartsWith(a1,a2) => - sym.atPhase(LIRLowering) { - if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[java.lang.String]) { - val arr1 = field[Array[Byte]](LIRLowering(a1),"array") - string_startswith(arr1.asInstanceOf[Exp[String]],a2.asInstanceOf[Exp[String]]).asInstanceOf[Exp[T]] - } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayStartsWith.") - } - case ArrayEndsWith(a1,a2) => - sym.atPhase(LIRLowering) { - if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[java.lang.String]) { - val arr1 = field[Array[Byte]](LIRLowering(a1),"array") - string_endswith(arr1.asInstanceOf[Exp[String]],a2.asInstanceOf[Exp[String]]).asInstanceOf[Exp[T]] - } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayEndsWith.") - } - case ArrayContainsSlice(a1,a2) => - sym.atPhase(LIRLowering) { - if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[java.lang.String]) { - val arr1 = field[Array[Byte]](LIRLowering(a1),"array") - string_containsSlice(arr1.asInstanceOf[Exp[String]],a2.asInstanceOf[Exp[String]]).asInstanceOf[Exp[T]] - } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayContainsSlice.") - } - case ArrayIndexOfSlice(a1,a2,idx) => - sym.atPhase(LIRLowering) { - if (a1.tp == manifest[Array[Byte]] && a2.tp == manifest[java.lang.String]) { - val arr1 = field[Array[Byte]](LIRLowering(a1),"array") - string_indexOfSlice(arr1.asInstanceOf[Exp[String]],LIRLowering(a2).asInstanceOf[Exp[String]],LIRLowering(idx)).asInstanceOf[Exp[T]] - } else throw new Exception("Unknown manifest combination (" + a1.tp + "," + a2.tp + ") when lowering ArrayIndexOfSlice.") - } - case as@ArraySlice(arr,idx1,idx2) => - sym.atPhase(LIRLowering) { - val len = LIRLowering(idx2) - LIRLowering(idx1) + 1 - // Initialize new array - val newarr = reflectEffect(SimpleStruct[LoweredArray[T]](ClassTag(structName(manifest[T])), Seq( - "array" -> array_obj_new(len)(as.m), - "length" -> len - ))) - // Perform the copy - // TODO: FIX THE TYPE OF THIS ARRAY -- IT CAN BE ANY, BUT DOES IT AFFECT ANYTHING? - val arr1 = field[Array[Byte]](newarr,"array") - val arr2 = field[Array[Byte]](LIRLowering(arr),"array") - array_copy(arr2.asInstanceOf[Exp[Array[Any]]],unit(0),arr1.asInstanceOf[Exp[Array[Any]]],unit(0),len-unit(1)) - newarr.asInstanceOf[Exp[T]] - } - case _ => super.lowerNode(sym, rhs) - } - -*/ - - - abstract class LoweredArray[T:Manifest] - - override def remap[A](m: Manifest[A]) = m match { - case s if m <:< manifest[LoweredArray[Any]] => "struct " + structName(m.typeArguments.head) + "*" - case s if m.erasure.isArray => remap(m.typeArguments.head) + "*" - case _ => super.remap(m) - } override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { diff --git a/src/common/BooleanOps.scala b/src/common/BooleanOps.scala index 13268753..f3f7f09e 100644 --- a/src/common/BooleanOps.scala +++ b/src/common/BooleanOps.scala @@ -155,23 +155,4 @@ trait CLikeGenBooleanOps extends CLikeGenBase with GenericNestedCodegen { trait CudaGenBooleanOps extends CudaGenBase with CLikeGenBooleanOps trait OpenCLGenBooleanOps extends OpenCLGenBase with CLikeGenBooleanOps -trait CGenBooleanOps extends CGenBase with CLikeGenBooleanOps { - val IR: BooleanOpsExp - import IR._ - - override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { - case BooleanAnd(lhs,rhs) => { - LIRTraversal(rhs) - sym.atPhase(LIRLowering) { - reflectEffect(BooleanAnd(LIRLowering(lhs),LIRLowering(rhs))).asInstanceOf[Exp[A]] - } - } - case BooleanOr(lhs,rhs) => { - LIRTraversal(rhs) - sym.atPhase(LIRLowering) { - reflectEffect(BooleanOr(LIRLowering(lhs),LIRLowering(rhs))).asInstanceOf[Exp[A]] - } - } - case _ => super.lowerNode(sym,rhs) - } -} +trait CGenBooleanOps extends CGenBase with CLikeGenBooleanOps diff --git a/src/common/Functions.scala b/src/common/Functions.scala index 8154b54a..90982e6b 100644 --- a/src/common/Functions.scala +++ b/src/common/Functions.scala @@ -475,51 +475,6 @@ trait CGenFunctions extends CNestedCodegen with CGenEffect with BaseGenFunctions val IR: FunctionsExp import IR._ - override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { - case UninlinedFunc0(f) => { - LIRTraversal(f) - sym.atPhase(LIRLowering) { - functionList0 -= sym - functionList0 += (sym -> LIRLowering(f)) - sym - } - } - case UninlinedFunc1(s,f) => { - LIRTraversal(f) - sym.atPhase(LIRLowering) { - functionList1 -= sym - functionList1 += (sym -> (s,LIRLowering(f))) - sym - } - } - case UninlinedFunc2(s1,s2,f) => { - LIRTraversal(f) - sym.atPhase(LIRLowering) { - functionList2 -= sym - functionList2 += (sym -> (s1,s2,LIRLowering(f))) - sym - } - } - case UninlinedFunc3(s1,s2,s3,f) => { - LIRTraversal(f) - sym.atPhase(LIRLowering) { - functionList3 -= sym - functionList3 += (sym -> (s1,s2,s3,LIRLowering(f))) - sym - } - } - case a@Apply(fun, arg) => - sym.atPhase(LIRLowering) { - val funSym = fun.asInstanceOf[Sym[_]] - val rM = (fun match { - case s if functionList0.contains(funSym) => getBlockResult(functionList0(funSym)).tp - case _ => a.mB - }).asInstanceOf[Manifest[T]] - doApply(fun, arg)(a.mA, rM, implicitly[SourceContext]).asInstanceOf[Exp[T]] - } - case _ => super.lowerNode(sym, rhs) - } - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case e@Lambda(fun, x, y) => stream.println(remap(y.tp)+" "+quote(sym)+"("+remap(x.tp)+" "+quote(x)+") {") diff --git a/src/common/GeneratorOps.scala b/src/common/GeneratorOps.scala index 0b71a608..f7ea9652 100644 --- a/src/common/GeneratorOps.scala +++ b/src/common/GeneratorOps.scala @@ -16,7 +16,7 @@ trait MapOps extends Base { def updateValue[K, V](x: Rep[MapType[K, V]], key: Rep[K], value: Rep[V]): Rep[Unit] } -trait GeneratorOps extends Base with Variables with LiftVariables with IfThenElse with Equal with TupleOps with ListOps with MapOps with ObjectOps with StringOps with HashMapOps with ListBuffer with HashMultiMapOps with SetOps with LiftNumeric with NumericOps with ArrayOps { +trait GeneratorOps extends Base with Variables with LiftVariables with IfThenElse with Equal with TupleOps with ListOps with MapOps with ObjectOps with StringOps with HashMapOps with SetOps with LiftNumeric with NumericOps with ArrayOps { def materializeGenerator[T:Manifest,U:Manifest](gen: Generator[U]): Rep[T] def dematerializeGenerator[T:Manifest,U:Manifest](genCon: Rep[T]): Generator[U] diff --git a/src/common/IfThenElse.scala b/src/common/IfThenElse.scala index e79c5dbd..7673201c 100644 --- a/src/common/IfThenElse.scala +++ b/src/common/IfThenElse.scala @@ -383,20 +383,6 @@ trait OpenCLGenIfThenElseFat extends OpenCLGenIfThenElse with OpenCLGenFat with trait CGenIfThenElse extends CGenEffect with BaseGenIfThenElse { import IR._ - override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { - case IfThenElse(c,a,b) => { - LIRTraversal(a) - LIRTraversal(b) - sym.atPhase(LIRLowering) { - val tc = LIRLowering(c) - val ta = LIRLowering(a) - val tb = LIRLowering(b) - reflectEffect(IfThenElse(tc, ta, tb)(tb.tp.asInstanceOf[Manifest[T]])).asInstanceOf[Exp[T]] - } - } - case _ => super.lowerNode(sym, rhs) - } - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { rhs match { case IfThenElse(c,a,b) => diff --git a/src/common/OPMOps.scala b/src/common/OPMOps.scala index 2b3c35e3..9337ce67 100644 --- a/src/common/OPMOps.scala +++ b/src/common/OPMOps.scala @@ -1,10 +1,9 @@ - -package scala.virtualization.lms +package scala.lms package common import java.io.PrintWriter -import scala.virtualization.lms.internal.{GenericNestedCodegen, GenerationFailedException} +import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException} import scala.reflect.SourceContext trait OMPOps extends Base { @@ -12,7 +11,7 @@ trait OMPOps extends Base { def critical_region(b: => Rep[Unit]): Rep[Unit] } -trait OMPOpsExp extends OMPOps { +trait OMPOpsExp extends OMPOps with BaseExp with EffectExp { case class ParallelRegion(b: Block[Unit]) extends Def[Unit] def parallel_region(b: => Exp[Unit]): Exp[Unit] = { diff --git a/src/common/Packages.scala b/src/common/Packages.scala index 62af7d2f..d92a5cc1 100644 --- a/src/common/Packages.scala +++ b/src/common/Packages.scala @@ -18,7 +18,7 @@ trait ScalaOpsPkg extends Base with PrimitiveOps with MiscOps with Functions with Equal with IfThenElse with Variables with While with TupleOps with ListOps with SeqOps with MathOps with CastingOps with SetOps with ObjectOps with ArrayBufferOps - with DateOps with GregorianCalendarOps with SimpleDateFormatOps with UncheckedOps + with UncheckedOps trait ScalaOpsPkgExp extends ScalaOpsPkg with StructExp with ImplicitOpsExp with NumericOpsExp with FractionalOpsExp with OrderingOpsExp @@ -26,13 +26,13 @@ trait ScalaOpsPkgExp extends ScalaOpsPkg with PrimitiveOpsExp with MiscOpsExp with FunctionsExp with EqualExp with IfThenElseExp with VariablesExp with WhileExp with TupleOpsExp with ListOpsExp with SeqOpsExp with MathOpsExp with CastingOpsExp with SetOpsExp with ObjectOpsExp with ArrayBufferOpsExp - with DateExp with GregorianCalendarExp with SimpleDateFormatExp with UncheckedOpsExp + with UncheckedOpsExp trait ScalaOpsPkgExpOpt extends ScalaOpsPkgExp with StructExpOptCommon with NumericOpsExpOpt with ArrayOpsExpOpt with ListOpsExpOpt with EqualExpOpt with IfThenElseExpOpt with VariablesExpOpt with WhileExpOpt - with DateExpOpt with GregorianCalendarExpOpt with SimpleDateFormatExpOpt with ObjectOpsExpOpt + with ObjectOpsExpOpt /** Code gen: each target must define a code generator package. */ trait ScalaCodeGenPkg extends ScalaGenImplicitOps with ScalaGenNumericOps with ScalaGenFractionalOps with ScalaGenOrderingOps @@ -40,8 +40,7 @@ trait ScalaCodeGenPkg extends ScalaGenImplicitOps with ScalaGenNumericOps with S with ScalaGenPrimitiveOps with ScalaGenMiscOps with ScalaGenFunctions with ScalaGenEqual with ScalaGenIfThenElse with ScalaGenVariables with ScalaGenWhile with ScalaGenTupleOps with ScalaGenListOps with ScalaGenSeqOps with ScalaGenDSLOps with ScalaGenMathOps with ScalaGenCastingOps with ScalaGenSetOps - with ScalaGenObjectOps with ScalaGenArrayBufferOps with ScalaGenDate with ScalaGenGregorianCalendar - with ScalaGenSimpleDateFormat with ScalaGenUncheckedOps + with ScalaGenObjectOps with ScalaGenArrayBufferOps { val IR: ScalaOpsPkgExp } diff --git a/src/common/RangeOps.scala b/src/common/RangeOps.scala index bc39deb9..3bb28f66 100644 --- a/src/common/RangeOps.scala +++ b/src/common/RangeOps.scala @@ -231,18 +231,6 @@ trait CGenRangeOps extends CGenEffect with BaseGenRangeOps { val IR: RangeOpsExp import IR._ - override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { - case RangeForeach(start, end, i, body) => { - LIRTraversal(body) - sym.atPhase(LIRLowering) { - val b = LIRLowering(body) - val be = summarizeEffects(b) - reflectEffect(RangeForeach(LIRLowering(start), LIRLowering(end), i, b), be.star).asInstanceOf[Exp[T]] - } - } - case _ => super.lowerNode(sym, rhs) - } - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case Until(start, end) => throw new GenerationFailedException("CGenRangeOps: Range vector is not supported") diff --git a/src/common/StringOps.scala b/src/common/StringOps.scala index 5b9083a8..6b5bdf8c 100644 --- a/src/common/StringOps.scala +++ b/src/common/StringOps.scala @@ -202,15 +202,6 @@ trait CGenStringOps extends CGenBase with CNestedCodegen { val IR: StringOpsExp import IR._ - override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { - case StringNew(s) => sym.atPhase(LIRLowering) { - // TODO: Find a better way than this. It assumes that the argument is an array of byte and it also assumes its implicit lowering - val ar = field[Array[Byte]](LIRLowering(s), "array") - ar.asInstanceOf[Exp[A]] - } - case _ => super.lowerNode(sym,rhs) - } - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case StringNew(s1) => emitValDef(sym, src"$s1") case StringLength(s1) => emitValDef(sym, src"tpch_strlen($s1)") diff --git a/src/common/Structs.scala b/src/common/Structs.scala index 2a879a6e..1fae7bbf 100644 --- a/src/common/Structs.scala +++ b/src/common/Structs.scala @@ -564,125 +564,6 @@ trait CGenStruct extends CGenBase with BaseGenStruct { case dflt@_ => throw new Exception("Unsupported printf descr " + dflt + " when emitting struct. Stringifying...") } - override def lowerNode[A:Manifest](sym: Sym[A], rhs: Def[A]) = rhs match { - case fa@FieldApply(rec,fldname) => - if (encounteredStructs.get(structName(rec.tp)).isEmpty) { - System.out.println("XX struct not encountered: "+rec.tp) - System.out.println("XX at: "+(sym:AnyRef)+"/"+rhs) - //registerStruct(rec.tp) - } - - val fldtype = encounteredStructs(structName(rec.tp)).find(e => e._1 == fldname).get._2 - val lfldtype = { - val s = fresh(fldtype) - s.tp = fldtype - remapManifest(s)(fldtype.asInstanceOf[Manifest[Any]]) - } - sym.atPhase(LIRLowering) { - val e = (if (sym.tp.erasure.isArray) - reflectEffect(FieldApply(LIRLowering(rec),fldname)(remapManifest(fresh(sym.tp))(sym.tp))) - else record_select(LIRLowering(rec),fldname)(rec.tp,lfldtype)) - e.tp = lfldtype - e.asInstanceOf[Exp[A]] - } - case RecordHash(t) => - sym.atPhase(LIRLowering) { - val rec = LIRLowering(t) - def hash[T:Manifest](lrec: Exp[T]): Exp[Size] = { - val fields = encounteredStructs(structName(manifest[T])) - var h = var_new[Size](unit(0)) - fields.foreach { fld => - if (fld._2.erasure.isPrimitive || fld._2 == manifest[java.lang.Character]) - h += field(lrec, fld._1)(fld._2,implicitly[SourceContext]) - else if (fld._2 == manifest[Array[Byte]]) { - val fldtype = { - val s = fresh(fld._2) - s.tp = fld._2 - remapManifest(s)(fld._2.asInstanceOf[Manifest[Any]]) - } - val a = field(lrec, fld._1)(fld._2, implicitly[SourceContext]) - a.tp = fldtype - val arr = field[Array[Byte]](a,"array") - val arrlen = field[Size](a,"length").asInstanceOf[Rep[Size]] - var i = var_new[Size](unit(0)) - var harr = var_new[Size](unit(0)) - __whileDo(i < arrlen && arr(i) != unit('\0'), { - harr += arr(i) - i+=1 - }) - h += readVar(h) - } - else throw new Exception("Unsupported hash type " + fld._2 + " in record hash!") - } - h - } - val newrec = fresh(rec.tp) // so that there are no effects - val func = uninlinedFunc1(newrec.asInstanceOf[Sym[Any]], reifyEffects({hash(newrec)(rec.tp);})) - doApply(func, rec.asInstanceOf[Sym[Any]]).asInstanceOf[Exp[A]] - } - case RecordEquals(r1,r2) => - sym.atPhase(LIRLowering) { - val rec1 = LIRLowering(r1) - val rec2 = LIRLowering(r2) - def equals[T:Manifest](lrec1: Exp[T], lrec2: Exp[T]): Exp[Boolean] = { - val fields = encounteredStructs(structName(manifest[T])) - var e = var_new[Boolean](unit(true)) - fields.foreach { fld => - if (fld._2.erasure.isPrimitive || fld._2 == manifest[java.lang.Character]) - e = e && __equal(field(lrec1, fld._1)(fld._2,implicitly[SourceContext]).asInstanceOf[Exp[A]], field(lrec2, fld._1)(fld._2,implicitly[SourceContext]).asInstanceOf[Exp[A]]) - else if (fld._2 == manifest[Array[Byte]]) { - val fldtype = { - val s = fresh(fld._2) - s.tp = fld._2 - remapManifest(s)(fld._2.asInstanceOf[Manifest[Any]]) - } - val a1 = field(lrec1, fld._1)(fld._2, implicitly[SourceContext]) - a1.tp = fldtype - val a2 = field(lrec2, fld._1)(fld._2, implicitly[SourceContext]) - a2.tp = fldtype - val arr2 = field[Array[Byte]](LIRLowering(a2),"array") - e = e && __equal(a1.asInstanceOf[Exp[A]], arr2.asInstanceOf[Exp[A]]) - } - else throw new Exception("Unsupported equals type " + fld._2 + " in record equals!") - } - e - } - val (newrec1,newrec2) = (fresh(rec1.tp), fresh(rec2.tp)) // so that there are no effects - val func = uninlinedFunc2(newrec1.asInstanceOf[Sym[Any]], newrec2.asInstanceOf[Sym[Any]], reifyEffects({equals(newrec1,newrec2)(rec1.tp);})).asInstanceOf[Exp[Function1[Tuple2[_,_],Boolean]]] - doApply(func, Const(scala.Tuple2(rec1.asInstanceOf[Sym[Any]], rec2.asInstanceOf[Sym[Any]]))).asInstanceOf[Exp[A]] - } - case RecordPrint(r) => - sym.atPhase(LIRLowering) { - val rec = LIRLowering(r) - def recordprint[T:Manifest](lrec: Exp[T]): Unit = { - val fields = encounteredStructs(structName(manifest[T])) - fields.foreach { fld => - val (fldname, fldtype) = (fld._1, fld._2) - val repfld = field(lrec, fldname)(fldtype,implicitly[SourceContext]) - if (fldtype <:< manifest[Record]) - recordprint(repfld)(fldtype.asInstanceOf[Manifest[Any]]) - else if (fldtype.erasure.getSimpleName == "LoweredArray") { - val arrayType = fldtype.typeArguments.head - val arrayElemType = arrayType.typeArguments.head - val array = field(repfld, "array")(arrayType, implicitly[SourceContext]) - if (arrayType == manifest[Array[Byte]]) - printf(remapToPrintFDescr(arrayType), array) - else { - val length = field[Long](repfld, "length") - for (i <- unit(0L) until length: Rep[LongRange]) - printf(remapToPrintFDescr(arrayElemType), array_apply(array.asInstanceOf[Exp[Array[Any]]],i)(arrayElemType.asInstanceOf[Manifest[Any]], implicitly[SourceContext])) - } - } - else printf(remapToPrintFDescr(fld._2), repfld) - } - } - val newrec = fresh(rec.tp) // so that there are no effects - val func = uninlinedFunc1(newrec.asInstanceOf[Sym[Any]], reifyEffects({recordprint(newrec)(rec.tp); printf("\n");})) - doApply(func, rec.asInstanceOf[Sym[Any]]).asInstanceOf[Exp[A]] - } - case _ => super.lowerNode(sym,rhs) - } - override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { case r@DefaultRecordDef() => def defaultValue[T: ClassManifest]: T = classManifest[T].erasure.toString match { diff --git a/src/common/While.scala b/src/common/While.scala index c34e5be4..af4e8488 100644 --- a/src/common/While.scala +++ b/src/common/While.scala @@ -194,24 +194,4 @@ trait CudaGenWhile extends CudaGenEffect with CLikeGenWhile trait OpenCLGenWhile extends OpenCLGenEffect with CLikeGenWhile -trait CGenWhile extends CGenEffect with CLikeGenWhile { - val IR: WhileExp - import IR._ - - override def lowerNode[T:Manifest](sym: Sym[T], rhs: Def[T]) = rhs match { - case While(cond,b) => { - LIRTraversal(cond) - LIRTraversal(b) - sym.atPhase(LIRLowering) { - val tc = LIRLowering(cond) - val ce = summarizeEffects(tc) - val tb = LIRLowering(b) - val ae = summarizeEffects(tb) - reflectEffect(While(tc, tb), ce andThen ((ae andThen ce).star)).asInstanceOf[Exp[T]] - } - } - case DoWhile(b,c) => - sym.atPhase(LIRLowering) { reflectEffect(DoWhile(runTransformations(b),c)).asInstanceOf[Exp[T]] } - case _ => super.lowerNode(sym, rhs) - } -} +trait CGenWhile extends CGenEffect with CLikeGenWhile