Compare commits

..

2 Commits

Author SHA1 Message Date
cat
f38a131146 More Arithmetic, Better sectioning of code 2026-02-10 02:10:58 +02:00
cat
c0e416e030 Fixed width hex output 2026-02-10 02:01:30 +02:00

View File

@@ -15,6 +15,7 @@
#include <cstdarg>
#include <cstddef>
#include <exception>
#include <iomanip>
#include <iostream>
namespace VariadicMachine {
@@ -30,6 +31,9 @@ enum : int {
// Two Arguments
IncrementBy,
DecrementBy,
MultiplyBy,
DivideBy,
ModulusBy,
SetTo,
Print,
@@ -56,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;
@@ -81,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
@@ -105,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;
@@ -135,8 +158,13 @@ private:
std::cout << std::bitset<sizeof(int) * 8>(memory[currentPosition]);
return;
// Ugh hate this, I really should use C++23
case AsHex:
std::cout << std::hex << memory[currentPosition] << std::dec;
std::cout << "0x" << std::setfill('0') << std::setw(sizeof(int))
<< std::hex << memory[currentPosition];
// Stupid reset because cout is a dumb dumb thing
std::cout << std::dec << std::setfill(' ') << std::setw(0);
return;
default: