More Arithmetic, Better sectioning of code

This commit is contained in:
2026-02-10 02:10:58 +02:00
parent c0e416e030
commit f38a131146

View File

@@ -31,6 +31,9 @@ enum : int {
// Two Arguments // Two Arguments
IncrementBy, IncrementBy,
DecrementBy, DecrementBy,
MultiplyBy,
DivideBy,
ModulusBy,
SetTo, SetTo,
Print, Print,
@@ -57,21 +60,29 @@ private:
void Execute(int command) { void Execute(int command) {
switch (State) { switch (State) {
case NoCommand: case NoCommand:
break; processCommand(command);
case IncrementBy:
memory[currentPosition] += command;
State = NoCommand;
return; return;
case DecrementBy: // Arithmatic
memory[currentPosition] -= command;
State = NoCommand;
return;
case SetTo: case SetTo:
memory[currentPosition] = command; memory[currentPosition] = command;
State = NoCommand; break;
return; 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: case Print:
handlePrint(command); handlePrint(command);
State = NoCommand; State = NoCommand;
@@ -82,7 +93,14 @@ private:
return; 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) { switch (command) {
case MoveLeft: case MoveLeft:
// Underflow wrap // Underflow wrap
@@ -106,8 +124,12 @@ private:
// Double Argument Commands // Double Argument Commands
case Print: case Print:
case SetTo:
case IncrementBy: case IncrementBy:
case DecrementBy: case DecrementBy:
case MultiplyBy:
case DivideBy:
case ModulusBy:
State = static_cast<Command>(command); State = static_cast<Command>(command);
return; return;