Script script = null;
try {
String filename = node.getPosition().getFile();
String classname = JavaNameMangler.mangledFilenameForStartupClasspath(filename);
StandardASMCompiler asmCompiler = null;
if (RubyInstanceConfig.JIT_CODE_CACHE != null && cachedClassName != null) {
asmCompiler = new StandardASMCompiler(cachedClassName.replace('.', '/'), filename);
} else {
asmCompiler = new StandardASMCompiler(classname, filename);
}
ASTCompiler compiler = config.newCompiler();
if (dump) {
compiler.compileRoot(node, asmCompiler, inspector, false, false);
asmCompiler.dumpClass(System.out);
} else {
compiler.compileRoot(node, asmCompiler, inspector, true, false);
}
if (RubyInstanceConfig.JIT_CODE_CACHE != null && cachedClassName != null) {
// save script off to disk
String pathName = cachedClassName.replace('.', '/');
JITCompiler.saveToCodeCache(this, asmCompiler.getClassByteArray(), "ruby/jit", new File(RubyInstanceConfig.JIT_CODE_CACHE, pathName + ".class"));
}
script = (Script)asmCompiler.loadClass(classLoader).newInstance();
// __file__ method expects its scope at 0, so prepare that here
// this is only needed for the "gets loop" which skips calling load
StaticScope rootScope = ((RootNode)node).getStaticScope();
if (rootScope.getModule() == null) rootScope.setModule(objectClass);