private void loadExtensions() { ServiceLoader<Extension> loader = ServiceLoader.load(Extension.class); for (Extension extension : loader) { env.scope.registerExtension(extension); } }
protected CompileScope newScope(){ CompileScope compileScope = new CompileScope(); compileScope.setDebugMode(true); compileScope.setLangMode(LangMode.DEFAULT); compileScope.registerExtension(new CoreExtension()); compileScope.registerExtension(new SPLExtension()); return compileScope; }
protected void loadModule(Environment env) { if (!module.isLoaded()) { synchronized (env.scope) { if (!module.isLoaded()) { env.scope.loadModule(module); env.scope.addUserModule(module); } } } }
protected void loadExtensions() { ServiceLoader<Extension> loader = ServiceLoader.load(Extension.class, compileScope.getClassLoader()); for (Extension extension : loader) { compileScope.registerExtension(extension); } }
registerLazyClass(extension, Closure.class); registerLazyClass(extension, Generator.class); registerLazyClass(extension, StdClass.class); registerLazyClass(extension, BaseThrowable.class); registerLazyClass(extension, BaseException.class); registerLazyClass(extension, BaseError.class); registerLazyClass(extension, BaseParseError.class); registerLazyClass(extension, BaseTypeError.class); registerLazyClass(extension, BaseArithmeticError.class); registerLazyClass(extension, BaseDivisionByZeroError.class); registerLazyClass(extension, ErrorException.class); registerLazyClass(extension, ArrayAccess.class); registerLazyClass(extension, Traversable.class); registerLazyClass(extension, php.runtime.lang.spl.iterator.Iterator.class); registerLazyClass(extension, IteratorAggregate.class); registerLazyClass(extension, Serializable.class); registerExtension(new NetExtension()); registerExtension(new JavaExtension()); registerExtension(extension);
@Signature(@Arg("extensionClass")) public Memory registerExtension(Environment env, Memory... args) { Extension extension = this.environment.scope.getExtension(args[0].toString()); if (extension != null) { env.exception("Extension '%s' already registered", extension.getName()); } this.environment.scope.registerExtension(args[0].toString()); return Memory.NULL; }
public StandaloneLoader() { config = new Properties(); scope = new CompileScope(); env = new ConcurrentEnvironment(scope, System.out); env.getDefaultBuffer().setImplicitFlush(true); scope.addClassEntityFetchHandler(new EntityFetchHandler() { @Override public void fetch(CompileScope scope, String originName, String name) { scope.addFunctionEntityFetchHandler(new EntityFetchHandler() { @Override public void fetch(CompileScope scope, String originName, String name) { scope.addConstantEntityFetchHandler(new EntityFetchHandler() { @Override public void fetch(CompileScope scope, String originName, String name) {
public void readConfig() { InputStream resource = classLoader.getResourceAsStream("JPHP-INF/launcher.conf"); if (resource != null) { try { config.load(resource); for (String name : config.stringPropertyNames()){ scope.configuration.put(name, new StringMemory(config.getProperty(name))); } isDebug = Startup.isDebug(); scope.setDebugMode(isDebug); scope.setLangMode( LangMode.valueOf(getConfigValue("env.langMode", LangMode.MODERN.name()).toString().toUpperCase()) ); } catch (IOException e) { throw new LaunchException(e.getMessage()); } } }
public ModuleEntity importCompiledModule(Context context, boolean debugInformation) throws Throwable { String moduleName = context.getModuleName(); ModuleEntity module = moduleName == null ? null : scope.findUserModule(moduleName); if (module == null) { ModuleDumper moduleDumper = new ModuleDumper(context, this, debugInformation); module = moduleDumper.load(context.getInputStream(getDefaultCharset())); synchronized (scope) { scope.loadModule(module); } } registerModule(module); scope.addUserModule(module); return module; }
public Environment(OutputStream output) { this(new CompileScope(), output); }
protected SyntaxAnalyzer getSyntax(Context context){ Tokenizer tokenizer = null; try { tokenizer = new Tokenizer(context); } catch (IOException e) { throw new RuntimeException(e); } environment.scope.setLangMode(LangMode.DEFAULT); return new SyntaxAnalyzer(environment, tokenizer); }
public void registerModule(ModuleEntity module) { addUserModule(module); for(ClassEntity entity : module.getClasses()) { if (entity.isStatic()){ if (classMap.put(entity.getLowerName(), entity) != null) { throw new CriticalException(Messages.ERR_CANNOT_REDECLARE_CLASS.fetch(entity.getName())); } } } for(FunctionEntity entity : module.getFunctions()) { if (entity.isStatic()) { if (functionMap.put(entity.getLowerName(), entity) != null) { throw new CriticalException(Messages.ERR_CANNOT_REDECLARE_FUNCTION.fetch(entity.getName())); } } } for(ConstantEntity entity : module.getConstants()) { if (constantMap.put(entity.getLowerName(), entity) != null) { throw new CriticalException(Messages.ERR_CANNOT_REDECLARE_CONSTANT.fetch(entity.getName())); } } }
public Memory findConstant(String name, String nameLower) { ConstantEntity entity = constantMap.get(nameLower); if (entity != null) { if (!entity.caseSensitise || name.equals(entity.getName())) return entity.getValue(); } CompileConstant constant = scope.findCompileConstant(name); if (constant != null) return constant.value; return null; }
compileScope.getClassLoader().onAddLibrary(new Callback<Void, URL>() { @Override public Void call(URL param) { compileScope.registerExtension(className);
try { Extension el = (Extension) Class.forName(dep).newInstance(); registerExtension(el); } catch (Exception e) { throw new CriticalException(e); try { Extension el = (Extension) Class.forName(dep).newInstance(); registerExtension(el); } catch (ClassNotFoundException e) { registerLazyClass(extension, clazz);
compileScope.setDebugMode(isDebug); compileScope.setLangMode( LangMode.valueOf(getConfigValue("env.langMode", LangMode.MODERN.name()).toString().toUpperCase()) );
public Launcher(String pathToConf, String[] args) { current = this; this.args = args; this.out = System.out != null ? System.out : new ByteArrayOutputStream(); this.compileScope = new CompileScope(); this.pathToConf = pathToConf == null ? "JPHP-INF/launcher.conf" : pathToConf; }
protected List<Token> getSyntaxTree(String code){ Tokenizer tokenizer = null; try { tokenizer = new Tokenizer(new Context(code)); environment.scope.setLangMode(LangMode.DEFAULT); SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer); return analyzer.getTree(); } catch (IOException e) { throw new RuntimeException(e); } } }
scope.addUserModule(module);
Memory writePushName(NameToken token, boolean returnMemory, boolean writeOpcode) { CompileConstant constant = compiler.getScope().findCompileConstant(token.getName()); if (constant != null) { if (returnMemory)