Search in sources :

Example 1 with JvmCompiler

use of org.develnext.jphp.core.compiler.jvm.JvmCompiler in project jphp by jphp-compiler.

the class EvalFunctions method eval.

public static Memory eval(Environment env, TraceInfo trace, @Runtime.GetLocals ArrayMemory locals, String code) throws Throwable {
    Context context = new Context(code);
    try {
        Tokenizer tokenizer = new Tokenizer(context);
        SyntaxAnalyzer analyzer = syntaxAnalyzer.get();
        analyzer.reset(env, tokenizer);
        AbstractCompiler compiler = new JvmCompiler(env, context, analyzer);
        ModuleEntity module = compiler.compile();
        env.scope.loadModule(module);
        env.registerModule(module);
        return module.include(env, locals);
    } catch (ErrorException e) {
        if (e.getType() == ErrorType.E_PARSE) {
            if (env.isHandleErrors(ErrorType.E_PARSE))
                throw new ParseException(evalErrorMessage(e), trace);
        } else
            env.error(trace, e.getType(), evalErrorMessage(e));
    }
    return Memory.FALSE;
}
Also used : Context(php.runtime.env.Context) AbstractCompiler(php.runtime.common.AbstractCompiler) SyntaxAnalyzer(org.develnext.jphp.core.syntax.SyntaxAnalyzer) JvmCompiler(org.develnext.jphp.core.compiler.jvm.JvmCompiler) ModuleEntity(php.runtime.reflection.ModuleEntity) ParseException(php.runtime.exceptions.ParseException) ErrorException(php.runtime.exceptions.support.ErrorException) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer)

Example 2 with JvmCompiler

use of org.develnext.jphp.core.compiler.jvm.JvmCompiler in project jphp by jphp-compiler.

the class Launcher method loadFromFile.

public ModuleEntity loadFromFile(String file) throws IOException {
    InputStream inputStream = getResource(file);
    if (inputStream == null)
        return null;
    Context context = new Context(inputStream, file, environment.getDefaultCharset());
    JvmCompiler compiler = new JvmCompiler(environment, context);
    return compiler.compile(false);
}
Also used : JvmCompiler(org.develnext.jphp.core.compiler.jvm.JvmCompiler)

Aggregations

JvmCompiler (org.develnext.jphp.core.compiler.jvm.JvmCompiler)2 SyntaxAnalyzer (org.develnext.jphp.core.syntax.SyntaxAnalyzer)1 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)1 AbstractCompiler (php.runtime.common.AbstractCompiler)1 Context (php.runtime.env.Context)1 ParseException (php.runtime.exceptions.ParseException)1 ErrorException (php.runtime.exceptions.support.ErrorException)1 ModuleEntity (php.runtime.reflection.ModuleEntity)1