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 / visor / visor.h

130 lines · 5492 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 * visor.h -- Omega Visor V1 shared session contract (lead-owned).
19 *
20 * The Visor is a viewport over existing canonical Omega objects. This header
21 * holds ONLY the per-session bookkeeping every lane shares: one OmegaGraph,
22 * named bindings, the `_` last result, and bounded tables of programs and
23 * realizations. It carries no authority and no semantic meaning of its own.
24 *
25 * Rules (see spec/visor.md):
26 * - OmegaGraph is the only semantic store. Never duplicate object contents.
27 * - Nothing here may mint capabilities, publish, promote or mutate runtime state.
28 * - Every lookup fails closed: unknown names / ids return an error, never a guess.
29 * - Field/iteration order is deterministic so output can be tested byte-for-byte.
30 */
31#ifndef OMEGA_VISOR_H
32#define OMEGA_VISOR_H
33
34#include <stdbool.h>
35#include <stddef.h>
36#include <stdint.h>
37
38#include "omega_types.h"
39#include "omega_machine.h"
40#include "omega_program.h"
41#include "omega_realize.h"
42
43#define VISOR_MAX_BINDINGS 64
44#define VISOR_MAX_PROGRAMS 16
45#define VISOR_MAX_REALIZATIONS 16
46#define VISOR_NAME_LEN 64
47
48/* What a binding names. */
49typedef enum {
50 VISOR_BIND_NONE = 0,
51 VISOR_BIND_OBJECT = 1, /* a SemanticId present in session->graph */
52 VISOR_BIND_PROGRAM = 2, /* index into session->programs */
53 VISOR_BIND_REALIZATION = 3 /* index into session->realizations */
54} VisorBindKind;
55
56typedef struct {
57 char name[VISOR_NAME_LEN];
58 VisorBindKind kind;
59 SemanticId id; /* object id, program_id, or realization_id */
60 int index; /* table index for PROGRAM / REALIZATION, else -1 */
61} VisorBinding;
62
63typedef struct {
64 VisorBinding items[VISOR_MAX_BINDINGS];
65 size_t count;
66} VisorBindings;
67
68/* A realization the session built. `subject_id` is the semantic object the
69 * user asked to realize (e.g. an APPLY); `real.semantic_id` is whatever the
70 * existing realizer keyed on (for omega_realize_pure_binary that is the
71 * OPERATION id). Both are shown; neither is invented. */
72typedef struct {
73 RealizationObject real;
74 SemanticId subject_id;
75 bool subject_is_program;
76 int program_index; /* when subject_is_program */
77 SemanticId machine_id;
78 bool has_machine_id;
79 char target_name[32]; /* e.g. "aarch64-v8a", "qemu-virt", "dgx-spark" */
80 uint32_t estimated_cycles; /* from synthesis/machine estimate; 0 = none */
81 bool has_estimate;
82 /* Realizer's own compatibility verdict, carried with the entry so a later
83 * view/run sees it. verdict_known=false means "not evaluated" (treated as
84 * compatible). Direct realizations set known+compatible; synthesized
85 * alternatives set compatible per their differential check. */
86 bool verdict_known;
87 bool compatible;
88 char incompatible_reason[128];
89} VisorRealizationEntry;
90
91typedef struct {
92 OmegaGraph *graph; /* the single semantic store */
93 VisorBindings bindings;
94 bool has_last;
95 VisorBinding last; /* `_` */
96 OmegaProgram programs[VISOR_MAX_PROGRAMS];
97 size_t program_count;
98 VisorRealizationEntry realizations[VISOR_MAX_REALIZATIONS];
99 size_t realization_count;
100 OmegaMachineGraph machine; /* current machine model */
101 bool has_machine;
102 bool machine_is_observed; /* false = assumed profile, not measured */
103} VisorSession;
104
105/* Lifecycle. init returns 0 on success, -1 on allocation failure. */
106int visor_session_init(VisorSession *s);
107void visor_session_destroy(VisorSession *s);
108void visor_session_clear(VisorSession *s); /* `clear`: drop bindings + tables, fresh graph */
109
110/* Bindings. set replaces an existing name. Returns 0 / -1 (full or bad name). */
111int visor_binding_set(VisorSession *s, const char *name, VisorBindKind kind,
112 const SemanticId *id, int index);
113const VisorBinding *visor_binding_get(const VisorSession *s, const char *name);
114void visor_set_last(VisorSession *s, const VisorBinding *b);
115
116/* Resolve a user token: "_" | binding name | 64-hex SemanticId | "sha256:<hex>".
117 * A hex id resolves to VISOR_BIND_OBJECT only if it exists in the graph,
118 * otherwise to a PROGRAM/REALIZATION whose id matches. Returns 0 on success,
119 * -1 if nothing matches (fail closed). */
120int visor_resolve(const VisorSession *s, const char *token, VisorBinding *out);
121
122/* Table insertion. Return the new index or -1 when full. */
123int visor_program_add(VisorSession *s, const OmegaProgram *p);
124int visor_realization_add(VisorSession *s, const VisorRealizationEntry *e);
125
126/* Small shared formatting helpers so every lane prints ids the same way. */
127void visor_format_id(const SemanticId *id, char out[72]); /* "sha256:<64 hex>" */
128const char *visor_kind_name(SemanticKind k); /* "VALUE", "TYPE", ... */
129
130#endif /* OMEGA_VISOR_H */