Skip to content

Commit

Permalink
tbv2: add a repeat instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHillion committed Oct 25, 2023
1 parent 6f35801 commit 5daed4c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion include/oi/exporters/inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,25 @@ 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);
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_,
Expand Down
6 changes: 6 additions & 0 deletions oi/IntrospectionResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions types/seq_type.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
"""

0 comments on commit 5daed4c

Please sign in to comment.