From 4de57e99ffdf95a45eef0dcbae5272d6e58211dc Mon Sep 17 00:00:00 2001 From: Torben Ewert Date: Wed, 24 Jun 2026 17:25:22 +0200 Subject: [PATCH] fix: store correct address for symbols --- lib/pinc_core/SymbolTable.ml | 5 +++-- test/vm/run.t | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/pinc_core/SymbolTable.ml b/lib/pinc_core/SymbolTable.ml index 01c40eb..c8633d0 100644 --- a/lib/pinc_core/SymbolTable.ml +++ b/lib/pinc_core/SymbolTable.ml @@ -14,8 +14,9 @@ and scope = Global let make () = { store = StringMap.empty; length = Int32.zero } let define_symbol t ~name = - let symbol = { name; scope = Global; address = t.length } in - { store = StringMap.add name symbol t.store; length = Int32.succ t.length } + let address = Int32.succ t.length in + let symbol = { name; scope = Global; address } in + { store = StringMap.add name symbol t.store; length = address } ;; let resolve_symbol t ~name = StringMap.find_opt name t.store diff --git a/test/vm/run.t b/test/vm/run.t index a0dc732..d7455a4 100644 --- a/test/vm/run.t +++ b/test/vm/run.t @@ -234,9 +234,9 @@ $ NO_COLOR="1" print_instructions . Let 0000 I_Constant 0x00000001 (00000001) 0005 I_Set_Global 0x00000001 (00000001) - 0010 I_Get_Global 0x00000000 (00000000) + 0010 I_Get_Global 0x00000001 (00000001) 0015 I_Set_Global 0x00000002 (00000002) - 0020 I_Get_Global 0x00000001 (00000001) + 0020 I_Get_Global 0x00000002 (00000002) 0025 I_Pop $ NO_COLOR="1" print_instructions . UnboundIdentifier -- 2.51.2