public Memory include(Environment env) throws Throwable { try { return (Memory) nativeMethod.invoke(null, env, argsMock, env.getGlobals()); } catch (InvocationTargetException e){ return env.__throwException(e); } }
@Override public Bindings createBindings() { return new JPHPBindings(environment.getGlobals()); }
public Memory eval(String code) throws Throwable { return eval(code, getGlobals()); }
public Memory includeNoThrow(Environment env){ return includeNoThrow(env, env.getGlobals()); }
@Signature public Memory getGlobals(Environment env, Memory... args) { return environment.getGlobals().toImmutable(); }
@Signature(@Arg("name")) public Memory hasGlobal(Environment env, Memory... args) { return environment.getGlobals().containsKey(args[0].toString()) ? Memory.TRUE : Memory.FALSE; }
@Signature(@Arg("name")) public Memory getGlobal(Environment env, Memory... args) { return environment.getGlobals().valueOfIndex(args[0]).toImmutable(); }
@Signature({ @Arg("name"), @Arg(value = "value", optional = @Optional("null")) }) public Memory addSuperGlobal(Environment env, Memory... args) { if (hasSuperGlobal(env, args[0]).toBoolean()) { environment.exception("Super-global variable $%s already exists", args[0]); } environment.getScope().superGlobals.add(args[0].toString()); environment.getGlobals().putAsKeyString(args[0].toString(), args[1].toImmutable()); return Memory.UNDEFINED; }
environment.getGlobals().put("argv", argv); environment.getGlobals().put("argc", LongMemory.valueOf(argv.size()));
@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; }
environment.getModuleManager().addModule(context.getFileName(), module); Memory memory = module.includeNoThrow(environment, environment.getGlobals()); } catch (ErrorException e) { if (withErrors){