Search in sources :

Example 1 with OperatorType

use of com.googlecode.aviator.lexer.token.OperatorType 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);
}
Also used : AviatorFunction(com.googlecode.aviator.runtime.type.AviatorFunction) OperatorIR(com.googlecode.aviator.code.interpreter.ir.OperatorIR) OperatorType(com.googlecode.aviator.lexer.token.OperatorType)

Example 2 with OperatorType

use of com.googlecode.aviator.lexer.token.OperatorType in project aviatorscript by killme2008.

the class OptimizeCodeGenerator method execute.

private int execute() {
    int exeCount = 0;
    final int size = this.tokenList.size();
    printTokenList();
    for (int i = 0; i < size; i++) {
        Token<?> token = this.tokenList.get(i);
        if (token.getType() == TokenType.Operator) {
            final OperatorToken op = (OperatorToken) token;
            final OperatorType operatorType = op.getOperatorType();
            final int operandCount = operatorType.getArity();
            switch(operatorType) {
                case FUNC:
                case INDEX:
                    // Could not optimize function and index call
                    break;
                default:
                    Map<Integer, DelegateTokenType> index2DelegateType = getIndex2DelegateTypeMap(operatorType);
                    final int result = executeOperator(index2DelegateType, token, operatorType, i, operandCount);
                    if (result < 0) {
                        compactTokenList();
                        return exeCount;
                    }
                    exeCount += result;
                    break;
            }
        }
    }
    compactTokenList();
    return exeCount;
}
Also used : OperatorToken(com.googlecode.aviator.lexer.token.OperatorToken) OperatorType(com.googlecode.aviator.lexer.token.OperatorType) DelegateTokenType(com.googlecode.aviator.lexer.token.DelegateToken.DelegateTokenType)

Example 3 with OperatorType

use of com.googlecode.aviator.lexer.token.OperatorType in project aviatorscript by killme2008.

the class ASMCodeGenerator method onAssignment.

@Override
public void onAssignment(final Token<?> lookhead) {
    visitLineNumber(lookhead);
    OperatorType opType = lookhead.getMeta(Constants.DEFINE_META, false) ? OperatorType.DEFINE : OperatorType.ASSIGNMENT;
    loadEnv();
    if (!OperationRuntime.hasRuntimeContext(this.compileEnv, opType)) {
        String methodName = (opType == OperatorType.DEFINE) ? "defineValue" : "setValue";
        this.mv.visitMethodInsn(INVOKEVIRTUAL, OBJECT_OWNER, methodName, "(Lcom/googlecode/aviator/runtime/type/AviatorObject;Ljava/util/Map;)Lcom/googlecode/aviator/runtime/type/AviatorObject;");
    } else {
        loadOpType(opType);
        this.mv.visitMethodInsn(INVOKESTATIC, "com/googlecode/aviator/runtime/op/OperationRuntime", "eval", "(Lcom/googlecode/aviator/runtime/type/AviatorObject;Lcom/googlecode/aviator/runtime/type/AviatorObject;Ljava/util/Map;Lcom/googlecode/aviator/lexer/token/OperatorType;)Lcom/googlecode/aviator/runtime/type/AviatorObject;");
        this.popOperand();
    }
    this.popOperand(3);
    this.pushOperand();
}
Also used : OperatorType(com.googlecode.aviator.lexer.token.OperatorType)

Aggregations

OperatorType (com.googlecode.aviator.lexer.token.OperatorType)3 OperatorIR (com.googlecode.aviator.code.interpreter.ir.OperatorIR)1 DelegateTokenType (com.googlecode.aviator.lexer.token.DelegateToken.DelegateTokenType)1 OperatorToken (com.googlecode.aviator.lexer.token.OperatorToken)1 AviatorFunction (com.googlecode.aviator.runtime.type.AviatorFunction)1