mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 10:56:30 +00:00
fix format header error
This commit is contained in:
parent
8839e19857
commit
70473f353a
16
runtime/alloc.cpp
Normal file
16
runtime/alloc.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "alloc.hpp"
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sliger::heap;
|
||||
|
||||
auto Array::at(int32_t index) & -> Value&
|
||||
{
|
||||
if (index >= static_cast<int32_t>(this->values.size()) || index < 0) {
|
||||
std::cout << std::format(
|
||||
"index not in range, expected to be in range (0..{}), got: {}",
|
||||
this->values.size(), index);
|
||||
exit(1);
|
||||
}
|
||||
return values.at(static_cast<size_t>(index));
|
||||
}
|
@ -13,13 +13,8 @@ namespace sliger::heap {
|
||||
|
||||
struct Array {
|
||||
std::vector<Value> values;
|
||||
inline auto at(int32_t index)& -> Value& {
|
||||
if (index >= static_cast<int32_t>(this->values.size()) || index < 0) {
|
||||
std::cout << std::format("index not in range, expected to be in range (0..{}), got: {}", this->values.size(), index);
|
||||
exit(1);
|
||||
}
|
||||
return values.at(index);
|
||||
}
|
||||
|
||||
auto at(int32_t index) & -> Value&;
|
||||
};
|
||||
|
||||
struct Struct {
|
||||
@ -40,9 +35,21 @@ template <> struct AllocTypeType<AllocType::Struct> { using Type = Struct; };
|
||||
// clang-format on
|
||||
|
||||
struct AllocItem {
|
||||
AllocItem(Value&& val) : type(AllocType::Value), value(val) {}
|
||||
AllocItem(Array&& val) : type(AllocType::Array), value(val) {}
|
||||
AllocItem(Struct&& val) : type(AllocType::Struct), value(val) {}
|
||||
AllocItem(Value&& val)
|
||||
: type(AllocType::Value)
|
||||
, value(val)
|
||||
{
|
||||
}
|
||||
AllocItem(Array&& val)
|
||||
: type(AllocType::Array)
|
||||
, value(val)
|
||||
{
|
||||
}
|
||||
AllocItem(Struct&& val)
|
||||
: type(AllocType::Struct)
|
||||
, value(val)
|
||||
{
|
||||
}
|
||||
|
||||
template <AllocType AT> inline auto as() & -> AllocTypeType<AT>::Type&
|
||||
{
|
||||
@ -65,26 +72,25 @@ struct AllocItem {
|
||||
std::get<typename AllocTypeType<AT>::Type>(this->value));
|
||||
}
|
||||
|
||||
inline auto as_value() & -> Value& {
|
||||
inline auto as_value() & -> Value& { return std::get<Value>(this->value); }
|
||||
inline auto as_value() const& -> const Value&
|
||||
{
|
||||
return std::get<Value>(this->value);
|
||||
}
|
||||
inline auto as_value() const & -> const Value& {
|
||||
return std::get<Value>(this->value);
|
||||
}
|
||||
inline auto as_array() & -> Array& {
|
||||
inline auto as_array() & -> Array& { return std::get<Array>(this->value); }
|
||||
inline auto as_array() const& -> const Array&
|
||||
{
|
||||
return std::get<Array>(this->value);
|
||||
}
|
||||
inline auto as_array() const & -> const Array& {
|
||||
return std::get<Array>(this->value);
|
||||
}
|
||||
inline auto as_struct() & -> Struct& {
|
||||
inline auto as_struct() & -> Struct&
|
||||
{
|
||||
return std::get<Struct>(this->value);
|
||||
}
|
||||
inline auto as_struct() const & -> const Struct& {
|
||||
inline auto as_struct() const& -> const Struct&
|
||||
{
|
||||
return std::get<Struct>(this->value);
|
||||
}
|
||||
|
||||
|
||||
AllocType type;
|
||||
std::variant<Value, Array, Struct> value;
|
||||
};
|
||||
|
@ -4,6 +4,17 @@
|
||||
|
||||
using namespace sliger;
|
||||
|
||||
auto String::at(int32_t index) -> int32_t
|
||||
{
|
||||
if (index >= static_cast<int32_t>(this->value.length()) || index < 0) {
|
||||
std::cout << std::format(
|
||||
"index not in range, expected to be in range (0..{}), got: {}",
|
||||
this->value.length() - 1, index);
|
||||
exit(1);
|
||||
}
|
||||
return this->value.at(static_cast<size_t>(index));
|
||||
}
|
||||
|
||||
auto Value::to_string() const -> std::string
|
||||
{
|
||||
switch (this->m_type) {
|
||||
|
@ -68,13 +68,8 @@ struct Bool {
|
||||
};
|
||||
struct String {
|
||||
std::string value;
|
||||
inline auto at(int32_t index) -> int32_t {
|
||||
if (index >= static_cast<int32_t>(this->value.length()) || index < 0) {
|
||||
std::cout << std::format("index not in range, expected to be in range (0..{}), got: {}", this->value.length()-1, index);
|
||||
exit(1);
|
||||
}
|
||||
return this->value.at(index);
|
||||
}
|
||||
|
||||
auto at(int32_t index) -> int32_t;
|
||||
};
|
||||
struct Ptr {
|
||||
uint32_t value;
|
||||
|
Loading…
Reference in New Issue
Block a user