-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathCompilerFacade.java
More file actions
38 lines (32 loc) · 1.25 KB
/
CompilerFacade.java
File metadata and controls
38 lines (32 loc) · 1.25 KB
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
package org.python.core;
import org.python.antlr.base.mod;
import org.python.compiler.LegacyCompiler;
/**
* Facade for different compiler implementations.
*
* The static methods of this class act as a Facade for the compiler subsystem.
* This is so that the rest of Jython (even generated code) can statically link
* to the static interface of this class, while allowing for different
* implementations of the various components of the compiler subsystem.
*
* @author Tobias Ivarsson
*/
public class CompilerFacade {
private static volatile PythonCompiler compiler = loadDefaultCompiler();
public static void setCompiler(PythonCompiler compiler) {
CompilerFacade.compiler = compiler;
}
private static PythonCompiler loadDefaultCompiler() {
return new LegacyCompiler();
}
public static PyCode compile(mod node, String name, String filename,
boolean linenumbers, boolean printResults, CompilerFlags cflags) {
try {
PythonCodeBundle bundle = compiler.compile(node, name, filename,
linenumbers, printResults, cflags);
return bundle.loadCode();
} catch (Throwable t) {
throw ParserFacade.fixParseError(null, t, filename);
}
}
}