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();
}
}
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);
}
}
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();
}
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();
}
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);
}
}
Aggregations