While details of what you need to implement for this project are in the C++ files, here is a copy in case you need it. The main project page can be found here
Methods to Implement #
-
pushInt(n)
: Creates an integer object on the heap and pushes the pointer on the stack. -
pushPair()
: Pops two pointers from the top of the stack:p_2
thenp_1
and creates a pair object on the heap with componentsp_1
andp_2
. If the stack is empty or only contains one element, aStackException
should be thrown. -
pop()
: Pops an element off the stack. If the stack is empty, aStackException
should be thrown. -
dup()
: Push a copy of the top element of the stack. If the stack is empty, aStackException
should be thrown. -
loadFirst()
: Pops an element from the stack, which is assumed to be a pointer to a pair object, and pushes it’s first component on the stack. If the stack is empty, aStackException
should be thrown. If the top of the stack is not a pointer to a pair, aRuntimeTypeError
should be thrown. -
loadSecond()
: Pops an element from the stack, which is assumed to be a pointer to a pair object, and pushes it’s second component on the stack. If the stack is empty, aStackException
should be thrown. If the top of the stack is not a pointer to a pair, aRuntimeTypeError
should be thrown. -
storeFirst()
: Pops an element from the stack, which is assumed to point to an object, and sets it as the first component of the next element on top of the stack, which is assumed to point to a pair object. If the stack is empty or only contains one element, aStackException
should be thrown. If the second element on the stack is not a pointer to a pair object, aRuntimeTypeError
should be thrown. -
storeSecond()
: Pops an element from the stack, which is assumed to point to an object, and sets it as the second component of the next element on top of the stack, which is assumed to point to a pair object. If the stack is empty or only contains one element, aStackException
should be thrown. If the second element on the stack is not a pointer to a pair object, aRuntimeTypeError
should be thrown. -
add()
: Pops the top two elements from the stack, which are assumed to be pointers to integer objects, and allocates a new integer object on the heap with value equal to the sum of the two integers, and pushes the pointer to the new object onto the stack. If the stack is empty or only contains one element, aStackException
should be thrown. If the elements on top of the stack are not pointers to integer objects, aRuntimeTypeError
should be thrown