From ee74706c3b1e040dded3baf2ee3c05ae111c968a Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 22 Feb 2014 01:09:43 +0100 Subject: fixed opcConv --- compiler/astalgo.nim | 10 ++++++++-- compiler/vm.nim | 32 +++++++++++++++++++++++++------- compiler/vmgen.nim | 5 ++--- 3 files changed, 35 insertions(+), 12 deletions(-) (limited to 'compiler') diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index 64c1b717c..cce2cc215 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -337,7 +337,10 @@ proc treeToYamlAux(n: PNode, marker: var TIntSet, indent: int, appf(result, ",$N$1\"floatVal\": $2", [istr, toRope(n.floatVal.toStrMaxPrecision)]) of nkStrLit..nkTripleStrLit: - appf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) + if n.strVal.isNil: + appf(result, ",$N$1\"strVal\": null", [istr]) + else: + appf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) of nkSym: appf(result, ",$N$1\"sym\": $2", [istr, symToYamlAux(n.sym, marker, indent + 2, maxRecDepth)]) @@ -407,7 +410,10 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope = appf(result, ",$N$1\"floatVal\": $2", [istr, toRope(n.floatVal.toStrMaxPrecision)]) of nkStrLit..nkTripleStrLit: - appf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) + if n.strVal.isNil: + appf(result, ",$N$1\"strVal\": null", [istr]) + else: + appf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) of nkSym: appf(result, ",$N$1\"sym\": $2_$3", [istr, toRope(n.sym.name.s), toRope(n.sym.id)]) diff --git a/compiler/vm.nim b/compiler/vm.nim index 8480cd1c6..f17da1c69 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -257,11 +257,25 @@ proc opConv*(dest: var TRegister, src: TRegister, desttyp, srctyp: PType): bool myreset(dest) dest.kind = rkStr dest.node = newNode(nkStrLit) - case srctyp.skipTypes(abstractRange).kind - of tyEnum: - dest.node.strVal = "too implement" #ordinalValToString(src) - of tyInt..tyInt64, tyUInt..tyUInt64: + let styp = srctyp.skipTypes(abstractRange) + case styp.kind + of tyEnum: + let n = styp.n + let x = src.intVal.int + if x <% n.len and (let f = n.sons[x].sym; f.position == x): + dest.node.strVal = if f.ast.isNil: f.name.s else: f.ast.strVal + else: + for i in 0..