mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
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:
@@ -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:
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user