2023-08-30 18:06:26 +00:00
|
|
|
#include "Value.hpp"
|
|
|
|
|
|
|
|
namespace roza
|
|
|
|
{
|
|
|
|
/*explicit*/ Value::Value(int value, SrcLoc loc)
|
|
|
|
: m_type { std::make_shared<Type>(BaseType::TY_INT) }
|
|
|
|
, m_int_val { value }
|
|
|
|
, m_loc { loc }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-31 09:07:03 +00:00
|
|
|
/*explicit*/ Value::Value(bool value, SrcLoc loc)
|
|
|
|
: m_type { std::make_shared<Type>(BaseType::TY_BOOL) }
|
|
|
|
, m_bool_val { value }
|
|
|
|
, m_loc { loc }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-30 18:06:26 +00:00
|
|
|
/*virtual*/ Value::~Value()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Value::string() const
|
|
|
|
{
|
|
|
|
if (m_type->equals(TY_INT))
|
|
|
|
{
|
|
|
|
return std::to_string(m_int_val);
|
|
|
|
}
|
|
|
|
|
2023-08-31 09:07:03 +00:00
|
|
|
if (m_type->equals(TY_BOOL))
|
|
|
|
{
|
|
|
|
return m_bool_val ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2023-08-30 18:06:26 +00:00
|
|
|
assert("cannot stringify unknown value " && 0);
|
|
|
|
}
|
|
|
|
}
|