/// Examine solid pill structure using C Vere #include #include #include #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; }