public void loadModule(ModuleEntity module) { loadModule(module, true); }
public ModuleEntity loadModule(String name) { return loadModule(name, true); }
protected void loadModule(Environment env) { if (!module.isLoaded()) { synchronized (env.scope) { if (!module.isLoaded()) { env.scope.loadModule(module); env.scope.addUserModule(module); } } } }
@Override public void fetch(CompileScope scope, String originName, String name) { ModuleEntity module = fetchClass(name); if (module != null) { loadModule(module); scope.loadModule(module, false); scope.registerModule(module); } } });
@Override public void fetch(CompileScope scope, String originName, String name) { ModuleEntity module = fetchFunction(name); if (module != null) { loadModule(module); scope.loadModule(module, false); scope.registerModule(module); } } });
@Override public void fetch(CompileScope scope, String originName, String name) { ModuleEntity module = fetchConstant(name); if (module != null) { loadModule(module); scope.loadModule(module, false); scope.registerModule(module); } } });
public Memory eval(String code, ArrayMemory locals) throws Throwable { Context context = new Context(code); AbstractCompiler compiler = scope.createCompiler(this, context); ModuleEntity module = compiler.compile(); scope.loadModule(module); registerModule(module); return module.include(this, locals); }
public ModuleEntity fetchModule(String name) { if (library == null) { throw new CriticalException("Standalone library is not loaded"); } ModuleEntity entity = _fetch(name, library.getModules()); if (entity != null) { loadModule(entity); scope.loadModule(entity, false); scope.addUserModule(entity); } return entity; }
public ModuleEntity importModule(Context context) throws Throwable { String moduleName = context.getModuleName(); ModuleEntity module = moduleName == null ? null : scope.findUserModule(moduleName); if (module == null) { AbstractCompiler compiler = scope.createCompiler(this, context); module = compiler.compile(true); synchronized (scope) { scope.loadModule(module); } } registerModule(module); return module; }
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; }
@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; }
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); }
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.getScope().loadModule(module); environment.getScope().addUserModule(module); environment.registerModule(module);