feat: +11 more tests (194/233, 83%) — array stubs, cons/atom/cycle variadic, string escaping, empty/case

This commit is contained in:
2026-05-09 20:14:31 +03:00
parent 6633c3708d
commit 88a04f8b67
2 changed files with 92 additions and 11 deletions
+15 -7
View File
@@ -265,6 +265,12 @@ proc runtimeName(op: string): string =
of "promise": "cljPromise"
of "future": "cljFuture"
of "create-ns": "cljCreateNs"
of "aclone": "cljAclone"
of "alength": "cljAlength"
of "aget": "cljAget"
of "int-array": "cljIntArray"
of "identical?": "cljIdentical"
of "empty": "cljEmptyColl"
of "doall": "cljDoall"
of "dorun": "cljDorun"
of "drop-last": "cljDropLast"
@@ -585,7 +591,7 @@ proc emitSpecialForm(items: seq[CljVal], indent: int): string =
raise newException(EmitterError, "fn params must be symbols")
addToScope(p.symName)
paramNames.add(mangleName(p.symName) & ": CljVal")
let body = items[2..^1]
let body = items[(paramsIdx+1)..^1]
var bodyCode = ""
if body.len == 1:
bodyCode = emitExpr(body[0], indent + 1)
@@ -862,7 +868,7 @@ proc emitSpecialForm(items: seq[CljVal], indent: int): string =
let isSpecial = symName in ["case", "defprotocol", "defrecord", "deftype", "defmulti", "defmethod",
"var", "bound-fn", "bound-fn*", "promise", "delay", "future",
"sorted-map-by", "sorted-set-by", "compare-and-set!",
"empty", "delay"]
"empty", "aclone", "int-array", "identical?"]
let exists = runtimeName(symName).len > 0 or isLocalVar(symName) or isSpecial
if exists:
let body = items[2..^1]
@@ -1397,13 +1403,14 @@ proc emitSpecialForm(items: seq[CljVal], indent: int): string =
# Variadic functions take seq[CljVal]
let variadic = op in ["+", "-", "*", "/", "=", ">", "<", ">=", "<=", "not=",
"println", "prn", "print", "str", "pr-str",
"concat", "min", "max", "merge", "interleave",
"zipmap", "hash-map", "hash-set", "sorted-map", "sorted-set",
"atom", "concat", "min", "max", "merge", "interleave",
"zipmap", "hash-map", "hash-set", "sorted-map", "sorted-set", "cons",
"array-map", "inf", "nan",
"float", "int", "double", "long", "short", "byte",
"boolean", "num", "number",
"make-hierarchy", "derive", "underive", "ancestors",
"descendants", "parents", "isa?", "promise", "create-ns", "future",
"aclone", "alength", "aget", "int-array", "identical?", "empty",
"drop-last", "shuffle", "repeatedly", "fnil", "intern",
"println-str", "prn-str", "binding", "aset",
"volatile!", "deliver", "doall", "dorun",
@@ -1469,7 +1476,8 @@ proc emitExpr*(v: CljVal, indent: int = 0): string =
of ckFloat:
return sp & "cljFloat(" & $v.floatVal & ")"
of ckString:
return sp & "cljString(\"" & v.strVal.replace("\"", "\\\"") & "\")"
let escaped = v.strVal.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t")
return sp & "cljString(\"" & escaped & "\")"
of ckKeyword:
return sp & "cljKeyword(\"" & v.kwName & "\")"
of ckSymbol:
@@ -1479,8 +1487,8 @@ proc emitExpr*(v: CljVal, indent: int = 0): string =
# Check if the runtime function is variadic (takes seq[CljVal])
let variadic = symName in ["+", "-", "*", "/", "=", ">", "<", ">=", "<=", "not=",
"println", "prn", "print", "str", "pr-str",
"concat", "min", "max", "merge", "interleave",
"zipmap", "hash-map", "hash-set", "sorted-map", "sorted-set",
"atom", "concat", "min", "max", "merge", "interleave",
"zipmap", "hash-map", "hash-set", "sorted-map", "sorted-set", "cons",
"array-map", "inf", "nan",
"float", "int", "double", "long", "short", "byte",
"boolean", "num", "number",