.
This commit is contained in:
44
.old/src/vm/value.cc
Normal file
44
.old/src/vm/value.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "value.hh"
|
||||
|
||||
#include "../common/overloaded.hh"
|
||||
|
||||
namespace tyche::vm {
|
||||
|
||||
std::string type_name(Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case Type::Nil: return "nil";
|
||||
case Type::Integer: return "integer";
|
||||
case Type::Float: return "float";
|
||||
case Type::String: return "string";
|
||||
case Type::Array: return "array";
|
||||
case Type::Table: return "table";
|
||||
case Type::Function: return "function";
|
||||
case Type::NativePointer: return "native pointer";
|
||||
case Type::COUNT: default: return "???";
|
||||
}
|
||||
}
|
||||
|
||||
Type Value::type() const
|
||||
{
|
||||
return std::visit(overloaded {
|
||||
[](std::monostate) { return Type::Nil; },
|
||||
[](int32_t) { return Type::Integer; },
|
||||
[](float) { return Type::Float; },
|
||||
[](std::string const&) { return Type::String; },
|
||||
[](Function const&) { return Type::Function; },
|
||||
}, value_);
|
||||
}
|
||||
|
||||
std::string Value::to_string() const
|
||||
{
|
||||
return std::visit(overloaded {
|
||||
[](std::monostate) { return std::string("nil"); },
|
||||
[](int32_t i) { return std::to_string(i); },
|
||||
[](float f) { return std::to_string(f); },
|
||||
[](std::string const& s) { return s; },
|
||||
[](Function const& f) { return "@" + std::to_string(f.f_id); }
|
||||
}, value_);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user