various bugfixes for generics; added generic sort proc
This commit is contained in:
parent
f93ca8e42a
commit
e424e13bd9
18 changed files with 392 additions and 113 deletions
11
rod/ast.nim
11
rod/ast.nim
|
|
@ -750,6 +750,12 @@ proc newSymNode(sym: PSym): PNode =
|
|||
result.typ = sym.typ
|
||||
result.info = sym.info
|
||||
|
||||
proc newSymNode*(sym: PSym, info: TLineInfo): PNode =
|
||||
result = newNode(nkSym)
|
||||
result.sym = sym
|
||||
result.typ = sym.typ
|
||||
result.info = info
|
||||
|
||||
proc newNodeI(kind: TNodeKind, info: TLineInfo): PNode =
|
||||
result = newNode(kind)
|
||||
result.info = info
|
||||
|
|
@ -869,6 +875,11 @@ proc len*(n: PNode): int {.inline.} =
|
|||
if isNil(n.sons): result = 0
|
||||
else: result = len(n.sons)
|
||||
|
||||
proc safeLen*(n: PNode): int {.inline.} =
|
||||
## works even for leaves.
|
||||
if n.kind in {nkNone..nkNilLit} or isNil(n.sons): result = 0
|
||||
else: result = len(n.sons)
|
||||
|
||||
proc add*(father, son: PNode) =
|
||||
assert son != nil
|
||||
if isNil(father.sons): father.sons = @[]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue