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

112 lines
3.3 KiB
C++

#include "internal.hpp"
namespace frames {
int view(const Bank* b,int h,View* out) {
if (!out) return ARG;
int object=index_of(b,h);
if (object<0) return object;
const Lock& lock=b->locks[object];
View result{};
result.mode=lock.attr.mode;
result.limit=lock.attr.limit;
result.aliases=alias_count(*b,object);
result.owner=lock.held.empty() ? -1 : lock.held.back().actor;
result.depth=unsigned(lock.held.size());
result.waiting=unsigned(lock.pending.size());
result.top=lock.held.empty() ? 0 : lock.held.back().note;
result.entered=lock.entered;
result.exited=lock.exited;
result.handoffs=lock.handoffs;
*out=result;
return OK;
}
int queued(const Bank* b,int h,unsigned position,WaitView* out) {
if (!out) return ARG;
int object=index_of(b,h);
if (object<0) return object;
const Lock& lock=b->locks[object];
if (position>=lock.pending.size()) return MISSING;
out->actor=lock.pending[position].actor;
out->note=lock.pending[position].note;
return OK;
}
int stats(const Bank* b,Stats* out) {
if (!b || !out) return ARG;
Stats result{};
for (int h:b->handles) {
if (h>=0) ++result.handles;
}
for (const Lock& lock:b->locks) {
if (!lock.used) continue;
++result.objects;
result.frames+=unsigned(lock.held.size());
result.waiters+=unsigned(lock.pending.size());
}
result.creates=b->creates;
result.duplicates=b->duplicates;
result.closes=b->closes;
result.revision=b->revision;
*out=result;
return OK;
}
int export_rows(const Bank* b,std::vector<Row>* out) {
if (!b || !out) return ARG;
std::vector<Row> result;
for (unsigned h=0;h<MAX_HANDLES;++h) {
View value{};
int rc=view(b,int(h),&value);
if (rc==ABSENT) continue;
if (rc!=OK) return rc;
result.push_back(Row{int(h),value});
}
*out=result;
return OK;
}
int owned(const Bank* b,int actor,std::vector<int>* out) {
if (!b || !out || actor<0 || actor>7) return ARG;
std::vector<int> result;
for (unsigned h=0;h<MAX_HANDLES;++h) {
View value{};
int rc=view(b,int(h),&value);
if (rc==ABSENT) continue;
if (rc!=OK) return rc;
if (value.owner==actor) result.push_back(int(h));
}
*out=result;
return OK;
}
const char* result_name(int rc) {
switch (rc) {
case OK: return "OK";
case QUEUED: return "QUEUED";
case ARG: return "ARG";
case ABSENT: return "ABSENT";
case BUSY: return "BUSY";
case LIMIT: return "LIMIT";
case OWNER: return "OWNER";
case DUPLICATE: return "DUPLICATE";
case MISSING: return "MISSING";
case SPACE: return "SPACE";
case RANGE: return "RANGE";
default: return "UNKNOWN";
}
}
int actor_view(const Bank* b,int actor,ActorView* out) {
if (!b || !out || actor<0 || actor>7) return ARG;
ActorView result{};
for (const Lock& lock:b->locks) {
if (!lock.used) continue;
if (!lock.held.empty() && lock.held.back().actor==actor) {
++result.held_objects;
result.held_frames+=unsigned(lock.held.size());
}
for (const Frame& waiting:lock.pending) {
if (waiting.actor==actor) ++result.pending_objects;
}
}
*out=result;
return OK;
}
}