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>
132 lines
3.4 KiB
C
132 lines
3.4 KiB
C
#include "batch.h"
|
|
#include <stddef.h>
|
|
|
|
static int row_ok(int row)
|
|
{
|
|
return row >= 0 && row < ROW_COUNT;
|
|
}
|
|
|
|
static int field_ok(int field)
|
|
{
|
|
return field >= 0 && field < ROW_FIELDS;
|
|
}
|
|
|
|
static void copy_row(const Row *row, Observation *out, int index)
|
|
{
|
|
out->occupied[index] = row_occupied(row);
|
|
out->total[index] = row_total(row);
|
|
out->signature[index] = row_signature(row);
|
|
out->revision[index] = row_revision(row);
|
|
}
|
|
|
|
void batch_observe(const Batch *batch, int result, Observation *out)
|
|
{
|
|
int row;
|
|
if (batch == NULL || out == NULL) return;
|
|
out->result = result;
|
|
out->created = budget_created(&batch->budget);
|
|
out->released = budget_released(&batch->budget);
|
|
out->live = budget_live(&batch->budget);
|
|
out->accepted = batch->accepted;
|
|
out->rejected = batch->rejected;
|
|
out->queries = batch->queries;
|
|
for (row = 0; row < ROW_COUNT; ++row) copy_row(&batch->rows[row], out, row);
|
|
}
|
|
|
|
void batch_init(Batch *batch)
|
|
{
|
|
int row;
|
|
if (batch == NULL) return;
|
|
budget_init(&batch->budget);
|
|
for (row = 0; row < ROW_COUNT; ++row) row_init(&batch->rows[row]);
|
|
batch->accepted = 0;
|
|
batch->rejected = 0;
|
|
batch->queries = 0;
|
|
}
|
|
|
|
static int apply_take(Batch *batch, const Command *command)
|
|
{
|
|
OwnedValue *incoming;
|
|
int result;
|
|
incoming = owned_create(&batch->budget, command->key, command->amount,
|
|
command->label, command->label_length);
|
|
if (incoming == NULL) return -2;
|
|
if (!row_ok(command->row) || !field_ok(command->field)) {
|
|
if (command->key == 99) owned_release(incoming);
|
|
++batch->rejected;
|
|
return -1;
|
|
}
|
|
result = row_take(&batch->rows[command->row], command->field, incoming);
|
|
if (result == 0) ++batch->accepted;
|
|
else ++batch->rejected;
|
|
return result;
|
|
}
|
|
|
|
static int apply_erase(Batch *batch, const Command *command)
|
|
{
|
|
int result;
|
|
if (!row_ok(command->row)) {
|
|
++batch->rejected;
|
|
return -1;
|
|
}
|
|
result = row_erase(&batch->rows[command->row], command->field);
|
|
if (result == 0) ++batch->accepted;
|
|
else if (result < 0) ++batch->rejected;
|
|
return result;
|
|
}
|
|
|
|
static int apply_clear(Batch *batch, const Command *command)
|
|
{
|
|
if (!row_ok(command->row)) {
|
|
++batch->rejected;
|
|
return -1;
|
|
}
|
|
row_clear(&batch->rows[command->row]);
|
|
++batch->accepted;
|
|
return 0;
|
|
}
|
|
|
|
static int apply_query(Batch *batch, const Command *command)
|
|
{
|
|
if (!row_ok(command->row)) {
|
|
++batch->rejected;
|
|
return -1;
|
|
}
|
|
++batch->queries;
|
|
return 0;
|
|
}
|
|
|
|
int batch_apply(Batch *batch, const Command *command, Observation *out)
|
|
{
|
|
int result;
|
|
if (batch == NULL || command == NULL || out == NULL) return -2;
|
|
switch (command->kind) {
|
|
case COMMAND_TAKE:
|
|
result = apply_take(batch, command);
|
|
break;
|
|
case COMMAND_ERASE:
|
|
result = apply_erase(batch, command);
|
|
break;
|
|
case COMMAND_CLEAR:
|
|
result = apply_clear(batch, command);
|
|
break;
|
|
case COMMAND_QUERY:
|
|
result = apply_query(batch, command);
|
|
break;
|
|
default:
|
|
++batch->rejected;
|
|
result = -1;
|
|
break;
|
|
}
|
|
batch_observe(batch, result, out);
|
|
return result;
|
|
}
|
|
|
|
void batch_finish(Batch *batch, Observation *out)
|
|
{
|
|
int row;
|
|
if (batch == NULL || out == NULL) return;
|
|
for (row = 0; row < ROW_COUNT; ++row) row_clear(&batch->rows[row]);
|
|
batch_observe(batch, 0, out);
|
|
}
|