wip ref fixes

This commit is contained in:
Zahary Karadjov 2019-11-25 20:45:37 +02:00
parent 1c4293b3e7
commit cb10d69c69
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 47 additions and 3 deletions

View File

@ -35,6 +35,9 @@ template readPragma*(field: FieldDescription, pragmaName: static string): NimNod
if p != nil and p.len == 2: p[1] else: p if p != nil and p.len == 2: p[1] else: p
proc recordFields*(typeImpl: NimNode): seq[FieldDescription] = proc recordFields*(typeImpl: NimNode): seq[FieldDescription] =
echo "TYPE IMPL"
echo typeImpl.treeRepr
if typeImpl.isTuple: if typeImpl.isTuple:
for i in 1 ..< typeImpl.len: for i in 1 ..< typeImpl.len:
result.add FieldDescription(typ: typeImpl[i], name: ident("Field" & $(i - 1))) result.add FieldDescription(typ: typeImpl[i], name: ident("Field" & $(i - 1)))
@ -42,7 +45,12 @@ proc recordFields*(typeImpl: NimNode): seq[FieldDescription] =
# TODO: This doesn't support inheritance yet # TODO: This doesn't support inheritance yet
let objectType = typeImpl[2] let objectType = typeImpl[2]
let recList = objectType[2] var recList = objectType[2]
if recList.kind == nnkSym:
echo recList.treeRepr
recList = getImpl(recList)
echo "RESOLVED"
echo recList.treeRepr
type type
RecursionStackItem = tuple RecursionStackItem = tuple
@ -67,6 +75,11 @@ proc recordFields*(typeImpl: NimNode): seq[FieldDescription] =
var stackTop = traversalStack[^1] var stackTop = traversalStack[^1]
let recList = stackTop.currentNode let recList = stackTop.currentNode
let idx = stackTop.currentChildItem let idx = stackTop.currentChildItem
if recList.kind == nnkSym:
echo "HRMM"
echo recList.treeRepr
echo getImpl(recList).treeRepr
echo typeImpl.treeRepr
let n = recList[idx] let n = recList[idx]
inc traversalStack[^1].currentChildItem inc traversalStack[^1].currentChildItem
@ -139,11 +152,42 @@ proc skipPragma*(n: NimNode): NimNode =
if n.kind == nnkPragmaExpr: n[0] if n.kind == nnkPragmaExpr: n[0]
else: n else: n
macro hasCustomPragmaFixed*(T: type, field: static string, pragma: typed{nkSym}): untyped = macro hasCustomPragmaFixed*(T: type, T2: typed, field: static string, pragma: typed{nkSym}): untyped =
let Tresolved = getType(T)[1] echo "T"
echo T.treeRepr
echo "T2"
echo T2.treeRepr
let ttt = getType(T)
echo "ttt"
echo ttt.treeRepr
let t2t = getType(T2)
echo "t2t"
echo t2t.treeRepr
let t2ti = getTypeImpl(T2)
echo "t2ti"
echo t2ti.treeRepr
echo t2ti[1].getImpl.treeRepr
var Tresolved = getType(T)[1]
if isTuple(Tresolved): if isTuple(Tresolved):
return newLit(false) return newLit(false)
if Tresolved.kind == nnkBracketExpr:
Tresolved = Tresolved[1]
echo "Tresolved"
echo Tresolved.treeRepr
let impl = Tresolved.getImpl
echo "impl"
echo impl.treeRepr
echo Tresolved.getTypeImpl.treeRepr
for f in recordFields(Tresolved.getImpl): for f in recordFields(Tresolved.getImpl):
var fieldName = f.name var fieldName = f.name
# TODO: Fix this in eqIdent # TODO: Fix this in eqIdent