Skip to content

Commit

Permalink
bring SLiM up to speed with EidosValue changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Dec 22, 2023
1 parent 092a01c commit fa1ade2
Show file tree
Hide file tree
Showing 26 changed files with 680 additions and 692 deletions.
2 changes: 1 addition & 1 deletion SLiMgui/slim_gui.mm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
#pragma unused (p_method_id, p_arguments, p_interpreter)

EidosValue_String *filePath_value = (EidosValue_String *)p_arguments[0].get();
std::string file_path = Eidos_ResolvedPath(Eidos_StripTrailingSlash(filePath_value->StringRefAtIndex(0, nullptr)));
std::string file_path = Eidos_ResolvedPath(Eidos_StripTrailingSlash(filePath_value->StringRefAtIndex_NOCAST(0, nullptr)));
NSString *filePath = [NSString stringWithUTF8String:file_path.c_str()];

[controller_ eidos_openDocument:filePath];
Expand Down
76 changes: 38 additions & 38 deletions core/chromosome.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions core/community.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ Species *Community::SpeciesForIndividuals(EidosValue *value)
EIDOS_TERMINATION << "ERROR (Community::SpeciesForIndividuals): (internal error) value is not of class Individual." << EidosTerminate();

if (value_count == 1)
return &((Individual *)object_value->ObjectElementAtIndex(0, nullptr))->subpopulation_->species_;
return &((Individual *)object_value->ObjectElementAtIndex_NOCAST(0, nullptr))->subpopulation_->species_;

EidosValue_Object_vector *object_vector_value = (EidosValue_Object_vector *)object_value;
Individual **individuals = (Individual **)object_vector_value->data();
Expand Down Expand Up @@ -1369,7 +1369,7 @@ Species *Community::SpeciesForGenomes(EidosValue *value)
EIDOS_TERMINATION << "ERROR (Community::SpeciesForGenomes): (internal error) value is not of class Genome." << EidosTerminate();

if (value_count == 1)
return &((Genome *)object_value->ObjectElementAtIndex(0, nullptr))->OwningIndividual()->subpopulation_->species_;
return &((Genome *)object_value->ObjectElementAtIndex_NOCAST(0, nullptr))->OwningIndividual()->subpopulation_->species_;

EidosValue_Object_vector *object_vector_value = (EidosValue_Object_vector *)object_value;
Genome **genomes = (Genome **)object_vector_value->data();
Expand Down Expand Up @@ -1414,7 +1414,7 @@ Species *Community::SpeciesForMutations(EidosValue *value)
EIDOS_TERMINATION << "ERROR (Community::SpeciesForMutations): (internal error) value is not of class Mutation." << EidosTerminate();

if (value_count == 1)
return &((Mutation *)object_value->ObjectElementAtIndex(0, nullptr))->mutation_type_ptr_->species_;
return &((Mutation *)object_value->ObjectElementAtIndex_NOCAST(0, nullptr))->mutation_type_ptr_->species_;

