Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
61 lines (53 loc) · 2.08 KB

File metadata and controls

61 lines (53 loc) · 2.08 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package edu.rice.cs.dynamicjava;
import java.io.*;
import edu.rice.cs.plt.tuple.Option;
import edu.rice.cs.plt.tuple.OptionVisitor;
import edu.rice.cs.plt.text.TextUtil;
import edu.rice.cs.plt.text.ArgumentParser;
import edu.rice.cs.plt.io.IOUtil;
import edu.rice.cs.plt.reflect.PathClassLoader;
import edu.rice.cs.dynamicjava.interpreter.Interpreter;
import edu.rice.cs.dynamicjava.interpreter.InterpreterException;
import static edu.rice.cs.plt.debug.DebugUtil.debug;
public final class DynamicJava {
private DynamicJava() {}
public static void main(String... args) throws IOException {
debug.log();
ArgumentParser argParser = new ArgumentParser();
argParser.supportOption("classpath", IOUtil.WORKING_DIRECTORY.toString());
argParser.supportAlias("cp", "classpath");
ArgumentParser.Result parsedArgs = argParser.parse(args);
Iterable<File> cp = IOUtil.parsePath(parsedArgs.getUnaryOption("classpath"));
Interpreter i = new Interpreter(Options.DEFAULT, new PathClassLoader(cp));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String prev = null;
boolean blank = false;
String input;
do {
System.out.print("> ");
System.out.flush();
input = in.readLine();
if (input != null) {
// two blank lines trigger a recompute
if (input.equals("")) {
if (blank == true) { input = prev; blank = false; }
else { blank = true; }
}
else { prev = input; blank = false; }
try {
Option<Object> result = i.interpret(input);
result.apply(new OptionVisitor<Object, Void>() {
public Void forSome(Object o) { System.out.println(TextUtil.toString(o)); return null; }
public Void forNone() { return null; }
});
}
catch (InterpreterException e) { e.printUserMessage(); debug.log(e); }
catch (RuntimeException e) {
System.out.println("INTERNAL ERROR: Uncaught exception");
e.printStackTrace(System.out);
}
System.out.println();
}
} while (input != null);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.