tbv2: add a repeat instruction

This commit is contained in:
Jake Hillion 2023-10-12 17:29:38 -07:00 committed by Jake Hillion
parent 6f3580143e
commit 5daed4cc72
3 changed files with 18 additions and 3 deletions

View File

@ -32,8 +32,10 @@ namespace oi::exporters::inst {
struct PopTypePath;
struct Field;
struct Repeat;
using Inst = std::variant<PopTypePath, std::reference_wrapper<const Field>>;
using Inst =
std::variant<PopTypePath, Repeat, std::reference_wrapper<const Field>>;
using Processor = void (*)(result::Element&,
std::function<void(Inst)>,
ParsedData);
@ -41,6 +43,14 @@ using ProcessorInst = std::pair<types::dy::Dynamic, Processor>;
struct PopTypePath {};
struct Repeat {
constexpr Repeat(size_t n_, const Field& field_) : n(n_), field(field_) {
}
size_t n;
std::reference_wrapper<const Field> field;
};
struct Field {
template <size_t N0, size_t N1, size_t N2>
constexpr Field(size_t static_size_,

View File

@ -44,6 +44,12 @@ IntrospectionResult::const_iterator::operator++() {
type_path_.pop_back();
dynamic_type_path_.pop_back();
return operator++();
} else if constexpr (std::is_same_v<U, exporters::inst::Repeat>) {
if (r.n-- != 0) {
stack_.emplace(r);
stack_.emplace(r.field);
}
return operator++();
} else {
// reference wrapper
auto ty = r.get();

View File

@ -101,6 +101,5 @@ auto list = std::get<ParsedData::List>(d.val);
el.container_stats->length = list.length;
el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(T0);
for (size_t i = 0; i < list.length; i++)
stack_ins(childField);
stack_ins(inst::Repeat{ list.length, childField });
"""