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:
|
if bname.kind != ckSymbol:
|
||||||
raise newException(EmitterError, "let binding name must be a symbol")
|
raise newException(EmitterError, "let binding name must be a symbol")
|
||||||
addToScope(bname.symName)
|
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
|
bi += 2
|
||||||
let body = items[2..^1]
|
let body = items[2..^1]
|
||||||
for j, b in body:
|
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()
|
let lastLine = if lastNl == -1: trimmed else: trimmed[lastNl+1..^1].strip()
|
||||||
# Prepend discard before the first non-empty line
|
# Prepend discard before the first non-empty line
|
||||||
if firstNl == -1:
|
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
|
code = indentStr(indent) & stripped
|
||||||
else:
|
else:
|
||||||
code = indentStr(indent) & "discard " & stripped
|
code = indentStr(indent) & "discard " & stripped
|
||||||
|
|||||||
+11
-4
@@ -395,10 +395,17 @@ proc initMacros*() =
|
|||||||
let coll = bindings.items[1]
|
let coll = bindings.items[1]
|
||||||
let gs = cljSymbol(gensymName("ds_"))
|
let gs = cljSymbol(gensymName("ds_"))
|
||||||
if name.kind == ckVector:
|
if name.kind == ckVector:
|
||||||
let destructured = cljList(@[cljSymbol("let"), name, cljList(@[cljSymbol("first"), gs])])
|
let seqGs = cljSymbol(gensymName("sq_"))
|
||||||
let loopBody = cljList(@[cljSymbol("when"), gs] & @[destructured] & body)
|
let tmpGs = cljSymbol(gensymName("tmp_"))
|
||||||
let recurBody = cljList(@[cljSymbol("recur"), cljList(@[cljSymbol("rest"), gs])])
|
var innerBindings: seq[CljVal] = @[]
|
||||||
let loopForm = cljList(@[cljSymbol("loop"), cljVector(@[gs, cljList(@[cljSymbol("seq"), gs])]), loopBody, recurBody])
|
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])
|
result = cljList(@[cljSymbol("let"), cljVector(@[gs, coll]), loopForm])
|
||||||
else:
|
else:
|
||||||
let loopBody = cljList(@[cljSymbol("when"), name] & body)
|
let loopBody = cljList(@[cljSymbol("when"), name] & body)
|
||||||
|
|||||||
+8
-2
@@ -259,9 +259,15 @@ proc readAtom(s: string, i: var int): CljVal =
|
|||||||
break
|
break
|
||||||
if hasDigit:
|
if hasDigit:
|
||||||
if isFloat:
|
if isFloat:
|
||||||
return cljFloat(parseFloat(numTok))
|
try:
|
||||||
|
return cljFloat(parseFloat(numTok))
|
||||||
|
except CatchableError:
|
||||||
|
return cljSymbol(tok)
|
||||||
else:
|
else:
|
||||||
return cljInt(parseInt(numTok).int64)
|
try:
|
||||||
|
return cljInt(parseInt(numTok).int64)
|
||||||
|
except CatchableError:
|
||||||
|
return cljSymbol(tok)
|
||||||
|
|
||||||
# symbol
|
# symbol
|
||||||
return cljSymbol(tok)
|
return cljSymbol(tok)
|
||||||
|
|||||||
Reference in New Issue
Block a user