Initial implementation of register machine emulator.

This commit is contained in:
2019-11-17 19:52:52 +00:00
commit be80b6383c
6 changed files with 180 additions and 0 deletions

43
src/register.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include "register.hpp"
template <>
std::pair<Register, Register> toPair<false>(Register unsplit) {
Register x = 0;
/* Skip to the first 1 bit in representation */
while (unsplit % 2 != 1) {
unsplit >>= 1;
x++;
}
unsplit >>= 1;
return std::make_pair(x, unsplit);
}
template <>
std::pair<Register, Register> toPair<true>(Register unsplit) {
Register x = 0;
/* Skip past the first 1 bits in representation */
while (unsplit % 2 == 1) {
unsplit >>= 1;
x++;
}
unsplit >>= 1;
return std::make_pair(x, unsplit);
}
std::vector<Register> toList(Register unsplit) {
std::vector<Register> list{};
while (unsplit != 0) {
const auto splitPair = toPair<false>(unsplit);
unsplit = splitPair.second;
list.push_back(splitPair.first);
}
return list;
}