Fixes and improvements for new table system
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-09-19 11:28:00 +02:00
parent 6c6d977000
commit 24923deed0
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 16 additions and 5 deletions

View File

@ -53,7 +53,7 @@ namespace Porygon::Evaluation {
[[nodiscard]] [[nodiscard]]
inline EvalValue* IndexValue(const EvalValue *val) const final { 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(); return this->_table->at(Utilities::HashedString::CreateLookup(stringKey))->Clone();
} }

View File

@ -407,8 +407,7 @@ namespace Porygon::Evaluation {
auto values = new map<Utilities::HashedString, EvalValuePointer>(); auto values = new map<Utilities::HashedString, EvalValuePointer>();
for (size_t i = 0; i < valueExpressions->size(); i++) { for (size_t i = 0; i < valueExpressions->size(); i++) {
auto val = this->EvaluateExpression(valueExpressions->at(i)); auto val = this->EvaluateExpression(valueExpressions->at(i));
auto k = Utilities::StringUtils::IntToString(i + 1); auto s = Utilities::HashedString::CreateLookup(i + 1);
auto s = Utilities::HashedString(new u16string(k));
values->insert({s, val}); values->insert({s, val});
} }
auto valuesPointer = shared_ptr<map<Utilities::HashedString, EvalValuePointer>>(values); auto valuesPointer = shared_ptr<map<Utilities::HashedString, EvalValuePointer>>(values);

View File

@ -1,6 +1,6 @@
#include "NumericalKeyIterator.hpp" #include "NumericalKeyIterator.hpp"
const Porygon::Evaluation::EvalValue *Porygon::Evaluation::NumericalKeyIterator::GetCurrent() { const Porygon::Evaluation::EvalValue *Porygon::Evaluation::NumericalKeyIterator::GetCurrent() {
auto s = *_iterator->first.GetString(); auto s = _iterator->first.GetHash();
return new NumericEvalValue(Utilities::StringUtils::ParseInteger(s)); return new NumericEvalValue(static_cast<int64_t >(s));
} }

View File

@ -98,6 +98,18 @@ table.foo = 500
delete script; 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 #endif