diff --git a/delta_mesh/Registry.c b/delta_mesh/Registry.c new file mode 100644 index 0000000..d39486a --- /dev/null +++ b/delta_mesh/Registry.c @@ -0,0 +1,55 @@ +#include "Registry.h" +#include +#include + +// Internal helper to ensure capacity +static int registry_ensure_capacity(Registry* r) { + if (r->entries == NULL) { + size_t cap = 4; + r->entries = (RegistryEntry*)calloc(cap, sizeof(RegistryEntry)); + if (!r->entries) return -1; + r->capacity = cap; + r->count = 0; + return 0; + } + if (r->count < r->capacity) return 0; + size_t newcap = r->capacity * 2; + RegistryEntry* tmp = (RegistryEntry*)realloc(r->entries, newcap * sizeof(RegistryEntry)); + if (!tmp) return -1; + // Initialize new slots to zero + for (size_t i = r->capacity; i < newcap; ++i) { + tmp[i].key = NULL; + tmp[i].value = NULL; + tmp[i].version = 0; + } + r->entries = tmp; + r->capacity = newcap; + return 0; +} + +void registry_init(Registry* r) { + r->entries = NULL; + r->count = 0; + r->capacity = 0; + // lazy initialization on first register +} + +int registry_register(Registry* r, const char* key, const char* value, int version) { + if (registry_ensure_capacity(r) != 0) return -1; + RegistryEntry e; + e.key = key; + e.value = value; + e.version = version; + r->entries[r->count++] = e; + return 0; +} + +const char* registry_lookup(Registry* r, const char* key) { + if (!r || !r->entries) return NULL; + for (size_t i = 0; i < r->count; ++i) { + if (r->entries[i].key && strcmp(r->entries[i].key, key) == 0) { + return r->entries[i].value; + } + } + return NULL; +} diff --git a/delta_mesh/Registry.h b/delta_mesh/Registry.h new file mode 100644 index 0000000..dcbe5dd --- /dev/null +++ b/delta_mesh/Registry.h @@ -0,0 +1,23 @@ +// Simple in-process registry to map canonical primitives to versions/handles +#ifndef REGISTRY_H +#define REGISTRY_H + +#include + +typedef struct RegistryEntry { + const char* key; + const char* value; + int version; +} RegistryEntry; + +typedef struct Registry { + RegistryEntry* entries; + size_t count; + size_t capacity; +} Registry; + +void registry_init(Registry* r); +int registry_register(Registry* r, const char* key, const char* value, int version); +const char* registry_lookup(Registry* r, const char* key); + +#endif diff --git a/delta_mesh/Registry.o b/delta_mesh/Registry.o new file mode 100644 index 0000000..cdb0b2f Binary files /dev/null and b/delta_mesh/Registry.o differ diff --git a/delta_mesh/delta_crdt.c b/delta_mesh/delta_crdt.c new file mode 100644 index 0000000..47c7b48 --- /dev/null +++ b/delta_mesh/delta_crdt.c @@ -0,0 +1,4 @@ +#include "delta_crdt.h" + +// No heavy implementation needed for a toy MVP; this file exists to +// satisfy build expectations and to place future CRDT logic here. diff --git a/delta_mesh/delta_crdt.h b/delta_mesh/delta_crdt.h new file mode 100644 index 0000000..301ebf6 --- /dev/null +++ b/delta_mesh/delta_crdt.h @@ -0,0 +1,20 @@ +// Lightweight CRDT-like delta structure and merge utility +#ifndef DELTA_CRDT_H +#define DELTA_CRDT_H + +typedef struct DeltaCRDT { + unsigned long version; + double value_delta; +} DeltaCRDT; + +// Merge two deltas by choosing the one with the higher version. +static inline void crdt_merge(const DeltaCRDT* a, const DeltaCRDT* b, DeltaCRDT* out) { + if (!a || !b || !out) return; + if (a->version >= b->version) { + *out = *a; + } else { + *out = *b; + } +} + +#endif diff --git a/delta_mesh/delta_crdt.o b/delta_mesh/delta_crdt.o new file mode 100644 index 0000000..8a27125 Binary files /dev/null and b/delta_mesh/delta_crdt.o differ diff --git a/delta_mesh/demo b/delta_mesh/demo index a4c4997..9ba0dcf 100755 Binary files a/delta_mesh/demo and b/delta_mesh/demo differ diff --git a/delta_mesh/demo_main.c b/delta_mesh/demo_main.c index 491bfd5..d2c4efb 100644 --- a/delta_mesh/demo_main.c +++ b/delta_mesh/demo_main.c @@ -1,16 +1,43 @@ #include #include "LocalMarket.h" #include "admm_lite.h" +#include "Registry.h" +#include "dsl_seed.h" +#include "delta_crdt.h" // A tiny demo that creates two LocalMarkets and demonstrates a simple ADMM-lite step. int main(void) { + // 1) Demonstrate a simple registry usage (GoC-like bridge) + Registry reg; + registry_init(®); + registry_register(®, "LocalMarket", "v1.0", 1); + registry_register(®, "SharedSignals", "v1.0", 1); + const char* lm_ver = registry_lookup(®, "LocalMarket"); + printf("DeltaMesh REG: LocalMarket -> %s\n", lm_ver ? lm_ver : ""); + + // 2) Demonstrate DSL seed usage (toy initialization) + LocalMarketSeed lm_seed; + dsl_localmarket_seed_init(&lm_seed, "VenueA", 100.0, 50.0); + SharedSignalsSeed ss_seed; + dsl_sharedsignals_seed_init(&ss_seed, 0.25, 0.18); + PlanDeltaSeed pd_seed; + dsl_plandelta_seed_init(&pd_seed, 0.5, 0.2, 12345); + printf("DeltaMesh DSL seeds: lm=%s, ivol=%.3f, quote=%.3f\n", + lm_seed.venue, ss_seed.implied_vol, pd_seed.quote); + + // 3) Demonstrate a CRDT-like delta merge (toy) + DeltaCRDT d1 = { .version = 1, .value_delta = 0.2 }; + DeltaCRDT d2 = { .version = 2, .value_delta = -0.1 }; + DeltaCRDT merged = {0}; + crdt_merge(&d1, &d2, &merged); + printf("DeltaMesh CRDT merge: ver=%lu delta=%.4f\n", merged.version, merged.value_delta); + + // 4) Simple ADMM-lite step using existing demo helper for compatibility LocalMarket v1 = {"VenueA", 100.0, 50.0}; LocalMarket v2 = {"VenueB", 150.0, 75.0}; - double quotes[2] = { v1.inventory, v2.inventory }; double aggregate = 0.0; admm_lite_step(quotes, 2, &aggregate); - printf("DeltaMesh DEMO: aggregated quote = %f\n", aggregate); return 0; } diff --git a/delta_mesh/demo_main.o b/delta_mesh/demo_main.o index b171076..0b29804 100644 Binary files a/delta_mesh/demo_main.o and b/delta_mesh/demo_main.o differ diff --git a/delta_mesh/dsl_seed.c b/delta_mesh/dsl_seed.c index cb4a45e..c624608 100644 --- a/delta_mesh/dsl_seed.c +++ b/delta_mesh/dsl_seed.c @@ -1,11 +1,21 @@ -// Minimal DSL seed implementation for DeltaMesh MVP (toy). #include "dsl_seed.h" -#include -// Example entry point to exercise the seed artifacts without pulling external deps. -void dsl_seed_example_log(void) { - AuditLog log = { "delta_seed_initialized", 0 }; - (void)log; // suppress unused warning in a tiny demo - // No-op print guarded by a macro in a real build; kept tiny to avoid side effects. - // printf("%s @ %lu\n", log.entry, log.timestamp); +void dsl_localmarket_seed_init(LocalMarketSeed* s, const char* venue, double inventory, double risk_budget) { + if (!s) return; + s->venue = venue; + s->inventory = inventory; + s->risk_budget = risk_budget; +} + +void dsl_sharedsignals_seed_init(SharedSignalsSeed* s, double greeks, double ivol) { + if (!s) return; + s->aggregated_greeks = greeks; + s->implied_vol = ivol; +} + +void dsl_plandelta_seed_init(PlanDeltaSeed* s, double quote, double hedge, unsigned long ts) { + if (!s) return; + s->quote = quote; + s->hedge = hedge; + s->timestamp = ts; } diff --git a/delta_mesh/dsl_seed.h b/delta_mesh/dsl_seed.h index 490829a..20bccc7 100644 --- a/delta_mesh/dsl_seed.h +++ b/delta_mesh/dsl_seed.h @@ -1,24 +1,28 @@ -// Minimal DSL seed primitives for DeltaMesh MVP (toy). -// This header provides lightweight, forward-looking data structures that -// can be used by adapters and the coordination layer to agree on contract -// representations without leaking raw data. +// Lightweight seed structures for LocalMarket, SharedSignals, and PlanDelta +// to bootstrap interoperability in the DeltaMesh MVP. #ifndef DSL_SEED_H #define DSL_SEED_H -typedef struct LocalArbProblem { - double objective; // toy objective value for the arb problem - unsigned long timestamp; // monotonic timestamp for replay -} LocalArbProblem; +typedef struct LocalMarketSeed { + const char* venue; + double inventory; + double risk_budget; +} LocalMarketSeed; -typedef struct AuditLog { - const char* entry; // human-readable log entry or hash - unsigned long timestamp; // log timestamp for replay and audit -} AuditLog; +typedef struct SharedSignalsSeed { + double aggregated_greeks; + double implied_vol; +} SharedSignalsSeed; -typedef struct GovernanceBlock { - const char* policy; // description of governance constraint - unsigned long timestamp; // policy versioning / timestamp -} GovernanceBlock; +typedef struct PlanDeltaSeed { + double quote; + double hedge; + unsigned long timestamp; +} PlanDeltaSeed; + +void dsl_localmarket_seed_init(LocalMarketSeed* s, const char* venue, double inventory, double risk_budget); +void dsl_sharedsignals_seed_init(SharedSignalsSeed* s, double greeks, double ivol); +void dsl_plandelta_seed_init(PlanDeltaSeed* s, double quote, double hedge, unsigned long ts); #endif diff --git a/delta_mesh/dsl_seed.o b/delta_mesh/dsl_seed.o new file mode 100644 index 0000000..ab3b1be Binary files /dev/null and b/delta_mesh/dsl_seed.o differ diff --git a/test.sh b/test.sh index d436ec3..a23c27f 100644 --- a/test.sh +++ b/test.sh @@ -13,7 +13,10 @@ $cc $CCFLAGS -c delta_mesh/LocalMarket.c -o delta_mesh/LocalMarket.o || true $cc $CCFLAGS -c delta_mesh/SharedSignals.c -o delta_mesh/SharedSignals.o || true $cc $CCFLAGS -c delta_mesh/PlanDelta.c -o delta_mesh/PlanDelta.o || true $cc $CCFLAGS -c delta_mesh/EnergiBridge.c -o delta_mesh/EnergiBridge.o -$cc $CCFLAGS -o delta_mesh/demo delta_mesh/demo_main.o delta_mesh/admm_lite.o delta_mesh/LocalMarket.o delta_mesh/SharedSignals.o delta_mesh/PlanDelta.o delta_mesh/EnergiBridge.o +$cc $CCFLAGS -c delta_mesh/Registry.c -o delta_mesh/Registry.o || true +$cc $CCFLAGS -c delta_mesh/dsl_seed.c -o delta_mesh/dsl_seed.o || true +$cc $CCFLAGS -c delta_mesh/delta_crdt.c -o delta_mesh/delta_crdt.o || true +$cc $CCFLAGS -o delta_mesh/demo delta_mesh/demo_main.o delta_mesh/admm_lite.o delta_mesh/LocalMarket.o delta_mesh/SharedSignals.o delta_mesh/PlanDelta.o delta_mesh/EnergiBridge.o delta_mesh/Registry.o delta_mesh/dsl_seed.o delta_mesh/delta_crdt.o echo "Running demo..." ./delta_mesh/demo