public ModuleEntity fetchModule(String path) throws Throwable { return fetchModule(path, path.endsWith(".phb")); }
public Environment(Environment parent, OutputStream output) { this(parent.scope, parent.defaultBuffer.getOutput()); configuration.putAll(parent.configuration); //constants.putAll(parent.constants); classMap.putAll(parent.classMap); for (ClassEntity e : classMap.values()) { try { e.initEnvironment(this); } catch (Throwable throwable) { throw new RuntimeException(throwable); } } functionMap.putAll(parent.functionMap); constantMap.putAll(parent.constantMap); moduleManager.apply(parent.moduleManager); packageManager.apply(parent.packageManager); }
protected ModuleEntity fetchClass(Environment env, String fileName, boolean compiled) throws Throwable { return env.getModuleManager().fetchTemporaryModule("res://" + fileName, compiled); } }
@Signature(@Arg("path")) public Memory findModule(Environment env, Memory... args) throws Throwable { ModuleManager moduleManager = this.environment.getModuleManager(); boolean hasModule = moduleManager.hasModule(args[0].toString()); if (hasModule) { return ObjectMemory.valueOf(new WrapModule(env, moduleManager.fetchModule(args[0].toString()))); } return Memory.NULL; }
public ModuleEntity fetchTemporaryModule(String path, boolean compiled) throws Throwable { Stream stream = fetchStream(path); if (stream == null) { return null; } try { if (stream._isExternalResourceStream()) { env.exception("Cannot import module form external stream: " + stream.getPath()); return null; } else { ModuleEntity module; Context context = fetchContext(stream); if (compiled) { module = env.importCompiledModule(context, true); } else { module = env.importModule(context); } module.setTrace(new TraceInfo(context)); return module; } } finally { env.invokeMethod(stream, "close"); } }
public ModuleEntity findModule(TraceInfo traceInfo) { if (traceInfo == null || traceInfo == TraceInfo.UNKNOWN) { return null; } return findModule(traceInfo.getFileName()); }
public static Memory get_included_files(Environment env){ return ArrayMemory.ofStringCollection(env.getModuleManager().getCachedPaths()); }
this.moduleManager = new ModuleManager(this); this.packageManager = new PackageManager(this);
environment.getScope().addUserModule(module); environment.registerModule(module); environment.getModuleManager().addModule(context.getFileName(), module);
private Memory __import(String path, ArrayMemory locals, TraceInfo trace, String funcName, boolean once, Callback<Void, Void> callback) throws Throwable { synchronized (moduleManager) { if (once && moduleManager.hasModule(path)) { return Memory.TRUE; } ModuleEntity module = moduleManager.fetchModule(path, path.endsWith(".phb")); if (module == null) { callback.call(null); return Memory.FALSE; } CallStackItem stackItem = pushCall( trace, null, new Memory[]{StringMemory.valueOf(path)}, funcName, null, null ); try { if (locals == null) { locals = new ArrayMemory(); } return module.include(this, locals); } finally { popCall(); } } }
public ModuleEntity module() { if (callStackTop <= 0) { return null; } return env.getModuleManager().findModule(peekCall(0).trace); }
public ModuleEntity loadFrom(String file) throws Throwable { return environment.getModuleManager().fetchModule(file); }
public ModuleEntity module(int depth) { CallStackItem stackItem = peekCall(depth); if (stackItem != null) { return env.getModuleManager().findModule(stackItem.trace); } return null; }
public ModuleEntity fetchModule(String path, boolean compiled) throws Throwable { ModuleEntity moduleEntity = modules.get(path); if (moduleEntity != null && (moduleEntity.getContext().getLastModified() == 0 || moduleEntity.getContext().getLastModified() == new File(path).lastModified())) { return moduleEntity; } else { env.scope.removeUserModule(path); moduleEntity = fetchTemporaryModule(path, compiled); if (moduleEntity == null) { return null; } modules.put(path, moduleEntity); return moduleEntity; } }
private ModuleEntity compileFile(File path, File destinationDirectory, File destinationResDirectory) { try { ModuleEntity entity = env.getModuleManager().fetchModule(path.getPath()); saveModuleClasses(entity, destinationDirectory, destinationResDirectory); return entity; } catch (Throwable throwable) { throw new RuntimeException(throwable); } }
private static Memory typeHintArg(Environment env, TraceInfo trace, ParameterEntity param, Memory arg, int i, String originClassName, String originMethodName, String staticClassName) { if (!param.checkTypeHinting(env, arg, staticClassName)) { ModuleEntity module = env.getModuleManager().findModule(trace); Memory memory = param.applyTypeHinting(env, arg, module != null && module.isStrictTypes()); if (memory != null) { return memory; } else { invalidType(env, trace, param, i + 1, arg, originClassName, originMethodName); } } return arg; }
ModuleEntity fetchModule = environment.getModuleManager().fetchModule(include);
public static Memory checkReturnType(Environment env, TraceInfo trace, Memory result, Function<String> callName, TypeChecker typeChecker, boolean nullable) { if (typeChecker == null) { return result; } if (!typeChecker.check(env, result, nullable, null)) { ModuleEntity module = env.getModuleManager().findModule(trace); Memory newReturn = typeChecker.apply( env, result, nullable, module != null && module.isStrictTypes() ); if (newReturn == null) { String given = result.isObject() ? result.toValue(ObjectMemory.class).getReflection().getName() : result.getRealType().toString(); env.exception( trace, BaseTypeError.class, Messages.ERR_RETURN_TYPE_INVALID.fetch(callName.call(), typeChecker.getHumanString(), given) ); return null; } else { return newReturn; } } return result; }