summaryrefslogtreecommitdiff
path: root/vere/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'vere/pkg')
-rw-r--r--vere/pkg/noun/nock.c69
-rw-r--r--vere/pkg/noun/vortex.c6
-rw-r--r--vere/pkg/vere/solid_boot_test.c121
-rw-r--r--vere/pkg/vere/test_bisect_lifecycle.c74
-rw-r--r--vere/pkg/vere/test_op8.c49
-rw-r--r--vere/pkg/vere/test_opcodes.c78
-rw-r--r--vere/pkg/vere/test_simple_lifecycle.c42
7 files changed, 402 insertions, 37 deletions
diff --git a/vere/pkg/noun/nock.c b/vere/pkg/noun/nock.c
index eef211b..87fcf2c 100644
--- a/vere/pkg/noun/nock.c
+++ b/vere/pkg/noun/nock.c
@@ -22,7 +22,7 @@
// along with some other debugging info
# undef VERBOSE_BYTECODE
-#if 0
+#if 1
// Retained for debugging purposes.
static u3_noun _n_nock_on(u3_noun bus, u3_noun fol);
@@ -118,7 +118,7 @@ _n_hint(u3_noun zep,
case c3__memo: {
u3z(hod);
-#if 0
+#if 1
return _n_nock_on(bus, nex);
#else
{
@@ -168,9 +168,9 @@ _n_nock_on(u3_noun bus, u3_noun fol)
u3R->pro.nox_d += 1;
#endif
- // Trace first 30 opcodes
+ // Trace first 200 opcodes
static c3_w opcode_count = 0;
- if ( opcode_count < 30 ) {
+ if ( opcode_count < 200 ) {
if ( c3y == u3du(hib) ) {
u3l_log("[C-Nock:%u] cell-cell formula", opcode_count);
} else {
@@ -213,8 +213,29 @@ _n_nock_on(u3_noun bus, u3_noun fol)
u3_assert(!"not reached");
case 2: {
- u3_noun nex = _n_nock_on(u3k(bus), u3k(u3t(gal)));
- u3_noun seb = _n_nock_on(bus, u3k(u3h(gal)));
+ static c3_w op2_debug = 0;
+ u3_noun c_gal = u3t(gal);
+ u3_noun b_gal = u3h(gal);
+
+ if (op2_debug == 0) {
+ u3l_log("[Op2 Debug] Computing formula (tail gal):");
+ u3l_log(" c_gal mug: 0x%x", u3r_mug(c_gal));
+ }
+
+ u3_noun nex = _n_nock_on(u3k(bus), u3k(c_gal));
+
+ if (op2_debug == 0) {
+ u3l_log(" nex mug: 0x%x", u3r_mug(nex));
+ u3l_log("[Op2 Debug] Computing subject (head gal):");
+ u3l_log(" b_gal mug: 0x%x", u3r_mug(b_gal));
+ }
+
+ u3_noun seb = _n_nock_on(bus, u3k(b_gal));
+
+ if (op2_debug == 0) {
+ u3l_log(" seb mug: 0x%x", u3r_mug(seb));
+ op2_debug = 1;
+ }
u3a_lose(fol);
bus = seb;
@@ -372,35 +393,15 @@ _n_nock_on(u3_noun bus, u3_noun fol)
}
case 11: {
- u3_noun ref = _n_nock_on(u3k(bus), u3k(u3h(gal)));
- u3_noun gof = _n_nock_on(bus, u3k(u3t(gal)));
- u3_noun val;
-
- u3t_off(noc_o);
- val = u3m_soft_esc(u3k(ref), u3k(gof));
- u3t_on(noc_o);
-
- if ( !_(u3du(val)) ) {
- u3m_bail(u3nt(1, gof, 0));
- }
- if ( !_(u3du(u3t(val))) ) {
- //
- // replace with proper error stack push
- //
- u3t_push(u3nt(c3__hunk, ref, gof));
- return u3m_bail(c3__exit);
- }
- else {
- u3_noun pro;
-
- u3z(ref);
- u3z(gof);
- u3z(fol);
- pro = u3k(u3t(u3t(val)));
- u3z(val);
+ // Simplified opcode 11: just ignore the hint and evaluate q_gal
+ // This matches OCaml's implementation
+ u3_noun q_gal = u3t(gal);
+ u3_noun pro;
- return pro;
- }
+ // Ignore the hint (head of gal), just evaluate q_gal
+ pro = _n_nock_on(bus, u3k(q_gal));
+ u3a_lose(fol);
+ return pro;
}
u3_assert(!"not reached");
}
diff --git a/vere/pkg/noun/vortex.c b/vere/pkg/noun/vortex.c
index e4b55d9..f9c21d9 100644
--- a/vere/pkg/noun/vortex.c
+++ b/vere/pkg/noun/vortex.c
@@ -58,11 +58,17 @@ u3v_life(u3_noun eve)
}
}
+ // Check slot 3 before lifecycle
+ u3_noun eve_slot3 = u3r_at(3, eve);
+ u3l_log("u3v_life: eve slot 3 (before lifecycle) mug: 0x%x", u3r_mug(eve_slot3));
+
u3l_log("u3v_life: calling u3n_nock_on(eve, [2 [0 3] [0 2]])...");
u3_noun gat = u3n_nock_on(eve, lyf);
u3l_log("u3v_life: u3n_nock_on returned successfully");
+ u3l_log("u3v_life: gate mug: 0x%x", u3r_mug(gat));
u3_noun cor = u3k(u3x_at(7, gat));
+ u3l_log("u3v_life: slot 7 (kernel) mug: 0x%x", u3r_mug(cor));
u3z(gat);
u3l_log("u3v_life: completed successfully");
diff --git a/vere/pkg/vere/solid_boot_test.c b/vere/pkg/vere/solid_boot_test.c
index 26a0f07..8598125 100644
--- a/vere/pkg/vere/solid_boot_test.c
+++ b/vere/pkg/vere/solid_boot_test.c
@@ -258,21 +258,136 @@ _setup(void)
u3C.wag_w |= u3o_hashless;
u3m_boot_lite(1 << 28); // 256MB loom for solid pill
+ u3l_log("=== Testing ivory.pill first for comparison ===");
+ u3_noun ivory_jammed = u3m_file("/home/y/code/urbit/vere/ocaml/ivory.pill");
+ u3l_log("ivory_jammed is_atom: %u", u3a_is_atom(ivory_jammed));
+ u3_noun ivory = u3ke_cue(ivory_jammed);
+ u3l_log("ivory (after cue) is_atom: %u", u3a_is_atom(ivory));
+ u3l_log("");
+
+ u3l_log("=== Now testing solid.pill ===");
u3l_log("Loading solid.pill from OCaml directory...");
u3_noun solid_jammed = u3m_file("/home/y/code/urbit/vere/ocaml/solid.pill");
+ u3l_log(" solid_jammed is_atom: %u", u3a_is_atom(solid_jammed));
+ u3l_log(" solid_jammed mug: 0x%x", u3r_mug(solid_jammed));
u3l_log("Cuing solid.pill...");
u3_noun pil = u3ke_cue(solid_jammed);
// Don't free ivory_jammed - it's managed by u3m_file
u3l_log("solid_pil is_atom: %u", u3a_is_atom(pil));
+ u3l_log("solid_pil mug: 0x%x", u3r_mug(pil));
+
+ if (u3a_is_cell(pil)) {
+ u3l_log("solid_pil is a CELL!");
+ u3_noun h = u3h(pil);
+ u3_noun t = u3t(pil);
+ u3l_log(" head is_atom: %u", u3a_is_atom(h));
+ u3l_log(" tail is_atom: %u", u3a_is_atom(t));
+ }
+
+ // Parse solid pill structure [%pill %solid [bot mod use]]
+ u3_noun pill_tag, rest;
+ if ( c3n == u3r_cell(pil, &pill_tag, &rest) ) {
+ printf("*** fail: pill is not a cell\n");
+ exit(1);
+ }
+
+ // Structure is flat 4-tuple like mars.c line 1631: [typ bot mod use]
+ u3_noun typ, bot, mod, use;
+ if ( c3n == u3r_qual(rest, &typ, &bot, &mod, &use) ) {
+ printf("*** fail: cannot extract [typ bot mod use]\n");
+ exit(1);
+ }
+
+ if ( c3y == u3a_is_atom(typ) ) {
+ c3_c* typ_c = u3r_string(typ);
+ u3l_log("Pill type: %s", typ_c);
+ c3_free(typ_c);
+ }
+
+ u3l_log("Bot events: %llu", (unsigned long long)u3qb_lent(bot));
+ u3l_log("Mod events: %llu", (unsigned long long)u3qb_lent(mod));
+ u3l_log("Use events: %llu", (unsigned long long)u3qb_lent(use));
+
+ // Add boot event to use list (mars.c lines 1785-1789)
+ {
+ u3_noun wir = u3nq(c3__d, c3__term, '1', u3_nul);
+ u3_noun ven = u3nc(c3__fake, 0); // [%fake ~zod]
+ u3_noun cad = u3nt(c3__boot, c3n, ven); // [%boot lit venue]
+ use = u3nc(u3nc(wir, cad), use);
+ }
+
+ // Add system events to mod list (mars.c lines 1764-1789)
+ // Note: prepend in reverse order so wyrd comes first
+ {
+ u3_noun cad, wir = u3nt(u3_blip, c3__arvo, u3_nul);
+
+ // Version negotiation (wyrd) - prepended LAST so it's FIRST
+ u3_noun ver = u3nq(c3__vere, u3i_string("live"), u3i_string("3.5"), u3_nul);
+ u3_noun sen = u3i_string("0v1s.vu178");
+ u3_noun kel = u3nl(u3nc(c3__zuse, 409),
+ u3nc(c3__lull, 321),
+ u3nc(c3__arvo, 235),
+ u3nc(c3__hoon, 136),
+ u3nc(c3__nock, 4),
+ u3_none);
+ cad = u3nt(c3__wyrd, u3nc(sen, ver), kel);
+ mod = u3nc(u3nc(wir, cad), mod); // transfer [wir], wyrd is now at head
+
+ wir = u3nt(u3_blip, c3__arvo, u3_nul); // recreate wir
+
+ // Verbosity (verb)
+ cad = u3nt(c3__verb, u3_nul, c3n); // verbose = no
+ mod = u3nc(u3nc(u3k(wir), cad), mod);
+
+ // Identity (whom) - use fake ship ~zod
+ cad = u3nc(c3__whom, 0);
+ mod = u3nc(u3nc(u3k(wir), cad), mod);
+
+ // Entropy (wack) - prepended FIRST so it's LAST
+ c3_w eny_w[16];
+ for (int i = 0; i < 16; i++) {
+ eny_w[i] = 0xdeadbeef; // Simple test entropy
+ }
+ cad = u3nc(c3__wack, u3i_words(16, eny_w));
+ mod = u3nc(u3nc(wir, cad), mod); // transfer [wir], wack is now at head
+ }
+
+ u3l_log("After adding system events:");
+ u3l_log(" Bot events: %llu", (unsigned long long)u3qb_lent(bot));
+ u3l_log(" Mod events: %llu", (unsigned long long)u3qb_lent(mod));
+ u3l_log(" Use events: %llu", (unsigned long long)u3qb_lent(use));
+
+ // Build event list exactly like _mars_boot_make (lines 1903-1922)
+ 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));
+
+ {
+ u3_noun lit = u3qb_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);
+ }
+
+ u3z(lit);
+ }
+
+ u3_noun all_events = u3kb_flop(eve);
+ u3z(now); u3z(bit);
- // Boot with solid pill
- u3l_log("Booting with solid.pill from OCaml...");
- if ( c3n == u3v_boot_lite(pil) ) {
+ u3l_log("Booting with %llu events...", (unsigned long long)u3qb_lent(all_events));
+ if ( c3n == u3v_boot(all_events) ) {
printf("*** fail: solid boot failed\n");
exit(1);
}
u3l_log("✓ solid boot completed!");
+ u3l_log("Kernel mug: 0x%x", u3r_mug(u3A->roc));
}
/* _test_lily(): test small noun parsing.
diff --git a/vere/pkg/vere/test_bisect_lifecycle.c b/vere/pkg/vere/test_bisect_lifecycle.c
new file mode 100644
index 0000000..3aa26d1
--- /dev/null
+++ b/vere/pkg/vere/test_bisect_lifecycle.c
@@ -0,0 +1,74 @@
+/// Bisect ivory pill to find where lifecycle diverges
+
+#include "noun.h"
+#include "vere.h"
+
+static u3_noun lifecycle_formula;
+
+static void test_lifecycle(const char* name, u3_noun subject) {
+ u3l_log("Testing: %s", name);
+ u3l_log(" Subject mug: 0x%x", u3r_mug(subject));
+
+ // Check if subject has valid structure
+ if (c3n == u3a_is_cell(subject)) {
+ u3l_log(" SKIP: subject is atom\n");
+ return;
+ }
+
+ u3_noun slot2 = u3h(subject);
+ if (c3n == u3a_is_cell(slot2)) {
+ u3l_log(" SKIP: slot 2 is atom (not a formula)\n");
+ return;
+ }
+
+ // Try to run lifecycle
+ u3_noun result = u3n_nock_on(u3k(subject), u3k(lifecycle_formula));
+ u3l_log(" Result mug: 0x%x\n", u3r_mug(result));
+ u3z(result);
+}
+
+static void walk_tree(const char* prefix, u3_noun subject, c3_w depth, c3_w max_depth) {
+ if (depth >= max_depth) return;
+
+ // Test current node
+ test_lifecycle(prefix, subject);
+
+ // Walk children if cell
+ if (c3y == u3a_is_cell(subject)) {
+ char buf[256];
+ u3_noun h = u3h(subject);
+ u3_noun t = u3t(subject);
+
+ snprintf(buf, sizeof(buf), "%s.2", prefix);
+ walk_tree(buf, h, depth + 1, max_depth);
+
+ snprintf(buf, sizeof(buf), "%s.3", prefix);
+ walk_tree(buf, t, depth + 1, max_depth);
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ u3C.wag_w |= u3o_hashless;
+ u3m_boot_lite(1 << 28); // 256MB loom
+
+ // Load ivory pill
+ u3l_log("Loading ivory.pill from OCaml directory...");
+ u3_noun ivory_jammed = u3m_file("/home/y/code/urbit/vere/ocaml/ivory.pill");
+ u3l_log("Cuing ivory.pill...");
+ u3_noun pil = u3ke_cue(ivory_jammed);
+
+ u3_noun arvo_core = u3t(pil);
+ u3l_log("Ivory core mug: 0x%x\n", u3r_mug(arvo_core));
+
+ u3l_log("Walking tree and testing lifecycle at each node...");
+ u3l_log("Format: slot path (e.g. '.2.3' = slot 6)\n");
+
+ // Create lifecycle formula: [2 [0 3] [0 2]]
+ lifecycle_formula = u3nt(2, u3nc(0, 3), u3nc(0, 2));
+
+ // Walk tree up to depth 5
+ walk_tree("core", arvo_core, 0, 5);
+
+ return 0;
+}
diff --git a/vere/pkg/vere/test_op8.c b/vere/pkg/vere/test_op8.c
new file mode 100644
index 0000000..2819e49
--- /dev/null
+++ b/vere/pkg/vere/test_op8.c
@@ -0,0 +1,49 @@
+/// Test opcode 8 (extend)
+
+#include "noun.h"
+#include "vere.h"
+
+int main(int argc, char* argv[])
+{
+ u3C.wag_w |= u3o_hashless;
+ u3m_boot_lite(1 << 20); // 1MB loom
+
+ // Test: *[[42 99] [8 [1 123] [0 1]]]
+ // This should compute: *[[123 [42 99]] [0 1]] = [123 [42 99]]
+
+ u3_noun subject = u3nc(42, 99);
+ u3_noun formula = u3nc(8, u3nc(u3nc(1, 123), u3nc(0, 1)));
+
+ u3l_log("Subject: [42 99]");
+ u3l_log("Subject mug: 0x%x", u3r_mug(subject));
+ u3l_log("Formula: [8 [1 123] [0 1]]");
+ u3l_log("Formula mug: 0x%x\n", u3r_mug(formula));
+
+ u3l_log("This should compute:");
+ u3l_log(" 1. Evaluate [1 123] on [42 99] -> 123");
+ u3l_log(" 2. Extend subject: [123 [42 99]]");
+ u3l_log(" 3. Evaluate [0 1] on [123 [42 99]] -> [123 [42 99]]\n");
+
+ u3_noun result = u3n_nock_on(subject, formula);
+
+ u3l_log("Result mug: 0x%x", u3r_mug(result));
+ if (c3y == u3a_is_cell(result)) {
+ u3_noun h = u3h(result);
+ u3_noun t = u3t(result);
+ if (c3y == u3a_is_atom(h) && c3y == u3a_is_cell(t)) {
+ u3_noun th = u3h(t);
+ u3_noun tt = u3t(t);
+ if (c3y == u3a_is_atom(th) && c3y == u3a_is_atom(tt)) {
+ u3l_log("Result: [%u [%u %u]]", h, th, tt);
+ } else {
+ u3l_log("Result: cell (unexpected structure)");
+ }
+ } else {
+ u3l_log("Result: cell (unexpected structure)");
+ }
+ } else {
+ u3l_log("Result: atom");
+ }
+
+ return 0;
+}
diff --git a/vere/pkg/vere/test_opcodes.c b/vere/pkg/vere/test_opcodes.c
new file mode 100644
index 0000000..e7e8781
--- /dev/null
+++ b/vere/pkg/vere/test_opcodes.c
@@ -0,0 +1,78 @@
+/// Consolidated opcode tests
+
+#include "noun.h"
+#include "vere.h"
+
+static void test_name(const char* name) {
+ u3l_log("\n=== %s ===", name);
+}
+
+static void test_op2_simple() {
+ test_name("Opcode 2: Simple lifecycle [0 1] -> 99");
+ u3_noun formula_slot2 = u3nc(0, 1);
+ u3_noun payload = 99;
+ u3_noun subject = u3nc(formula_slot2, payload);
+ u3_noun formula = u3nt(2, u3nc(0, 3), u3nc(0, 2));
+
+ u3_noun result = u3n_nock_on(subject, formula);
+ u3l_log("Result: %u, mug: 0x%x", result, u3r_mug(result));
+}
+
+static void test_op7_compose() {
+ test_name("Opcode 7: Compose with [0 1]");
+ u3_noun formula_slot2 = u3nt(7, u3nc(0, 3), u3nc(0, 1));
+ u3_noun payload = u3nc(42, 99);
+ u3_noun subject = u3nc(formula_slot2, payload);
+ u3_noun formula = u3nt(2, u3nc(0, 3), u3nc(0, 2));
+
+ u3_noun result = u3n_nock_on(subject, formula);
+ u3l_log("Result mug: 0x%x", u3r_mug(result));
+ u3z(result);
+}
+
+static void test_op8_extend() {
+ test_name("Opcode 8: Extend subject");
+ u3_noun subject = u3nc(42, 99);
+ u3_noun formula = u3nc(8, u3nc(u3nc(1, 123), u3nc(0, 1)));
+
+ u3_noun result = u3n_nock_on(subject, formula);
+ if (c3y == u3a_is_cell(result)) {
+ u3_noun h = u3h(result);
+ u3_noun t = u3t(result);
+ if (c3y == u3a_is_atom(h) && c3y == u3a_is_cell(t)) {
+ u3_noun th = u3h(t);
+ u3_noun tt = u3t(t);
+ if (c3y == u3a_is_atom(th) && c3y == u3a_is_atom(tt)) {
+ u3l_log("Result: [%u [%u %u]], mug: 0x%x", h, th, tt, u3r_mug(result));
+ }
+ }
+ }
+ u3z(result);
+}
+
+static void test_op9_invoke() {
+ test_name("Opcode 9: Invoke core arm");
+ u3_noun core = u3nc(u3nc(0, 3), 42);
+ u3_noun formula = u3nc(9, u3nc(2, u3nc(0, 1)));
+
+ u3_noun result = u3n_nock_on(core, formula);
+ if (c3y == u3a_is_atom(result)) {
+ u3l_log("Result: %u, mug: 0x%x", result, u3r_mug(result));
+ }
+ u3z(result);
+}
+
+int main(int argc, char* argv[])
+{
+ u3C.wag_w |= u3o_hashless;
+ u3m_boot_lite(1 << 20);
+
+ u3l_log("Testing Nock opcodes...");
+ test_op2_simple();
+ test_op7_compose();
+ test_op8_extend();
+ test_op9_invoke();
+ u3l_log("\nAll tests complete.");
+
+ return 0;
+}
diff --git a/vere/pkg/vere/test_simple_lifecycle.c b/vere/pkg/vere/test_simple_lifecycle.c
new file mode 100644
index 0000000..3fd92aa
--- /dev/null
+++ b/vere/pkg/vere/test_simple_lifecycle.c
@@ -0,0 +1,42 @@
+/// Test simple lifecycle formula
+
+#include "noun.h"
+#include "vere.h"
+
+int main(int argc, char* argv[])
+{
+ u3C.wag_w |= u3o_hashless;
+ u3m_boot_lite(1 << 20); // 1MB loom
+
+ // Subject: [[7 [0 3] [0 1]] [42 99]]
+ // Formula: [7 [0 3] [0 1]] - compose: *[payload [0 1]] returns payload
+ u3_noun formula_slot2 = u3nt(7, u3nc(0, 3), u3nc(0, 1));
+ u3_noun payload = u3nc(42, 99);
+ u3_noun subject = u3nc(formula_slot2, payload);
+
+ // Lifecycle formula: [2 [0 3] [0 2]]
+ u3_noun formula = u3nt(2, u3nc(0, 3), u3nc(0, 2));
+
+ u3l_log("Subject: [[7 [0 3] [0 1]] [42 99]]");
+ u3l_log("Subject mug: 0x%x", u3r_mug(subject));
+ u3l_log("Formula: [2 [0 3] [0 2]]");
+ u3l_log("Formula mug: 0x%x\n", u3r_mug(formula));
+
+ u3l_log("Slot 2 (formula): [7 [0 3] [0 1]] (mug=0x%x)", u3r_mug(formula_slot2));
+ u3l_log("Slot 3 (payload): [42 99] (mug=0x%x)\n", u3r_mug(payload));
+
+ u3l_log("Running nock...");
+ u3l_log("This should compute: *[[42 99] [7 [0 3] [0 1]]]");
+ u3l_log("Which is: *[99 [0 1]] = 99\n");
+
+ u3_noun result = u3n_nock_on(subject, formula);
+
+ u3l_log("Result mug: 0x%x", u3r_mug(result));
+ if (c3y == u3a_is_atom(result)) {
+ u3l_log("Result: %u (atom)", result);
+ } else {
+ u3l_log("Result: cell");
+ }
+
+ return 0;
+}