fix: +3 tests (197/233, 85%) — bigint overflow, var_qmark indent, merge double discard
This commit is contained in:
+3
-2
@@ -621,7 +621,7 @@ proc emitSpecialForm(items: seq[CljVal], indent: int): string =
|
||||
if bname.kind != ckSymbol:
|
||||
raise newException(EmitterError, "let binding name must be a symbol")
|
||||
addToScope(bname.symName)
|
||||
lines.add(indentStr(indent + 1) & "let " & mangleName(bname.symName) & " = " & emitExpr(bval, 0))
|
||||
lines.add(indentStr(indent + 1) & "let " & mangleName(bname.symName) & " = " & emitExpr(bval, indent + 1))
|
||||
bi += 2
|
||||
let body = items[2..^1]
|
||||
for j, b in body:
|
||||
@@ -1557,7 +1557,8 @@ proc emitBlock(items: seq[CljVal], indent: int, useResult: bool = false): string
|
||||
let lastLine = if lastNl == -1: trimmed else: trimmed[lastNl+1..^1].strip()
|
||||
# Prepend discard before the first non-empty line
|
||||
if firstNl == -1:
|
||||
if stripped.startsWith("let ") or stripped.startsWith("proc ") or stripped.startsWith("var "):
|
||||
if stripped.startsWith("let ") or stripped.startsWith("proc ") or stripped.startsWith("var ") or
|
||||
stripped.startsWith("discard "):
|
||||
code = indentStr(indent) & stripped
|
||||
else:
|
||||
code = indentStr(indent) & "discard " & stripped
|
||||
|
||||
+11
-4
@@ -395,10 +395,17 @@ proc initMacros*() =
|
||||
let coll = bindings.items[1]
|
||||
let gs = cljSymbol(gensymName("ds_"))
|
||||
if name.kind == ckVector:
|
||||
let destructured = cljList(@[cljSymbol("let"), name, cljList(@[cljSymbol("first"), gs])])
|
||||
let loopBody = cljList(@[cljSymbol("when"), gs] & @[destructured] & body)
|
||||
let recurBody = cljList(@[cljSymbol("recur"), cljList(@[cljSymbol("rest"), gs])])
|
||||
let loopForm = cljList(@[cljSymbol("loop"), cljVector(@[gs, cljList(@[cljSymbol("seq"), gs])]), loopBody, recurBody])
|
||||
let seqGs = cljSymbol(gensymName("sq_"))
|
||||
let tmpGs = cljSymbol(gensymName("tmp_"))
|
||||
var innerBindings: seq[CljVal] = @[]
|
||||
for j in 0..<name.items.len:
|
||||
innerBindings.add(name.items[j])
|
||||
innerBindings.add(cljList(@[cljSymbol("nth"), tmpGs, cljInt(j)]))
|
||||
let destructured = cljList(@[cljSymbol("let"), cljVector(innerBindings)] & body)
|
||||
let loopBody = cljList(@[cljSymbol("when"), seqGs,
|
||||
cljList(@[cljSymbol("let"), cljVector(@[tmpGs, cljList(@[cljSymbol("first"), seqGs])]), destructured])])
|
||||
let recurBody = cljList(@[cljSymbol("recur"), cljList(@[cljSymbol("rest"), seqGs])])
|
||||
let loopForm = cljList(@[cljSymbol("loop"), cljVector(@[seqGs, cljList(@[cljSymbol("seq"), gs])]), loopBody, recurBody])
|
||||
result = cljList(@[cljSymbol("let"), cljVector(@[gs, coll]), loopForm])
|
||||
else:
|
||||
let loopBody = cljList(@[cljSymbol("when"), name] & body)
|
||||
|
||||
@@ -259,9 +259,15 @@ proc readAtom(s: string, i: var int): CljVal =
|
||||
break
|
||||
if hasDigit:
|
||||
if isFloat:
|
||||
try:
|
||||
return cljFloat(parseFloat(numTok))
|
||||
except CatchableError:
|
||||
return cljSymbol(tok)
|
||||
else:
|
||||
try:
|
||||
return cljInt(parseInt(numTok).int64)
|
||||
except CatchableError:
|
||||
return cljSymbol(tok)
|
||||
|
||||
# symbol
|
||||
return cljSymbol(tok)
|
||||
|
||||
Reference in New Issue
Block a user