Scalaxy/Reify provides a powerful reified values mechanism that deals well with composition and captures of runtime values, allowing for complex ASTs to be generated during runtime for re-compilation or transformation purposes.
It preserves the original value that was reified, allowing for flexible mixed usage of runtime value and compile-time AST.
import scalaxy.reified._
def comp(capture1: Int): ReifiedFunction1[Int, Int] = {
val capture2 = Seq(10, 20, 30)
val f = reified((x: Int) => capture1 + capture2(x))
val g = reified((x: Int) => x * x)
g.compose(f)
}
val f = comp(10)
// Normal evaluation, using regular function:
println(f(1))
// Get the function's AST, inlining all captured values and captured reified values:
println(f.expr.tree)
// Compile the AST at runtime (needs scala-compiler.jar in the classpath):val compiledF = f.compile()()
// Evaluation, using the freshly-compiled function:
println(compiledF(1))
Scalaxy/Reify provides a powerful reified values mechanism that deals well with composition and captures of runtime values, allowing for complex ASTs to be generated during runtime for re-compilation or transformation purposes.
It preserves the original value that was reified, allowing for flexible mixed usage of runtime value and compile-time AST.
Please look at documentation of scalaxy.reified.reified and scalaxy.reified.Reified first.