I am looking at Scala Compiler Options. This doc explains all the compiler options in detail. But, this doc doesn't seem to be targeted for a specific scala version.
Does it mean it all the options are supported/recommended for all versions ?
Is there any official documentation which defines these compiler options with respect to a particular scala version ?
Would be really helpful to know the correct references to use for selecting these compiler options.
Print standard options
scalac -help
Print advanced options
scalac -X
Print private options
scalac -Y
Related
Just verified that javac compiles every reference or import that it sees, such as JavaDoc #link references.
Can this be turned off with an argument?
And/or, can a less eager compile be implemented using the javax compiler API?
(I could blank out those references before feeding the source into the compiler, I guess, but I hope there are simpler ways.)
ecj lets you choose whether or not javadoc tags should be analysed, the option is -enableJavadoc.
I don't know whether javac has a similar option.
In Python we can do
help(function)
or
help(class)
to find the documentation of a particular function or class
How can we do that in Scala from the scala interpreter ?
I think it is not yet implemented.
You can read here https://contributors.scala-lang.org/t/documentation-in-scala-shell/1652/4
I want to see the control flow graph generated by the Scala compiler. Is there a way to do so? I tried searching online but only found Eclipse plugins for Java like the one from here www.drgarbage.com but none for Scala.
Thanks
EDIT: I took the .class file generated by scalac and opened that with the dr garbage plug in to see the bytecode visualized as a control flow graph. But scalac makes 3 different .class files: Foo, Foo$, and Foo$delayedInit$body. I see a bunch of disconnected graphs and only one of the graphs in Foo$ looks reasonable. I tried searching online for the difference between the 3 .class files but couldn't find anything.
I didn't realize that the IR (intermediate representation) for scala in the backend was actually called icode. The option in the compiler -Xprint-icode actually shows the IR separated into basic blocks. This was what I was looking for.
A compiler plugin can do just that. However, it requires abstracting away some internals introduced by the compiler - which are more specific than what you'd expect from how a project's source code looks. You can use this plugin to get the raw information extracted for you, whereas the re-abstraction from the raw data is still work-in-progress, and you'd have to sbt publishLocal before you can include this plugin in your sbt definition.
I wanted to check some examples with annotations in macro paradise and I am getting the error, as is specified in: this example
I have related the projects, the other scala macros (not with annotations) are working very well. I have included the library paradise_2.11.6-2.1.0-M5 (in both projects also :( ). I think, I do not get what means with *to enable*. !? bthw, I am using Scala IDE in Eclipse.
By enable, I meant adding it as a compiler plugin, as e.g. in https://github.com/scalamacros/sbt-example-paradise/blob/17f4a0d421ad7002334c7081d3ec79cc9edb4f24/project/Build.scala#L14
The scala.tools.nsc API has been completely changed from 2.10 to 2.11. For example, there's no Interpreter anymore.
I'm trying to build a site similar to http://codingbat.com in Scala, so I need the ability to compile and run code that's provided by a user while my program is running.
Does anyone know of something that explains how to use the new API anywhere? (I didn't have any luck Googling what I thought were reasonable search terms.) If not, could someone who knows something about the new API provide a small working example that lets you compile code and then retrieve the result of running it?
UPDATE 2.11.0-M5 seems to break Script Engine support, but I went back to 2.11.0-M4 and I'm able to use ScriptEngineManager to get an interpreter. The weird thing is, the type is scala.tools.nsc.interpreter.IMain. That package and class don't appear in the 2.11.0-M4 Scaladocs, so I'm wondering if they've moved out of the compiler artifact somewhere else, or if there's just an oversight in Scaladoc production and they should still be there.
Scala 2.11.0-M4 now has JSR 223 scripting support which, I think, might supersede some of the functionality you are looking for. See docs.scala-lang.org/scala/2.11
The feature is broken in scala 2.11.0-M5 but apparently fixed in 2.11.0-M6 and 2.11.0-M4
Welcome to Scala version 2.11.0-M4 (OpenJDK Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import javax.script.ScriptEngineManager
import javax.script.ScriptEngineManager
scala> val e = new ScriptEngineManager().getEngineByName("scala")
e: javax.script.ScriptEngine = scala.tools.nsc.interpreter.IMain#1741b6d
See the ScriptEngine Javadoc and the javax.script package summary