Skip to content

Commit 9726632

Browse files
author
Olivier Chafik
committed
Reified: more javadoc
1 parent 18f1069 commit 9726632

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

Reified/Doc/src/main/rootdoc.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
Scalaxy/Reify provides a reify method that goes beyond the stock Universe.reify method, by taking care of captured values and allowing composition of reified functions for improved flexibility of dynamic usage of ASTs. The original expression is also available at runtime, without having to compile it with ToolBox.eval.
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.
2+
3+
It preserves the original value that was reified, allowing for flexible mixed usage of runtime value and compile-time AST.
4+
5+
Please look at documentation of [[scalaxy.reified.reify]] and [[scalaxy.reified.ReifiedValue]] first.
6+
7+
{{{
8+
import scalaxy.reified._
9+
10+
def comp(capture1: Int): ReifiedFunction1[Int, Int] = {
11+
val capture2 = Seq(10, 20, 30)
12+
val f = reify((x: Int) => capture1 + capture2(x))
13+
val g = reify((x: Int) => x * x)
14+
15+
g.compose(f)
16+
}
17+
18+
val f = comp(10)
19+
// Normal evaluation, using regular function:
20+
println(f(1))
21+
22+
// Get the function's AST, inlining all captured values and captured reified values:
23+
val ast = f.expr().tree
24+
println(ast)
25+
26+
// Compile the AST at runtime (needs scala-compiler.jar in the classpath).
27+
// This is an optimized compilation by default, soon with extra optimizing AST transforms taken from Scalaxy.
28+
val compiledF = ast.compile()()
29+
// Evaluation, using the freshly-compiled function:
30+
println(compiledF(1))
31+
}}}

Reified/src/main/scala/scalaxy/reified/package.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ package object reified {
8787
}
8888
*/
8989

90+
/**
91+
* Creates a tupled version of this reified function: instead of 2 arguments, it accepts a
92+
* single `scala.Tuple2` argument.
93+
*/
9094
def tupled: ReifiedFunction1[(T1, T2), R] = {
9195
val f = this
9296
internal.reifyMacro((p: (T1, T2)) => {

0 commit comments

Comments
 (0)