Fix macro expansion in REPL; update roadmap to reflect actual capabilities

This commit is contained in:
2026-05-08 17:05:53 +03:00
parent f189dbd14a
commit 301231787c
4 changed files with 128 additions and 67 deletions
+62 -33
View File
@@ -2,50 +2,79 @@
## Фаза 0: Компилаторно Ядро ✅ ## Фаза 0: Компилаторно Ядро ✅
- [x] Clojure Reader (EDN парсер) - [x] Clojure Reader (EDN парсер)
- [x] Reader поддържа: списъци `()`, вектори `[]`, карти `{}`, низове, ключови думи, символи, числа, булеви, nil
- [x] Reader поддържа: quote `'`, syntax-quote `` ` ``, unquote `~`, unquote-splicing `~@`
- [x] Reader поддържа: коментари `;`, read-all
- [x] AST → Nim Генератор - [x] AST → Nim Генератор
- [x] CLI (`compile`, `run`, `read`) - [x] CLI (`compile`, `run`, `read`, `repl`)
- [x] Специални форми: `def`, `defn`, `fn`, `let`, `if`, `do`, `quote` - [x] Специални форми: `def`, `defn`, `fn`, `let`, `if`, `do`, `quote`
- [x] Аритметични оператори - [x] Специални форми: `when`, `cond`
- [x] Човешки и JSON REPL - [x] Аритметични оператори: `+`, `-`, `*`, `/`
- [x] AOT компилация до native бинарни файлове - [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 Инструменти 🔄 ## Фаза 1: Макро Система ✅
- [x] JSON REPL режим - [x] `macroexpand`, `macroexpand-1`
- [x] Batch оценка - [x] `syntax-quote`, `unquote`, `unquote-splicing`
- [x] Структурирани грешки - [x] `gensym`
- [ ] Файлови операции (`file/read`, `file/write`) - [x] `defmacro` (потребителски макроси)
- [ ] Git операции (`git/commit`, `git/push`) - [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 протокол съвместимост - [ ] nREPL протокол съвместимост
- [ ] Tool-call формат за интеграция с AI frameworks
## Фаза 2: Persistent Структури от Данни ## Фаза 5: Persistent Структури от Данни
- [ ] Persistent Vector (HAMT) - [ ] Persistent Vector (Hash Array Mapped Trie)
- [ ] Persistent Map (HAMT) - [ ] Persistent Map (HAMT)
- [ ] Persistent Set - [ ] Persistent Set
- [ ] `conj`, `assoc`, `dissoc`, `get`, `get-in` - [ ] `conj`, `assoc`, `dissoc`, `get`, `get-in`
- [ ] `nth`, `first`, `rest`, `last`, `count` - [ ] `nth`, `first`, `rest`, `last`, `count` върху persistent колекции
- [ ] Transients за batch мутации
## Фаза 3: Clojure Core Библиотека ## Фаза 6: Clojure Core Библиотека
- [ ] Seq функции: `map`, `filter`, `reduce`, `range` - [ ] `range`, `repeat`, `cycle`, `iterate`
- [ ] Низови функции: `str`, `pr-str`, `slurp`, `spit` - [ ] `take`, `drop`, `partition`, `interleave`, `concat`
- [ ] Мета: `meta`, `with-meta`, `type` - [ ] `str`, `pr-str`, `println`, `prn`
- [ ] `slurp`, `spit`, `read-line`
- [ ] `meta`, `with-meta`, `vary-meta`
- [ ] `type`, `instance?`, `satisfies?`
## Фаза 4: Макро Система ## Фаза 7: Компилация на Проекти
- [ ] `defmacro` - [ ] Компилиране на цели проекти (не само отделни файлове)
- [ ] `syntax-quote`, `unquote`, `unquote-splicing` - [ ] Система за namespaces (`ns`, `require`, `use`)
- [ ] `gensym` - [ ] Кеширане на модули за по-бърз REPL старт
- [ ] Core макроси: `->`, `->>`, `and`, `or`, `when`, `cond` - [ ] Резолюция на зависимости
## Фаза 5: Nim Interop ## Фаза 8: Self-Hosted REPL
- [ ] `nim/import` — Импорт на Nim модули - [ ] Компилиране на форми в паметта (без temp файлове)
- [ ] `nim/call` — Извикване на Nim функции - [ ] Бърз REPL старт (< 100ms)
- [ ] C FFI декларации - [ ] Hot code reloading
## Фаза 6: Оптимизация ## Фаза 9: Конкурентност
- [ ] AOT компилация на цели проекти - [ ] Atoms (compare-and-swap)
- [ ] Кеширане на компилирани модули
- [ ] Self-hosted REPL (компилация в паметта)
## Фаза 7: Конкурентност
- [ ] Atoms (CAS)
- [ ] Agents - [ ] Agents
- [ ] core.async channels (упростен вариант) - [ ] core.async channels (упростен вариант)
## Известни Проблеми
- `->>` threading macro с вложени `map`/`reduce` изисква правилен macro expansion контекст
- REPL дефинициите се прекомпилират от нулата при всяка оценка (бавно, но коректно)
- Няма истински persistent структури от данни (runtime използва Nim seq/tables)
+62 -32
View File
@@ -2,49 +2,79 @@
## Phase 0: Compiler Core ✅ ## Phase 0: Compiler Core ✅
- [x] Clojure Reader (EDN parser) - [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] 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] Special forms: `def`, `defn`, `fn`, `let`, `if`, `do`, `quote`
- [x] Arithmetic operators - [x] Special forms: `when`, `cond`
- [x] Human and JSON REPL - [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 🔄 ## Phase 1: Macro System ✅
- [x] JSON REPL mode - [x] `macroexpand`, `macroexpand-1`
- [x] Batch evaluation - [x] `syntax-quote`, `unquote`, `unquote-splicing`
- [x] Structured errors - [x] `gensym`
- [ ] File operations (`file/read`, `file/write`) - [x] `defmacro` (user-defined macros)
- [ ] Git operations (`git/commit`, `git/push`) - [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 - [ ] nREPL protocol compatibility
- [ ] Tool-call format for AI framework integration
## Phase 2: Persistent Data Structures ## Phase 5: Persistent Data Structures
- [ ] Persistent Vector (HAMT) - [ ] Persistent Vector (Hash Array Mapped Trie)
- [ ] Persistent Map (HAMT) - [ ] Persistent Map (HAMT)
- [ ] Persistent Set - [ ] Persistent Set
- [ ] `conj`, `assoc`, `dissoc`, `get`, `get-in` - [ ] `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 ## Phase 6: Clojure Core Library
- [ ] Seq functions: `map`, `filter`, `reduce`, `range` - [ ] `range`, `repeat`, `cycle`, `iterate`
- [ ] String functions: `str`, `pr-str`, `slurp`, `spit` - [ ] `take`, `drop`, `partition`, `interleave`, `concat`
- [ ] Meta: `meta`, `with-meta`, `type` - [ ] `str`, `pr-str`, `println`, `prn`
- [ ] `slurp`, `spit`, `read-line`
- [ ] `meta`, `with-meta`, `vary-meta`
- [ ] `type`, `instance?`, `satisfies?`
## Phase 4: Macro System ## Phase 7: Project Compilation
- [ ] `defmacro` - [ ] Compile entire projects (not just single files)
- [ ] `syntax-quote`, `unquote`, `unquote-splicing` - [ ] Namespace system (`ns`, `require`, `use`)
- [ ] `gensym` - [ ] Module caching for faster REPL startup
- [ ] Core macros: `->`, `->>`, `and`, `or`, `when`, `cond` - [ ] Dependency resolution
## Phase 5: Nim Interop ## Phase 8: Self-Hosted REPL
- [ ] `nim/import` — Import Nim modules - [ ] Compile forms in memory (no temp files)
- [ ] `nim/call` — Call Nim functions - [ ] Fast REPL startup (< 100ms)
- [ ] C FFI declarations - [ ] Hot code reloading
## Phase 6: Optimization ## Phase 9: Concurrency
- [ ] AOT project compilation - [ ] Atoms (compare-and-swap)
- [ ] Module caching
- [ ] Self-hosted REPL (compile in memory)
## Phase 7: Concurrency
- [ ] Atoms (CAS)
- [ ] Agents - [ ] Agents
- [ ] core.async channels (simplified) - [ ] 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)
+2 -1
View File
@@ -1,6 +1,6 @@
# Clojure/Nim — AI-First Clojure Compiler # Clojure/Nim — AI-First Clojure Compiler
import os, osproc, strutils import os, osproc, strutils
import reader, emitter, types, repl import reader, emitter, types, repl, macros
proc getLibPath(): string = proc getLibPath(): string =
let appDir = getAppDir() let appDir = getAppDir()
@@ -53,6 +53,7 @@ proc runFile*(inputPath: string) =
quit(1) quit(1)
proc main() = proc main() =
initBuiltinMacros()
let args = commandLineParams() let args = commandLineParams()
if args.len == 0: if args.len == 0:
+2 -1
View File
@@ -1,6 +1,6 @@
# AI-First REPL for Clojure/Nim # AI-First REPL for Clojure/Nim
import os, osproc, strutils, json, times import os, osproc, strutils, json, times
import reader, emitter, types import reader, emitter, types, macros
type type
ReplMode* = enum ReplMode* = enum
@@ -25,6 +25,7 @@ proc getLibPath(): string =
return "lib" return "lib"
proc initReplState*(mode: ReplMode): ReplState = proc initReplState*(mode: ReplMode): ReplState =
initBuiltinMacros()
result.mode = mode result.mode = mode
result.ns = "user" result.ns = "user"
result.defs = @[] result.defs = @[]