Skip to content

Commit

Permalink
remove IsSingleton(), no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Dec 23, 2023
1 parent 07ec4e0 commit 202ae02
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 198 deletions.
209 changes: 60 additions & 149 deletions eidos/eidos_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3771,89 +3771,48 @@ EidosValue_SP EidosInterpreter::Evaluate_Assign(const EidosASTNode *p_node)
{
EidosTokenType compound_operator = rvalue_node->token_->token_type_;
int64_t operand2_value = cached_operand2->IntAtIndex_NOCAST(0, nullptr);
int64_t *int_data = lvalue->IntData_Mutable();

if ((lvalue_count == 1) && lvalue->IsSingleton())
switch (compound_operator)
{
EidosValue_Int *int_singleton = static_cast<EidosValue_Int *>(lvalue);

switch (compound_operator)
case EidosTokenType::kTokenPlus:
{
case EidosTokenType::kTokenPlus:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
int64_t &operand1_value = int_singleton->IntData_Mutable()[0];
bool overflow = Eidos_add_overflow(operand1_value, operand2_value, &operand1_value);
int64_t &int_vec_value = int_data[value_index];
bool overflow = Eidos_add_overflow(int_vec_value, operand2_value, &int_vec_value);

if (overflow)
EIDOS_TERMINATION << "ERROR (EidosInterpreter::Evaluate_Assign): integer addition overflow with the binary '+' operator." << EidosTerminate(rvalue_node->token_);
goto compoundAssignmentSuccess;
}
case EidosTokenType::kTokenMinus:
goto compoundAssignmentSuccess;
}
case EidosTokenType::kTokenMinus:
{
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
int64_t &operand1_value = int_singleton->IntData_Mutable()[0];
bool overflow = Eidos_sub_overflow(operand1_value, operand2_value, &operand1_value);
int64_t &int_vec_value = int_data[value_index];
bool overflow = Eidos_sub_overflow(int_vec_value, operand2_value, &int_vec_value);

if (overflow)
EIDOS_TERMINATION << "ERROR (EidosInterpreter::Evaluate_Assign): integer subtraction overflow with the binary '-' operator." << EidosTerminate(rvalue_node->token_);
goto compoundAssignmentSuccess;
}
case EidosTokenType::kTokenMult:
goto compoundAssignmentSuccess;
}
case EidosTokenType::kTokenMult:
{
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
int64_t &operand1_value = int_singleton->IntData_Mutable()[0];
bool overflow = Eidos_mul_overflow(operand1_value, operand2_value, &operand1_value);
int64_t &int_vec_value = int_data[value_index];
bool overflow = Eidos_mul_overflow(int_vec_value, operand2_value, &int_vec_value);

if (overflow)
EIDOS_TERMINATION << "ERROR (EidosInterpreter::Evaluate_Assign): integer multiplication overflow with the '*' operator." << EidosTerminate(rvalue_node->token_);
goto compoundAssignmentSuccess;
}
default: // div, mod, and exp always produce float, so we don't handle them for int; we can't change the type of x here
break;
}
}
else
{
int64_t *int_data = lvalue->IntData_Mutable();

switch (compound_operator)
{
case EidosTokenType::kTokenPlus:
{
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
int64_t &int_vec_value = int_data[value_index];
bool overflow = Eidos_add_overflow(int_vec_value, operand2_value, &int_vec_value);

if (overflow)
EIDOS_TERMINATION << "ERROR (EidosInterpreter::Evaluate_Assign): integer addition overflow with the binary '+' operator." << EidosTerminate(rvalue_node->token_);
}
goto compoundAssignmentSuccess;
}
case EidosTokenType::kTokenMinus:
{
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
int64_t &int_vec_value = int_data[value_index];
bool overflow = Eidos_sub_overflow(int_vec_value, operand2_value, &int_vec_value);

if (overflow)
EIDOS_TERMINATION << "ERROR (EidosInterpreter::Evaluate_Assign): integer subtraction overflow with the binary '-' operator." << EidosTerminate(rvalue_node->token_);
}
goto compoundAssignmentSuccess;
}
case EidosTokenType::kTokenMult:
{
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
int64_t &int_vec_value = int_data[value_index];
bool overflow = Eidos_mul_overflow(int_vec_value, operand2_value, &int_vec_value);

if (overflow)
EIDOS_TERMINATION << "ERROR (EidosInterpreter::Evaluate_Assign): integer multiplication overflow with the '*' operator." << EidosTerminate(rvalue_node->token_);
}
goto compoundAssignmentSuccess;
}
default: // div, mod, and exp always produce float, so we don't handle them for int; we can't change the type of x here
break;
goto compoundAssignmentSuccess;
}
default: // div, mod, and exp always produce float, so we don't handle them for int; we can't change the type of x here
break;
}
}
}
Expand All @@ -3864,99 +3823,51 @@ EidosValue_SP EidosInterpreter::Evaluate_Assign(const EidosASTNode *p_node)
EidosValue *cached_operand2 = rvalue_node->children_[1]->cached_literal_value_.get(); // the numeric constant
EidosTokenType compound_operator = rvalue_node->token_->token_type_;
double operand2_value = cached_operand2->NumericAtIndex_NOCAST(0, nullptr); // might be an int64_t and get converted
double *float_data = lvalue->FloatData_Mutable();

