fixes codegen for nil cstrings

This commit is contained in:
Andreas Rumpf 2018-04-02 17:00:35 +02:00
commit cc6fe6e578

View file

@ -65,9 +65,13 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
else: else:
result = rope("NIM_NIL") result = rope("NIM_NIL")
of nkStrLit..nkTripleStrLit: of nkStrLit..nkTripleStrLit:
case skipTypes(ty, abstractVarRange).kind
of tyNil:
result = ropecg(p.module, "((#NimStringDesc*) NIM_NIL)", [])
of tyString:
if n.strVal.isNil: if n.strVal.isNil:
result = ropecg(p.module, "((#NimStringDesc*) NIM_NIL)", []) result = ropecg(p.module, "((#NimStringDesc*) NIM_NIL)", [])
elif skipTypes(ty, abstractVarRange).kind == tyString: else:
let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels) let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels)
if id == p.module.labels: if id == p.module.labels:
# string literal not found in the cache: # string literal not found in the cache:
@ -77,7 +81,8 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
result = ropecg(p.module, "((#NimStringDesc*) &$1$2)", result = ropecg(p.module, "((#NimStringDesc*) &$1$2)",
[p.module.tmpBase, rope(id)]) [p.module.tmpBase, rope(id)])
else: else:
result = makeCString(n.strVal) if n.strVal.isNil: result = rope("NIM_NIL")
else: result = makeCString(n.strVal)
of nkFloatLit, nkFloat64Lit: of nkFloatLit, nkFloat64Lit:
result = rope(n.floatVal.toStrMaxPrecision) result = rope(n.floatVal.toStrMaxPrecision)
of nkFloat32Lit: of nkFloat32Lit: