2025-06-08 18:16:17 +01:00

36 lines
820 B
C++

#pragma once
#include <cstdint>
#include <iostream>
#include <variant>
enum class StringObjectType : uint8_t {
IDENTIFIER,
LITERAL,
};
enum class ObjectType : uint8_t {
NIL,
IDENTIFIER,
STRING_LIT,
NUMBER,
};
struct Object {
Object() : type{ObjectType::NIL}, value{std::monostate{}} {};
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)} {};
ObjectType type;
std::variant<std::monostate, std::string, double> value;
};
std::ostream &operator<<(std::ostream &os, const ObjectType &type);
std::ostream &operator<<(std::ostream &os, const Object &obj);