if ((lvalue_count == 1) && lvalue->IsSingleton())
switch (compound_operator)
{
EidosValue_Float *float_singleton = static_cast<EidosValue_Float *>(lvalue);

switch (compound_operator)
{
case EidosTokenType::kTokenPlus:
float_singleton->FloatData_Mutable()[0] += operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenMinus:
float_singleton->FloatData_Mutable()[0] -= operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenMult:
float_singleton->FloatData_Mutable()[0] *= operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenDiv:
float_singleton->FloatData_Mutable()[0] /= operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenMod:
case EidosTokenType::kTokenPlus:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
float_data[value_index] += operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenMinus:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
float_data[value_index] -= operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenMult:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
float_data[value_index] *= operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenDiv:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
float_data[value_index] /= operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenMod:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
double &operand1_value = float_singleton->FloatData_Mutable()[0];
double &float_vec_value = float_data[value_index];

operand1_value = fmod(operand1_value, operand2_value);
goto compoundAssignmentSuccess;
float_vec_value = fmod(float_vec_value, operand2_value);
}

case EidosTokenType::kTokenExp:
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenExp:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
double &operand1_value = float_singleton->FloatData_Mutable()[0];
double &float_vec_value = float_data[value_index];

operand1_value = pow(operand1_value, operand2_value);
goto compoundAssignmentSuccess;
float_vec_value = pow(float_vec_value, operand2_value);
}

default:
// CODE COVERAGE: This is dead code
break;
}

}
else
{
double *float_data = lvalue->FloatData_Mutable();

switch (compound_operator)
{
case EidosTokenType::kTokenPlus:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
float_data[value_index] += operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenMinus:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
float_data[value_index] -= operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenMult:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
float_data[value_index] *= operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenDiv:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
float_data[value_index] /= operand2_value;
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenMod:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
double &float_vec_value = float_data[value_index];

float_vec_value = fmod(float_vec_value, operand2_value);
}
goto compoundAssignmentSuccess;

case EidosTokenType::kTokenExp:
for (int value_index = 0; value_index < lvalue_count; ++value_index)
{
double &float_vec_value = float_data[value_index];

float_vec_value = pow(float_vec_value, operand2_value);
}
goto compoundAssignmentSuccess;

default:
// CODE COVERAGE: This is dead code
break;
}
goto compoundAssignmentSuccess;

default:
// CODE COVERAGE: This is dead code
break;
}

goto compoundAssignmentSuccess;
Expand Down
34 changes: 17 additions & 17 deletions eidos/eidos_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ int EidosValue::valueTrackingCount;
std::vector<EidosValue *> EidosValue::valueTrackingVector;
#endif

