amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27,
11 canonical families), 38 skipped for scope or duplication. Each task
has at least one independent contract-edge defect, boundary types
rotate, and public docs state trap clauses as plain contract prose.
Claude reviewed 63/63 USABLE against current digests. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:14:57 +08:00

50 lines
1.8 KiB
C

#include "model_internal.h"
int fm_exit(struct fm_model *model, int process, int mode, unsigned int code)
{
size_t offsets[FM_DESCRIPTION_CAP];
int s, d, result;
struct fm_process *target;
if (process < 0 || process >= FM_PROCESS_CAP ||
(mode != FM_NORMAL && mode != FM_QUICK) || code > 255)
return FM_RANGE;
result = fm_process_check(model, process);
if (result != FM_OK) return result;
target = &model->processes[process];
for (d = 0; d < FM_DESCRIPTION_CAP; ++d)
offsets[d] = model->descriptions[d].offset;
if (mode == FM_NORMAL) {
for (s = 0; s < FM_STREAM_CAP; ++s) {
const struct fm_stream *stream = &target->streams[s];
d = stream->description;
if (d >= 0 && stream->length != 0) {
if (stream->length > model->capacity - offsets[d])
return FM_NOSPACE;
offsets[d] += stream->length;
}
}
}
for (s = 0; s < FM_STREAM_CAP; ++s) {
struct fm_stream *stream = &target->streams[s];
d = stream->description;
if (d < 0) continue;
if (mode == FM_NORMAL && stream->length != 0) {
struct fm_description *file = &model->descriptions[d];
size_t i;
while (file->length < file->offset)
file->bytes[file->length++] = 0;
for (i = 0; i < stream->length; ++i)
file->bytes[file->offset++] = stream->pending[i];
if (file->offset > file->length) file->length = file->offset;
++file->commits;
}
--model->descriptions[d].references;
stream->description = -1;
stream->length = 0;
}
target->alive = 0;
target->used = 1;
target->code = code;
return FM_OK;
}