2018-08-28 07:16:52 +00:00
|
|
|
/* This file is part of the sirit project.
|
|
|
|
* Copyright (c) 2018 ReinUsesLisp
|
|
|
|
* This software may be used and distributed according to the terms of the GNU
|
2018-11-16 07:10:10 +00:00
|
|
|
* Lesser General Public License version 3 or any later version.
|
2018-08-28 07:16:52 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-03 03:32:45 +00:00
|
|
|
#include <cassert>
|
2019-03-11 06:26:21 +00:00
|
|
|
#include "literal_number.h"
|
2018-08-28 07:16:52 +00:00
|
|
|
|
|
|
|
namespace Sirit {
|
|
|
|
|
2018-10-03 03:32:45 +00:00
|
|
|
LiteralNumber::LiteralNumber(std::type_index type) : type(type) {
|
2018-08-28 07:16:52 +00:00
|
|
|
operand_type = OperandType::Number;
|
|
|
|
}
|
|
|
|
|
|
|
|
LiteralNumber::~LiteralNumber() = default;
|
|
|
|
|
|
|
|
void LiteralNumber::Fetch(Stream& stream) const {
|
2018-10-03 03:32:45 +00:00
|
|
|
if (is_32) {
|
|
|
|
stream.Write(static_cast<u32>(raw));
|
|
|
|
} else {
|
|
|
|
stream.Write(raw);
|
2018-08-28 07:16:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-11 06:26:21 +00:00
|
|
|
u16 LiteralNumber::GetWordCount() const {
|
|
|
|
return is_32 ? 1 : 2;
|
|
|
|
}
|
2018-08-28 07:16:52 +00:00
|
|
|
|
|
|
|
bool LiteralNumber::operator==(const Operand& other) const {
|
|
|
|
if (operand_type == other.GetType()) {
|
|
|
|
const auto& o{dynamic_cast<const LiteralNumber&>(other)};
|
|
|
|
return o.type == type && o.raw == raw;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Sirit
|