blob: ce98863e465b94b0a902f7120ddd82f98367b1f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
(* Test Event 4 using slot 42 instead of slot 23 *)
open Nock_lib
let slam_on gate event =
let battery = Noun.head gate in
let context = Noun.tail (Noun.tail gate) in
let new_core = Noun.cell battery (Noun.cell event context) in
let kick_formula = Noun.cell (Noun.atom 9)
(Noun.cell (Noun.atom 2)
(Noun.cell (Noun.atom 0) (Noun.atom 1))) in
Nock.nock_on new_core kick_formula
let rec to_list acc noun =
match noun with
| Noun.Atom _ -> List.rev acc
| Noun.Cell (item, rest) -> to_list (item :: acc) rest
let test _env =
Printf.printf "š Testing Event 4 with Slot 42\n\n";
let in_channel = open_in_bin "solid.noun" in
let pill = (Marshal.from_channel in_channel : Noun.noun) in
close_in in_channel;
match pill with
| Noun.Cell (_tag, events) ->
let event_list = to_list [] events in
let kernel1 = List.nth event_list 1 in
let event3 = List.nth event_list 3 in
let event4 = List.nth event_list 4 in
(* Slam Event 3 with slot 23 *)
Printf.printf "=== Event 3 (slot 23) ===\n";
let poke_gate3 = Noun.slot (Z.of_int 23) kernel1 in
let result3 = slam_on poke_gate3 (Noun.cell (Noun.atom 0) event3) in
let kernel_after_3 = match result3 with
| Noun.Cell (_effects, new_kernel) ->
Printf.printf "ā Succeeded\n\n";
new_kernel
| _ -> kernel1
in
(* Try Event 4 with SLOT 42 *)
Printf.printf "=== Event 4 (slot 42) ===\n";
begin try
let poke_gate4 = Noun.slot (Z.of_int 42) kernel_after_3 in
Printf.printf "ā Found poke gate at slot 42\n";
(* Check gate structure *)
begin match poke_gate4 with
| Noun.Cell (battery, payload) ->
Printf.printf " Battery: %s\n" (match battery with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell");
begin match payload with
| Noun.Cell (_sample, _context) ->
Printf.printf " Payload: cell [sample context] ā\n\n"
| _ ->
Printf.printf " Payload: atom ā\n\n"
end
| _ -> ()
end;
Printf.printf "Slamming Event 4...\n";
let start = Unix.gettimeofday () in
let result4 = slam_on poke_gate4 (Noun.cell (Noun.atom 0) event4) in
let elapsed = Unix.gettimeofday () -. start in
begin match result4 with
| Noun.Cell (_effects, _new_kernel) ->
Printf.printf "ā Event 4 succeeded in %.4fs!\n\n" elapsed;
Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n";
Printf.printf " ššš FULL BOOT SUCCESS! ššš\n";
Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n\n";
Printf.printf "Boot sequence:\n";
Printf.printf " 1. Event 1: Initial larval kernel\n";
Printf.printf " 2. Event 3: Poked with slot 23 (larval)\n";
Printf.printf " 3. Kernel metamorphosed!\n";
Printf.printf " 4. Event 4: Poked with slot 42 (adult)\n\n";
Printf.printf "The kernel has metamorphosed from larval to adult!\n";
Printf.printf " - Larval poke: slot 23\n";
Printf.printf " - Adult poke: slot 42\n"
| Noun.Atom _ ->
Printf.printf "Result is atom\n"
end
with
| Noun.Exit ->
Printf.printf "ā Still failed with slot 42\n"
| Not_found ->
Printf.printf "ā No slot 42 found\n"
| e ->
Printf.printf "ā Error: %s\n" (Printexc.to_string e)
end
| Noun.Atom _ ->
Printf.printf "Pill is atom\n"
let () =
Printf.printf "\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n";
Printf.printf " Test Event 4 with Slot 42\n";
Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n\n";
Eio_main.run test
|