From 9bb3f73482e899b3db81f55a1c2ce8ebf3159ca6 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 14 May 2023 23:01:09 +0300 Subject: [PATCH] Add destructor --- src/sfall_arrays.cc | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/sfall_arrays.cc b/src/sfall_arrays.cc index c79efe1..2785623 100644 --- a/src/sfall_arrays.cc +++ b/src/sfall_arrays.cc @@ -157,8 +157,27 @@ public: } ProgramValue toValue(Program* program) const { - // todo - return ProgramValue(0); + ProgramValue out; + switch (type) { + case ArrayElementType::INT: + out.opcode = VALUE_TYPE_INT; + out.integerValue = integerValue; + return out; + case ArrayElementType::FLOAT: + out.opcode = VALUE_TYPE_FLOAT; + out.floatValue = floatValue; + return out; + case ArrayElementType::POINTER: + out.opcode = VALUE_TYPE_PTR; + out.pointerValue = pointerValue; + return out; + case ArrayElementType::STRING: + out.opcode = VALUE_TYPE_DYNAMIC_STRING; + out.integerValue = programPushString(program, stringValue); + return out; + default: + throw(std::exception()); + } } bool operator<(ArrayElement const& other) const @@ -197,6 +216,12 @@ public: throw(std::exception()); } } + + ~ArrayElement(){ + if (type == ArrayElementType::STRING) { + free(stringValue); + }; + } }; class SFallArray {