From 24923deed05f64a37460847e0c4fafd011d0c997 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 19 Sep 2019 11:28:00 +0200 Subject: [PATCH] Fixes and improvements for new table system --- src/Evaluator/EvalValues/TableEvalValue.hpp | 2 +- src/Evaluator/Evaluator.cpp | 3 +-- src/Evaluator/Iterator/NumericalKeyIterator.cpp | 4 ++-- tests/integration/TablesTests.cpp | 12 ++++++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Evaluator/EvalValues/TableEvalValue.hpp b/src/Evaluator/EvalValues/TableEvalValue.hpp index 36cad69..2655731 100644 --- a/src/Evaluator/EvalValues/TableEvalValue.hpp +++ b/src/Evaluator/EvalValues/TableEvalValue.hpp @@ -53,7 +53,7 @@ namespace Porygon::Evaluation { [[nodiscard]] inline EvalValue* IndexValue(const EvalValue *val) const final { - const auto stringKey = val->EvaluateString(); + const auto stringKey = val->GetHashCode(); return this->_table->at(Utilities::HashedString::CreateLookup(stringKey))->Clone(); } diff --git a/src/Evaluator/Evaluator.cpp b/src/Evaluator/Evaluator.cpp index d409b58..7f1d869 100644 --- a/src/Evaluator/Evaluator.cpp +++ b/src/Evaluator/Evaluator.cpp @@ -407,8 +407,7 @@ namespace Porygon::Evaluation { auto values = new map(); for (size_t i = 0; i < valueExpressions->size(); i++) { auto val = this->EvaluateExpression(valueExpressions->at(i)); - auto k = Utilities::StringUtils::IntToString(i + 1); - auto s = Utilities::HashedString(new u16string(k)); + auto s = Utilities::HashedString::CreateLookup(i + 1); values->insert({s, val}); } auto valuesPointer = shared_ptr>(values); diff --git a/src/Evaluator/Iterator/NumericalKeyIterator.cpp b/src/Evaluator/Iterator/NumericalKeyIterator.cpp index d4149ef..f48cee6 100644 --- a/src/Evaluator/Iterator/NumericalKeyIterator.cpp +++ b/src/Evaluator/Iterator/NumericalKeyIterator.cpp @@ -1,6 +1,6 @@ #include "NumericalKeyIterator.hpp" const Porygon::Evaluation::EvalValue *Porygon::Evaluation::NumericalKeyIterator::GetCurrent() { - auto s = *_iterator->first.GetString(); - return new NumericEvalValue(Utilities::StringUtils::ParseInteger(s)); + auto s = _iterator->first.GetHash(); + return new NumericEvalValue(static_cast(s)); } diff --git a/tests/integration/TablesTests.cpp b/tests/integration/TablesTests.cpp index 97941a3..b792679 100644 --- a/tests/integration/TablesTests.cpp +++ b/tests/integration/TablesTests.cpp @@ -98,6 +98,18 @@ table.foo = 500 delete script; } +TEST_CASE( "Dynamic numerical table size", "[integration]" ) { + Script* script = Script::Create( + R"( +table = {} +table[1] = 500 +return table[1] +)"); + REQUIRE(!script->Diagnostics -> HasErrors()); + auto result = script->Evaluate(); + CHECK(result -> EvaluateInteger() == 500); + delete script; +} #endif