amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

100 lines
2.7 KiB
C

#include "window.h"
#include <string.h>
static CodeResult outcome(int rc)
{
CodeResult result = {rc, 0, 0};
return result;
}
static int usable_slot(unsigned slot)
{
return slot < CW_SLOTS;
}
CodeResult window_install(CodeWorkbench *work, unsigned slot,
const uint16_t *words, unsigned count)
{
if (!usable_slot(slot) || !program_valid(words, count)) {
return outcome(CW_PROGRAM);
}
int rc = store_write(work, slot, 0, words, count);
if (rc != CW_OK) {
return outcome(rc);
}
rc = store_publish(work, slot, count, CW_INSTALL);
return outcome(rc);
}
static int prepare_edit(const CodeSlot *current, unsigned first,
const uint16_t *words, unsigned count,
uint16_t *merged)
{
if (count == 0 || first >= current->length) {
return 0;
}
if (count > current->length - first) {
return 0;
}
memcpy(merged, current->data, current->length * sizeof(*merged));
memcpy(merged + first, words, count * sizeof(*merged));
return program_valid(merged, current->length);
}
CodeResult window_patch(CodeWorkbench *work, unsigned slot, uint64_t expected,
unsigned first, const uint16_t *words, unsigned count)
{
if (!usable_slot(slot)) {
return outcome(CW_PROGRAM);
}
CodeSlot *current = &work->slots[slot];
if (!current->active) {
return outcome(CW_INACTIVE);
}
if (expected != current->generation) {
return outcome(CW_CONFLICT);
}
uint16_t merged[CW_CAPACITY];
if (!prepare_edit(current, first, words, count, merged)) {
return outcome(CW_PROGRAM);
}
int rc = store_write(work, slot, first, words, count);
if (rc != CW_OK) {
return outcome(rc);
}
rc = store_sync(work, slot, first, first + count);
if (rc != CW_OK) {
return outcome(rc);
}
rc = store_publish(work, slot, current->length, CW_PATCH);
return outcome(rc);
}
CodeResult window_drop(CodeWorkbench *work, unsigned slot, uint64_t expected)
{
if (!usable_slot(slot)) {
return outcome(CW_PROGRAM);
}
CodeSlot *current = &work->slots[slot];
if (!current->active) {
return outcome(CW_INACTIVE);
}
if (expected != current->generation) {
return outcome(CW_CONFLICT);
}
return outcome(store_publish(work, slot, 0, CW_DROP));
}
CodeResult window_execute(CodeWorkbench *work, unsigned slot, uint32_t input)
{
if (!usable_slot(slot)) {
return outcome(CW_PROGRAM);
}
const CodeSlot *current = &work->slots[slot];
if (!current->active) {
return outcome(CW_INACTIVE);
}
work->counts.executions += 1;
return interpret(current->execution, current->length, input);
}