From 6f237be68665da8d201dcf8162fe25772989c769 Mon Sep 17 00:00:00 2001 From: demotomohiro Date: Wed, 29 Oct 2025 14:03:14 +0900 Subject: [PATCH] saves/loads symbol magic, options and offset --- compiler/icnif/nifdecoder.nim | 9 +++++++++ compiler/icnif/nifencoder.nim | 6 ++++++ tests/icnif/tencode_node2node.nim | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/compiler/icnif/nifdecoder.nim b/compiler/icnif/nifdecoder.nim index aca9ac47dd..77cbff5517 100644 --- a/compiler/icnif/nifdecoder.nim +++ b/compiler/icnif/nifdecoder.nim @@ -98,7 +98,13 @@ proc fromNifSymDef(c: var DecodeContext; n: var Cursor): PSym = incExpect n, Ident let ident = c.graph.cache.getIdent(pool.strings[n.litId]) incExpect n, {Ident, DotToken} + let magic = if n.kind == Ident: pool.strings[n.litId].parseMagic else: mNone + incExpect n, {Ident, DotToken} let flags = if n.kind == Ident: pool.strings[n.litId].parseSymFlags else: {} + incExpect n, {Ident, DotToken} + let options = if n.kind == Ident: pool.strings[n.litId].parseOptions else: {} + incExpect n, IntLit + let offset = pool.integers[n.intId].int32 incExpect n, IntLit let disamb = pool.integers[n.intId].int32 incExpect n, ParLe @@ -107,9 +113,12 @@ proc fromNifSymDef(c: var DecodeContext; n: var Cursor): PSym = result = PSym(itemId: ItemId(module: itemIdModule.int32, item: itemId), kind: kind, + magic: magic, name: ident, info: info, flags: flags, + options: options, + offset: offset, disamb: disamb) # PNode, PSym or PType type fields in PSym can have cycles. diff --git a/compiler/icnif/nifencoder.nim b/compiler/icnif/nifencoder.nim index 6a91064ac8..0f7b6720f4 100644 --- a/compiler/icnif/nifencoder.nim +++ b/compiler/icnif/nifencoder.nim @@ -59,7 +59,13 @@ proc toNifDef(c: var EncodeContext; sym: PSym) = c.toNifModuleId sym.itemId.module c.dest.addIntLit sym.itemId.item c.dest.addIdent sym.name.s + if sym.magic == mNone: + c.dest.addDotToken + else: + c.dest.addIdent toNifTag(sym.magic) c.dest.writeFlags sym.flags + c.dest.writeFlags sym.options + c.dest.addIntLit sym.offset c.dest.addIntLit sym.disamb c.dest.buildTree sym.kind.toNifTag: case sym.kind diff --git a/tests/icnif/tencode_node2node.nim b/tests/icnif/tencode_node2node.nim index b688542717..c71f53c63c 100644 --- a/tests/icnif/tencode_node2node.nim +++ b/tests/icnif/tencode_node2node.nim @@ -143,14 +143,23 @@ proc eql(x, y: PSym; c: var EqlContext): bool = elif x.kind != y.kind: echo "symbol kind mismatch: ", x.kind, "/", y.kind result = false + elif x.magic != y.magic: + echo "symbol magic mismatch: ", x.magic, "/", y.magic + result = false elif not eql(x.info, y.info, c): echo "symbol line info mismatch" result = false elif x.flags != y.flags: echo "symbol flag mismatch: ", x.flags, "/", y.flags result = false + elif x.options != y.options: + echo "symbol options mismatch: ", x.options, "/", y.options + result = false elif not eqlSymPos(x, y, c): result = false + elif x.offset != y.offset: + echo "symbol offset mismatch: ", x.offset, "/", y.offset + result = false elif x.disamb != y.disamb: echo "symbol disamb mismatch: ", x.disamb, "/", y.disamb result = false