few more fixes for static params in macros; new failing test cases for static evaluation
This commit is contained in:
parent
5820093e58
commit
5aa486cf11
2 changed files with 58 additions and 15 deletions
|
|
@ -602,15 +602,24 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
incl(result.flags, tfFinal)
|
incl(result.flags, tfFinal)
|
||||||
|
|
||||||
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
|
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
|
||||||
if kind == skMacro and param.typ.kind notin {tyTypeDesc, tyStatic}:
|
template addDecl(x) =
|
||||||
# within a macro, every param has the type PNimrodNode!
|
if sfGenSym notin x.flags: addDecl(c, x)
|
||||||
# and param.typ.kind in {tyTypeDesc, tyExpr, tyStmt}:
|
|
||||||
let nn = getSysSym"PNimrodNode"
|
if kind == skMacro:
|
||||||
var a = copySym(param)
|
if param.typ.kind == tyTypeDesc:
|
||||||
a.typ = nn.typ
|
addDecl(param)
|
||||||
if sfGenSym notin a.flags: addDecl(c, a)
|
elif param.typ.kind == tyStatic:
|
||||||
|
var a = copySym(param)
|
||||||
|
a.typ = param.typ.base
|
||||||
|
addDecl(a)
|
||||||
|
else:
|
||||||
|
# within a macro, every param has the type PNimrodNode!
|
||||||
|
let nn = getSysSym"PNimrodNode"
|
||||||
|
var a = copySym(param)
|
||||||
|
a.typ = nn.typ
|
||||||
|
addDecl(a)
|
||||||
else:
|
else:
|
||||||
if sfGenSym notin param.flags: addDecl(c, param)
|
addDecl(param)
|
||||||
|
|
||||||
let typedescId = getIdent"typedesc"
|
let typedescId = getIdent"typedesc"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,52 @@ discard """
|
||||||
3
|
3
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
3'''
|
3'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
const s = @[1,2,3]
|
when false:
|
||||||
|
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:
|
||||||
|
for e in s:
|
||||||
|
echo e
|
||||||
|
|
||||||
|
macro bar(x: static[seq[int]]): stmt =
|
||||||
|
for e in x:
|
||||||
|
echo e
|
||||||
|
|
||||||
|
bar s
|
||||||
|
bar(@[1, 2, 3])
|
||||||
|
|
||||||
|
type
|
||||||
|
TData = tuple
|
||||||
|
letters: seq[string]
|
||||||
|
numbers: seq[int]
|
||||||
|
|
||||||
|
const data: TData = (@["aa", "bb"], @[11, 22])
|
||||||
|
|
||||||
static:
|
static:
|
||||||
for e in s:
|
for x in data.letters:
|
||||||
echo e
|
echo x
|
||||||
|
|
||||||
|
var m = data
|
||||||
|
for x in m.letters:
|
||||||
|
echo x
|
||||||
|
|
||||||
|
macro ff(d: static[TData]): stmt =
|
||||||
|
for x in d.letters:
|
||||||
|
echo x
|
||||||
|
|
||||||
|
ff(data)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue