100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth range given to batch 22), each with at least one independent contract-edge defect and plain public docs. Claude reviewed 100/100 USABLE against current digests; no ID or source overlap with main or batch 22. Difficulty is unmeasured. progress.md records the wrap-up: all Codex sessions and Qwen schedulers stopped for the user's rollout, Qwen results so far (57 HARD of 373), and what is left on each batch branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
150 lines
4.4 KiB
C++
150 lines
4.4 KiB
C++
#include "dispatch.hpp"
|
|
#include <array>
|
|
#include <limits>
|
|
#include <string>
|
|
#include <utility>
|
|
namespace edf {
|
|
namespace {
|
|
enum class Operation { Define, Update, Erase, Post, Cancel, Retime, Advance };
|
|
struct Instruction {
|
|
Operation operation;
|
|
std::array<std::int64_t, 3> arguments{};
|
|
};
|
|
class Parser {
|
|
public:
|
|
explicit Parser(std::string_view text) : text_(text) {}
|
|
bool instruction(Instruction& output) {
|
|
std::size_t begin = cursor_;
|
|
while (cursor_ < text_.size() && text_[cursor_] >= 'a' && text_[cursor_] <= 'z') {
|
|
++cursor_;
|
|
}
|
|
std::string_view name = text_.substr(begin, cursor_ - begin);
|
|
std::size_t count = 0;
|
|
if (name == "define") {
|
|
output.operation = Operation::Define;
|
|
count = 3;
|
|
} else if (name == "update") {
|
|
output.operation = Operation::Update;
|
|
count = 3;
|
|
} else if (name == "erase") {
|
|
output.operation = Operation::Erase;
|
|
count = 1;
|
|
} else if (name == "post") {
|
|
output.operation = Operation::Post;
|
|
count = 3;
|
|
} else if (name == "cancel") {
|
|
output.operation = Operation::Cancel;
|
|
count = 1;
|
|
} else if (name == "retime") {
|
|
output.operation = Operation::Retime;
|
|
count = 2;
|
|
} else if (name == "advance") {
|
|
output.operation = Operation::Advance;
|
|
count = 1;
|
|
} else {
|
|
return false;
|
|
}
|
|
if (!take('(')) {
|
|
return false;
|
|
}
|
|
for (std::size_t index = 0; index < count; ++index) {
|
|
if (index != 0 && !take(',')) {
|
|
return false;
|
|
}
|
|
if (!number(output.arguments[index])) {
|
|
return false;
|
|
}
|
|
}
|
|
return take(')');
|
|
}
|
|
bool done() const {
|
|
return cursor_ == text_.size();
|
|
}
|
|
bool separator() {
|
|
return take(';');
|
|
}
|
|
private:
|
|
bool take(char token) {
|
|
if (cursor_ == text_.size() || text_[cursor_] != token) {
|
|
return false;
|
|
}
|
|
++cursor_;
|
|
return true;
|
|
}
|
|
bool number(std::int64_t& output) {
|
|
if (cursor_ == text_.size() || text_[cursor_] < '0' || text_[cursor_] > '9') {
|
|
return false;
|
|
}
|
|
std::int64_t result = 0;
|
|
while (cursor_ < text_.size() && text_[cursor_] >= '0' && text_[cursor_] <= '9') {
|
|
int digit = text_[cursor_] - '0';
|
|
if (result > (std::numeric_limits<std::int64_t>::max() - digit) / 10) {
|
|
return false;
|
|
}
|
|
result = result * 10 + digit;
|
|
++cursor_;
|
|
}
|
|
output = result;
|
|
return true;
|
|
}
|
|
std::string_view text_;
|
|
std::size_t cursor_ = 0;
|
|
};
|
|
int execute(Dispatcher& dispatcher, const Instruction& instruction) {
|
|
const auto& a = instruction.arguments;
|
|
switch (instruction.operation) {
|
|
case Operation::Define:
|
|
return dispatcher.define(a[0], a[1], a[2]);
|
|
case Operation::Update:
|
|
return dispatcher.update(a[0], a[1], a[2]);
|
|
case Operation::Erase:
|
|
return dispatcher.erase(a[0]);
|
|
case Operation::Post:
|
|
return dispatcher.post(a[0], a[1], a[2]);
|
|
case Operation::Cancel:
|
|
return dispatcher.cancel(a[0]);
|
|
case Operation::Retime:
|
|
return dispatcher.retime(a[0], a[1]);
|
|
case Operation::Advance:
|
|
return dispatcher.advance(a[0]);
|
|
}
|
|
return Invalid;
|
|
}
|
|
}
|
|
PlanResult apply_plan(Dispatcher& dispatcher, std::string_view text) {
|
|
if (text.size() > 4096) {
|
|
return {Limit, 0};
|
|
}
|
|
if (text.empty()) {
|
|
return {Ok, 0};
|
|
}
|
|
Parser parser(text);
|
|
std::vector<Instruction> instructions;
|
|
while (true) {
|
|
if (instructions.size() == 32) {
|
|
return {Limit, 32};
|
|
}
|
|
Instruction instruction{};
|
|
if (!parser.instruction(instruction)) {
|
|
return {Syntax, instructions.size()};
|
|
}
|
|
instructions.push_back(instruction);
|
|
if (parser.done()) {
|
|
break;
|
|
}
|
|
if (!parser.separator()) {
|
|
return {Syntax, instructions.size() - 1};
|
|
}
|
|
}
|
|
Dispatcher trial(dispatcher);
|
|
for (std::size_t index = 0; index < instructions.size(); ++index) {
|
|
int code = execute(trial, instructions[index]);
|
|
if (code != Ok) {
|
|
return {code, index};
|
|
}
|
|
}
|
|
dispatcher = trial;
|
|
return {Ok, instructions.size()};
|
|
}
|
|
}
|