Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package reproduction
- import scala.reflect.Manifest
- import scala.lms.common._
- trait Reproducing
- extends BooleanOps with OrderingOps with PrimitiveOps with ArrayOps with StringOps with NumericOps with TupleOps with StructOps
- with Equal with Variables with While with IfThenElse with TupledFunctions
- with LiftVariables with LiftBoolean with LiftPrimitives with LiftString {
- trait Gen[S] {
- def k1(k : S => Rep[Int]): Rep[Int]
- def k2(s : S, k: (Rep[Int] => Rep[Int])) : Rep[Int]
- }
- sealed trait HidesS
- case class G[S](gen : Gen[S]) extends HidesS
- /*
- Box[Int](x).start() where x is some integer compiles down to the following:
- class reproducingTest extends ((Int)=>(Int)) {
- def apply(x0:Int): Int = {
- var x1: Int = 0
- var x2: Int = 0 // why is this declared outside the loop? assuming this is the i.
- val x10 = while ({val x3 = x2
- val x4 = x3 < 10
- x4}) {
- var x6: Int = 0
- x6 = 1
- x2 = 1 // x2 doesn't seem to be updated
- ()
- }
- 5
- }
- }
- */
- class Box(hidden_s : HidesS) {
- def start() : Rep[Int] = {
- val G(gen) = hidden_s
- gen.k1(s => {
- var counter = 0
- while (counter < 10){
- gen.k2(s, (a : Rep[Int]) => {
- counter = a // counter is updated by index conceptually
- counter
- })
- ()
- }
- 4
- })
- 5
- }
- }
- object Box {
- def apply(element : Rep[Int]) : Box = {
- class GenImpl extends Gen[Rep[Int]] {
- def k1(k : Rep[Int] => Rep[Int]) : Rep[Int] = {
- var i = 0 // creates state
- k(i)
- }
- def k2(s : Rep[Int], k : (Rep[Int] => Rep[Int])) : Rep[Int] = {
- var index = s
- index = index + 1 // updates state
- k(index)
- }
- }
- new Box(G(new GenImpl))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement