Virtual Trading v2.0.95版本的 MD5 值为:ef0f95d706f7364286da0edbbd29a27d
以下内容为反编译后的 repl.java 源代码,内容仅作参考
package kawa;
import androidx.constraintlayout.core.motion.utils.TypedValues;
import gnu.bytecode.ClassType;
import gnu.expr.ApplicationMainSupport;
import gnu.expr.Compilation;
import gnu.expr.Language;
import gnu.expr.ModuleBody;
import gnu.expr.ModuleExp;
import gnu.expr.ModuleInfo;
import gnu.expr.ModuleManager;
import gnu.kawa.servlet.HttpRequestContext;
import gnu.lists.FString;
import gnu.mapping.CharArrayInPort;
import gnu.mapping.Environment;
import gnu.mapping.InPort;
import gnu.mapping.OutPort;
import gnu.mapping.Procedure0or1;
import gnu.mapping.Values;
import gnu.text.Options;
import gnu.text.SourceMessages;
import gnu.text.SyntaxException;
import gnu.text.WriterManager;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Vector;
public class repl extends Procedure0or1 {
public static String compilationTopname = null;
static int defaultParseOptions = 72;
public static String homeDirectory;
public static boolean noConsole;
static Language previousLanguage;
static boolean shutdownRegistered = WriterManager.instance.registerShutdownHook();
Language language;
public repl(Language language) {
this.language = language;
}
@Override
public Object apply0() {
Shell.run(this.language, Environment.getCurrent());
return Values.empty;
}
@Override
public Object apply1(Object obj) {
Shell.run(this.language, (Environment) obj);
return Values.empty;
}
static void bad_option(String str) {
System.err.println("kawa: bad option '" + str + "'");
printOptions(System.err);
System.exit(-1);
}
public static void printOption(PrintStream printStream, String str, String str2) {
printStream.print(" ");
printStream.print(str);
int length = str.length() + 1;
for (int i = 0; i < 30 - length; i++) {
printStream.print(" ");
}
printStream.print(" ");
printStream.println(str2);
}
public static void printOptions(PrintStream printStream) {
printStream.println("Usage: [java kawa.repl | kawa] [options ...]");
printStream.println();
printStream.println(" Generic options:");
printOption(printStream, "--help", "Show help about options");
printOption(printStream, "--author", "Show author information");
printOption(printStream, "--version", "Show version information");
printStream.println();
printStream.println(" Options");
printOption(printStream, "-e <expr>", "Evaluate expression <expr>");
printOption(printStream, "-c <expr>", "Same as -e, but make sure ~/.kawarc.scm is run first");
printOption(printStream, "-f <filename>", "File to interpret");
printOption(printStream, "-s| --", "Start reading commands interactively from console");
printOption(printStream, "-w", "Launch the interpreter in a GUI window");
printOption(printStream, "--server <port>", "Start a server accepting telnet connections on <port>");
printOption(printStream, "--debug-dump-zip", "Compiled interactive expressions to a zip archive");
printOption(printStream, "--debug-print-expr", "Print generated internal expressions");
printOption(printStream, "--debug-print-final-expr", "Print expression after any optimizations");
printOption(printStream, "--debug-error-prints-stack-trace", "Print stack trace with errors");
printOption(printStream, "--debug-warning-prints-stack-trace", "Print stack trace with warnings");
printOption(printStream, "--[no-]full-tailcalls", "(Don't) use full tail-calls");
printOption(printStream, "-C <filename> ...", "Compile named files to Java class files");
printOption(printStream, "--output-format <format>", "Use <format> when printing top-level output");
printOption(printStream, "--<language>", "Select source language, one of:");
String[][] languages = Language.getLanguages();
for (int i = 0; i < languages.length; i++) {
printStream.print(" ");
String[] strArr = languages[i];
int length = strArr.length - 1;
for (int i2 = 0; i2 < length; i2++) {
printStream.print(strArr[i2] + " ");
}
if (i == 0) {
printStream.print("[default]");
}
printStream.println();
}
printStream.println(" Compilation options, must be specified before -C");
printOption(printStream, "-d <dirname>", "Directory to place .class files in");
printOption(printStream, "-P <prefix>", "Prefix to prepand to class names");
printOption(printStream, "-T <topname>", "name to give to top-level class");
printOption(printStream, "--main", "Generate an application, with a main method");
printOption(printStream, "--applet", "Generate an applet");
printOption(printStream, "--servlet", "Generate a servlet");
printOption(printStream, "--module-static", "Top-level definitions are by default static");
ArrayList<String> keys = Compilation.options.keys();
for (int i3 = 0; i3 < keys.size(); i3++) {
String str = keys.get(i3);
printOption(printStream, "--" + str, Compilation.options.getDoc(str));
}
printStream.println();
printStream.println("For more information go to: http://www.gnu.org/software/kawa/");
}
public static void checkInitFile() {
File file;
Object obj;
if (homeDirectory == null) {
String property = System.getProperty("user.home");
homeDirectory = property;
if (property != null) {
obj = new FString(homeDirectory);
file = new File(homeDirectory, "/".equals(System.getProperty("file.separator")) ? ".kawarc.scm" : "kawarc.scm");
} else {
file = null;
obj = Boolean.FALSE;
}
Environment.getCurrent().put("home-directory", obj);
if (file == null || !file.exists() || Shell.runFileOrClass(file.getPath(), true, 0)) {
return;
}
System.exit(-1);
}
}
public static void setArgs(String[] strArr, int i) {
ApplicationMainSupport.setArgs(strArr, i);
}
public static void getLanguageFromFilenameExtension(String str) {
if (previousLanguage == null) {
Language instanceFromFilenameExtension = Language.getInstanceFromFilenameExtension(str);
previousLanguage = instanceFromFilenameExtension;
if (instanceFromFilenameExtension != null) {
Language.setDefaults(instanceFromFilenameExtension);
return;
}
}
getLanguage();
}
public static void getLanguage() {
if (previousLanguage == null) {
Language language = Language.getInstance(null);
previousLanguage = language;
Language.setDefaults(language);
}
}
public static int processArgs(String[] strArr, int i, int i2) {
int i3;
String str;
int i4 = 0;
int i5 = i;
boolean z = false;
while (true) {
int i6 = -1;
if (i5 >= i2) {
break;
}
String str2 = strArr[i5];
if (str2.equals("-c") || str2.equals("-e")) {
i5++;
if (i5 == i2) {
bad_option(str2);
}
getLanguage();
setArgs(strArr, i5 + 1);
if (str2.equals("-c")) {
checkInitFile();
}
Language defaultLanguage = Language.getDefaultLanguage();
SourceMessages sourceMessages = new SourceMessages();
Throwable run = Shell.run(defaultLanguage, Environment.getCurrent(), new CharArrayInPort(strArr[i5]), OutPort.outDefault(), (OutPort) null, sourceMessages);
if (run != null) {
Shell.printError(run, sourceMessages, OutPort.errDefault());
System.exit(-1);
}
} else if (str2.equals("-f")) {
i5++;
if (i5 == i2) {
bad_option(str2);
}
String str3 = strArr[i5];
getLanguageFromFilenameExtension(str3);
setArgs(strArr, i5 + 1);
checkInitFile();
if (!Shell.runFileOrClass(str3, true, i4)) {
System.exit(-1);
}
} else {
if (str2.startsWith("--script")) {
String substring = str2.substring(8);
int i7 = i5 + 1;
if (substring.length() > 0) {
try {
i4 = Integer.parseInt(substring);
} catch (Throwable unused) {
i7 = i2;
}
}
if (i7 == i2) {
bad_option(str2);
}
String str4 = strArr[i7];
getLanguageFromFilenameExtension(str4);
setArgs(strArr, i7 + 1);
checkInitFile();
if (!Shell.runFileOrClass(str4, true, i4)) {
System.exit(-1);
}
return -1;
}
if (str2.equals("\\")) {
int i8 = i5 + 1;
if (i8 == i2) {
bad_option(str2);
}
String str5 = strArr[i8];
SourceMessages sourceMessages2 = new SourceMessages();
try {
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(str5));
int read = bufferedInputStream.read();
if (read == 35) {
StringBuffer stringBuffer = new StringBuffer(100);
Vector vector = new Vector(10);
while (read != 10 && read != 13 && read >= 0) {
read = bufferedInputStream.read();
}
int i9 = 0;
while (true) {
int read2 = bufferedInputStream.read();
if (read2 < 0) {
System.err.println("unexpected end-of-file processing argument line for: '" + str5 + '\'');
System.exit(-1);
}
if (i9 == 0) {
if (read2 != 92 && read2 != 39 && read2 != 34) {
if (read2 == 10 || read2 == 13) {
break;
}
if (read2 == 32 || read2 == 9) {
if (stringBuffer.length() > 0) {
vector.addElement(stringBuffer.toString());
stringBuffer.setLength(0);
}
}
}
i9 = read2;
} else if (i9 == 92) {
i9 = 0;
} else if (read2 == i9) {
i9 = 0;
}
stringBuffer.append((char) read2);
}
if (stringBuffer.length() > 0) {
vector.addElement(stringBuffer.toString());
}
int size = vector.size();
if (size > 0) {
String[] strArr2 = new String[size];
vector.copyInto(strArr2);
int processArgs = processArgs(strArr2, 0, size);
if (processArgs >= 0 && processArgs < size) {
System.err.println("" + (size - processArgs) + " unused meta args");
}
}
}
getLanguageFromFilenameExtension(str5);
InPort openFile = InPort.openFile(bufferedInputStream, str5);
setArgs(strArr, i8 + 1);
checkInitFile();
OutPort errDefault = OutPort.errDefault();
Throwable run2 = Shell.run(Language.getDefaultLanguage(), Environment.getCurrent(), openFile, OutPort.outDefault(), (OutPort) null, sourceMessages2);
sourceMessages2.printAll(errDefault, 20);
if (run2 != null) {
if (run2 instanceof SyntaxException) {
if (((SyntaxException) run2).getMessages() == sourceMessages2) {
System.exit(1);
throw run2;
}
throw run2;
}
throw run2;
}
} catch (Throwable th) {
Shell.printError(th, sourceMessages2, OutPort.errDefault());
System.exit(1);
}
return -1;
}
if (str2.equals("-s") || str2.equals("--")) {
break;
}
if (str2.equals("-w")) {
i5++;
getLanguage();
setArgs(strArr, i5);
checkInitFile();
startGuiConsole();
} else {
if (str2.equals("-d")) {
i5++;
if (i5 == i2) {
bad_option(str2);
}
ModuleManager.getInstance().setCompilationDirectory(strArr[i5]);
} else {
if (str2.equals("--target") || str2.equals(TypedValues.AttributesType.S_TARGET)) {
i4 = 0;
i5++;
if (i5 == i2) {
bad_option(str2);
}
String str6 = strArr[i5];
if (str6.equals("7")) {
Compilation.defaultClassFileVersion = ClassType.JDK_1_7_VERSION;
}
if (str6.equals("6") || str6.equals("1.6")) {
Compilation.defaultClassFileVersion = ClassType.JDK_1_6_VERSION;
} else if (str6.equals("5") || str6.equals("1.5")) {
Compilation.defaultClassFileVersion = ClassType.JDK_1_5_VERSION;
} else if (str6.equals("1.4")) {
Compilation.defaultClassFileVersion = ClassType.JDK_1_4_VERSION;
} else if (str6.equals("1.3")) {
Compilation.defaultClassFileVersion = ClassType.JDK_1_3_VERSION;
} else if (str6.equals("1.2")) {
Compilation.defaultClassFileVersion = ClassType.JDK_1_2_VERSION;
} else if (str6.equals("1.1")) {
Compilation.defaultClassFileVersion = ClassType.JDK_1_1_VERSION;
} else {
bad_option(str6);
}
} else if (str2.equals("-P")) {
i5++;
if (i5 == i2) {
bad_option(str2);
}
Compilation.classPrefixDefault = strArr[i5];
} else if (str2.equals("-T")) {
i5++;
if (i5 == i2) {
bad_option(str2);
}
compilationTopname = strArr[i5];
} else {
if (str2.equals("-C")) {
int i10 = i5 + 1;
if (i10 == i2) {
bad_option(str2);
}
compileFiles(strArr, i10, i2);
return -1;
}
if (str2.equals("--output-format") || str2.equals("--format")) {
i4 = 0;
i5++;
if (i5 == i2) {
bad_option(str2);
}
Shell.setDefaultFormat(strArr[i5]);
} else {
String str7 = null;
if (str2.equals("--connect")) {
i5++;
if (i5 == i2) {
bad_option(str2);
}
if (strArr[i5].equals("-")) {
i6 = 0;
} else {
try {
i6 = Integer.parseInt(strArr[i5]);
} catch (NumberFormatException unused2) {
bad_option("--connect port#");
}
}
try {
Telnet telnet = new Telnet(new Socket(InetAddress.getByName(null), i6), true);
TelnetInputStream inputStream = telnet.getInputStream();
PrintStream printStream = new PrintStream((OutputStream) telnet.getOutputStream(), true);
System.setIn(inputStream);
System.setOut(printStream);
System.setErr(printStream);
} catch (IOException e) {
e.printStackTrace(System.err);
throw new Error(e.toString());
}
} else {
if (str2.equals("--server")) {
break;
}
if (str2.equals("--http-auto-handler")) {
i5 += 2;
if (i5 >= i2) {
bad_option(str2);
}
System.err.println("kawa: HttpServer classes not found");
System.exit(-1);
} else if (str2.equals("--http-start")) {
i5++;
if (i5 >= i2) {
bad_option("missing httpd port argument");
}
System.err.println("kawa: HttpServer classes not found");
System.exit(-1);
} else if (str2.equals("--main")) {
Compilation.generateMainDefault = true;
} else if (str2.equals("--applet")) {
defaultParseOptions |= 16;
} else {
if (str2.equals("--servlet")) {
defaultParseOptions |= 32;
HttpRequestContext.importServletDefinitions = 2;
} else if (str2.equals("--debug-dump-zip")) {
ModuleExp.dumpZipPrefix = "kawa-zip-dump-";
} else if (str2.equals("--debug-print-expr")) {
Compilation.debugPrintExpr = true;
} else if (str2.equals("--debug-print-final-expr")) {
Compilation.debugPrintFinalExpr = true;
} else if (str2.equals("--debug-error-prints-stack-trace")) {
SourceMessages.debugStackTraceOnError = true;
} else if (str2.equals("--debug-warning-prints-stack-trace")) {
SourceMessages.debugStackTraceOnWarning = true;
} else if (str2.equals("--module-nonstatic") || str2.equals("--no-module-static")) {
i4 = 0;
Compilation.moduleStatic = -1;
} else if (str2.equals("--module-static")) {
Compilation.moduleStatic = 1;
} else if (str2.equals("--module-static-run")) {
Compilation.moduleStatic = 2;
} else if (str2.equals("--no-inline") || str2.equals("--inline=none")) {
i4 = 0;
Compilation.inlineOk = false;
} else if (str2.equals("--no-console")) {
noConsole = true;
} else if (str2.equals("--inline")) {
Compilation.inlineOk = true;
} else if (str2.equals("--cps")) {
Compilation.defaultCallConvention = 4;
} else if (str2.equals("--full-tailcalls")) {
Compilation.defaultCallConvention = 3;
} else if (str2.equals("--no-full-tailcalls")) {
Compilation.defaultCallConvention = 1;
} else if (str2.equals("--pedantic")) {
Language.requirePedantic = true;
} else if (str2.equals("--help")) {
printOptions(System.out);
i4 = 0;
System.exit(0);
} else {
i4 = 0;
if (str2.equals("--author")) {
System.out.println("Per Bothner <per@bothner.com>");
System.exit(0);
} else if (str2.equals("--version")) {
System.out.print("Kawa ");
System.out.print(Version.getVersion());
System.out.println();
System.out.println("Copyright (C) 2009 Per Bothner");
} else if (str2.length() > 0 && str2.charAt(0) == '-') {
if (str2.length() <= 2 || str2.charAt(0) != '-') {
str = str2;
} else {
str = str2.substring(str2.charAt(1) != '-' ? 1 : 2);
}
Language language = Language.getInstance(str);
if (language != null) {
if (previousLanguage == null) {
Language.setDefaults(language);
} else {
Language.setCurrentLanguage(language);
}
previousLanguage = language;
} else {
int indexOf = str.indexOf("=");
if (indexOf >= 0) {
str7 = str.substring(indexOf + 1);
str = str.substring(0, indexOf);
}
boolean z2 = str.startsWith("no-") && str.length() > 3;
if (str7 == null && z2) {
str = str.substring(3);
str7 = "no";
}
String str8 = Compilation.options.set(str, str7);
if (str8 != null) {
if (z2 && str8 == Options.UNKNOWN) {
str8 = "both '--no-' prefix and '=" + str7 + "' specified";
}
if (str8 == Options.UNKNOWN) {
bad_option(str2);
} else {
System.err.println("kawa: bad option '" + str2 + "': " + str8);
System.exit(-1);
}
}
}
} else if (!ApplicationMainSupport.processSetProperty(str2)) {
break;
}
}
}
}
}
}
i5++;
}
i4 = 0;
i5++;
}
i4 = 0;
}
z = true;
i5++;
}
getLanguage();
setArgs(strArr, i5 + 1);
checkInitFile();
Shell.run(Language.getDefaultLanguage(), Environment.getCurrent());
return -1;
try {
ServerSocket serverSocket = new ServerSocket(i3);
int localPort = serverSocket.getLocalPort();
System.err.println("Listening on port " + localPort);
while (true) {
System.err.print("waiting ... ");
System.err.flush();
Socket accept = serverSocket.accept();
System.err.println("got connection from " + accept.getInetAddress() + " port:" + accept.getPort());
TelnetRepl.serve(Language.getDefaultLanguage(), accept);
}
} catch (IOException e2) {
throw new Error(e2.toString());
}
}
public static void compileFiles(String[] strArr, int i, int i2) {
ModuleManager moduleManager = ModuleManager.getInstance();
int i3 = i2 - i;
Compilation[] compilationArr = new Compilation[i3];
ModuleInfo[] moduleInfoArr = new ModuleInfo[i3];
SourceMessages sourceMessages = new SourceMessages();
for (int i4 = i; i4 < i2; i4++) {
String str = strArr[i4];
getLanguageFromFilenameExtension(str);
try {
try {
Compilation parse = Language.getDefaultLanguage().parse(InPort.openFile(str), sourceMessages, defaultParseOptions);
if (compilationTopname != null) {
ClassType classType = new ClassType(Compilation.mangleNameIfNeeded(compilationTopname));
ModuleExp module = parse.getModule();
module.setType(classType);
module.setName(compilationTopname);
parse.mainClass = classType;
}
int i5 = i4 - i;
moduleInfoArr[i5] = moduleManager.find(parse);
compilationArr[i5] = parse;
} catch (Throwable th) {
if (!(th instanceof SyntaxException) || th.getMessages() != sourceMessages) {
internalError(th, null, str);
}
}
if (sourceMessages.seenErrorsOrWarnings()) {
System.err.println("(compiling " + str + ')');
if (sourceMessages.checkErrors(System.err, 20)) {
System.exit(1);
}
}
} catch (FileNotFoundException e) {
System.err.println(e);
System.exit(-1);
break;
}
}
for (int i6 = i; i6 < i2; i6++) {
String str2 = strArr[i6];
int i7 = i6 - i;
Compilation compilation = compilationArr[i7];
try {
System.err.println("(compiling " + str2 + " to " + compilation.mainClass.getName() + ')');
moduleInfoArr[i7].loadByStages(14);
boolean seenErrors = sourceMessages.seenErrors();
sourceMessages.checkErrors(System.err, 50);
if (seenErrors) {
System.exit(-1);
}
compilationArr[i7] = compilation;
boolean seenErrors2 = sourceMessages.seenErrors();
sourceMessages.checkErrors(System.err, 50);
if (seenErrors2) {
System.exit(-1);
}
} catch (Throwable th2) {
internalError(th2, compilation, str2);
}
}
}
static void internalError(Throwable th, Compilation compilation, Object obj) {
StringBuffer stringBuffer = new StringBuffer();
if (compilation != null) {
String fileName = compilation.getFileName();
int lineNumber = compilation.getLineNumber();
if (fileName != null && lineNumber > 0) {
stringBuffer.append(fileName);
stringBuffer.append(':');
stringBuffer.append(lineNumber);
stringBuffer.append(": ");
}
}
stringBuffer.append("internal error while compiling ");
stringBuffer.append(obj);
System.err.println(stringBuffer.toString());
th.printStackTrace(System.err);
System.exit(-1);
}
public static void main(String[] strArr) {
try {
int processArgs = processArgs(strArr, 0, strArr.length);
if (processArgs < 0) {
return;
}
if (processArgs < strArr.length) {
String str = strArr[processArgs];
getLanguageFromFilenameExtension(str);
setArgs(strArr, processArgs + 1);
checkInitFile();
Shell.runFileOrClass(str, false, 0);
} else {
getLanguage();
setArgs(strArr, processArgs);
checkInitFile();
if (shouldUseGuiConsole()) {
startGuiConsole();
} else if (!Shell.run(Language.getDefaultLanguage(), Environment.getCurrent())) {
System.exit(-1);
}
}
if (!shutdownRegistered) {
OutPort.runCleanups();
}
ModuleBody.exitDecrement();
} finally {
if (!shutdownRegistered) {
OutPort.runCleanups();
}
ModuleBody.exitDecrement();
}
}
public static boolean shouldUseGuiConsole() {
if (noConsole) {
return true;
}
return Class.forName("java.lang.System").getMethod("console", new Class[0]).invoke(new Object[0], new Object[0]) == null;
}
private static void startGuiConsole() {
try {
Class.forName("kawa.GuiConsole").newInstance();
} catch (Exception e) {
System.err.println("failed to create Kawa window: " + e);
System.exit(-1);
}
}
}