[Avida-SVN] r2642 - in branches/collect: documentation source/cpu source/main source/script source/tools tests/bgs_dyn_mutrates_births tests/bgs_dyn_mutrates_fit tests/bgs_dyn_mutrates_rank tests/sex/config tests/sex-asex/config tests/sex-modular/config
blwalker at myxo.css.msu.edu
blwalker at myxo.css.msu.edu
Wed Jun 11 07:47:14 PDT 2008
Author: blwalker
Date: 2008-06-11 10:47:14 -0400 (Wed, 11 Jun 2008)
New Revision: 2642
Modified:
branches/collect/documentation/code_standards.html
branches/collect/source/cpu/cHardwareCPU.cc
branches/collect/source/cpu/cHardwareCPU.h
branches/collect/source/main/cAvidaConfig.h
branches/collect/source/main/cDeme.cc
branches/collect/source/main/cDeme.h
branches/collect/source/main/cEnvironment.cc
branches/collect/source/main/cPhenotype.cc
branches/collect/source/main/cPopulation.cc
branches/collect/source/main/cPopulation.h
branches/collect/source/main/cReactionResult.cc
branches/collect/source/main/cReactionResult.h
branches/collect/source/script/ASTree.cc
branches/collect/source/script/ASTree.h
branches/collect/source/script/AvidaScript.h
branches/collect/source/script/cASTVisitor.h
branches/collect/source/script/cDumpASTVisitor.cc
branches/collect/source/script/cDumpASTVisitor.h
branches/collect/source/script/cParser.cc
branches/collect/source/script/cSemanticASTVisitor.cc
branches/collect/source/script/cSemanticASTVisitor.h
branches/collect/source/script/cSymbolTable.cc
branches/collect/source/script/cSymbolTable.h
branches/collect/source/tools/cConstSchedule.cc
branches/collect/source/tools/cConstSchedule.h
branches/collect/source/tools/cDemeProbSchedule.cc
branches/collect/source/tools/cDemeProbSchedule.h
branches/collect/source/tools/cIntegratedSchedule.cc
branches/collect/source/tools/cIntegratedSchedule.h
branches/collect/source/tools/cMerit.h
branches/collect/source/tools/cProbDemeProbSchedule.cc
branches/collect/source/tools/cProbDemeProbSchedule.h
branches/collect/source/tools/cProbSchedule.cc
branches/collect/source/tools/cProbSchedule.h
branches/collect/source/tools/cSchedule.h
branches/collect/tests/bgs_dyn_mutrates_births/test_list
branches/collect/tests/bgs_dyn_mutrates_fit/test_list
branches/collect/tests/bgs_dyn_mutrates_rank/test_list
branches/collect/tests/sex-asex/config/avida.cfg
branches/collect/tests/sex-modular/config/avida.cfg
branches/collect/tests/sex/config/avida.cfg
Log:
Porting r2392:2407 from development to collect branch
Resolved purely textual conflicts in the cReactionResult files.
Yes, I know, I should be able to merge everything all at once and rejoice in one giant resolve-conflicts-and-commit. But Bad Things have happened to me in the past doing this, and now I am superstitious and shy of doing so. So you'll just have to put up with the spam; I assure you that I am trying to minimize it.
Modified: branches/collect/documentation/code_standards.html
===================================================================
--- branches/collect/documentation/code_standards.html 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/documentation/code_standards.html 2008-06-11 14:47:14 UTC (rev 2642)
@@ -281,6 +281,34 @@
</ul>
+<p> </p>
+<h2>Class Dependency Guidelines</h2>
+<div style="margin-left: 10px">
+ <p>
+ Some groupings of classes should maintain important limitations with respect
+ to class dependency.
+ </p>
+
+ <h3>Tools Classes</h3>
+ <div style="margin-left: 10px">
+ <p>
+ All classes developed as general utility classes should be placed within the
+ <kbd style="color: #008844">source/tools</kbd> directory. These classes
+ should have no dependencies that extend outside of this directory.
+ </p>
+ </div>
+
+ <h3>STL Usage</h3>
+ <div style="margin-left: 10px">
+ <p>
+ Usage of the Standard Template Library should be very limited. A number of
+ these templates have unspecified orderings that can vary across platforms,
+ affecting consistency. Where possible, it is greatly preferred to use the
+ local tools classes.
+ </p>
+ </div>
+</div>
+
<hr />
<p><a href="index.html">Return to the Index</a></p>
Modified: branches/collect/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/cpu/cHardwareCPU.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -377,8 +377,14 @@
tInstLibEntry<tMethod>("s-regulate", &cHardwareCPU::Inst_SenseRegulate),
tInstLibEntry<tMethod>("numberate", &cHardwareCPU::Inst_Numberate),
tInstLibEntry<tMethod>("numberate-24", &cHardwareCPU::Inst_Numberate24),
+
+ // Bit Consensus
tInstLibEntry<tMethod>("bit-cons", &cHardwareCPU::Inst_BitConsensus),
tInstLibEntry<tMethod>("bit-cons-24", &cHardwareCPU::Inst_BitConsensus24),
+ tInstLibEntry<tMethod>("if-cons", &cHardwareCPU::Inst_IfConsensus, 0, "Execute next instruction if ?BX? in consensus, else skip it"),
+ tInstLibEntry<tMethod>("if-cons-24", &cHardwareCPU::Inst_IfConsensus24, 0, "Execute next instruction if ?BX[0:23]? in consensus , else skip it"),
+ tInstLibEntry<tMethod>("if-less-cons", &cHardwareCPU::Inst_IfLessConsensus, 0, "Execute next instruction if Count(?BX?) < Count(?CX?), else skip it"),
+ tInstLibEntry<tMethod>("if-less-cons-24", &cHardwareCPU::Inst_IfLessConsensus24, 0, "Execute next instruction if Count(?BX[0:23]?) < Count(?CX[0:23]?), else skip it"),
// Energy usage
tInstLibEntry<tMethod>("double-energy-usage", &cHardwareCPU::Inst_DoubleEnergyUsage, nInstFlag::STALL),
@@ -4781,40 +4787,69 @@
return code;
}
-/*!
- Sets BX to 1 if >=50% of the bits in the specified register places
- are 1's and zero otherwise.
-*/
+//// Copied from cHardwareExperimental -- @JEB
+static const unsigned int CONSENSUS = (sizeof(int) * 8) / 2;
+static const unsigned int CONSENSUS24 = 12;
+static const unsigned int MASK24 = 0xFFFFFF;
+
+inline unsigned int cHardwareCPU::BitCount(unsigned int value) const
+{
+ const unsigned int w = value - ((value >> 1) & 0x55555555);
+ const unsigned int x = (w & 0x33333333) + ((w >> 2) & 0x33333333);
+ const unsigned int bit_count = ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
+ return bit_count;
+}
+
bool cHardwareCPU::Inst_BitConsensus(cAvidaContext& ctx)
{
- return BitConsensus(ctx, sizeof(int) * 8);
+ const int reg_used = FindModifiedRegister(REG_BX);
+ const int op1 = FindModifiedNextRegister(reg_used);
+ GetRegister(reg_used) = (BitCount(GetRegister(op1)) >= CONSENSUS) ? 1 : 0;
+ return true;
}
-// Looks at only the lower 24 bits
bool cHardwareCPU::Inst_BitConsensus24(cAvidaContext& ctx)
{
- return BitConsensus(ctx, 24);
+ const int reg_used = FindModifiedRegister(REG_BX);
+ const int op1 = FindModifiedNextRegister(reg_used);
+ GetRegister(reg_used) = (BitCount(GetRegister(op1) & MASK24) >= CONSENSUS24) ? 1 : 0;
+ return true;
}
-bool cHardwareCPU::BitConsensus(cAvidaContext& ctx, const unsigned int num_bits)
+bool cHardwareCPU::Inst_IfConsensus(cAvidaContext& ctx)
{
- assert(num_bits <= sizeof(int) * 8);
+ const int op1 = FindModifiedRegister(REG_BX);
+ if (BitCount(GetRegister(op1)) < CONSENSUS) IP().Advance();
+ return true;
+}
- const int reg_used = FindModifiedRegister(REG_BX);
- int reg_val = GetRegister(REG_CX);
- unsigned int bits_on = 0;
-
- for (unsigned int i = 0; i < num_bits; i++)
- {
- bits_on += (reg_val & 1);
- reg_val >>= 1;
- }
-
- GetRegister(reg_used) = ( bits_on >= (sizeof(int) * 8)/2 ) ? 1 : 0;
- return true;
+bool cHardwareCPU::Inst_IfConsensus24(cAvidaContext& ctx)
+{
+ const int op1 = FindModifiedRegister(REG_BX);
+ if (BitCount(GetRegister(op1) & MASK24) < CONSENSUS24) IP().Advance();
+ return true;
}
+bool cHardwareCPU::Inst_IfLessConsensus(cAvidaContext& ctx)
+{
+ const int op1 = FindModifiedRegister(REG_BX);
+ const int op2 = FindModifiedNextRegister(op1);
+ if (BitCount(GetRegister(op1)) >= BitCount(GetRegister(op2))) IP().Advance();
+ return true;
+}
+
+bool cHardwareCPU::Inst_IfLessConsensus24(cAvidaContext& ctx)
+{
+ const int op1 = FindModifiedRegister(REG_BX);
+ const int op2 = FindModifiedNextRegister(op1);
+ if (BitCount(GetRegister(op1) & MASK24) >= BitCount(GetRegister(op2) & MASK24)) IP().Advance();
+ return true;
+}
+
+//// End copied from cHardwareExperimental
+
+
/*! Send a message to the organism that is currently faced by this cell,
where the label field of sent message is from register ?BX?, and the data field
is from register ~?BX?.
Modified: branches/collect/source/cpu/cHardwareCPU.h
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/cpu/cHardwareCPU.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -581,13 +581,15 @@
void NextPromoter();
int Numberate(int _pos, int _dir, int _num_bits = 0);
-
//// Bit consensus functions ////
+ inline unsigned int BitCount(unsigned int value) const;
bool Inst_BitConsensus(cAvidaContext& ctx);
bool Inst_BitConsensus24(cAvidaContext& ctx);
- bool BitConsensus(cAvidaContext& ctx, const unsigned int num_bits);
-
-
+ bool Inst_IfConsensus(cAvidaContext& ctx);
+ bool Inst_IfConsensus24(cAvidaContext& ctx);
+ bool Inst_IfLessConsensus(cAvidaContext& ctx);
+ bool Inst_IfLessConsensus24(cAvidaContext& ctx);
+
//// Messaging ////
bool Inst_SendMessage(cAvidaContext& ctx);
bool Inst_RetrieveMessage(cAvidaContext& ctx);
Modified: branches/collect/source/main/cAvidaConfig.h
===================================================================
--- branches/collect/source/main/cAvidaConfig.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/main/cAvidaConfig.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -297,7 +297,6 @@
CONFIG_ADD_GROUP(DEME_GROUP, "Demes and Germlines");
CONFIG_ADD_VAR(NUM_DEMES, int, 1, "Number of independent groups in the\npopulation (default=1).");
CONFIG_ADD_VAR(DEMES_USE_GERMLINE, int, 0, "Whether demes use a distinct germline (default=0).");
- CONFIG_ADD_VAR(DEMES_HAVE_MERIT, int, 0, "Whether demes have merit (default=0).");
CONFIG_ADD_VAR(DEMES_PREVENT_STERILE, int, 0, "Whether to prevent sterile demes from\nreplicating (default=0).");
CONFIG_ADD_VAR(DEMES_RESET_RESOURCES, int, 0, "Reset resources in demes on replication. \n0 = reset both demes \n1 = reset target deme \n2 = deme resources remain unchanged\n");
CONFIG_ADD_VAR(DEMES_REPLICATE_SIZE, int, 1, "Number of identical organisms to create or copy from the\nsource deme to the target deme (default=1).");
Modified: branches/collect/source/main/cDeme.cc
===================================================================
--- branches/collect/source/main/cDeme.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/main/cDeme.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -139,6 +139,7 @@
we need to rotate the heritable merit to the current merit.
*/
void cDeme::UpdateDemeMerit() {
+ assert(_next_merit.GetDouble()>=1.0);
_current_merit = _next_merit;
_next_merit = 1.0;
}
@@ -149,6 +150,7 @@
void cDeme::UpdateDemeMerit(cDeme& source) {
_current_merit = source.GetHeritableDemeMerit();
_next_merit = 1.0;
+ assert(_current_merit.GetDouble()>=1.0);
}
Modified: branches/collect/source/main/cDeme.h
===================================================================
--- branches/collect/source/main/cDeme.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/main/cDeme.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -106,6 +106,8 @@
const cMerit& GetDemeMerit() const { return _current_merit; }
//! Retrieve this deme's heritable merit.
const cMerit& GetHeritableDemeMerit() const { return _next_merit; }
+
+ bool HasDemeMerit() const { return _current_merit.GetDouble() != 1.0; }
// -= Update support =-
//! Called once, at the end of every update.
Modified: branches/collect/source/main/cEnvironment.cc
===================================================================
--- branches/collect/source/main/cEnvironment.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/main/cEnvironment.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -1044,23 +1044,26 @@
double deme_bonus = cur_process->GetDemeFraction() * consumed * cur_process->GetValue();
double bonus = (1.0 - cur_process->GetDemeFraction()) * consumed * cur_process->GetValue();
- result.DemeBonus(deme_bonus);
-
switch (cur_process->GetType()) {
case nReaction::PROCTYPE_ADD:
result.AddBonus(bonus, reaction_id);
+ result.AddDemeBonus(deme_bonus);
break;
case nReaction::PROCTYPE_MULT:
result.MultBonus(bonus);
+ result.AddDemeBonus(deme_bonus);
break;
case nReaction::PROCTYPE_POW:
- result.MultBonus( pow(2.0, bonus) );
+ result.MultBonus(pow(2.0, bonus));
+ result.AddDemeBonus(pow(2.0, deme_bonus));
break;
case nReaction::PROCTYPE_LIN:
- result.AddBonus( bonus * task_count, reaction_id);
+ result.AddBonus(bonus * task_count, reaction_id);
+ assert(deme_bonus == 0.0);
break;
case nReaction::PROCTYPE_ENERGY:
result.AddEnergy(bonus);
+ assert(deme_bonus == 0.0);
break;
case nReaction::PROCTYPE_ENZYME: //@JEB
{
Modified: branches/collect/source/main/cPhenotype.cc
===================================================================
--- branches/collect/source/main/cPhenotype.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/main/cPhenotype.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -1055,8 +1055,11 @@
cur_bonus += result.GetAddBonus();
// Update deme merit.
- if(taskctx.GetOrganism()->GetOrgInterface().GetDeme()) {
- taskctx.GetOrganism()->GetOrgInterface().GetDeme()->UpdateHeritableDemeMerit(result.GetDemeBonus());
+ if(taskctx.GetOrganism()->GetOrgInterface().GetDeme() && result.GetActiveDeme()) {
+ cDeme* deme = taskctx.GetOrganism()->GetOrgInterface().GetDeme();
+ double deme_bonus = 1 + result.GetAddDemeBonus();
+ deme_bonus *= result.GetMultDemeBonus();
+ deme->UpdateHeritableDemeMerit(deme_bonus);
}
// Update the energy bonus
Modified: branches/collect/source/main/cPopulation.cc
===================================================================
--- branches/collect/source/main/cPopulation.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/main/cPopulation.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -133,6 +133,7 @@
// Allocate the cells, resources, and market.
cell_array.ResizeClear(num_cells);
+ empty_cell_id_array.ResizeClear(cell_array.GetSize());
market.Resize(MARKET_SIZE);
// Setup the cells. Do things that are not dependent upon topology here.
@@ -274,6 +275,15 @@
}
+inline void cPopulation::AdjustSchedule(const cPopulationCell& cell, const cMerit& merit)
+{
+ const int deme_id = cell.GetDemeID();
+ const cDeme& deme = deme_array[deme_id];
+ schedule->Adjust(cell.GetID(), deme.HasDemeMerit() ? (merit * deme.GetDemeMerit()) : merit, cell.GetDemeID());
+}
+
+
+
// Activate the child, given information from the parent.
// Return true if parent lives through this process.
@@ -356,7 +366,7 @@
delete test_cpu;
}
}
- schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit(), deme_array[parent_cell.GetDemeID()]);
+ AdjustSchedule(parent_cell, parent_phenotype.GetMerit());
// In a local run, face the child toward the parent.
const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
@@ -489,7 +499,7 @@
m_world->GetClassificationManager().AdjustGenotype(*in_genotype);
// Initialize the time-slice for this new organism.
- schedule->Adjust(target_cell.GetID(), in_organism->GetPhenotype().GetMerit(), deme_array[target_cell.GetDemeID()]);
+ AdjustSchedule(target_cell, in_organism->GetPhenotype().GetMerit());
// Special handling for certain birth methods.
if (m_world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
@@ -684,7 +694,7 @@
else organism->GetPhenotype().SetToDelete();
// Alert the scheduler that this cell has a 0 merit.
- schedule->Adjust(in_cell.GetID(), cMerit(0), deme_array[in_cell.GetDemeID()]);
+ AdjustSchedule(in_cell, cMerit(0));
// Update the archive (note: genotype adjustment may be defered)
m_world->GetClassificationManager().AdjustGenotype(*genotype);
@@ -822,9 +832,9 @@
cOrganism * org2 = cell2.RemoveOrganism();
if (org2 != NULL) {
cell1.InsertOrganism(org2);
- schedule->Adjust(cell1.GetID(), org2->GetPhenotype().GetMerit(), deme_array[cell1.GetDemeID()]);
+ AdjustSchedule(cell1, org2->GetPhenotype().GetMerit());
} else {
- schedule->Adjust(cell1.GetID(), cMerit(0), deme_array[cell1.GetDemeID()]);
+ AdjustSchedule(cell1, cMerit(0));
}
if (org1 != NULL) {
cell2.InsertOrganism(org1);
@@ -840,9 +850,9 @@
cAvidaContext& ctx = m_world->GetDefaultContext();
org1->DoOutput(ctx,0);
}
- schedule->Adjust(cell2.GetID(), org1->GetPhenotype().GetMerit(), deme_array[cell2.GetDemeID()]);
+ AdjustSchedule(cell2, org1->GetPhenotype().GetMerit());
} else {
- schedule->Adjust(cell2.GetID(), cMerit(0), deme_array[cell2.GetDemeID()]);
+ AdjustSchedule(cell2, cMerit(0));
}
}
@@ -1217,11 +1227,10 @@
SeedDeme(source_deme, target_deme);
}
- // If we're using deme merit, the source's merit must be transferred to the target.
- if(m_world->GetConfig().DEMES_HAVE_MERIT.Get()) {
- target_deme.UpdateDemeMerit(source_deme);
- source_deme.UpdateDemeMerit();
- }
+ // The source's merit must be transferred to the target, and then the source has
+ // rotate its merits.
+ target_deme.UpdateDemeMerit(source_deme);
+ source_deme.UpdateDemeMerit();
bool source_deme_resource_reset(true), target_deme_resource_reset(true);
switch(m_world->GetConfig().DEMES_RESET_RESOURCES.Get()) {
@@ -2180,6 +2189,26 @@
}
// @AWC If not migrating try out global/full-deme birth methods first...
else if (birth_method == POSITION_CHILD_FULL_SOUP_RANDOM) {
+
+ // @JEB Look randomly within empty cells, if requested
+ if (m_world->GetConfig().PREFER_EMPTY.Get()) {
+
+ // Note: empty_cell_id_array was resized to be large enough to hold
+ // all cells in the cPopulation when it was created. Using functions
+ // that resize it (like Push) will slow this code down considerably.
+ // Instead, we keep track of how much of this memory we are using.
+
+ int num_empty_cells = 0;
+ for (int i=0; i<cell_array.GetSize(); i++) {
+ if (GetCell(i).IsOccupied() == false) empty_cell_id_array[num_empty_cells++] = i;
+ }
+
+ if (num_empty_cells > 0) {
+ int out_pos = m_world->GetRandom().GetUInt(num_empty_cells);
+ return GetCell(empty_cell_id_array[out_pos]);
+ }
+ }
+
int out_pos = m_world->GetRandom().GetUInt(cell_array.GetSize());
while (parent_ok == false && out_pos == parent_cell.GetID()) {
out_pos = m_world->GetRandom().GetUInt(cell_array.GetSize());
@@ -2195,18 +2224,39 @@
return *out_cell;
}
else if (birth_method == POSITION_CHILD_DEME_RANDOM) {
-
const int deme_id = parent_cell.GetDemeID();
const int deme_size = deme_array[deme_id].GetSize();
+ deme_array[deme_id].IncBirthCount();
+
+ // @JEB Look randomly within empty cells, if requested
+ if (m_world->GetConfig().PREFER_EMPTY.Get()) {
+
+ // Note: empty_cell_id_array was resized to be large enough to hold
+ // all cells in the cPopulation when it was created. Using functions
+ // that resize it (like Push) will slow this code down considerably.
+ // Instead, we keep track of how much of this memory we are using.
+
+ int num_empty_cells = 0;
+ for (int i=0; i<deme_array[deme_id].GetSize(); i++) {
+ int cell_id = deme_array[deme_id].GetCellID(i);
+ if (!GetCell(cell_id).IsOccupied()) /*return cell;*/ empty_cell_id_array[num_empty_cells++] = cell_id;
+ }
+
+ if (num_empty_cells > 0) {
+ int out_pos = m_world->GetRandom().GetUInt(num_empty_cells);
+ return GetCell(empty_cell_id_array[out_pos]);
+ }
+ }
+
int out_pos = m_world->GetRandom().GetUInt(deme_size);
int out_cell_id = deme_array[deme_id].GetCellID(out_pos);
+
while (parent_ok == false && out_cell_id == parent_cell.GetID()) {
out_pos = m_world->GetRandom().GetUInt(deme_size);
out_cell_id = deme_array[deme_id].GetCellID(out_pos);
}
- deme_array[deme_id].IncBirthCount();
return GetCell(out_cell_id);
}
else if (birth_method == POSITION_CHILD_PARENT_FACING) {
@@ -2927,7 +2977,7 @@
InjectGenotype( current_cell, (*it).genotype );
cPhenotype & phenotype = GetCell(current_cell).GetOrganism()->GetPhenotype();
if ( (*it).merit > 0) phenotype.SetMerit( cMerit((*it).merit) );
- schedule->Adjust(current_cell, phenotype.GetMerit(), deme_array[GetCell(current_cell).GetDemeID()]);
+ AdjustSchedule(GetCell(current_cell), phenotype.GetMerit());
int lineage_label = 0;
LineageSetupOrganism(GetCell(current_cell).GetOrganism(),
@@ -3017,7 +3067,7 @@
phenotype.SetNeutralMetric(neutral);
if (merit > 0) phenotype.SetMerit(cMerit(merit));
- schedule->Adjust(cell_id, phenotype.GetMerit(), deme_array[GetCell(cell_id).GetDemeID()]);
+ AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
LineageSetupOrganism(GetCell(cell_id).GetOrganism(), 0, lineage_label);
@@ -3055,7 +3105,6 @@
return cell_array[in_num];
}
-
void cPopulation::UpdateResources(const tArray<double> & res_change)
{
resource_count.Modify(res_change);
@@ -3481,7 +3530,7 @@
if (new_merit <= old_merit) {
phenotype.SetIsDonorCur(); }
else { phenotype.SetIsReceiver(); }
- schedule->Adjust(cell_id, phenotype.GetMerit(), deme_array[GetCell(cell_id).GetDemeID()]);
+ AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
return true;
}
Modified: branches/collect/source/main/cPopulation.h
===================================================================
--- branches/collect/source/main/cPopulation.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/main/cPopulation.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -90,6 +90,7 @@
cWorld* m_world;
cSchedule* schedule; // Handles allocation of CPU cycles
tArray<cPopulationCell> cell_array; // Local cells composing the population
+ tArray<int> empty_cell_id_array; // Used for PREFER_EMPTY birth methods
cResourceCount resource_count; // Global resources available
cBirthChamber birth_chamber; // Global birth chamber.
tArray<tList<cSaleItem> > market; // list of lists of items for sale, each list goes with 1 label
@@ -143,6 +144,9 @@
// Must be called to activate *any* organism in the population.
void ActivateOrganism(cAvidaContext& ctx, cOrganism* in_organism, cPopulationCell& target_cell);
+
+ inline void AdjustSchedule(const cPopulationCell& cell, const cMerit& merit);
+
cPopulation(); // @not_implemented
cPopulation(const cPopulation&); // @not_implemented
Modified: branches/collect/source/main/cReactionResult.cc
===================================================================
--- branches/collect/source/main/cReactionResult.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/main/cReactionResult.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -45,7 +45,9 @@
, sterilize(false)
, active_reaction(false)
, used_env_resource(true)
- , deme_bonus(0.0)
+ , deme_add_bonus(0.0)
+ , deme_mult_bonus(1.0)
+ , active_deme_reaction(false)
{
}
@@ -138,12 +140,19 @@
bonus_mult *= value;
}
-void cReactionResult::DemeBonus(double value)
+void cReactionResult::AddDemeBonus(double value)
{
ActivateReaction();
- deme_bonus += value;
+ active_deme_reaction = true;
+ deme_add_bonus += value;
}
+void cReactionResult::MultDemeBonus(double value)
+{
+ ActivateReaction();
+ active_deme_reaction = true;
+ deme_mult_bonus *= value;
+}
void cReactionResult::AddInst(int id)
{
Modified: branches/collect/source/main/cReactionResult.h
===================================================================
--- branches/collect/source/main/cReactionResult.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/main/cReactionResult.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -49,7 +49,9 @@
bool active_reaction;
bool used_env_resource;
- double deme_bonus; //!< Bonus applied to the deme as a result of this reaction.
+ double deme_add_bonus; //!< Additive bonus applied to the deme as a result of this reaction.
+ double deme_mult_bonus; //!< Multiplicative bonus applied to the deme as a result of this reaction.
+ bool active_deme_reaction; //!< Whether this reaction result includes a deme merit component.
inline void ActivateReaction();
@@ -62,6 +64,7 @@
~cReactionResult() { ; }
bool GetActive() { return active_reaction; }
+ bool GetActiveDeme() { return active_deme_reaction; }
void Consume(int id, double num, bool is_env_resource);
void Produce(int id, double num);
@@ -74,7 +77,8 @@
void AddEnergy(double value);
void AddBonus(double value, int id);
void MultBonus(double value);
- void DemeBonus(double value);
+ void AddDemeBonus(double value);
+ void MultDemeBonus(double value);
void AddInst(int id);
@@ -94,7 +98,8 @@
tArray<int>& GetInstArray() { return insts_triggered; }
bool UsedEnvResource() { return used_env_resource; }
bool IsEnvResource() { return used_env_resource; }
- double GetDemeBonus() { return deme_bonus; }
+ double GetAddDemeBonus() { return deme_add_bonus; }
+ double GetMultDemeBonus() { return deme_mult_bonus; }
};
Modified: branches/collect/source/script/ASTree.cc
===================================================================
--- branches/collect/source/script/ASTree.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/ASTree.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -47,6 +47,8 @@
void cASTFunctionCall::Accept(cASTVisitor& visitor) { visitor.visitFunctionCall(*this); }
void cASTLiteral::Accept(cASTVisitor& visitor) { visitor.visitLiteral(*this); }
void cASTLiteralArray::Accept(cASTVisitor& visitor) { visitor.visitLiteralArray(*this); }
+void cASTObjectCall::Accept(cASTVisitor& visitor) { visitor.visitObjectCall(*this); }
+void cASTObjectReference::Accept(cASTVisitor& visitor) { visitor.visitObjectReference(*this); }
void cASTVariableReference::Accept(cASTVisitor& visitor) { visitor.visitVariableReference(*this); }
void cASTUnpackTarget::Accept(cASTVisitor& visitor) { visitor.visitUnpackTarget(*this); }
@@ -57,3 +59,9 @@
tListIterator<cASTNode> it(m_nodes);
while ((node = it.Next())) delete node;
}
+
+cASTFunctionDefinition::~cASTFunctionDefinition()
+{
+ delete m_args;
+ delete m_code;
+}
Modified: branches/collect/source/script/ASTree.h
===================================================================
--- branches/collect/source/script/ASTree.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/ASTree.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -113,6 +113,8 @@
class cASTFunctionCall;
class cASTLiteral;
class cASTLiteralArray;
+class cASTObjectCall;
+class cASTObjectReference;
class cASTVariableReference;
class cASTUnpackTarget;
@@ -153,9 +155,10 @@
public:
cASTArgumentList(const cASFilePosition& fp) : cASTNode(fp) { ; }
- ~cASTArgumentList() { ; }
+ ~cASTArgumentList() { while (m_nodes.GetSize()) delete m_nodes.Pop(); }
inline void AddNode(cASTNode* n) { m_nodes.PushRear(n); }
+ inline int GetSize() const { return m_nodes.GetSize(); }
inline tListIterator<cASTNode> Iterator() { return tListIterator<cASTNode>(m_nodes); }
void Accept(cASTVisitor& visitor);
@@ -303,16 +306,16 @@
public:
cASTFunctionDefinition(const cASFilePosition& fp, ASType_t type, const cString& name, cASTVariableDefinitionList* args)
: cASTNode(fp), m_type(type), m_name(name), m_args(args), m_code(NULL) { ; }
+ ~cASTFunctionDefinition();
- inline ASType_t GetType() { return m_type; }
+ inline ASType_t GetType() const { return m_type; }
inline const cString& GetName() { return m_name; }
inline cASTVariableDefinitionList* GetArguments() { return m_args; }
+ inline void ClearArguments() { m_args = NULL; }
inline void SetCode(cASTNode* code) { m_code = code; }
inline cASTNode* GetCode() { return m_code; }
- inline bool IsDefinition() { return (m_code); }
-
void Accept(cASTVisitor& visitor);
};
@@ -321,22 +324,26 @@
{
private:
ASType_t m_type;
- cString m_var;
+ cString m_name;
cASTNode* m_assign;
cASTArgumentList* m_dims;
+ int m_id;
public:
- cASTVariableDefinition(const cASFilePosition& fp, ASType_t type, const cString& var)
- : cASTNode(fp), m_type(type), m_var(var), m_assign(NULL), m_dims(NULL) { ; }
+ cASTVariableDefinition(const cASFilePosition& fp, ASType_t type, const cString& name)
+ : cASTNode(fp), m_type(type), m_name(name), m_assign(NULL), m_dims(NULL), m_id(-1) { ; }
~cASTVariableDefinition() { delete m_assign; delete m_dims; }
- inline ASType_t GetType() { return m_type; }
- inline const cString& GetVariable() { return m_var; }
+ inline ASType_t GetType() const { return m_type; }
+ inline const cString& GetName() { return m_name; }
inline void SetAssignmentExpression(cASTNode* assign) { delete m_assign; m_assign = assign; }
inline cASTNode* GetAssignmentExpression() { return m_assign; }
inline void SetDimensions(cASTArgumentList* dims) { delete m_dims; m_dims = dims; }
inline cASTArgumentList* GetDimensions() { return m_dims; }
+ inline int GetVarID() const { return m_id; }
+ inline void SetVar(int in_id) { m_id = in_id; }
+
void Accept(cASTVisitor& visitor);
};
@@ -352,6 +359,7 @@
inline void AddNode(cASTVariableDefinition* n) { m_nodes.PushRear(n); }
inline tListIterator<cASTVariableDefinition> Iterator() { return tListIterator<cASTVariableDefinition>(m_nodes); }
+ inline cASTVariableDefinition* GetFirst() { return m_nodes.GetFirst(); }
inline int GetSize() const { return m_nodes.GetSize(); }
@@ -419,21 +427,28 @@
class cASTFunctionCall : public cASTNode
{
private:
- cASTNode* m_target;
+ cString m_name;
cASTArgumentList* m_args;
ASType_t m_type;
+ int m_id;
+ bool m_global;
public:
- cASTFunctionCall(const cASFilePosition& fp, cASTNode* target)
- : cASTNode(fp), m_target(target), m_args(NULL), m_type(AS_TYPE_INVALID) { ; }
+ cASTFunctionCall(const cASFilePosition& fp, const cString& name)
+ : cASTNode(fp), m_name(name), m_args(NULL), m_type(AS_TYPE_INVALID), m_id(-1), m_global(false) { ; }
~cASTFunctionCall() { delete m_args; }
- cASTNode* GetTarget() { return m_target; }
+ const cString& GetName() const { return m_name; }
+
void SetArguments(cASTArgumentList* args) { delete m_args; m_args = args; }
cASTArgumentList* GetArguments() { return m_args; }
ASType_t GetType() const { return m_type; }
inline void SetType(ASType_t type) { m_type = type; }
+
+ inline int GetFuncID() const { return m_id; }
+ inline bool IsFuncGlobal() const { return m_global; }
+ inline void SetFunc(int in_id, bool global) { m_id = in_id; m_global = global; }
bool HasArguments() const { return (m_args); }
@@ -460,14 +475,15 @@
class cASTLiteralArray : public cASTNode
{
private:
- cASTNode* m_value;
+ cASTArgumentList* m_values;
bool m_is_matrix;
public:
- cASTLiteralArray(const cASFilePosition& fp, cASTNode* v, bool is_mat) : cASTNode(fp), m_value(v), m_is_matrix(is_mat) { ; }
- ~cASTLiteralArray() { delete m_value; }
+ cASTLiteralArray(const cASFilePosition& fp, cASTArgumentList* v, bool is_mat)
+ : cASTNode(fp), m_values(v), m_is_matrix(is_mat) { ; }
+ ~cASTLiteralArray() { delete m_values; }
- inline cASTNode* GetValue() { return m_value; }
+ inline cASTArgumentList* GetValues() { return m_values; }
inline bool IsMatrix() const { return m_is_matrix; }
ASType_t GetType() const { return m_is_matrix ? AS_TYPE_MATRIX : AS_TYPE_ARRAY; }
@@ -476,6 +492,57 @@
};
+class cASTObjectCall : public cASTNode
+{
+private:
+ cASTNode* m_object;
+ cString m_name;
+ cASTArgumentList* m_args;
+ ASType_t m_type;
+
+public:
+ cASTObjectCall(const cASFilePosition& fp, cASTNode* object, const cString& name)
+ : cASTNode(fp), m_object(object), m_name(name), m_args(NULL), m_type(AS_TYPE_INVALID) { ; }
+ ~cASTObjectCall() { delete m_object; delete m_args; }
+
+ cASTNode* GetObject() { return m_object; }
+ const cString& GetName() const { return m_name; }
+
+ void SetArguments(cASTArgumentList* args) { delete m_args; m_args = args; }
+ cASTArgumentList* GetArguments() { return m_args; }
+
+ ASType_t GetType() const { return m_type; }
+ inline void SetType(ASType_t type) { m_type = type; }
+
+
+ bool HasArguments() const { return (m_args); }
+
+ void Accept(cASTVisitor& visitor);
+};
+
+
+class cASTObjectReference : public cASTNode
+{
+private:
+ cASTNode* m_object;
+ cString m_name;
+ ASType_t m_type;
+
+public:
+ cASTObjectReference(const cASFilePosition& fp, cASTNode* object, const cString& name)
+ : cASTNode(fp), m_object(object), m_name(name) { ; }
+ ~cASTObjectReference() { delete m_object; }
+
+ cASTNode* GetObject() { return m_object; }
+ inline const cString& GetName() { return m_name; }
+
+ ASType_t GetType() const { return m_type; }
+ inline void SetType(ASType_t type) { m_type = type; }
+
+ void Accept(cASTVisitor& visitor);
+};
+
+
class cASTVariableReference : public cASTNode
{
private:
Modified: branches/collect/source/script/AvidaScript.h
===================================================================
--- branches/collect/source/script/AvidaScript.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/AvidaScript.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -112,12 +112,24 @@
typedef enum eASSemanticErrors {
AS_SEMANTIC_WARN_LOSS_OF_PRECISION,
+ AS_SEMANTIC_WARN_NO_DIMENSIONS,
+ AS_SEMANTIC_WARN_NO_RETURN,
AS_SEMANTIC_WARN_UNREACHABLE,
AS_SEMANTIC_WARN__LAST,
+ AS_SEMANTIC_ERR_ARGUMENT_DEFAULT_REQUIRED,
+ AS_SEMANTIC_ERR_ARGUMENT_MISSING_REQUIRED,
AS_SEMANTIC_ERR_CANNOT_CAST,
+ AS_SEMANTIC_ERR_FUNCTION_CALL_SIGNATURE_MISMATCH,
+ AS_SEMANTIC_ERR_FUNCTION_REDEFINITION,
+ AS_SEMANTIC_ERR_FUNCTION_RTYPE_MISMATCH,
+ AS_SEMANTIC_ERR_FUNCTION_SIGNATURE_MISMATCH,
+ AS_SEMANTIC_ERR_FUNCTION_UNDECLARED,
+ AS_SEMANTIC_ERR_FUNCTION_UNDEFINED,
+ AS_SEMANTIC_ERR_TOO_MANY_ARGUMENTS,
AS_SEMANTIC_ERR_UNDEFINED_TYPE_OP,
AS_SEMANTIC_ERR_UNPACK_WILD_NONARRAY,
+ AS_SEMANTIC_ERR_VARIABLE_DIMENSIONS_INVALID,
AS_SEMANTIC_ERR_VARIABLE_UNDEFINED,
AS_SEMANTIC_ERR_VARIABLE_REDEFINITION,
AS_SEMANTIC_ERR_INTERNAL,
Modified: branches/collect/source/script/cASTVisitor.h
===================================================================
--- branches/collect/source/script/cASTVisitor.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/cASTVisitor.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -55,6 +55,8 @@
virtual void visitFunctionCall(cASTFunctionCall&) = 0;
virtual void visitLiteral(cASTLiteral&) = 0;
virtual void visitLiteralArray(cASTLiteralArray&) = 0;
+ virtual void visitObjectCall(cASTObjectCall&) = 0;
+ virtual void visitObjectReference(cASTObjectReference&) = 0;
virtual void visitVariableReference(cASTVariableReference&) = 0;
virtual void visitUnpackTarget(cASTUnpackTarget&) = 0;
};
Modified: branches/collect/source/script/cDumpASTVisitor.cc
===================================================================
--- branches/collect/source/script/cDumpASTVisitor.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/cDumpASTVisitor.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -193,7 +193,7 @@
void cDumpASTVisitor::visitFunctionDefinition(cASTFunctionDefinition& node)
{
indent();
- cout << (node.IsDefinition() ? "":"@") << "function: " << mapType(node.GetType()) << " " << node.GetName() << "(";
+ cout << (node.GetCode() ? "":"@") << "function: " << mapType(node.GetType()) << " " << node.GetName() << "(";
if (node.GetArguments()->GetSize()) {
cout << endl;
node.GetArguments()->Accept(*this);
@@ -204,7 +204,7 @@
indent();
cout << "{" << endl;
- if (node.IsDefinition()) {
+ if (node.GetCode()) {
m_depth++;
node.GetCode()->Accept(*this);
m_depth--;
@@ -218,8 +218,19 @@
void cDumpASTVisitor::visitVariableDefinition(cASTVariableDefinition& node)
{
indent();
- cout << mapType(node.GetType()) << " " << node.GetVariable() << endl;
+ cout << mapType(node.GetType()) << " " << node.GetName() << endl;
+ if (node.GetDimensions()) {
+ m_depth++;
+ indent();
+ cout << "dimensions:" << endl;
+
+ m_depth++;
+ node.GetDimensions()->Accept(*this);
+
+ m_depth -= 2;
+ }
+
if (node.GetAssignmentExpression()) {
m_depth++;
indent();
@@ -295,7 +306,8 @@
cout << "target:" << endl;
m_depth++;
- node.GetTarget()->Accept(*this);
+ indent();
+ cout << node.GetName() << endl;
m_depth--;
if (node.HasArguments()) {
@@ -325,7 +337,7 @@
cout << "{" << endl;
m_depth++;
- node.GetValue()->Accept(*this);
+ node.GetValues()->Accept(*this);
m_depth--;
indent();
@@ -333,6 +345,47 @@
}
+void cDumpASTVisitor::visitObjectCall(cASTObjectCall& node)
+{
+ indent();
+ cout << "call:" << endl;
+ m_depth++;
+
+ indent();
+ cout << "target:" << endl;
+
+ m_depth++;
+ node.GetObject()->Accept(*this);
+ m_depth--;
+
+ if (node.HasArguments()) {
+ indent();
+ cout << "with:" << endl;
+
+ m_depth++;
+ node.GetArguments()->Accept(*this);
+ m_depth--;
+ }
+
+ m_depth--;
+
+}
+
+void cDumpASTVisitor::visitObjectReference(cASTObjectReference& node)
+{
+ m_depth++;
+ node.GetObject()->Accept(*this);
+ m_depth--;
+
+ indent();
+ cout << mapToken(AS_TOKEN_DOT) << endl;
+
+ m_depth++;
+ indent();
+ cout << node.GetName() << endl;
+ m_depth--;
+}
+
void cDumpASTVisitor::visitVariableReference(cASTVariableReference& node)
{
indent();
Modified: branches/collect/source/script/cDumpASTVisitor.h
===================================================================
--- branches/collect/source/script/cDumpASTVisitor.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/cDumpASTVisitor.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -56,6 +56,8 @@
void visitFunctionCall(cASTFunctionCall&);
void visitLiteral(cASTLiteral&);
void visitLiteralArray(cASTLiteralArray&);
+ void visitObjectCall(cASTObjectCall&);
+ void visitObjectReference(cASTObjectReference&);
void visitVariableReference(cASTVariableReference&);
void visitUnpackTarget(cASTUnpackTarget&);
Modified: branches/collect/source/script/cParser.cc
===================================================================
--- branches/collect/source/script/cParser.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/cParser.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -339,32 +339,32 @@
bool eoe = false;
while (!eoe) {
- switch (currentToken()) {
- case TOKEN(DOT):
- if (nextToken() != TOKEN(ID)) PARSE_UNEXPECT();
- ce.Set(new cASTExpressionBinary(FILEPOS, TOKEN(DOT), ce.Release(), new cASTVariableReference(FILEPOS, currentText())));
- nextToken(); // consume id
- break;
- case TOKEN(PREC_OPEN):
- cASTFunctionCall* fc = new cASTFunctionCall(FILEPOS, ce.Release());
- ce.Set(fc);
- if (nextToken() != TOKEN(PREC_CLOSE)) fc->SetArguments(parseArgumentList());
+ if (currentToken() == TOKEN(DOT)) {
+ if (nextToken() != TOKEN(ID)) PARSE_UNEXPECT();
+ cString name(currentText());
+ nextToken(); // consume id
+
+ if (currentToken() == TOKEN(PREC_OPEN)) {
+ cASTObjectCall* oc = new cASTObjectCall(FILEPOS, ce.Release(), name);
+ ce.Set(oc);
+ if (nextToken() != TOKEN(PREC_CLOSE)) oc->SetArguments(parseArgumentList());
if (currentToken() != TOKEN(PREC_CLOSE)) PARSE_UNEXPECT();
nextToken(); // consume ')'
// If the next token is not a continued call expression, then set the end-of-expression flag
if (currentToken() != TOKEN(IDX_OPEN) && currentToken() != TOKEN(DOT)) eoe = true;
- break;
- case TOKEN(IDX_OPEN):
- do {
- nextToken(); // consume '['
- ce.Set(new cASTExpressionBinary(FILEPOS, TOKEN(IDX_OPEN), ce.Release(), parseExpression()));
- if (currentToken() != TOKEN(IDX_CLOSE)) PARSE_UNEXPECT();
- } while (nextToken() == TOKEN(IDX_OPEN));
- break;
- default:
- if (required) { PARSE_UNEXPECT(); }
- else eoe = true;
+ } else {
+ ce.Set(new cASTObjectReference(FILEPOS, ce.Release(), name));
+ }
+ } else if (currentToken() == TOKEN(IDX_OPEN)) {
+ do {
+ nextToken(); // consume '['
+ ce.Set(new cASTExpressionBinary(FILEPOS, TOKEN(IDX_OPEN), ce.Release(), parseExpression()));
+ if (currentToken() != TOKEN(IDX_CLOSE)) PARSE_UNEXPECT();
+ } while (nextToken() == TOKEN(IDX_OPEN));
+ } else {
+ if (required) { PARSE_UNEXPECT(); }
+ else eoe = true;
}
}
@@ -576,10 +576,9 @@
break;
case TOKEN(ID):
if (peekToken() == TOKEN(PREC_OPEN)) {
- cASTNode* vr = new cASTVariableReference(FILEPOS, currentText());
+ cASTFunctionCall* fc = new cASTFunctionCall(FILEPOS, currentText());
+ expr.Set(fc);
nextToken(); // consume id token
- cASTFunctionCall* fc = new cASTFunctionCall(FILEPOS, vr);
- expr.Set(fc);
if (nextToken() != TOKEN(PREC_CLOSE)) fc->SetArguments(parseArgumentList());
if (currentToken() != TOKEN(PREC_CLOSE)) PARSE_UNEXPECT();
} else {
@@ -596,9 +595,12 @@
if (nextToken() != TOKEN(ARR_OPEN)) PARSE_UNEXPECT();
is_matrix = true;
case TOKEN(ARR_OPEN):
- if (nextToken() != TOKEN(ARR_CLOSE)) expr.Set(parseArgumentList());
- if (currentToken() != TOKEN(ARR_CLOSE)) PARSE_UNEXPECT();
- expr.Set(new cASTLiteralArray(FILEPOS, expr.Release(), is_matrix));
+ {
+ tAutoRelease<cASTArgumentList> al;
+ if (nextToken() != TOKEN(ARR_CLOSE)) al.Set(parseArgumentList());
+ if (currentToken() != TOKEN(ARR_CLOSE)) PARSE_UNEXPECT();
+ expr.Set(new cASTLiteralArray(FILEPOS, al.Release(), is_matrix));
+ }
break;
case TOKEN(OP_BIT_NOT):
Modified: branches/collect/source/script/cSemanticASTVisitor.cc
===================================================================
--- branches/collect/source/script/cSemanticASTVisitor.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/cSemanticASTVisitor.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -32,8 +32,8 @@
using namespace AvidaScript;
-#define SEMANTIC_ERROR(code, ...) reportError(true, AS_SEMANTIC_ERR_ ## code, node.GetFilePosition(), __LINE__, ##__VA_ARGS__)
-#define SEMANTIC_WARNING(code, ...) reportError(false, AS_SEMANTIC_WARN_ ## code, node.GetFilePosition(), __LINE__, ##__VA_ARGS__)
+#define SEMANTIC_ERROR(code, ...) reportError(AS_SEMANTIC_ERR_ ## code, node.GetFilePosition(), __LINE__, ##__VA_ARGS__)
+#define SEMANTIC_WARNING(code, ...) reportError(AS_SEMANTIC_WARN_ ## code, node.GetFilePosition(), __LINE__, ##__VA_ARGS__)
#define TOKEN(x) AS_TOKEN_ ## x
#define TYPE(x) AS_TYPE_ ## x
@@ -70,7 +70,8 @@
: m_library(lib), m_global_symtbl(global_symtbl), m_parent_scope(global_symtbl), m_fun_id(0), m_cur_symtbl(global_symtbl)
{
// Add internal definition of the global function
- m_global_symtbl->AddFunction("__asmain", TYPE(INT));
+ int fun_id = -1;
+ m_global_symtbl->AddFunction("__asmain", TYPE(INT), fun_id);
}
@@ -91,7 +92,7 @@
{
node.GetExpression()->Accept(*this);
checkCast(m_parent_scope->GetFunctionRType(m_fun_id), node.GetExpression()->GetType());
- // @TODO - mark scope as containing return
+ m_cur_symtbl->SetScopeReturn();
}
@@ -99,45 +100,243 @@
{
tListIterator<cASTNode> it = node.Iterator();
+ bool has_return = false;
+ bool warn_unreach = false;
cASTNode* stmt = NULL;
while ((stmt = it.Next())) {
+ m_fun_def = false;
stmt->Accept(*this);
- // @TODO - check for unreachable statements
+ if (!has_return && m_cur_symtbl->ScopeHasReturn()) has_return = true;
+ else if (has_return && !m_fun_def && !warn_unreach) {
+ reportError(AS_SEMANTIC_WARN_UNREACHABLE, stmt->GetFilePosition(), __LINE__);
+ warn_unreach = true;
+ }
}
}
void cSemanticASTVisitor::visitForeachBlock(cASTForeachBlock& node)
{
+ // Check values and make sure we can process it as an array
+ node.GetValues()->Accept(*this);
+ checkCast(node.GetValues()->GetType(), TYPE(ARRAY));
+
+ m_cur_symtbl->PushScope();
+
+ // Check and define the variable in this scope
+ node.GetVariable()->Accept(*this);
+
+ // Check the code
+ node.GetCode()->Accept(*this);
+
+ // Check all functions in the current scope level and make sure they have been defined
+ cSymbolTable::cFunctionIterator fit = m_cur_symtbl->ActiveFunctionIterator();
+ while (fit.Next()) if (!fit.HasCode()) SEMANTIC_ERROR(FUNCTION_UNDEFINED, (const char*)fit.GetName());
+ m_cur_symtbl->PopScope();
}
void cSemanticASTVisitor::visitIfBlock(cASTIfBlock& node)
{
+ // Check main condition and code
+ node.GetCondition()->Accept(*this);
+ checkCast(node.GetCondition()->GetType(), TYPE(BOOL));
+
+ m_cur_symtbl->PushScope();
+
+ node.GetCode()->Accept(*this);
+
+ // Check all functions in the current scope level and make sure they have been defined
+ cSymbolTable::cFunctionIterator fit = m_cur_symtbl->ActiveFunctionIterator();
+ while (fit.Next()) if (!fit.HasCode()) SEMANTIC_ERROR(FUNCTION_UNDEFINED, (const char*)fit.GetName());
+ m_cur_symtbl->PopScope();
+
+ // Check all elseif blocks
+ tListIterator<cASTIfBlock::cElseIf> it = node.ElseIfIterator();
+ cASTIfBlock::cElseIf* ei = NULL;
+ while ((ei = it.Next())) {
+ ei->GetCondition()->Accept(*this);
+ checkCast(ei->GetCondition()->GetType(), TYPE(BOOL));
+
+ m_cur_symtbl->PushScope();
+
+ ei->GetCode()->Accept(*this);
+
+ // Check all functions in the current scope level and make sure they have been defined
+ cSymbolTable::cFunctionIterator fit = m_cur_symtbl->ActiveFunctionIterator();
+ while (fit.Next()) if (!fit.HasCode()) SEMANTIC_ERROR(FUNCTION_UNDEFINED, (const char*)fit.GetName());
+ m_cur_symtbl->PopScope();
+ }
+
+ // Check else block if there is one
+ if (node.GetElseCode()) {
+ m_cur_symtbl->PushScope();
+
+ node.GetElseCode()->Accept(*this);
+
+ // Check all functions in the current scope level and make sure they have been defined
+ cSymbolTable::cFunctionIterator fit = m_cur_symtbl->ActiveFunctionIterator();
+ while (fit.Next()) if (!fit.HasCode()) SEMANTIC_ERROR(FUNCTION_UNDEFINED, (const char*)fit.GetName());
+ m_cur_symtbl->PopScope();
+ }
}
void cSemanticASTVisitor::visitWhileBlock(cASTWhileBlock& node)
{
+ node.GetCondition()->Accept(*this);
+ checkCast(node.GetCondition()->GetType(), TYPE(BOOL));
+
+ m_cur_symtbl->PushScope();
+
+ node.GetCode()->Accept(*this);
+
+ // Check all functions in the current scope level and make sure they have been defined
+ cSymbolTable::cFunctionIterator fit = m_cur_symtbl->ActiveFunctionIterator();
+ while (fit.Next()) if (!fit.HasCode()) SEMANTIC_ERROR(FUNCTION_UNDEFINED, (const char*)fit.GetName());
+ m_cur_symtbl->PopScope();
}
void cSemanticASTVisitor::visitFunctionDefinition(cASTFunctionDefinition& node)
{
+ int fun_id = -1;
+ bool added = m_cur_symtbl->AddFunction(node.GetName(), node.GetType(), fun_id);
+
+ m_fun_stack.Push(sFunctionEntry(m_parent_scope, m_fun_id));
+ m_parent_scope = m_cur_symtbl;
+ m_fun_id = fun_id;
+
+ if (added) {
+ // Create new symtbl and scope
+ m_cur_symtbl = new cSymbolTable;
+ m_parent_scope->SetFunctionSymbolTable(fun_id, m_cur_symtbl);
+
+ // Check call signature
+ cASTVariableDefinitionList* args = node.GetArguments();
+ if (args) {
+ // Move the args to the symbol table entry
+ m_parent_scope->SetFunctionSignature(fun_id, args);
+ node.ClearArguments();
+
+ tListIterator<cASTVariableDefinition> it = args->Iterator();
+ cASTVariableDefinition* vd = NULL;
+ bool def_val_start = false;
+ while ((vd = it.Next())) {
+ vd->Accept(*this);
+ if (def_val_start) {
+ if (!vd->GetAssignmentExpression())
+ SEMANTIC_ERROR(ARGUMENT_DEFAULT_REQUIRED, (const char*)vd->GetName(), (const char*)node.GetName());
+ } else {
+ if (vd->GetAssignmentExpression()) def_val_start = true;
+ }
+ }
+ }
+ } else {
+ if (m_parent_scope->GetFunctionRType(fun_id) != node.GetType())
+ SEMANTIC_ERROR(FUNCTION_RTYPE_MISMATCH, (const char*)node.GetName());
+
+ // Lookup previously defined symbol table
+ m_cur_symtbl = m_parent_scope->GetFunctionSymbolTable(fun_id);
+
+ // Verify that the call signatures match
+ cASTVariableDefinitionList* ssig = m_parent_scope->GetFunctionSignature(fun_id);
+ if (ssig && node.GetArguments()) {
+ if (ssig->GetSize() == node.GetArguments()->GetSize()) {
+ tListIterator<cASTVariableDefinition> sit = ssig->Iterator();
+ tListIterator<cASTVariableDefinition> nit = node.GetArguments()->Iterator();
+ while (true) {
+ cASTVariableDefinition* svd = sit.Next();
+ cASTVariableDefinition* nvd = nit.Next();
+ if (!svd || !nvd) break;
+
+ if (svd->GetName() != nvd->GetName() || svd->GetType() != nvd->GetType() || nvd->GetAssignmentExpression()) {
+ SEMANTIC_ERROR(FUNCTION_SIGNATURE_MISMATCH, (const char*)node.GetName());
+ break;
+ }
+ }
+ } else {
+ SEMANTIC_ERROR(FUNCTION_SIGNATURE_MISMATCH, (const char*)node.GetName());
+ }
+ } else if ((ssig && !node.GetArguments()) || (!ssig && node.GetArguments())) {
+ SEMANTIC_ERROR(FUNCTION_SIGNATURE_MISMATCH, (const char*)node.GetName());
+ }
+ }
+
+ // If this is the definition process the code
+ if (node.GetCode()) {
+ if (!m_parent_scope->GetFunctionDefinition(fun_id)) {
+ node.GetCode()->Accept(*this);
+
+ if (node.GetType() != TYPE(VOID) && !m_cur_symtbl->ScopeHasReturn()) SEMANTIC_WARNING(NO_RETURN);
+
+ // Move the code to the symbol table entry
+ m_parent_scope->SetFunctionDefinition(fun_id, node.GetCode());
+ node.SetCode(NULL);
+ } else {
+ SEMANTIC_ERROR(FUNCTION_REDEFINITION, (const char*)node.GetName());
+ }
+ }
+
+ // Check all functions in the current scope level and make sure they have been defined
+ cSymbolTable::cFunctionIterator fit = m_cur_symtbl->ActiveFunctionIterator();
+ while (fit.Next()) if (!fit.HasCode()) SEMANTIC_ERROR(FUNCTION_UNDEFINED, (const char*)fit.GetName());
+
+ // Pop function stack
+ sFunctionEntry prev = m_fun_stack.Pop();
+ m_cur_symtbl = m_parent_scope;
+ m_parent_scope = prev.parent_scope;
+ m_fun_id = prev.fun_id;
+
+ m_fun_def = true;
}
void cSemanticASTVisitor::visitVariableDefinition(cASTVariableDefinition& node)
{
- if (!m_cur_symtbl->AddVariable(node.GetVariable(), node.GetType())) {
- SEMANTIC_ERROR(VARIABLE_REDEFINITION, (const char*)node.GetVariable());
+ int var_id = -1;
+ if (m_cur_symtbl->AddVariable(node.GetName(), node.GetType(), var_id)) node.SetVar(var_id);
+ else SEMANTIC_ERROR(VARIABLE_REDEFINITION, (const char*)node.GetName());
+
+ // Process matrix/array dimensions
+ cASTArgumentList* al = node.GetDimensions();
+ if (al) {
+ if (node.GetType() == TYPE(MATRIX) || node.GetType() == TYPE(ARRAY)) {
+ // Check individual arguments for validity
+ tListIterator<cASTNode> it = al->Iterator();
+ cASTNode* alnode = NULL;
+ while ((alnode = it.Next())) {
+ alnode->Accept(*this);
+ checkCast(alnode->GetType(), TYPE(INT));
+ }
+
+ // If empty, warn...
+ if (al->GetSize() == 0) SEMANTIC_WARNING(NO_DIMENSIONS);
+
+ // If dimensions exceed type limits
+ if ((node.GetType() == TYPE(ARRAY) && al->GetSize() > 1) || (node.GetType() == TYPE(MATRIX) && al->GetSize() > 2)) {
+ SEMANTIC_ERROR(TOO_MANY_ARGUMENTS);
+ SEMANTIC_ERROR(VARIABLE_DIMENSIONS_INVALID, (const char*)node.GetName(), mapType(node.GetType()));
+ }
+ } else {
+ SEMANTIC_ERROR(VARIABLE_DIMENSIONS_INVALID, (const char*)node.GetName(), mapType(node.GetType()));
+ }
}
+
+ // Process assignment
+ cASTNode* ae = node.GetAssignmentExpression();
+ if (ae) {
+ ae->Accept(*this);
+ checkCast(ae->GetType(), node.GetType());
+ }
}
void cSemanticASTVisitor::visitVariableDefinitionList(cASTVariableDefinitionList& node)
{
+ // Should never recurse into here. Variable definition lists are processed by function definitions.
+ SEMANTIC_ERROR(INTERNAL);
}
@@ -148,9 +347,6 @@
node.GetRight()->Accept(*this);
switch (node.GetOperator()) {
- case TOKEN(DOT):
- // @TODO
- break;
case TOKEN(IDX_OPEN):
checkCast(node.GetLeft()->GetType(), TYPE(ARRAY));
checkCast(node.GetRight()->GetType(), TYPE(INT));
@@ -280,10 +476,65 @@
void cSemanticASTVisitor::visitArgumentList(cASTArgumentList& node)
{
+ // Should never recurse into here. Argument lists are processed by their owners as needed.
+ SEMANTIC_ERROR(INTERNAL);
}
void cSemanticASTVisitor::visitFunctionCall(cASTFunctionCall& node)
{
+ int fun_id = -1;
+ bool global = false;
+ if (lookupFunction(node.GetName(), fun_id, global)) {
+ cASTVariableDefinitionList* sig = (global ? m_global_symtbl : m_cur_symtbl)->GetFunctionSignature(fun_id);
+
+ // Check function parameters for match to the signature
+ cASTArgumentList* args = node.GetArguments();
+ if (args) {
+ if (sig && args->GetSize() <= sig->GetSize()) {
+
+ bool err = false;
+ tListIterator<cASTVariableDefinition> sit = sig->Iterator();
+ tListIterator<cASTNode> cit = node.GetArguments()->Iterator();
+ cASTNode* an = NULL;
+ while ((an = cit.Next())) {
+ an->Accept(*this);
+
+ ASType_t in_type = an->GetType();
+ ASType_t out_type = sit.Next()->GetType();
+ if (valid_cast[in_type][out_type]) {
+ if ((in_type == TYPE(FLOAT) && out_type == TYPE(INT)) || (in_type == TYPE(INT) && out_type == TYPE(CHAR)))
+ SEMANTIC_WARNING(LOSS_OF_PRECISION, mapType(in_type), mapType(out_type));
+ } else {
+ if (!err) {
+ SEMANTIC_ERROR(FUNCTION_CALL_SIGNATURE_MISMATCH, (const char*)node.GetName());
+ err = true;
+ }
+ SEMANTIC_ERROR(CANNOT_CAST, mapType(in_type), mapType(out_type));
+ }
+ }
+
+ if (!sit.AtEnd() && !sit.Next()->GetAssignmentExpression())
+ SEMANTIC_ERROR(ARGUMENT_MISSING_REQUIRED, (const char*)sit.Get()->GetName());
+ } else {
+ SEMANTIC_ERROR(FUNCTION_CALL_SIGNATURE_MISMATCH, (const char*)node.GetName());
+ }
+ } else {
+ if (sig && sig->GetSize() && !sig->GetFirst()->GetAssignmentExpression()) {
+ SEMANTIC_ERROR(FUNCTION_CALL_SIGNATURE_MISMATCH, (const char*)node.GetName());
+ tListIterator<cASTVariableDefinition> it = sig->Iterator();
+ cASTVariableDefinition* vd = NULL;
+ while ((vd == it.Next())) {
+ if (!vd->GetAssignmentExpression()) SEMANTIC_ERROR(ARGUMENT_MISSING_REQUIRED, (const char*)vd->GetName());
+ else break;
+ }
+ }
+ }
+
+ node.SetFunc(fun_id, global);
+ node.SetType(m_cur_symtbl->GetFunctionRType(fun_id));
+ } else {
+ SEMANTIC_ERROR(FUNCTION_UNDECLARED, (const char*)node.GetName());
+ }
}
@@ -295,9 +546,29 @@
void cSemanticASTVisitor::visitLiteralArray(cASTLiteralArray& node)
{
+ cASTArgumentList* al = node.GetValues();
+ if (al) {
+ tListIterator<cASTNode> it = al->Iterator();
+ cASTNode* alnode = NULL;
+ while ((alnode = it.Next())) alnode->Accept(*this);
+ }
+
+ // Matrix dimension check must be performed at runtime
}
+void cSemanticASTVisitor::visitObjectCall(cASTObjectCall& node)
+{
+ // @TODO - object call
+}
+
+
+void cSemanticASTVisitor::visitObjectReference(cASTObjectReference& node)
+{
+ // @TODO - object reference
+}
+
+
void cSemanticASTVisitor::visitVariableReference(cASTVariableReference& node)
{
int var_id = -1;
@@ -444,7 +715,7 @@
return false;
}
}
-
+
inline bool cSemanticASTVisitor::lookupVariable(const cString& name, int& var_id, bool& global) const
{
if (m_cur_symtbl->LookupVariable(name, var_id)) {
@@ -459,47 +730,105 @@
}
+inline bool cSemanticASTVisitor::lookupFunction(const cString& name, int& fun_id, bool& global) const
+{
+ if (m_cur_symtbl->LookupFunction(name, fun_id)) {
+ global = false;
+ return true;
+ } else if (m_cur_symtbl != m_global_symtbl && m_global_symtbl->LookupFunction(name, fun_id)) {
+ global = true;
+ return true;
+ }
+
+ return false;
+}
-void cSemanticASTVisitor::reportError(bool fail, ASSemanticError_t err, const cASFilePosition& fp, const int line, ...)
+
+
+void cSemanticASTVisitor::reportError(ASSemanticError_t err, const cASFilePosition& fp, const int line, ...)
{
#define ERR_ENDL " (cSemanticASTVisitor.cc:" << line << ")" << std::endl
+#define VA_ARG_STR va_arg(vargs, const char*)
- if (fail) m_success = false;
-
std::cerr << fp.GetFilename() << ":" << fp.GetLineNumber();
if (err < AS_SEMANTIC_WARN__LAST) std::cerr << ": warning: ";
- else std::cerr << ": error: ";
+ else { m_success = false; std::cerr << ": error: "; }
va_list vargs;
va_start(vargs, line);
switch (err) {
case AS_SEMANTIC_WARN_LOSS_OF_PRECISION:
- std::cerr << "loss of precision occuring in cast of " << va_arg(vargs, const char*) << " to "
- << va_arg(vargs, const char*) << ERR_ENDL;
+ std::cerr << "loss of precision occuring in cast of " << VA_ARG_STR << " to " << VA_ARG_STR << ERR_ENDL;
break;
+ case AS_SEMANTIC_WARN_NO_DIMENSIONS:
+ std::cerr << "no dimensions specified" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_WARN_NO_RETURN:
+ std::cerr << "control reaches the end of non-void function" << ERR_ENDL;
+ break;
case AS_SEMANTIC_WARN_UNREACHABLE:
std::cerr << "unreachable statement(s)" << ERR_ENDL;
break;
+
+ case AS_SEMANTIC_ERR_ARGUMENT_DEFAULT_REQUIRED:
+ std::cerr << "'" << VA_ARG_STR << "' argument of '" << VA_ARG_STR << "()' requires a default value due to previous"
+ << "argument defaults" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_ERR_ARGUMENT_MISSING_REQUIRED:
+ std::cerr << "required argument " << VA_ARG_STR << " not found" << ERR_ENDL;
+ break;
case AS_SEMANTIC_ERR_CANNOT_CAST:
- std::cerr << "cannot cast " << va_arg(vargs, const char*) << " to " << va_arg(vargs, const char*) << ERR_ENDL;
+ std::cerr << "cannot cast " << VA_ARG_STR << " to " << VA_ARG_STR << ERR_ENDL;
break;
+ case AS_SEMANTIC_ERR_FUNCTION_CALL_SIGNATURE_MISMATCH:
+ std::cerr << "invalid call signature for '" << VA_ARG_STR << "()'" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_ERR_FUNCTION_REDEFINITION:
+ std::cerr << "redefinition of '" << VA_ARG_STR << "()'" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_ERR_FUNCTION_RTYPE_MISMATCH:
+ std::cerr << "return type of '" << VA_ARG_STR << "()' does not match declaration" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_ERR_FUNCTION_SIGNATURE_MISMATCH:
+ std::cerr << "call signature of '" << VA_ARG_STR << "()' does not match declaration" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_ERR_FUNCTION_UNDECLARED:
+ {
+ cString varname = VA_ARG_STR;
+ std::cerr << "'" << varname << "()' undeclared";
+ cString nearmatch1 = m_cur_symtbl->FunctionNearMatch(varname);
+ cString nearmatch2 = m_global_symtbl->FunctionNearMatch(varname);
+ if (nearmatch1 != "") std::cerr << " - possible match '" << nearmatch1 << "()'";
+ if (nearmatch2 != "" && nearmatch1 != nearmatch2) std::cerr << " or '" << nearmatch2 << "()'";
+ std::cerr << ERR_ENDL;
+ }
+ break;
+ case AS_SEMANTIC_ERR_FUNCTION_UNDEFINED:
+ std::cerr << "'" << VA_ARG_STR << "()' declared but not defined" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_ERR_TOO_MANY_ARGUMENTS:
+ std::cerr << "too many arguments" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_ERR_UNDEFINED_TYPE_OP:
+ std::cerr << "'" << VA_ARG_STR << "' operation undefined for type '" << VA_ARG_STR << "'" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_ERR_UNPACK_WILD_NONARRAY:
+ std::cerr << "cannot unpack ... items into '" << VA_ARG_STR << "', variable must be an array" << ERR_ENDL;
+ break;
+ case AS_SEMANTIC_ERR_VARIABLE_DIMENSIONS_INVALID:
+ std::cerr << "dimensions of '" << VA_ARG_STR << "' invalid for type " << VA_ARG_STR << ERR_ENDL;
+ break;
case AS_SEMANTIC_ERR_VARIABLE_UNDEFINED:
{
- cString varname = va_arg(vargs, const char*);
+ cString varname = VA_ARG_STR;
std::cerr << "'" << varname << "' undefined";
cString nearmatch = m_cur_symtbl->VariableNearMatch(varname);
if (nearmatch != "") std::cerr << " - possible match '" << nearmatch << "'";
std::cerr << ERR_ENDL;
}
break;
- case AS_SEMANTIC_ERR_UNDEFINED_TYPE_OP:
- std::cerr << "'" << va_arg(vargs, const char*) << "' operation undefined for type '"
- << va_arg(vargs, const char*) << "'" << ERR_ENDL;
- break;
- case AS_SEMANTIC_ERR_UNPACK_WILD_NONARRAY:
- std::cerr << "cannot unpack ... items into '" << va_arg(vargs, const char*) << "', variable must be an array" << ERR_ENDL;
case AS_SEMANTIC_ERR_VARIABLE_REDEFINITION:
- std::cerr << "redefining variable '" << va_arg(vargs, const char*) << "'" << ERR_ENDL;
+ std::cerr << "redefining variable '" << VA_ARG_STR << "'" << ERR_ENDL;
break;
case AS_SEMANTIC_ERR_INTERNAL:
std::cerr << "internal semantic analysis error at cSemanticASTVisitor.cc:" << line << std::endl;
@@ -511,6 +840,7 @@
va_end(vargs);
#undef ERR_ENDL
+#undef VA_ARG_STR
}
#undef SEMANTIC_ERROR()
Modified: branches/collect/source/script/cSemanticASTVisitor.h
===================================================================
--- branches/collect/source/script/cSemanticASTVisitor.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/cSemanticASTVisitor.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -45,17 +45,19 @@
struct sFunctionEntry
{
- cSymbolTable* scope;
+ cSymbolTable* parent_scope;
int fun_id;
cSymbolTable* fun_symtbl;
- sFunctionEntry() : scope(NULL), fun_id(-1) { ; }
+ sFunctionEntry() : parent_scope(NULL), fun_id(-1) { ; }
+ sFunctionEntry(cSymbolTable* ps, int in_fun_id) : parent_scope(ps), fun_id(in_fun_id) { ; }
};
tSmartArray<sFunctionEntry> m_fun_stack;
bool m_success;
+ bool m_fun_def;
cSemanticASTVisitor(); // @not_implemented
@@ -86,6 +88,8 @@
void visitFunctionCall(cASTFunctionCall&);
void visitLiteral(cASTLiteral&);
void visitLiteralArray(cASTLiteralArray&);
+ void visitObjectCall(cASTObjectCall&);
+ void visitObjectReference(cASTObjectReference&);
void visitVariableReference(cASTVariableReference&);
void visitUnpackTarget(cASTUnpackTarget&);
@@ -95,7 +99,8 @@
inline bool validBitwiseType(ASType_t type) const;
inline bool lookupVariable(const cString& name, int& var_id, bool& global) const;
+ inline bool lookupFunction(const cString& name, int& fun_id, bool& global) const;
- void reportError(bool fail, ASSemanticError_t err, const cASFilePosition& fp, const int line, ...);
+ void reportError(ASSemanticError_t err, const cASFilePosition& fp, const int line, ...);
};
#endif
Modified: branches/collect/source/script/cSymbolTable.cc
===================================================================
--- branches/collect/source/script/cSymbolTable.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/cSymbolTable.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -31,24 +31,49 @@
for (int i = 0; i < m_fun_tbl.GetSize(); i++) delete m_fun_tbl[i];
}
-bool cSymbolTable::AddVariable(const cString& name, ASType_t type)
+bool cSymbolTable::AddVariable(const cString& name, ASType_t type, int& var_id)
{
- if (HasSymbol(name)) return false;
+ if (LookupVariable(name, var_id)) return false;
- m_sym_tbl.Push(new sSymbolEntry(name, type));
- m_sym_dict.Add(name, m_sym_tbl.GetSize() - 1);
+ var_id = m_sym_tbl.GetSize();
+ m_sym_tbl.Push(new sSymbolEntry(name, type, m_scope));
+ m_sym_dict.Add(name, var_id);
return true;
}
-bool cSymbolTable::AddFunction(const cString& name, ASType_t type)
+bool cSymbolTable::AddFunction(const cString& name, ASType_t type, int& fun_id)
{
- if (HasSymbol(name)) return false;
+ if (LookupFunction(name, fun_id)) return false;
- m_fun_tbl.Push(new sFunctionEntry(name, type));
- m_fun_dict.Add(name, m_fun_tbl.GetSize() - 1);
+ fun_id = m_fun_tbl.GetSize();
+ m_fun_tbl.Push(new sFunctionEntry(name, type, m_scope));
+ m_fun_dict.Add(name, fun_id);
return true;
}
+void cSymbolTable::PopScope()
+{
+ m_deactivate_cycle++;
+
+ for (int i = 0; i < m_sym_tbl.GetSize(); i++) {
+ sSymbolEntry* se = m_sym_tbl[i];
+ if (se->scope == m_scope && !se->deactivate) {
+ m_sym_dict.Remove(se->name);
+ se->deactivate = m_deactivate_cycle;
+ }
+ }
+
+ for (int i = 0; i < m_fun_tbl.GetSize(); i++) {
+ sFunctionEntry* fe = m_fun_tbl[i];
+ if (fe->scope == m_scope && !fe->deactivate) {
+ m_fun_dict.Remove(fe->name);
+ fe->deactivate = m_deactivate_cycle;
+ }
+ }
+ m_return = false;
+ m_scope--;
+}
+
Modified: branches/collect/source/script/cSymbolTable.h
===================================================================
--- branches/collect/source/script/cSymbolTable.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/script/cSymbolTable.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -26,10 +26,12 @@
#define cSymbolTable_h
#include "AvidaScript.h"
+#include "ASTree.h"
#include "tArray.h"
#include "tDictionary.h"
+
// Active/inactive functions and variables within the scope of the current function (or globally)
@@ -41,9 +43,11 @@
cString name;
ASType_t type;
- bool active;
+ int scope;
+ bool deactivate;
- sSymbolEntry(const cString& in_name, ASType_t in_type) : name(in_name), type(in_type), active(true) { ; }
+ sSymbolEntry(const cString& in_name, ASType_t in_type, int in_scope)
+ : name(in_name), type(in_type), scope(in_scope), deactivate(0) { ; }
};
tArray<sSymbolEntry*> m_sym_tbl;
tDictionary<int> m_sym_dict;
@@ -52,37 +56,96 @@
{
cString name;
ASType_t type;
+ cASTVariableDefinitionList* signature;
+ cSymbolTable* symtbl;
+ cASTNode* code;
- bool active;
+ int scope;
+ int deactivate;
- sFunctionEntry(const cString& in_name, ASType_t in_type) : name(in_name), type(in_type), active(true) { ; }
+ sFunctionEntry(const cString& in_name, ASType_t in_type, int in_scope)
+ : name(in_name), type(in_type), signature(NULL), symtbl(NULL), code(NULL), scope(in_scope), deactivate(0) { ; }
+ ~sFunctionEntry() { delete signature; delete symtbl; delete code; }
};
tArray<sFunctionEntry*> m_fun_tbl;
tDictionary<int> m_fun_dict;
+
+ int m_scope;
+ int m_deactivate_cycle;
+ bool m_return;
+
cSymbolTable(const cSymbolTable&); // @not_implemented
cSymbolTable& operator=(const cSymbolTable&); // @not_implemented
public:
- cSymbolTable() { ; }
+ cSymbolTable() : m_scope(0), m_deactivate_cycle(0), m_return(false) { ; }
~cSymbolTable();
- bool AddVariable(const cString& name, ASType_t type);
- bool AddFunction(const cString& name, ASType_t type);
+ bool AddVariable(const cString& name, ASType_t type, int& var_id);
+ bool AddFunction(const cString& name, ASType_t type, int& fun_id);
- ASType_t GetVariableType(int var_id) const { return m_sym_tbl[var_id]->type; }
- ASType_t GetFunctionRType(int fun_id) const { return m_fun_tbl[fun_id]->type; }
-
bool LookupVariable(const cString& name, int& var_id) { return m_sym_dict.Find(name, var_id); }
bool LookupFunction(const cString& name, int& fun_id) { return m_fun_dict.Find(name, fun_id); }
- inline bool HasSymbol(const cString& name) const { return m_sym_dict.HasEntry(name) || m_fun_dict.HasEntry(name); }
+ inline int GetNumVariables() const { return m_sym_tbl.GetSize(); }
+ inline int GetNumFunctions() const { return m_fun_tbl.GetSize(); }
+ inline void PushScope() { m_scope++; }
+ void PopScope();
+ inline int GetScope() const { return m_scope; }
+
+ inline void SetScopeReturn() { m_return = true; }
+ inline bool ScopeHasReturn() const { return m_return; }
+
+ inline ASType_t GetVariableType(int var_id) const { return m_sym_tbl[var_id]->type; }
+
+ inline const cString& GetFunctionName(int fun_id) const { return m_fun_tbl[fun_id]->name; }
+ inline ASType_t GetFunctionRType(int fun_id) const { return m_fun_tbl[fun_id]->type; }
+ inline cSymbolTable* GetFunctionSymbolTable(int fun_id) { return m_fun_tbl[fun_id]->symtbl; }
+ inline cASTVariableDefinitionList* GetFunctionSignature(int fun_id) { return m_fun_tbl[fun_id]->signature; }
+ inline cASTNode* GetFunctionDefinition(int fun_id) { return m_fun_tbl[fun_id]->code; }
+ inline int GetFunctionScope(int fun_id) const { return m_fun_tbl[fun_id]->scope; }
+ inline bool IsFunctionActive(int fun_id) const { return !m_fun_tbl[fun_id]->deactivate; }
+
+ inline void SetFunctionSymbolTable(int fun_id, cSymbolTable* symtbl) { m_fun_tbl[fun_id]->symtbl = symtbl; }
+ inline void SetFunctionSignature(int fun_id, cASTVariableDefinitionList* vdl) { m_fun_tbl[fun_id]->signature = vdl; }
+ inline void SetFunctionDefinition(int fun_id, cASTNode* code) { m_fun_tbl[fun_id]->code = code; }
+
inline cString VariableNearMatch(const cString& name) const { return m_sym_dict.NearMatch(name); }
inline cString FunctionNearMatch(const cString& name) const { return m_fun_dict.NearMatch(name); }
+
+
+ class cFunctionIterator
+ {
+ friend class cSymbolTable;
+
+ private:
+ cSymbolTable* m_symtbl;
+ int m_scope;
+ int m_idx;
+
+ cFunctionIterator(cSymbolTable* symtbl)
+ : m_symtbl(symtbl), m_scope(symtbl->GetScope()), m_idx(symtbl->GetNumFunctions() - 1) { ; }
+
+ public:
+ bool Next()
+ {
+ for (; m_idx >= 0; m_idx--)
+ if (m_symtbl->GetFunctionScope(m_idx) == m_scope && m_symtbl->IsFunctionActive(m_idx)) return true;
+
+ return false;
+ }
+
+ inline bool HasCode() const { return m_symtbl->GetFunctionDefinition(m_idx); }
+ inline const cString& GetName() const { return m_symtbl->GetFunctionName(m_idx); }
+ };
+
+
+ inline cFunctionIterator ActiveFunctionIterator() { return cFunctionIterator(this); }
};
Modified: branches/collect/source/tools/cConstSchedule.cc
===================================================================
--- branches/collect/source/tools/cConstSchedule.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cConstSchedule.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -36,13 +36,8 @@
return true;
}
-void cConstSchedule::Adjust(int item_id, const cMerit & merit, const cDeme& deme)
+void cConstSchedule::Adjust(int item_id, const cMerit& merit, int deme_id)
{
- Adjust(item_id, merit);
-}
-
-void cConstSchedule::Adjust(int item_id, const cMerit & merit)
-{
if (cChangeList *change_list = GetChangeList()) {
change_list->MarkChange(item_id);
}
Modified: branches/collect/source/tools/cConstSchedule.h
===================================================================
--- branches/collect/source/tools/cConstSchedule.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cConstSchedule.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -59,8 +59,7 @@
bool OK();
- virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
- virtual void Adjust(int item_id, const cMerit& merit);
+ virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
int GetNextID();
};
Modified: branches/collect/source/tools/cDemeProbSchedule.cc
===================================================================
--- branches/collect/source/tools/cDemeProbSchedule.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cDemeProbSchedule.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -72,10 +72,8 @@
//adjust the weight of an org within deme
-void cDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, const cDeme& deme)
+void cDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, int deme_id)
{
- int deme_id = deme.GetID();
-
//calculate the corrected id for the org to be adjusted
int offset_id = item_id - (deme_id * deme_size);
@@ -88,9 +86,3 @@
chart[deme_id]->SetWeight(offset_id, item_merit.GetDouble());
}
-
-//adjust the weight of an org within deme
-void cDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit)
-{
- assert(false);
-}
Modified: branches/collect/source/tools/cDemeProbSchedule.h
===================================================================
--- branches/collect/source/tools/cDemeProbSchedule.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cDemeProbSchedule.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -83,8 +83,7 @@
}
~cDemeProbSchedule() { for (int i = 0; i < chart.GetSize(); i++) delete chart[i]; }
- virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
- virtual void Adjust(int item_id, const cMerit& merit);
+ virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
int GetNextID();
};
Modified: branches/collect/source/tools/cIntegratedSchedule.cc
===================================================================
--- branches/collect/source/tools/cIntegratedSchedule.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cIntegratedSchedule.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -76,13 +76,8 @@
return true;
}
-void cIntegratedSchedule::Adjust(int item_id, const cMerit& new_merit, const cDeme& deme)
+void cIntegratedSchedule::Adjust(int item_id, const cMerit& new_merit, int deme_id)
{
- Adjust(item_id, new_merit * deme.GetDemeMerit());
-}
-
-void cIntegratedSchedule::Adjust(int item_id, const cMerit& new_merit)
-{
if (cChangeList *change_list = GetChangeList()) {
change_list->MarkChange(item_id);
}
Modified: branches/collect/source/tools/cIntegratedSchedule.h
===================================================================
--- branches/collect/source/tools/cIntegratedSchedule.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cIntegratedSchedule.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -66,8 +66,7 @@
cIntegratedSchedule(int _item_count);
~cIntegratedSchedule();
- virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
- virtual void Adjust(int item_id, const cMerit& merit);
+ virtual void Adjust(int item_id, const cMerit& merit, int deme_id);
int GetNextID();
double GetStatus(int id);
Modified: branches/collect/source/tools/cMerit.h
===================================================================
--- branches/collect/source/tools/cMerit.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cMerit.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -62,14 +62,18 @@
}
void operator=(double _merit) { UpdateValue(_merit); }
- void operator+=(const cMerit & _m){ UpdateValue(value + _m.GetDouble()); }
+
+ void operator+=(const cMerit & _m) { UpdateValue(value + _m.GetDouble()); }
void operator+=(double _merit) { UpdateValue(value + _merit); }
+
cMerit operator*(const cMerit& _m) const { return cMerit(value * _m.GetDouble()); }
- int operator>(const cMerit & _m) const { return value > _m.GetDouble(); }
- int operator<(const cMerit & _m) const { return value < _m.GetDouble(); }
- int operator>=(const cMerit & _m) const { return value >= _m.GetDouble(); }
- int operator<=(const cMerit & _m) const { return value <= _m.GetDouble(); }
+ void operator*=(const cMerit& _m) { UpdateValue(value * _m.GetDouble()); }
+ int operator>(const cMerit& _m) const { return value > _m.GetDouble(); }
+ int operator<(const cMerit& _m) const { return value < _m.GetDouble(); }
+ int operator>=(const cMerit& _m) const { return value >= _m.GetDouble(); }
+ int operator<=(const cMerit& _m) const { return value <= _m.GetDouble(); }
+
int operator==(const cMerit & _m) const { return value == _m.GetDouble(); }
int operator==(const double _m) const { return value == _m; }
int operator==(const unsigned int _m) const { return (offset==0 && base==_m); }
Modified: branches/collect/source/tools/cProbDemeProbSchedule.cc
===================================================================
--- branches/collect/source/tools/cProbDemeProbSchedule.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cProbDemeProbSchedule.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -57,10 +57,8 @@
//adjust the weight of an org within deme -- adjust the weighting for scheduling that deme
-void cProbDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, const cDeme& deme)
+void cProbDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, int deme_id)
{
- int deme_id = deme.GetID();
-
//calculate the corrected id for the org to be adjusted
int offset_id = item_id - (deme_id * deme_size);
@@ -84,9 +82,3 @@
//adjust the merit of the org in the tree
chart[deme_id]->SetWeight(offset_id, item_merit.GetDouble());
}
-
-
-void cProbDemeProbSchedule::Adjust(int item_id, const cMerit& merit)
-{
- assert(false);
-}
Modified: branches/collect/source/tools/cProbDemeProbSchedule.h
===================================================================
--- branches/collect/source/tools/cProbDemeProbSchedule.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cProbDemeProbSchedule.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -89,8 +89,7 @@
~cProbDemeProbSchedule() { for (int i = 0; i < chart.GetSize(); i++) delete chart[i]; }
- virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
- virtual void Adjust(int item_id, const cMerit& merit);
+ virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
int GetNextID();
};
Modified: branches/collect/source/tools/cProbSchedule.cc
===================================================================
--- branches/collect/source/tools/cProbSchedule.cc 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cProbSchedule.cc 2008-06-11 14:47:14 UTC (rev 2642)
@@ -38,13 +38,8 @@
return chart.FindPosition(position);
}
-void cProbSchedule::Adjust(int item_id, const cMerit& item_merit, const cDeme& deme)
-{
- Adjust(item_id, item_merit * deme.GetDemeMerit());
-}
-
-void cProbSchedule::Adjust(int item_id, const cMerit& item_merit)
+void cProbSchedule::Adjust(int item_id, const cMerit& item_merit, int deme_id)
{
if (cChangeList *change_list = GetChangeList()) {
change_list->MarkChange(item_id);
Modified: branches/collect/source/tools/cProbSchedule.h
===================================================================
--- branches/collect/source/tools/cProbSchedule.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cProbSchedule.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -57,8 +57,7 @@
cProbSchedule(int num_cells, int seed) : cSchedule(num_cells), m_rng(seed), chart(num_cells) { ; }
~cProbSchedule() { ; }
- virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
- virtual void Adjust(int item_id, const cMerit& merit);
+ virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
int GetNextID();
};
Modified: branches/collect/source/tools/cSchedule.h
===================================================================
--- branches/collect/source/tools/cSchedule.h 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/source/tools/cSchedule.h 2008-06-11 14:47:14 UTC (rev 2642)
@@ -60,8 +60,7 @@
virtual ~cSchedule();
virtual bool OK() { return true; }
- virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme) = 0;
- virtual void Adjust(int item_id, const cMerit& merit) = 0;
+ virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0) = 0;
virtual int GetNextID() = 0;
virtual double GetStatus(int id) { return 0.0; }
void SetChangeList(cChangeList *change_list);
Modified: branches/collect/tests/bgs_dyn_mutrates_births/test_list
===================================================================
--- branches/collect/tests/bgs_dyn_mutrates_births/test_list 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/tests/bgs_dyn_mutrates_births/test_list 2008-06-11 14:47:14 UTC (rev 2642)
@@ -1,7 +1,7 @@
;--- Begin Test Configuration File (test_list) ---
[main]
; Command line arguments to pass to the application
-args = -s 1 -set BIRTH_METHOD 6 -set NUM_DEMES 30 -set EVENT_FILE events-Test-NumBirthsSelection.cfg -set INST_SET inst_set.divide -set ENVIRONMENT_FILE environment.77 -set WORLD_X 15 -set WORLD_Y 60 -set CHILD_SIZE_RANGE 1.0 -set COPY_MUT_PROB 0.0 -set DIVIDE_INS_PROB 0.0 -set DIVIDE_DEL_PROB 0.0 -set DIV_MUT_PROB 0.03 -set START_CREATURE org.div1
+args = -s 1 -set BIRTH_METHOD 6 -set PREFER_EMPTY 0 -set NUM_DEMES 30 -set EVENT_FILE events-Test-NumBirthsSelection.cfg -set INST_SET inst_set.divide -set ENVIRONMENT_FILE environment.77 -set WORLD_X 15 -set WORLD_Y 60 -set CHILD_SIZE_RANGE 1.0 -set COPY_MUT_PROB 0.0 -set DIVIDE_INS_PROB 0.0 -set DIVIDE_DEL_PROB 0.0 -set DIV_MUT_PROB 0.03 -set START_CREATURE org.div1
app = %(default_app)s
nonzeroexit = disallow ; Exit code handling (disallow, allow, or require)
Modified: branches/collect/tests/bgs_dyn_mutrates_fit/test_list
===================================================================
--- branches/collect/tests/bgs_dyn_mutrates_fit/test_list 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/tests/bgs_dyn_mutrates_fit/test_list 2008-06-11 14:47:14 UTC (rev 2642)
@@ -1,7 +1,7 @@
;--- Begin Test Configuration File (test_list) ---
[main]
; Command line arguments to pass to the application
-args = -s 1 -set BIRTH_METHOD 6 -set NUM_DEMES 30 -set EVENT_FILE events-Test-ParentFitSelection.cfg -set INST_SET inst_set.divide -set ENVIRONMENT_FILE environment.77 -set WORLD_X 15 -set WORLD_Y 60 -set CHILD_SIZE_RANGE 1.0 -set COPY_MUT_PROB 0.0 -set DIVIDE_INS_PROB 0.0 -set DIVIDE_DEL_PROB 0.0 -set DIV_MUT_PROB 0.03 -set START_CREATURE org.div1
+args = -s 1 -set BIRTH_METHOD 6 -set PREFER_EMPTY 0 -set NUM_DEMES 30 -set EVENT_FILE events-Test-ParentFitSelection.cfg -set INST_SET inst_set.divide -set ENVIRONMENT_FILE environment.77 -set WORLD_X 15 -set WORLD_Y 60 -set CHILD_SIZE_RANGE 1.0 -set COPY_MUT_PROB 0.0 -set DIVIDE_INS_PROB 0.0 -set DIVIDE_DEL_PROB 0.0 -set DIV_MUT_PROB 0.03 -set START_CREATURE org.div1
app = %(default_app)s
nonzeroexit = disallow ; Exit code handling (disallow, allow, or require)
Modified: branches/collect/tests/bgs_dyn_mutrates_rank/test_list
===================================================================
--- branches/collect/tests/bgs_dyn_mutrates_rank/test_list 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/tests/bgs_dyn_mutrates_rank/test_list 2008-06-11 14:47:14 UTC (rev 2642)
@@ -1,7 +1,7 @@
;--- Begin Test Configuration File (test_list) ---
[main]
; Command line arguments to pass to the application
-args = -s 1 -set BIRTH_METHOD 6 -set NUM_DEMES 30 -set EVENT_FILE events-Test-RankSelection.cfg -set INST_SET inst_set.divide -set ENVIRONMENT_FILE environment.77 -set WORLD_X 15 -set WORLD_Y 60 -set CHILD_SIZE_RANGE 1.0 -set COPY_MUT_PROB 0.0 -set DIVIDE_INS_PROB 0.0 -set DIVIDE_DEL_PROB 0.0 -set DIV_MUT_PROB 0.03 -set START_CREATURE org.div1
+args = -s 1 -set BIRTH_METHOD 6 -set PREFER_EMPTY 0 -set NUM_DEMES 30 -set EVENT_FILE events-Test-RankSelection.cfg -set INST_SET inst_set.divide -set ENVIRONMENT_FILE environment.77 -set WORLD_X 15 -set WORLD_Y 60 -set CHILD_SIZE_RANGE 1.0 -set COPY_MUT_PROB 0.0 -set DIVIDE_INS_PROB 0.0 -set DIVIDE_DEL_PROB 0.0 -set DIV_MUT_PROB 0.03 -set START_CREATURE org.div1
app = %(default_app)s
nonzeroexit = disallow ; Exit code handling (disallow, allow, or require)
Modified: branches/collect/tests/sex/config/avida.cfg
===================================================================
--- branches/collect/tests/sex/config/avida.cfg 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/tests/sex/config/avida.cfg 2008-06-11 14:47:14 UTC (rev 2642)
@@ -45,7 +45,7 @@
# 4 = Replace random from population (Mass Action)
# 5 = Replace oldest in entire population (like Tierra)
# 6 = Replace random within deme
-PREFER_EMPTY 1 # Give empty cells preference in offsping placement?
+PREFER_EMPTY 0 # Give empty cells preference in offsping placement?
DEATH_METHOD 2 # 0 = Never die of old age.
# 1 = Die when inst executed = AGE_LIMIT (+deviation)
# 2 = Die when inst executed = length*AGE_LIMIT (+dev)
Modified: branches/collect/tests/sex-asex/config/avida.cfg
===================================================================
--- branches/collect/tests/sex-asex/config/avida.cfg 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/tests/sex-asex/config/avida.cfg 2008-06-11 14:47:14 UTC (rev 2642)
@@ -45,7 +45,7 @@
# 4 = Replace random from population (Mass Action)
# 5 = Replace oldest in entire population (like Tierra)
# 6 = Replace random within deme
-PREFER_EMPTY 1 # Give empty cells preference in offsping placement?
+PREFER_EMPTY 0 # Give empty cells preference in offsping placement?
DEATH_METHOD 2 # 0 = Never die of old age.
# 1 = Die when inst executed = AGE_LIMIT (+deviation)
# 2 = Die when inst executed = length*AGE_LIMIT (+dev)
Modified: branches/collect/tests/sex-modular/config/avida.cfg
===================================================================
--- branches/collect/tests/sex-modular/config/avida.cfg 2008-06-11 14:24:12 UTC (rev 2641)
+++ branches/collect/tests/sex-modular/config/avida.cfg 2008-06-11 14:47:14 UTC (rev 2642)
@@ -45,7 +45,7 @@
# 4 = Replace random from population (Mass Action)
# 5 = Replace oldest in entire population (like Tierra)
# 6 = Replace random within deme
-PREFER_EMPTY 1 # Give empty cells preference in offsping placement?
+PREFER_EMPTY 0 # Give empty cells preference in offsping placement?
DEATH_METHOD 2 # 0 = Never die of old age.
# 1 = Die when inst executed = AGE_LIMIT (+deviation)
# 2 = Die when inst executed = length*AGE_LIMIT (+dev)
More information about the Avida-cvs
mailing list