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

83 lines · 4527 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#ifndef OMEGA_CORE_H
18#define OMEGA_CORE_H
19
20#include <stddef.h>
21
22#include "omega_types.h"
23
24OmegaGraph* omega_graph_create(void);
25void omega_graph_destroy(OmegaGraph *g);
26OmegaObject* omega_graph_add_object(OmegaGraph *g, SemanticKind kind);
27OmegaObject* omega_graph_find_object(OmegaGraph *g, const SemanticId *id);
28const OmegaObject* omega_graph_find_object_const(const OmegaGraph *g, const SemanticId *id);
29
30/* Attribute / Relation / Constraint attachers */
31int omega_object_add_attribute(OmegaObject *obj, const char *key, const uint8_t *val, uint16_t val_len);
32int omega_object_add_relation(OmegaObject *obj, RelationKind kind, const SemanticId *target);
33int omega_object_add_constraint(OmegaObject *obj, ConstraintKind kind, const uint8_t *payload, uint16_t payload_len);
34
35/* Builders for canonical types */
36OmegaObject* omega_build_type_unit(OmegaGraph *g);
37OmegaObject* omega_build_type_bool(OmegaGraph *g);
38OmegaObject* omega_build_type_uint(OmegaGraph *g, uint16_t width);
39OmegaObject* omega_build_type_signed_int(OmegaGraph *g, uint16_t width);
40OmegaObject* omega_build_type_bitvector(OmegaGraph *g, uint16_t width);
41OmegaObject* omega_build_type_fp32(OmegaGraph *g); /* TYPE_FP32, width 32 */
42OmegaObject* omega_build_type_byte(OmegaGraph *g);
43OmegaObject* omega_build_type_sequence(OmegaGraph *g, const SemanticId *elem_type, uint32_t len);
44OmegaObject* omega_build_type_cap_ref(OmegaGraph *g);
45
46/* Builders for canonical values */
47OmegaObject* omega_build_val_bool(OmegaGraph *g, const SemanticId *bool_type_id, bool val);
48OmegaObject* omega_build_val_uint(OmegaGraph *g, const SemanticId *uint_type_id, uint16_t width, uint64_t val);
49
50/* Program parameter (spec/program-identity.md 2.2): KIND_VALUE, attribute
51 * "omega.param" = index (u16 big-endian), ValuePayload{type_id, byte_len 0}.
52 * Carries the position, never the source name; never equal to a literal. */
53OmegaObject* omega_build_param(OmegaGraph *g, const SemanticId *type_id, uint16_t index);
54
55/* Builders for operations and applications */
56OmegaObject* omega_build_op_binary(OmegaGraph *g, OpCode op, OverflowPolicy ov, const SemanticId *type_id);
57OmegaObject* omega_build_apply(OmegaGraph *g, const SemanticId *op_id, const SemanticId *arg1, const SemanticId *arg2);
58
59/* Builder for effect. cap_gen is the full 64-bit AIENOS capability generation. */
60OmegaObject* omega_build_effect(OmegaGraph *g, uint16_t res_class, uint16_t op_code, uint32_t cap_slot, uint64_t cap_gen);
61
62/* Effect payload v2 (spec/effect-cap64-migration.md): explicit 178-byte
63 * big-endian layout. encode is a plain serializer (writes every field as
64 * given); decode is strict and is the only way to read an effect payload. */
65#define OMEGA_EFFECT_OK 0
66#define OMEGA_EFFECT_ERR_ARG -1 /* null argument / not an effect object */
67#define OMEGA_EFFECT_ERR_LENGTH -2 /* payload length != OMEGA_EFFECT_PAYLOAD_LEN */
68#define OMEGA_EFFECT_ERR_LEGACY_V1 -3 /* 176-byte v1 host-struct payload (32-bit generation) */
69#define OMEGA_EFFECT_ERR_RESOURCE -4 /* resource_class == 0 */
70#define OMEGA_EFFECT_ERR_PARAM_LEN -5 /* param_len > 128 */
71#define OMEGA_EFFECT_ERR_PADDING -6 /* non-zero byte after param_len */
72int omega_effect_payload_encode(const EffectPayload *eff, uint8_t out[OMEGA_EFFECT_PAYLOAD_LEN]);
73int omega_effect_payload_decode(const uint8_t *bytes, size_t len, EffectPayload *out);
74/* Encode into obj->payload and set payload_len. Does NOT recompute the id. */
75int omega_effect_write(OmegaObject *obj, const EffectPayload *eff);
76/* Decode obj->payload of a KIND_EFFECT object. */
77int omega_effect_read(const OmegaObject *obj, EffectPayload *out);
78const char *omega_effect_strerror(int code);
79
80/* Evaluation of pure operations */
81int omega_eval_pure_binary_uint(OpCode op, OverflowPolicy ov, uint16_t width, uint64_t a, uint64_t b, uint64_t *out_res);
82
83#endif /* OMEGA_CORE_H */