Setting values on registries
This commit is contained in:
22
machine.hpp
22
machine.hpp
@@ -37,8 +37,11 @@ enum : int {
|
||||
SetTo,
|
||||
JumpTo,
|
||||
Print,
|
||||
|
||||
// Registry
|
||||
StoreValueIn,
|
||||
PutValueIn,
|
||||
SetValueIn, // Three Argumens!!
|
||||
|
||||
// Type
|
||||
W,
|
||||
@@ -60,6 +63,7 @@ public:
|
||||
|
||||
private:
|
||||
Command State = NoCommand;
|
||||
int selectedRegistry = 0;
|
||||
std::array<int, maxCells> memory;
|
||||
int RW = 0, RX = 0, RY = 0, RZ = 0;
|
||||
std::size_t currentPosition = 0;
|
||||
@@ -97,10 +101,17 @@ private:
|
||||
case StoreValueIn:
|
||||
whichRegistry(command) = memory[currentPosition];
|
||||
break;
|
||||
|
||||
case PutValueIn:
|
||||
memory[currentPosition] = whichRegistry(command);
|
||||
break;
|
||||
case SetValueIn:
|
||||
if (selectedRegistry == 0) {
|
||||
selectedRegistry = command;
|
||||
return;
|
||||
}
|
||||
whichRegistry(selectedRegistry) = command;
|
||||
selectedRegistry = 0;
|
||||
break;
|
||||
|
||||
case Print:
|
||||
handlePrint(command);
|
||||
@@ -112,7 +123,7 @@ private:
|
||||
}
|
||||
|
||||
// This is only called after multi-argument functions are done
|
||||
if (State != NoCommand) {
|
||||
if (State != NoCommand && selectedRegistry == 0) {
|
||||
State = NoCommand;
|
||||
return;
|
||||
}
|
||||
@@ -140,12 +151,15 @@ private:
|
||||
--memory[currentPosition];
|
||||
return;
|
||||
|
||||
// Double Argument Commands
|
||||
// Multi Argument Commands
|
||||
case Print:
|
||||
case JumpTo:
|
||||
case SetTo:
|
||||
|
||||
case StoreValueIn:
|
||||
case PutValueIn:
|
||||
case SetValueIn:
|
||||
|
||||
case SetTo:
|
||||
case IncrementBy:
|
||||
case DecrementBy:
|
||||
case MultiplyBy:
|
||||
|
||||
Reference in New Issue
Block a user