public static void main(String[] args) { Environment env = new Environment();
: new Environment(compileScope, out);
public static Memory getValue(Debugger context, String value) { DebugTick tick = context.getRegisteredTick(); Environment environment = new Environment(new CompileScope(tick.getEnvironment().getScope())); try { return LangFunctions.eval(environment, tick.getTrace(), tick.getLocals(), "return " + value + ";"); } catch (Throwable throwable) { return null; } }
@SuppressWarnings("unchecked") protected Memory includeResource(String name, ArrayMemory globals){ ByteArrayOutputStream output = new ByteArrayOutputStream(); Environment environment; if (isConcurrent()) { environment = new ConcurrentEnvironment(newScope(), output); } else { environment = new Environment(newScope(), output); } File file = new File(Thread.currentThread().getContextClassLoader().getResource("resources/" + name).getFile()); Context context = new Context(file); 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); } if (globals != null) environment.getGlobals().putAll(globals); Memory memory = module.includeNoThrow(environment, environment.getGlobals()); try { environment.doFinal(); } catch (Throwable throwable) { throw new RuntimeException(throwable); } lastOutput = output.toString(); return memory; }
@Signature({ @Arg(value = "parent", nativeType = WrapEnvironment.class, optional = @Optional("NULL")), @Arg(value = "flags", optional = @Optional(value = "0", type = HintType.INT)) }) public Memory __construct(Environment env, Memory... args){ CompileScope scope = env.scope; int flags = args[1].toInteger(); boolean hotReload = (flags & HOT_RELOAD) == HOT_RELOAD; boolean concurrent = (flags & CONCURRENT) == CONCURRENT; if (hotReload) { scope = new CompileScope(scope); } if (args[0].isNull()) { if (concurrent) setEnvironment(new ConcurrentEnvironment(scope, env.getDefaultBuffer().getOutput())); else setEnvironment(new Environment(scope, env.getDefaultBuffer().getOutput())); } else { if (hotReload) env.exception("Environment cannot be hot-reloadable with parent"); if (concurrent) setEnvironment(new ConcurrentEnvironment(args[0].toObject(WrapEnvironment.class).getWrapEnvironment())); else setEnvironment(new Environment(args[0].toObject(WrapEnvironment.class).getWrapEnvironment())); } return Memory.NULL; }
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); }
public JPHPScriptEngine() { super(); Launcher launcher = new Launcher(); try { launcher.run(false); } catch (Throwable e) { //pass } environment = new Environment(launcher.getCompileScope(), System.out); environment.getDefaultBuffer().setImplicitFlush(true); JPHPContext ctx = new JPHPContext(); ctx.setBindings(createBindings(), ScriptContext.ENGINE_SCOPE); setContext(ctx); put(LANGUAGE_VERSION, __LANGUAGE_VERSION__); put(LANGUAGE, __LANGUAGE__); put(ENGINE, __NAME__); put(ENGINE_VERSION, __ENGINE_VERSION__); put(NAME, __SHORT_NAME__); }
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); } }
environment = new ConcurrentEnvironment(newScope(), outputR); } else { environment = new Environment(newScope(), outputR);