adds procedure test code and fix bugs

This commit is contained in:
demotomohiro
2025-10-29 18:26:45 +09:00
parent 6f237be686
commit b50c453b14
4 changed files with 16 additions and 3 deletions

View File

@@ -261,7 +261,9 @@ proc fromNif(c: var DecodeContext; n: var Cursor): PNode =
case kind:
of nkEmpty:
result = newNodeI(nkEmpty, c.fromNifLineInfo(n))
inc n
incExpect n, {Ident, DotToken}
let flags = fromNifNodeFlags n
result.flags = flags
skipParRi n
of nkIdent:
incExpect n, Ident
@@ -304,7 +306,7 @@ proc fromNif(c: var DecodeContext; n: var Cursor): PNode =
else:
c.withNode n, result, kind:
while n.kind != ParRi:
result.add c.fromNif n
result.addAllowNil c.fromNif n
else:
assert false, "Not yet implemented " & $n.kind

View File

@@ -143,6 +143,7 @@ proc toNif(c: var EncodeContext; n: PNode) =
of nkEmpty:
let info = c.toNif n.info
c.dest.addParLe pool.tags.getOrIncl(toNifTag(nkEmpty)), info
c.dest.writeNodeFlags(n.flags)
c.dest.addParRi
of nkIdent:
let info = c.toNif n.info
@@ -187,7 +188,7 @@ proc toNif(c: var EncodeContext; n: PNode) =
c.withNode n:
discard
else:
assert n.len > 0, $n.kind
assert n.kind in {nkArgList, nkBracket} or n.len > 0, $n.kind
c.withNode(n):
for i in 0 ..< n.len:
c.toNif n[i]

View File

@@ -330,3 +330,4 @@ testNifEncDec(graph, "modtest1.nim")
testNifEncDec(graph, "modtestliterals.nim")
testNifEncDec(graph, "modtesttypesections.nim")
testNifEncDec(graph, "modtestpragmas.nim")
testNifEncDec(graph, "modtestprocs.nim")

View File

@@ -0,0 +1,9 @@
proc foo() = discard
proc bar(x: int): int = x
proc baz(x, y: int): string = $(x + y)
proc baz(a: bool; b: string; c: int): float =
if a and b == "" and c == 0:
result = 0.0
else:
result = 1.0