Implements userdata function support
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2019-06-21 17:03:13 +02:00
parent 6f7d319148
commit 95c322ed2c
9 changed files with 245 additions and 57 deletions

View File

@@ -1,5 +1,7 @@
#include <utility>
#include <utility>
#ifndef PORYGONLANG_SCRIPTFUNCTIONEVALVALUE_HPP
#define PORYGONLANG_SCRIPTFUNCTIONEVALVALUE_HPP
@@ -11,30 +13,19 @@
#include "../Evaluator.hpp"
#include "../EvaluationScope/EvaluationScope.hpp"
using namespace std;
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;
class GenericFunctionEvalValue : public EvalValue{
protected:
const std::shared_ptr<GenericFunctionScriptType> _type;
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) {
}
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()) {
GenericFunctionEvalValue(shared_ptr<GenericFunctionScriptType> type, size_t hash)
: _type(move(type)),
_hash(hash){
}
const std::shared_ptr<ScriptType> GetType() const {
@@ -45,25 +36,48 @@ namespace Porygon::Evaluation {
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 bool operator==(EvalValue *b) const final {
if (b->GetTypeClass() != TypeClass::Function)
return false;
return this->_hash == ((ScriptFunctionEvalValue *) b)->_hash;
return this->_hash == ((GenericFunctionEvalValue *) b)->_hash;
};
const std::shared_ptr<BoundBlockStatement> &GetInnerBlock() const {
return _innerBlock;
}
const std::size_t GetHashCode() const final {
return _hash;
}
};
class ScriptFunctionEvalValue : public GenericFunctionEvalValue {
const std::shared_ptr<BoundBlockStatement> _innerBlock;
const std::shared_ptr<EvaluationScope> _scope;
explicit ScriptFunctionEvalValue(shared_ptr<BoundBlockStatement> innerBlock,
shared_ptr<EvaluationScope> scope,
shared_ptr<FunctionScriptType> type, size_t hash)
: GenericFunctionEvalValue(move(type), hash),
_innerBlock(std::move(innerBlock)),
_scope(std::move(scope)){
}
public:
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock,
std::shared_ptr<EvaluationScope> scope,
std::shared_ptr<FunctionScriptType> type)
: GenericFunctionEvalValue(move(type), rand()),
_innerBlock(std::move(innerBlock)),
_scope(std::move(scope)){
}
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,
dynamic_pointer_cast<FunctionScriptType>(_type), _hash));
}
const std::shared_ptr<BoundBlockStatement> &GetInnerBlock() const {
return _innerBlock;
}
const std::shared_ptr<EvaluationScope> &GetScope() const {
return _scope;