feat: +13 tests (184/233, 79%) — case, hex/radix, protocol/record stubs, doseq destructuring

This commit is contained in:
2026-05-09 19:53:08 +03:00
parent 0ba94881be
commit 6633c3708d
6 changed files with 412 additions and 59 deletions
+44 -31
View File
@@ -1,17 +1,32 @@
# Clojure/Nim — Test Suite Compliance Plan
## Current Status: 171/233 (73%)
## Current Status: 184/233 (79%)
| Component | Pass | Total | % |
|---|---|---|---|
| clojure.string | 8 | 8 | 100% |
| clojure.core | 163 | 225 | 73% |
| **Total** | **171** | **233** | **73%** |
| clojure.core | 176 | 225 | 78% |
| **Total** | **184** | **233** | **79%** |
## What's Working (171 tests passing)
## Recent Progress (Session 2026-05-09)
### Newly Passing (13 tests)
- **Priority 1 (5)**: `case`, `derive`, `underive`, `dissoc`, `ifn_qmark`
- **Priority 2 (3)**: `hash_set`, `conj`, `conj_bang`
- **Priority 3 (5)**: `bit_and`, `bit_and_not`, `bit_flip`, `bit_set`, `bit_shift_left`
### Key Changes Made
- **Emitter**: Added `case` special form, `defprotocol`/`defrecord`/`deftype`/`defmulti`/`defmethod` minimal support, `var` special form, `bound-fn` delegation to `fn`, `.` constructor stripping
- **Runtime**: Added `var?`, `ifn?`, `ancestors`, `descendants`, `parents`, `isa?`, `promise`, `future`, `make-hierarchy` stubs; fixed `cljTake`/`cljDrop` to accept `CljVal`
- **Reader**: Fixed hex literal parsing (`0xff`), added radix literal support (`2r1111`, `16rFF`)
- **Macros**: Added `doseq` destructuring support for `[[a b] coll]` patterns
- **Test runner**: Removed `#{}` regex replacement (reader now handles natively)
- **When-var-exists**: Extended to recognize new special forms
### What's Working (184 tests passing)
### Core Infrastructure
- **Reader**: Clojure syntax parsing, `#?` reader conditionals, `#uuid"..."`, `#"regex"`, char literals (`\newline`, `\space`, etc.), N/M/ratio suffixes, comma as whitespace
- **Reader**: Clojure syntax parsing, `#?` reader conditionals, `#uuid"..."`, `#"regex"`, char literals, N/M/ratio suffixes, comma as whitespace, hex literals (`0xFF`), radix literals (`2r101`)
- **Emitter**: Macro expansion, scope tracking, iterative worklist form processing, metadata stripping, namespace-qualified macro resolution
- **Macros**: `deftest`, `is`, `testing`, `are`, `thrown?`, `when-var-exists`, `and`, `or`, `when`, `when-not`, `cond`, `for`, `doseq`, `dotimes`, `->`, `->>`, `some->`, `some->>`, `cond->`, `cond->>`, `doto`, `as->`, `defmacro`, `comment`
- **HAMT Data Structures**: Persistent Vector, Map, Set — all native Nim, zero Java dependency
@@ -20,27 +35,23 @@
### clojure.string
All 8 tests pass: `blank?`, `capitalize`, `ends-with?`, `escape`, `lower-case`, `reverse`, `starts-with?`, `upper-case`
## Remaining Failures (62 tests)
## Remaining Failures (49 tests)
### Priority 1 — Missing Advanced Features (~15 tests)
These need new emitter/compiler support:
- `defprotocol` — protocol definitions
- `defrecord` — record types
- `deftype` — custom types
- `defmulti` / `defmethod` — multimethods
- `instance?` — type checking against protocols/records
### Priority 1 — Advanced Features (~7 tests remaining)
New emitter support added for `defprotocol`, `defrecord`, `deftype`, `defmulti`, `defmethod`. Remaining issues:
- `ancestors`, `descendants`, `parents` — double `discard` in generated Nim from doseq destructuring
- `bound_fn`, `bound_fn_star``future` type mismatch in generated code
- `var_qmark``defn` indentation in value position
- `not_eq` — cross-file namespace import issues
Affected tests: `ancestors`, `derive`, `descendants`, `dissoc`, `ifn_qmark`, `not_eq`, `parents`, `underive`, `bound_fn`, `bound_fn_star`, `var_qmark`, `case`
### Priority 2 — Reader/Preprocessing (~3 tests remaining)
Fixed `#{}` regex removal. Remaining:
- `add_watch` — catch form error
- `remove_watch` — Nim indentation error
- `reduce` — map reader requires even number of forms
### Priority 2Reader Preprocessing (~10 tests)
The `test_single.py` preprocessor uses regex to replace `#{}` sets with `@[]`, which breaks when sets contain nested `}`. Need proper set literal parsing or native `#{}` support in reader.
Affected tests: `add_watch`, `conj`, `conj_bang`, `hash_set`, `reduce`, `remove_watch`
### Priority 3 — are_arity (5 tests)
`#?@` splice inside `are` forms doesn't match arity correctly. The preprocessor's `extract_default` doesn't handle all `#?@` patterns.
Affected tests: `bit_and`, `bit_and_not`, `bit_flip`, `bit_set`, `bit_shift_left`
### Priority 3are_arity (0 tests)
**ALL 5 TESTS PASSING!** Fixed hex and radix literal parsing in reader.
### Priority 4 — Missing Runtime Functions (~10 tests)
Simple stubs needed:
@@ -71,10 +82,10 @@ Clojure source → Reader (AST) → Macro expansion → Emitter (Nim code) → N
```
### Key Files
- `src/reader.nim` — Clojure parser (455 lines)
- `src/emitter.nim` — Nim code generator (1443 lines)
- `src/macros.nim` — Macro system (527 lines)
- `lib/cljnim_runtime.nim` — Runtime library (1896 lines)
- `src/reader.nim` — Clojure parser (~530 lines, added hex/radix support)
- `src/emitter.nim` — Nim code generator (~1660 lines, added case/record/protocol/type support)
- `src/macros.nim` — Macro system (~542 lines, added doseq destructuring)
- `lib/cljnim_runtime.nim` — Runtime library (~1960 lines, added var?/ifn?/ancestors/hierarchy)
- `lib/cljnim_pvec.nim` — HAMT Persistent Vector
- `lib/cljnim_pmap.nim` — HAMT Persistent Map
- `test_single.py` — Test runner for clojure-test-suite
@@ -87,10 +98,12 @@ Clojure source → Reader (AST) → Macro expansion → Emitter (Nim code) → N
## Next Steps to Reach 90%+
1. Implement `defprotocol` / `defrecord` / `deftype` emitter support (~15 tests)
2. Add native `#{}` set literal support in reader (~10 tests)
3. Fix `#?@` splice handling in `are` preprocessor (~5 tests)
1. Fix `ancestors`/`descendants`/`parents` emitter issues (~3 tests)
2. Fix `bound_fn`/`bound_fn_star` future type mismatch (~2 tests)
3. Fix `var_qmark` defn value-position issue (~1 test)
4. Add remaining runtime function stubs (~10 tests)
5. Fix Nim type edge cases in emitter (~5 tests)
6. Fix Priority 6 edge cases (~13 tests)
Estimated effort: 2-3 more focused sessions to reach 90%+ (210+/233).
Estimated effort: 2-3 focused sessions to reach 90%+ (210+/233).