Example #1
0
void InstructionStack::exit(OperandStack & stack)
{
	while (!stack.empty())
	{
		IOperand const * op = stack.top();
		stack.pop();
		delete op;
	}
	m_exitProperly = true;
}
Example #2
0
File: vm.cpp Project: pangc/pvm
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();
    }
}
Example #3
0
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());
}
Example #4
0
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;
}
Example #5
0
void InstructionStack::push(OperandStack & stack, std::string const & value, eOperandType type)
{
	stack.push(Factory::getInstance().createOperand(type, value));
}
Example #6
0
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;
}
Example #7
0
void InstructionStack::dump(OperandStack & stack)
{
	for (int i = stack.size() - 1; i >= 0; i--)
		std::cout << stack[i]->toString() << std::endl;
}
Example #8
0
void InstructionStack::pop(OperandStack & stack)
{
	if (stack.empty())
		throw EmptyStackException();
	stack.pop();
}