Work on performance improvements
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -5,11 +5,7 @@
|
||||
|
||||
extern "C" {
|
||||
TypeClass GetEvalValueTypeClass(EvalValue* v){
|
||||
return v->GetType().get()->GetClass();
|
||||
}
|
||||
|
||||
ScriptType* GetEvalValueType(EvalValue* v){
|
||||
return v->GetType().get();
|
||||
return v->GetTypeClass();
|
||||
}
|
||||
|
||||
int64_t EvaluateEvalValueInteger(EvalValue* v){
|
||||
|
||||
@@ -12,7 +12,7 @@ class EvalValue{
|
||||
public:
|
||||
EvalValue() = default;
|
||||
virtual ~EvalValue() = default;
|
||||
virtual std::shared_ptr<ScriptType> GetType() = 0;
|
||||
virtual const TypeClass GetTypeClass() = 0;
|
||||
|
||||
virtual bool operator ==(EvalValue* b) = 0;
|
||||
|
||||
@@ -43,28 +43,27 @@ public:
|
||||
};
|
||||
|
||||
class BooleanEvalValue : public EvalValue{
|
||||
bool _value;
|
||||
std::shared_ptr<ScriptType> _type;
|
||||
const bool _value;
|
||||
public:
|
||||
explicit BooleanEvalValue(bool val){
|
||||
_value = val;
|
||||
_type = std::make_shared<ScriptType>(TypeClass::Bool);
|
||||
explicit BooleanEvalValue(bool val)
|
||||
: _value(val)
|
||||
{
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Clone() final{
|
||||
return make_shared<BooleanEvalValue>(_value);
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> GetType() final{
|
||||
return _type;
|
||||
};
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::Bool;
|
||||
}
|
||||
|
||||
bool EvaluateBool() final{
|
||||
return _value;
|
||||
}
|
||||
|
||||
bool operator ==(EvalValue* b) final{
|
||||
if (b->GetType()->GetClass() != TypeClass::Bool)
|
||||
if (b->GetTypeClass() != TypeClass::Bool)
|
||||
return false;
|
||||
return this->EvaluateBool() == b->EvaluateBool();
|
||||
};
|
||||
|
||||
@@ -66,7 +66,7 @@ NumericEvalValue *NumericEvalValue::operator/(NumericEvalValue *b) {
|
||||
}
|
||||
|
||||
bool NumericEvalValue::operator==(EvalValue *b) {
|
||||
if (b->GetType()->GetClass() != TypeClass::Number)
|
||||
if (b->GetTypeClass() != TypeClass::Number)
|
||||
return false;
|
||||
auto numVal = (NumericEvalValue*)b;
|
||||
if (this->IsFloat() != numVal->IsFloat())
|
||||
|
||||
@@ -10,12 +10,11 @@ class NumericEvalValue : public EvalValue{
|
||||
virtual long GetIntegerValue() = 0;
|
||||
virtual double GetFloatValue() = 0;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ScriptType> _type;
|
||||
public:
|
||||
virtual const bool IsFloat() = 0;
|
||||
std::shared_ptr<ScriptType> GetType() override {
|
||||
return _type;
|
||||
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::Number;
|
||||
}
|
||||
|
||||
NumericEvalValue* operator +(NumericEvalValue* b);
|
||||
@@ -35,7 +34,6 @@ class IntegerEvalValue : public NumericEvalValue{
|
||||
double GetFloatValue() final{ throw EvaluationException("Attempting to retrieve float from int eval value."); }
|
||||
public:
|
||||
explicit IntegerEvalValue(long value){
|
||||
_type = std::make_shared<NumericScriptType>(true, false);
|
||||
_value = value;
|
||||
}
|
||||
const bool IsFloat() final{
|
||||
@@ -61,7 +59,6 @@ class FloatEvalValue : public NumericEvalValue{
|
||||
double GetFloatValue() final{return _value;}
|
||||
public:
|
||||
explicit FloatEvalValue(double value){
|
||||
_type = std::make_shared<NumericScriptType>(true, true);
|
||||
_value = value;
|
||||
}
|
||||
const bool IsFloat() final{
|
||||
|
||||
@@ -38,17 +38,21 @@ public:
|
||||
_hash = rand();
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> GetType() final{
|
||||
std::shared_ptr<ScriptType> GetType(){
|
||||
return _type;
|
||||
}
|
||||
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::Function;
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Clone() final{
|
||||
return shared_ptr<ScriptFunctionEvalValue>(new ScriptFunctionEvalValue(_innerBlock, _scope, _type, _hash));
|
||||
}
|
||||
|
||||
|
||||
bool operator ==(EvalValue* b) final{
|
||||
if (b->GetType()->GetClass() != TypeClass::Function)
|
||||
if (b->GetTypeClass() != TypeClass::Function)
|
||||
return false;
|
||||
return this->_hash == ((ScriptFunctionEvalValue*)b)->_hash;
|
||||
};
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
#include "StringEvalValue.hpp"
|
||||
@@ -11,19 +11,18 @@ 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);
|
||||
_hash = HashedString::ConstHash (_value.c_str());
|
||||
_type = std::make_shared<StringScriptType>(true, _hash);
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> GetType() final{
|
||||
return _type;
|
||||
};
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::String;
|
||||
}
|
||||
|
||||
bool operator ==(EvalValue* b) final{
|
||||
if (b->GetType()->GetClass() != TypeClass::String)
|
||||
if (b->GetTypeClass() != TypeClass::String)
|
||||
return false;
|
||||
return this->_hash == b->GetHashCode();
|
||||
};
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
#include "TableEvalValue.hpp"
|
||||
@@ -8,23 +8,20 @@ using namespace std;
|
||||
|
||||
class TableEvalValue : public EvalValue {
|
||||
shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> _table;
|
||||
shared_ptr<ScriptType> _type;
|
||||
size_t _hash;
|
||||
|
||||
explicit TableEvalValue(shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> table, shared_ptr<ScriptType> type, size_t hash){
|
||||
explicit TableEvalValue(shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> table, size_t hash){
|
||||
_table = std::move(table);
|
||||
_type = std::move(type);
|
||||
_hash = hash;
|
||||
}
|
||||
public:
|
||||
explicit TableEvalValue(shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> table, shared_ptr<ScriptType> type){
|
||||
explicit TableEvalValue(shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> table){
|
||||
_table = std::move(table);
|
||||
_type = std::move(type);
|
||||
_hash = rand();
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> GetType() final{
|
||||
return _type;
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::Table;
|
||||
}
|
||||
|
||||
size_t GetHashCode() final{
|
||||
@@ -36,7 +33,7 @@ public:
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Clone() final{
|
||||
return shared_ptr<EvalValue>(new TableEvalValue(_table, _type, _hash));
|
||||
return shared_ptr<EvalValue>(new TableEvalValue(_table, _hash));
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> IndexValue(EvalValue* val) final{
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include "EvaluationScope.hpp"
|
||||
#include <memory>
|
||||
|
||||
EvaluationScope::EvaluationScope(unordered_map<size_t, shared_ptr<EvalValue>> *scriptVariables, int deepestScope) {
|
||||
EvaluationScope::EvaluationScope(unordered_map<size_t, shared_ptr<EvalValue>> *scriptVariables, int localVariableCount) {
|
||||
_scriptScope = scriptVariables;
|
||||
_localScope = unordered_map<uint64_t, shared_ptr<EvalValue>>(deepestScope);
|
||||
_localScope = unordered_map<uint64_t, shared_ptr<EvalValue>>(localVariableCount);
|
||||
}
|
||||
|
||||
void EvaluationScope::CreateVariable(BoundVariableKey* key, const shared_ptr<EvalValue> &value) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <memory>
|
||||
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include "Evaluator.hpp"
|
||||
@@ -12,7 +14,7 @@
|
||||
using namespace std;
|
||||
|
||||
EvalValue* Evaluator::Evaluate(BoundScriptStatement *statement) {
|
||||
this->_evaluationScope = make_shared<EvaluationScope>(this->_scriptData->_scriptVariables, statement->GetDeepestScope());
|
||||
this->_evaluationScope = make_shared<EvaluationScope>(this->_scriptData->_scriptVariables, statement->GetLocalVariableCount());
|
||||
EvaluateBlockStatement(statement, false);
|
||||
return this -> _returnValue.get();
|
||||
}
|
||||
@@ -223,10 +225,6 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunctionCallExpression(BoundExpression*
|
||||
|
||||
for (int i = 0; i < parameterTypes.size() && i < parameterKeys.size() && i < parameters.size(); i++){
|
||||
auto parameter = parameters[i];
|
||||
auto requiredType = parameterTypes.at(i);
|
||||
if (*parameter->GetType() != requiredType.get()){
|
||||
throw EvaluationException("Passed wrong type to function.");
|
||||
}
|
||||
auto key = parameterKeys.at(i);
|
||||
this->_evaluationScope->CreateVariable(key.get(), parameter->Clone());
|
||||
}
|
||||
@@ -249,10 +247,6 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunction(ScriptFunctionEvalValue *funct
|
||||
|
||||
for (int i = 0; i < parameterTypes.size() && i < parameterKeys.size() && i < parameters.size(); i++){
|
||||
auto parameter = parameters[i];
|
||||
auto requiredType = parameterTypes.at(i);
|
||||
if (*parameter->GetType() != requiredType.get()){
|
||||
throw EvaluationException("Passed wrong type to function.");
|
||||
}
|
||||
auto key = parameterKeys.at(i);
|
||||
this->_evaluationScope->CreateVariable(key.get(), parameter->Clone());
|
||||
}
|
||||
@@ -280,7 +274,7 @@ shared_ptr<EvalValue> Evaluator::EvaluateNumericTableExpression(BoundExpression
|
||||
values -> insert({i + 1, val});
|
||||
}
|
||||
auto valuesPointer = shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>>(values);
|
||||
return make_shared<TableEvalValue>(valuesPointer, tableExpression->GetType());
|
||||
return make_shared<TableEvalValue>(valuesPointer);
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Evaluator::EvaluateComplexTableExpression(BoundExpression *expression) {
|
||||
@@ -291,10 +285,10 @@ shared_ptr<EvalValue> Evaluator::EvaluateComplexTableExpression(BoundExpression
|
||||
for (auto i : *declaredVars){
|
||||
variables->insert({i.first, nullptr});
|
||||
}
|
||||
auto evaluator = make_shared<EvaluationScope>(variables.get(), type -> GetDeepestScope());
|
||||
auto evaluator = make_shared<EvaluationScope>(variables.get(), type -> GetLocalVariableCount());
|
||||
auto currentEvaluator = this -> _evaluationScope;
|
||||
this -> _evaluationScope = evaluator;
|
||||
this -> EvaluateBlockStatement(tableExpression->GetBlock(), false);
|
||||
this -> _evaluationScope = currentEvaluator;
|
||||
return shared_ptr<TableEvalValue>(new TableEvalValue(variables, tableExpression->GetType()));
|
||||
return make_shared<TableEvalValue>(variables);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user