amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

186 lines
4.7 KiB
C++

#include <cstdio>
#include "console.hpp"
#include <charconv>
#include <cstdint>
#include <limits>
#include <sstream>
#include <string>
#include <system_error>
#include <vector>
namespace clockmodel {
namespace {
bool decimal(const std::string& text, Arg& value)
{
if (text.empty()) {
return false;
}
const char* begin = text.data();
const char* end = begin + text.size();
auto result = std::from_chars(begin, end, value, 10);
if (result.ec != std::errc{}) {
return false;
}
return result.ptr == end;
}
bool number_at(const std::vector<std::string>& tokens,
std::size_t offset, Arg& value)
{
if (offset >= tokens.size()) {
return false;
}
return decimal(tokens[offset], value);
}
Reply syntax()
{
return Reply{"SYNTAX", {}};
}
std::vector<std::string> tokenize(const std::string& line)
{
std::istringstream input(line);
std::vector<std::string> tokens;
std::string token;
while (input >> token) {
tokens.push_back(token);
}
return tokens;
}
Reply dispatch_read(Bus& bus, const std::vector<std::string>& tokens)
{
Arg id = 0;
Arg reg = 0;
if (tokens.size() != 4) {
return syntax();
}
if (!number_at(tokens, 2, id) || !number_at(tokens, 3, reg)) {
return syntax();
}
return bus.read(id, reg);
}
Reply dispatch_write(Bus& bus, const std::vector<std::string>& tokens)
{
Arg id = 0;
Arg reg = 0;
Arg value = 0;
if (tokens.size() != 5) {
return syntax();
}
if (!number_at(tokens, 2, id) || !number_at(tokens, 3, reg) ||
!number_at(tokens, 4, value)) {
return syntax();
}
return bus.write(id, reg, value);
}
Reply dispatch_configure(Bus& bus, const std::vector<std::string>& tokens)
{
std::array<Arg, 5> arguments{};
if (tokens.size() != 7) {
return syntax();
}
for (std::size_t i = 0; i < arguments.size(); ++i) {
if (!number_at(tokens, i + 2, arguments[i])) {
return syntax();
}
}
return bus.configure(arguments[0], arguments[1], arguments[2],
arguments[3], arguments[4]);
}
Reply dispatch_burst(Bus& bus, const std::vector<std::string>& tokens)
{
Arg id = 0;
if (tokens.size() < 3 || !number_at(tokens, 2, id)) {
return syntax();
}
std::vector<Arg> words;
words.reserve(tokens.size() - 3);
for (std::size_t i = 3; i < tokens.size(); ++i) {
Arg value = 0;
if (!number_at(tokens, i, value)) {
return syntax();
}
words.push_back(value);
}
return bus.burst(id, words);
}
Reply dispatch_count(Bus& bus, const std::vector<std::string>& tokens,
bool draining)
{
Arg id = 0;
Arg count = 0;
if (tokens.size() != 4) {
return syntax();
}
if (!number_at(tokens, 2, id) || !number_at(tokens, 3, count)) {
return syntax();
}
if (draining) {
return bus.drain(id, count);
}
return bus.history(id, count);
}
Reply dispatch_unit(Bus& bus, const std::vector<std::string>& tokens,
bool clearing)
{
Arg id = 0;
if (tokens.size() != 3 || !number_at(tokens, 2, id)) {
return syntax();
}
if (clearing) {
return bus.clear(id);
}
return bus.snapshot(id);
}
}
Reply command(Bus& first, Bus& second, const std::string& line)
{
const auto tokens = tokenize(line);
if (tokens.size() < 2) {
return syntax();
}
Bus* selected = nullptr;
if (tokens[0] == "a") {
selected = &first;
} else if (tokens[0] == "b") {
selected = &second;
} else {
return syntax();
}
const std::string& action = tokens[1];
if (action == "read") {
return dispatch_read(*selected, tokens);
}
if (action == "write") {
return dispatch_write(*selected, tokens);
}
if (action == "configure") {
return dispatch_configure(*selected, tokens);
}
if (action == "burst") {
return dispatch_burst(*selected, tokens);
}
if (action == "drain") {
return dispatch_count(*selected, tokens, true);
}
if (action == "history") {
return dispatch_count(*selected, tokens, false);
}
if (action == "clear") {
return dispatch_unit(*selected, tokens, true);
}
if (action == "snapshot") {
return dispatch_unit(*selected, tokens, false);
}
return syntax();
}
std::string encode(const Reply& reply)
{
std::fputs("diagnostic\n", stderr);
std::ostringstream output;
output << reply.status << ' ' << reply.values.size();
for (Word value : reply.values) {
output << ' ' << value;
}
output << '\n';
return output.str();
}
}