Compare commits
2 Commits
f38a131146
...
e8850f37bc
| Author | SHA1 | Date | |
|---|---|---|---|
| e8850f37bc | |||
| 19b6306927 |
45
machine.hpp
45
machine.hpp
@@ -35,9 +35,16 @@ enum : int {
|
||||
DivideBy,
|
||||
ModulusBy,
|
||||
SetTo,
|
||||
JumpTo,
|
||||
Print,
|
||||
StoreValueIn,
|
||||
PutValueIn,
|
||||
|
||||
// Type
|
||||
W,
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
AsDigit,
|
||||
AsUnsignedDigit,
|
||||
AsCharacter,
|
||||
@@ -54,7 +61,7 @@ public:
|
||||
private:
|
||||
Command State = NoCommand;
|
||||
std::array<int, maxCells> memory;
|
||||
int W = 0, X = 0, Y = 0, Z = 0;
|
||||
int RW = 0, RX = 0, RY = 0, RZ = 0;
|
||||
std::size_t currentPosition = 0;
|
||||
|
||||
void Execute(int command) {
|
||||
@@ -63,7 +70,7 @@ private:
|
||||
processCommand(command);
|
||||
return;
|
||||
|
||||
// Arithmatic
|
||||
// Arithmetic
|
||||
case SetTo:
|
||||
memory[currentPosition] = command;
|
||||
break;
|
||||
@@ -83,10 +90,21 @@ private:
|
||||
memory[currentPosition] %= command;
|
||||
break;
|
||||
|
||||
case JumpTo:
|
||||
currentPosition = command;
|
||||
break;
|
||||
|
||||
case StoreValueIn:
|
||||
whichRegistry(command) = memory[currentPosition];
|
||||
break;
|
||||
|
||||
case PutValueIn:
|
||||
memory[currentPosition] = whichRegistry(command);
|
||||
break;
|
||||
|
||||
case Print:
|
||||
handlePrint(command);
|
||||
State = NoCommand;
|
||||
return;
|
||||
break;
|
||||
|
||||
default:
|
||||
std::terminate();
|
||||
@@ -124,7 +142,10 @@ private:
|
||||
|
||||
// Double Argument Commands
|
||||
case Print:
|
||||
case JumpTo:
|
||||
case SetTo:
|
||||
case StoreValueIn:
|
||||
case PutValueIn:
|
||||
case IncrementBy:
|
||||
case DecrementBy:
|
||||
case MultiplyBy:
|
||||
@@ -140,6 +161,22 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
int &whichRegistry(int Type) {
|
||||
switch (Type) {
|
||||
case W:
|
||||
return RW;
|
||||
case X:
|
||||
return RX;
|
||||
case Y:
|
||||
return RY;
|
||||
case Z:
|
||||
return RZ;
|
||||
|
||||
default:
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
|
||||
void handlePrint(int Type) {
|
||||
switch (Type) {
|
||||
case AsDigit:
|
||||
|
||||
Reference in New Issue
Block a user