@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(); }
/** * This method peforms the equivilent of an XSWAP operation to flip the operator * over to the top of the stack, and loads the stored values on the d-stack onto * the main program stack. */ private void reduceRight() { if (dStack.isEmpty()) return; Object o = stk.pop(); stk.push(dStack.pop(), o, dStack.pop()); reduce(); }
public ExecutionStack getRelPath() { if (relPath == null) { relPath = new ExecutionStack(); relPath.push(baseDir); } return relPath; } }
stk.discard(); if (stk.isEmpty()) { if ((tk.fields & ASTNode.STACKLANG) != 0) { stk.push(tk.getReducedValue(stk, ctx, variableFactory)); Object o = stk.peek(); if (o instanceof Integer) { arithmeticFunctionReduction((Integer) o); stk.push(tk.getReducedValue(ctx, ctx, variableFactory)); stk.push(nextToken().getReducedValue(ctx, ctx, variableFactory), operator); return stk.peek(); else continue; return stk.pop(); case RETURN: variableFactory.setTiltFlag(true); return stk.pop(); case OP_TERMINATE: return stk.peek(); case OP_RESET_FRAME: continue; case OP_OVERFLOW: if (!tk.isOperator()) { if (!(stk.peek() instanceof Class)) {
ExecutionStack stk = new ExecutionStack(); else if (stk.isEmpty()) { stk.push(tk.getReducedValueAccelerated(ctx, ctx, variableFactory)); if (!stk.popBoolean()) { stk.clear(); continue; return stk.pop(); stk.clear(); stk.push(tk.nextASTNode.getReducedValueAccelerated(ctx, ctx, variableFactory), operator); 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); stk.op();
System.out.println(stack.toString() + " >> " + instruction.opcode + ":" + instruction.expr); case Operator.STORE: if (instruction.cache == null) { instruction.cache = factory.createVariable(instruction.expr, stack.peek()); ((VariableResolver) instruction.cache).setValue(stack.peek()); 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); instruction.cache = field = ((Class) stack.pop()).getField(instruction.expr); stack.discard(); field = (Field) instruction.cache; stack.push(field.get(stack.pop())); 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();
stk.xswap(); splitAccumulator.push(tk); splitAccumulator.push(new OperatorNode(operator2)); return tk instanceof Substatement ? -2 : OP_TERMINATE; dStack.push(operator = operator2, tk.getReducedValue(ctx, ctx, variableFactory)); if (dStack.isReduceable()) { stk.copyx2(dStack); dStack.push(operator = operator2, nextToken().getReducedValue(ctx, ctx, variableFactory)); if (!dStack.isEmpty()) dreduce(); else { while (stk.isReduceable()) { stk.xswap_op(); dStack.push(operator = operator2, nextToken().getReducedValue(ctx, ctx, variableFactory)); while (dStack.size() > 1) { dreduce(); while (stk.size() != 1 && stk.peek2() instanceof Integer && ((operator2 = (Integer) stk.peek2()) < PTABLE.length) && PTABLE[operator2] >= PTABLE[operator]) { stk.xswap_op(); if (dStack.size() > 1) {
if (!stk.peekBoolean()) { if (unwindStatement(operator)) { return -1; stk.clear(); return OP_RESET_FRAME; stk.discard(); return OP_RESET_FRAME; if (stk.peekBoolean()) { if (unwindStatement(operator)) { return OP_TERMINATE; stk.clear(); return OP_RESET_FRAME; stk.discard(); return OP_RESET_FRAME; if (!BlankLiteral.INSTANCE.equals(stk.peek())) { return OP_TERMINATE; if (!stk.popBoolean()) { stk.clear(); holdOverRegister = stk.pop(); stk.clear();
int operator; try { switch (operator = (Integer) stk.pop()) { case ADD: case SUB: case LETHAN: case POWER: stk.op(operator); break; v1 = stk.pop(); stk.push(((Boolean) stk.pop()) && ((Boolean) v1)); break; v1 = stk.pop(); stk.push(((Boolean) stk.pop()) || ((Boolean) v1)); break; v1 = stk.pop(); if (!isEmpty(v2 = stk.pop()) || !isEmpty(v1)) { stk.clear(); stk.push(!isEmpty(v2) ? v2 : v1); return; else stk.push(null); break; stk.push(java.util.regex.Pattern.compile(java.lang.String.valueOf(stk.pop()))
stk = new ExecutionStack(); dStack = new ExecutionStack(); compileMode = true; && tkOp.getOperator() < 34 && ((lastOp == -1 || (lastOp < PTABLE.length && PTABLE[lastOp] < PTABLE[tkOp.getOperator()])))) { stk.push(tk.getLiteralValue(), tkLA.getLiteralValue(), op = tkOp.getOperator()); astBuild.addTokenNode(new LiteralNode(stk.pop(), pCtx), verify(pCtx, tkOp2)); break; stk.push(tkLA2.getLiteralValue(), op = tkOp2.getOperator()); if (!stk.isEmpty()) { astBuild.addTokenNode(new LiteralNode(getStackValueResult(), pCtx)); if (!stk.isEmpty()) astBuild.addTokenNode(new LiteralNode(getStackValueResult(), pCtx)); if (!stk.isEmpty()) { throw new CompileException("COMPILE ERROR: non-empty stack after compileShared.", expr, cursor);
splitAccumulator.add(new DeclTypedVarNode(new String(expr, st, cursor - st), expr, st, cursor - st, (Class) lastNode.getLiteralValue(), fields | ASTNode.ASSIGN, pCtx)); splitAccumulator.add(new TypedVarNode(expr, st, cursor - st - 1, fields | ASTNode.ASSIGN, (Class) lastNode.getLiteralValue(), pCtx)); captureToEOS(); if (decl) { splitAccumulator.add(new DeclProtoVarNode(new String(expr, st, cursor - st), (Proto) lastNode, fields | ASTNode.ASSIGN, pCtx)); splitAccumulator.add(new ProtoVarNode(expr, st, cursor - st, fields | ASTNode.ASSIGN, (Proto) lastNode, pCtx)); if (stk.peek() instanceof Class) { captureToEOS(); if (decl) { splitAccumulator.add(new DeclTypedVarNode(new String(expr, st, cursor - st), expr, st, cursor - st, (Class) stk.pop(), fields | ASTNode.ASSIGN, pCtx)); splitAccumulator.add(new TypedVarNode(expr, st, cursor - st, fields | ASTNode.ASSIGN, (Class) stk.pop(), pCtx)); else if (stk.peek() instanceof Proto) { captureToEOS(); if (decl) { splitAccumulator.add(new DeclProtoVarNode(new String(expr, st, cursor - st), (Proto) stk.pop(), fields | ASTNode.ASSIGN, pCtx));
public static String readInFile(TemplateRuntime runtime, String fileName) { File file = new File(String.valueOf(runtime.getRelPath().peek()) + "/" + fileName); BufferedInputStream bufstream = new BufferedInputStream(instream); runtime.getRelPath().push(file.getParent()); instream.close(); runtime.getRelPath().pop();
if (!splitAccumulator.isEmpty()) { lastNode = (ASTNode) splitAccumulator.pop(); if (cursor >= end && lastNode instanceof EndOfStatement) { return nextToken(); name = new String(expr, st, end - st); if (pCtx != null && (idx = pCtx.variableIndexOf(name)) != -1) { splitAccumulator.add(lastNode = new IndexedDeclTypedVarNode(idx, st, end - st, Object.class, pCtx)); splitAccumulator.add(lastNode = new DeclTypedVarNode(name, expr, st, end - st, Object.class, fields, pCtx)); return (ASTNode) splitAccumulator.pop();
private void reduce(long op1, int operator, long op2) { switch (operator) { case BW_AND: stk.push(op1 & op2); break; case BW_OR: stk.push(op1 | op2); break; case BW_XOR: stk.push(op1 ^ op2); break; case BW_SHIFT_LEFT: stk.push(op1 << op2); break; case BW_USHIFT_LEFT: long iv2 = op1; if (iv2 < 0) iv2 *= -1; stk.push(iv2 << op2); break; case BW_SHIFT_RIGHT: stk.push(op1 >> op2); break; case BW_USHIFT_RIGHT: stk.push(op1 >>> op2); break; } }
private boolean compileReduce(int opCode, ASTLinkedList astBuild) { switch (arithmeticFunctionReduction(opCode)) { case -1: /** * The reduction failed because we encountered a non-literal, * so we must now back out and cleanup. */ stk.xswap_op(); astBuild.addTokenNode(new LiteralNode(stk.pop(), pCtx)); astBuild.addTokenNode( (OperatorNode) splitAccumulator.pop(), verify(pCtx, (ASTNode) splitAccumulator.pop()) ); return false; case -2: /** * Back out completely, pull everything back off the stack and add the instructions * to the output payload as they are. */ LiteralNode rightValue = new LiteralNode(stk.pop(), pCtx); OperatorNode operator = new OperatorNode((Integer) stk.pop(), expr, st, pCtx); astBuild.addTokenNode(new LiteralNode(stk.pop(), pCtx), operator); astBuild.addTokenNode(rightValue, (OperatorNode) splitAccumulator.pop()); astBuild.addTokenNode(verify(pCtx, (ASTNode) splitAccumulator.pop())); } return true; }
private static Object peek() { return relativePathStack.get().peek(); }
public CompiledTemplate compile() { return new CompiledTemplate(template, compileFrom(null, new ExecutionStack())); }