diff --git a/docs/ROADMAP.bg.md b/docs/ROADMAP.bg.md index 2aa48a4..5a35e40 100644 --- a/docs/ROADMAP.bg.md +++ b/docs/ROADMAP.bg.md @@ -2,50 +2,79 @@ ## Фаза 0: Компилаторно Ядро ✅ - [x] Clojure Reader (EDN парсер) +- [x] Reader поддържа: списъци `()`, вектори `[]`, карти `{}`, низове, ключови думи, символи, числа, булеви, nil +- [x] Reader поддържа: quote `'`, syntax-quote `` ` ``, unquote `~`, unquote-splicing `~@` +- [x] Reader поддържа: коментари `;`, read-all - [x] AST → Nim Генератор -- [x] CLI (`compile`, `run`, `read`) +- [x] CLI (`compile`, `run`, `read`, `repl`) - [x] Специални форми: `def`, `defn`, `fn`, `let`, `if`, `do`, `quote` -- [x] Аритметични оператори -- [x] Човешки и JSON REPL -- [x] AOT компилация до native бинарни файлове +- [x] Специални форми: `when`, `cond` +- [x] Аритметични оператори: `+`, `-`, `*`, `/` +- [x] Оператори за сравнение: `=`, `not=`, `not`, `<`, `>`, `<=`, `>=` +- [x] Core функции: `println`, `map`, `filter`, `reduce` +- [x] Runtime типова система: `CljVal` с `nil`, `bool`, `int`, `float`, `string`, `keyword`, `symbol`, `list`, `vector`, `map`, `fn`, `atom` -## Фаза 1: AI-Native Инструменти 🔄 -- [x] JSON REPL режим -- [x] Batch оценка -- [x] Структурирани грешки -- [ ] Файлови операции (`file/read`, `file/write`) -- [ ] Git операции (`git/commit`, `git/push`) +## Фаза 1: Макро Система ✅ +- [x] `macroexpand`, `macroexpand-1` +- [x] `syntax-quote`, `unquote`, `unquote-splicing` +- [x] `gensym` +- [x] `defmacro` (потребителски макроси) +- [x] Вградени макроси: `->`, `->>`, `and`, `or`, `when`, `when-not`, `cond` +- [x] Вградени макроси: `cond->`, `cond->>`, `doto`, `as->`, `some->`, `some->>` +- [x] Вградени макроси: `for`, `doseq`, `dotimes` +- [x] Вградени макроси: `when-let`, `if-let` +- [x] Вградени макроси: `comment`, `assert`, `with-open` + +## Фаза 2: REPL и Инструменти ✅ +- [x] Човешки REPL (`:help`, `:defs`, `:clear`, `:ns`, `:quit`) +- [x] JSON REPL (`--json`) със структуриран I/O +- [x] Batch оценка (`eval-batch`) +- [x] Структурирани грешки (тип, съобщение, форма, ред) +- [x] Персистентност на сесията за `def`/`defn` + +## Фаза 3: Nim Interop ✅ +- [x] Извикване на Nim функции: `(nim/math/sin x)`, `(nim/strutils/toUpper s)` +- [x] C FFI през Nim `importc` + +## Фаза 4: AI-Native Инструменти 🔄 +- [ ] Файлови операции от REPL: `(file/read "path")`, `(file/write "path" "content")` +- [ ] Git операции от REPL: `(git/status)`, `(git/commit "msg")`, `(git/push)` - [ ] nREPL протокол съвместимост +- [ ] Tool-call формат за интеграция с AI frameworks -## Фаза 2: Persistent Структури от Данни -- [ ] Persistent Vector (HAMT) +## Фаза 5: Persistent Структури от Данни +- [ ] Persistent Vector (Hash Array Mapped Trie) - [ ] Persistent Map (HAMT) - [ ] Persistent Set - [ ] `conj`, `assoc`, `dissoc`, `get`, `get-in` -- [ ] `nth`, `first`, `rest`, `last`, `count` +- [ ] `nth`, `first`, `rest`, `last`, `count` върху persistent колекции +- [ ] Transients за batch мутации -## Фаза 3: Clojure Core Библиотека -- [ ] Seq функции: `map`, `filter`, `reduce`, `range` -- [ ] Низови функции: `str`, `pr-str`, `slurp`, `spit` -- [ ] Мета: `meta`, `with-meta`, `type` +## Фаза 6: Clojure Core Библиотека +- [ ] `range`, `repeat`, `cycle`, `iterate` +- [ ] `take`, `drop`, `partition`, `interleave`, `concat` +- [ ] `str`, `pr-str`, `println`, `prn` +- [ ] `slurp`, `spit`, `read-line` +- [ ] `meta`, `with-meta`, `vary-meta` +- [ ] `type`, `instance?`, `satisfies?` -## Фаза 4: Макро Система -- [ ] `defmacro` -- [ ] `syntax-quote`, `unquote`, `unquote-splicing` -- [ ] `gensym` -- [ ] Core макроси: `->`, `->>`, `and`, `or`, `when`, `cond` +## Фаза 7: Компилация на Проекти +- [ ] Компилиране на цели проекти (не само отделни файлове) +- [ ] Система за namespaces (`ns`, `require`, `use`) +- [ ] Кеширане на модули за по-бърз REPL старт +- [ ] Резолюция на зависимости -## Фаза 5: Nim Interop -- [ ] `nim/import` — Импорт на Nim модули -- [ ] `nim/call` — Извикване на Nim функции -- [ ] C FFI декларации +## Фаза 8: Self-Hosted REPL +- [ ] Компилиране на форми в паметта (без temp файлове) +- [ ] Бърз REPL старт (< 100ms) +- [ ] Hot code reloading -## Фаза 6: Оптимизация -- [ ] AOT компилация на цели проекти -- [ ] Кеширане на компилирани модули -- [ ] Self-hosted REPL (компилация в паметта) - -## Фаза 7: Конкурентност -- [ ] Atoms (CAS) +## Фаза 9: Конкурентност +- [ ] Atoms (compare-and-swap) - [ ] Agents - [ ] core.async channels (упростен вариант) + +## Известни Проблеми +- `->>` threading macro с вложени `map`/`reduce` изисква правилен macro expansion контекст +- REPL дефинициите се прекомпилират от нулата при всяка оценка (бавно, но коректно) +- Няма истински persistent структури от данни (runtime използва Nim seq/tables) diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 9628e9c..51e5cf5 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -2,49 +2,79 @@ ## Phase 0: Compiler Core ✅ - [x] Clojure Reader (EDN parser) +- [x] Reader supports: lists `()`, vectors `[]`, maps `{}`, strings, keywords, symbols, numbers, booleans, nil +- [x] Reader supports: quote `'`, syntax-quote `` ` ``, unquote `~`, unquote-splicing `~@` +- [x] Reader supports: comments `;`, read-all - [x] AST → Nim Emitter -- [x] CLI (`compile`, `run`, `read`) +- [x] CLI (`compile`, `run`, `read`, `repl`) - [x] Special forms: `def`, `defn`, `fn`, `let`, `if`, `do`, `quote` -- [x] Arithmetic operators -- [x] Human and JSON REPL +- [x] Special forms: `when`, `cond` +- [x] Arithmetic operators: `+`, `-`, `*`, `/` +- [x] Comparison operators: `=`, `not=`, `not`, `<`, `>`, `<=`, `>=` +- [x] Core functions: `println`, `map`, `filter`, `reduce` +- [x] Runtime type system: `CljVal` with `nil`, `bool`, `int`, `float`, `string`, `keyword`, `symbol`, `list`, `vector`, `map`, `fn`, `atom` -## Phase 1: AI-Native Tooling 🔄 -- [x] JSON REPL mode -- [x] Batch evaluation -- [x] Structured errors -- [ ] File operations (`file/read`, `file/write`) -- [ ] Git operations (`git/commit`, `git/push`) +## Phase 1: Macro System ✅ +- [x] `macroexpand`, `macroexpand-1` +- [x] `syntax-quote`, `unquote`, `unquote-splicing` +- [x] `gensym` +- [x] `defmacro` (user-defined macros) +- [x] Built-in macros: `->`, `->>`, `and`, `or`, `when`, `when-not`, `cond` +- [x] Built-in macros: `cond->`, `cond->>`, `doto`, `as->`, `some->`, `some->>` +- [x] Built-in macros: `for`, `doseq`, `dotimes` +- [x] Built-in macros: `when-let`, `if-let` +- [x] Built-in macros: `comment`, `assert`, `with-open` + +## Phase 2: REPL & Tooling ✅ +- [x] Human REPL (`:help`, `:defs`, `:clear`, `:ns`, `:quit`) +- [x] JSON REPL (`--json`) with structured I/O +- [x] Batch evaluation (`eval-batch`) +- [x] Structured errors (type, message, form, line) +- [x] Session persistence for `def`/`defn` definitions + +## Phase 3: Nim Interop ✅ +- [x] Call Nim functions: `(nim/math/sin x)`, `(nim/strutils/toUpper s)` +- [x] C FFI via Nim `importc` + +## Phase 4: AI-Native Tooling 🔄 +- [ ] File operations from REPL: `(file/read "path")`, `(file/write "path" "content")` +- [ ] Git operations from REPL: `(git/status)`, `(git/commit "msg")`, `(git/push)` - [ ] nREPL protocol compatibility +- [ ] Tool-call format for AI framework integration -## Phase 2: Persistent Data Structures -- [ ] Persistent Vector (HAMT) +## Phase 5: Persistent Data Structures +- [ ] Persistent Vector (Hash Array Mapped Trie) - [ ] Persistent Map (HAMT) - [ ] Persistent Set - [ ] `conj`, `assoc`, `dissoc`, `get`, `get-in` -- [ ] `nth`, `first`, `rest`, `last`, `count` +- [ ] `nth`, `first`, `rest`, `last`, `count` on persistent collections +- [ ] Transients for batch mutations -## Phase 3: Clojure Core Library -- [ ] Seq functions: `map`, `filter`, `reduce`, `range` -- [ ] String functions: `str`, `pr-str`, `slurp`, `spit` -- [ ] Meta: `meta`, `with-meta`, `type` +## Phase 6: Clojure Core Library +- [ ] `range`, `repeat`, `cycle`, `iterate` +- [ ] `take`, `drop`, `partition`, `interleave`, `concat` +- [ ] `str`, `pr-str`, `println`, `prn` +- [ ] `slurp`, `spit`, `read-line` +- [ ] `meta`, `with-meta`, `vary-meta` +- [ ] `type`, `instance?`, `satisfies?` -## Phase 4: Macro System -- [ ] `defmacro` -- [ ] `syntax-quote`, `unquote`, `unquote-splicing` -- [ ] `gensym` -- [ ] Core macros: `->`, `->>`, `and`, `or`, `when`, `cond` +## Phase 7: Project Compilation +- [ ] Compile entire projects (not just single files) +- [ ] Namespace system (`ns`, `require`, `use`) +- [ ] Module caching for faster REPL startup +- [ ] Dependency resolution -## Phase 5: Nim Interop -- [ ] `nim/import` — Import Nim modules -- [ ] `nim/call` — Call Nim functions -- [ ] C FFI declarations +## Phase 8: Self-Hosted REPL +- [ ] Compile forms in memory (no temp files) +- [ ] Fast REPL startup (< 100ms) +- [ ] Hot code reloading -## Phase 6: Optimization -- [ ] AOT project compilation -- [ ] Module caching -- [ ] Self-hosted REPL (compile in memory) - -## Phase 7: Concurrency -- [ ] Atoms (CAS) +## Phase 9: Concurrency +- [ ] Atoms (compare-and-swap) - [ ] Agents - [ ] core.async channels (simplified) + +## Known Issues +- `->>` threading macro with nested `map`/`reduce` requires proper macro expansion context +- REPL definitions are re-compiled from scratch on each evaluation (slow but correct) +- No true persistent data structures yet (runtime uses Nim seq/tables) diff --git a/src/cljnim.nim b/src/cljnim.nim index 6b97552..ba57df3 100644 --- a/src/cljnim.nim +++ b/src/cljnim.nim @@ -1,6 +1,6 @@ # Clojure/Nim — AI-First Clojure Compiler import os, osproc, strutils -import reader, emitter, types, repl +import reader, emitter, types, repl, macros proc getLibPath(): string = let appDir = getAppDir() @@ -53,6 +53,7 @@ proc runFile*(inputPath: string) = quit(1) proc main() = + initBuiltinMacros() let args = commandLineParams() if args.len == 0: diff --git a/src/repl.nim b/src/repl.nim index 68c497b..d8d4320 100644 --- a/src/repl.nim +++ b/src/repl.nim @@ -1,6 +1,6 @@ # AI-First REPL for Clojure/Nim import os, osproc, strutils, json, times -import reader, emitter, types +import reader, emitter, types, macros type ReplMode* = enum @@ -25,6 +25,7 @@ proc getLibPath(): string = return "lib" proc initReplState*(mode: ReplMode): ReplState = + initBuiltinMacros() result.mode = mode result.ns = "user" result.defs = @[]