use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class TestUtils method getTestEnv.
public static Env getTestEnv() {
Env env = new Env();
env.setInstance(AviatorEvaluator.getInstance());
return env;
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class AviatorEvaluatorInstance method executeModule.
@SuppressWarnings("unchecked")
private Map<String, Object> executeModule(final Expression exp, final String abPath) {
final Env exports = new Env();
final Map<String, Object> module = exp.newEnv("exports", exports, "path", abPath);
Map<String, Object> env = exp.newEnv("__MODULE__", module, "exports", exports);
exp.execute(env);
exports.configure(this, exp);
return (Map<String, Object>) module.get("exports");
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class AviatorEvaluatorInstance method loadModule.
private Env loadModule(final Class<?> moduleClazz) throws IllegalAccessException, NoSuchMethodException {
Map<String, List<Method>> methodMap = findMethodsFromClass(moduleClazz, true);
if (methodMap == null || methodMap.isEmpty()) {
throw new IllegalArgumentException("Empty module");
}
Env exports = new Env();
for (Map.Entry<String, List<Method>> entry : methodMap.entrySet()) {
exports.put(entry.getKey(), new ClassMethodFunction(moduleClazz, true, entry.getKey(), entry.getKey(), entry.getValue()));
}
exports.setInstance(this);
return exports;
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class BaseExpression method execute.
@Override
public Object execute(Map<String, Object> map) {
if (map == null) {
map = Collections.emptyMap();
}
Env env = genTopEnv(map);
EnvProcessor envProcessor = this.instance.getEnvProcessor();
if (envProcessor != null) {
envProcessor.beforeExecute(env, this);
}
try {
return executeDirectly(env);
} finally {
if (envProcessor != null) {
envProcessor.afterExecute(env, this);
}
}
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class InterpretExpression method loadConstants.
private void loadConstants(final Set<Token<?>> constants, final List<IR> instruments) {
final Env env = new Env();
env.setInstance(this.instance);
InterpretContext ctx = new InterpretContext(this, instruments, env);
for (Token<?> token : constants) {
final LoadIR loadConstantIR = new LoadIR(this.sourceFile, token, null, false);
loadConstantIR.evalWithoutDispatch(ctx);
this.constantPool.put(token, ctx.pop());
}
}
Aggregations