From e934cf1c0928f04524caafe6e9b5c93fb20e59b4 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Thu, 20 Apr 2023 01:21:56 +0300 Subject: [PATCH] Add get_array_key --- src/sfall_arrays.cc | 10 ++++++++++ src/sfall_opcodes.cc | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sfall_arrays.cc b/src/sfall_arrays.cc index c561151..3b805e9 100644 --- a/src/sfall_arrays.cc +++ b/src/sfall_arrays.cc @@ -104,7 +104,17 @@ ProgramValue GetArrayKey(ArrayId array_id, int index) if (index == -1) { // special index to indicate if array is associative throw(std::invalid_argument("Not implemented yet")); }; + // TODO: if assoc return SFallArrayElement(index); } +int LenArray(ArrayId array_id) +{ + auto arr = get_array_by_id(array_id); + if (arr == nullptr) { + return -1; + }; + return arr->size(); +} + } \ No newline at end of file diff --git a/src/sfall_opcodes.cc b/src/sfall_opcodes.cc index 6c92042..c9db981 100644 --- a/src/sfall_opcodes.cc +++ b/src/sfall_opcodes.cc @@ -335,8 +335,7 @@ static void opGetArray(Program* program) static void opLenArray(Program* program) { auto arrayId = programStackPopInteger(program); - - programStackPushInteger(program, 100); + programStackPushInteger(program, LenArray(arrayId)); } // party_member_list