diff options
author | Araq <rumpf_a@web.de> | 2014-02-22 01:09:43 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-02-22 01:09:43 +0100 |
commit | ee74706c3b1e040dded3baf2ee3c05ae111c968a (patch) | |
tree | 1997239cf771c759dd8d8a5feb3fbc2e614e8c15 | |
parent | 6e584c42c2d340a31acad85add79b579b3e56f0b (diff) | |
download | Nim-ee74706c3b1e040dded3baf2ee3c05ae111c968a.tar.gz |
fixed opcConv
-rw-r--r-- | compiler/astalgo.nim | 10 | ||||
-rw-r--r-- | compiler/vm.nim | 32 | ||||
-rw-r--r-- | compiler/vmgen.nim | 5 | ||||
-rw-r--r-- | todo.txt | 1 |
4 files changed, 35 insertions, 13 deletions
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.. <n.len: + if n.sons[i].kind != nkSym: internalError("opConv for enum") + let f = n.sons[i].sym + if f.position == x: + dest.node.strVal = if f.ast.isNil: f.name.s else: f.ast.strVal + return + internalError("opConv for enum") + of tyInt..tyInt64: dest.node.strVal = $src.intVal + of tyUInt..tyUInt64: + dest.node.strVal = $uint64(src.intVal) of tyBool: dest.node.strVal = if src.intVal == 0: "false" else: "true" of tyFloat..tyFloat128: @@ -1007,7 +1021,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TRegister = else: stackTrace(c, tos, pc, errFieldXNotFound, "ident") of opcSetType: - if regs[ra].kind != rkNode: globalError(c.debug[pc], "cannot set type") + if regs[ra].kind != rkNode: + internalError(c.debug[pc], "cannot set type") regs[ra].node.typ = c.types[instr.regBx - wordExcess] of opcConv: let rb = instr.regB @@ -1023,9 +1038,12 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TRegister = of opcCast: let rb = instr.regB inc pc - let typ = c.types[c.code[pc].regBx - wordExcess] + let desttyp = c.types[c.code[pc].regBx - wordExcess] + inc pc + let srctyp = c.types[c.code[pc].regBx - wordExcess] + when hasFFI: - let dest = fficast(regs[rb], typ) + let dest = fficast(regs[rb], desttyp) asgnRef(regs[ra], dest) else: globalError(c.debug[pc], "cannot evaluate cast") diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index b01514167..cddda7bd3 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -579,11 +579,10 @@ proc genAddSubInt(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode) = proc genConv(c: PCtx; n, arg: PNode; dest: var TDest; opc=opcConv) = let tmp = c.genx(arg) - c.gABx(n, opcSetType, tmp, genType(c, arg.typ)) if dest < 0: dest = c.getTemp(n.typ) c.gABC(n, opc, dest, tmp) c.gABx(n, opc, 0, genType(c, n.typ)) - if opc == opcConv: c.gABx(n, opc, 0, genType(c, arg.typ)) + c.gABx(n, opc, 0, genType(c, arg.typ)) c.freeTemp(tmp) proc genCard(c: PCtx; n: PNode; dest: var TDest) = @@ -1504,7 +1503,7 @@ proc genProc(c: PCtx; s: PSym): int = c.gABC(body, opcEof, eofInstr.regA) c.optimizeJumps(result) s.offset = c.prc.maxSlots - #if s.name.s == "concatStyleInterpolation": + #if s.name.s == "traverse": # c.echoCode(result) # echo renderTree(body) c.prc = oldPrc diff --git a/todo.txt b/todo.txt index 3985343e0..7009d9a84 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,6 @@ version 0.9.4 ============= -- make vmgen insert opcNodeToReg, opcRegToNode - fix macros\tstringinterp.nim - fix GC issues - test and fix showoff |