Rework of memory handling in Evaluation
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -74,10 +74,10 @@ namespace Porygon::StandardLibraries{
|
||||
}
|
||||
|
||||
|
||||
static shared_ptr<Evaluation::EvalValue> GetFuncEvalValue(
|
||||
const Evaluation::EvalValue* (*func)(void* obj, const Evaluation::EvalValue* parameters[], int parameterCount),
|
||||
const shared_ptr<GenericFunctionScriptType>& type, size_t optionLength){
|
||||
auto f = make_shared<Evaluation::GenericFunctionEvalValue>(type, rand());
|
||||
static Evaluation::EvalValue* GetFuncEvalValue(
|
||||
const Evaluation::EvalValue* (*func)(void* obj, const Evaluation::EvalValue* parameters[], int parameterCount),
|
||||
const shared_ptr<GenericFunctionScriptType>& type, size_t optionLength){
|
||||
auto f = new Evaluation::GenericFunctionEvalValue(type, rand());
|
||||
for (size_t i = 0; i < optionLength; i++){
|
||||
auto funcOption = new UserData::UserDataFunction(func, nullptr);
|
||||
f->RegisterOption(funcOption);
|
||||
@@ -88,7 +88,7 @@ namespace Porygon::StandardLibraries{
|
||||
|
||||
public:
|
||||
static void RegisterVariables(std::map<Utilities::HashedString, Binder::BoundVariable *>* bound,
|
||||
std::map<Utilities::HashedString, shared_ptr<Evaluation::EvalValue>>* values){
|
||||
std::map<Utilities::HashedString, Evaluation::EvalValue*>* values){
|
||||
// Register error function
|
||||
auto errorFuncType = BasicLibrary::GetErrorFuncType();
|
||||
auto errorLookup = Utilities::HashedString::CreateLookup(u"error");
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Porygon::StandardLibraries{
|
||||
class InternalScope{
|
||||
public:
|
||||
map<Utilities::HashedString, Binder::BoundVariable *> _boundVariables;
|
||||
map<Utilities::HashedString, shared_ptr<Evaluation::EvalValue>> _variables;
|
||||
map<Utilities::HashedString, Evaluation::EvalValue*> _variables;
|
||||
|
||||
InternalScope(){
|
||||
BasicLibrary::RegisterVariables(&_boundVariables, &_variables);
|
||||
@@ -29,6 +29,9 @@ namespace Porygon::StandardLibraries{
|
||||
for (const auto& b: _boundVariables){
|
||||
delete b.second;
|
||||
}
|
||||
for (const auto& v: _variables){
|
||||
delete v.second;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -36,7 +39,7 @@ namespace Porygon::StandardLibraries{
|
||||
public:
|
||||
static void RegisterVariable(const Utilities::HashedString& identifier, shared_ptr<ScriptType> type, Evaluation::EvalValue* value){
|
||||
_internal._boundVariables.insert({identifier, new Binder::BoundVariable(std::move(type))});
|
||||
_internal._variables.insert({identifier, shared_ptr<Evaluation::EvalValue>(value)});
|
||||
_internal._variables.insert({identifier, value});
|
||||
}
|
||||
|
||||
static Binder::BoundVariable* GetBoundVariable(const Utilities::HashedString &identifier){
|
||||
@@ -47,8 +50,8 @@ namespace Porygon::StandardLibraries{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline static shared_ptr<Evaluation::EvalValue> GetVariable(const Utilities::HashedString &identifier){
|
||||
return _internal._variables[identifier];
|
||||
inline static Evaluation::EvalValuePointer GetVariable(const Utilities::HashedString &identifier){
|
||||
return _internal._variables[identifier]->Clone();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user