Skip to content

Commit 4997618

Browse files
committed
fixes #573, fixes #574, clean up conflicts with constants/globals
1 parent 6e2109f commit 4997618

24 files changed

Lines changed: 189 additions & 16 deletions

EidosSLiMTests/SLiMTests.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ - (void)setUp {
3939
#ifdef _OPENMP
4040
Eidos_WarmUpOpenMP(&SLIM_ERRSTREAM, changed_max_thread_count, (int)max_thread_count, true, /* max per-task thread counts */ "maxThreads");
4141
#endif
42+
SLiM_ConfigureContext();
4243
Eidos_WarmUp();
4344
SLiM_WarmUp();
4445

QtSLiM/QtSLiMAppDelegate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ QtSLiMAppDelegate::QtSLiMAppDelegate(QObject *p_parent) : QObject(p_parent)
189189
QCoreApplication::setApplicationVersion(SLIM_VERSION_STRING);
190190

191191
// Warm up our back ends before anything else happens, including our own class objects
192+
SLiM_ConfigureContext();
192193
Eidos_WarmUp();
193194
SLiM_WarmUp();
194195

QtSLiM/QtSLiMScriptTextEdit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,13 @@ void QtSLiMTextEdit::scriptHelpOptionClick(QString searchString)
512512
else if (searchString == "//") searchString = "comments";
513513
else if (searchString == "if") searchString = "if and if–else statements";
514514
else if (searchString == "else") searchString = "if and if–else statements";
515+
else if (searchString == "do") searchString = "do–while statements";
516+
else if (searchString == "while") searchString = "while statements"; // this brings up both while and do-while statements, correctly
515517
else if (searchString == "for") searchString = "for statements";
516518
else if (searchString == "in") searchString = "for statements";
519+
else if (searchString == "next") searchString = "next statements";
520+
else if (searchString == "break") searchString = "break statements";
521+
else if (searchString == "return") searchString = "return statements";
517522
else if (searchString == "function") searchString = "user-defined functions";
518523
// and SLiM substitutions; "initialize" is deliberately omitted here so that the initialize...() methods also come up
519524
else if (searchString == "first") searchString = "Eidos events";

QtSLiM/QtSLiMSyntaxHighlighting.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void QtSLiMOutputHighlighter::highlightBlock(const QString &text)
9090
setFormat(match.capturedStart(), match.capturedLength(), genomicElementFormat);
9191
else if (matchString[0] == 'm')
9292
setFormat(match.capturedStart(), match.capturedLength(), mutationTypeFormat);
93+
// we don't presently color sX or iX in the output
9394
}
9495
}
9596
}

QtSLiM/QtSLiMWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,7 @@ void QtSLiMWindow::startNewSimulationFromScript(void)
22752275
slimgui = new SLiMgui(*community, this);
22762276

22772277
// set up the "slimgui" symbol for it immediately
2278+
// BCH 11/7/2025: note this symbol is now protected in SLiM_ConfigureContext()
22782279
community->simulation_constants_->InitializeConstantSymbolEntry(slimgui->SymbolTableEntry());
22792280
}
22802281

SLiMgui/AppDelegate.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
230230
Eidos_WarmUpOpenMP(&std::cout, true, 4, false, /* default per-task thread counts */ "");
231231
#endif
232232

233+
SLiM_ConfigureContext();
233234
Eidos_WarmUp();
234235
SLiM_WarmUp();
235236

SLiMgui/SLiMWindowController.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ - (void)startNewSimulationFromScript
595595
slimgui = new SLiMgui(*community, self);
596596

597597
// set up the "slimgui" symbol for it immediately
598+
// BCH 11/7/2025: note this symbol is now protected in SLiM_ConfigureContext()
598599
community->simulation_constants_->InitializeConstantSymbolEntry(slimgui->SymbolTableEntry());
599600
}
600601
}

VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ development head (in the master branch):
1616
add mtext() call to Plot, for drawing text in the margins outside the plot area
1717
add rowSums() and colSums() functions to Eidos, for use with matrices as a faster alternative to apply()
1818
add the PCG random number generator, switch to pcg32_fast and pcg64_fast, remove all use of the old taus2 and MT19937-64 generators; note this completely breaks backward reproducibility
19+
fix various bugs involving conflicts between defined constants and other symbols, including #573 and #574; this sets new definition rules that could break some existing scripts (but is unlikely to)
1920

2021

2122
version 5.1 (Eidos version 4.1):

core/chromosome.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ Mutation *Chromosome::ApplyMutationCallbacks(Mutation *p_mut, Haplosome *p_haplo
11291129
// We can use that method because we know the lifetime of the symbol table is shorter than that of
11301130
// the value objects, and we know that the values we are setting here will not change (the objects
11311131
// referred to by the values may change, but the values themselves will not change).
1132+
// BCH 11/7/2025: note these symbols are now protected in SLiM_ConfigureContext()
11321133
if (mutation_callback->contains_mut_)
11331134
{
11341135
local_mut.StackAllocated(); // prevent Eidos_intrusive_ptr from trying to delete this

core/community.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,19 @@ void Community::AllSpecies_RunInitializeCallbacks(void)
23102310

23112311
// set up global symbols for all species, and for ourselves
23122312
for (Species *species : all_species_)
2313-
simulation_constants_->InitializeConstantSymbolEntry(species->SymbolTableEntry());
2313+
{
2314+
EidosSymbolTableEntry &symbol_entry = species->SymbolTableEntry();
2315+
EidosGlobalStringID symbol_id = symbol_entry.first;
2316+
std::string symbol_string = EidosStringRegistry::StringForGlobalStringID(symbol_id);
2317+
2318+
if (simulation_constants_->ContainsSymbol(symbol_id))
2319+
EIDOS_TERMINATION << "ERROR (Community::AllSpecies_RunInitializeCallbacks): A species with name '" << symbol_string << "' cannot be defined because that name is already in use." << EidosTerminate();
2320+
if (!Eidos_GoodSymbolForDefine(symbol_string) && (symbol_string != "sim"))
2321+
EIDOS_TERMINATION << "ERROR (Community::AllSpecies_RunInitializeCallbacks): A species with name '" << symbol_string << "' cannot be defined because the symbol '" << symbol_string << "' is reserved." << EidosTerminate();
2322+
2323+
simulation_constants_->InitializeConstantSymbolEntry(symbol_entry);
2324+
}
2325+
23142326
simulation_constants_->InitializeConstantSymbolEntry(SymbolTableEntry());
23152327

23162328
// we're done with the initialization tick, so remove the zero-tick functions

0 commit comments

Comments
 (0)