mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-03 18:34:43 +00:00
teach opcLdObj about nkExprColonExpr
This commit is contained in:
@@ -425,7 +425,9 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
decodeBC(rkNode)
|
||||
let src = regs[rb].node
|
||||
if src.kind notin {nkEmpty..nkNilLit}:
|
||||
regs[ra].node = src.sons[rc]
|
||||
let n = src.sons[rc]
|
||||
regs[ra].node = if n.kind == nkExprColonExpr: n[1]
|
||||
else: n
|
||||
else:
|
||||
stackTrace(c, tos, pc, errIndexOutOfBounds)
|
||||
of opcWrObj:
|
||||
|
||||
52
tests/static/tstaticparammacro.nim
Normal file
52
tests/static/tstaticparammacro.nim
Normal file
@@ -0,0 +1,52 @@
|
||||
discard """
|
||||
msg: '''letters
|
||||
aa
|
||||
bb
|
||||
numbers
|
||||
11
|
||||
22
|
||||
AST a
|
||||
[(11, 22), (33, 44)]
|
||||
AST b
|
||||
(e: [55, 66], f: [77, 88])
|
||||
55
|
||||
'''
|
||||
"""
|
||||
|
||||
import macros
|
||||
|
||||
type
|
||||
TConfig = tuple
|
||||
letters: seq[string]
|
||||
numbers:seq[int]
|
||||
|
||||
const data: Tconfig = (@["aa", "bb"], @[11, 22])
|
||||
|
||||
macro mymacro(data: static[TConfig]): stmt =
|
||||
echo "letters"
|
||||
for s in items(data.letters):
|
||||
echo s
|
||||
echo "numbers"
|
||||
for n in items(data.numbers):
|
||||
echo n
|
||||
|
||||
mymacro(data)
|
||||
|
||||
type
|
||||
Ta = seq[tuple[c:int, d:int]]
|
||||
Tb = tuple[e:seq[int], f:seq[int]]
|
||||
|
||||
const
|
||||
a : Ta = @[(11, 22), (33, 44)]
|
||||
b : Tb = (@[55,66], @[77, 88])
|
||||
|
||||
macro mA(data: static[Ta]): stmt =
|
||||
echo "AST a \n", repr(data)
|
||||
|
||||
macro mB(data: static[Tb]): stmt =
|
||||
echo "AST b \n", repr(data)
|
||||
echo data.e[0]
|
||||
|
||||
mA(a)
|
||||
mB(b)
|
||||
|
||||
@@ -10,28 +10,31 @@ discard """
|
||||
3
|
||||
1
|
||||
2
|
||||
3'''
|
||||
3
|
||||
aa
|
||||
bb
|
||||
aa
|
||||
bb'''
|
||||
"""
|
||||
|
||||
when false:
|
||||
const s = @[1,2,3]
|
||||
const s = @[1,2,3]
|
||||
|
||||
macro foo: stmt =
|
||||
for e in s:
|
||||
echo e
|
||||
macro foo: stmt =
|
||||
for e in s:
|
||||
echo e
|
||||
|
||||
foo()
|
||||
foo()
|
||||
|
||||
static:
|
||||
for e in s:
|
||||
echo e
|
||||
static:
|
||||
for e in s:
|
||||
echo e
|
||||
|
||||
macro bar(x: static[seq[int]]): stmt =
|
||||
for e in x:
|
||||
echo e
|
||||
macro bar(x: static[seq[int]]): stmt =
|
||||
for e in x:
|
||||
echo e
|
||||
|
||||
bar s
|
||||
bar(@[1, 2, 3])
|
||||
bar s
|
||||
bar(@[1, 2, 3])
|
||||
|
||||
type
|
||||
TData = tuple
|
||||
@@ -41,9 +44,6 @@ type
|
||||
const data: TData = (@["aa", "bb"], @[11, 22])
|
||||
|
||||
static:
|
||||
for x in data.letters:
|
||||
echo x
|
||||
|
||||
var m = data
|
||||
for x in m.letters:
|
||||
echo x
|
||||
|
||||
Reference in New Issue
Block a user