Start adding statements

This commit is contained in:
2025-06-29 19:25:08 +01:00
parent 2690c07220
commit 4f39417d3e
16 changed files with 613 additions and 67 deletions

View File

@@ -2,7 +2,7 @@
#include <cstddef>
#include <string>
std::string Object::to_string() {
std::string Object::to_string() const {
switch (type) {
case ObjectType::NIL:
return "nil";
@@ -78,25 +78,7 @@ std::ostream &operator<<(std::ostream &os, const ObjectType &type) {
}
std::ostream &operator<<(std::ostream &os, const Object &obj) {
os << "Object(" << obj.type;
switch (obj.type) {
case ObjectType::NIL:
break;
case ObjectType::BOOL:
os << ", " << std::to_string(std::get<bool>(obj.value));
break;
case ObjectType::IDENTIFIER:
case ObjectType::STRING_LIT:
os << ", " << std::get<std::string>(obj.value);
break;
case ObjectType::NUMBER:
os << ", " << std::get<double>(obj.value);
break;
}
os << ')';
os << obj.to_string();
return os;
}

View File

@@ -29,7 +29,7 @@ struct Object {
ObjectType::STRING_LIT
},
value{std::move(value)} {};
std::string to_string();
std::string to_string() const;
bool operator==(const Object &other);
bool operator!=(const Object &other);