diff --git a/docs/docs/reference/metaprogramming/staging.md b/docs/docs/reference/metaprogramming/staging.md index 24fd723498e9..27f04cd1fbf9 100644 --- a/docs/docs/reference/metaprogramming/staging.md +++ b/docs/docs/reference/metaprogramming/staging.md @@ -71,6 +71,16 @@ def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = .. def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = ... ``` +## Create a new Dotty project with staging enabled + +```shell +sbt new lampepfl/dotty-staging.g8 +``` + +From [lampepfl/dotty-staging.g8](https://github.com/lampepfl/dotty-staging.g8). + +It will create a project with the necessary dependencies and some examples. + ## Example Now take exactly the same example as in [Macros](./macros.md). Assume that we @@ -84,7 +94,7 @@ to get a source-like representation of the expression. import scala.quoted.staging._ // make available the necessary toolbox for runtime code generation -delegate for Toolbox = Toolbox.make(getClass.getClassLoader) +given as Toolbox = Toolbox.make(getClass.getClassLoader) val f: Array[Int] => Int = run { val stagedSum: Expr[Array[Int] => Int] = '{ (arr: Array[Int]) => ${sum('arr)}} @@ -99,11 +109,12 @@ Note that if we need to run the main (in an object called `Test`) after compilation we need make available the compiler to the runtime: ```shell -sbt:dotty> dotr -classpath out -with-compiler Test +dotc -with-compiler -d out Test.scala +dotr -with-compiler -classpath out Test ``` Or, from SBT: ```scala -libraryDependencies += "ch.epfl.lamp" %% "dotty-compiler" % scalaVersion.value +libraryDependencies += "ch.epfl.lamp" %% "dotty-staging" % scalaVersion.value ```