Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.31 KB | None | 0 0
  1.  case S.Prim(prim: L3TestPrimitive, args) => {
  2.         implicit val p = UnknownPosition
  3.         val ifTree = S.If(tree, S.Lit(BooleanLit(true)), S.Lit(BooleanLit(false)))
  4.         transform(ifTree)(ctx)
  5.       }
  6.  
  7.       case S.Prim(prim: L3ValuePrimitive, args) => args match {
  8.         case Seq() => {
  9.           val n = Symbol.fresh("n")
  10.           C.LetP(n, prim, Seq[Symbol](), ctx(n))
  11.         }
  12.        
  13.         case Seq(head, tail @ _*) => {
  14.           //Creating the helper function
  15.           def nCtx(s: Seq[S.Tree], symbols: Seq[Symbol]):(Symbol => C.Tree) = {
  16.             //This function handles giving the variables
  17.             //new names to be used by the LetP algorithm
  18.             def f(v: Symbol):C.Tree = s match {
  19.               //If the sequence is empty then we have exhausted
  20.               //all of the expressions in the primitive
  21.               case Seq() => {
  22.                 val syms = symbols :+ v
  23.                 val n = Symbol.fresh("n")
  24.                 C.LetP(n, prim, syms, ctx(n))
  25.               }
  26.               case Seq(head, tail @ _*) => {
  27.                 val syms = symbols :+ v
  28.                 transform(head)(nCtx(tail, syms))
  29.               }
  30.             }
  31.             f
  32.           }
  33.           var f2 = nCtx(tail, Seq[Symbol]())
  34.           transform(head)(f2)
  35.         }
  36.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement