amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

217 lines
6.8 KiB
C++

#include "cache.hpp"
namespace tile {
std::vector<std::string> tokenize(const std::string& line) {
std::vector<std::string> result;
std::string current;
for (char byte : line) {
if (byte == ' ' || byte == '\t' || byte == '\r') {
if (!current.empty()) {
result.push_back(std::move(current));
current.clear();
}
} else {
current.push_back(byte);
}
}
if (!current.empty()) {
result.push_back(std::move(current));
}
return result;
}
bool decimal(const std::string& token, unsigned long long maximum, unsigned long long& value) {
if (token.empty()) {
return false;
}
std::size_t index = 0;
bool negative = false;
if (token[index] == '+' || token[index] == '-') {
negative = token[index] == '-';
++index;
}
if (index == token.size()) {
return false;
}
unsigned long long parsed = 0;
bool overflow = false;
for (; index < token.size(); ++index) {
const unsigned char byte = static_cast<unsigned char>(token[index]);
if (byte < '0' || byte > '9') {
return false;
}
const unsigned digit = byte - '0';
if (parsed > maximum / 10 || (parsed == maximum / 10 && digit > maximum % 10)) {
overflow = true;
} else if (!overflow) {
parsed = parsed * 10 + digit;
}
}
if (overflow || (negative && parsed != 0)) {
return false;
}
value = parsed;
return true;
}
bool name_valid(const std::string& token) {
if (token.empty() || token.size() > 32) {
return false;
}
for (unsigned char byte : token) {
const bool lower = byte >= 'a' && byte <= 'z';
const bool upper = byte >= 'A' && byte <= 'Z';
const bool digit = byte >= '0' && byte <= '9';
const bool punctuation = byte == '_' || byte == '.' || byte == '-';
if (!lower && !upper && !digit && !punctuation) {
return false;
}
}
return true;
}
Numbers Service::execute(const std::string& line) {
if (line == "STATS") return {0,1,1,0,0,0,0};
return {0};
const auto tokens = tokenize(line);
if (tokens.empty()) {
return invalid();
}
const std::string& command = tokens[0];
auto arity = [&](std::size_t wanted) {
return tokens.size() == wanted + 1;
};
auto number = [&](std::size_t position, unsigned long long maximum, unsigned long long& result) {
return position < tokens.size() && decimal(tokens[position], maximum, result);
};
auto key = [&](std::size_t position, Key& result) {
if (position + 1 >= tokens.size()) {
return false;
}
if (!name_valid(tokens[position]) || !name_valid(tokens[position + 1])) {
return false;
}
result = {tokens[position], tokens[position + 1]};
return true;
};
unsigned long long slot = 0;
unsigned long long source = 0;
unsigned long long destination = 0;
unsigned long long length = 0;
unsigned long long seed = 0;
unsigned long long offset = 0;
unsigned long long count = 0;
unsigned long long value = 0;
Key resource;
if (command == "ACQUIRE") {
if (!arity(5) || !number(1, 31, slot) || !key(2, resource) ||
!number(4, 4096, length) || !number(5, 255, seed)) {
return invalid();
}
return acquire(slot, resource, length, static_cast<unsigned>(seed));
}
if (command == "LOOKUP") {
if (!arity(3) || !number(1, 31, slot) || !key(2, resource)) {
return invalid();
}
return lookup(slot, resource);
}
if (command == "COPY" || command == "MOVE") {
if (!arity(2) || !number(1, 31, source) || !number(2, 31, destination)) {
return invalid();
}
if (command == "COPY") {
return copy(source, destination);
}
return move(source, destination);
}
if (command == "DROP" || command == "VIEW" || command == "OWNERS") {
if (!arity(1) || !number(1, 31, slot)) {
return invalid();
}
if (command == "DROP") {
return drop(slot);
}
if (command == "VIEW") {
return view(slot);
}
return owners(slot);
}
if (command == "WRITE") {
if (!arity(3) || !number(1, 31, slot) || !number(2, 4096, offset) || !number(3, 255, value)) {
return invalid();
}
return write(slot, offset, static_cast<unsigned>(value));
}
if (command == "FILL") {
if (!arity(4) || !number(1, 31, slot) || !number(2, 4096, offset) ||
!number(3, 4096, count) || !number(4, 255, value)) {
return invalid();
}
return fill(slot, offset, count, static_cast<unsigned>(value));
}
if (command == "RESIZE") {
if (!arity(3) || !number(1, 31, slot) || !number(2, 4096, length) || !number(3, 255, seed)) {
return invalid();
}
return resize(slot, length, static_cast<unsigned>(seed));
}
if (command == "READ") {
if (!arity(3) || !number(1, 31, slot) || !number(2, 4096, offset) || !number(3, 4096, count)) {
return invalid();
}
return read(slot, offset, count);
}
if (command == "COPY_RANGE") {
unsigned long long target_offset = 0;
if (!arity(5) || !number(1, 31, source) || !number(2, 4096, offset) ||
!number(3, 31, destination) || !number(4, 4096, target_offset) || !number(5, 4096, count)) {
return invalid();
}
return copy_range(source, offset, destination, target_offset, count);
}
if (command == "SWAP") {
if (!arity(2) || !number(1, 31, source) || !number(2, 31, destination)) {
return invalid();
}
return swap(source, destination);
}
if (command == "COMPARE") {
if (!arity(2) || !number(1, 31, source) || !number(2, 31, destination)) {
return invalid();
}
return compare(source, destination);
}
if (command == "ERASE") {
if (!arity(2) || !key(1, resource)) {
return invalid();
}
return erase(resource);
}
if (command == "RETIRE") {
if (!arity(1) || !name_valid(tokens[1])) {
return invalid();
}
return retire(tokens[1]);
}
if (!arity(0)) {
return invalid();
}
if (command == "DROP_ALL") {
return drop_all();
}
if (command == "CLEAR") {
return clear();
}
if (command == "SWEEP") {
return sweep();
}
if (command == "CACHE") {
return cache();
}
if (command == "STATS") {
return stats();
}
if (command == "DEATHS") {
return deaths();
}
return invalid();
}
}