nk
1.0.0
C++ Numerical Computing Runtime
Toggle main menu visibility
Loading...
Searching...
No Matches
reactive_session.hpp
1
32
33
#pragma once
34
35
#include <nk/core/ast.hpp>
36
#include <nk/core/dependency_graph.hpp>
37
#include <nk/core/types.hpp>
38
#include <
nk/figure/figure_manager.hpp
>
39
40
#include <cstdint>
41
#include <memory>
42
#include <set>
43
#include <string>
44
#include <vector>
45
46
namespace
nk {
47
48
class
Engine
;
49
50
class
ReactiveSession
51
{
52
public
:
55
explicit
ReactiveSession
(
Engine
&engine);
56
61
bool
load
(
const
std::string &source);
62
66
void
setParam
(
const
std::string &var,
Value
value);
67
71
void
setParamElement
(
const
std::string &var,
size_t
r,
size_t
c,
72
Value
value);
73
77
size_t
evalDirty
();
78
80
bool
hasDirty
()
const
{
return
!dirty_.empty(); }
81
84
std::vector<std::vector<size_t>>
detectCycles
()
const
;
85
86
const
DependencyGraph
&graph()
const
{
return
*graph_; }
87
size_t
statementCount()
const
{
return
statements_.size(); }
88
const
std::string &lastError()
const
{
return
lastError_; }
89
92
uint64_t
generation
()
const
{
return
generation_; }
93
94
private
:
95
void
markDirty(
const
std::vector<size_t> &indices);
96
Value
runStatement(
size_t
index);
97
98
Engine
&engine_;
99
std::shared_ptr<const std::string> src_;
100
std::vector<ASTNodePtr> statements_;
// program children (owned)
101
std::unique_ptr<DependencyGraph> graph_;
102
// Figure-state rollback points, one per statement (captured after
103
// that statement ran). evalDirty restores the checkpoint of the
104
// last CLEAN statement before the dirty set, so re-run graphics
105
// statements reproduce the full-re-run figure (no `hold on`
106
// line accumulation across ticks).
107
std::vector<FigureManager::FigureCheckpoint> checkpoints_;
108
// Figure state captured in load() BEFORE the first statement runs
109
// (may hold a PREVIOUS script's figures — sessions share the
110
// engine). The rollback target when a dirty set starts at 0.
111
FigureManager::FigureCheckpoint
preScriptCp_;
112
std::set<size_t> dirty_;
113
std::set<std::string> params_;
// externally-set variables
114
std::string lastError_;
115
uint64_t generation_ = 0;
116
};
117
118
}
// namespace nk
nk::DependencyGraph
Dependency DAG over statement indices.
Definition
dependency_graph.hpp:85
nk::Engine
Definition
engine.hpp:32
nk::ReactiveSession::evalDirty
size_t evalDirty()
Execute the dirty statements in source order through the per-statement seam.
nk::ReactiveSession::detectCycles
std::vector< std::vector< size_t > > detectCycles() const
Tarjan SCCs over the dependency edges (invariant guard — expected empty while edges stay forward-only...
nk::ReactiveSession::load
bool load(const std::string &source)
Parse source, compute facts + DAG, run the initial FULL pass (whole-source eval — script/function sem...
nk::ReactiveSession::ReactiveSession
ReactiveSession(Engine &engine)
The engine is NOT owned; the session must outlive uses of it with that engine (workspace state is sha...
nk::ReactiveSession::generation
uint64_t generation() const
Bumped on every committed write (param/element/evalDirty) — the buffer-generation source for zero-cop...
Definition
reactive_session.hpp:92
nk::ReactiveSession::setParamElement
void setParamElement(const std::string &var, size_t r, size_t c, Value value)
Single-cell write (the reactive table editor).
nk::ReactiveSession::setParam
void setParam(const std::string &var, Value value)
Whole-variable parameter write (Play sliders).
nk::ReactiveSession::hasDirty
bool hasDirty() const
True when something is pending for evalDirty().
Definition
reactive_session.hpp:80
nk::Value
Core MATLAB-compatible multidimensional array and scalar value type.
Definition
value.hpp:61
figure_manager.hpp
nk::FigureManager::FigureCheckpoint
Definition
figure_manager.hpp:1147
src
core
include
nk
core
reactive_session.hpp
Generated by
1.17.0