omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / research / atemporal / at0 / model / at0_main.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* at0-model: run one AT0_CASE_V1 case through the candidate engine. |
| 18 | * at0-model <case-file> [--reversed] |
| 19 | * stdout: OMEGA-AT0-ENGINE v1 text. Refused case: stderr "AT0_CASE_REFUSED <code>", |
| 20 | * exit 2 (AT0_RESULT_V1 section 5). Other failures: stderr "AT0_ENGINE_ERROR <code>", exit 1. */ |
| 21 | #include "at0_model.h" |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | |
| 25 | int main(int argc, char **argv) |
| 26 | { |
| 27 | if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[2], "--reversed") != 0)) { |
| 28 | fprintf(stderr, "usage: at0-model <case-file> [--reversed]\n"); |
| 29 | return 1; |
| 30 | } |
| 31 | at0_case *c = calloc(1, sizeof *c); |
| 32 | at0_engine_result *r = calloc(1, sizeof *r); |
| 33 | char *buf = malloc(1 << 20); |
| 34 | if (!c || !r || !buf) { fprintf(stderr, "AT0_ENGINE_ERROR ERR_INTERNAL\n"); return 1; } |
| 35 | at0_status st = at0_case_read_file(argv[1], c); |
| 36 | if (at0_status_is_refusal(st)) { fprintf(stderr, "AT0_CASE_REFUSED %s\n", at0_status_name(st)); free(c); free(r); free(buf); return 2; } |
| 37 | if (st != AT0_OK) { fprintf(stderr, "AT0_ENGINE_ERROR %s\n", at0_status_name(st)); free(c); free(r); free(buf); return 1; } |
| 38 | st = argc == 3 ? at0_engine_run_reversed(c, r) : at0_engine_run(c, r); |
| 39 | if (st != AT0_OK) { fprintf(stderr, "AT0_ENGINE_ERROR %s\n", at0_status_name(st)); free(c); free(r); free(buf); return 1; } |
| 40 | long n = at0_engine_emit(c, r, buf, 1 << 20); |
| 41 | if (n < 0) { fprintf(stderr, "AT0_ENGINE_ERROR ERR_INTERNAL\n"); free(c); free(r); free(buf); return 1; } |
| 42 | int rc = fwrite(buf, 1, (size_t)n, stdout) == (size_t)n && fflush(stdout) == 0 ? 0 : 1; |
| 43 | if (rc) fprintf(stderr, "AT0_ENGINE_ERROR ERR_IO\n"); |
| 44 | free(c); free(r); free(buf); |
| 45 | return rc; |
| 46 | } |