More Arithmetic, Better sectioning of code
This commit is contained in:
46
machine.hpp
46
machine.hpp
@@ -31,6 +31,9 @@ enum : int {
|
||||
// Two Arguments
|
||||
IncrementBy,
|
||||
DecrementBy,
|
||||
MultiplyBy,
|
||||
DivideBy,
|
||||
ModulusBy,
|
||||
SetTo,
|
||||
Print,
|
||||
|
||||
@@ -57,21 +60,29 @@ private:
|
||||
void Execute(int command) {
|
||||
switch (State) {
|
||||
case NoCommand:
|
||||
break;
|
||||
|
||||
case IncrementBy:
|
||||
memory[currentPosition] += command;
|
||||
State = NoCommand;
|
||||
processCommand(command);
|
||||
return;
|
||||
|
||||
case DecrementBy:
|
||||
memory[currentPosition] -= command;
|
||||
State = NoCommand;
|
||||
return;
|
||||
// Arithmatic
|
||||
case SetTo:
|
||||
memory[currentPosition] = command;
|
||||
State = NoCommand;
|
||||
return;
|
||||
break;
|
||||
case IncrementBy:
|
||||
memory[currentPosition] += command;
|
||||
break;
|
||||
case DecrementBy:
|
||||
memory[currentPosition] -= command;
|
||||
break;
|
||||
case MultiplyBy:
|
||||
memory[currentPosition] *= command;
|
||||
break;
|
||||
case DivideBy:
|
||||
memory[currentPosition] /= command;
|
||||
break;
|
||||
case ModulusBy:
|
||||
memory[currentPosition] %= command;
|
||||
break;
|
||||
|
||||
case Print:
|
||||
handlePrint(command);
|
||||
State = NoCommand;
|
||||
@@ -82,7 +93,14 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
// State: NoCommand
|
||||
// This is only called after multi-argument functions are done
|
||||
if (State != NoCommand) {
|
||||
State = NoCommand;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void processCommand(int command) {
|
||||
switch (command) {
|
||||
case MoveLeft:
|
||||
// Underflow wrap
|
||||
@@ -106,8 +124,12 @@ private:
|
||||
|
||||
// Double Argument Commands
|
||||
case Print:
|
||||
case SetTo:
|
||||
case IncrementBy:
|
||||
case DecrementBy:
|
||||
case MultiplyBy:
|
||||
case DivideBy:
|
||||
case ModulusBy:
|
||||
State = static_cast<Command>(command);
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user