amos 73a5240295 Batches 21 and 18: add 74 calibrated tasks (40 Bos redo, 34 HWE code-gen)
Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao
environments: hidden assertions that ran inside the candidate's process
now run in a trusted parent that reads observations from a low-UID
worker; gold bytes are unchanged. 9 were excluded for scope (ROS2,
oversize, security core), 3 are blocked because the source requires an
exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6.

Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the
first 100 landed in 2f32624d.

Claude reviewed 74/74 USABLE against current digests, canonical
families, no ID or source overlap with main, plain public docs. Only the
new task directories are taken; the stale pre-batch-20 copies of
concur-release-capsule and resource-temp-link on the batch 21 branch and
both branches' progress notes stay as main has them. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 10:23:12 +08:00

127 lines
3.2 KiB
C++

#include "decimal.hpp"
#include <utility>
namespace decimal {
Session::Session() = default;
bool Session::slot_ok(int slot) {
return slot >= 0 && slot < 4;
}
Code Session::put(int slot, const std::string& source) {
if (!slot_ok(slot)) {
return Code::SLOT;
}
if (source.size() > 128) {
return Code::LENGTH;
}
Cell replacement;
replacement.source = source;
cells_[static_cast<std::size_t>(slot)] = std::move(replacement);
return Code::OK;
}
Prefix Session::scan(int slot, int begin) {
if (!slot_ok(slot)) {
Prefix rejected;
rejected.code = Code::SLOT;
return rejected;
}
Cell& cell = cells_[static_cast<std::size_t>(slot)];
Prefix result = decode(cell.source, begin);
if (result.code != Code::OK) {
return result;
}
cell.last = result;
cell.scanned = true;
return result;
}
Code Session::clear(int slot) {
if (!slot_ok(slot)) {
return Code::SLOT;
}
cells_[static_cast<std::size_t>(slot)] = Cell{};
return Code::OK;
}
View Session::view(int slot) const {
View result;
if (!slot_ok(slot)) {
result.code = Code::SLOT;
return result;
}
const Cell& cell = cells_[static_cast<std::size_t>(slot)];
result.source = cell.source;
result.scanned = cell.scanned;
result.last = cell.last;
return result;
}
std::string code_name(Code code) {
switch (code) {
case Code::OK:
return "OK";
case Code::SLOT:
return "SLOT";
case Code::LENGTH:
return "LENGTH";
case Code::OFFSET:
return "OFFSET";
case Code::NO_NUMBER:
return "NO_NUMBER";
case Code::VALUE:
return "VALUE";
}
return "UNKNOWN";
}
std::string hex_encode(const std::string& bytes) {
if (bytes.empty()) {
return "-";
}
const char* alphabet = "0123456789abcdef";
std::string text;
text.reserve(bytes.size() * 2);
for (unsigned char byte : bytes) {
unsigned high = byte >> 4;
unsigned low = byte & 15;
char first = alphabet[high];
char second = alphabet[low];
text.push_back(first);
text.push_back(second);
}
return text;
}
namespace {
int unhex(unsigned char byte) {
if (byte >= '0' && byte <= '9') {
return byte - '0';
}
if (byte >= 'a' && byte <= 'f') {
return byte - 'a' + 10;
}
if (byte >= 'A' && byte <= 'F') {
return byte - 'A' + 10;
}
return -1;
}
}
bool hex_decode(const std::string& token, std::string& bytes) {
std::string decoded;
if (token == "-") {
bytes.clear();
return true;
}
if (token.empty() || token.size() % 2 != 0) {
return false;
}
decoded.reserve(token.size() / 2);
for (std::size_t i = 0; i < token.size(); i += 2) {
int high = unhex(static_cast<unsigned char>(token[i]));
int low = unhex(static_cast<unsigned char>(token[i + 1]));
if (high < 0 || low < 0) {
return false;
}
unsigned combined = static_cast<unsigned>(high) << 4;
combined |= static_cast<unsigned>(low);
char byte = static_cast<char>(combined);
decoded.push_back(byte);
}
bytes.swap(decoded);
return true;
}
}