use of com.googlecode.aviator.runtime.type.AviatorFunction in project aviatorscript by killme2008.
the class AviatorEvaluatorInstance method disableFeature.
/**
* Disable a script engine feature.
*
* @see Feature
* @since 5.0.0
* @param feature
*/
public void disableFeature(final Feature feature) {
this.options.get(Options.FEATURE_SET).featureSet.remove(feature);
for (AviatorFunction fn : feature.getFunctions()) {
this.removeFunction(fn);
}
loadFeatureFunctions();
}
use of com.googlecode.aviator.runtime.type.AviatorFunction in project aviatorscript by killme2008.
the class InterpretCodeGenerator method emit.
private void emit(IR ir) {
if (ir instanceof OperatorIR) {
// check if operator is override.
final OperatorType op = ((OperatorIR) ir).getOp();
AviatorFunction fn = this.instance.getOpFunction(op);
if (fn != null) {
// replace it with new IR
ir = new OperatorIR(op, fn);
}
}
this.instruments.add(ir);
}
use of com.googlecode.aviator.runtime.type.AviatorFunction in project aviatorscript by killme2008.
the class AviatorEvaluatorInstanceUnitTest method testInstanceCustomOperator.
@Test
public void testInstanceCustomOperator() {
AviatorFunction func = (AviatorFunction) this.instance.execute("lambda(x,y) -> x-y end");
this.instance.addOpFunction(OperatorType.ADD, func);
assertEquals(-1, this.instance.execute("3+4"));
assertEquals(7, AviatorEvaluator.execute("3+4"));
assertEquals(7, AviatorEvaluator.newInstance().execute("3+4"));
}
use of com.googlecode.aviator.runtime.type.AviatorFunction in project aviatorscript by killme2008.
the class TryCatchFunction method call.
@SuppressWarnings("unchecked")
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2, final AviatorObject arg3, final AviatorObject arg4) {
AviatorFunction tryBody = (AviatorFunction) arg1;
List<CatchHandler> catchHandlers = (List<CatchHandler>) arg2.getValue(env);
AviatorFunction finallyBody = arg3 != AviatorNil.NIL ? (AviatorFunction) arg3 : null;
AviatorObject result = null;
try {
result = tryBody.call(env);
} catch (Throwable t) {
boolean handle = false;
if (catchHandlers != null) {
for (CatchHandler handler : catchHandlers) {
if (handler.isMatch(t.getClass())) {
AviatorObject ret = handler.getFunc().call(env, AviatorRuntimeJavaType.valueOf(t));
result = chooseResult(result, ret);
handle = true;
break;
}
}
}
if (!handle) {
throw Reflector.sneakyThrow(t);
}
} finally {
if (finallyBody != null) {
AviatorObject ret = finallyBody.call(env);
result = chooseResult(result, ret);
}
}
if (isReturnResult(result)) {
return result;
}
Object val = arg4.getValue(env);
if (val == Constants.REDUCER_EMPTY) {
return result;
}
AviatorFunction continueFn = (AviatorFunction) val;
AviatorObject contResult = continueFn.call(env);
if (contResult == Constants.REDUCER_EMPTY) {
return result;
} else {
return contResult;
}
}
use of com.googlecode.aviator.runtime.type.AviatorFunction in project aviatorscript by killme2008.
the class IfCallccFunction method call.
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
if (arg1 instanceof ReducerResult) {
return arg1;
} else {
final Object nextClauseVal = arg2.getValue(env);
if (nextClauseVal == Constants.REDUCER_EMPTY) {
return arg1;
}
AviatorFunction otherClausesFn = (AviatorFunction) nextClauseVal;
AviatorObject result = otherClausesFn.call(env);
// No remaining statements, return the if statement result.
if (result == Constants.REDUCER_EMPTY) {
return arg1;
}
return result;
}
}
Aggregations