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>
131 lines
6.4 KiB
C
131 lines
6.4 KiB
C
#define _POSIX_C_SOURCE 200809L
|
|
#include "reduction.h"
|
|
#include <inttypes.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static struct rp_span spans[2][67];
|
|
static struct rp_chunk chunks[2];
|
|
static struct rp_result results[2];
|
|
static uint64_t digest(const void *object, size_t length)
|
|
{
|
|
const unsigned char *p = object;
|
|
uint64_t value = UINT64_C(1469598103934665603);
|
|
for (size_t i = 0; i < length; ++i) value = (value ^ p[i]) * UINT64_C(1099511628211);
|
|
return value;
|
|
}
|
|
static void chunk_json(const struct rp_chunk *c)
|
|
{
|
|
printf("[%zu,%" PRId64 ",%" PRId64 ",%" PRId64 "]",c->count,c->sum,c->minimum,c->maximum);
|
|
}
|
|
static void result_json(const struct rp_result *r)
|
|
{
|
|
printf("[%zu,",r->workers); chunk_json(&r->total);
|
|
for (size_t i = 0; i < RP_MAX_WORKERS; ++i) { putchar(','); chunk_json(&r->chunks[i]); }
|
|
putchar(']');
|
|
}
|
|
static void init_chunk(struct rp_chunk *c, int64_t seed)
|
|
{
|
|
c->count=(size_t)seed; c->sum=seed+1; c->minimum=seed+2; c->maximum=seed+3;
|
|
}
|
|
static void init_outputs(int64_t seed)
|
|
{
|
|
for (size_t s=0;s<2;++s) {
|
|
init_chunk(&chunks[s],seed+(int64_t)s*100);
|
|
results[s].workers=(size_t)(seed+(int64_t)s*100);
|
|
init_chunk(&results[s].total,seed+(int64_t)s*100+1);
|
|
for (size_t i=0;i<RP_MAX_WORKERS;++i)
|
|
init_chunk(&results[s].chunks[i],seed+(int64_t)s*100+(int64_t)i+2);
|
|
for (size_t i=0;i<67;++i) {
|
|
spans[s][i].begin=(size_t)(seed+(int64_t)s*100+(int64_t)i);
|
|
spans[s][i].end=spans[s][i].begin+1;
|
|
}
|
|
}
|
|
}
|
|
int main(void)
|
|
{
|
|
char op;
|
|
while (scanf(" %c", &op)==1) {
|
|
int slot, null_in, null_out, rc;
|
|
int64_t seed;
|
|
size_t count, workers, index;
|
|
if (op=='T') {
|
|
size_t length; unsigned byte;
|
|
int64_t output[2];
|
|
scanf("%d%d%d%" SCNd64 "%zu", &slot,&null_in,&null_out,&seed,&length);
|
|
unsigned char *data=malloc(length+2);
|
|
if (!data) return 3;
|
|
data[0]=199; data[length+1]=201;
|
|
for(size_t i=0;i<length;++i) { scanf("%u",&byte); data[i+1]=(unsigned char)byte; }
|
|
output[0]=seed; output[1]=seed+100;
|
|
uint64_t before=digest(data,length+2);
|
|
rc=rp_token_i64(null_in?NULL:(const char*)data+1,length,null_out?NULL:&output[slot]);
|
|
printf("[%d,%" PRId64 ",%" PRId64 ",%" PRIu64 ",%" PRIu64 "]\n",rc,output[0],output[1],before,digest(data,length+2));
|
|
free(data);
|
|
} else if (op=='S' || op=='L') {
|
|
scanf("%d%d%" SCNd64 "%zu%zu%zu",&slot,&null_out,&seed,&count,&workers,&index);
|
|
init_outputs(seed);
|
|
if(op=='S') rc=rp_span_for(count,workers,index,null_out?NULL:&spans[slot][0]);
|
|
else rc=rp_plan(count,workers,null_out?NULL:spans[slot],index);
|
|
printf("[%d",rc);
|
|
for(size_t s=0;s<2;++s) for(size_t i=0;i<67;++i)
|
|
printf(",%zu,%zu",spans[s][i].begin,spans[s][i].end);
|
|
puts("]");
|
|
} else if (op=='P') {
|
|
int64_t values[RP_MAX_ITEMS+1]; size_t n, begin, end;
|
|
scanf("%d%d%d%" SCNd64 "%zu%zu%zu%zu",&slot,&null_in,&null_out,&seed,&count,&begin,&end,&n);
|
|
for(size_t i=0;i<RP_MAX_ITEMS+1;++i) values[i]=seed+(int64_t)i;
|
|
for(size_t i=0;i<n;++i) scanf("%" SCNd64,&values[i]);
|
|
init_outputs(seed);
|
|
uint64_t before=digest(values,sizeof values);
|
|
rc=rp_partial(null_in?NULL:values,count,(struct rp_span){begin,end},null_out?NULL:&chunks[slot]);
|
|
printf("[%d,",rc); chunk_json(&chunks[0]); putchar(','); chunk_json(&chunks[1]);
|
|
printf(",%" PRIu64 ",%" PRIu64 "]\n",before,digest(values,sizeof values));
|
|
} else if (op=='M') {
|
|
struct rp_chunk input[RP_MAX_WORKERS+1]; size_t n;
|
|
scanf("%d%d%d%" SCNd64 "%zu%zu",&slot,&null_in,&null_out,&seed,&workers,&n);
|
|
memset(input,0,sizeof input);
|
|
for(size_t i=0;i<n;++i) scanf("%zu%" SCNd64 "%" SCNd64 "%" SCNd64,&input[i].count,&input[i].sum,&input[i].minimum,&input[i].maximum);
|
|
init_outputs(seed);
|
|
uint64_t before=digest(input,sizeof input);
|
|
rc=rp_merge(null_in?NULL:input,workers,null_out?NULL:&chunks[slot]);
|
|
printf("[%d,",rc); chunk_json(&chunks[0]); putchar(','); chunk_json(&chunks[1]);
|
|
printf(",%" PRIu64 ",%" PRIu64 "]\n",before,digest(input,sizeof input));
|
|
} else if (op=='R') {
|
|
struct rp_request requests[2]; size_t n;
|
|
scanf("%d%d%d%" SCNd64 "%zu%zu%" SCNd64 "%" SCNd64 "%zu",&slot,&null_in,&null_out,&seed,&count,&workers,&requests[0].lower,&requests[0].upper,&n);
|
|
int64_t lower=requests[0].lower, upper=requests[0].upper;
|
|
memset(requests,0,sizeof requests);
|
|
for(size_t s=0;s<2;++s) {
|
|
requests[s].count=0; requests[s].workers=1; requests[s].lower=-1; requests[s].upper=1;
|
|
for(size_t i=0;i<RP_MAX_ITEMS;++i) requests[s].values[i]=seed+(int64_t)s*100+(int64_t)i;
|
|
}
|
|
requests[slot].count=count; requests[slot].workers=workers;
|
|
requests[slot].lower=lower; requests[slot].upper=upper;
|
|
for(size_t i=0;i<n;++i) scanf("%" SCNd64,&requests[slot].values[i]);
|
|
init_outputs(seed);
|
|
uint64_t before[2]={digest(&requests[0],sizeof requests[0]),digest(&requests[1],sizeof requests[1])};
|
|
rc=rp_run(null_in?NULL:&requests[slot],null_out?NULL:&results[slot]);
|
|
printf("[%d,",rc); result_json(&results[0]); putchar(','); result_json(&results[1]);
|
|
printf(",%" PRIu64 ",%" PRIu64 ",%" PRIu64 ",%" PRIu64 "]\n",before[0],digest(&requests[0],sizeof requests[0]),before[1],digest(&requests[1],sizeof requests[1]));
|
|
} else if (op=='C') {
|
|
int mode;
|
|
scanf("%d",&mode);
|
|
FILE *input=tmpfile(), *output=tmpfile();
|
|
if(!input || !output) return 3;
|
|
fputs("0 1 0 1\n",input); rewind(input);
|
|
if(mode==3) { fclose(input); input=fopen(".","r"); }
|
|
if(mode==4) { fclose(output); output=fopen("/dev/full","w"); }
|
|
if(!input || !output) return 3;
|
|
rc=rp_console(mode==1?NULL:input,mode==2?NULL:output);
|
|
printf("[%d,\"",rc);
|
|
if(mode!=4) {
|
|
rewind(output); int byte;
|
|
while((byte=fgetc(output))!=EOF) printf("%02x",(unsigned char)byte);
|
|
}
|
|
puts("\"]"); fclose(input); fclose(output);
|
|
} else return 3;
|
|
}
|
|
return 0;
|
|
}
|