start adding doctests

This commit is contained in:
2022-11-13 11:42:40 -08:00
parent c3b3de5416
commit e6f19d8ee3
8 changed files with 7155 additions and 12 deletions

View File

@@ -33,10 +33,13 @@ public:
/// @param offset from base pointer
/// @return reference to memory at given offset
auto Rel(std::size_t offset) -> ValueType &;
auto Rel(std::size_t offset) const -> ValueType;
auto Next() -> ValueType &;
auto Goto(std::size_t address) -> void;
auto Rebase(std::size_t offset) -> void;
auto Dump() const -> std::vector<ValueType>;
};
} // namespace

View File

@@ -21,6 +21,10 @@ auto Machine::Rel(std::size_t const i) -> ValueType & {
return At(base_ + i);
}
auto Machine::Rel(std::size_t const i) const -> ValueType {
return At(base_ + i);
}
auto Machine::Rebase(std::size_t const offset) -> void {
base_ += offset;
}
@@ -33,4 +37,21 @@ auto Machine::Goto(std::size_t const address) -> void {
pc_ = address;
}
auto Machine::Dump() const -> std::vector<ValueType> {
if (ram_.empty()) { return rom_; }
std::size_t size = rom_.size();
for (auto const& [k,v] : ram_) {
if (k >= size) { size = k+1; }
}
std::vector<ValueType> result(size);
std::copy(rom_.begin(), rom_.end(), result.begin());
for (auto const& [k,v] : ram_) {
result[k] = v;
}
return result;
}
} // namespace