42 lines
956 B
C++
42 lines
956 B
C++
#ifndef OBJECT_HH
|
|
#define OBJECT_HH
|
|
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <variant>
|
|
|
|
enum class StringObjectType : uint8_t {
|
|
IDENTIFIER,
|
|
LITERAL,
|
|
};
|
|
|
|
enum class ObjectType : uint8_t {
|
|
NIL,
|
|
BOOL,
|
|
IDENTIFIER,
|
|
STRING_LIT,
|
|
NUMBER,
|
|
};
|
|
|
|
struct Object {
|
|
Object() : type{ObjectType::NIL}, value{std::monostate{}} {};
|
|
Object(bool value) : type{ObjectType::BOOL}, value{value} {};
|
|
Object(double number) : type{ObjectType::NUMBER}, value{number} {};
|
|
Object(StringObjectType string_type, std::string value)
|
|
: type{
|
|
string_type == StringObjectType::IDENTIFIER ?
|
|
ObjectType::IDENTIFIER :
|
|
ObjectType::STRING_LIT
|
|
},
|
|
value{std::move(value)} {};
|
|
std::string to_string();
|
|
|
|
ObjectType type;
|
|
std::variant<std::monostate, std::string, double, bool> value;
|
|
};
|
|
|
|
std::ostream &operator<<(std::ostream &os, const ObjectType &type);
|
|
std::ostream &operator<<(std::ostream &os, const Object &obj);
|
|
|
|
#endif
|