commit
7f14d0e782
4 changed files with 11 additions and 4 deletions
|
|
@ -306,7 +306,7 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode =
|
||||||
var typ = skipTypes(n.sons[1].typ, abstractVarRange +
|
var typ = skipTypes(n.sons[1].typ, abstractVarRange +
|
||||||
{tyTypeDesc, tyFieldAccessor})
|
{tyTypeDesc, tyFieldAccessor})
|
||||||
case typ.kind
|
case typ.kind
|
||||||
of tySequence, tyString, tyOpenArray, tyVarargs:
|
of tySequence, tyString, tyCString, tyOpenArray, tyVarargs:
|
||||||
n.typ = getSysType(tyInt)
|
n.typ = getSysType(tyInt)
|
||||||
of tyArrayConstr, tyArray:
|
of tyArrayConstr, tyArray:
|
||||||
n.typ = typ.sons[0] # indextype
|
n.typ = typ.sons[0] # indextype
|
||||||
|
|
|
||||||
|
|
@ -666,7 +666,7 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
result = newIntNodeT(firstOrd(n.sons[1].typ), n)
|
result = newIntNodeT(firstOrd(n.sons[1].typ), n)
|
||||||
of mHigh:
|
of mHigh:
|
||||||
if skipTypes(n.sons[1].typ, abstractVar).kind notin
|
if skipTypes(n.sons[1].typ, abstractVar).kind notin
|
||||||
{tyOpenArray, tyVarargs, tySequence, tyString}:
|
{tySequence, tyString, tyCString, tyOpenArray, tyVarargs}:
|
||||||
result = newIntNodeT(lastOrd(skipTypes(n[1].typ, abstractVar)), n)
|
result = newIntNodeT(lastOrd(skipTypes(n[1].typ, abstractVar)), n)
|
||||||
else:
|
else:
|
||||||
var a = getArrayConstr(m, n.sons[1])
|
var a = getArrayConstr(m, n.sons[1])
|
||||||
|
|
|
||||||
|
|
@ -893,7 +893,8 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest) =
|
||||||
of mHigh:
|
of mHigh:
|
||||||
if dest < 0: dest = c.getTemp(n.typ)
|
if dest < 0: dest = c.getTemp(n.typ)
|
||||||
let tmp = c.genx(n.sons[1])
|
let tmp = c.genx(n.sons[1])
|
||||||
if n.sons[1].typ.skipTypes(abstractVar-{tyTypeDesc}).kind == tyString:
|
case n.sons[1].typ.skipTypes(abstractVar-{tyTypeDesc}).kind:
|
||||||
|
of tyString, tyCString:
|
||||||
c.gABI(n, opcLenStr, dest, tmp, 1)
|
c.gABI(n, opcLenStr, dest, tmp, 1)
|
||||||
else:
|
else:
|
||||||
c.gABI(n, opcLenSeq, dest, tmp, 1)
|
c.gABI(n, opcLenSeq, dest, tmp, 1)
|
||||||
|
|
|
||||||
6
tests/exprs/thighCString.nim
Normal file
6
tests/exprs/thighCString.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
discard """
|
||||||
|
output: "5"
|
||||||
|
"""
|
||||||
|
let test = cstring("foobar")
|
||||||
|
|
||||||
|
echo high(test)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue