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

116 lines
4.0 KiB
C++

#include "jump.hpp"
#include <array>
#include <vector>
#include <algorithm>
namespace jumpmodel {
struct Machine::Impl {
struct Event { int operation; int a; int b; };
struct Image {
std::vector<FrameView> frames;
std::array<ContextView,8> slots;
std::uint64_t next=1;
};
std::vector<Event> history;
Image reconstruct() const {
Image out;
for (const Event& event:history) {
if (event.operation==0) {
out.frames.push_back({OK,event.a,event.b,0,out.next++});
} else if (event.operation==1) {
out.frames.pop_back();
} else if (event.operation==2) {
for (auto& frame:out.frames) {
if (frame.id==event.a) frame.local=event.b;
}
} else if (event.operation==3) {
auto& frame=out.frames.back();
out.slots[event.a]={OK,1,frame.id,frame.token,0};
frame.returned=0;
} else if (event.operation==4) {
auto& slot=out.slots[event.a];
auto it=std::find_if(out.frames.begin(),out.frames.end(),[&](const FrameView& f){return f.token==slot.token;});
out.frames.erase(it+1,out.frames.end());
out.frames.back().returned=event.b ? event.b : 1;
++slot.resumes;
} else {
out.slots[event.a]=ContextView{};
}
for (auto& slot:out.slots) {
if (slot.state!=1) continue;
const bool alive=std::any_of(out.frames.begin(),out.frames.end(),[&](const FrameView& frame){return frame.token==slot.token;});
if (!alive) slot.state=2;
}
}
return out;
}
void add(int operation,int a=0,int b=0) {
history.push_back({operation,a,b});
}
};
Machine::Machine():p(new Impl) {}
Machine::~Machine()=default;
Reply Machine::enter(int id,int local) {
if(id<0 || id>31 || local<-1000 || local>1000) return {RANGE,-1};
const auto image=p->reconstruct();
for(const auto& frame:image.frames) if(frame.id==id) return {EXISTS,-1};
if(image.frames.size()==8) return {FULL,-1};
p->add(0,id,local);
return {OK,static_cast<int>(image.frames.size()+1)};
}
Reply Machine::leave() {
const auto image=p->reconstruct();
if(image.frames.empty()) return {EMPTY,-1};
const int id=image.frames.back().id;
p->add(1);
return {OK,id};
}
Reply Machine::store(int id,int local) {
if(id<0 || id>31 || local<-1000 || local>1000) return {RANGE,-1};
const auto image=p->reconstruct();
for(const auto& frame:image.frames) {
if(frame.id!=id) continue;
p->add(2,id,local);
return {OK,frame.local};
}
return {MISSING,-1};
}
Reply Machine::save(int slot) {
if(slot<0 || slot>7) return {RANGE,-1};
const auto image=p->reconstruct();
if(image.frames.empty()) return {EMPTY,-1};
p->add(3,slot);
return {OK,0};
}
Reply Machine::jump(int slot,int value) {
if(slot<0 || slot>7 || value<-128 || value>128) return {RANGE,-1};
const auto image=p->reconstruct();
if(image.slots[slot].state==0) return {VACANT,-1};
if(image.slots[slot].state==2) return {STALE,-1};
p->add(4,slot,value);
return {OK,value ? value : 1};
}
Reply Machine::clear(int slot) {
if(slot<0 || slot>7) return {RANGE,-1};
const int old=p->reconstruct().slots[slot].state;
p->add(5,slot);
return {OK,old};
}
FrameView Machine::frame(int index) const {
if(index<0 || index>7) return {RANGE,-1,0,0,0};
const auto image=p->reconstruct();
if(static_cast<std::size_t>(index)>=image.frames.size()) return {};
return image.frames[index];
}
ContextView Machine::context(int slot) const {
if(slot<0 || slot>7) return {RANGE,0,-1,0,0};
return p->reconstruct().slots[slot];
}
FrameView Machine::top() const {
const auto image=p->reconstruct();
return image.frames.empty() ? FrameView{} : image.frames.back();
}
int Machine::depth() const {
return static_cast<int>(p->reconstruct().frames.size());
}
}