Implements basic numerical tables
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-09 20:15:09 +02:00
parent ec2419bc7d
commit 081def0be0
21 changed files with 324 additions and 24 deletions

View File

@@ -9,11 +9,13 @@ using namespace std;
class StringEvalValue : public EvalValue{
string _value;
size_t _hash;
std::shared_ptr<ScriptType> _type;
public:
explicit StringEvalValue(string s){
_value = move(s);
_type = std::make_shared<ScriptType>(TypeClass::String);
_hash = std::hash<string>{}(_value);
}
std::shared_ptr<ScriptType> GetType() final{
@@ -22,7 +24,7 @@ public:
bool operator ==(EvalValue* b) final{
if (b->GetType()->GetClass() != TypeClass::String)
return false;
return this->_value == *b->EvaluateString();
return this->_hash == b->GetHashCode();
};
string* EvaluateString() final{
@@ -33,10 +35,14 @@ public:
return make_shared<StringEvalValue>(_value);
}
EvalValue* IndexValue(EvalValue* val) final{
shared_ptr<EvalValue> IndexValue(EvalValue* val) final{
// Porygon is 1-indexed, so we convert to that.
auto l = val->EvaluateInteger() - 1;
return new StringEvalValue(string(1, _value[l]));
return make_shared<StringEvalValue>(string(1, _value[l]));
}
std::size_t GetHashCode() final{
return _hash;
}
};