Search in sources :

Example 16 with Env

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;
}
Also used : Env(com.googlecode.aviator.utils.Env)

Example 17 with 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");
}
Also used : Env(com.googlecode.aviator.utils.Env) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LRUMap(com.googlecode.aviator.utils.LRUMap)

Example 18 with Env

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;
}
Also used : ClassMethodFunction(com.googlecode.aviator.runtime.function.ClassMethodFunction) ArrayList(java.util.ArrayList) List(java.util.List) Env(com.googlecode.aviator.utils.Env) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LRUMap(com.googlecode.aviator.utils.LRUMap)

Example 19 with Env

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);
        }
    }
}
Also used : Env(com.googlecode.aviator.utils.Env)

Example 20 with Env

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());
    }
}
Also used : InterpretContext(com.googlecode.aviator.code.interpreter.InterpretContext) LoadIR(com.googlecode.aviator.code.interpreter.ir.LoadIR) Env(com.googlecode.aviator.utils.Env)

Aggregations

Env (com.googlecode.aviator.utils.Env)28 AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)10 Test (org.junit.Test)8 AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)6 BigDecimal (java.math.BigDecimal)4 BigInteger (java.math.BigInteger)4 LRUMap (com.googlecode.aviator.utils.LRUMap)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Import (com.googlecode.aviator.annotation.Import)1 InterpretContext (com.googlecode.aviator.code.interpreter.InterpretContext)1 LoadIR (com.googlecode.aviator.code.interpreter.ir.LoadIR)1 ExpressionRuntimeException (com.googlecode.aviator.exception.ExpressionRuntimeException)1 ExpressionSyntaxErrorException (com.googlecode.aviator.exception.ExpressionSyntaxErrorException)1 FunctionParam (com.googlecode.aviator.runtime.FunctionParam)1 ClassMethodFunction (com.googlecode.aviator.runtime.function.ClassMethodFunction)1