teach opcLdObj about nkExprColonExpr

This commit is contained in:
Zahary Karadjov 2014-03-09 17:06:29 +02:00
commit eebe0035b5
3 changed files with 73 additions and 19 deletions

View file

@ -425,7 +425,9 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
decodeBC(rkNode) decodeBC(rkNode)
let src = regs[rb].node let src = regs[rb].node
if src.kind notin {nkEmpty..nkNilLit}: 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: else:
stackTrace(c, tos, pc, errIndexOutOfBounds) stackTrace(c, tos, pc, errIndexOutOfBounds)
of opcWrObj: of opcWrObj:

View 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)

View file

@ -10,28 +10,31 @@ discard """
3 3
1 1
2 2
3''' 3
aa
bb
aa
bb'''
""" """
when false: const s = @[1,2,3]
const s = @[1,2,3]
macro foo: stmt = macro foo: stmt =
for e in s: for e in s:
echo e echo e
foo() foo()
static: static:
for e in s: for e in s:
echo e echo e
macro bar(x: static[seq[int]]): stmt = macro bar(x: static[seq[int]]): stmt =
for e in x: for e in x:
echo e echo e
bar s bar s
bar(@[1, 2, 3]) bar(@[1, 2, 3])
type type
TData = tuple TData = tuple
@ -41,9 +44,6 @@ type
const data: TData = (@["aa", "bb"], @[11, 22]) const data: TData = (@["aa", "bb"], @[11, 22])
static: static:
for x in data.letters:
echo x
var m = data var m = data
for x in m.letters: for x in m.letters:
echo x echo x