interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / src / osh / osh_expand_ref.h

83 lines · 3044 bytes Raw Blame History
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/*
18 * osh_expand_ref.h -- an independent C reference expander for osh R1, used ONLY for differential testing of the OSC
19 * expander (osh_expand.osc). Written from the rules (E-parser-design.md section 4, ABI draft sections 6.3 and 7.1,
20 * the DECISIONS in osh_expand.osc.in's header) over the reference tokenizer and parser tables, as "pieces then
21 * fields" (a word becomes a sequence of pieces; each piece is applied to a field builder), not as the OSC byte
22 * state machine. Not a shell, not for production.
23 */
24#ifndef OSH_EXPAND_REF_H
25#define OSH_EXPAND_REF_H
26#include <stddef.h>
27#include <stdint.h>
28
29#include "osh_lex_ref.h"
30#include "osh_parse_ref.h"
31
32#define OSH_XR_VALCAP 1300 /* room for a value above CAP_VALUE so the test can exceed it */
33#define OSH_XR_MAXVARS 24
34#define OSH_XR_MAXPOS 24
35#define OSH_XR_OUTCAP 8192
36#define OSH_XR_MAXREQ 80
37
38typedef struct {
39 int set;
40 size_t len;
41 uint8_t b[OSH_XR_VALCAP];
42} OshXrStr;
43
44typedef struct {
45 int nvars;
46 struct {
47 char name[40];
48 OshXrStr v;
49 } var[OSH_XR_MAXVARS];
50 int npos; /* $1..$npos */
51 OshXrStr arg0;
52 OshXrStr pos[OSH_XR_MAXPOS];
53 uint64_t status; /* $? */
54} OshXrEnv;
55
56/* The host side of the NEED_VAR protocol (ABI 6.3), shared by the driver (as the host) and the reference.
57 * kind 1 name[0..nlen), 2 $?, 3 positional k, 4 $#, 5 count only. *found, *len (may exceed 1024), *npos; bytes
58 * copied to val (up to OSH_XR_VALCAP). */
59void osh_xr_env_get(const OshXrEnv *env, int kind, const uint8_t *name, size_t nlen, uint64_t k, int *found, size_t *len, uint64_t *npos, uint8_t *val);
60
61typedef struct {
62 int kind;
63 uint64_t a, len;
64} OshXrReq;
65
66typedef struct {
67 unsigned status; /* 103 ready, else a refusal code */
68 uint64_t err_off;
69 uint64_t rec[8 + 8 * 164];
70 size_t nrec;
71 uint8_t out[OSH_XR_OUTCAP];
72 size_t out_used;
73 OshXrReq req[OSH_XR_MAXREQ];
74 unsigned nreq;
75} OshXrOut;
76
77/* First pipeline index >= cand that runs, given the connector rules and the status of the last executed pipeline
78 * (noskip: cand itself). Returns npipe when none is left. */
79unsigned osh_xr_next(const OshRefParse *pr, unsigned cand, uint64_t last_status, int noskip);
80
81/* Expand pipeline p of a completed list. */
82void osh_xr_pipe(const uint8_t *in, size_t n, const OshRefLex *lx, const OshRefParse *pr, const OshXrEnv *env, unsigned p, OshXrOut *out);
83#endif