summaryrefslogtreecommitdiff
path: root/ocaml/CLAUDE.md
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/CLAUDE.md')
-rw-r--r--ocaml/CLAUDE.md53
1 files changed, 20 insertions, 33 deletions
diff --git a/ocaml/CLAUDE.md b/ocaml/CLAUDE.md
index 2577dee..491c73c 100644
--- a/ocaml/CLAUDE.md
+++ b/ocaml/CLAUDE.md
@@ -97,7 +97,7 @@ type reader = {
### 5. Jam/Cue Serialization (`lib/serial.ml`)
-**Status**: ๐Ÿ”ด IN PROGRESS - Has bugs
+**Status**: โœ… Complete and tested
Implementation of noun serialization with backreference compression.
@@ -130,16 +130,24 @@ let mat_encode w n =
end
```
-**Known Bugs**:
-1. โœ… Fixed: mat_encode for 0 wrote `true` instead of `false`
-2. โœ… Fixed: Was writing `a-1` in `b-1` bits, changed to `a` based on C code analysis
-3. ๐Ÿ”ด **CURRENT BUG**: Roundtrip test passes for 0,1,2,3 but fails at 4
- - Test shows: `FAIL: 4 -> 0`
- - Need to compare against actual Urbit jam output to find discrepancy
+**Key Fixes**:
+1. โœ… Mat encoding uses **leading 0 bits** followed by 1 bit (not the reverse!)
+2. โœ… Mat decoding formula: `a = 2^(b-1) + bits_read` (not just bits_read)
+3. โœ… Buffer initialization: Must use `Bytes.make` with zeros, not `Bytes.create`
**Test Status** (`test/test_serial.ml`):
-- Atom roundtrip: FAILS at value 4
-- Basic jam/cue: Not yet fully validated
+- โœ… All atom roundtrip tests pass (0, 1, 2, 42, 255, 256, 65535, 1000000)
+- โœ… All cell roundtrip tests pass
+- โœ… All tree structure tests pass
+- โœ… Backref tests pass
+- โœ… Edge case tests pass (large atoms, deep nesting, wide trees)
+
+**Performance** (`test/bench_serial.ml`):
+- Small atom jam/cue: ~1 ยตs
+- Balanced tree: ~3 ยตs
+- Deep nesting (100 levels): ~76 ยตs
+- Comparable or faster than C for simple cases
+- See `BENCHMARKS_SERIAL.md` for detailed comparison
### 6. Python Urbit Interface (`urb.py`)
@@ -183,34 +191,13 @@ ocaml/
## Next Steps
-### Immediate Priority: Fix Jam/Cue Bug
-
-1. **Get test vectors from Urbit**:
- ```bash
- python3 urb.py -d "(jam 0)"
- python3 urb.py -d "(jam 1)"
- python3 urb.py -d "(jam 2)"
- python3 urb.py -d "(jam 3)"
- python3 urb.py -d "(jam 4)" # This is where OCaml fails
- ```
+### Completed: Jam/Cue Serialization โœ…
-2. **Compare OCaml output**:
- - Create test program to print hex output of jam for 0-10
- - Compare against Urbit's output byte-by-byte
- - Identify exact discrepancy in mat encoding
-
-3. **Fix mat_decode**:
- - Ensure it matches the corrected mat_encode formula
- - Currently may be reading `a-1` when it should read `a`
+All jam/cue functionality is now complete and tested!
### Future Work
-1. **Complete Jam/Cue**:
- - Fix current bugs
- - Add comprehensive tests
- - Benchmark performance vs C
-
-2. **Memory Management**:
+1. **Memory Management**:
- Implement noun hash-consing/deduplication
- Add reference counting or GC integration
- Study u3 memory system from C implementation