Examples of ExecutionStack


Examples of org.mvel2.util.ExecutionStack

    return stk.peek();
  }

  @Override
  public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
    ExecutionStack stack = (ExecutionStack) ctx;

    for (int i1 = 0, instructionListSize = instructionList.size(); i1 < instructionListSize; i1++) {
      Instruction instruction = instructionList.get(i1);

      System.out.println(stack.toString() + " >> " + instruction.opcode + ":" + instruction.expr);


      switch (instruction.opcode) {
        case Operator.STORE:
          if (instruction.cache == null) {
            instruction.cache = factory.createVariable(instruction.expr, stack.peek());
          }
          else {
            ((VariableResolver) instruction.cache).setValue(stack.peek());
          }
          break;
        case Operator.LOAD:
          if (instruction.cache == null) {
            instruction.cache = factory.getVariableResolver(instruction.expr);
          }
          stack.push(((VariableResolver) instruction.cache).getValue());
          break;
        case Operator.GETFIELD:
          try {
            if (stack.isEmpty() || !(stack.peek() instanceof Class)) {
              throw new CompileException("getfield without class", expr, blockStart);
            }

            Field field;
            if (instruction.cache == null) {
              instruction.cache = field = ((Class) stack.pop()).getField(instruction.expr);
            }
            else {
              stack.discard();
              field = (Field) instruction.cache;
            }

            stack.push(field.get(stack.pop()));
          }
          catch (Exception e) {
            throw new CompileException("field access error", expr, blockStart, e);
          }
          break;
        case Operator.STOREFIELD:
          try {
            if (stack.isEmpty() || !(stack.peek() instanceof Class)) {
              throw new CompileException("storefield without class", expr, blockStart);
            }

            Class cls = (Class) stack.pop();
            Object val = stack.pop();
            cls.getField(instruction.expr).set(stack.pop(), val);
            stack.push(val);
          }
          catch (Exception e) {
            throw new CompileException("field access error", expr, blockStart, e);
          }
          break;

        case Operator.LDTYPE:
          try {
            if (instruction.cache == null) {
              instruction.cache = ParseTools.createClass(instruction.expr, pCtx);
            }
            stack.push(instruction.cache);
          }
          catch (ClassNotFoundException e) {
            throw new CompileException("error", expr, blockStart, e);
          }
          break;

        case Operator.INVOKE:
          Object[] parms;
          ExecutionStack call = new ExecutionStack();
          while (!stack.isEmpty() && !(stack.peek() instanceof Class)) {
            call.push(stack.pop());
          }
          if (stack.isEmpty()) {
            throw new CompileException("invoke without class", expr, blockStart);
          }

          parms = new Object[call.size()];
          for (int i = 0; !call.isEmpty(); i++) parms[i] = call.pop();

          if ("<init>".equals(instruction.expr)) {
            Constructor c;
            if (instruction.cache == null) {
              instruction.cache = c = ParseTools.getBestConstructorCandidate(parms, (Class) stack.pop(), false);
View Full Code Here

Examples of org.mvel2.util.ExecutionStack

    this.pCtx = pCtx;
  }

  @Override
  public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
    ExecutionStack stk = new ExecutionStack();
    stk.push(getReducedValue(stk, thisValue, factory));
    if (stk.isReduceable()) {
      while (true) {
        stk.op();
        if (stk.isReduceable()) {
          stk.xswap();
        }
        else {
          break;
        }
      }
    }
    return stk.peek();
  }
View Full Code Here

Examples of org.mvel2.util.ExecutionStack

   */
  public static Object execute(boolean debugger, final CompiledExpression expression, final Object ctx,
                               VariableResolverFactory variableFactory) {

    Object v1, v2;
    ExecutionStack stk = new ExecutionStack();

    ASTNode tk = expression.getFirstNode();
    Integer operator;

    if (tk == null) return null;
    try {
      do {
        if (tk.fields == -1) {
          /**
           * This may seem silly and redundant, however, when an MVEL script recurses into a block
           * or substatement, a new runtime loop is entered.   Since the debugger state is not
           * passed through the AST, it is not possible to forward the state directly.  So when we
           * encounter a debugging symbol, we check the thread local to see if there is are registered
           * breakpoints.  If we find them, we assume that we are debugging.
           *
           * The consequence of this of course, is that it's not ideal to compileShared expressions with
           * debugging symbols which you plan to use in a production enviroment.
           */
          if (debugger || (debugger = hasDebuggerContext())) {
            try {
              debuggerContext.get().checkBreak((LineLabel) tk, variableFactory, expression);
            }
            catch (NullPointerException e) {
              // do nothing for now.  this isn't as calus as it seems.
            }
          }
          continue;
        }
        else if (stk.isEmpty()) {
          stk.push(tk.getReducedValueAccelerated(ctx, ctx, variableFactory));
        }

        if (variableFactory.tiltFlag()) {
          return stk.pop();
        }

        switch (operator = tk.getOperator()) {
          case RETURN:
            variableFactory.setTiltFlag(true);
            return stk.pop();

          case NOOP:
            continue;

          case TERNARY:
            if (!stk.popBoolean()) {
              //noinspection StatementWithEmptyBody
              while (tk.nextASTNode != null && !(tk = tk.nextASTNode).isOperator(TERNARY_ELSE)) ;
            }
            stk.clear();
            continue;

          case TERNARY_ELSE:
            return stk.pop();

          case END_OF_STMT:
            /**
             * If the program doesn't end here then we wipe anything off the stack that remains.
             * Althought it may seem like intuitive stack optimizations could be leveraged by
             * leaving hanging values on the stack,  trust me it's not a good idea.
             */
            if (tk.nextASTNode != null) {
              stk.clear();
            }

            continue;
        }

        stk.push(tk.nextASTNode.getReducedValueAccelerated(ctx, ctx, variableFactory), operator);

        try {
          while (stk.isReduceable()) {
            if ((Integer) stk.peek() == CHOR) {
              stk.pop();
              v1 = stk.pop();
              v2 = stk.pop();
              if (!isEmpty(v2) || !isEmpty(v1)) {
                stk.clear();
                stk.push(!isEmpty(v2) ? v2 : v1);
              }
              else stk.push(null);
            }
            else {
              stk.op();
            }
          }
        }
        catch (ClassCastException e) {
          throw new CompileException("syntax error or incomptable types", new char[0], 0, e);
        }
        catch (CompileException e) {
          throw e;
        }
        catch (Exception e) {
          throw new CompileException("failed to compileShared sub expression", new char[0], 0, e);
        }
      }
      while ((tk = tk.nextASTNode) != null);

      return stk.peek();
    }
    catch (NullPointerException e) {
      if (tk != null && tk.isOperator() && tk.nextASTNode != null) {
        throw new CompileException("incomplete statement: "
            + tk.getName() + " (possible use of reserved keyword as identifier: " + tk.getName() + ")", tk.getExpr(), tk.getStart());
View Full Code Here

Examples of org.mvel2.util.ExecutionStack

    this.namedTemplateRegistry = namedTemplateRegistry;
  }

  public ExecutionStack getRelPath() {
    if (relPath == null) {
      relPath = new ExecutionStack();
      relPath.push(baseDir);
    }
    return relPath;
  }
View Full Code Here

Examples of org.mvel2.util.ExecutionStack

*/
@SuppressWarnings({"CaughtExceptionImmediatelyRethrown"})
public class MVELInterpretedRuntime extends AbstractParser {
  public Object parse() {
    try {
      stk = new ExecutionStack();
      dStack = new ExecutionStack();
      variableFactory.setTiltFlag(false);
      cursor = start;
      return parseAndExecuteInterpreted();
    }
    catch (ArrayIndexOutOfBoundsException e) {
View Full Code Here

Examples of org.mvel2.util.ExecutionStack

    OPCODES.put("stop", Opcodes.STOP);
  }


  public CompiledTemplate compile() {
    return new CompiledTemplate(template, compileFrom(null, new ExecutionStack()));
  }
View Full Code Here

Examples of org.mvel2.util.ExecutionStack

*/
@SuppressWarnings({"CaughtExceptionImmediatelyRethrown"})
public class MVELInterpretedRuntime extends AbstractParser {
  public Object parse() {
    try {
      stk = new ExecutionStack();
      dStack = new ExecutionStack();
      variableFactory.setTiltFlag(false);
      cursor = start;
      return parseAndExecuteInterpreted();
    }
    catch (ArrayIndexOutOfBoundsException e) {
View Full Code Here

Examples of org.mvel2.util.ExecutionStack

   */
  public static Object execute(boolean debugger, final CompiledExpression expression, final Object ctx,
                               VariableResolverFactory variableFactory) {

    Object v1, v2;
    ExecutionStack stk = new ExecutionStack();
    variableFactory.setTiltFlag(false);

    ASTNode tk = expression.getFirstNode();
    Integer operator;

    if (tk == null) return null;
    try {
      do {
        if (tk.fields == -1) {
          /**
           * This may seem silly and redundant, however, when an MVEL script recurses into a block
           * or substatement, a new runtime loop is entered.   Since the debugger state is not
           * passed through the AST, it is not possible to forward the state directly.  So when we
           * encounter a debugging symbol, we check the thread local to see if there is are registered
           * breakpoints.  If we find them, we assume that we are debugging.
           *
           * The consequence of this of course, is that it's not ideal to compileShared expressions with
           * debugging symbols which you plan to use in a production enviroment.
           */
          if (debugger || (debugger = hasDebuggerContext())) {
            try {
              debuggerContext.get().checkBreak((LineLabel) tk, variableFactory, expression);
            }
            catch (NullPointerException e) {
              // do nothing for now.  this isn't as calus as it seems.
            }
          }
          continue;
        }
        else if (stk.isEmpty()) {
          stk.push(tk.getReducedValueAccelerated(ctx, ctx, variableFactory));
        }

        if (variableFactory.tiltFlag()) {
          return stk.pop();
        }

        switch (operator = tk.getOperator()) {
          case RETURN:
            variableFactory.setTiltFlag(true);
            return stk.pop();
          //     throw new EndWithValue(stk.pop());

          case NOOP:
            continue;

          case TERNARY:
            if (!stk.popBoolean()) {
              //noinspection StatementWithEmptyBody
              while (tk.nextASTNode != null && !(tk = tk.nextASTNode).isOperator(TERNARY_ELSE)) ;
            }
            stk.clear();
            continue;

          case TERNARY_ELSE:
            return stk.pop();

          case END_OF_STMT:
            /**
             * If the program doesn't end here then we wipe anything off the stack that remains.
             * Althought it may seem like intuitive stack optimizations could be leveraged by
             * leaving hanging values on the stack,  trust me it's not a good idea.
             */
            if (tk.nextASTNode != null) {
              stk.clear();
            }

            continue;
        }

        stk.push(tk.nextASTNode.getReducedValueAccelerated(ctx, ctx, variableFactory), operator);

        try {
          while (stk.isReduceable()) {
            if ((Integer) stk.peek() == CHOR) {
              stk.pop();
              v1 = stk.pop();
              v2 = stk.pop();
              if (!isEmpty(v2) || !isEmpty(v1)) {
                stk.clear();
                stk.push(!isEmpty(v2) ? v2 : v1);
              }
              else stk.push(null);
            }
            else {
              stk.op();
            }
          }
        }
        catch (ClassCastException e) {
          throw new CompileException("syntax error or incomptable types", new char[0], 0, e);
        }
        catch (CompileException e) {
          throw e;
        }
        catch (Exception e) {
          throw new CompileException("failed to compileShared sub expression", new char[0], 0, e);
        }
      }
      while ((tk = tk.nextASTNode) != null);

      return stk.peek();
    }
    catch (NullPointerException e) {
      if (tk != null && tk.isOperator() && tk.nextASTNode != null) {
        throw new CompileException("incomplete statement: "
            + tk.getName() + " (possible use of reserved keyword as identifier: " + tk.getName() + ")", tk.getExpr(), tk.getStart());
View Full Code Here

Examples of org.mvel2.util.ExecutionStack

    this.namedTemplateRegistry = namedTemplateRegistry;
  }

  public ExecutionStack getRelPath() {
    if (relPath == null) {
      relPath = new ExecutionStack();
      relPath.push(baseDir);
    }
    return relPath;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.