summaryrefslogtreecommitdiff
path: root/vere/pkg/noun
diff options
context:
space:
mode:
Diffstat (limited to 'vere/pkg/noun')
-rw-r--r--vere/pkg/noun/life_test.c96
-rw-r--r--vere/pkg/noun/vortex.c28
2 files changed, 117 insertions, 7 deletions
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;
{