Added namespaces to most classes, general cleanup
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2019-06-17 18:35:12 +02:00
parent 21d3329c55
commit fde102d954
66 changed files with 4301 additions and 3909 deletions

View File

@@ -3,42 +3,45 @@
#include "StringEvalValue.hpp"
#include <cstring>
extern "C" {
TypeClass GetEvalValueTypeClass(EvalValue* v){
namespace Porygon::Evaluation {
extern "C" {
Porygon::TypeClass GetEvalValueTypeClass(EvalValue *v) {
return v->GetTypeClass();
}
int64_t EvaluateEvalValueInteger(EvalValue* v){
int64_t EvaluateEvalValueInteger(EvalValue *v) {
return v->EvaluateInteger();
}
double EvaluateEvalValueFloat(EvalValue* v){
double EvaluateEvalValueFloat(EvalValue *v) {
return v->EvaluateFloat();
}
bool EvaluateEvalValueBool(EvalValue* v){
bool EvaluateEvalValueBool(EvalValue *v) {
return v->EvaluateBool();
}
const char16_t * EvaluateEvalValueString(EvalValue* v){
return v->EvaluateString() -> c_str();
const char16_t *EvaluateEvalValueString(EvalValue *v) {
return v->EvaluateString()->c_str();
}
EvalValue* CreateIntegerEvalValue(long l){
EvalValue *CreateIntegerEvalValue(long l) {
return new IntegerEvalValue(l);
}
EvalValue* CreateFloatEvalValue(double d){
EvalValue *CreateFloatEvalValue(double d) {
return new FloatEvalValue(d);
}
EvalValue* CreateBoolEvalValue(bool b){
EvalValue *CreateBoolEvalValue(bool b) {
return new BooleanEvalValue(b);
}
EvalValue* CreateStringEvalValue(const char16_t * s){
EvalValue *CreateStringEvalValue(const char16_t *s) {
return new StringEvalValue(s);
}
}
}
#ifdef TESTS_BUILD
@@ -47,7 +50,7 @@ extern "C" {
TEST_CASE( "Evaluate String", "[integration]" ) {
auto script = Script::Create(u"\"foo bar\"");
auto script = Porygon::Script::Create(u"\"foo bar\"");
REQUIRE(!script->Diagnostics -> HasErrors());
script->Evaluate();
auto lastValue = script->GetLastValue();

View File

@@ -8,77 +8,83 @@
#include <sstream>
#include <memory>
class EvalValue{
public:
EvalValue() = default;
virtual ~EvalValue() = default;
virtual const TypeClass GetTypeClass() const = 0;
namespace Porygon::Evaluation {
class EvalValue {
public:
EvalValue() = default;
virtual const bool operator ==(EvalValue* b) const = 0;
virtual ~EvalValue() = default;
virtual const bool operator !=(EvalValue*b) const{
return ! (this->operator==(b));
}
virtual const TypeClass GetTypeClass() const = 0;
virtual const shared_ptr<EvalValue> Clone() const = 0;
virtual const bool operator==(EvalValue *b) const = 0;
virtual const long EvaluateInteger() const{
throw EvaluationException("Can't evaluate this EvalValue as integer.");
}
virtual const double EvaluateFloat() const{
throw EvaluationException("Can't evaluate this EvalValue as float.");
}
virtual const bool EvaluateBool() const{
throw EvaluationException("Can't evaluate this EvalValue as bool.");
}
virtual const std::u16string* EvaluateString() const {
throw EvaluationException("Can't evaluate this EvalValue as string.");
}
virtual const bool operator!=(EvalValue *b) const {
return !(this->operator==(b));
}
virtual const std::size_t GetHashCode() const = 0;
virtual const shared_ptr<EvalValue> Clone() const = 0;
virtual const shared_ptr<EvalValue> IndexValue(EvalValue* val) const{
throw EvaluationException("Can't index this EvalValue");
}
virtual const long EvaluateInteger() const {
throw EvaluationException("Can't evaluate this EvalValue as integer.");
}
virtual const shared_ptr<EvalValue> IndexValue(uint32_t hash) const{
throw EvaluationException("Can't index this EvalValue");
}
virtual const double EvaluateFloat() const {
throw EvaluationException("Can't evaluate this EvalValue as float.");
}
virtual void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue>& value) const{
throw EvaluationException("Can't index this EvalValue");
}
};
virtual const bool EvaluateBool() const {
throw EvaluationException("Can't evaluate this EvalValue as bool.");
}
class BooleanEvalValue : public EvalValue{
const bool _value;
public:
explicit BooleanEvalValue(bool val)
: _value(val)
{
}
virtual const std::u16string *EvaluateString() const {
throw EvaluationException("Can't evaluate this EvalValue as string.");
}
const shared_ptr<EvalValue> Clone() const final{
return make_shared<BooleanEvalValue>(_value);
}
virtual const std::size_t GetHashCode() const = 0;
const TypeClass GetTypeClass() const final{
return TypeClass ::Bool;
}
virtual const shared_ptr<EvalValue> IndexValue(EvalValue *val) const {
throw EvaluationException("Can't index this EvalValue");
}
const bool EvaluateBool() const final{
return _value;
}
virtual const shared_ptr<EvalValue> IndexValue(uint32_t hash) const {
throw EvaluationException("Can't index this EvalValue");
}
const bool operator ==(EvalValue* b) const final{
if (b->GetTypeClass() != TypeClass::Bool)
return false;
return this->EvaluateBool() == b->EvaluateBool();
virtual void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const {
throw EvaluationException("Can't index this EvalValue");
}
};
const std::size_t GetHashCode() const final{
return _value;
}
};
class BooleanEvalValue : public EvalValue {
const bool _value;
public:
explicit BooleanEvalValue(bool val)
: _value(val) {
}
const shared_ptr<EvalValue> Clone() const final {
return make_shared<BooleanEvalValue>(_value);
}
const TypeClass GetTypeClass() const final {
return TypeClass::Bool;
}
const bool EvaluateBool() const final {
return _value;
}
const bool operator==(EvalValue *b) const final {
if (b->GetTypeClass() != TypeClass::Bool)
return false;
return this->EvaluateBool() == b->EvaluateBool();
};
const std::size_t GetHashCode() const final {
return _value;
}
};
}
#endif //PORYGONLANG_EVALVALUE_HPP

View File

@@ -1,144 +1,146 @@
#include "NumericEvalValue.hpp"
const shared_ptr<NumericEvalValue> NumericEvalValue::operator+(const shared_ptr<NumericEvalValue>& b) const {
if (this->IsFloat()){
if (b->IsFloat()){
return make_shared<FloatEvalValue>(this->GetFloatValue() + b->GetFloatValue());
} else{
return make_shared<FloatEvalValue>(this->GetFloatValue() + b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return make_shared<FloatEvalValue>(this->GetIntegerValue() + b->GetFloatValue());
} else{
return make_shared<IntegerEvalValue>(this->GetIntegerValue() + b->GetIntegerValue());
namespace Porygon::Evaluation {
const shared_ptr<NumericEvalValue> NumericEvalValue::operator+(const shared_ptr<NumericEvalValue> &b) const {
if (this->IsFloat()) {
if (b->IsFloat()) {
return make_shared<FloatEvalValue>(this->GetFloatValue() + b->GetFloatValue());
} else {
return make_shared<FloatEvalValue>(this->GetFloatValue() + b->GetIntegerValue());
}
} else {
if (b->IsFloat()) {
return make_shared<FloatEvalValue>(this->GetIntegerValue() + b->GetFloatValue());
} else {
return make_shared<IntegerEvalValue>(this->GetIntegerValue() + b->GetIntegerValue());
}
}
}
}
const shared_ptr<NumericEvalValue> NumericEvalValue::operator-(const shared_ptr<NumericEvalValue>& b) const {
if (this->IsFloat()){
if (b->IsFloat()){
return make_shared<FloatEvalValue>(this->GetFloatValue() - b->GetFloatValue());
} else{
return make_shared<FloatEvalValue>(this->GetFloatValue() - b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return make_shared<FloatEvalValue>(this->GetIntegerValue() - b->GetFloatValue());
} else{
return make_shared<IntegerEvalValue>(this->GetIntegerValue() - b->GetIntegerValue());
const shared_ptr<NumericEvalValue> NumericEvalValue::operator-(const shared_ptr<NumericEvalValue> &b) const {
if (this->IsFloat()) {
if (b->IsFloat()) {
return make_shared<FloatEvalValue>(this->GetFloatValue() - b->GetFloatValue());
} else {
return make_shared<FloatEvalValue>(this->GetFloatValue() - b->GetIntegerValue());
}
} else {
if (b->IsFloat()) {
return make_shared<FloatEvalValue>(this->GetIntegerValue() - b->GetFloatValue());
} else {
return make_shared<IntegerEvalValue>(this->GetIntegerValue() - b->GetIntegerValue());
}
}
}
}
const shared_ptr<NumericEvalValue> NumericEvalValue::operator*(const shared_ptr<NumericEvalValue>& b) const {
if (this->IsFloat()){
if (b->IsFloat()){
return make_shared<FloatEvalValue>(this->GetFloatValue() * b->GetFloatValue());
} else{
return make_shared<FloatEvalValue>(this->GetFloatValue() * b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return make_shared<FloatEvalValue>(this->GetIntegerValue() * b->GetFloatValue());
} else{
return make_shared<IntegerEvalValue>(this->GetIntegerValue() * b->GetIntegerValue());
const shared_ptr<NumericEvalValue> NumericEvalValue::operator*(const shared_ptr<NumericEvalValue> &b) const {
if (this->IsFloat()) {
if (b->IsFloat()) {
return make_shared<FloatEvalValue>(this->GetFloatValue() * b->GetFloatValue());
} else {
return make_shared<FloatEvalValue>(this->GetFloatValue() * b->GetIntegerValue());
}
} else {
if (b->IsFloat()) {
return make_shared<FloatEvalValue>(this->GetIntegerValue() * b->GetFloatValue());
} else {
return make_shared<IntegerEvalValue>(this->GetIntegerValue() * b->GetIntegerValue());
}
}
}
}
const shared_ptr<NumericEvalValue> NumericEvalValue::operator/(const shared_ptr<NumericEvalValue>& b) const {
if (this->IsFloat()){
if (b->IsFloat()){
return make_shared<FloatEvalValue>(this->GetFloatValue() / b->GetFloatValue());
} else{
return make_shared<FloatEvalValue>(this->GetFloatValue() / b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return make_shared<FloatEvalValue>(this->GetIntegerValue() / b->GetFloatValue());
} else{
return make_shared<IntegerEvalValue>(this->GetIntegerValue() / b->GetIntegerValue());
const shared_ptr<NumericEvalValue> NumericEvalValue::operator/(const shared_ptr<NumericEvalValue> &b) const {
if (this->IsFloat()) {
if (b->IsFloat()) {
return make_shared<FloatEvalValue>(this->GetFloatValue() / b->GetFloatValue());
} else {
return make_shared<FloatEvalValue>(this->GetFloatValue() / b->GetIntegerValue());
}
} else {
if (b->IsFloat()) {
return make_shared<FloatEvalValue>(this->GetIntegerValue() / b->GetFloatValue());
} else {
return make_shared<IntegerEvalValue>(this->GetIntegerValue() / b->GetIntegerValue());
}
}
}
}
const bool NumericEvalValue::operator==(EvalValue *b) const {
if (b->GetTypeClass() != TypeClass::Number)
return false;
auto numVal = (NumericEvalValue*)b;
if (this->IsFloat() != numVal->IsFloat())
return false;
const bool NumericEvalValue::operator==(EvalValue *b) const {
if (b->GetTypeClass() != TypeClass::Number)
return false;
auto numVal = (NumericEvalValue *) b;
if (this->IsFloat() != numVal->IsFloat())
return false;
if (this->IsFloat()){
return this->EvaluateFloat() == numVal->EvaluateFloat();
} else{
return this->EvaluateInteger() == numVal->EvaluateInteger();
}
}
const shared_ptr<BooleanEvalValue> NumericEvalValue::operator<(const shared_ptr<NumericEvalValue>& b) const {
if (this->IsFloat()){
if (b->IsFloat()){
return make_shared<BooleanEvalValue>(this->GetFloatValue() < b->GetFloatValue());
} else{
return make_shared<BooleanEvalValue>(this->GetFloatValue() < b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return make_shared<BooleanEvalValue>(this->GetIntegerValue() < b->GetFloatValue());
} else{
return make_shared<BooleanEvalValue>(this->GetIntegerValue() < b->GetIntegerValue());
if (this->IsFloat()) {
return this->EvaluateFloat() == numVal->EvaluateFloat();
} else {
return this->EvaluateInteger() == numVal->EvaluateInteger();
}
}
}
const shared_ptr<BooleanEvalValue> NumericEvalValue::operator<=(const shared_ptr<NumericEvalValue>& b) const {
if (this->IsFloat()){
if (b->IsFloat()){
return make_shared<BooleanEvalValue>(this->GetFloatValue() <= b->GetFloatValue());
} else{
return make_shared<BooleanEvalValue>(this->GetFloatValue() <= b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return make_shared<BooleanEvalValue>(this->GetIntegerValue() <= b->GetFloatValue());
} else{
return make_shared<BooleanEvalValue>(this->GetIntegerValue() <= b->GetIntegerValue());
const shared_ptr<BooleanEvalValue> NumericEvalValue::operator<(const shared_ptr<NumericEvalValue> &b) const {
if (this->IsFloat()) {
if (b->IsFloat()) {
return make_shared<BooleanEvalValue>(this->GetFloatValue() < b->GetFloatValue());
} else {
return make_shared<BooleanEvalValue>(this->GetFloatValue() < b->GetIntegerValue());
}
} else {
if (b->IsFloat()) {
return make_shared<BooleanEvalValue>(this->GetIntegerValue() < b->GetFloatValue());
} else {
return make_shared<BooleanEvalValue>(this->GetIntegerValue() < b->GetIntegerValue());
}
}
}
}
const shared_ptr<BooleanEvalValue> NumericEvalValue::operator>(const shared_ptr<NumericEvalValue>& b) const {
if (this->IsFloat()){
if (b->IsFloat()){
return make_shared<BooleanEvalValue>(this->GetFloatValue() > b->GetFloatValue());
} else{
return make_shared<BooleanEvalValue>(this->GetFloatValue() > b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return make_shared<BooleanEvalValue>(this->GetIntegerValue() > b->GetFloatValue());
} else{
return make_shared<BooleanEvalValue>(this->GetIntegerValue() > b->GetIntegerValue());
const shared_ptr<BooleanEvalValue> NumericEvalValue::operator<=(const shared_ptr<NumericEvalValue> &b) const {
if (this->IsFloat()) {
if (b->IsFloat()) {
return make_shared<BooleanEvalValue>(this->GetFloatValue() <= b->GetFloatValue());
} else {
return make_shared<BooleanEvalValue>(this->GetFloatValue() <= b->GetIntegerValue());
}
} else {
if (b->IsFloat()) {
return make_shared<BooleanEvalValue>(this->GetIntegerValue() <= b->GetFloatValue());
} else {
return make_shared<BooleanEvalValue>(this->GetIntegerValue() <= b->GetIntegerValue());
}
}
}
}
const shared_ptr<BooleanEvalValue> NumericEvalValue::operator>=(const shared_ptr<NumericEvalValue>& b) const {
if (this->IsFloat()){
if (b->IsFloat()){
return make_shared<BooleanEvalValue>(this->GetFloatValue() >= b->GetFloatValue());
} else{
return make_shared<BooleanEvalValue>(this->GetFloatValue() >= b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return make_shared<BooleanEvalValue>(this->GetIntegerValue() >= b->GetFloatValue());
} else{
return make_shared<BooleanEvalValue>(this->GetIntegerValue() >= b->GetIntegerValue());
const shared_ptr<BooleanEvalValue> NumericEvalValue::operator>(const shared_ptr<NumericEvalValue> &b) const {
if (this->IsFloat()) {
if (b->IsFloat()) {
return make_shared<BooleanEvalValue>(this->GetFloatValue() > b->GetFloatValue());
} else {
return make_shared<BooleanEvalValue>(this->GetFloatValue() > b->GetIntegerValue());
}
} else {
if (b->IsFloat()) {
return make_shared<BooleanEvalValue>(this->GetIntegerValue() > b->GetFloatValue());
} else {
return make_shared<BooleanEvalValue>(this->GetIntegerValue() > b->GetIntegerValue());
}
}
}
}
const shared_ptr<BooleanEvalValue> NumericEvalValue::operator>=(const shared_ptr<NumericEvalValue> &b) const {
if (this->IsFloat()) {
if (b->IsFloat()) {
return make_shared<BooleanEvalValue>(this->GetFloatValue() >= b->GetFloatValue());
} else {
return make_shared<BooleanEvalValue>(this->GetFloatValue() >= b->GetIntegerValue());
}
} else {
if (b->IsFloat()) {
return make_shared<BooleanEvalValue>(this->GetIntegerValue() >= b->GetFloatValue());
} else {
return make_shared<BooleanEvalValue>(this->GetIntegerValue() >= b->GetIntegerValue());
}
}
}
}

View File

@@ -4,76 +4,98 @@
#include <sstream>
#include "EvalValue.hpp"
namespace Porygon::Evaluation {
class NumericEvalValue : public EvalValue {
class NumericEvalValue : public EvalValue{
virtual const long GetIntegerValue() const = 0;
virtual const long GetIntegerValue() const = 0;
virtual const double GetFloatValue() const = 0;
virtual const double GetFloatValue() const = 0;
public:
virtual const bool IsFloat() const = 0;
public:
virtual const bool IsFloat() const = 0;
const TypeClass GetTypeClass() const final{
return TypeClass ::Number;
}
const TypeClass GetTypeClass() const final {
return TypeClass::Number;
}
const shared_ptr<NumericEvalValue> operator +(const shared_ptr<NumericEvalValue>& b) const;
const shared_ptr<NumericEvalValue> operator -(const shared_ptr<NumericEvalValue>& b) const ;
const shared_ptr<NumericEvalValue> operator *(const shared_ptr<NumericEvalValue>& b) const ;
const shared_ptr<NumericEvalValue> operator /(const shared_ptr<NumericEvalValue>& b) const ;
const shared_ptr<BooleanEvalValue> operator <(const shared_ptr<NumericEvalValue>& b) const ;
const shared_ptr<BooleanEvalValue> operator <=(const shared_ptr<NumericEvalValue>& b)const ;
const shared_ptr<BooleanEvalValue> operator >(const shared_ptr<NumericEvalValue>& b) const ;
const shared_ptr<BooleanEvalValue> operator >=(const shared_ptr<NumericEvalValue>& b) const ;
const bool operator ==(EvalValue* b) const final;
};
const shared_ptr<NumericEvalValue> operator+(const shared_ptr<NumericEvalValue> &b) const;
class IntegerEvalValue : public NumericEvalValue{
const long _value;
const long GetIntegerValue() const final{return _value;}
const double GetFloatValue() const final{ throw EvaluationException("Attempting to retrieve float from int eval value."); }
public:
explicit IntegerEvalValue(long value) :_value(value){
}
const bool IsFloat() const final{
return false;
}
const shared_ptr<NumericEvalValue> operator-(const shared_ptr<NumericEvalValue> &b) const;
const long EvaluateInteger() const final{
return _value;
}
const shared_ptr<NumericEvalValue> operator*(const shared_ptr<NumericEvalValue> &b) const;
const shared_ptr<EvalValue> Clone() const final{
return make_shared<IntegerEvalValue>(_value);
}
const shared_ptr<NumericEvalValue> operator/(const shared_ptr<NumericEvalValue> &b) const;
const std::size_t GetHashCode() const final{
return std::hash<long>{}(_value);
}
};
const shared_ptr<BooleanEvalValue> operator<(const shared_ptr<NumericEvalValue> &b) const;
class FloatEvalValue : public NumericEvalValue{
const double _value;
const long GetIntegerValue() const final{ throw EvaluationException("Attempting to retrieve float from int eval value."); }
const double GetFloatValue() const final{return _value;}
public:
explicit FloatEvalValue(double value) :_value(value){
}
const bool IsFloat() const final{
return true;
}
const shared_ptr<BooleanEvalValue> operator<=(const shared_ptr<NumericEvalValue> &b) const;
const double EvaluateFloat() const final{
return _value;
}
const shared_ptr<BooleanEvalValue> operator>(const shared_ptr<NumericEvalValue> &b) const;
const shared_ptr<EvalValue> Clone() const final{
return make_shared<FloatEvalValue>(_value);
}
const shared_ptr<BooleanEvalValue> operator>=(const shared_ptr<NumericEvalValue> &b) const;
const std::size_t GetHashCode() const final{
return std::hash<double >{}(_value);
}
};
const bool operator==(EvalValue *b) const final;
};
class IntegerEvalValue : public NumericEvalValue {
const long _value;
const long GetIntegerValue() const final { return _value; }
const double GetFloatValue() const final {
throw EvaluationException("Attempting to retrieve float from int eval value.");
}
public:
explicit IntegerEvalValue(long value) : _value(value) {
}
const bool IsFloat() const final {
return false;
}
const long EvaluateInteger() const final {
return _value;
}
const shared_ptr<EvalValue> Clone() const final {
return make_shared<IntegerEvalValue>(_value);
}
const std::size_t GetHashCode() const final {
return std::hash<long>{}(_value);
}
};
class FloatEvalValue : public NumericEvalValue {
const double _value;
const long GetIntegerValue() const final {
throw EvaluationException("Attempting to retrieve float from int eval value.");
}
const double GetFloatValue() const final { return _value; }
public:
explicit FloatEvalValue(double value) : _value(value) {
}
const bool IsFloat() const final {
return true;
}
const double EvaluateFloat() const final {
return _value;
}
const shared_ptr<EvalValue> Clone() const final {
return make_shared<FloatEvalValue>(_value);
}
const std::size_t GetHashCode() const final {
return std::hash<double>{}(_value);
}
};
}
#endif //PORYGONLANG_NUMERICEVALVALUE_HPP

View File

@@ -11,63 +11,65 @@
#include "../Evaluator.hpp"
#include "../EvaluationScope/EvaluationScope.hpp"
namespace Porygon::Evaluation {
class ScriptFunctionEvalValue : public EvalValue {
const std::shared_ptr<BoundBlockStatement> _innerBlock;
const std::shared_ptr<FunctionScriptType> _type;
const std::shared_ptr<EvaluationScope> _scope;
const std::size_t _hash;
class ScriptFunctionEvalValue : public EvalValue{
const std::shared_ptr<BoundBlockStatement> _innerBlock;
const std::shared_ptr<FunctionScriptType> _type;
const std::shared_ptr<EvaluationScope> _scope;
const std::size_t _hash;
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock, std::shared_ptr<EvaluationScope> scope,
std::shared_ptr<FunctionScriptType> type, size_t hash)
: _type(std::move(type)),
_innerBlock(std::move(innerBlock)),
_scope(std::move(scope)),
_hash(hash)
{
}
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock,
std::shared_ptr<EvaluationScope> scope,
std::shared_ptr<FunctionScriptType> type, size_t hash)
: _type(std::move(type)),
_innerBlock(std::move(innerBlock)),
_scope(std::move(scope)),
_hash(hash) {
}
public:
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock, std::shared_ptr<EvaluationScope> scope,
std::shared_ptr<FunctionScriptType> type)
: _type(std::move(type)),
_innerBlock(std::move(innerBlock)),
_scope(std::move(scope)),
_hash(rand())
{
}
public:
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock,
std::shared_ptr<EvaluationScope> scope,
std::shared_ptr<FunctionScriptType> type)
: _type(std::move(type)),
_innerBlock(std::move(innerBlock)),
_scope(std::move(scope)),
_hash(rand()) {
}
const std::shared_ptr<ScriptType> GetType() const{
return _type;
}
const std::shared_ptr<ScriptType> GetType() const {
return _type;
}
const TypeClass GetTypeClass() const final{
return TypeClass ::Function;
}
const TypeClass GetTypeClass() const final {
return TypeClass::Function;
}
const shared_ptr<EvalValue> Clone() const final{
// We don't run make_shared here as it can't call private constructors
return shared_ptr<ScriptFunctionEvalValue>(new ScriptFunctionEvalValue(_innerBlock, _scope, _type, _hash));
}
const shared_ptr<EvalValue> Clone() const final {
// We don't run make_shared here as it can't call private constructors
return shared_ptr<ScriptFunctionEvalValue>(new ScriptFunctionEvalValue(_innerBlock, _scope, _type, _hash));
}
const bool operator ==(EvalValue* b) const final{
if (b->GetTypeClass() != TypeClass::Function)
return false;
return this->_hash == ((ScriptFunctionEvalValue*)b)->_hash;
const bool operator==(EvalValue *b) const final {
if (b->GetTypeClass() != TypeClass::Function)
return false;
return this->_hash == ((ScriptFunctionEvalValue *) b)->_hash;
};
const std::shared_ptr<BoundBlockStatement> &GetInnerBlock() const {
return _innerBlock;
}
const std::size_t GetHashCode() const final {
return _hash;
}
const std::shared_ptr<EvaluationScope> &GetScope() const {
return _scope;
}
};
const std::shared_ptr<BoundBlockStatement>& GetInnerBlock() const{
return _innerBlock;
}
const std::size_t GetHashCode() const final{
return _hash;
}
const std::shared_ptr<EvaluationScope>& GetScope() const{
return _scope;
}
};
}
#endif //PORYGONLANG_SCRIPTFUNCTIONEVALVALUE_HPP

View File

@@ -8,43 +8,44 @@
using namespace std;
class StringEvalValue : public EvalValue{
u16string _value;
size_t _hash;
public:
explicit StringEvalValue(u16string s){
_value = move(s);
_hash = HashedString::ConstHash (_value.c_str());
}
namespace Porygon::Evaluation {
class StringEvalValue : public EvalValue {
u16string _value;
size_t _hash;
public:
explicit StringEvalValue(u16string s) {
_value = move(s);
_hash = Utilities::HashedString::ConstHash(_value.c_str());
}
const TypeClass GetTypeClass() const final{
return TypeClass ::String;
}
const TypeClass GetTypeClass() const final {
return TypeClass::String;
}
const bool operator ==(EvalValue* b) const final{
if (b->GetTypeClass() != TypeClass::String)
return false;
return this->_hash == b->GetHashCode();
const bool operator==(EvalValue *b) const final {
if (b->GetTypeClass() != TypeClass::String)
return false;
return this->_hash == b->GetHashCode();
};
const u16string *EvaluateString() const final {
return &_value;
}
const shared_ptr<EvalValue> Clone() const final {
return make_shared<StringEvalValue>(_value);
}
const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final {
// Porygon is 1-indexed, so we convert to that.
auto l = val->EvaluateInteger() - 1;
return make_shared<StringEvalValue>(u16string(1, _value[l]));
}
const std::size_t GetHashCode() const final {
return _hash;
}
};
const u16string* EvaluateString() const final{
return &_value;
}
const shared_ptr<EvalValue> Clone() const final{
return make_shared<StringEvalValue>(_value);
}
const shared_ptr<EvalValue> IndexValue(EvalValue* val) const final{
// Porygon is 1-indexed, so we convert to that.
auto l = val->EvaluateInteger() - 1;
return make_shared<StringEvalValue>(u16string(1, _value[l]));
}
const std::size_t GetHashCode() const final{
return _hash;
}
};
}
#endif //PORYGONLANG_STRINGEVALVALUE_HPP

View File

@@ -6,55 +6,57 @@
using namespace std;
class TableEvalValue : public EvalValue {
shared_ptr<unordered_map<uint32_t, shared_ptr<EvalValue>>> _table;
size_t _hash;
namespace Porygon::Evaluation {
class TableEvalValue : public EvalValue {
shared_ptr<unordered_map<uint32_t, shared_ptr<EvalValue>>> _table;
size_t _hash;
explicit TableEvalValue(shared_ptr<unordered_map<uint32_t, shared_ptr<EvalValue>>> table, size_t hash){
_table = std::move(table);
_hash = hash;
}
public:
explicit TableEvalValue(shared_ptr<unordered_map<uint32_t, shared_ptr<EvalValue>>> table){
_table = std::move(table);
_hash = rand();
}
explicit TableEvalValue(shared_ptr<unordered_map<uint32_t, shared_ptr<EvalValue>>> table, size_t hash) {
_table = std::move(table);
_hash = hash;
}
const TypeClass GetTypeClass() const final{
return TypeClass ::Table;
}
public:
explicit TableEvalValue(shared_ptr<unordered_map<uint32_t, shared_ptr<EvalValue>>> table) {
_table = std::move(table);
_hash = rand();
}
const size_t GetHashCode() const final{
return _hash;
}
const TypeClass GetTypeClass() const final {
return TypeClass::Table;
}
const bool operator ==(EvalValue* b) const final{
return this -> _hash == b->GetHashCode();
}
const size_t GetHashCode() const final {
return _hash;
}
const shared_ptr<EvalValue> Clone() const final{
return shared_ptr<EvalValue>(new TableEvalValue(_table, _hash));
}
const bool operator==(EvalValue *b) const final {
return this->_hash == b->GetHashCode();
}
const shared_ptr<EvalValue> IndexValue(EvalValue* val) const final{
auto hash = val->GetHashCode();
return this -> _table->at(hash);
}
const shared_ptr<EvalValue> Clone() const final {
return shared_ptr<EvalValue>(new TableEvalValue(_table, _hash));
}
const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final{
return this -> _table->at(hash);
}
const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final {
auto hash = val->GetHashCode();
return this->_table->at(hash);
}
const shared_ptr<EvalValue> IndexValue(const char* val) const {
auto hash = HashedString::ConstHash(val);
return this -> _table -> at(hash);
}
const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final {
return this->_table->at(hash);
}
void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue>& value) const final{
auto hash = key->GetHashCode();
this -> _table->at(hash) = value;
}
};
const shared_ptr<EvalValue> IndexValue(const char *val) const {
auto hash = Utilities::HashedString::ConstHash(val);
return this->_table->at(hash);
}
void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const final {
auto hash = key->GetHashCode();
this->_table->at(hash) = value;
}
};
}
#endif //PORYGONLANG_TABLEEVALVALUE_HPP