amos 73a5240295 Batches 21 and 18: add 74 calibrated tasks (40 Bos redo, 34 HWE code-gen)
Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao
environments: hidden assertions that ran inside the candidate's process
now run in a trusted parent that reads observations from a low-UID
worker; gold bytes are unchanged. 9 were excluded for scope (ROS2,
oversize, security core), 3 are blocked because the source requires an
exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6.

Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the
first 100 landed in 2f32624d.

Claude reviewed 74/74 USABLE against current digests, canonical
families, no ID or source overlap with main, plain public docs. Only the
new task directories are taken; the stale pre-batch-20 copies of
concur-release-capsule and resource-temp-link on the batch 21 branch and
both branches' progress notes stay as main has them. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 10:23:12 +08:00

249 lines
6.4 KiB
C++

#include "jump.hpp"
#include <array>
namespace jumpmodel {
struct Machine::Impl {
struct Frame {
bool active=false;
int parent=-1;
int id=-1;
int local=0;
int returned=0;
std::uint64_t token=0;
};
struct Context {
int state=0;
int owner=-1;
std::uint64_t token=0;
int resumes=0;
};
std::array<Frame,32> frames;
std::array<Context,8> contexts;
int head=-1;
std::uint64_t next=1;
static bool id_valid(int id) {
return id>=0 && id<=31;
}
static bool local_valid(int value) {
return value>=-1000 && value<=1000;
}
static bool slot_valid(int slot) {
return slot>=0 && slot<=7;
}
static bool jump_valid(int value) {
return value>=-128 && value<=128;
}
int active_depth() const {
int count=0;
int cursor=head;
while (cursor!=-1) {
count+=1;
const Frame& item=frames[static_cast<std::size_t>(cursor)];
cursor=item.parent;
}
return count;
}
int find_id(int id) const {
const Frame& item=frames[static_cast<std::size_t>(id)];
if (!item.active) {
return -1;
}
return id;
}
int find_token(std::uint64_t token) const {
int cursor=head;
while (cursor!=-1) {
const Frame& item=frames[static_cast<std::size_t>(cursor)];
if (item.token==token) {
return cursor;
}
cursor=item.parent;
}
return -1;
}
int frame_at(int index) const {
const int count=active_depth();
if (index>=count) {
return -1;
}
int steps=count-index-1;
int cursor=head;
while (steps>0) {
const Frame& item=frames[static_cast<std::size_t>(cursor)];
cursor=item.parent;
steps-=1;
}
return cursor;
}
void invalidate(std::uint64_t token) {
for (Context& item:contexts) {
if (item.state==1 && item.token==token) {
item.state=2;
}
}
}
void remove_top() {
const Frame& item=frames[static_cast<std::size_t>(head)];
invalidate(item.token);
detach_top();
}
void detach_top() {
const int removed=head;
const Frame& item=frames[static_cast<std::size_t>(removed)];
const int parent=item.parent;
head=parent;
frames[static_cast<std::size_t>(removed)]=Frame{};
}
FrameView view(const Frame& item) const {
FrameView result;
result.code=OK;
result.id=item.id;
result.local=item.local;
result.returned=item.returned;
result.token=item.token;
return result;
}
};
Machine::Machine():p(new Impl) {
}
Machine::~Machine()=default;
Reply Machine::enter(int id,int local) {
if (!Impl::id_valid(id)) {
return {RANGE,-1};
}
if (!Impl::local_valid(local)) {
return {RANGE,-1};
}
if (p->find_id(id)>=0) {
return {EXISTS,-1};
}
const int previous_depth=p->active_depth();
if (previous_depth==8) {
return {FULL,-1};
}
Impl::Frame item;
item.active=true;
item.parent=p->head;
item.id=id;
item.local=local;
item.returned=0;
item.token=p->next;
p->next+=1;
p->frames[static_cast<std::size_t>(id)]=item;
p->head=id;
return {OK,previous_depth+1};
}
Reply Machine::leave() {
if (p->head==-1) {
return {EMPTY,-1};
}
const Impl::Frame item=p->frames[static_cast<std::size_t>(p->head)];
p->remove_top();
return {OK,item.id};
}
Reply Machine::store(int id,int local) {
if (!Impl::id_valid(id)) {
return {RANGE,-1};
}
if (!Impl::local_valid(local)) {
return {RANGE,-1};
}
const int index=p->find_id(id);
if (index<0) {
return {MISSING,-1};
}
Impl::Frame& item=p->frames[static_cast<std::size_t>(index)];
const int previous=item.local;
item.local=local;
return {OK,previous};
}
Reply Machine::save(int slot) {
if (!Impl::slot_valid(slot)) {
return {RANGE,-1};
}
if (p->head==-1) {
return {EMPTY,-1};
}
Impl::Frame& owner=p->frames[static_cast<std::size_t>(p->head)];
Impl::Context fresh;
fresh.state=1;
fresh.owner=owner.id;
fresh.token=owner.token;
fresh.resumes=0;
p->contexts[static_cast<std::size_t>(slot)]=fresh;
owner.returned=0;
return {OK,0};
}
Reply Machine::jump(int slot,int value) {
if (!Impl::slot_valid(slot)) {
return {RANGE,-1};
}
if (!Impl::jump_valid(value)) {
return {RANGE,-1};
}
Impl::Context& target=p->contexts[static_cast<std::size_t>(slot)];
if (target.state==0) {
return {VACANT,-1};
}
if (target.state==2) {
return {STALE,-1};
}
const int owner=p->find_token(target.token);
if (owner<0) {
return {STALE,-1};
}
while (p->head!=owner) {
p->remove_top();
}
const int resumed=value==0 ? 1 : value;
Impl::Frame& frame=p->frames[static_cast<std::size_t>(owner)];
frame.returned=resumed;
target.resumes+=1;
return {OK,resumed};
}
Reply Machine::clear(int slot) {
if (!Impl::slot_valid(slot)) {
return {RANGE,-1};
}
Impl::Context& target=p->contexts[static_cast<std::size_t>(slot)];
const int previous=target.state;
target=Impl::Context{};
return {OK,previous};
}
FrameView Machine::frame(int index) const {
if (index<0 || index>7) {
FrameView result;
result.code=RANGE;
return result;
}
const int id=p->frame_at(index);
if (id==-1) {
return FrameView{};
}
const Impl::Frame& item=p->frames[static_cast<std::size_t>(id)];
return p->view(item);
}
ContextView Machine::context(int slot) const {
ContextView result;
if (!Impl::slot_valid(slot)) {
result.code=RANGE;
return result;
}
const Impl::Context& item=p->contexts[static_cast<std::size_t>(slot)];
result.state=item.state;
result.owner=item.owner;
result.token=item.token;
result.resumes=item.resumes;
return result;
}
FrameView Machine::top() const {
if (p->head==-1) {
return FrameView{};
}
const Impl::Frame& item=p->frames[static_cast<std::size_t>(p->head)];
return p->view(item);
}
int Machine::depth() const {
return p->active_depth();
}
}