parent
f82100ac93
commit
2c6f5ae681
2 changed files with 18 additions and 8 deletions
|
|
@ -15,6 +15,8 @@ import
|
||||||
platform, math, msgs, idents, renderer, types,
|
platform, math, msgs, idents, renderer, types,
|
||||||
commands, magicsys, modulegraphs, strtabs, lineinfos
|
commands, magicsys, modulegraphs, strtabs, lineinfos
|
||||||
|
|
||||||
|
from system/memory import nimCStrLen
|
||||||
|
|
||||||
proc errorType*(g: ModuleGraph): PType =
|
proc errorType*(g: ModuleGraph): PType =
|
||||||
## creates a type representing an error state
|
## creates a type representing an error state
|
||||||
result = newType(tyError, nextTypeId(g.idgen), g.owners[^1])
|
result = newType(tyError, nextTypeId(g.idgen), g.owners[^1])
|
||||||
|
|
@ -133,7 +135,10 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode =
|
||||||
if a.kind == nkNilLit:
|
if a.kind == nkNilLit:
|
||||||
result = newIntNodeT(Zero, n, g)
|
result = newIntNodeT(Zero, n, g)
|
||||||
elif a.kind in {nkStrLit..nkTripleStrLit}:
|
elif a.kind in {nkStrLit..nkTripleStrLit}:
|
||||||
result = newIntNodeT(toInt128(a.strVal.len), n, g)
|
if a.typ.kind == tyString:
|
||||||
|
result = newIntNodeT(toInt128(a.strVal.len), n, g)
|
||||||
|
elif a.typ.kind == tyCString:
|
||||||
|
result = newIntNodeT(toInt128(nimCStrLen(a.strVal)), n, g)
|
||||||
else:
|
else:
|
||||||
result = newIntNodeT(toInt128(a.len), n, g)
|
result = newIntNodeT(toInt128(a.len), n, g)
|
||||||
of mUnaryPlusI, mUnaryPlusF64: result = a # throw `+` away
|
of mUnaryPlusI, mUnaryPlusF64: result = a # throw `+` away
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
discard """
|
|
||||||
output: "DONE: tostring.nim"
|
|
||||||
"""
|
|
||||||
|
|
||||||
doAssert "@[23, 45]" == $(@[23, 45])
|
doAssert "@[23, 45]" == $(@[23, 45])
|
||||||
doAssert "[32, 45]" == $([32, 45])
|
doAssert "[32, 45]" == $([32, 45])
|
||||||
doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"])
|
doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"])
|
||||||
|
|
@ -108,7 +104,7 @@ bar(nilstring)
|
||||||
static:
|
static:
|
||||||
stringCompare()
|
stringCompare()
|
||||||
|
|
||||||
# bug 8847
|
# issue #8847
|
||||||
var a2: cstring = "fo\"o2"
|
var a2: cstring = "fo\"o2"
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
|
@ -116,5 +112,14 @@ block:
|
||||||
s.addQuoted a2
|
s.addQuoted a2
|
||||||
doAssert s == "\"fo\\\"o2\""
|
doAssert s == "\"fo\\\"o2\""
|
||||||
|
|
||||||
|
# issue #16650
|
||||||
echo "DONE: tostring.nim"
|
template fn() =
|
||||||
|
doAssert len(cstring"ab\0c") == 5
|
||||||
|
doAssert len(cstring("ab\0c")) == 2
|
||||||
|
when nimvm:
|
||||||
|
discard
|
||||||
|
else:
|
||||||
|
let c = cstring("ab\0c")
|
||||||
|
doAssert len(c) == 2
|
||||||
|
fn()
|
||||||
|
static: fn()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue