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>
72 lines
2.0 KiB
C
72 lines
2.0 KiB
C
#include "model_internal.h"
|
|
|
|
int fm_open(struct fm_model *model, int process, int stream, int description)
|
|
{
|
|
struct fm_stream *target;
|
|
int result;
|
|
if (process < 0 || process >= FM_PROCESS_CAP ||
|
|
stream < 0 || stream >= FM_STREAM_CAP ||
|
|
description < 0 || description >= FM_DESCRIPTION_CAP) {
|
|
return FM_RANGE;
|
|
}
|
|
result = fm_process_check(model, process);
|
|
if (result != FM_OK) {
|
|
return result;
|
|
}
|
|
target = &model->processes[process].streams[stream];
|
|
if (target->description >= 0) {
|
|
return FM_BUSY;
|
|
}
|
|
fm_stream_clear(target);
|
|
target->description = description;
|
|
model->descriptions[description].references += 1;
|
|
return FM_OK;
|
|
}
|
|
|
|
int fm_seek(struct fm_model *model, int process, int stream, size_t offset)
|
|
{
|
|
int description;
|
|
int result;
|
|
if (process < 0 || process >= FM_PROCESS_CAP ||
|
|
stream < 0 || stream >= FM_STREAM_CAP || offset > model->capacity) {
|
|
return FM_RANGE;
|
|
}
|
|
result = fm_stream_check(model, process, stream);
|
|
if (result != FM_OK) {
|
|
return result;
|
|
}
|
|
description = model->processes[process].streams[stream].description;
|
|
model->descriptions[description].offset = offset;
|
|
return FM_OK;
|
|
}
|
|
|
|
int fm_fork(struct fm_model *model, int parent, int child)
|
|
{
|
|
int stream;
|
|
int result;
|
|
struct fm_process *copy;
|
|
if (parent < 0 || parent >= FM_PROCESS_CAP ||
|
|
child < 0 || child >= FM_PROCESS_CAP) {
|
|
return FM_RANGE;
|
|
}
|
|
result = fm_process_check(model, parent);
|
|
if (result != FM_OK) {
|
|
return result;
|
|
}
|
|
if (model->processes[child].alive) {
|
|
return FM_BUSY;
|
|
}
|
|
copy = &model->processes[child];
|
|
*copy = model->processes[parent];
|
|
copy->used = 1;
|
|
copy->alive = 1;
|
|
copy->code = 0;
|
|
for (stream = 0; stream < FM_STREAM_CAP; ++stream) {
|
|
int description = copy->streams[stream].description;
|
|
if (description >= 0) {
|
|
model->descriptions[description].references += 1;
|
|
}
|
|
}
|
|
return FM_OK;
|
|
}
|