Search in sources :

Example 1 with ModuleEntity

use of php.runtime.reflection.ModuleEntity 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 ModuleEntity

use of php.runtime.reflection.ModuleEntity in project jphp by jphp-compiler.

the class JvmCompilerCase method run.

protected Memory run(String code, boolean returned) {
    runIndex += 1;
    Environment environment = new Environment(newScope());
    code = "class TestClass { static function test(){ " + (returned ? "return " : "") + code + "; } }";
    Context context = new Context(code);
    JvmCompiler compiler = new JvmCompiler(environment, context, getSyntax(context));
    ModuleEntity module = compiler.compile();
    environment.getScope().loadModule(module);
    ClassEntity entity = module.findClass("TestClass");
    try {
        return entity.findMethod("test").invokeStatic(environment);
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ModuleEntity(php.runtime.reflection.ModuleEntity)

Example 3 with ModuleEntity

use of php.runtime.reflection.ModuleEntity in project jphp by jphp-compiler.

the class JvmCompilerCase method runDynamic.

protected Memory runDynamic(String code, boolean returned) {
    runIndex += 1;
    Environment environment = new Environment(newScope());
    code = (returned ? "return " : "") + code + ";";
    Context context = new Context(code);
    JvmCompiler compiler = new JvmCompiler(environment, context, getSyntax(context));
    ModuleEntity module = compiler.compile();
    environment.getScope().loadModule(module);
    try {
        environment.registerModule(module);
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
    return module.includeNoThrow(environment);
}
Also used : ModuleEntity(php.runtime.reflection.ModuleEntity)

Example 4 with ModuleEntity

use of php.runtime.reflection.ModuleEntity in project jphp by jphp-compiler.

the class StandaloneLoader method fetchModule.

public ModuleEntity fetchModule(String name) {
    ModuleEntity entity = _fetch(name.toLowerCase(), modules);
    if (entity != null) {
        loadModule(entity);
        scope.loadModule(entity, false);
        scope.addUserModule(entity);
    }
    return entity;
}
Also used : ModuleEntity(php.runtime.reflection.ModuleEntity)

Example 5 with ModuleEntity

use of php.runtime.reflection.ModuleEntity in project jphp by jphp-compiler.

the class CLI method executeFile.

protected void executeFile(String filename) throws Throwable {
    Launcher launcher = new Launcher("jphp.conf", args);
    launcher.run(false);
    File file = new File(filename);
    Environment environment = new Environment(launcher.getCompileScope(), output);
    environment.getDefaultBuffer().setImplicitFlush(true);
    try {
        Context context = new Context(file);
        ModuleEntity module = environment.importModule(context);
        module.include(environment);
    } catch (Exception e) {
        environment.catchUncaught(e);
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    } finally {
        try {
            environment.doFinal();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
}
Also used : Context(php.runtime.env.Context) Launcher(php.runtime.launcher.Launcher) Environment(php.runtime.env.Environment) ModuleEntity(php.runtime.reflection.ModuleEntity) File(java.io.File)

Aggregations

ModuleEntity (php.runtime.reflection.ModuleEntity)12 File (java.io.File)3 Context (php.runtime.env.Context)3 ArrayMemory (php.runtime.memory.ArrayMemory)3 ClassEntity (php.runtime.reflection.ClassEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Memory (php.runtime.Memory)2 ErrorException (php.runtime.exceptions.support.ErrorException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 JvmCompiler (org.develnext.jphp.core.compiler.jvm.JvmCompiler)1 ModuleOpcodePrinter (org.develnext.jphp.core.opcode.ModuleOpcodePrinter)1 SyntaxAnalyzer (org.develnext.jphp.core.syntax.SyntaxAnalyzer)1 Test (org.develnext.jphp.core.tester.Test)1 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)1 ReaderInputStream (org.develnext.jphp.scripting.util.ReaderInputStream)1 AbstractCompiler (php.runtime.common.AbstractCompiler)1 Environment (php.runtime.env.Environment)1 CriticalException (php.runtime.exceptions.CriticalException)1 CustomErrorException (php.runtime.exceptions.CustomErrorException)1