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;
}
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);
}
}
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);
}
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;
}
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);
}
}
}
Aggregations