Implements very simple REPL, fixes several issues found with it.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2021-01-02 17:41:53 +01:00
parent de15173b0b
commit 9109b7513a
8 changed files with 317 additions and 11 deletions

View File

@@ -35,21 +35,26 @@ namespace MalachScript {
0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330,
0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D};
static int constexpr CalcLength(const char8_t* str) { return *str ? 1 + CalcLength(str + 1) : 0; }
static std::u8string empty;
class Identifier {
std::u8string_view _str;
const char8_t* _str;
size_t _length;
uint32_t _hash;
public:
Identifier() : _str(empty), _hash(0) {}
constexpr Identifier(const char8_t* c) : _str(c), _hash(Hash(c)) {}
Identifier(const std::u8string_view& c) : _str(c), _hash(Hash(c)) {}
Identifier(const std::u8string_view& c, uint32_t hash) : _str(c), _hash(hash) {}
Identifier() : _str(nullptr), _length(0), _hash(0) {}
constexpr Identifier(const char8_t* c) : _str(c), _length(CalcLength(c)), _hash(Hash(c)) {}
constexpr Identifier(const char8_t* c, size_t length, uint32_t hash) : _str(c), _length(length), _hash(hash) {}
[[nodiscard]] constexpr inline uint32_t GetHash() const noexcept { return _hash; }
[[nodiscard]] constexpr inline const std::u8string_view& GetString() const noexcept { return _str; }
[[nodiscard]] constexpr inline std::u8string_view GetString() const noexcept {
return std::u8string_view(_str, _length);
}
[[nodiscard]] constexpr inline size_t GetLength() const noexcept { return _length; }
constexpr inline static uint32_t Hash(const std::u8string_view& sv) {
uint32_t crc = 0xffffffff;
@@ -59,6 +64,11 @@ namespace MalachScript {
return crc ^ 0xffffffff;
}
friend std::ostream& operator<<(std::ostream& out, const Identifier& c) {
out << std::string((const char*)c._str, c._length);
return out;
}
private:
};