EidosValue::EidosValue(EidosValueType p_value_type, bool p_singleton) : intrusive_ref_count_(0), cached_type_(p_value_type), constant_(false), invisible_(false), is_singleton_(p_singleton), dim_(nullptr)
EidosValue::EidosValue(EidosValueType p_value_type) : intrusive_ref_count_(0), cached_type_(p_value_type), constant_(false), invisible_(false), dim_(nullptr)
{
#ifdef EIDOS_TRACK_VALUE_ALLOCATION
valueTrackingCount++;
Expand Down Expand Up @@ -968,7 +968,7 @@ void EidosValue_NULL::Sort(bool p_ascending)
#pragma mark EidosValue_Logical
#pragma mark -

EidosValue_Logical::EidosValue_Logical(const std::vector<eidos_logical_t> &p_logicalvec) : EidosValue(EidosValueType::kValueLogical, false)
EidosValue_Logical::EidosValue_Logical(const std::vector<eidos_logical_t> &p_logicalvec) : EidosValue(EidosValueType::kValueLogical)
{
size_t count = p_logicalvec.size();
const eidos_logical_t *values = p_logicalvec.data();
Expand All @@ -979,20 +979,20 @@ EidosValue_Logical::EidosValue_Logical(const std::vector<eidos_logical_t> &p_log
set_logical_no_check(values[index], index);
}

EidosValue_Logical::EidosValue_Logical(eidos_logical_t p_logical1) : EidosValue(EidosValueType::kValueLogical, false) // protected
EidosValue_Logical::EidosValue_Logical(eidos_logical_t p_logical1) : EidosValue(EidosValueType::kValueLogical) // protected
{
push_logical(p_logical1);
}

EidosValue_Logical::EidosValue_Logical(std::initializer_list<eidos_logical_t> p_init_list) : EidosValue(EidosValueType::kValueLogical, false)
EidosValue_Logical::EidosValue_Logical(std::initializer_list<eidos_logical_t> p_init_list) : EidosValue(EidosValueType::kValueLogical)
{
reserve(p_init_list.size());

for (auto init_item : p_init_list)
push_logical_no_check(init_item);
}

EidosValue_Logical::EidosValue_Logical(const eidos_logical_t *p_values, size_t p_count) : EidosValue(EidosValueType::kValueLogical, false)
EidosValue_Logical::EidosValue_Logical(const eidos_logical_t *p_values, size_t p_count) : EidosValue(EidosValueType::kValueLogical)
{
resize_no_initialize(p_count);

Expand Down Expand Up @@ -1168,17 +1168,17 @@ void EidosValue_Logical::erase_index(size_t p_index)
#pragma mark EidosValue_String
#pragma mark -

EidosValue_String::EidosValue_String(const std::vector<std::string> &p_stringvec) : EidosValue(EidosValueType::kValueString, false), values_(p_stringvec)
EidosValue_String::EidosValue_String(const std::vector<std::string> &p_stringvec) : EidosValue(EidosValueType::kValueString), values_(p_stringvec)
{
}

EidosValue_String::EidosValue_String(std::initializer_list<const std::string> p_init_list) : EidosValue(EidosValueType::kValueString, false)
EidosValue_String::EidosValue_String(std::initializer_list<const std::string> p_init_list) : EidosValue(EidosValueType::kValueString)
{
for (const auto &init_item : p_init_list)
values_.emplace_back(init_item);
}

EidosValue_String::EidosValue_String(std::initializer_list<const char *> p_init_list) : EidosValue(EidosValueType::kValueString, false)
EidosValue_String::EidosValue_String(std::initializer_list<const char *> p_init_list) : EidosValue(EidosValueType::kValueString)
{
for (const auto &init_item : p_init_list)
values_.emplace_back(init_item);
Expand Down Expand Up @@ -1314,7 +1314,7 @@ void EidosValue_String::Sort(bool p_ascending)
#pragma mark EidosValue_Int
#pragma mark -

EidosValue_Int::EidosValue_Int(const std::vector<int16_t> &p_intvec) : EidosValue(EidosValueType::kValueInt, false), values_(&singleton_value_), count_(0), capacity_(1)
EidosValue_Int::EidosValue_Int(const std::vector<int16_t> &p_intvec) : EidosValue(EidosValueType::kValueInt), values_(&singleton_value_), count_(0), capacity_(1)
{
size_t count = p_intvec.size();
const int16_t *values = p_intvec.data();
Expand All @@ -1325,7 +1325,7 @@ EidosValue_Int::EidosValue_Int(const std::vector<int16_t> &p_intvec) : EidosValu
set_int_no_check(values[index], index);
}

EidosValue_Int::EidosValue_Int(const std::vector<int32_t> &p_intvec) : EidosValue(EidosValueType::kValueInt, false), values_(&singleton_value_), count_(0), capacity_(1)
EidosValue_Int::EidosValue_Int(const std::vector<int32_t> &p_intvec) : EidosValue(EidosValueType::kValueInt), values_(&singleton_value_), count_(0), capacity_(1)
{
size_t count = p_intvec.size();
const int32_t *values = p_intvec.data();
Expand All @@ -1336,7 +1336,7 @@ EidosValue_Int::EidosValue_Int(const std::vector<int32_t> &p_intvec) : EidosValu
set_int_no_check(values[index], index);
}

EidosValue_Int::EidosValue_Int(const std::vector<int64_t> &p_intvec) : EidosValue(EidosValueType::kValueInt, false), values_(&singleton_value_), count_(0), capacity_(1)
EidosValue_Int::EidosValue_Int(const std::vector<int64_t> &p_intvec) : EidosValue(EidosValueType::kValueInt), values_(&singleton_value_), count_(0), capacity_(1)
{
size_t count = p_intvec.size();
const int64_t *values = p_intvec.data();
Expand All @@ -1347,15 +1347,15 @@ EidosValue_Int::EidosValue_Int(const std::vector<int64_t> &p_intvec) : EidosValu
set_int_no_check(values[index], index);
}

EidosValue_Int::EidosValue_Int(std::initializer_list<int64_t> p_init_list) : EidosValue(EidosValueType::kValueInt, false), values_(&singleton_value_), count_(0), capacity_(1)
EidosValue_Int::EidosValue_Int(std::initializer_list<int64_t> p_init_list) : EidosValue(EidosValueType::kValueInt), values_(&singleton_value_), count_(0), capacity_(1)
{
reserve(p_init_list.size());

for (auto init_item : p_init_list)
push_int_no_check(init_item);
}

EidosValue_Int::EidosValue_Int(const int64_t *p_values, size_t p_count) : EidosValue(EidosValueType::kValueInt, false), values_(&singleton_value_), count_(0), capacity_(1)
EidosValue_Int::EidosValue_Int(const int64_t *p_values, size_t p_count) : EidosValue(EidosValueType::kValueInt), values_(&singleton_value_), count_(0), capacity_(1)
{
resize_no_initialize(p_count);

Expand Down Expand Up @@ -1536,7 +1536,7 @@ void EidosValue_Int::erase_index(size_t p_index)
#pragma mark EidosValue_Float
#pragma mark -

EidosValue_Float::EidosValue_Float(const std::vector<double> &p_doublevec) : EidosValue(EidosValueType::kValueFloat, false), values_(&singleton_value_), count_(0), capacity_(1)
EidosValue_Float::EidosValue_Float(const std::vector<double> &p_doublevec) : EidosValue(EidosValueType::kValueFloat), values_(&singleton_value_), count_(0), capacity_(1)
{
size_t count = p_doublevec.size();
const double *values = p_doublevec.data();
Expand All @@ -1547,15 +1547,15 @@ EidosValue_Float::EidosValue_Float(const std::vector<double> &p_doublevec) : Eid
set_float_no_check(values[index], index);
}

EidosValue_Float::EidosValue_Float(std::initializer_list<double> p_init_list) : EidosValue(EidosValueType::kValueFloat, false), values_(&singleton_value_), count_(0), capacity_(1)
EidosValue_Float::EidosValue_Float(std::initializer_list<double> p_init_list) : EidosValue(EidosValueType::kValueFloat), values_(&singleton_value_), count_(0), capacity_(1)
{
reserve(p_init_list.size());

for (auto init_item : p_init_list)
push_float_no_check(init_item);
}

EidosValue_Float::EidosValue_Float(const double *p_values, size_t p_count) : EidosValue(EidosValueType::kValueFloat, false), values_(&singleton_value_), count_(0), capacity_(1)
EidosValue_Float::EidosValue_Float(const double *p_values, size_t p_count) : EidosValue(EidosValueType::kValueFloat), values_(&singleton_value_), count_(0), capacity_(1)
{
resize_no_initialize(p_count);

Expand Down Expand Up @@ -1756,7 +1756,7 @@ void EidosValue_Float::erase_index(size_t p_index)
// See comments on EidosValue_Object::EidosValue_Object() below. Note this is shared by all species.
std::vector<EidosValue_Object *> gEidosValue_Object_Mutation_Registry;

EidosValue_Object::EidosValue_Object(const EidosClass *p_class) : EidosValue(EidosValueType::kValueObject, false),
EidosValue_Object::EidosValue_Object(const EidosClass *p_class) : EidosValue(EidosValueType::kValueObject),
class_(p_class), values_(&singleton_value_), count_(0), capacity_(1)
{
class_uses_retain_release_ = (class_ == gEidosObject_Class ? true : class_->UsesRetainRelease());
Expand Down
Loading

0 comments on commit 202ae02

Please sign in to comment.