|
PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
|
One-line C ABI export for a hand-written NativeStrategyHost.
More...
#include <pineforge/native_host.hpp>#include <pineforge/pineforge.h>#include <pineforge/run_failure.hpp>#include <atomic>#include <cstddef>#include <cstdint>#include <cstring>#include <exception>#include <limits>#include <optional>#include <string>#include <type_traits>#include <vector>Go to the source code of this file.
Data Structures | |
| struct | pineforge::native_module::MetricsPlainHostV1< Host > |
| Specialize for the EXACT host passed to PINEFORGE_EXPORT_NATIVE_STRATEGY. More... | |
| class | pineforge::native_module::MetricsBindingHashV1 |
| class | pineforge::native_module::Module< Host > |
| The one class the macro instantiates: the host plus the module boundary. More... | |
Namespaces | |
| namespace | pineforge |
| namespace | pineforge::native_module |
Macros | |
| #define | PINEFORGE_EXPORT_NATIVE_STRATEGY(Class) |
Define the loadable-module C ABI for one NativeStrategyHost subclass. | |
Functions | |
| std::int32_t | strategy_metrics_only_capability_v1 (void) noexcept |
| Optional per-module probe. | |
| template<typename Host> | |
| bool | pineforge::native_module::metrics_plain_declaration_v1 (MetricsPlainDeclarationV1 &out) noexcept |
| template<typename Host> | |
| std::int32_t | pineforge::native_module::metrics_only_capability_v1 () noexcept |
| std::uint64_t | pineforge::native_module::next_metrics_attempt_v1 () noexcept |
| BacktestEngine * | pineforge::native_module::as_engine (pf_strategy_t strategy) |
| template<typename Host> | |
| Module< Host > * | pineforge::native_module::as_module (pf_strategy_t strategy) |
| template<typename Host> | |
| void | pineforge::native_module::note_error (pf_strategy_t strategy, const char *text, const RunFailureValue &value) |
| RunFailureValue | pineforge::native_module::unclassified_failure () noexcept |
| The code of an exception no coded site raised: engine_unclassified_error. | |
| template<typename Host> | |
| void | pineforge::native_module::note_error (pf_strategy_t strategy, const char *text) |
| The text alone, as before run-failure codes: engine_unclassified_error. | |
| template<typename Host, typename Fn> | |
| void | pineforge::native_module::guarded (pf_strategy_t strategy, Fn &&fn) |
Runs fn and converts any escaping exception into presentation text and its code. | |
| Bar | pineforge::native_module::copy_bar (const pf_bar_t &in) |
| bool | pineforge::native_module::magnifier_unsupported (int bar_magnifier, int magnifier_samples, pf_magnifier_distribution_t distribution) |
A native host owns its own intrabar path through NativeRunSpec::intrabar, so the C magnifier arguments have no meaning here. | |
| void | pineforge::native_module::publish_report (BacktestEngine *engine, pf_report_t *out) |
| Fills a local report first: the caller's struct is written only once the engine has produced a complete, owned value. | |
| template<typename Host> | |
| pf_strategy_t | pineforge::native_module::create () |
| void | pineforge::native_module::destroy (pf_strategy_t strategy) |
| template<typename Host> | |
| void | pineforge::native_module::set_input (pf_strategy_t strategy, const char *key, const char *value) |
| template<typename Host> | |
| void | pineforge::native_module::set_override (pf_strategy_t strategy, const char *key, const char *value) |
| template<typename Host> | |
| void | pineforge::native_module::set_magnifier_volume_weighted (pf_strategy_t strategy, int on) |
| template<typename Host> | |
| void | pineforge::native_module::run_batch (pf_strategy_t strategy, pf_bar_t *bars, int count, const char *input_tf, const char *script_tf, bool with_timeframes, pf_report_t *out) |
| template<typename Host> | |
| void | pineforge::native_module::run_backtest (pf_strategy_t strategy, pf_bar_t *bars, int count, pf_report_t *out) |
| template<typename Host> | |
| void | pineforge::native_module::run_backtest_full (pf_strategy_t strategy, pf_bar_t *bars, int count, const char *input_tf, const char *script_tf, int bar_magnifier, int magnifier_samples, pf_magnifier_distribution_t magnifier_distribution, pf_report_t *out) |
| void | pineforge::native_module::report_free (pf_report_t *report) |
One-line C ABI export for a hand-written NativeStrategyHost.
A loadable PineForge strategy is a shared object that exports a small, fixed set of extern "C" entry points (strategy_create, run_backtest, …) declared in <pineforge/pineforge.h>. Codegen emits them for a PineScript strategy; a native C++ host had to hand-write them. This header generates exactly that surface from one macro:
The ordinary entry points are declared in <pineforge/pineforge.h>. The optional metrics-only capability below belongs to each module, not the static runtime. The remaining runtime exports (strategy_configure_native_v1, the strategy_stream_* family, strategy_get_last_error, …) come from the engine's own c_abi.cpp; the generated strategy_create references pf_abi_version() so the linker keeps that object when the module links libpineforge.a statically.
The host class must be a NativeStrategyHost subclass and must not be final: the module wraps it in one derived class, which is what makes the engine's protected presentation-error string (read back through strategy_get_last_error) writable from the C boundary.
Definition in file native_module.hpp.
| #define PINEFORGE_EXPORT_NATIVE_STRATEGY | ( | Class | ) |
Define the loadable-module C ABI for one NativeStrategyHost subclass.
Use it once, at namespace scope, in the module's translation unit.
Definition at line 521 of file native_module.hpp.
|
noexcept |
Optional per-module probe.
Call it, rather than testing symbol presence: Ok (0) certifies this module's metrics-only adapter; NotImplemented (-1) keeps the actual curve. Callers must resolve LegacyRerun before publishing any report, using a fresh strategy with the same settings and frozen bars.
References PF_API.