Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/src/physics0/pd0_world.h # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / physics0 / pd0_world.h` 82 lines ยท 3482 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 /* PD-0 black-box world (spec section 2) and the learner's channel to it. 18 * 19 * World side (links pd0_gen.c): pd0_world_* implements describe / reset / 20 * step with the bounded intervention rules, budgets, hash chain and the 21 * STAND_IN recorder. pd0_world_serve runs the request/response loop over two 22 * file descriptors so the world can be its own process (spec 2.4). 23 * 24 * Learner side (no generator knowledge): pd0_chan is the only handle the 25 * learner holds. It sends request bytes and receives record bytes, either 26 * through a pipe to the world process or through an in-process function 27 * pointer (tests). The learner never sees a pd0_world. */ 28 #ifndef PD0_WORLD_H 29 #define PD0_WORLD_H 30 31 #include 32 #include 33 34 #include "physics0/pd0_wire.h" 35 36 /* ---- learner side ---- */ 37 typedef size_t (*pd0_chan_fn)(void *ctx, const uint8_t *req, size_t req_len, uint8_t *resp, size_t cap); 38 typedef struct { 39 pd0_chan_fn fn; void *ctx; /* in-process transport */ 40 int in_fd, out_fd; /* or pipe transport (fn == NULL) */ 41 } pd0_chan; 42 43 /* framed pipe I/O shared by both ends (u32 length + bytes) */ 44 int pd0_read_full(int fd, uint8_t *buf, size_t n); 45 int pd0_write_full(int fd, const uint8_t *buf, size_t n); 46 /* each returns 0 ok, -1 transport or decode failure */ 47 int pd0_chan_describe(pd0_chan *c, pd0_desc *d); 48 int pd0_chan_reset(pd0_chan *c, uint8_t n_obs, const int64_t *vals, pd0_rec *r); 49 int pd0_chan_step(pd0_chan *c, uint8_t channel, int64_t value, pd0_rec *r); 50 51 /* ---- world side ---- */ 52 #ifdef PD0_WORLD_IMPL 53 #include "physics0/pd0_gen.h" 54 typedef struct { 55 pd0_gen gen; 56 pd0_desc desc; 57 uint64_t seed; 58 pd0_rng noise, null; 59 int64_t s[PD0_MAX_OBS], h; 60 int in_episode; 61 uint32_t step_in_episode, episodes_used, steps_used, episode; 62 uint64_t seq; 63 uint8_t last_hash[PD0_HASH]; 64 /* protocol v2 rev 2: final gate and refusal counters */ 65 int final_done; 66 uint8_t final_hash[PD0_HASH]; 67 uint32_t n_score_before_final, n_shape_before_final, n_play_after_final, n_dup_final; 68 } pd0_world; 69 70 int pd0_world_init(pd0_world *w, int level, uint64_t seed); 71 void pd0_world_describe(const pd0_world *w, pd0_desc *d); 72 void pd0_world_reset(pd0_world *w, const int64_t *vals, uint8_t n_vals, pd0_rec *r); 73 void pd0_world_step(pd0_world *w, uint8_t channel, int64_t value, pd0_rec *r); 74 /* one request -> one response (bytes); returns response length, 0 refused */ 75 size_t pd0_world_handle(pd0_world *w, const uint8_t *req, size_t len, uint8_t *resp, size_t cap); 76 /* pd0_chan_fn adapter around pd0_world_handle (ctx = pd0_world*) */ 77 size_t pd0_world_chan(void *ctx, const uint8_t *req, size_t len, uint8_t *resp, size_t cap); 78 /* serve until EOF on in_fd; frames are u32 length + bytes both ways */ 79 int pd0_world_serve(pd0_world *w, int in_fd, int out_fd); 80 #endif 81 82 #endif