diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2024-03-03 15:40:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-03 15:40:08 +0100 |
commit | 24fbacc63fe8c7a36c77a35bede98462607e950e (patch) | |
tree | 432913a91f2d40713d1710ac75a504caa1ec74ca | |
parent | 1e7ca2dc789eafccdb44304f7e42206c3702fc13 (diff) | |
download | Nim-24fbacc63fe8c7a36c77a35bede98462607e950e.tar.gz |
fixes an issue with string to 'var openArray' at compile-time; [backp… (#23363)
…ort]
-rw-r--r-- | compiler/ccgutils.nim | 40 | ||||
-rw-r--r-- | compiler/vm.nim | 7 |
2 files changed, 26 insertions, 21 deletions
diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index 7c305a195..4ba1c19d9 100644 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -13,7 +13,7 @@ import ast, types, msgs, wordrecg, platform, trees, options, cgendata -import std/[hashes, strutils, formatFloat] +import std/[hashes, strutils, formatfloat] when defined(nimPreviewSlimSystem): import std/assertions @@ -126,10 +126,10 @@ proc mapSetType(conf: ConfigRef; typ: PType): TCTypeKind = proc ccgIntroducedPtr*(conf: ConfigRef; s: PSym, retType: PType): bool = var pt = skipTypes(s.typ, typedescInst) assert skResult != s.kind - + #note precedence: params override types if optByRef in s.options: return true - elif sfByCopy in s.flags: return false + elif sfByCopy in s.flags: return false elif tfByRef in pt.flags: return true elif tfByCopy in pt.flags: return false case pt.kind @@ -153,62 +153,62 @@ proc ccgIntroducedPtr*(conf: ConfigRef; s: PSym, retType: PType): bool = result = not (pt.kind in {tyVar, tyArray, tyOpenArray, tyVarargs, tyRef, tyPtr, tyPointer} or pt.kind == tySet and mapSetType(conf, pt) == ctArray) -proc encodeName*(name: string): string = +proc encodeName*(name: string): string = result = mangle(name) result = $result.len & result -proc makeUnique(m: BModule; s: PSym, name: string = ""): string = +proc makeUnique(m: BModule; s: PSym, name: string = ""): string = result = if name == "": s.name.s else: name result.add "__" result.add m.g.graph.ifaces[s.itemId.module].uniqueName result.add "_u" result.add $s.itemId.item -proc encodeSym*(m: BModule; s: PSym; makeUnique: bool = false): string = +proc encodeSym*(m: BModule; s: PSym; makeUnique: bool = false): string = #Module::Type - var name = s.name.s + var name = s.name.s if makeUnique: name = makeUnique(m, s, name) "N" & encodeName(s.owner.name.s) & encodeName(name) & "E" -proc encodeType*(m: BModule; t: PType): string = +proc encodeType*(m: BModule; t: PType): string = result = "" var kindName = ($t.kind)[2..^1] kindName[0] = toLower($kindName[0])[0] case t.kind - of tyObject, tyEnum, tyDistinct, tyUserTypeClass, tyGenericParam: + of tyObject, tyEnum, tyDistinct, tyUserTypeClass, tyGenericParam: result = encodeSym(m, t.sym) of tyGenericInst, tyUserTypeClassInst, tyGenericBody: result = encodeName(t[0].sym.name.s) result.add "I" - for i in 1..<t.len - 1: + for i in 1..<t.len - 1: result.add encodeType(m, t[i]) result.add "E" of tySequence, tyOpenArray, tyArray, tyVarargs, tyTuple, tyProc, tySet, tyTypeDesc, tyPtr, tyRef, tyVar, tyLent, tySink, tyStatic, tyUncheckedArray, tyOr, tyAnd, tyBuiltInTypeClass: - result = + result = case t.kind: - of tySequence: encodeName("seq") + of tySequence: encodeName("seq") else: encodeName(kindName) result.add "I" for i in 0..<t.len: - let s = t[i] + let s = t[i] if s.isNil: continue result.add encodeType(m, s) result.add "E" of tyRange: var val = "range_" - if t.n[0].typ.kind in {tyFloat..tyFloat128}: - val.addFloat t.n[0].floatVal - val.add "_" + if t.n[0].typ.kind in {tyFloat..tyFloat128}: + val.addFloat t.n[0].floatVal + val.add "_" val.addFloat t.n[1].floatVal - else: + else: val.add $t.n[0].intVal & "_" & $t.n[1].intVal result = encodeName(val) - of tyString..tyUInt64, tyPointer, tyBool, tyChar, tyVoid, tyAnything, tyNil, tyEmpty: + of tyString..tyUInt64, tyPointer, tyBool, tyChar, tyVoid, tyAnything, tyNil, tyEmpty: result = encodeName(kindName) - of tyAlias, tyInferred, tyOwned: + of tyAlias, tyInferred, tyOwned: result = encodeType(m, t.elementType) else: assert false, "encodeType " & $t.kind - + diff --git a/compiler/vm.nim b/compiler/vm.nim index d74a64908..a775cf584 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -813,6 +813,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = # a[b] = c decodeBC(rkNode) let idx = regs[rb].intVal.int + assert regs[ra].kind == rkNode let arr = regs[ra].node case arr.kind of nkTupleConstr: # refer to `opcSlice` @@ -826,7 +827,11 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = of nkStrKinds: src.strVal[int(realIndex)] = char(regs[rc].intVal) of nkBracket: - src[int(realIndex)] = regs[rc].node + if regs[rc].kind == rkInt: + src[int(realIndex)] = newIntNode(nkIntLit, regs[rc].intVal) + else: + assert regs[rc].kind == rkNode + src[int(realIndex)] = regs[rc].node else: stackTrace(c, tos, pc, "opcWrArr internal error") else: |