Fixes and changes for function declarations, using shared_ptr instead of raw pointers

This commit is contained in:
2019-06-01 13:43:25 +02:00
parent 6936b26cae
commit 1231a77761
8 changed files with 91 additions and 68 deletions

View File

@@ -2,16 +2,18 @@
#ifndef PORYGONLANG_SCRIPTFUNCTIONEVALVALUE_HPP
#define PORYGONLANG_SCRIPTFUNCTIONEVALVALUE_HPP
#include <memory>
#include "../../ScriptType.hpp"
#include "EvalValue.hpp"
#include "../../Binder/BoundStatements/BoundStatement.hpp"
#include "../Evaluator.hpp"
class ScriptFunctionEvalValue : public EvalValue{
BoundBlockStatement* _innerBlock;
std::shared_ptr<BoundBlockStatement> _innerBlock;
FunctionScriptType _type;
public:
explicit ScriptFunctionEvalValue(BoundBlockStatement* innerBlock, const FunctionScriptType& type)
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock, const FunctionScriptType& type)
: _type(type)
{
_innerBlock = innerBlock;
@@ -21,10 +23,6 @@ public:
return new ScriptFunctionEvalValue(_innerBlock, _type);
}
~ScriptFunctionEvalValue() final{
delete _innerBlock;
}
ScriptType* GetType() final{
return &_type;
};
@@ -42,13 +40,13 @@ public:
for (int i = 0; i < parameterTypes.size() && i < parameterKeys.size() && i < parameters.size(); i++){
auto parameter = parameters[i];
auto requiredType = parameterTypes[i];
if (parameter->GetType() != requiredType){
if (parameter->GetType() != requiredType.get()){
throw EvaluationException("Passed wrong type to function.");
}
auto key = parameterKeys[i];
scope->CreateVariable(_type.GetScopeId(), key, parameter->Clone());
scope->CreateVariable(key->GetScopeId(), key->GetIdentifier(), parameter->Clone());
}
evaluator->EvaluateBlockStatement(_innerBlock);
evaluator->EvaluateBlockStatement(_innerBlock.get());
return nullptr;
}
};