From 1b68ef970c8728a871e8f0ee586a0200602146e1 Mon Sep 17 00:00:00 2001 From: Lex Spoon Date: Thu, 15 Jun 2006 14:54:14 +0000 Subject: --- .../scala/tools/nsc/MainGenericRunner.scala | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/compiler/scala/tools/nsc/MainGenericRunner.scala (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala new file mode 100644 index 0000000000..2df23c2539 --- /dev/null +++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala @@ -0,0 +1,64 @@ +package scala.tools.nsc +import java.io.File + +/* NSC -- new scala compiler + * Copyright 2006 LAMP/EPFL + * @author Lex Spoon + */ +// $Id$ + +/** An object that runs Scala code. It has three possible + * sources for the code to run: pre-compiled code, a script file, + * or interactive entry. + */ +object MainGenericRunner { + def main(args: Array[String]): Unit = { + def error(str: String) = Console.println(str) + val command = new GenericRunnerCommand(args.toList, error) + if(!command.ok) { + Console.println(command.usageMessage) + return () + } + + val settings = command.settings + + if(settings.help.value) { + Console.println(command.usageMessage) + return () + } + + if(settings.version.value) { + val version = + System.getProperty("scala.tool.version", "unknown version") + Console.println("scala version " + version) + Console.println("(c) 2002-2006 LAMP/EPFL") + return () + } + + command.thingToRun match { + case None => { + (new InterpreterLoop).main(settings) + } + case Some(thingToRun) => { + val isObjectName = + settings.howtorun.value match { + case "guess" => !(new File(thingToRun)).exists + case "object" => true + case "script" => false + } + + if(isObjectName) { + def paths(str: String) = str.split(File.pathSeparator).toList + + val classpath = + paths(settings.bootclasspath.value) ::: + paths(settings.classpath.value) + + ObjectRunner.run(classpath, thingToRun, command.arguments) + } else { + MainScript.runScript(settings, thingToRun, command.arguments) + } + } + } + } +} -- cgit v1.2.3