@@ -33,6 +33,7 @@ withCompiler=true
3333CompilerMain=dotty.tools.dotc.Main
3434DecompilerMain=dotty.tools.dotc.decompiler.Main
3535ReplMain=dotty.tools.repl.Main
36+ ScriptingMain=dotty.tools.scripting.Main
3637
3738PROG_NAME=$CompilerMain
3839
@@ -45,6 +46,9 @@ addScala () {
4546addResidual () {
4647 residual_args+=(" '$1 '" )
4748}
49+ addScripting () {
50+ scripting_args+=(" '$1 '" )
51+ }
4852
4953classpathArgs () {
5054 # echo "dotty-compiler: $DOTTY_COMP"
@@ -74,6 +78,7 @@ classpathArgs () {
7478 jvm_cp_args=" -classpath \" $toolchain \" "
7579}
7680
81+ in_scripting_args=false
7782while [[ $# -gt 0 ]]; do
7883case " $1 " in
7984 --) shift ; for arg; do addResidual " $arg " ; done ; set -- ;;
@@ -85,6 +90,7 @@ case "$1" in
8590 # Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222
8691 -Oshort) addJava " -XX:+TieredCompilation -XX:TieredStopAtLevel=1" && shift ;;
8792 -repl) PROG_NAME=" $ReplMain " && shift ;;
93+ -script) PROG_NAME=" $ScriptingMain " && target_script=" $2 " && in_scripting_args=true && shift && shift ;;
8894 -compile) PROG_NAME=" $CompilerMain " && shift ;;
8995 -decompile) PROG_NAME=" $DecompilerMain " && shift ;;
9096 -print-tasty) PROG_NAME=" $DecompilerMain " && addScala " -print-tasty" && shift ;;
@@ -98,12 +104,22 @@ case "$1" in
98104 # will be available as system properties.
99105 -D* ) addJava " $1 " && shift ;;
100106 -J* ) addJava " ${1: 2} " && shift ;;
101- * ) addResidual " $1 " && shift ;;
107+ * ) if [ $in_scripting_args == false ]; then
108+ addResidual " $1 "
109+ else
110+ addScripting " $1 "
111+ fi
112+ shift
113+ ;;
102114 esac
103115done
104116
105117classpathArgs
106118
119+ if [ " $PROG_NAME " == " $ScriptingMain " ]; then
120+ scripting_string=" -script $target_script ${scripting_args[@]} "
121+ fi
122+
107123eval exec " \" $JAVACMD \" " \
108124 ${JAVA_OPTS:- $default_java_opts } \
109125 " $DEBUG " \
@@ -112,5 +128,6 @@ eval exec "\"$JAVACMD\"" \
112128 -Dscala.usejavacp=true \
113129 " $PROG_NAME " \
114130 " ${scala_args[@]} " \
115- " ${residual_args[@]} "
131+ " ${residual_args[@]} " \
132+ " $scripting_string "
116133exit $?
0 commit comments