void InstructionStack::exit(OperandStack & stack) { while (!stack.empty()) { IOperand const * op = stack.top(); stack.pop(); delete op; } m_exitProperly = true; }
void VMachine::showStack(){ int o; OperandStack tmpStack; while(!operstack.empty()){ o = operstack.top(); operstack.pop(); printf("ip = %d\t",ip); printObj(ObjTable[o]); printf("\n"); tmpStack.push(o); } while(!tmpStack.empty()){ operstack.push(tmpStack.top()); tmpStack.pop(); } }
void InstructionStack::assert(OperandStack & stack, std::string const & value, eOperandType type) { IOperand const * op = Factory::getInstance().createOperand(type, value); IOperand const * res = *op - *stack.top(); if (res->toString().compare("0")) throw AssertException(op->toString()); }
void InstructionStack::mod(OperandStack & stack) { if (stack.size() < 2) throw NotEnoughValueException(); IOperand const * op1 = stack.top(); stack.pop(); IOperand const * op2 = stack.top(); stack.pop(); stack.push(*op2 % *op1); delete op1; delete op2; }
void InstructionStack::push(OperandStack & stack, std::string const & value, eOperandType type) { stack.push(Factory::getInstance().createOperand(type, value)); }
void InstructionStack::print(OperandStack & stack) { if (stack.top()->getType() != eOperandType::Int8) throw PrintFailedException(stack.top()->toString()); std::cout << static_cast<char>(std::atoi(stack.top()->toString().c_str())) << std::endl; }
void InstructionStack::dump(OperandStack & stack) { for (int i = stack.size() - 1; i >= 0; i--) std::cout << stack[i]->toString() << std::endl; }
void InstructionStack::pop(OperandStack & stack) { if (stack.empty()) throw EmptyStackException(); stack.pop(); }