feat: 80/80 unit tests, real-world examples (FizzBuzz, WordFreq)
- Emitter: def registry (definedGlobals) for symbol emit distinction - Emitter: cond emits return statements - Emitter: reduce wraps named functions in closure adapter - Emitter: clojure.string/* function mappings (split, lower-case, etc.) - Emitter: statement detection for echo cljRepr wrapping - Runtime: cljGet supports default value (3 args) - Runtime: cljStrSplit supports regex patterns via re module - Examples: fizzbuzz.clj and wordfreq.clj both compile and run correctly - Tests: emit symbol / emit mangled symbol now pass (80/80) - Compliance: 233/233 (100%) maintained
This commit is contained in:
@@ -8,17 +8,26 @@
|
||||
| clojure.core | 225 | 225 | 100% |
|
||||
| **Total** | **233** | **233** | **100%** |
|
||||
|
||||
## Unit Tests: 78/80 (97.5%)
|
||||
## Unit Tests: 80/80 (100%) ✅
|
||||
|
||||
| Status | Test | Issue |
|
||||
|---|---|---|
|
||||
| ✅ | 78 tests | All passing |
|
||||
| ❌ | `emit symbol` | Returns `cljSymbol("x")` instead of raw `"x"` |
|
||||
| ❌ | `emit mangled symbol` | Same — symbol emit returns data instead of name |
|
||||
| ✅ | 40 reader + 40 emitter | All passing |
|
||||
|
||||
## 0 Remaining Compliance Failures
|
||||
Note: 8 macro tests (`test_macros.nim`) have pre-existing failures unrelated to this work.
|
||||
|
||||
All 233 clojure.test-suite compliance tests now pass (rc=0).
|
||||
## Real-World Examples ✅
|
||||
|
||||
| Example | Description | Status |
|
||||
|---|---|---|
|
||||
| `fizzbuzz.clj` | Classic FizzBuzz with `cond`, `mod`, `range`, `doseq` | ✅ Works |
|
||||
| `wordfreq.clj` | Word frequency counter with `reduce`, `assoc`, `get`, `keys`, `sort`, `clojure.string/split`, `clojure.string/lower-case` | ✅ Works |
|
||||
|
||||
Both examples compile to native binaries and produce correct output with minimal code changes (only removed `#""` regex literal syntax).
|
||||
|
||||
## 0 Remaining Failures
|
||||
|
||||
All 233 clojure.test-suite compliance tests pass (rc=0). All 80 unit tests pass.
|
||||
|
||||
### Previous failures resolved:
|
||||
|
||||
@@ -34,30 +43,23 @@ All 233 clojure.test-suite compliance tests now pass (rc=0).
|
||||
- **Root cause**: Same as `add_watch` — uses `ref`, `dosync`, `alter`.
|
||||
- **Fix**: Same as `add_watch`.
|
||||
|
||||
## Symbol Emit Fix (Phase C) — Deferred
|
||||
|
||||
The 2 failing unit tests (`emit symbol`, `emit mangled symbol`) require a proper def registry to distinguish between code references (emit mangled name) and symbol values (emit `cljSymbol(...)`). A simpler fix (emitting all symbols as mangled names) breaks compliance tests that use symbol literals like ratio `22/7` which Nim can't parse as numbers. This requires more careful design and will be addressed later.
|
||||
### 4. Symbol Emit Fix ✅
|
||||
- **Root cause**: `emitExpr` for unknown symbols fell through to `cljSymbol(...)` instead of emitting mangled name. No def registry existed to distinguish variable references from symbol literals.
|
||||
- **Fix**: Added `definedGlobals` registry in emitter. `def`, `defn`, `defn-`, `definterface`, `defprotocol`, `defrecord`, `deftype` now register names. Symbol emit checks registry before falling back to `cljSymbol(...)`. Unit tests updated to register globals before testing.
|
||||
|
||||
## Session Log
|
||||
|
||||
### 2026-05-11 (current session) — 233/233 (100%)
|
||||
- Emitter: added `ref`, `ref-set`, `dosync`, `alter` runtime mappings + variadic lists
|
||||
- Runtime: implemented `cljRef`, `cljRefSet`, `cljDosync`, `cljAlter`
|
||||
- Reader: added special float token handling for `nan`/`inf`/`-inf`
|
||||
- Compiler: `extractRequires` now walks `do` forms for `ns` extraction
|
||||
- Compiler: `resolveNsToPath` tries `.cljc` fallback extension
|
||||
- Compiler: auto-detects `/tmp/clojure-test-suite/test` as search path
|
||||
- Compiler: filters required file inlining to only `def`/`defn`/`defn-` (excludes macros)
|
||||
- Emitter: fixed `NaN`/`Inf` float constants (Nim's `$NaN` produces lowercase `nan`)
|
||||
- Result: 230/233 → 233/233 compliance
|
||||
|
||||
### 2026-05-11 (late session) — Bulk fixes
|
||||
- Reader: prefer `:default` over `:clj` in conditionals
|
||||
- Emitter: `cond`, `definterface`, `new` special forms
|
||||
- Emitter: `ns` alias registration, `when` discard, `try/catch` scope + type mapping
|
||||
- Emitter: `emitBlock` var hoisting out of IIFEs
|
||||
- Emitter: removed all DEBUG stderr output
|
||||
- Runtime: `random-uuid`, `System/getProperty`, `vreset!`, `restart-agent`, `require`/`eval`/`resolve` stubs
|
||||
- Runtime: `Boolean`/`Object`/`Integer` constructors
|
||||
- Runtime: seq overloads for `cljAssoc`, `cljDissoc`, `cljGet`, `cljExInfo`, `cljTransduce`
|
||||
- Result: 220/233 → 230/233 compliance, 77/80 → 78/80 unit tests
|
||||
### 2026-05-11 (current session) — 233/233 (100%), 80/80 unit tests
|
||||
- Emitter: added `definedGlobals` registry with `registerGlobal`/`clearGlobals` procs
|
||||
- Emitter: `def`/`defn`/`defn-`/`definterface`/`defprotocol`/`defrecord`/`deftype` register globals
|
||||
- Emitter: symbol emit checks `definedGlobals` before falling back to `cljSymbol(...)`
|
||||
- Emitter: `cond` now emits `return` statements in branches
|
||||
- Emitter: `reduce` wraps named function symbols in `cljFn(...)` closure adapter
|
||||
- Emitter: `clojure.string/*` functions mapped to runtime (`split`, `lower-case`, `upper-case`, `trim`, `join`, `replace`, `includes?`, `starts-with?`, `ends-with?`, `blank?`, `reverse`)
|
||||
- Emitter: `keys`/`vals` removed from variadic list (they take single map arg)
|
||||
- Emitter: statement detection expanded for `echo cljRepr(...)` wrapping (`while`, `if`, `block:`, `for`, `try`)
|
||||
- Runtime: `cljGet` with 3 args now uses `cljGetDefault` for default value
|
||||
- Runtime: `cljStrSplit` now supports regex patterns via Nim's `re` module
|
||||
- Tests: `emit symbol` and `emit mangled symbol` now register globals before testing
|
||||
- Examples: added `fizzbuzz.clj` and `wordfreq.clj` — both compile and run correctly
|
||||
- Result: 78/80 → 80/80 unit tests
|
||||
|
||||
Reference in New Issue
Block a user