allow addressing elements of openArray[char] in VM (#22045)

allow addressing elements of openArray[char]

(cherry picked from commit a8d0dda833)
This commit is contained in:
ringabout
2023-06-08 20:08:49 +08:00
committed by narimiran
parent 8f102f9e62
commit e8ec3efd3d
2 changed files with 16 additions and 0 deletions

View File

@@ -772,6 +772,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
else:
if src.kind notin {nkEmpty..nkTripleStrLit} and idx <% src.len:
takeAddress regs[ra], src.sons[idx]
elif src.kind in nkStrKinds and idx <% src.strVal.len:
regs[ra] = takeCharAddress(c, src, idx, pc)
else:
stackTrace(c, tos, pc, formatErrorIndexBound(idx, src.safeLen-1))
of opcLdStrIdx:

View File

@@ -657,3 +657,17 @@ proc macroGlobal =
static: macroGlobal()
macroGlobal()
block:
proc swap[T](x: var T): T =
result = x
x = default(T)
proc merge[T](a, b: var openArray[T]) =
a[0] = swap b[0]
static:
var x = "abc"
var y = "356"
merge(x, y)
doAssert x == "3bc"