All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.python.core.CompilerFacade Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

There is a newer version: 2.7.4
Show newest version
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);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy