Search in sources :

Example 66 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class BranchUnlessIR method eval.

@Override
public void eval(final InterpretContext context) {
    AviatorObject top = context.peek();
    if (!top.booleanValue(context.getEnv())) {
        context.jumpTo(this.pc);
        context.dispatch(false);
    } else {
        context.dispatch();
    }
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject)

Example 67 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class InterpretExpression method executeDirectly.

@Override
public Object executeDirectly(final Map<String, Object> env) {
    final boolean trace = RuntimeUtils.isTracedEval(env);
    if (trace) {
        traceInstruments(env, null, false);
        RuntimeUtils.printlnTrace(env, "Execute instruments: ");
    }
    InterpretContext ctx = new InterpretContext(this, this.instruments, (Env) env);
    ctx.dispatch(false);
    // }
    if (trace) {
        RuntimeUtils.printlnTrace(env, "    return    " + ctx.descOperandsStack());
    }
    assert (ctx.getOperands().size() <= 1);
    AviatorObject result = ctx.peek();
    if (result == null) {
        return null;
    }
    if (this.unboxObject) {
        return result.getValue(env);
    } else {
        return result.deref(env);
    }
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) InterpretContext(com.googlecode.aviator.code.interpreter.InterpretContext)

Example 68 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class OperatorIR method eval.

@Override
public void eval(final InterpretContext context) {
    assert (this.op != OperatorType.FUNC);
    int arity = this.op.getArity();
    AviatorObject[] args = new AviatorObject[arity];
    for (int i = args.length - 1; i >= 0; i--) {
        args[i] = context.pop();
    }
    AviatorObject result;
    if (this.fn == null) {
        result = this.op.eval(args, context.getEnv());
    } else {
        result = OperationRuntime.evalOpFunction(context.getEnv(), args, this.op, this.fn);
    }
    context.push(result);
    context.dispatch();
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject)

Example 69 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class SendIR method eval.

@Override
public void eval(final InterpretContext context) {
    AviatorFunction fn = null;
    if (this.name != null) {
        fn = RuntimeUtils.getFunction(context.getEnv(), this.name);
    }
    int i = this.arity;
    AviatorObject[] args = new AviatorObject[this.arity];
    while (--i >= 0) {
        args[i] = context.pop();
    }
    if (this.name == null) {
        fn = (AviatorFunction) context.pop();
    }
    if (RuntimeUtils.isTracedEval(context.getEnv())) {
        fn = TraceFunction.wrapTrace(fn);
    }
    if (this.unpackArgs) {
        fn = RuntimeUtils.unpackArgsFunction(fn);
    }
    if (this.funcId >= 0) {
        // put function arguments ref id to env.
        context.getEnv().put(ASMCodeGenerator.FUNC_ARGS_INNER_VAR, this.funcId);
    }
    context.push(callFn(fn, args, this.arity, context.getEnv()));
    context.dispatch();
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorFunction(com.googlecode.aviator.runtime.type.AviatorFunction)

Example 70 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class SeqFilterFunctionUnitTest method testFilter_String.

@Test
public void testFilter_String() {
    SeqFilterFunction fun = new SeqFilterFunction();
    SeqPredicateFunction predicate = new SeqPredicateFunction("eq_temp_1", OperatorType.EQ, new AviatorString("l"));
    Map<String, Object> env = new HashMap<String, Object>();
    env.putAll(AviatorEvaluator.FUNC_MAP);
    env.put("eq_temp_1", predicate);
    AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf("hello"), new AviatorJavaType("eq_temp_1"));
    List list = (List) result.getValue(null);
    assertEquals(2, list.size());
    for (Object i : list) {
        assertEquals("l", i);
    }
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) HashMap(java.util.HashMap) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) List(java.util.List) LinkedList(java.util.LinkedList) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Test(org.junit.Test)

Aggregations

AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)110 Test (org.junit.Test)51 AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)25 AviatorString (com.googlecode.aviator.runtime.type.AviatorString)22 AviatorFunction (com.googlecode.aviator.runtime.type.AviatorFunction)16 HashMap (java.util.HashMap)12 Map (java.util.Map)11 List (java.util.List)10 AbstractFunction (com.googlecode.aviator.runtime.function.AbstractFunction)9 FunctionNotFoundException (com.googlecode.aviator.exception.FunctionNotFoundException)7 Env (com.googlecode.aviator.utils.Env)6 ExpressionRuntimeException (com.googlecode.aviator.exception.ExpressionRuntimeException)5 LinkedList (java.util.LinkedList)5 Collection (java.util.Collection)4 NumberToken (com.googlecode.aviator.lexer.token.NumberToken)3 AviatorPattern (com.googlecode.aviator.runtime.type.AviatorPattern)3 AviatorRuntimeJavaType (com.googlecode.aviator.runtime.type.AviatorRuntimeJavaType)3 Sequence (com.googlecode.aviator.runtime.type.Sequence)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3