diff --git a/src/Amalgam/AmalgamMain.cpp b/src/Amalgam/AmalgamMain.cpp index bee5386d..11975b71 100644 --- a/src/Amalgam/AmalgamMain.cpp +++ b/src/Amalgam/AmalgamMain.cpp @@ -319,6 +319,8 @@ PLATFORM_MAIN_CONSOLE if(debug_internal_memory) { + entity->VerifyEvaluableNodeIntegrityAndAllContainedEntities(); + delete entity; auto num_strings_used = string_intern_pool.GetNumDynamicStringsInUse(); diff --git a/src/Amalgam/entity/Entity.cpp b/src/Amalgam/entity/Entity.cpp index 52221b50..4956adc4 100644 --- a/src/Amalgam/entity/Entity.cpp +++ b/src/Amalgam/entity/Entity.cpp @@ -999,3 +999,10 @@ void Entity::VerifyEvaluableNodeIntegrity() for(auto &[en, _] : nr.nodesReferenced) EvaluableNodeManager::ValidateEvaluableNodeTreeMemoryIntegrity(en); } + +void Entity::VerifyEvaluableNodeIntegrityAndAllContainedEntities() +{ + VerifyEvaluableNodeIntegrity(); + for(auto ce : GetContainedEntities()) + ce->VerifyEvaluableNodeIntegrity(); +} diff --git a/src/Amalgam/entity/Entity.h b/src/Amalgam/entity/Entity.h index b861f48b..a4848752 100644 --- a/src/Amalgam/entity/Entity.h +++ b/src/Amalgam/entity/Entity.h @@ -714,6 +714,9 @@ class Entity //ensures that there are no reachable nodes that are deallocated void VerifyEvaluableNodeIntegrity(); + //like VerifyEvaluableNodeIntegrity but includes all contained + void VerifyEvaluableNodeIntegrityAndAllContainedEntities(); + //this is an estimate of the number of nodes required to reconstruct the entity if it were flattened // including amortization of all extra overhead static inline size_t GetEntityCreationSizeInNodes() diff --git a/src/Amalgam/evaluablenode/EvaluableNodeManagement.cpp b/src/Amalgam/evaluablenode/EvaluableNodeManagement.cpp index 7b4fe318..5a476e8e 100644 --- a/src/Amalgam/evaluablenode/EvaluableNodeManagement.cpp +++ b/src/Amalgam/evaluablenode/EvaluableNodeManagement.cpp @@ -448,6 +448,10 @@ void EvaluableNodeManager::FreeNodeTreeRecurse(EvaluableNode *tree) } } +#ifdef AMALGAM_FAST_MEMORY_INTEGRITY + assert(!tree->GetNeedCycleCheck()); +#endif + tree->Invalidate(); } diff --git a/src/Amalgam/interpreter/InterpreterOpcodesTransformations.cpp b/src/Amalgam/interpreter/InterpreterOpcodesTransformations.cpp index 62ffe8ca..3a9e2b18 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesTransformations.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesTransformations.cpp @@ -634,6 +634,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_WEAVE(EvaluableNode *en, b //find the largest of all the lists and the total number of elements size_t maximum_list_size = 0; size_t total_num_elements = 0; + bool all_lists_unique = true; for(auto &list : lists) { if(list != nullptr) @@ -641,11 +642,13 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_WEAVE(EvaluableNode *en, b size_t num_elements = list->GetOrderedChildNodes().size(); maximum_list_size = std::max(maximum_list_size, num_elements); total_num_elements += num_elements; + + all_lists_unique &= list.unique; } } //the result - EvaluableNodeReference woven_list(evaluableNodeManager->AllocNode(ENT_LIST), true); + EvaluableNodeReference woven_list(evaluableNodeManager->AllocNode(ENT_LIST), all_lists_unique); //just lists, interleave if(EvaluableNode::IsNull(function))