From e89782f921d7896a302bf8ccfbb97f4d477d496d Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 14 Sep 2019 13:19:52 +0200 Subject: [PATCH] Make numerical table type countable --- src/Evaluator/EvalValues/NumericalTableEvalValue.hpp | 8 ++++++-- src/ScriptTypes/ScriptType.hpp | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Evaluator/EvalValues/NumericalTableEvalValue.hpp b/src/Evaluator/EvalValues/NumericalTableEvalValue.hpp index ff2112b..f62e15a 100644 --- a/src/Evaluator/EvalValues/NumericalTableEvalValue.hpp +++ b/src/Evaluator/EvalValues/NumericalTableEvalValue.hpp @@ -60,7 +60,11 @@ namespace Porygon::Evaluation { inline void SetIndexValue(const EvalValue *key, const EvalValue* value) const final { auto index = key->EvaluateInteger(); - this->_table->at(index - 1) = value; + index--; + if (this->_table->size() <= index){ + this->_table->resize(index); + } + this->_table->at(index) = value; } [[nodiscard]] @@ -71,7 +75,7 @@ namespace Porygon::Evaluation { return _table; } - EvalValue *UnaryOperation(Binder::BoundUnaryOperation operation) const override;; + [[nodiscard]] EvalValue *UnaryOperation(Binder::BoundUnaryOperation operation) const override;; }; } diff --git a/src/ScriptTypes/ScriptType.hpp b/src/ScriptTypes/ScriptType.hpp index 059f311..b63bb76 100644 --- a/src/ScriptTypes/ScriptType.hpp +++ b/src/ScriptTypes/ScriptType.hpp @@ -178,6 +178,10 @@ namespace Porygon{ inline shared_ptr GetIteratorKeyType() const final{ return NumericScriptType::AwareInt; } + + [[nodiscard]] bool IsCountable() const override { + return true; + } }; }