Interface PushDownMachine
- All Known Implementing Classes:
SingleThreadPushDownMachine
A stack-based machine which can perform mathematical calculations as part of the QubecTalk runtime. It assumes that units provided are appropriately converted prior to pushing. It also can perform logical operations like ternary operations.
-
Method Summary
Modifier and TypeMethodDescriptionvoidadd()Add the two numbers on top of the stack.voidand()Perform a logical AND operation on the two numbers on top of the stack.voidchangeUnits(String units) Change the units of the number at the top of the stack.voidchangeUnits(String units, boolean force) Change the units of the number at the top of the stack, optionally forcing the change.voiddivide()Divide the two numbers on top of the stack.voidDraw a random number from a normal distribution.voidDraw a random number from a uniform distribution.voidequals()Perform an equality comparison on the two numbers on top of the stack.Get the engine in which this machine is running.Get the result of the machine's calculations.voidPerform a greater-than comparison on the two numbers on top of the stack.voidPerform a greater-than-or-equal comparison on the two numbers on top of the stack.voidlessThan()Perform a less-than comparison on the two numbers on top of the stack.voidPerform a less-than-or-equal comparison on the two numbers on top of the stack.voidmultiply()Multiply the two numbers on top of the stack.voidPerform a not-equals comparison on the two numbers on top of the stack.voidor()Perform a logical OR operation on the two numbers on top of the stack.voidpower()Raise a number to a power.voidpush(EngineNumber value) Push a number onto the machine's stack.voidsubtract()Subtract the two numbers on top of the stack.voidxor()Perform a logical XOR operation on the two numbers on top of the stack.
-
Method Details
-
push
Push a number onto the machine's stack.- Parameters:
value- The value to push.
-
getResult
EngineNumber getResult()Get the result of the machine's calculations.- Returns:
- The result of the calculations.
- Throws:
RuntimeException- if the machine does not have exactly one result waiting at the top of its stack.
-
add
void add()Add the two numbers on top of the stack.Add the two numbers on top of the stack, pushing the result of the calculation to the top of the stack.
-
subtract
void subtract()Subtract the two numbers on top of the stack.Subtract the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
-
multiply
void multiply()Multiply the two numbers on top of the stack.Multiply the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
-
divide
void divide()Divide the two numbers on top of the stack.Divide the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Throws:
ArithmeticException- If the right operand (divisor) is zero.
-
changeUnits
Change the units of the number at the top of the stack.- Parameters:
units- The new units for the number at the top of the stack.- Throws:
RuntimeException- If the stack is empty or the top value already has units which do not match the desired units.
-
changeUnits
Change the units of the number at the top of the stack, optionally forcing the change.- Parameters:
units- The new units for the number at the top of the stack.force- If true, force the unit change even if the current units do not match.- Throws:
RuntimeException- If the stack is empty, or if force is false and the top value already has units which do not match the desired units.
-
getEngine
Engine getEngine()Get the engine in which this machine is running.- Returns:
- The engine in which this machine is running.
-
and
void and()Perform a logical AND operation on the two numbers on top of the stack.Perform a logical AND operation on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below. Non-zero values are treated as true, zero values as false.
-
or
void or()Perform a logical OR operation on the two numbers on top of the stack.Perform a logical OR operation on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below. Non-zero values are treated as true, zero values as false.
-
xor
void xor()Perform a logical XOR operation on the two numbers on top of the stack.Perform a logical XOR operation on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below. Non-zero values are treated as true, zero values as false.
-
equals
void equals()Perform an equality comparison on the two numbers on top of the stack.Perform an equality comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
-
notEquals
void notEquals()Perform a not-equals comparison on the two numbers on top of the stack.Perform a not-equals comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
-
greaterThan
void greaterThan()Perform a greater-than comparison on the two numbers on top of the stack.Perform a greater-than comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
-
lessThan
void lessThan()Perform a less-than comparison on the two numbers on top of the stack.Perform a less-than comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
-
greaterThanOrEqual
void greaterThanOrEqual()Perform a greater-than-or-equal comparison on the two numbers on top of the stack.Perform a greater-than-or-equal comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
-
lessThanOrEqual
void lessThanOrEqual()Perform a less-than-or-equal comparison on the two numbers on top of the stack.Perform a less-than-or-equal comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
-
drawNormal
void drawNormal()Draw a random number from a normal distribution.Draw a random number from a normal distribution using the two numbers on top of the stack as the mean and standard deviation. The right operand (top of stack) is the standard deviation and the left operand (next on stack) is the mean. Pushes the sampled value to the top of the stack.
-
drawUniform
void drawUniform()Draw a random number from a uniform distribution.Draw a random number from a uniform distribution using the two numbers on top of the stack as the low and high bounds. The right operand (top of stack) is the high bound and the left operand (next on stack) is the low bound. Pushes the sampled value to the top of the stack.
-
power
void power()Raise a number to a power.The right operand (top of stack) is the power and the left operand is the base (next on stack). Goes through double.
-