From 5daed4cc72bc252e7278a53f7ab9bc2890b5f009 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Thu, 12 Oct 2023 17:29:38 -0700 Subject: [PATCH] tbv2: add a repeat instruction --- include/oi/exporters/inst.h | 12 +++++++++++- oi/IntrospectionResult.cpp | 6 ++++++ types/seq_type.toml | 3 +-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/oi/exporters/inst.h b/include/oi/exporters/inst.h index db8856f..8397cd6 100644 --- a/include/oi/exporters/inst.h +++ b/include/oi/exporters/inst.h @@ -32,8 +32,10 @@ namespace oi::exporters::inst { struct PopTypePath; struct Field; +struct Repeat; -using Inst = std::variant>; +using Inst = + std::variant>; using Processor = void (*)(result::Element&, std::function, ParsedData); @@ -41,6 +43,14 @@ using ProcessorInst = std::pair; struct PopTypePath {}; +struct Repeat { + constexpr Repeat(size_t n_, const Field& field_) : n(n_), field(field_) { + } + + size_t n; + std::reference_wrapper field; +}; + struct Field { template constexpr Field(size_t static_size_, diff --git a/oi/IntrospectionResult.cpp b/oi/IntrospectionResult.cpp index e44d740..bc6cf22 100644 --- a/oi/IntrospectionResult.cpp +++ b/oi/IntrospectionResult.cpp @@ -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) { + if (r.n-- != 0) { + stack_.emplace(r); + stack_.emplace(r.field); + } + return operator++(); } else { // reference wrapper auto ty = r.get(); diff --git a/types/seq_type.toml b/types/seq_type.toml index 495fa7c..1da8fd6 100644 --- a/types/seq_type.toml +++ b/types/seq_type.toml @@ -101,6 +101,5 @@ auto list = std::get(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 }); """