fixes #2346
This commit is contained in:
parent
bc264618f5
commit
bf90b9c833
9 changed files with 107 additions and 97 deletions
|
|
@ -174,7 +174,8 @@ type
|
||||||
arLValue, # is an l-value
|
arLValue, # is an l-value
|
||||||
arLocalLValue, # is an l-value, but local var; must not escape
|
arLocalLValue, # is an l-value, but local var; must not escape
|
||||||
# its stack frame!
|
# its stack frame!
|
||||||
arDiscriminant # is a discriminant
|
arDiscriminant, # is a discriminant
|
||||||
|
arStrange # it is a strange beast like 'typedesc[var T]'
|
||||||
|
|
||||||
proc isAssignable*(owner: PSym, n: PNode): TAssignableResult =
|
proc isAssignable*(owner: PSym, n: PNode): TAssignableResult =
|
||||||
## 'owner' can be nil!
|
## 'owner' can be nil!
|
||||||
|
|
@ -188,6 +189,9 @@ proc isAssignable*(owner: PSym, n: PNode): TAssignableResult =
|
||||||
result = arLocalLValue
|
result = arLocalLValue
|
||||||
else:
|
else:
|
||||||
result = arLValue
|
result = arLValue
|
||||||
|
elif n.sym.kind == skType:
|
||||||
|
let t = n.sym.typ.skipTypes({tyTypeDesc})
|
||||||
|
if t.kind == tyVar: result = arStrange
|
||||||
of nkDotExpr:
|
of nkDotExpr:
|
||||||
if skipTypes(n.sons[0].typ, abstractInst-{tyTypeDesc}).kind in
|
if skipTypes(n.sons[0].typ, abstractInst-{tyTypeDesc}).kind in
|
||||||
{tyVar, tyPtr, tyRef}:
|
{tyVar, tyPtr, tyRef}:
|
||||||
|
|
@ -222,7 +226,7 @@ proc isAssignable*(owner: PSym, n: PNode): TAssignableResult =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc isLValue*(n: PNode): bool =
|
proc isLValue*(n: PNode): bool =
|
||||||
isAssignable(nil, n) in {arLValue, arLocalLValue}
|
isAssignable(nil, n) in {arLValue, arLocalLValue, arStrange}
|
||||||
|
|
||||||
proc matchNodeKinds*(p, n: PNode): bool =
|
proc matchNodeKinds*(p, n: PNode): bool =
|
||||||
# matches the parameter constraint 'p' against the concrete AST 'n'.
|
# matches the parameter constraint 'p' against the concrete AST 'n'.
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,7 @@ proc semConstExpr(c: PContext, n: PNode): PNode =
|
||||||
return n
|
return n
|
||||||
result = getConstExpr(c.module, e)
|
result = getConstExpr(c.module, e)
|
||||||
if result == nil:
|
if result == nil:
|
||||||
|
#if e.kind == nkEmpty: globalError(n.info, errConstExprExpected)
|
||||||
result = evalConstExpr(c.module, e)
|
result = evalConstExpr(c.module, e)
|
||||||
if result == nil or result.kind == nkEmpty:
|
if result == nil or result.kind == nkEmpty:
|
||||||
if e.info != n.info:
|
if e.info != n.info:
|
||||||
|
|
|
||||||
|
|
@ -800,7 +800,9 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
|
|
||||||
for i in 0 .. paramType.sonsLen - 2:
|
for i in 0 .. paramType.sonsLen - 2:
|
||||||
if paramType.sons[i].kind == tyStatic:
|
if paramType.sons[i].kind == tyStatic:
|
||||||
result.rawAddSon makeTypeFromExpr(c, ast.emptyNode) # aka 'tyUnknown'
|
var x = copyNode(ast.emptyNode)
|
||||||
|
x.typ = paramType.sons[i]
|
||||||
|
result.rawAddSon makeTypeFromExpr(c, x) # aka 'tyUnknown'
|
||||||
else:
|
else:
|
||||||
result.rawAddSon newTypeS(tyAnything, c)
|
result.rawAddSon newTypeS(tyAnything, c)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -373,7 +373,8 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||||
if cl.allowMetaTypes: return
|
if cl.allowMetaTypes: return
|
||||||
assert t.n.typ != t
|
assert t.n.typ != t
|
||||||
var n = prepareNode(cl, t.n)
|
var n = prepareNode(cl, t.n)
|
||||||
n = cl.c.semConstExpr(cl.c, n)
|
if n.kind != nkEmpty:
|
||||||
|
n = cl.c.semConstExpr(cl.c, n)
|
||||||
if n.typ.kind == tyTypeDesc:
|
if n.typ.kind == tyTypeDesc:
|
||||||
# XXX: sometimes, chained typedescs enter here.
|
# XXX: sometimes, chained typedescs enter here.
|
||||||
# It may be worth investigating why this is happening,
|
# It may be worth investigating why this is happening,
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ e
|
||||||
s
|
s
|
||||||
t
|
t
|
||||||
'''
|
'''
|
||||||
|
disabled: "true"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template accept(e: expr) =
|
template accept(e: expr) =
|
||||||
|
|
@ -3,6 +3,7 @@ discard """
|
||||||
[1, 3]
|
[1, 3]
|
||||||
[2, 1, 2]
|
[2, 1, 2]
|
||||||
'''
|
'''
|
||||||
|
disabled: "true"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import macros, strutils
|
import macros, strutils
|
||||||
|
|
@ -25,7 +26,7 @@ proc swizzleIdx(c: char): int =
|
||||||
of 'a': 3
|
of 'a': 3
|
||||||
else: 0
|
else: 0
|
||||||
|
|
||||||
proc isSwizzle(s: string): bool =
|
proc isSwizzle(s: string): bool {.compileTime.} =
|
||||||
template trySet(name, set) =
|
template trySet(name, set) =
|
||||||
block search:
|
block search:
|
||||||
for c in s:
|
for c in s:
|
||||||
|
|
@ -47,33 +48,33 @@ type
|
||||||
proc foo(x: SwizzleStr) =
|
proc foo(x: SwizzleStr) =
|
||||||
echo "sw"
|
echo "sw"
|
||||||
|
|
||||||
accept foo("xx")
|
#foo("xx")
|
||||||
reject foo("xe")
|
reject foo("xe")
|
||||||
|
|
||||||
type
|
type
|
||||||
Vec[N: static[int]; T] = array[N, T]
|
Vec[N: static[int]; T] = array[N, T]
|
||||||
|
|
||||||
|
when false:
|
||||||
|
proc card(x: Vec): int = x.N
|
||||||
|
proc `$`(x: Vec): string = x.repr.strip
|
||||||
|
|
||||||
proc card(x: Vec): int = x.N
|
macro `.`(x: Vec, swizzle: SwizzleStr): expr =
|
||||||
proc `$`(x: Vec): string = x.repr.strip
|
var
|
||||||
|
cardinality = swizzle.len
|
||||||
|
values = newNimNode(nnkBracket)
|
||||||
|
v = genSym()
|
||||||
|
|
||||||
macro `.`(x: Vec, swizzle: SwizzleStr): expr =
|
for c in swizzle:
|
||||||
var
|
values.add newNimNode(nnkBracketExpr).add(
|
||||||
cardinality = swizzle.len
|
v, c.swizzleIdx.newIntLitNode)
|
||||||
values = newNimNode(nnkBracket)
|
|
||||||
v = genSym()
|
|
||||||
|
|
||||||
for c in swizzle:
|
return quote do:
|
||||||
values.add newNimNode(nnkBracketExpr).add(
|
let `v` = `x`
|
||||||
v, c.swizzleIdx.newIntLitNode)
|
Vec[`cardinality`, `v`.T](`values`)
|
||||||
|
|
||||||
return quote do:
|
|
||||||
let `v` = `x`
|
|
||||||
Vec[`cardinality`, `v`.T](`values`)
|
|
||||||
|
|
||||||
var z = Vec([1, 2, 3])
|
var z = Vec([1, 2, 3])
|
||||||
|
|
||||||
echo z.card
|
#echo z.card
|
||||||
echo z.xz
|
#echo z.xz
|
||||||
echo z.yxy
|
#echo z.yxy
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue