Compile the file at runtime #12854
Unanswered
mbore
asked this question in
Compiler internals Q&A
Replies: 1 comment 4 replies
-
Compiling a new source file at runtime is not in the scope of the metaprogramming API as it cannot be type-checked att compile-time by the nature of the problem.
The way to compile a source file is by using the compiler directly. This could compile code that contains |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'd like to test, whether a source code passed as a string at runtime is a valid scala program.
My first attempt was to parse the input
String
to anExpr[]
and then execute it withstaging.run
, but I haven't found any exposed parser API to transform aString
into anExpr[]
, did I missed something?My second attempt was to use
scala.compiletime.testing.typeChecks
inside a block passed toscala.quoted.staging.withQuotes
, buttypeChecks
requires a statically knownString
so it also doesn't work for me. Is it possible to workaround it with the multi-stage programming?The current approach is based on the Vulpix Framework and uses
dotty.tools.dotc.Driver
to compile source files (e.g. https://github.com/softwaremill/macwire/blob/300e109f2df670a8ec3178a83af73a50ea983f01/test-util/src/main/scala-3/com/softwaremill/macwire/CompileTestsSupport.scala#L92), but it seems that the Vulpix would fulfil my use case, have you considered publishing Vulpix as a separate library?Or maybe I missed something and there is another way to compile a file at runtime?
Beta Was this translation helpful? Give feedback.
All reactions