From cfc174757e10f9f92207aa4b8be0e8c03d151528 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Sun, 14 May 2023 22:56:25 +0300 Subject: [PATCH] Removing TODOs --- src/sfall_arrays.cc | 71 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/src/sfall_arrays.cc b/src/sfall_arrays.cc index 6fb0fc6..c79efe1 100644 --- a/src/sfall_arrays.cc +++ b/src/sfall_arrays.cc @@ -83,18 +83,77 @@ public: ArrayElement(const ArrayElement& other) = delete; ArrayElement& operator=(const ArrayElement& rhs) = delete; - ArrayElement(ArrayElement&& other) { - // todo - }; - ArrayElement& operator=(ArrayElement&& rhs) + ArrayElement(ArrayElement&& other) { - // todo + // Maybe this can be done simpler way? + type = other.type; + switch (type) { + case ArrayElementType::INT: + integerValue = other.integerValue; + break; + case ArrayElementType::FLOAT: + floatValue = other.floatValue; + break; + case ArrayElementType::POINTER: + pointerValue = other.pointerValue; + break; + case ArrayElementType::STRING: + stringValue = other.stringValue; + other.stringValue = nullptr; + break; + default: + throw(std::exception()); + } + }; + ArrayElement& operator=(ArrayElement&& other) + { + // Maybe this can be done simpler way? + type = other.type; + switch (type) { + case ArrayElementType::INT: + integerValue = other.integerValue; + break; + case ArrayElementType::FLOAT: + floatValue = other.floatValue; + break; + case ArrayElementType::POINTER: + pointerValue = other.pointerValue; + break; + case ArrayElementType::STRING: + stringValue = other.stringValue; + other.stringValue = nullptr; + break; + default: + throw(std::exception()); + } return *this; } ArrayElement(ProgramValue programValue, Program* program) { - // todo + switch (programValue.opcode) { + case VALUE_TYPE_INT: + type = ArrayElementType::INT; + integerValue = programValue.integerValue; + return; + case VALUE_TYPE_FLOAT: + type = ArrayElementType::INT; + floatValue = programValue.floatValue; + return; + case VALUE_TYPE_PTR: + type = ArrayElementType::INT; + pointerValue = programValue.pointerValue; + return; + case VALUE_TYPE_STRING: + case VALUE_TYPE_DYNAMIC_STRING: + type = ArrayElementType::STRING; + auto str = programGetString(program, programValue.opcode, programValue.integerValue); + auto len = strlen(str); + auto buf = (char*)malloc(len + 1); + strcpy(buf, str); + stringValue = buf; + return; + } } ProgramValue toValue(Program* program) const {