@@ -2,8 +2,10 @@
|
||||
|
||||
#include "furvm/detail/serialization.hpp"
|
||||
#include "furvm/fwd.hpp"
|
||||
#include "furvm/type.hpp"
|
||||
|
||||
#include <ios>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace furvm {
|
||||
|
||||
@@ -35,6 +37,26 @@ std::ostream& mod::serialize(std::ostream& os) const {
|
||||
}
|
||||
}
|
||||
|
||||
type_id typeCount = type_id(m_types.cend() - m_types.cbegin());
|
||||
detail::serialize(os, typeCount);
|
||||
for (type_id id = 0; id < typeCount; ++id) {
|
||||
if (!m_types.contains(id)) {
|
||||
detail::serialize(os, std::uint8_t(0xFF)); // null type
|
||||
continue;
|
||||
}
|
||||
|
||||
auto type = *m_types.at(id);
|
||||
switch (type->t) {
|
||||
case type_t::Primitive: detail::serialize(os, type->primitive); break;
|
||||
case type_t::Reference: throw std::runtime_error("reference type serialization is unimplemented");
|
||||
case type_t::List: detail::serialize(os, type->list.id()); break;
|
||||
case type_t::Import: {
|
||||
detail::serialize(os, type->imp.mod);
|
||||
detail::serialize(os, type->imp.type);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
detail::serialize(os, std::uint64_t(m_bytecode.size()));
|
||||
return os.write(reinterpret_cast<const char*>(m_bytecode.data()), static_cast<std::streamsize>(m_bytecode.size()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user