Fix: isolate temp/cache build dirs to avoid shadowing Nim stdlib modules. All 7 examples pass.
This commit is contained in:
+1
-3
@@ -79,10 +79,8 @@
|
|||||||
|
|
||||||
## Known Issues
|
## Known Issues
|
||||||
- `->>` threading macro with nested `map`/`reduce` requires proper macro expansion context
|
- `->>` threading macro with nested `map`/`reduce` requires proper macro expansion context
|
||||||
- REPL definitions are re-compiled from scratch on each evaluation (slow but correct — interpreter path handles most cases in <0.1ms now)
|
|
||||||
- ffi/interop examples fail — `sin` symbol not found (Nim module import issue, pre-existing)
|
|
||||||
|
|
||||||
## Recent Bug Fixes (2026-05-08)
|
## Recent Bug Fixes (2026-05-08)
|
||||||
|
- Fixed: ffi/interop examples — temp files now use isolated subdirectories to avoid shadowing Nim stdlib modules (e.g., `math.nim` shadowing `import math`)
|
||||||
- Fixed: `quot`/`rem` — added `cljQuot`/`cljRem` to runtime + interpreter support
|
- Fixed: `quot`/`rem` — added `cljQuot`/`cljRem` to runtime + interpreter support
|
||||||
- Fixed: `rem` — interpreter and compiled path both now handle `(rem n d)`
|
|
||||||
- Cleanup: removed unused `processAgentActions` proc, unused `sequtils` import in repl.nim
|
- Cleanup: removed unused `processAgentActions` proc, unused `sequtils` import in repl.nim
|
||||||
|
|||||||
+21
-9
@@ -111,11 +111,17 @@ proc nimCompile(nimPath: string, binPath: string, release: bool = false): int =
|
|||||||
echo "Compiling: ", cmd
|
echo "Compiling: ", cmd
|
||||||
execCmd(cmd)
|
execCmd(cmd)
|
||||||
|
|
||||||
|
proc makeTempDir(): string =
|
||||||
|
let pid = getCurrentProcessId()
|
||||||
|
let ts = epochTime().int
|
||||||
|
result = getTempDir() / "cljnim_build_" & $pid & "_" & $ts
|
||||||
|
createDir(result)
|
||||||
|
|
||||||
proc runFile*(inputPath: string) =
|
proc runFile*(inputPath: string) =
|
||||||
let tmpDir = getTempDir()
|
|
||||||
let baseName = inputPath.splitFile.name
|
let baseName = inputPath.splitFile.name
|
||||||
let nimPath = tmpDir / baseName & "_generated.nim"
|
let buildDir = makeTempDir()
|
||||||
let binPath = tmpDir / baseName & "_generated"
|
let nimPath = buildDir / baseName & ".nim"
|
||||||
|
let binPath = buildDir / baseName
|
||||||
|
|
||||||
# Resolve project dependencies
|
# Resolve project dependencies
|
||||||
let inputDir = inputPath.parentDir
|
let inputDir = inputPath.parentDir
|
||||||
@@ -124,8 +130,9 @@ proc runFile*(inputPath: string) =
|
|||||||
# Check nimcache for cached output
|
# Check nimcache for cached output
|
||||||
let projectDir = inputPath.parentDir
|
let projectDir = inputPath.parentDir
|
||||||
let cacheDir = projectDir / "nimcache"
|
let cacheDir = projectDir / "nimcache"
|
||||||
let cacheNimPath = cacheDir / baseName & ".nim"
|
let cacheSubDir = cacheDir / baseName
|
||||||
let cacheBinPath = cacheDir / baseName
|
let cacheNimPath = cacheSubDir / baseName & ".nim"
|
||||||
|
let cacheBinPath = cacheSubDir / baseName
|
||||||
|
|
||||||
var useCache = false
|
var useCache = false
|
||||||
if fileExists(cacheNimPath) and fileExists(cacheBinPath):
|
if fileExists(cacheNimPath) and fileExists(cacheBinPath):
|
||||||
@@ -140,6 +147,7 @@ proc runFile*(inputPath: string) =
|
|||||||
if compileResult != 0:
|
if compileResult != 0:
|
||||||
stderr.writeLine("Compilation failed (cached)")
|
stderr.writeLine("Compilation failed (cached)")
|
||||||
quit(1)
|
quit(1)
|
||||||
|
try: removeDir(buildDir) except: discard
|
||||||
let runResult = execCmd(cacheBinPath)
|
let runResult = execCmd(cacheBinPath)
|
||||||
quit(runResult)
|
quit(runResult)
|
||||||
|
|
||||||
@@ -148,11 +156,12 @@ proc runFile*(inputPath: string) =
|
|||||||
let compileResult = nimCompile(nimPath, binPath)
|
let compileResult = nimCompile(nimPath, binPath)
|
||||||
if compileResult != 0:
|
if compileResult != 0:
|
||||||
stderr.writeLine("Compilation failed")
|
stderr.writeLine("Compilation failed")
|
||||||
|
try: removeDir(buildDir) except: discard
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
# Save to cache
|
# Save to cache
|
||||||
try:
|
try:
|
||||||
createDir(cacheDir)
|
createDir(cacheSubDir)
|
||||||
copyFile(nimPath, cacheNimPath)
|
copyFile(nimPath, cacheNimPath)
|
||||||
copyFile(binPath, cacheBinPath)
|
copyFile(binPath, cacheBinPath)
|
||||||
echo "Cached: ", cacheNimPath
|
echo "Cached: ", cacheNimPath
|
||||||
@@ -160,6 +169,7 @@ proc runFile*(inputPath: string) =
|
|||||||
discard
|
discard
|
||||||
|
|
||||||
let runResult = execCmd(binPath)
|
let runResult = execCmd(binPath)
|
||||||
|
try: removeDir(buildDir) except: discard
|
||||||
if runResult != 0:
|
if runResult != 0:
|
||||||
stderr.writeLine("Execution failed")
|
stderr.writeLine("Execution failed")
|
||||||
quit(1)
|
quit(1)
|
||||||
@@ -199,17 +209,19 @@ proc main() =
|
|||||||
stderr.writeLine("Error: Missing expression after -e")
|
stderr.writeLine("Error: Missing expression after -e")
|
||||||
quit(1)
|
quit(1)
|
||||||
let code = args[1]
|
let code = args[1]
|
||||||
let tmpDir = getTempDir()
|
let buildDir = makeTempDir()
|
||||||
let nimPath = tmpDir / "cljnim_expr.nim"
|
let nimPath = buildDir / "expr.nim"
|
||||||
let binPath = tmpDir / "cljnim_expr"
|
let binPath = buildDir / "expr"
|
||||||
let forms = reader.readAll(code)
|
let forms = reader.readAll(code)
|
||||||
let nimCode = emitter.emitProgram(forms)
|
let nimCode = emitter.emitProgram(forms)
|
||||||
writeFile(nimPath, nimCode)
|
writeFile(nimPath, nimCode)
|
||||||
let compileResult = nimCompile(nimPath, binPath)
|
let compileResult = nimCompile(nimPath, binPath)
|
||||||
if compileResult != 0:
|
if compileResult != 0:
|
||||||
stderr.writeLine("Compilation failed")
|
stderr.writeLine("Compilation failed")
|
||||||
|
try: removeDir(buildDir) except: discard
|
||||||
quit(1)
|
quit(1)
|
||||||
let runResult = execCmd(binPath)
|
let runResult = execCmd(binPath)
|
||||||
|
try: removeDir(buildDir) except: discard
|
||||||
quit(runResult)
|
quit(runResult)
|
||||||
|
|
||||||
case cmd
|
case cmd
|
||||||
|
|||||||
Reference in New Issue
Block a user