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

6.3 KiB

Expression tree service contract

This C11 component supports a bounded arithmetic configuration tree. These clauses apply to every public entry point and all allowed inputs, including allocation failure and repeated replacement. Implementations may use any algorithm satisfying the interface in expr.h. Only initialized trees and trees created by these APIs are passed to an API. Callbacks and input byte ranges are valid for the call duration.

C01. ex_init installs the supplied allocator and an empty root. Node limit is 1..256 and depth limit is 1..32, with a root at depth one. Invalid limits or null required arguments return EX_ARGUMENT and leave the object unchanged. An already initialized tree must first be destroyed before a successful ex_init. Empty trees have count/height zero, render as an empty string, evaluate to zero and visit no nodes. ex_destroy accepts NULL and repeated destruction of an initialized tree.

C02. Input is an explicit byte range, never implicitly NUL terminated, at most 4096 bytes. ASCII space, tab, CR and LF are the only whitespace. Grammar is a signed decimal integer in [-1000000,1000000], a variable name matching [a-z][a-z0-9_]{0,14}, or '(' operator whitespace argument (whitespace argument)* ')'. Whitespace around a whole expression or after '(' is allowed. Operators are add, sub, mul, min, max (two arguments), neg, abs (one), and sum (one to eight). Arguments must be separated from the operator and each other by whitespace; ')' needs none. Leading zeroes and '-0' are accepted; '+' is not a sign. There must be exactly one expression. All other bytes, NUL included, unknown operators, wrong arity, missing delimiters and out of range literals return EX_SYNTAX. Input length above 4096, node/depth limits return EX_LIMIT. For malformed inputs that also exceed a tree limit either corresponding status is allowed. Tests keep these causes separate. Null text with length zero is an empty invalid expression; null text with nonzero length returns EX_ARGUMENT.

C03. Each node is exactly one sizeof(ex_node) allocation from the installed allocator. No other heap allocations or global node pools are allowed. A node's kind, number/name, arity and used children represent the grammar tree; number is zero for other kinds and name is empty except for variables. Unused child entries are not specified. Allocations return NULL after a configured failure budget. Every allocated node must eventually be returned once to the same allocator. A release must happen after all of that node's children have been released. The allocator is allowed to inspect node fields at release. ex_destroy frees every owned node and sets root to NULL without changing limits or allocator.

C04. ex_parse is transactional. Success replaces the whole old tree; failure leaves its existing nodes and value intact and returns every temporary node. Allocation failure returns EX_MEMORY. No partial new tree becomes visible. The old tree remains owned until the replacement is complete. The input is not modified, stored or used after return. No tree ownership is shared.

C05. ex_clone replaces destination with an independent deep copy of source using the destination allocator and limits. Empty source clears destination. Self clone is allowed. Failure is atomic and all temporary nodes are returned, with EX_MEMORY for allocation failure and EX_LIMIT for destination limits. Source is unchanged. All used structural fields must be copied; unused tail fields are unspecified.

C06. ex_count reports all nodes. ex_height is the longest root-to-leaf node count. ex_visit calls the supplied visitor for every node once, left to right in postorder; a null visitor is a no-op. Queries do not change any tree or allocate nodes.

C07. ex_render produces a canonical representation: decimal integers without leading zeroes, variable names unchanged, each group '(' + operator + one space before each canonical argument + ')'. Empty tree produces ''. *needed receives the byte count excluding NUL. Success needs capacity > needed and writes the representation plus NUL. Bytes after that NUL are unspecified. EX_BUFFER leaves the supplied buffer entirely unchanged but still reports needed. A null buffer is allowed only with capacity zero. No heap allocation or tree mutation occurs.

C08. ex_evaluate accepts at most 64 bindings, names as C02 and values in [-1000000000,1000000000]. Null bindings with positive count, invalid/duplicate names, out of range values or null output return EX_ARGUMENT. Validate every binding before evaluation, including unused bindings. Variable lookup uses exact names; missing bindings return EX_UNBOUND. Children are evaluated left to right; report the first child error. add/sub/mul/min/max/neg/abs have their mathematical meaning. sum adds left to right starting at zero. Every intermediate result must remain in [-1000000000000,1000000000000], otherwise EX_ARITH (avoid C signed overflow). Errors leave *out unchanged. Evaluation does not mutate the tree or allocate.

C09. All public operations are synchronous and finish for the above bounds. The component must not terminate its caller or access grader files. Diagnostics may be written to stderr, including arbitrary bytes; no stderr content affects grading. The observation executable prints its documented raw JSON lines on stdout only.

C10. observe.c is a public raw observation driver. P slot budget hex parses into one of two trees; '-' is zero bytes and budget -1 means no injected failure. C dst src budget clones. D slot destroys. I slot nodes depth destroys then initializes. Q slot capacity count name value ... evaluates and renders. Each operation emits [status, live_allocations, invalid_releases, parents_released_before_live_children, view0, view1, extra]. A view is [count,height,render_status,canonical,postorder], with postorder items [kind,number,name]. Q extra is [evaluate_status,value,render_status, needed,observed_buffer_hex]; initial value is 888888; success shows only bytes through NUL, failure shows capacity bytes initially filled with 5a. Other extras are []. EOF destroys both trees and emits ["END",live,invalid,early]. The allocator quarantines released blocks until process end so observations remain safe to inspect; these are still logically returned blocks. It records facts only, no expected results. Commands in demos and formal tests satisfy driver field bounds.