diff options
author | polwex <polwex@sortug.com> | 2025-10-06 10:30:19 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-10-06 10:30:19 +0700 |
commit | 4be1d7f999ffb3eb1c12c54e863b141af21b3fbf (patch) | |
tree | 6e33b141cd98985799e02a253dddcf201fec6b74 /ocaml/test/examine_solid_structure.c | |
parent | c3545b7ba9e8448226417fab6edaa2d039c9babe (diff) |
some progress but man
Diffstat (limited to 'ocaml/test/examine_solid_structure.c')
-rw-r--r-- | ocaml/test/examine_solid_structure.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/ocaml/test/examine_solid_structure.c b/ocaml/test/examine_solid_structure.c new file mode 100644 index 0000000..158083c --- /dev/null +++ b/ocaml/test/examine_solid_structure.c @@ -0,0 +1,109 @@ +/// Examine solid pill structure using C Vere + +#include <sys/stat.h> +#include <stdio.h> +#include <stdlib.h> +#include "noun.h" +#include "ur/ur.h" +#include "vere.h" + +static void print_noun_structure(u3_noun noun, int depth, int max_depth) { + if (depth > max_depth) { + printf("..."); + return; + } + + if (u3_none == noun) { + printf("none"); + return; + } + + if (c3y == u3a_is_atom(noun)) { + if (u3r_met(3, noun) < 20) { + printf("atom(%u)", u3r_word(0, noun)); + } else { + printf("atom(large, %u bytes)", u3r_met(3, noun)); + } + } else { + printf("["); + print_noun_structure(u3h(noun), depth + 1, max_depth); + printf(" "); + print_noun_structure(u3t(noun), depth + 1, max_depth); + printf("]"); + } +} + +int main(int argc, char* argv[]) { + const char* pill_path = argc > 1 ? argv[1] : "../../../ocaml/solid.pill"; + + // Read pill + FILE* f = fopen(pill_path, "rb"); + if (!f) { + printf("Error: cannot open %s\n", pill_path); + return 1; + } + + struct stat st; + fstat(fileno(f), &st); + c3_d len_d = st.st_size; + c3_y* byt_y = malloc(len_d); + fread(byt_y, 1, len_d, f); + fclose(f); + + printf("Examining solid pill structure...\n\n"); + + // Initialize runtime + u3C.wag_w |= u3o_hashless; + u3m_boot_lite(1 << 26); + + // Cue pill + u3_cue_xeno* sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28); + u3_weak pil = u3s_cue_xeno_with(sil_u, len_d, byt_y); + u3s_cue_xeno_done(sil_u); + + if (u3_none == pil) { + printf("Error: cue failed\n"); + return 1; + } + + printf("Pill top-level structure:\n"); + print_noun_structure(pil, 0, 3); + printf("\n\n"); + + // Check if it's a cell + if (c3y == u3a_is_cell(pil)) { + printf("Pill is a cell [head tail]\n\n"); + + u3_noun head = u3h(pil); + u3_noun tail = u3t(pil); + + printf("Head: "); + print_noun_structure(head, 0, 2); + printf("\n\n"); + + printf("Tail: "); + print_noun_structure(tail, 0, 2); + printf("\n\n"); + + // Check if head is an atom (tag) + if (c3y == u3a_is_atom(head) && u3r_met(3, head) < 20) { + printf("Head is small atom: %u\n", u3r_word(0, head)); + printf(" (might be a tag)\n\n"); + } + + // If tail is a list, count elements + if (c3y == u3a_is_cell(tail)) { + int count = 0; + u3_noun cur = tail; + while (c3y == u3a_is_cell(cur) && count < 100) { + count++; + cur = u3t(cur); + } + printf("Tail appears to be a list with ~%d elements\n", count); + printf(" (these might be boot events)\n"); + } + } + + free(byt_y); + return 0; +} |