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>
241 lines
6.4 KiB
C++
241 lines
6.4 KiB
C++
#include "jump.hpp"
|
|
#include <charconv>
|
|
#include <cstdint>
|
|
#include <istream>
|
|
#include <limits>
|
|
#include <ostream>
|
|
#include <string>
|
|
#include <vector>
|
|
namespace jumpmodel {
|
|
namespace {
|
|
bool separator(char c) {
|
|
return c==' ' || c=='\t';
|
|
}
|
|
std::vector<std::string> split(const std::string& text) {
|
|
std::vector<std::string> words;
|
|
std::size_t at=0;
|
|
while (at<text.size()) {
|
|
while (at<text.size() && separator(text[at])) {
|
|
++at;
|
|
}
|
|
if (at==text.size()) {
|
|
break;
|
|
}
|
|
const std::size_t first=at;
|
|
while (at<text.size() && !separator(text[at])) {
|
|
++at;
|
|
}
|
|
words.push_back(text.substr(first,at-first));
|
|
}
|
|
return words;
|
|
}
|
|
bool number(const std::string& text,int& output) {
|
|
if (text.empty()) {
|
|
return false;
|
|
}
|
|
std::size_t pos=0;
|
|
bool negative=false;
|
|
if (text[0]=='-') {
|
|
negative=true;
|
|
pos=1;
|
|
}
|
|
if (pos==text.size()) {
|
|
return false;
|
|
}
|
|
std::uint64_t value=0;
|
|
const std::uint64_t limit=negative ? 2147483648ULL : 2147483647ULL;
|
|
for (;pos<text.size();++pos) {
|
|
const char c=text[pos];
|
|
if (c<'0' || c>'9') {
|
|
return false;
|
|
}
|
|
const unsigned digit=static_cast<unsigned>(c-'0');
|
|
if (value>(limit-digit)/10) {
|
|
return false;
|
|
}
|
|
value=value*10+digit;
|
|
}
|
|
if (negative) {
|
|
if (value==2147483648ULL) {
|
|
output=std::numeric_limits<int>::min();
|
|
} else {
|
|
output=-static_cast<int>(value);
|
|
}
|
|
} else {
|
|
output=static_cast<int>(value);
|
|
}
|
|
return true;
|
|
}
|
|
void word(std::ostream& output,const std::string& text) {
|
|
output.write(text.data(),static_cast<std::streamsize>(text.size()));
|
|
}
|
|
template<class Integer>
|
|
void digit(std::ostream& output,Integer value) {
|
|
char buffer[32];
|
|
const auto converted=std::to_chars(buffer,buffer+sizeof(buffer),value);
|
|
output.write(buffer,static_cast<std::streamsize>(converted.ptr-buffer));
|
|
}
|
|
void space(std::ostream& output) {
|
|
output.put(' ');
|
|
}
|
|
void newline(std::ostream& output) {
|
|
output.put('\n');
|
|
}
|
|
void reply(std::ostream& output,const Reply& value) {
|
|
word(output,"R");
|
|
space(output);
|
|
digit(output,value.code);
|
|
space(output);
|
|
digit(output,value.value);
|
|
newline(output);
|
|
}
|
|
void frame(std::ostream& output,const FrameView& value) {
|
|
word(output,"F");
|
|
space(output);
|
|
digit(output,value.code);
|
|
space(output);
|
|
digit(output,value.id);
|
|
space(output);
|
|
digit(output,value.local);
|
|
space(output);
|
|
digit(output,value.returned);
|
|
space(output);
|
|
digit(output,value.token);
|
|
newline(output);
|
|
}
|
|
void context(std::ostream& output,const ContextView& value) {
|
|
word(output,"C");
|
|
space(output);
|
|
digit(output,value.code);
|
|
space(output);
|
|
digit(output,value.state);
|
|
space(output);
|
|
digit(output,value.owner);
|
|
space(output);
|
|
digit(output,value.token);
|
|
space(output);
|
|
digit(output,value.resumes);
|
|
newline(output);
|
|
}
|
|
void syntax(std::ostream& output,CliReply& result) {
|
|
word(output,"SYNTAX\n");
|
|
result.errors+=1;
|
|
}
|
|
void note(const Reply& reply,CliReply& result) {
|
|
if (reply.code!=OK) {
|
|
result.errors+=1;
|
|
}
|
|
}
|
|
void note(const FrameView& view,CliReply& result) {
|
|
if (view.code!=OK) {
|
|
result.errors+=1;
|
|
}
|
|
}
|
|
void note(const ContextView& view,CliReply& result) {
|
|
if (view.code!=OK) {
|
|
result.errors+=1;
|
|
}
|
|
}
|
|
}
|
|
CliReply run_cli(Machine& machine,std::istream& input,std::ostream& output) {
|
|
CliReply result;
|
|
std::string line;
|
|
while (std::getline(input,line)) {
|
|
if (result.lines==64) {
|
|
word(output,"LIMIT\n");
|
|
result.limited=true;
|
|
break;
|
|
}
|
|
result.lines+=1;
|
|
const auto words=split(line);
|
|
if (words.empty()) {
|
|
syntax(output,result);
|
|
continue;
|
|
}
|
|
const std::string& command=words[0];
|
|
int a=0;
|
|
int b=0;
|
|
if (command=="ENTER" || command=="STORE" || command=="JUMP") {
|
|
if (words.size()!=3 || !number(words[1],a) || !number(words[2],b)) {
|
|
syntax(output,result);
|
|
continue;
|
|
}
|
|
Reply value;
|
|
if (command=="ENTER") {
|
|
value=machine.enter(a,b);
|
|
} else if (command=="STORE") {
|
|
value=machine.store(a,b);
|
|
} else {
|
|
value=machine.jump(a,b);
|
|
}
|
|
reply(output,value);
|
|
note(value,result);
|
|
continue;
|
|
}
|
|
if (command=="SAVE" || command=="CLEAR") {
|
|
if (words.size()!=2 || !number(words[1],a)) {
|
|
syntax(output,result);
|
|
continue;
|
|
}
|
|
const Reply value=command=="SAVE" ? machine.save(a) : machine.clear(a);
|
|
reply(output,value);
|
|
note(value,result);
|
|
continue;
|
|
}
|
|
if (command=="FRAME") {
|
|
if (words.size()!=2 || !number(words[1],a)) {
|
|
syntax(output,result);
|
|
continue;
|
|
}
|
|
const FrameView value=machine.frame(a);
|
|
frame(output,value);
|
|
note(value,result);
|
|
continue;
|
|
}
|
|
if (command=="CONTEXT") {
|
|
if (words.size()!=2 || !number(words[1],a)) {
|
|
syntax(output,result);
|
|
continue;
|
|
}
|
|
const ContextView value=machine.context(a);
|
|
context(output,value);
|
|
note(value,result);
|
|
continue;
|
|
}
|
|
if (command=="LEAVE") {
|
|
if (words.size()!=1) {
|
|
syntax(output,result);
|
|
continue;
|
|
}
|
|
const Reply value=machine.leave();
|
|
reply(output,value);
|
|
note(value,result);
|
|
continue;
|
|
}
|
|
if (command=="TOP") {
|
|
if (words.size()!=1) {
|
|
syntax(output,result);
|
|
continue;
|
|
}
|
|
const FrameView value=machine.top();
|
|
frame(output,value);
|
|
note(value,result);
|
|
continue;
|
|
}
|
|
if (command=="DEPTH") {
|
|
if (words.size()!=1) {
|
|
syntax(output,result);
|
|
continue;
|
|
}
|
|
word(output,"D");
|
|
space(output);
|
|
digit(output,machine.depth());
|
|
newline(output);
|
|
continue;
|
|
}
|
|
syntax(output,result);
|
|
}
|
|
return result;
|
|
}
|
|
}
|