PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
report_pages.hpp
Go to the documentation of this file.
1#pragma once
2
3// O1 report contract v1: C++ reader declarations, not a support probe.
4// Modes/metadata remain in report_mode.h; see docs/design/o1-report-contract.md.
5// Ledger and metrics lanes supply the providers, with no storage defined here.
7
8#include <cstddef>
9#include <cstdint>
10
11namespace pineforge {
12namespace report {
13
14using LogicalIndexV1 = std::uint64_t;
15
16// Text is transferred separately, so an arbitrarily long ID/comment does not
17// force a row or a bounded page to own an equally large string.
18enum class TradeTextV1 : std::uint32_t {
21 ExitId = 2,
23};
24
25// Detached numeric value: preserve every field/float bit and the existing
26// close-cause classification. exit_from_bracket is the separate raw 0/1 label.
27struct TradeRowV1 {
29 std::uint64_t entry_incarnation = 0;
30 std::int32_t close_cause = 0; // pf_close_cause_t values
31 std::uint32_t exit_from_bracket = 0;
32};
33
36 bool complete = false;
37};
38
39// Values, including callback arguments, never alias a refillable/retired page.
40using TradeVisitorV1 = bool (*)(void*, LogicalIndexV1, TradeRowV1);
42
43// A single frozen final presented point, also available in SUMMARY_ONLY.
44// present is independent of sequence capture and does not certify completion.
45// If present, index == logical point count - 1; otherwise index/value are zero.
46// During execution the metrics owner holds an editable last point and its
47// pre-tail fold snapshot, finalizing it only after presentation is settled.
53
54// One source describes a fixed logical generation. Engine accessors return
55// caller-owned adapters, not pointers/references to rows or resident pages.
56// Their engine context is borrowed: use only until the next execution/config
57// mutation and while the engine lives. Read-cache refills do not change the
58// logical generation. Completed history is readable at a committed
59// script callback boundary; report sources describe a completed frozen report.
60// Never mutate/run the engine inside a visitor. Provider-owned pages may be
61// retired/refilled between calls; detached values and caller buffers survive.
62//
63// size() counts ALL logical rows, including retired history. at(index) returns
64// a value for index < size(). read_page(from,out,capacity) copies ascending
65// indices, at most min(capacity,size()-from) rows. from==size() and capacity==0
66// are valid. nullptr is valid only with capacity==0, even at the sequence end.
67//
68// Both visits select [from,from+count). visit() walks ascending indices;
69// visit_backward() walks from+count-1 down to from, newest logical row first,
70// never sorted by exit_time (including ties and nonmonotonic times). Each is
71// ONE pass, without restarting execution per row or accumulating a row list.
72// A false callback stops after that row: visited includes it and complete is
73// false, even on the final row. A consumed range, including empty, is complete.
74//
75// Validate ranges without overflow: from<=size(), count<=size()-from. Invalid
76// indices/ranges throw std::out_of_range; invalid buffers, text selectors or
77// null visitors throw std::invalid_argument, including on empty visits.
78// Validate before copying/callbacks. Context may be null. Backing/visitor
79// failures propagate; they never become EOF, an empty source or a success.
80// Capacity is a transfer quantum, never an admission/capacity refusal.
82public:
83 virtual ~TradeSourceV1() = default;
84 virtual LogicalIndexV1 size() const = 0;
85 virtual TradeRowV1 at(LogicalIndexV1 index) const = 0;
86 virtual std::size_t read_page(LogicalIndexV1 from, TradeRowV1* out,
87 std::size_t capacity) const = 0;
89 void* context, TradeVisitorV1 visitor) const = 0;
91 void* context, TradeVisitorV1 visitor) const = 0;
92 // Exact stored text bytes, no normalization or appended NUL. Offsets and
93 // lengths are bytes; a chunk may split UTF-8. Chunks belong to the caller.
94 // Same end/buffer rules as read_page; byte_offset>text_size(index,field) throws.
95 virtual std::uint64_t text_size(LogicalIndexV1 index, TradeTextV1 field) const = 0;
96 virtual std::size_t read_text(LogicalIndexV1 index, TradeTextV1 field,
97 std::uint64_t byte_offset, char* out,
98 std::size_t capacity) const = 0;
99};
100
101// Same by-value/index/page/forward-visit/error rules as TradeSourceV1. Points
102// are final presented values in report order, including a selected anchor.
103// A source supports repeated ordered passes through bounded buffers, never an
104// execution restart per at(). SUMMARY_ONLY has no captured point source:
105// the metrics lane instead feeds final values to EquityVisitorV1 during its
106// fixed ordered passes and keeps only the held point/folds/replay witnesses.
108public:
109 virtual ~EquityPointSourceV1() = default;
110 virtual LogicalIndexV1 size() const = 0;
111 virtual pf_equity_point_t at(LogicalIndexV1 index) const = 0;
112 virtual std::size_t read_page(LogicalIndexV1 from, pf_equity_point_t* out,
113 std::size_t capacity) const = 0;
115 void* context, EquityVisitorV1 visitor) const = 0;
116};
117
118} // namespace report
119} // namespace pineforge
virtual std::size_t read_page(LogicalIndexV1 from, pf_equity_point_t *out, std::size_t capacity) const =0
virtual LogicalIndexV1 size() const =0
virtual VisitResultV1 visit(LogicalIndexV1 from, LogicalIndexV1 count, void *context, EquityVisitorV1 visitor) const =0
virtual pf_equity_point_t at(LogicalIndexV1 index) const =0
virtual ~TradeSourceV1()=default
virtual std::size_t read_page(LogicalIndexV1 from, TradeRowV1 *out, std::size_t capacity) const =0
virtual VisitResultV1 visit(LogicalIndexV1 from, LogicalIndexV1 count, void *context, TradeVisitorV1 visitor) const =0
virtual VisitResultV1 visit_backward(LogicalIndexV1 from, LogicalIndexV1 count, void *context, TradeVisitorV1 visitor) const =0
virtual std::size_t read_text(LogicalIndexV1 index, TradeTextV1 field, std::uint64_t byte_offset, char *out, std::size_t capacity) const =0
virtual std::uint64_t text_size(LogicalIndexV1 index, TradeTextV1 field) const =0
virtual LogicalIndexV1 size() const =0
virtual TradeRowV1 at(LogicalIndexV1 index) const =0
bool(*)(void *, LogicalIndexV1, pf_equity_point_t) EquityVisitorV1
std::uint64_t LogicalIndexV1
bool(*)(void *, LogicalIndexV1, TradeRowV1) TradeVisitorV1
Single per-script-bar equity point.
Definition pineforge.h:326
Closed-trade record returned in pf_report_t::trades.
Definition pineforge.h:166