Leonardus
Loading...
Searching...
No Matches
context.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Library
20#include <string>
21#include <map>
22#include <cstdint>
23
24// Inc HAA
25#include "dbc.h"
26#include "helper.h"
27
28// Inc Medium
29#include "counter.h"
30
31// Inc Rich
32#include "sok.h"
33#include "sof.h"
34
35
45class Context : public Counter<Context>, protected DbC {
46
47 bool run_ = true;
48 SOK os_{},
49 es_{},
50 ds_{};
52 std::string snapLeonline_{};
53 int proclevel_ = 0;
55 int loadlevel_ = 0;
57 int arraynesting_ = 0;
63 size_t maxloadlevel_ = 1000;
64 uint32_t seed_ = 0;
67public:
68 constexpr static size_t mindictstack_ = 3;
71protected:
72#ifndef DBC_IS_VOID
77 bool invariant() const noexcept override { /* LCOV_EXCL_START */
78 if( proclevel_ < 0 )
79 return false;
80 if( loadlevel_ < 0 )
81 return false;
82 if( inf_ == nullptr )
83 return false;
84 if( outf_ == nullptr )
85 return false;
86 if( ! inf_->isOpen() )
87 return false;
88 if( ! outf_->isOpen() )
89 return false;
90 return arraynesting_ >= 0;
91 } /* LCOV_EXCL_STOP */
92#endif
93
94private:
96 static const std::map<const char *, core_t *> systemdictmap_,
99
100
101public:
109 explicit Context( const std::string & p_inf_name );
110
111
112 Context() = delete;
113 Context( const Context & ) = delete;
114 Context( Context && ) = delete;
115 Context & operator=( const Context & ) = delete;
116 Context & operator=( Context && ) = delete;
117
118
121 virtual ~Context();
122
123
124public: /* accessor */
127 SOK & opst() { return os_; }
128
129
132 SOK & exst() { return es_; }
133
134
137 SOK & dist() { return ds_; }
138
139
141 size_t getProclevel() const { return static_cast<size_t>(proclevel_); }
142
143
145 size_t getLoadlevel() const { return static_cast<size_t>(loadlevel_); }
146
147
149 size_t getArraynesting() const { return static_cast<size_t>(arraynesting_); }
150
151
153 size_t getMaxloadlevel() const { return maxloadlevel_; }
154
155
157 bool getInterpreterLoop() const { return run_; }
158
159
161 void stopInterpreterLoop() { run_ = false; }
162
163
165 void setSnapLeonline( const std::string & p_line ) { snapLeonline_ = p_line; }
166
167
169 auto getAngularUnit() const { return angularunit_; }
170
171
173 void setAngularUnit( AngularUnit p_unit ) { angularunit_ = p_unit; }
174
175
177 uint32_t getSeed() const { return seed_; }
178
179
181 void setSeed( uint32_t p_seed ) { seed_ = p_seed; }
182
183
184public: /* other */
188 proclevel_++;
189 }
190
191
195 proclevel_--;
196 }
197
198
202 loadlevel_++;
203 }
204
205
209 loadlevel_--;
210 }
211
212
217 }
218
219
225
226
229 void print( const std::string & p_line ) const {
230 outf_->writestring( p_line );
231 }
232
233
236 void print( std::string_view p_line ) const {
237 outf_->writestring( p_line );
238 }
239
240
243 void print( const char * p_line ) const {
244 outf_->writestring( std::string_view( p_line ) );
245 }
246
247
249 void flushoutfile() const {
250 outf_->flush();
251 }
252
253
258 bool readLeonLine( std::string & p_line ) const {
259 return inf_->readLeonLine( p_line );
260 }
261
262
264 void status_statistics() const;
265
266
268 void property_statistics() const;
269
270
272 void stack_statistics() const;
273
274
277 void pstackdump( const SOK & p_stack ) const;
278
279};
The context of execution.
Definition context.h:45
size_t getLoadlevel() const
Getter for load level.
Definition context.h:145
SOK os_
The operand stack.
Definition context.h:48
uint32_t getSeed() const
Getter for seed_.
Definition context.h:177
void stopInterpreterLoop()
Sets run_ to false.
Definition context.h:161
SOK ds_
The dictionary stack.
Definition context.h:50
void decArraynesting()
Decrements array nesting.
Definition context.h:221
uint32_t seed_
Context Property.
Definition context.h:64
void property_statistics() const
Dumps a snapshot of the Context properties to the output file.
Definition context.cpp:257
void print(const char *p_line) const
Wrapper around SOF writestring().
Definition context.h:243
virtual ~Context()
Dtor.
Definition context.cpp:73
bool invariant() const noexcept override
Checks class invariants.
Definition context.h:77
SOK & opst()
Access to the operand stack.
Definition context.h:127
SOF * inf_
Context Property.
Definition context.h:60
void stack_statistics() const
Dumps a snapshot of stacks to the output file.
Definition context.cpp:274
size_t getMaxloadlevel() const
Getter for maximum load level.
Definition context.h:153
auto getAngularUnit() const
Getter for angularunit_.
Definition context.h:169
void status_statistics() const
Dumps a snapshot of the Context state to the output file.
Definition context.cpp:266
void incProclevel()
Increments the procedure level.
Definition context.h:186
bool run_
Control variable for the interpreter loop.
Definition context.h:47
int loadlevel_
The load level is incemented for ever load_exec() call.
Definition context.h:55
void print(const std::string &p_line) const
Wrapper around SOF writestring().
Definition context.h:229
void pstackdump(const SOK &p_stack) const
A dump of a single stack.
Definition context.cpp:243
void incArraynesting()
Increments array nesting.
Definition context.h:214
void setAngularUnit(AngularUnit p_unit)
Setter for angularunit_.
Definition context.h:173
size_t getArraynesting() const
Getter for nesting level.
Definition context.h:149
AngularUnit angularunit_
Context Property.
Definition context.h:62
void decLoadlevel()
Decrements load level.
Definition context.h:207
void print(std::string_view p_line) const
Wrapper around SOF writestring().
Definition context.h:236
static constexpr size_t mindictstack_
Corresponds with the setup in the ctor.
Definition context.h:68
bool getInterpreterLoop() const
Getter for interpreter loop control variable run_.
Definition context.h:157
void setSnapLeonline(const std::string &p_line)
Setter for snapLeonline_.
Definition context.h:165
std::string snapLeonline_
For debugging purposes a copy of the current leon-format line.
Definition context.h:52
int arraynesting_
The nesting level is incemented for every array within an array for the bind operator.
Definition context.h:57
void decProclevel()
Decrements the procedure level.
Definition context.h:193
SOK & exst()
Access to the execution stack.
Definition context.h:132
void setSeed(uint32_t p_seed)
Setter for seed_.
Definition context.h:181
SOK & dist()
Access to the dictionary stack.
Definition context.h:137
void flushoutfile() const
Wrapper around SOF flush().
Definition context.h:249
size_t maxloadlevel_
Context Property.
Definition context.h:63
int proclevel_
The process level is incremented for every '{' on input.
Definition context.h:53
bool readLeonLine(std::string &p_line) const
Wrapper around SOF readLeonLine().
Definition context.h:258
SOF * outf_
Context Property.
Definition context.h:61
size_t getProclevel() const
Getter for procedure level.
Definition context.h:141
static const std::map< const char *, core_t * > systemdictmap_
Maps SON data to SOO data for the systemdict.
Definition context.h:82
void incLoadlevel()
Increments load level.
Definition context.h:200
static const std::map< const char *, core_t * > leodictmap_
Maps SON data to SOO data for the leodict.
Definition context.h:215
SOK es_
The execution stack.
Definition context.h:49
Counter base class.
Definition counter.h:30
Design by contract interface class.
Definition dbc.h:30
Semantic Object File.
Definition sof.h:35
OpError writestring(const std::string &p_data)
Writes to file.
Definition sof.cpp:130
bool isOpen() const
Checks if the file is open.
Definition sof.h:140
OpError flush()
Flushes the file.
Definition sof.cpp:79
bool readLeonLine(std::string &p_str)
Our std::getline( istream, string ) version.
Definition sof.cpp:153
Semantic Object stacK.
Definition sok.h:45
The class Counter.
Helpers for design by contract idioms.
#define DBC_INV_RAII(TT)
Defines an instance of the class DbCRAIIassert<>, which calls the invariant()-function at the return ...
Definition dbc.h:93
Miscellaneous definitions and functions.
AngularUnit
Angular Unit for trigonometric functions.
Definition helper.h:101
@ DEG
degree.
The class SOF - file object.
The class SOK - semantik object stack.