EidosValue_Object_vector *object_vector_value = (EidosValue_Object_vector *)object_value;
Mutation **mutations = (Mutation **)object_vector_value->data();
Expand Down
78 changes: 39 additions & 39 deletions core/community_eidos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ EidosValue_SP Community::ExecuteContextFunction_initializeSLiMModelType(const st

{
// string$ modelType
std::string model_type = arg_modelType_value->StringAtIndex(0, nullptr);
std::string model_type = arg_modelType_value->StringAtIndex_NOCAST(0, nullptr);

if (model_type == "WF")
SetModelType(SLiMModelType::kModelTypeWF);
Expand Down Expand Up @@ -249,10 +249,10 @@ EidosValue_SP Community::ExecuteContextFunction_initializeInteractionType(const
EIDOS_TERMINATION << "ERROR (Community::ExecuteContextFunction_initializeInteractionType): in multispecies models, initializeInteractionType() may only be called from a non-species-specific (`species all`) initialize() callback." << EidosTerminate();

slim_objectid_t map_identifier = SLiM_ExtractObjectIDFromEidosValue_is(id_value, 0, 'i');
std::string spatiality_string = spatiality_value->StringAtIndex(0, nullptr);
bool reciprocal = reciprocal_value->LogicalAtIndex(0, nullptr); // UNUSED
double max_distance = maxDistance_value->FloatAtIndex(0, nullptr);
std::string sex_string = sexSegregation_value->StringAtIndex(0, nullptr);
std::string spatiality_string = spatiality_value->StringAtIndex_NOCAST(0, nullptr);
bool reciprocal = reciprocal_value->LogicalAtIndex_NOCAST(0, nullptr); // UNUSED
double max_distance = maxDistance_value->NumericAtIndex_NOCAST(0, nullptr);
std::string sex_string = sexSegregation_value->StringAtIndex_NOCAST(0, nullptr);
IndividualSex receiver_sex = IndividualSex::kUnspecified, exerter_sex = IndividualSex::kUnspecified;

if (InteractionTypeWithID(map_identifier))
Expand Down Expand Up @@ -454,7 +454,7 @@ void Community::SetProperty(EidosGlobalStringID p_property_id, const EidosValue
{
case gID_tick:
{
int64_t value = p_value.IntAtIndex(0, nullptr);
int64_t value = p_value.IntAtIndex_NOCAST(0, nullptr);
slim_tick_t old_tick = tick_;
slim_tick_t new_tick = SLiMCastToTickTypeOrRaise(value);

Expand Down Expand Up @@ -522,15 +522,15 @@ void Community::SetProperty(EidosGlobalStringID p_property_id, const EidosValue

case gID_tag:
{
slim_usertag_t value = SLiMCastToUsertagTypeOrRaise(p_value.IntAtIndex(0, nullptr));
slim_usertag_t value = SLiMCastToUsertagTypeOrRaise(p_value.IntAtIndex_NOCAST(0, nullptr));

tag_value_ = value;
return;
}

case gID_verbosity:
{
int64_t value = p_value.IntAtIndex(0, nullptr);
int64_t value = p_value.IntAtIndex_NOCAST(0, nullptr);

SLiM_verbosity_level = value; // at the command line we bounds-check this, but here I see no need
return;
Expand Down Expand Up @@ -581,11 +581,11 @@ EidosValue_SP Community::ExecuteMethod_createLogFile(EidosGlobalStringID p_metho
EidosValue *flushInterval_value = p_arguments[6].get();

// process parameters
const std::string &filePath = filePath_value->StringRefAtIndex(0, nullptr);
const std::string &filePath = filePath_value->StringRefAtIndex_NOCAST(0, nullptr);
std::vector<const std::string *> initialContents;
bool append = append_value->LogicalAtIndex(0, nullptr);
bool do_compress = compress_value->LogicalAtIndex(0, nullptr);
const std::string &sep = sep_value->StringRefAtIndex(0, nullptr);
bool append = append_value->LogicalAtIndex_NOCAST(0, nullptr);
bool do_compress = compress_value->LogicalAtIndex_NOCAST(0, nullptr);
const std::string &sep = sep_value->StringRefAtIndex_NOCAST(0, nullptr);
bool autologging = false, explicitFlushing = false;
int64_t logInterval = 0, flushInterval = 0;

Expand All @@ -595,7 +595,7 @@ EidosValue_SP Community::ExecuteMethod_createLogFile(EidosGlobalStringID p_metho
int ic_count = initialContents_value->Count();

for (int ic_index = 0; ic_index < ic_count; ++ic_index)
initialContents.emplace_back(&ic_string_value->StringRefAtIndex(ic_index, nullptr));
initialContents.emplace_back(&ic_string_value->StringRefAtIndex_NOCAST(ic_index, nullptr));
}

if (logInterval_value->Type() == EidosValueType::kValueNULL)
Expand All @@ -607,7 +607,7 @@ EidosValue_SP Community::ExecuteMethod_createLogFile(EidosGlobalStringID p_metho
else
{
autologging = true;
logInterval = logInterval_value->IntAtIndex(0, nullptr);
logInterval = logInterval_value->IntAtIndex_NOCAST(0, nullptr);
}

if (flushInterval_value->Type() == EidosValueType::kValueNULL)
Expand All @@ -619,7 +619,7 @@ EidosValue_SP Community::ExecuteMethod_createLogFile(EidosGlobalStringID p_metho
else
{
explicitFlushing = true;
flushInterval = flushInterval_value->IntAtIndex(0, nullptr);
flushInterval = flushInterval_value->IntAtIndex_NOCAST(0, nullptr);
}

// Create the LogFile object
Expand Down Expand Up @@ -724,7 +724,7 @@ EidosValue_SP Community::ExecuteMethod_genomicElementTypesWithIDs(EidosGlobalStr
if (ids_count == 1)
{
// Singleton case
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(0, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(0, nullptr));
GenomicElementType *object = GenomicElementTypeWithID(id);

if (!object)
Expand All @@ -739,7 +739,7 @@ EidosValue_SP Community::ExecuteMethod_genomicElementTypesWithIDs(EidosGlobalStr

for (int id_index = 0; id_index < ids_count; id_index++)
{
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(id_index, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(id_index, nullptr));
GenomicElementType *object = GenomicElementTypeWithID(id);

if (!object)
Expand All @@ -763,7 +763,7 @@ EidosValue_SP Community::ExecuteMethod_interactionTypesWithIDs(EidosGlobalString
if (ids_count == 1)
{
// Singleton case
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(0, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(0, nullptr));
InteractionType *object = InteractionTypeWithID(id);

if (!object)
Expand All @@ -778,7 +778,7 @@ EidosValue_SP Community::ExecuteMethod_interactionTypesWithIDs(EidosGlobalString

for (int id_index = 0; id_index < ids_count; id_index++)
{
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(id_index, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(id_index, nullptr));
InteractionType *object = InteractionTypeWithID(id);

if (!object)
Expand All @@ -802,7 +802,7 @@ EidosValue_SP Community::ExecuteMethod_mutationTypesWithIDs(EidosGlobalStringID
if (ids_count == 1)
{
// Singleton case
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(0, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(0, nullptr));
MutationType *object = MutationTypeWithID(id);

if (!object)
Expand All @@ -817,7 +817,7 @@ EidosValue_SP Community::ExecuteMethod_mutationTypesWithIDs(EidosGlobalStringID

for (int id_index = 0; id_index < ids_count; id_index++)
{
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(id_index, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(id_index, nullptr));
MutationType *object = MutationTypeWithID(id);

if (!object)
Expand All @@ -841,7 +841,7 @@ EidosValue_SP Community::ExecuteMethod_scriptBlocksWithIDs(EidosGlobalStringID p
if (ids_count == 1)
{
// Singleton case
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(0, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(0, nullptr));
SLiMEidosBlock *object = ScriptBlockWithID(id);

if (!object)
Expand All @@ -856,7 +856,7 @@ EidosValue_SP Community::ExecuteMethod_scriptBlocksWithIDs(EidosGlobalStringID p

for (int id_index = 0; id_index < ids_count; id_index++)
{
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(id_index, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(id_index, nullptr));
SLiMEidosBlock *object = ScriptBlockWithID(id);

if (!object)
Expand All @@ -880,7 +880,7 @@ EidosValue_SP Community::ExecuteMethod_speciesWithIDs(EidosGlobalStringID p_meth
if (ids_count == 1)
{
// Singleton case
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(0, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(0, nullptr));
Species *object = SpeciesWithID(id);

if (!object)
Expand All @@ -895,7 +895,7 @@ EidosValue_SP Community::ExecuteMethod_speciesWithIDs(EidosGlobalStringID p_meth

for (int id_index = 0; id_index < ids_count; id_index++)
{
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(id_index, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(id_index, nullptr));
Species *object = SpeciesWithID(id);

if (!object)
Expand All @@ -919,7 +919,7 @@ EidosValue_SP Community::ExecuteMethod_subpopulationsWithIDs(EidosGlobalStringID
if (ids_count == 1)
{
// Singleton case
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(0, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(0, nullptr));
Subpopulation *object = SubpopulationWithID(id);

if (!object)
Expand All @@ -934,7 +934,7 @@ EidosValue_SP Community::ExecuteMethod_subpopulationsWithIDs(EidosGlobalStringID

for (int id_index = 0; id_index < ids_count; id_index++)
{
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex(id_index, nullptr));
slim_objectid_t id = SLiMCastToObjectidTypeOrRaise(ids_value->IntAtIndex_NOCAST(id_index, nullptr));
Subpopulation *object = SubpopulationWithID(id);

if (!object)
Expand Down Expand Up @@ -1083,9 +1083,9 @@ EidosValue_SP Community::ExecuteMethod_registerFirstEarlyLateEvent(EidosGlobalSt
EidosValue *ticksSpec_value = p_arguments[4].get();

slim_objectid_t script_id = -1; // used if the id is NULL, to indicate an anonymous block
std::string script_string = source_value->StringAtIndex(0, nullptr);
slim_tick_t start_tick = ((start_value->Type() != EidosValueType::kValueNULL) ? SLiMCastToTickTypeOrRaise(start_value->IntAtIndex(0, nullptr)) : 1);
slim_tick_t end_tick = ((end_value->Type() != EidosValueType::kValueNULL) ? SLiMCastToTickTypeOrRaise(end_value->IntAtIndex(0, nullptr)) : SLIM_MAX_TICK + 1);
std::string script_string = source_value->StringAtIndex_NOCAST(0, nullptr);
slim_tick_t start_tick = ((start_value->Type() != EidosValueType::kValueNULL) ? SLiMCastToTickTypeOrRaise(start_value->IntAtIndex_NOCAST(0, nullptr)) : 1);
slim_tick_t end_tick = ((end_value->Type() != EidosValueType::kValueNULL) ? SLiMCastToTickTypeOrRaise(end_value->IntAtIndex_NOCAST(0, nullptr)) : SLIM_MAX_TICK + 1);

if (id_value->Type() != EidosValueType::kValueNULL)
script_id = SLiM_ExtractObjectIDFromEidosValue_is(id_value, 0, 's');
Expand Down Expand Up @@ -1115,7 +1115,7 @@ EidosValue_SP Community::ExecuteMethod_registerFirstEarlyLateEvent(EidosGlobalSt
else
EIDOS_TERMINATION << "ERROR (Community::ExecuteMethod_registerFirstEarlyLateEvent): (internal error) unrecognized target_type." << EidosTerminate();

Species *ticksSpec = ((ticksSpec_value->Type() != EidosValueType::kValueNULL) ? (Species *)ticksSpec_value->ObjectElementAtIndex(0, nullptr) : nullptr);
Species *ticksSpec = ((ticksSpec_value->Type() != EidosValueType::kValueNULL) ? (Species *)ticksSpec_value->ObjectElementAtIndex_NOCAST(0, nullptr) : nullptr);

if (ticksSpec && !is_explicit_species_)
EIDOS_TERMINATION << "ERROR (Community::ExecuteMethod_registerFirstEarlyLateEvent): ticksSpec must be NULL in models without explicit species declarations." << EidosTerminate();
Expand All @@ -1142,17 +1142,17 @@ EidosValue_SP Community::ExecuteMethod_registerInteractionCallback(EidosGlobalSt
EidosValue *end_value = p_arguments[5].get();

slim_objectid_t script_id = -1; // used if the id is NULL, to indicate an anonymous block
std::string script_string = source_value->StringAtIndex(0, nullptr);
slim_objectid_t int_type_id = (intType_value->Type() == EidosValueType::kValueInt) ? SLiMCastToObjectidTypeOrRaise(intType_value->IntAtIndex(0, nullptr)) : ((InteractionType *)intType_value->ObjectElementAtIndex(0, nullptr))->interaction_type_id_;
std::string script_string = source_value->StringAtIndex_NOCAST(0, nullptr);
slim_objectid_t int_type_id = (intType_value->Type() == EidosValueType::kValueInt) ? SLiMCastToObjectidTypeOrRaise(intType_value->IntAtIndex_NOCAST(0, nullptr)) : ((InteractionType *)intType_value->ObjectElementAtIndex_NOCAST(0, nullptr))->interaction_type_id_;
slim_objectid_t subpop_id = -1;
slim_tick_t start_tick = ((start_value->Type() != EidosValueType::kValueNULL) ? SLiMCastToTickTypeOrRaise(start_value->IntAtIndex(0, nullptr)) : 1);
slim_tick_t end_tick = ((end_value->Type() != EidosValueType::kValueNULL) ? SLiMCastToTickTypeOrRaise(end_value->IntAtIndex(0, nullptr)) : SLIM_MAX_TICK + 1);
slim_tick_t start_tick = ((start_value->Type() != EidosValueType::kValueNULL) ? SLiMCastToTickTypeOrRaise(start_value->IntAtIndex_NOCAST(0, nullptr)) : 1);
slim_tick_t end_tick = ((end_value->Type() != EidosValueType::kValueNULL) ? SLiMCastToTickTypeOrRaise(end_value->IntAtIndex_NOCAST(0, nullptr)) : SLIM_MAX_TICK + 1);

if (id_value->Type() != EidosValueType::kValueNULL)
script_id = SLiM_ExtractObjectIDFromEidosValue_is(id_value, 0, 's');

if (subpop_value->Type() != EidosValueType::kValueNULL)
subpop_id = (subpop_value->Type() == EidosValueType::kValueInt) ? SLiMCastToObjectidTypeOrRaise(subpop_value->IntAtIndex(0, nullptr)) : ((Subpopulation *)subpop_value->ObjectElementAtIndex(0, nullptr))->subpopulation_id_;
subpop_id = (subpop_value->Type() == EidosValueType::kValueInt) ? SLiMCastToObjectidTypeOrRaise(subpop_value->IntAtIndex_NOCAST(0, nullptr)) : ((Subpopulation *)subpop_value->ObjectElementAtIndex_NOCAST(0, nullptr))->subpopulation_id_;

if (start_tick > end_tick)
EIDOS_TERMINATION << "ERROR (Community::ExecuteMethod_registerInteractionCallback): registerInteractionCallback() requires start <= end." << EidosTerminate();
Expand Down Expand Up @@ -1245,8 +1245,8 @@ EidosValue_SP Community::ExecuteMethod_rescheduleScriptBlock(EidosGlobalStringID
{
// start/end case; this is simple

slim_tick_t start = (start_null ? 1 : SLiMCastToTickTypeOrRaise(start_value->IntAtIndex(0, nullptr)));
slim_tick_t end = (end_null ? SLIM_MAX_TICK + 1 : SLiMCastToTickTypeOrRaise(end_value->IntAtIndex(0, nullptr)));
slim_tick_t start = (start_null ? 1 : SLiMCastToTickTypeOrRaise(start_value->IntAtIndex_NOCAST(0, nullptr)));
slim_tick_t end = (end_null ? SLIM_MAX_TICK + 1 : SLiMCastToTickTypeOrRaise(end_value->IntAtIndex_NOCAST(0, nullptr)));

if (start > end)
EIDOS_TERMINATION << "ERROR (Community::ExecuteMethod_rescheduleScriptBlock): rescheduleScriptBlock() requires start <= end." << EidosTerminate();
Expand Down Expand Up @@ -1281,7 +1281,7 @@ EidosValue_SP Community::ExecuteMethod_rescheduleScriptBlock(EidosGlobalStringID
ticks.reserve(tick_count);

for (int tick_index = 0; tick_index < tick_count; ++tick_index)
ticks.emplace_back(SLiMCastToTickTypeOrRaise(ticks_value->IntAtIndex(tick_index, nullptr)));
ticks.emplace_back(SLiMCastToTickTypeOrRaise(ticks_value->IntAtIndex_NOCAST(tick_index, nullptr)));

// next, sort the tick list and check that the first scheduling it requests is not in the past
std::sort(ticks.begin(), ticks.end());
Expand Down
Loading

0 comments on commit fa1ade2

Please sign in to comment.