File tree 1 file changed +14
-3
lines changed
docs/docs/reference/metaprogramming
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,16 @@ def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = ..
71
71
def withQuoteContext [T ](thunk : given QuoteContext => T ) given (toolbox : Toolbox ): T = ...
72
72
```
73
73
74
+ ## Create a new Dotty project with staging enabled
75
+
76
+ ``` shell
77
+ sbt new lampepfl/dotty-staging.g8
78
+ ```
79
+
80
+ From [ lampepfl/dotty-staging.g8] ( https://github.com/lampepfl/dotty-staging.g8 ) .
81
+
82
+ It will create a project with the necessary dependencies and some examples.
83
+
74
84
## Example
75
85
76
86
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.
84
94
import scala .quoted .staging ._
85
95
86
96
// make available the necessary toolbox for runtime code generation
87
- delegate for Toolbox = Toolbox .make(getClass.getClassLoader)
97
+ given as Toolbox = Toolbox .make(getClass.getClassLoader)
88
98
89
99
val f : Array [Int ] => Int = run {
90
100
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
99
109
compilation we need make available the compiler to the runtime:
100
110
101
111
``` shell
102
- sbt:dotty> dotr -classpath out -with-compiler Test
112
+ dotc -with-compiler -d out Test.scala
113
+ dotr -with-compiler -classpath out Test
103
114
```
104
115
105
116
Or, from SBT:
106
117
107
118
``` scala
108
- libraryDependencies += " ch.epfl.lamp" %% " dotty-compiler " % scalaVersion.value
119
+ libraryDependencies += " ch.epfl.lamp" %% " dotty-staging " % scalaVersion.value
109
120
```
You can’t perform that action at this time.
0 commit comments