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

206 lines
6.3 KiB
C++

#include "registry.hpp"
#include <charconv>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
namespace named {
namespace {
bool number(const std::string& text, std::int64_t& result) {
if (text.empty()) {
return false;
}
std::size_t start = text.front() == '-' ? 1 : 0;
if (start == text.size()) {
return false;
}
if (text[start] == '0' && text.size() - start != 1) {
return false;
}
if (start == 1 && text[start] == '0') {
return false;
}
for (std::size_t index = start; index < text.size(); ++index) {
if (text[index] < '0' || text[index] > '9') {
return false;
}
}
auto conversion = std::from_chars(text.data(), text.data() + text.size(), result);
return conversion.ec == std::errc{} && conversion.ptr == text.data() + text.size();
}
std::vector<std::string> words(const std::string& line) {
std::vector<std::string> result;
std::string word;
for (char character : line) {
if (character == ' ' || character == '\t') {
if (!word.empty()) {
result.push_back(word);
word.clear();
}
} else {
word.push_back(character);
}
}
if (!word.empty()) {
result.push_back(word);
}
return result;
}
bool arity(const std::vector<std::string>& tokens, std::size_t arguments) {
return tokens.size() == arguments + 1;
}
void status(std::ostream& output, Code code) {
if (code == Code::OK) {
output << "OK\n";
} else {
output << "ERR " << spelling(code) << '\n';
}
}
void object_line(std::ostream& output, Code code, const ObjectInfo& object) {
if (code != Code::OK) {
status(output, code);
return;
}
output << "OK " << object.identity << ' ' << object.permits << ' '
<< object.balance << ' ' << object.handles << ' ' << object.linked
<< ' ' << object.leases << ' ' << object.commits << '\n';
}
void lease_line(std::ostream& output, Code code, const LeaseInfo& lease) {
if (code != Code::OK) {
status(output, code);
return;
}
output << "OK " << lease.active << ' ' << lease.handle << ' '
<< lease.identity << ' ' << lease.pending << '\n';
}
void stats_line(std::ostream& output, const Statistics& stats) {
output << "OK " << stats.objects << ' ' << stats.names << ' '
<< stats.handles << ' ' << stats.active << ' '
<< stats.next_identity << '\n';
}
bool execute(Registry& registry, const std::vector<std::string>& tokens,
std::ostream& output) {
if (tokens.empty()) {
return false;
}
const std::string& verb = tokens[0];
std::int64_t first = 0;
std::int64_t second = 0;
std::int64_t third = 0;
if (verb == "fresh") {
if (!arity(tokens, 0)) {
return false;
}
status(output, registry.fresh());
return true;
}
if (verb == "stats") {
if (!arity(tokens, 0)) {
return false;
}
stats_line(output, registry.stats());
return true;
}
if (verb == "open") {
if (!arity(tokens, 4)) {
return false;
}
if (!number(tokens[1], first) || !number(tokens[3], second)
|| !number(tokens[4], third)) {
return false;
}
status(output, registry.open(first, tokens[2], second, third));
return true;
}
if (verb == "unlink") {
if (!arity(tokens, 1)) {
return false;
}
status(output, registry.unlink(tokens[1]));
return true;
}
if (verb == "named") {
if (!arity(tokens, 1)) {
return false;
}
ObjectInfo result;
Code code = registry.named(tokens[1], result);
object_line(output, code, result);
return true;
}
if (verb == "move") {
if (!arity(tokens, 3) || !number(tokens[1], first)
|| !number(tokens[2], second) || !number(tokens[3], third)) {
return false;
}
status(output, registry.move(first, second, third));
return true;
}
if (verb == "wait" || verb == "post" || verb == "write"
|| verb == "begin" || verb == "stage" || verb == "duplicate") {
if (!arity(tokens, 2)) {
return false;
}
if (!number(tokens[1], first) || !number(tokens[2], second)) {
return false;
}
if (verb == "wait") {
status(output, registry.wait(first, second));
} else if (verb == "post") {
status(output, registry.post(first, second));
} else if (verb == "write") {
status(output, registry.write(first, second));
} else if (verb == "begin") {
status(output, registry.begin(first, second));
} else if (verb == "duplicate") {
status(output, registry.duplicate(first, second));
} else {
status(output, registry.stage(first, second));
}
return true;
}
if (verb == "close" || verb == "commit" || verb == "cancel"
|| verb == "info" || verb == "lease") {
if (!arity(tokens, 1) || !number(tokens[1], first)) {
return false;
}
if (verb == "close") {
status(output, registry.close(first));
} else if (verb == "commit") {
status(output, registry.commit(first));
} else if (verb == "cancel") {
status(output, registry.cancel(first));
} else if (verb == "info") {
ObjectInfo result;
Code code = registry.info(first, result);
object_line(output, code, result);
} else {
LeaseInfo result;
Code code = registry.lease(first, result);
lease_line(output, code, result);
}
return true;
}
return false;
}
}
std::int64_t serve(std::istream& input, std::ostream& output) {
Registry registry;
std::string line;
std::int64_t processed = 0;
while (processed < 4096 && std::getline(input, line)) {
processed += 1;
if (line.size() > 256) {
output << "ERR FORMAT\n";
continue;
}
auto tokens = words(line);
if (!execute(registry, tokens, output)) {
output << "ERR FORMAT\n";
}
}
return processed;
}
}