amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27,
11 canonical families), 38 skipped for scope or duplication. Each task
has at least one independent contract-edge defect, boundary types
rotate, and public docs state trap clauses as plain contract prose.
Claude reviewed 63/63 USABLE against current digests. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:14:57 +08:00

114 lines
4.7 KiB
C++

#include "log_gate.hpp"
#include <array>
#include <iostream>
#include <sstream>
#include <string>
#include <limits>
using namespace burstlog;
using U = std::uint64_t;
namespace {
void number(U value) { std::cout << ' ' << value; }
void gate_fields(const Gate& g)
{
for (U v : Snapshot{g.ready,g.start,g.last,g.interval,g.burst,g.used,
g.pending,g.requests,g.emitted,g.suppressed,g.closed,g.reported}) number(v);
}
void result_fields(const Result& r)
{
number(r.allowed); number(r.blocked); number(r.flushed); number(r.windows);
}
void command_fields(const Command& c)
{
number(static_cast<U>(c.kind)); number(c.object); number(c.time);
number(c.config.interval); number(c.config.burst); number(c.count);
}
std::string hex(const std::string& s)
{
if (s.empty()) return "-";
const char* digits = "0123456789abcdef";
std::string r;
for (unsigned char c : s) { r += digits[c >> 4]; r += digits[c & 15]; }
return r;
}
std::string unhex(const std::string& s)
{
if (s == "-") return {};
std::string r;
for (std::size_t i=0;i<s.size();i+=2)
r.push_back(static_cast<char>(std::stoul(s.substr(i,2),nullptr,16)));
return r;
}
}
int main()
{
std::array<Gate,2> gates{};
std::string line;
while (std::getline(std::cin,line)) {
std::istringstream in(line);
char tag; in >> tag;
if (tag == 'H') {
U now,deadline,interval,burst,a,b;
in >> now >> deadline >> interval >> burst >> a >> b;
Config c{interval,burst};
std::cout << "H"; number(valid_time(now)); number(window_due(now,deadline));
number(valid_config(c)); number(saturating_add(a,b));
number(c.interval); number(c.burst);
} else if (tag == 'D') {
U limit,seed,mask; std::string encoded;
in >> limit >> seed >> mask >> encoded;
auto content = unhex(encoded);
std::string storage = std::string("\xa5" "9:",3) + content + std::string("7Z\0q",4);
std::string_view text(storage.data()+3,content.size()); U value=seed;
int rc=parse_decimal(text,limit,mask ? nullptr : &value);
std::cout << "D " << rc; number(value); std::cout << ' ' << hex(storage);
} else if (tag == 'P') {
U seed,mask; std::string encoded; in >> seed >> mask >> encoded;
auto content=unhex(encoded);
std::string storage = std::string("\xa5" "9:",3) + content + std::string("7Z\0q",4);
std::string_view text(storage.data()+3,content.size());
Command c{static_cast<Kind>(seed),seed+1,seed+2,{seed+3,seed+4},seed+5};
int rc=parse_command(text,mask ? nullptr : &c);
std::cout << "P " << rc; command_fields(c); std::cout << ' ' << hex(storage);
} else if (tag == 'F') {
U mode,seed; in >> mode >> seed;
Snapshot s{};
for (std::size_t i=0;i<s.size();++i) s[i]=i%3==0 ? std::numeric_limits<U>::max() : seed+i;
Result r{s[0],s[1],s[2],s[3]};
const auto text=mode ? result_json(r) : snapshot_json(s);
std::cout << "F " << hex(text);
for (auto value:s) number(value);
result_fields(r);
} else if (tag == 'R') {
U mode,action,object,now,interval,burst,count,seed,mask;
in >> mode >> action >> object >> now >> interval >> burst >> count >> seed >> mask;
Command c{static_cast<Kind>(action),object,now,{interval,burst},count};
Config config{interval,burst};
Result result{seed,seed+1,seed+2,seed+3};
Snapshot snapshot{};
for (std::size_t i=0;i<snapshot.size();++i) snapshot[i]=seed+i;
Gate* gate=(object<2 && !(mask&1)) ? &gates[object] : nullptr;
Result* out=(mask&2) ? nullptr : &result;
int rc=-1;
if (mode) {
rc=execute(c,(mask&1) ? nullptr : &gates,out);
} else {
switch(action) {
case 1: rc=gate_init(gate,now,config,out);break;
case 2: rc=gate_log(gate,now,count,out);break;
case 3: rc=gate_advance(gate,now,out);break;
case 4: rc=gate_configure(gate,now,config,out);break;
case 5: rc=gate_reset(gate,now,out);break;
case 6: rc=gate_snapshot(gate,(mask&2) ? nullptr : &snapshot);break;
default: break;
}
}
std::cout << "R " << rc; result_fields(result);
for (auto v:snapshot) number(v);
number(config.interval); number(config.burst); command_fields(c);
gate_fields(gates[0]); gate_fields(gates[1]);
}
std::cout << '\n';
}
return 0;
}