mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-01 10:52:14 +00:00
fixed opcConv
This commit is contained in:
@@ -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)])
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user