Search in sources :

Example 1 with AbstractCompiler

use of php.runtime.common.AbstractCompiler 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 AbstractCompiler

use of php.runtime.common.AbstractCompiler in project jphp by jphp-compiler.

the class WrapModule method __construct.

@Signature({ @Arg("source"), @Arg(value = "compiled", optional = @Optional("false")), @Arg(value = "debugInformation", optional = @Optional("true")) })
public Memory __construct(Environment env, Memory... args) throws Throwable {
    InputStream is = Stream.getInputStream(env, args[0]);
    try {
        Context context = new Context(is, Stream.getPath(args[0]), env.getDefaultCharset());
        if (args[1].toBoolean()) {
            ModuleDumper moduleDumper = new ModuleDumper(context, env, args[2].toBoolean());
            module = moduleDumper.load(context.getInputStream(env.getDefaultCharset()));
        } else {
            AbstractCompiler compiler = env.scope.createCompiler(env, context);
            module = compiler.compile(false);
        }
        register(env);
    } finally {
        Stream.closeStream(env, is);
    }
    return Memory.NULL;
}
Also used : AbstractCompiler(php.runtime.common.AbstractCompiler) InputStream(java.io.InputStream) ModuleDumper(php.runtime.loader.dump.ModuleDumper)

Aggregations

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