blob: 96e0603f381b8f360bc8e7fe17fa8ecb8ef0b9dc (
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
|
(* Simple test of lifecycle formula on small noun *)
open Nock_lib
let () =
(* Test subject: [[formula] payload] *)
(* Formula: [7 [0 3] [0 1]] - compose: *[payload [0 1]] returns payload *)
(* Payload: [42 99] *)
let formula_slot2 = Noun.cell
(Noun.atom 7)
(Noun.cell
(Noun.cell (Noun.atom 0) (Noun.atom 3))
(Noun.cell (Noun.atom 0) (Noun.atom 1)))
in
let payload = Noun.cell (Noun.atom 42) (Noun.atom 99) in
let subject = Noun.cell formula_slot2 payload in
(* Lifecycle formula: [2 [0 3] [0 2]] *)
let formula = Noun.cell
(Noun.atom 2)
(Noun.cell
(Noun.cell (Noun.atom 0) (Noun.atom 3))
(Noun.cell (Noun.atom 0) (Noun.atom 2)))
in
Printf.printf "Subject: [[7 [0 3] [0 1]] [42 99]]\n";
Printf.printf "Subject mug: 0x%08lx\n" (Noun.mug subject);
Printf.printf "Formula: [2 [0 3] [0 2]]\n";
Printf.printf "Formula mug: 0x%08lx\n\n" (Noun.mug formula);
Printf.printf "Slot 2 of subject (formula): [7 [0 3] [0 1]] (mug=0x%08lx)\n"
(Noun.mug formula_slot2);
Printf.printf "Slot 3 of subject (payload): [42 99] (mug=0x%08lx)\n\n"
(Noun.mug payload);
Printf.printf "Running nock...\n";
Printf.printf "This should compute: *[[42 99] [7 [0 3] [0 1]]]\n";
Printf.printf "Which is: *[99 [0 1]] = 99\n\n";
let result = Nock.nock_on subject formula in
Printf.printf "Result mug: 0x%08lx\n" (Noun.mug result);
Printf.printf "Result: %s\n"
(match result with
| Noun.Atom { z; _ } -> Z.to_string z
| Noun.Cell _ -> "cell")
|