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

107 lines
3.1 KiB
C

#include "expr.h"
#include <string.h>
static int bounded(int64_t value)
{
return value >= -EX_VALUE_LIMIT && value <= EX_VALUE_LIMIT;
}
static ex_status lookup(const ex_node *node, const ex_binding *bindings, size_t count, int64_t *value)
{
size_t i;
for (i = 0; i < count; ++i) {
if (bindings[i].name && !strcmp(node->name, bindings[i].name)) {
if (bindings[i].value < -1000000000 || bindings[i].value > 1000000000)
return EX_ARGUMENT;
*value = bindings[i].value;
return EX_OK;
}
}
return EX_UNBOUND;
}
static ex_status checked_add(int64_t left, int64_t right, int64_t *out)
{
int64_t result = left + right;
if (!bounded(result))
return EX_ARITH;
*out = result;
return EX_OK;
}
static ex_status checked_sub(int64_t left, int64_t right, int64_t *out)
{
int64_t result = left - right;
if (!bounded(result))
return EX_ARITH;
*out = result;
return EX_OK;
}
static ex_status checked_mul(int64_t left, int64_t right, int64_t *out)
{
int64_t a = left < 0 ? -left : left;
int64_t b = right < 0 ? -right : right;
if (a && b > EX_VALUE_LIMIT / a)
return EX_ARITH;
*out = left * right;
return EX_OK;
}
static ex_status evaluate_node(const ex_node *node, const ex_binding *bindings, size_t count, int64_t *out)
{
int64_t values[EX_MAX_CHILDREN];
int64_t value;
size_t i;
ex_status status;
if (node->kind == EX_NUMBER) {
*out = node->number;
return EX_OK;
}
if (node->kind == EX_VARIABLE)
return lookup(node, bindings, count, out);
for (i = 0; i < node->arity; ++i) {
status = evaluate_node(node->child[i], bindings, count, &values[i]);
if (status != EX_OK)
return status;
}
switch (node->kind) {
case EX_ADD:
return checked_add(values[0], values[1], out);
case EX_SUB:
return checked_sub(values[0], values[1], out);
case EX_MUL:
return checked_mul(values[0], values[1], out);
case EX_MIN:
*out = values[0] < values[1] ? values[0] : values[1];
return EX_OK;
case EX_MAX:
*out = values[0] > values[1] ? values[0] : values[1];
return EX_OK;
case EX_NEG:
*out = -values[0];
return EX_OK;
case EX_ABS:
*out = values[0] < 0 ? -values[0] : values[0];
return EX_OK;
case EX_SUM:
value = 0;
for (i = 0; i < node->arity; ++i) {
status = checked_add(value, values[i], &value);
if (status != EX_OK)
return status;
}
*out = value;
return EX_OK;
default:
return EX_ARGUMENT;
}
}
static int valid_binding_name(const char *name)
{
size_t i;
if (!name || name[0] < 'a' || name[0] > 'z')
return 0;
for (i = 1; name[i]; ++i) {
unsigned char c = (unsigned char)name[i];
if (i == EX_NAME_SIZE - 1 || !((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_'))
return 0;
}
return 1;
}
ex_status ex_evaluate(const ex_tree *t, const ex_binding *b, size_t n, int64_t *v) { (void)t; (void)b; (void)n; *v=23; return EX_OK; }