summaryrefslogtreecommitdiff
path: root/vere
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-06 17:07:33 +0700
committerpolwex <polwex@sortug.com>2025-10-06 17:07:33 +0700
commita4615148975bed241ae26ffa2655dc9c407107d8 (patch)
treebd127b13f0027cd2870b8f016c5658465785d3df /vere
parent256376afffe66faa239a6a6aaebb8f68a9c6cbe4 (diff)
maybe now maybe now
Diffstat (limited to 'vere')
-rw-r--r--vere/build.zig10
-rw-r--r--vere/pkg/noun/life_test.c96
-rw-r--r--vere/pkg/noun/vortex.c28
-rw-r--r--vere/pkg/vere/boot_tests.c48
-rw-r--r--vere/pkg/vere/king.c7
-rw-r--r--vere/pkg/vere/main.c2
-rw-r--r--vere/pkg/vere/mars.c34
-rw-r--r--vere/pkg/vere/solid_boot_test.c178
8 files changed, 394 insertions, 9 deletions
diff --git a/vere/build.zig b/vere/build.zig
index 66318a0..707ca2b 100644
--- a/vere/build.zig
+++ b/vere/build.zig
@@ -616,6 +616,11 @@ fn buildBinary(
.file = "pkg/noun/serial_tests.c",
.deps = noun_test_deps,
},
+ .{
+ .name = "life-test",
+ .file = "pkg/noun/life_test.c",
+ .deps = noun_test_deps,
+ },
// pkg_vere
.{
.name = "ames-test",
@@ -628,6 +633,11 @@ fn buildBinary(
.deps = vere_test_deps,
},
.{
+ .name = "solid-boot-test",
+ .file = "pkg/vere/solid_boot_test.c",
+ .deps = vere_test_deps,
+ },
+ .{
.name = "newt-test",
.file = "pkg/vere/newt_tests.c",
.deps = vere_test_deps,
diff --git a/vere/pkg/noun/life_test.c b/vere/pkg/noun/life_test.c
new file mode 100644
index 0000000..cffe97b
--- /dev/null
+++ b/vere/pkg/noun/life_test.c
@@ -0,0 +1,96 @@
+/// @file
+/// Test lifecycle formula on different subjects
+
+#include "noun.h"
+
+/* _setup(): prepare for tests.
+*/
+static void
+_setup(void)
+{
+ u3m_boot_lite(1 << 28); // 256MB loom
+}
+
+/* Helper to run nock with subject+formula in a cell for u3m_soft */
+static u3_noun
+_nock_pair(u3_noun sub_fol)
+{
+ u3_noun sub, fol;
+ u3x_cell(sub_fol, &sub, &fol);
+ return u3n_nock_on(u3k(sub), u3k(fol));
+}
+
+/* _test_life_on_null(): test lifecycle formula on atom 0
+*/
+static c3_i
+_test_life_on_null(void)
+{
+ fprintf(stderr, "\n=================================================\n");
+ fprintf(stderr, "Testing lifecycle formula [2 [0 3] [0 2]] on null\n");
+ fprintf(stderr, "=================================================\n\n");
+
+ /* Build lifecycle formula: [2 [0 3] [0 2]] */
+ u3_noun lyf = u3nt(2, u3nc(0, 3), u3nc(0, 2));
+
+ fprintf(stderr, "Formula: [2 [0 3] [0 2]]\n");
+ fprintf(stderr, "Subject: 0 (null)\n");
+ fprintf(stderr, "Formula mug: %x\n\n", u3r_mug(lyf));
+
+ /* Test on null (atom 0) */
+ u3_noun eve = 0; /* u3_nul is defined as 0 */
+
+ fprintf(stderr, "Testing: *[0 [2 [0 3] [0 2]]]\n\n");
+
+ /* Try running it - need to pass [subject formula] as single argument */
+ u3_noun pair = u3nc(eve, lyf);
+ u3_noun pro = u3m_soft(0, _nock_pair, pair);
+
+ if ( u3_blip != u3h(pro) ) {
+ fprintf(stderr, "✗ FAILED!\n");
+ fprintf(stderr, "Error: ");
+ u3m_p("", u3h(pro));
+ fprintf(stderr, "\n");
+
+ /* Print trace if available */
+ if ( u3du(pro) ) {
+ fprintf(stderr, "\nTrace:\n");
+ u3m_p("trace", u3t(pro));
+ fprintf(stderr, "\n");
+ }
+
+ fprintf(stderr, "\nThis confirms the formula CANNOT work on atom 0!\n");
+ u3z(pro);
+ return 0;
+ }
+
+ fprintf(stderr, "✓ SUCCESS!\n");
+ fprintf(stderr, "Result mug: %x\n", u3r_mug(u3t(pro)));
+ fprintf(stderr, "\nResult structure:\n");
+ u3m_p("result", u3t(pro));
+ fprintf(stderr, "\n");
+
+ fprintf(stderr, "\nThis is UNEXPECTED! The formula somehow works on atom 0 in C!\n");
+
+ u3z(pro);
+
+ return 1;
+}
+
+int
+main(int argc, char* argv[])
+{
+ _setup();
+
+ if ( !_test_life_on_null() ) {
+ fprintf(stderr, "test life on null: failed (as expected)\r\n");
+ fprintf(stderr, "This is actually the CORRECT behavior - lifecycle formula cannot work on null.\r\n");
+ return 0; // Return success since failure is expected
+ }
+
+ // GC
+ //
+ u3m_grab(u3_none);
+
+ fprintf(stderr, "test life on null: unexpected success!\r\n");
+ return 0;
+}
diff --git a/vere/pkg/noun/vortex.c b/vere/pkg/noun/vortex.c
index 0d6d1cf..63b4fc2 100644
--- a/vere/pkg/noun/vortex.c
+++ b/vere/pkg/noun/vortex.c
@@ -25,14 +25,17 @@ u3v_home* u3v_Home;
u3_noun
u3v_life(u3_noun eve)
{
- c3_o is_null = u3r_sing(u3_nul, eve);
- c3_o is_atom = u3a_is_atom(eve);
- c3_o is_cell = u3du(eve);
+ u3l_log("u3f_life()");
+
- u3l_log("u3v_life: eve=%s (atom=%s cell=%s)",
- is_null ? "null" : (is_cell ? "cell" : "atom"),
- is_atom ? "yes" : "no",
- is_cell ? "yes" : "no");
+ c3_o is_atom = u3a_is_atom(eve);
+ c3_d len_d;
+ {
+ u3_noun len = u3qb_lent(eve);
+ u3_assert( c3y == u3r_safe_chub(len, &len_d) );
+ u3z(len);
+ }
+ u3l_log("u3v_life: processing %llu events", (unsigned long long)len_d);
u3_noun lyf = u3nt(2, u3nc(0, 3), u3nc(0, 2));
u3_noun gat = u3n_nock_on(eve, lyf);
@@ -48,6 +51,7 @@ u3v_life(u3_noun eve)
c3_o
u3v_boot(u3_noun eve)
{
+
c3_d len_d;
{
u3_noun len = u3qb_lent(eve);
@@ -105,8 +109,18 @@ _cv_lite(u3_noun pil)
c3_o
u3v_boot_lite(u3_noun pil)
{
+
// ensure zero-initialized kernel
//
+ c3_d len_d;
+ {
+ u3_noun len = u3qb_lent(pil);
+ u3_assert( c3y == u3r_safe_chub(len, &len_d) );
+ u3z(len);
+ }
+
+ u3l_log("u3v_boot_lite: processing %llu events", (unsigned long long)len_d);
+
u3A->roc = 0;
{
diff --git a/vere/pkg/vere/boot_tests.c b/vere/pkg/vere/boot_tests.c
index d9728d8..c90c538 100644
--- a/vere/pkg/vere/boot_tests.c
+++ b/vere/pkg/vere/boot_tests.c
@@ -17,11 +17,59 @@ _setup(void)
u3C.wag_w |= u3o_hashless;
u3m_boot_lite(1 << 26);
+ // this follows king.c
sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28);
if ( u3_none == (pil = u3s_cue_xeno_with(sil_u, len_d, byt_y)) ) {
printf("*** fail _setup 1\n");
exit(1);
}
+
+ u3l_log("embed_pil_is_atom %u", u3a_is_atom(pil));
+ u3_noun local_pil = u3m_file("/home/y/code/urbit/vere/ocaml/ivory.pill");
+ u3_noun cued_pil = u3ke_cue(local_pil);
+
+ u3l_log("local_pil_is_atom %u", u3a_is_atom(local_pil));
+ u3l_log("cued_pil_is_atom %u", u3a_is_atom(cued_pil));
+
+ c3_d len_pp;
+ {
+ u3_noun len = u3qb_lent(pil);
+ u3_assert( c3y == u3r_safe_chub(len, &len_pp) );
+ u3z(len);
+ }
+ u3l_log("embedded pill length %llu", (unsigned long long)len_pp);
+ c3_d len_pp2;
+ {
+ u3_noun len = u3qb_lent(cued_pil);
+ u3_assert( c3y == u3r_safe_chub(len, &len_pp2) );
+ u3z(len);
+ }
+ u3l_log("file_pill_length %llu", (unsigned long long)len_pp2);
+
+ // 1. Direct equality check
+ c3_o match = u3r_sing(pil, cued_pil);
+ u3l_log("pills equal: %u", match);
+
+ // 2. Compare mugs (32-bit hashes)
+ u3l_log("embedded mug: %x", u3r_mug(pil));
+ u3l_log("file mug: %x", u3r_mug(cued_pil));
+
+ // 3. If they're cells, compare heads
+ if ( c3y == u3a_is_cell(pil) && c3y == u3a_is_cell(cued_pil) ) {
+ u3l_log("head mug embedded: %x", u3r_mug(u3h(pil)));
+ u3l_log("head mug file: %x", u3r_mug(u3h(cued_pil)));
+ }
+
+ // 4. Jam both and compare sizes
+ u3_noun jam1 = u3qe_jam(pil);
+ u3_noun jam2 = u3qe_jam(cued_pil);
+ u3l_log("jammed embedded: %u met", u3r_met(3, jam1));
+ u3l_log("jammed file: %u met", u3r_met(3, jam2));
+ u3l_log("jams equal: %u", u3r_sing(jam1, jam2));
+ u3z(jam1); u3z(jam2);
+
+
+ //
u3s_cue_xeno_done(sil_u);
if ( c3n == u3v_boot_lite(pil) ) {
printf("*** fail _setup 2\n");
diff --git a/vere/pkg/vere/king.c b/vere/pkg/vere/king.c
index 0a2aef7..dd4711a 100644
--- a/vere/pkg/vere/king.c
+++ b/vere/pkg/vere/king.c
@@ -616,7 +616,7 @@ _boothack_pill(void)
c3_c url_c[2048];
if ( (c3y == u3_Host.ops_u.git) &&
- (0 != u3_Host.ops_u.arv_c) )
+ (0 != u3_Host.ops_u.arv_c) )
{
_git_pill_url(url_c, u3_Host.ops_u.arv_c);
}
@@ -714,9 +714,11 @@ static u3_noun
_boothack_doom(void)
{
u3_noun pax = u3i_string(u3_Host.dir_c);
+ u3m_p("pax boothack_doom", pax);
u3_noun bot;
if ( c3n == u3_Host.ops_u.nuu ) {
+ u3l_log("u3_Host.ops.u.nuu");
return u3nt(c3__pier, u3_nul, pax);
}
else if ( 0 != u3_Host.ops_u.fak_c ) {
@@ -961,6 +963,7 @@ _king_loop_exit()
static void
_king_boot_ivory(void)
{
+ u3l_log("king boot ivory");
c3_d len_d;
c3_y* byt_y;
@@ -1007,6 +1010,8 @@ _king_boot_ivory(void)
void
u3_king_commence()
{
+ u3l_log("king commence");
+
u3_Host.lup_u = uv_default_loop();
// initialize top-level timer
diff --git a/vere/pkg/vere/main.c b/vere/pkg/vere/main.c
index a547e23..db19f77 100644
--- a/vere/pkg/vere/main.c
+++ b/vere/pkg/vere/main.c
@@ -1293,6 +1293,8 @@ _cw_eval(c3_i argc, c3_c* argv[])
u3_cue_xeno* sil_u;
u3_weak pil;
+ u3l_log("initialize loom and load ivory main.c");
+
u3C.wag_w |= u3o_hashless;
u3m_boot_lite((size_t)1 << u3_Host.ops_u.lom_y);
sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28);
diff --git a/vere/pkg/vere/mars.c b/vere/pkg/vere/mars.c
index 5f9eb68..7b1ed03 100644
--- a/vere/pkg/vere/mars.c
+++ b/vere/pkg/vere/mars.c
@@ -1153,10 +1153,28 @@ _mars_do_boot(u3_disk* log_u, c3_d eve_d, u3_noun cax)
u3l_log("--------------- bootstrap starting ----------------");
- u3l_log("boot: 1-%u", u3qb_lent(eve));
+ c3_d eve_count = u3qb_lent(eve);
+ u3l_log("boot: 1-%llu", (unsigned long long)eve_count);
+ u3l_log("_mars_do_boot: eve list has %llu events", (unsigned long long)eve_count);
+
+ // Check structure of first event
+ if ( u3_nul != eve ) {
+ u3_noun first = u3h(eve);
+ c3_o is_atom = u3a_is_atom(first);
+ c3_o is_cell = u3a_is_cell(first);
+ u3l_log("_mars_do_boot: first event is %s", is_cell ? "cell" : (is_atom ? "atom" : "unknown"));
+
+ if ( is_cell ) {
+ u3_noun fst_h = u3h(first);
+ u3_noun fst_t = u3t(first);
+ u3l_log(" first event head: %s", u3a_is_atom(fst_h) ? "atom (timestamp?)" : "cell");
+ u3l_log(" first event tail: %s", u3a_is_atom(fst_t) ? "atom" : "cell");
+ }
+ }
// XX check mug if available
//
+ u3l_log("_mars_do_boot: calling u3v_boot(eve)...");
if ( c3n == u3v_boot(eve) ) {
return c3n;
}
@@ -1814,10 +1832,21 @@ _mars_boot_make(u3_boot_opts* inp_u,
// timestamp events, cons list
//
{
+ c3_d bot_c = u3qb_lent(bot);
+ c3_d mod_c = u3qb_lent(mod);
+ c3_d use_c = u3qb_lent(use);
+
+ u3l_log("_mars_boot_make: assembling events");
+ u3l_log(" bot (lifecycle): %llu events (NO timestamp)", (unsigned long long)bot_c);
+ u3l_log(" mod (vanes): %llu events (WITH timestamp)", (unsigned long long)mod_c);
+ u3l_log(" use (userspace): %llu events (WITH timestamp)", (unsigned long long)use_c);
+
u3_noun now = u3_time_in_tv(&inp_u->tim_u);
u3_noun bit = u3qc_bex(48); // 1/2^16 seconds
u3_noun eve = u3kb_flop(bot);
+ u3l_log(" starting with bot events (untimestamped)");
+
{
u3_noun lit = u3kb_weld(mod, use);
u3_noun i, t = lit;
@@ -1832,6 +1861,7 @@ _mars_boot_make(u3_boot_opts* inp_u,
}
*ova = u3kb_flop(eve);
+ u3l_log(" final event list: %llu events", (unsigned long long)u3qb_lent(*ova));
u3z(now); u3z(bit);
}
@@ -1907,6 +1937,8 @@ u3_mars_boot(u3_mars* mar_u, c3_d len_d, c3_y* hun_y)
u3_meta met_u;
u3_noun com, ova, cax;
+ u3l_log("u3_mars_boot()");
+
inp_u.veb_o = __( u3C.wag_w & u3o_verbose );
inp_u.lit_o = c3n; // unimplemented in arvo
diff --git a/vere/pkg/vere/solid_boot_test.c b/vere/pkg/vere/solid_boot_test.c
new file mode 100644
index 0000000..b0d5200
--- /dev/null
+++ b/vere/pkg/vere/solid_boot_test.c
@@ -0,0 +1,178 @@
+/// @file
+/// Test solid pill boot flow - exactly as mars.c does it
+
+#include "vere.h"
+
+static void
+_setup(void)
+{
+ u3m_boot_lite(1 << 28); // 256MB loom
+}
+
+/* Helper wrapper for u3v_boot to use with u3m_soft */
+static u3_noun
+_boot_wrapper(u3_noun ova)
+{
+ if ( c3n == u3v_boot(ova) ) {
+ return u3nc(c3__exit, u3_nul);
+ }
+ return u3nc(u3_blip, u3_nul);
+}
+
+/* _test_solid_boot(): boot from solid.pill following exact mars.c flow
+*/
+static c3_i
+_test_solid_boot(void)
+{
+ fprintf(stderr, "\n");
+ fprintf(stderr, "═══════════════════════════════════════════════════\n");
+ fprintf(stderr, " Solid Pill Boot Test (Exact C Vere Flow)\n");
+ fprintf(stderr, "═══════════════════════════════════════════════════\n\n");
+
+ /* Step 1: Load solid.pill (like king.c:611) */
+ fprintf(stderr, "[1] Loading solid.pill (u3m_file like king.c)...\n");
+ u3_noun pil_p = u3m_file("solid.pill");
+ // u3_noun pil_p = u3m_file("/home/y/code/urbit/vere/ocaml/solid.pill");
+ u3_noun arv = u3_nul;
+ c3_o arv_atom = u3a_is_atom(arv);
+ c3_o atom2 = u3a_is_atom(42);
+ c3_o atom3 = u3a_is_atom(u3nc(1, 5));
+ u3l_log("arv_atom %u", arv_atom);
+ u3l_log("atoms ? %u - %u", atom2, atom3);
+ u3l_log("c3y %u", c3y);
+ u3l_log("c3n %u", c3n);
+ u3_noun pil2 = u3nc(pil_p, arv);
+
+ fprintf(stderr, " ✓ Loaded pill as atom\n\n");
+
+ /* Step 2: Cue the pill atom (like _mars_sift_pill:1597) */
+ fprintf(stderr, "[2] Cuing pill atom (like _mars_sift_pill)...\n");
+ u3_noun pro = u3m_soft(0, u3ke_cue, u3k(pil_p));
+ u3_noun mot, tag, dat;
+
+ if ( (c3n == u3r_trel(pro, &mot, &tag, &dat))
+ || (u3_blip != mot) )
+ {
+ fprintf(stderr, " ✗ Failed to cue pill\n");
+ u3z(pro);
+ u3z(pil_p);
+ return 0;
+ }
+
+ /* Check for %pill tag */
+ if ( c3__pill != tag ) {
+ fprintf(stderr, " ✗ Not a pill (expected %%pill tag)\n");
+ u3z(pro);
+ u3z(pil_p);
+ return 0;
+ }
+
+ fprintf(stderr, " ✓ Cued successfully, got %%pill\n\n");
+
+ /* Step 3: Parse pill structure [%solid [bot mod use]] */
+ fprintf(stderr, "[3] Parsing pill structure...\n");
+
+ u3_noun sol_tag, events;
+ if ( c3n == u3r_cell(dat, &sol_tag, &events) ) {
+ fprintf(stderr, " ✗ Invalid pill data structure\n");
+ u3z(pro);
+ u3z(pil_p);
+ return 0;
+ }
+
+ /* Extract bot, mod, use */
+ u3_noun bot, mod, use;
+ if ( c3n == u3r_trel(events, &bot, &mod, &use) ) {
+ fprintf(stderr, " ✗ Cannot extract bot/mod/use\n");
+ u3z(pro);
+ u3z(pil_p);
+ return 0;
+ }
+
+ u3k(bot); u3k(mod); u3k(use);
+ u3z(pro);
+ u3z(pil_p);
+
+ c3_d bot_c = u3qb_lent(bot);
+ c3_d mod_c = u3qb_lent(mod);
+ c3_d use_c = u3qb_lent(use);
+
+ fprintf(stderr, " Bot events: %llu\n", (unsigned long long)bot_c);
+ fprintf(stderr, " Mod events: %llu\n", (unsigned long long)mod_c);
+ fprintf(stderr, " Use events: %llu\n", (unsigned long long)use_c);
+ fprintf(stderr, " Total: %llu events\n\n",
+ (unsigned long long)(bot_c + mod_c + use_c));
+
+ /* Step 4: Build event list (like _mars_boot_make lines 1814-1836) */
+ fprintf(stderr, "[4] Building event list (C Vere style)...\n");
+ fprintf(stderr, " Bot events: NOT timestamped\n");
+ fprintf(stderr, " Mod/use events: timestamped\n\n");
+
+ struct timeval tim_u;
+ gettimeofday(&tim_u, 0);
+ u3_noun now = u3_time_in_tv(&tim_u);
+ u3_noun bit = u3qc_bex(48); // 1/2^16 seconds
+ u3_noun eve = u3kb_flop(u3k(bot)); // Bot events WITHOUT timestamp
+
+ {
+ u3_noun lit = u3kb_weld(u3k(mod), u3k(use));
+ u3_noun i, t = lit;
+
+ while ( u3_nul != t ) {
+ u3x_cell(t, &i, &t);
+ now = u3ka_add(now, u3k(bit));
+ eve = u3nc(u3nc(u3k(now), u3k(i)), eve); // WITH timestamp
+ }
+
+ u3z(lit);
+ }
+
+ u3_noun ova = u3kb_flop(eve);
+ u3z(now); u3z(bit);
+ u3z(bot); u3z(mod); u3z(use);
+
+ c3_d eve_count = u3qb_lent(ova);
+ fprintf(stderr, " ✓ Event list built: %llu events\n\n", (unsigned long long)eve_count);
+
+ /* Step 5: Call u3v_boot (like _mars_do_boot line 1160) */
+ fprintf(stderr, "[5] Calling u3v_boot with event list...\n");
+ fprintf(stderr, " (This is what actually happens in C Vere!)\n\n");
+
+ u3_noun boot_pro = u3m_soft(0, _boot_wrapper, ova);
+
+ if ( u3_blip != u3h(boot_pro) ) {
+ fprintf(stderr, " ✗ BOOT FAILED!\n");
+ fprintf(stderr, " Error: ");
+ u3m_p("", u3h(boot_pro));
+ fprintf(stderr, "\n");
+ u3z(boot_pro);
+ return 0;
+ }
+
+ fprintf(stderr, " ✓ BOOT SUCCEEDED!\n");
+ fprintf(stderr, " Kernel mug: %x\n", u3r_mug(u3A->roc));
+ fprintf(stderr, "\n");
+
+ fprintf(stderr, "═══════════════════════════════════════════════════\n");
+ fprintf(stderr, " ✓ SOLID PILL BOOT TEST PASSED!\n");
+ fprintf(stderr, "═══════════════════════════════════════════════════\n\n");
+
+ u3z(boot_pro);
+
+ return 1;
+}
+
+int
+main(int argc, char* argv[])
+{
+ _setup();
+
+ if ( !_test_solid_boot() ) {
+ fprintf(stderr, "test solid boot: FAILED\r\n");
+ return 1;
+ }
+
+ u3m_grab(u3_none);
+ fprintf(stderr, "test solid boot: OK\r\n");
+ return 0;
+}