Skip to content

Scripting solution #10491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 11, 2020
Merged

Scripting solution #10491

merged 8 commits into from
Dec 11, 2020

Conversation

anatoliykmetyuk
Copy link
Contributor

@anatoliykmetyuk anatoliykmetyuk commented Nov 25, 2020

This PR adds scripting support to Scala 3. Given a source named Test.scala:

@main def Test(name: String): Unit =
  println(s"Hello ${name}!")

You can run: ./bin/scala ../playground/foo/Test.scala World to get an output Hello World.

Internally, scala detects the first residual argument which ends with *.scala. It then assumes it to be a file that the user wants to run as a script, and all the arguments after that file are treated as the arguments to that script.

A "script" is an ordinary Scala file which contains a @main method. The semantics of the scala Script.scala command are as follows:

  • Compile Script.scala with scalac into a temporary directory
  • Detect the main method in the *.class files produced by the compilation
  • Execute the main method reflectively

@anatoliykmetyuk anatoliykmetyuk changed the title Scripting Scripting solution Nov 25, 2020
@anatoliykmetyuk anatoliykmetyuk self-assigned this Nov 25, 2020
@anatoliykmetyuk anatoliykmetyuk added this to the 3.0.0-RC1 milestone Nov 25, 2020
@anatoliykmetyuk anatoliykmetyuk linked an issue Dec 7, 2020 that may be closed by this pull request
@anatoliykmetyuk anatoliykmetyuk force-pushed the scripting branch 3 times, most recently from 0d6ba8c to d713412 Compare December 9, 2020 14:01
@anatoliykmetyuk anatoliykmetyuk marked this pull request as ready for review December 9, 2020 14:02
@anatoliykmetyuk anatoliykmetyuk force-pushed the scripting branch 3 times, most recently from d600d2f to 17e8f4a Compare December 10, 2020 13:09
@nicolasstucki
Copy link
Contributor

We are also missing some docs.

@anatoliykmetyuk anatoliykmetyuk force-pushed the scripting branch 2 times, most recently from c03e824 to 8d68bc0 Compare December 11, 2020 14:36
@anatoliykmetyuk anatoliykmetyuk merged commit 67625b0 into scala:master Dec 11, 2020
@anatoliykmetyuk anatoliykmetyuk deleted the scripting branch December 11, 2020 18:43
@philwalk
Copy link
Contributor

I have used scala for several years, and make heavy use of scala scripting. I am eager to contribute to this and have some ideas to greatly improve the user experience for new users.

@som-snytt
Copy link
Contributor

This will make it much easier to run quick test comparisons between Scala 2 and 3!

@rjolly
Copy link
Contributor

rjolly commented Dec 16, 2020

I have a dream that scala is just a shorthand for

jrunscript -cp lib/scala3-compiler_3.0.0-M3.jar:lib/scala3-library_3.0.0-M3.jar:lib/scala3-interfaces-3.0.0-M3.jar:lib/tasty-core_3.0.0-M3.jar:lib/scala-library-2.13.4.jar:lib/scala-asm-7.3.1-scala-1.jar -Djava.class.path=lib/scala3-library_3.0.0-M3.jar:lib/scala-library-2.13.4.jar -l scala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotr should exec scripts
6 participants