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

201 lines
5.7 KiB
C++

#include "record.hpp"
#include <cstdint>
#include <iostream>
#include <limits>
#include <string>
#include <vector>
namespace inline_record {
namespace {
bool read_command(std::istream& input, std::string& line, bool& oversized)
{
line.clear();
oversized = false;
bool received = false;
char character = 0;
while (input.get(character)) {
received = true;
if (character == '\n') {
return true;
}
if (line.size() < 256) {
line.push_back(character);
} else {
oversized = true;
}
}
return received;
}
std::vector<std::string> split(const std::string& line)
{
std::vector<std::string> tokens;
std::size_t position = 0;
while (position < line.size()) {
while (position < line.size() && (line[position] == ' ' || line[position] == '\t')) {
++position;
}
if (position == line.size()) {
break;
}
const std::size_t start = position;
while (position < line.size() && line[position] != ' ' && line[position] != '\t') {
++position;
}
tokens.push_back(line.substr(start, position - start));
}
return tokens;
}
bool integer(const std::string& text, std::int64_t& value)
{
if (text.empty()) {
return false;
}
const bool negative = text[0] == '-';
const std::size_t beginning = negative ? 1 : 0;
if (beginning == text.size()) {
return false;
}
const std::uint64_t positive_limit = static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max());
const std::uint64_t limit = positive_limit + (negative ? 1u : 0u);
std::uint64_t accumulated = 0;
for (std::size_t position = beginning; position < text.size(); ++position) {
const unsigned char letter = static_cast<unsigned char>(text[position]);
if (letter < '0' || letter > '9') {
return false;
}
const std::uint64_t digit = letter - '0';
if (accumulated > (limit - digit) / 10) {
return false;
}
accumulated = accumulated * 10 + digit;
}
if (!negative) {
value = static_cast<std::int64_t>(accumulated);
} else if (accumulated == positive_limit + 1) {
value = std::numeric_limits<std::int64_t>::min();
} else {
value = -static_cast<std::int64_t>(accumulated);
}
return true;
}
std::size_t arity(const std::string& verb)
{
if (verb == "REPLACE") {
return 4;
}
if (verb == "FILL") {
return 4;
}
if (verb == "COPY") {
return 5;
}
if (verb == "DROP" || verb == "INFO") {
return 1;
}
if (verb == "GET" || verb == "BYTE") {
return 2;
}
if (verb == "TOTAL") {
return 0;
}
return 100;
}
void output(const std::string& verb, const Result& result)
{
if (!result.error.empty()) {
std::cout << "ERR " << result.error << '\n';
return;
}
if (verb == "INFO") {
std::cout << "INFO " << result.token << ' ' << result.count << ' '
<< result.tag << ' ' << result.bytes << ' ' << result.checksum << '\n';
return;
}
if (verb == "GET") {
std::cout << "ITEM " << result.value << '\n';
return;
}
if (verb == "BYTE") {
std::cout << "BYTE " << result.value << '\n';
return;
}
std::cout << "OK\n";
}
void execute(Store& store, const std::string& verb, const std::vector<std::int64_t>& args)
{
if (verb == "TOTAL") {
const Totals totals = store.totals();
std::cout << "TOTAL " << totals.allocations << ' ' << totals.frees << ' '
<< totals.live << ' ' << totals.bytes << ' ' << totals.next << '\n';
return;
}
Result result;
if (verb == "REPLACE") {
result = store.replace(args[0], args[1], args[2], args[3]);
} else if (verb == "FILL") {
result = store.fill(args[0], args[1], args[2], args[3]);
} else if (verb == "COPY") {
result = store.copy(args[0], args[1], args[2], args[3], args[4]);
} else if (verb == "DROP") {
result = store.drop(args[0]);
} else if (verb == "INFO") {
result = store.info(args[0]);
} else if (verb == "GET") {
result = store.get(args[0], args[1]);
} else if (verb == "BYTE") {
result = store.byte(args[0], args[1]);
}
output(verb, result);
}
}
int run_cli()
{
Store store;
std::string line;
std::size_t commands = 0;
bool oversized = false;
while (read_command(std::cin, line, oversized)) {
++commands;
if (commands > 4096) {
std::cout << "ERR LIMIT\n";
continue;
}
if (oversized) {
std::cout << "ERR SYNTAX\n";
continue;
}
const std::vector<std::string> tokens = split(line);
if (tokens.empty()) {
std::cout << "ERR SYNTAX\n";
continue;
}
const std::size_t expected = arity(tokens[0]);
if (expected == 100 || tokens.size() != expected + 1) {
std::cout << "ERR SYNTAX\n";
continue;
}
std::vector<std::int64_t> arguments;
bool valid = true;
for (std::size_t index = 1; index < tokens.size(); ++index) {
std::int64_t value = 0;
if (!integer(tokens[index], value)) {
valid = false;
break;
}
arguments.push_back(value);
}
if (!valid) {
std::cout << "ERR SYNTAX\n";
continue;
}
execute(store, tokens[0], arguments);
}
return 0;
}
}
#ifndef INLINE_LIBRARY
int main()
{
return inline_record::run_cli();
}
#endif