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

196 lines
5.8 KiB
C++

#include "flash.hpp"
#include <istream>
#include <limits>
#include <ostream>
#include <string>
#include <string_view>
#include <vector>
namespace flash {
namespace {
bool separator(char ch) {
return ch == ' ' || ch == '\t' || ch == '\r';
}
std::vector<std::string_view> tokens(const std::string& line) {
std::vector<std::string_view> result;
std::size_t cursor = 0;
while (cursor < line.size()) {
while (cursor < line.size() && separator(line[cursor])) {
++cursor;
}
const auto start = cursor;
while (cursor < line.size() && !separator(line[cursor])) {
++cursor;
}
if (cursor > start) {
result.emplace_back(line.data() + start, cursor - start);
}
}
return result;
}
bool number(std::string_view text, Number& output) {
if (text.empty()) {
return false;
}
bool negative = text.front() == '-';
std::size_t cursor = negative ? 1 : 0;
if (cursor == text.size()) {
return false;
}
const auto maximum = static_cast<std::uint64_t>(std::numeric_limits<Number>::max());
const auto limit = maximum + (negative ? 1u : 0u);
std::uint64_t value = 0;
for (; cursor < text.size(); ++cursor) {
const auto ch = static_cast<unsigned char>(text[cursor]);
if (ch < '0' || ch > '9') {
return false;
}
const auto digit = static_cast<std::uint64_t>(ch - '0');
if (value > (limit - digit) / 10) {
return false;
}
value = value * 10 + digit;
}
if (!negative) {
output = static_cast<Number>(value);
} else if (value == maximum + 1u) {
output = std::numeric_limits<Number>::min();
} else {
output = -static_cast<Number>(value);
}
return true;
}
void decimal(std::ostream& output, Number value) {
const std::string text = std::to_string(value);
output.write(text.data(), static_cast<std::streamsize>(text.size()));
}
void bytes(std::ostream& output, const unsigned char* data, std::size_t size) {
static constexpr char alphabet[] = "0123456789abcdef";
for (std::size_t index = 0; index < size; ++index) {
const auto value = data[index];
output.put(alphabet[value >> 4]);
output.put(alphabet[value & 15]);
}
}
void render(std::ostream& output, const Result& result) {
decimal(output, static_cast<int>(result.code));
output.put(' ');
const Number error_size = static_cast<Number>(result.error.size());
decimal(output, error_size);
output.put(':');
bytes(output, reinterpret_cast<const unsigned char*>(result.error.data()), result.error.size());
output.put(' ');
const Number field_size = static_cast<Number>(result.fields.size());
decimal(output, field_size);
for (Number value : result.fields) {
output.put(' ');
decimal(output, value);
}
output.put(' ');
const Number data_size = static_cast<Number>(result.data.size());
decimal(output, data_size);
output.put(':');
bytes(output, result.data.data(), result.data.size());
output.put('\n');
}
Result syntax() {
Result result;
result.code = Code::Syntax;
result.error = "syntax";
return result;
}
int arity(std::string_view verb) {
if (verb == "RESET" || verb == "INSPECT") {
return 0;
}
if (verb == "DETACH" || verb == "WREN" || verb == "WRDI" || verb == "STATUS") {
return 1;
}
if (verb == "ATTACH" || verb == "ERASE" || verb == "ADVANCE") {
return 2;
}
if (verb == "READ" || verb == "WORD") {
return 3;
}
if (verb == "PROGRAM") {
return 4;
}
return -1;
}
Result dispatch(FlashBank& bank, const std::vector<std::string_view>& words) {
if (words.empty()) {
return syntax();
}
const auto verb = words.front();
const auto expected = arity(verb);
if (expected < 0 || words.size() != static_cast<std::size_t>(expected + 1)) {
return syntax();
}
std::vector<Number> arguments;
for (std::size_t index = 1; index < words.size(); ++index) {
Number value = 0;
if (!number(words[index], value)) {
return syntax();
}
arguments.push_back(value);
}
if (verb == "RESET") {
return bank.reset();
}
if (verb == "ATTACH") {
return bank.attach(arguments[0], arguments[1]);
}
if (verb == "DETACH") {
return bank.detach(arguments[0]);
}
if (verb == "WREN") {
return bank.wren(arguments[0]);
}
if (verb == "WRDI") {
return bank.wrdi(arguments[0]);
}
if (verb == "PROGRAM") {
return bank.program(arguments[0], arguments[1], arguments[2], arguments[3]);
}
if (verb == "ERASE") {
return bank.erase(arguments[0], arguments[1]);
}
if (verb == "ADVANCE") {
return bank.advance(arguments[0], arguments[1]);
}
if (verb == "READ") {
return bank.read(arguments[0], arguments[1], arguments[2]);
}
if (verb == "WORD") {
return bank.word(arguments[0], arguments[1], arguments[2]);
}
if (verb == "STATUS") {
return bank.status(arguments[0]);
}
return bank.inspect();
}
}
CliResult run_cli(std::istream& input, std::ostream& output, FlashBank& bank) {
bank.reset();
CliResult counters;
std::string line;
while (std::getline(input, line)) {
++counters.physical;
if (counters.physical > 128) {
Result limit;
limit.code = Code::Limit;
limit.error = "limit";
render(output, limit);
counters.limited = true;
break;
}
const Result result = dispatch(bank, tokens(line));
render(output, result);
++counters.processed;
if (result.code == Code::Syntax) {
++counters.syntax;
}
}
return counters;
}
}