Skip to content

Commit 0f6b35b

Browse files
committed
Code cleanup; Two kinds of execution: integrative and not; TestTemporal moved to Entity; Other minor improvements
1 parent 863be2e commit 0f6b35b

13 files changed

+124
-174
lines changed

source/Code.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
///
88
#include "Code.inl"
99
#include "Verb.hpp"
10+
#include "Temporal.hpp"
11+
#include "Time.hpp"
1012

1113
#include "verbs/Do.inl"
1214
#include "verbs/Select.inl"
@@ -75,6 +77,9 @@ namespace Langulus::Flow
7577

7678
// Make sure that all default types are registered before parsing
7779
(void)MetaOf<Index>();
80+
(void)MetaOf<Temporal>();
81+
//(void)MetaOf<Time>(); //TODO causes conflict with the trait that isn't detected due to too lax constraints!
82+
(void)MetaOf<Code>();
7883

7984
// Make sure that all default verbs are registered before parsing
8085
(void)MetaOf<Verbs::Do>();

source/Code.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,10 @@ namespace Langulus
124124
return Anyness::Text::From(text, size);
125125
}
126126

127+
/// Make a code literal and parse it
128+
LANGULUS(INLINED)
129+
auto operator "" _parse(const char* text, ::std::size_t size) {
130+
return Flow::Code(Anyness::Text::From(text, size)).Parse();
131+
}
132+
127133
} // namespace Langulus

source/Executor.cpp

Lines changed: 74 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,55 @@
2525
namespace Langulus::Flow
2626
{
2727

28-
/// Nested AND/OR scope execution (discarding outputs)
29-
/// TODO optimize for unneeded outputs
30-
/// @param flow - the flow to execute
31-
/// @param context - the environment in which flow will be executed
32-
/// @param silent - whether or not to silence logging, in case we're
33-
/// executing at compile-time, for example
34-
/// @return true of no errors occured
35-
/*bool Execute(const Many& flow, Many& context, const bool silent) {
36-
Many output;
37-
bool skipVerbs = false;
38-
return Execute(flow, context, output, skipVerbs, silent);
39-
}*/
40-
4128
/// Nested AND/OR scope execution with output
4229
/// @param flow - the flow to execute
4330
/// @param context - the environment in which scope will be executed
4431
/// @param output - [out] verb result will be pushed here
32+
/// @param integrate - execution happens in two styles:
33+
/// 1. integration - everything not executed will still be pushed to
34+
/// output, preserving the hierarchy. useful when integrating verbs
35+
/// 2. not integration - only unexecuted verbs will push to output,
36+
/// useful for collecting side-effects when updating
4537
/// @param silent - whether or not to silence logging, in case we're
4638
/// executing at compile-time, for example
4739
/// @return true of no errors occured
48-
bool Execute(const Many& flow, Many& context, Many& output, const bool silent) {
40+
bool Execute(
41+
const Many& flow, Many& context, Many& output,
42+
const bool integrate, const bool silent
43+
) {
4944
bool skipVerbs = false;
50-
return Execute(flow, context, output, skipVerbs, silent);
45+
return Execute(flow, context, output, integrate, skipVerbs, silent);
5146
}
5247

5348
/// Nested AND/OR scope execution with output
5449
/// @param flow - the flow to execute
5550
/// @param context - the environment in which scope will be executed
5651
/// @param output - [out] verb result will be pushed here
52+
/// @param integrate - execution happens in two styles:
53+
/// 1. integration - everything not executed will still be pushed to
54+
/// output, preserving the hierarchy. useful when integrating verbs
55+
/// 2. not integration - only unexecuted verbs will push to output,
56+
/// useful for collecting side-effects when updating
5757
/// @param skipVerbs - [in/out] whether to skip verbs after OR success
5858
/// @param silent - whether or not to silence logging, in case we're
5959
/// executing at compile-time, for example
6060
/// @return true of no errors occured
61-
bool Execute(const Many& flow, Many& context, Many& output, bool& skipVerbs, const bool silent) {
61+
bool Execute(
62+
const Many& flow, Many& context, Many& output,
63+
const bool integrate, bool& skipVerbs, const bool silent
64+
) {
6265
auto results = Many::FromState(flow);
6366
if (flow) {
64-
VERBOSE_TAB("Executing scope: [", flow, ']');
67+
if (integrate)
68+
VERBOSE_TAB("Executing scope (integrating): [", flow, ']');
69+
else
70+
VERBOSE_TAB("Executing scope: [", flow, ']');
6571

6672
try {
6773
if (flow.IsOr())
68-
ExecuteOR(flow, context, results, skipVerbs, silent);
74+
ExecuteOR(flow, context, results, integrate, skipVerbs, silent);
6975
else
70-
ExecuteAND(flow, context, results, skipVerbs, silent);
76+
ExecuteAND(flow, context, results, integrate, skipVerbs, silent);
7177
}
7278
catch (const Except::Flow&) {
7379
// Execution failed
@@ -83,17 +89,25 @@ namespace Langulus::Flow
8389
/// @param flow - the flow to execute
8490
/// @param context - the environment in which scope will be executed
8591
/// @param output - [out] verb result will be pushed here
92+
/// @param integrate - execution happens in two styles:
93+
/// 1. integration - everything not executed will still be pushed to
94+
/// output, preserving the hierarchy. useful when integrating verbs
95+
/// 2. not integration - only unexecuted verbs will push to output,
96+
/// useful for collecting side-effects when updating
8697
/// @param skipVerbs - [in/out] whether to skip verbs after OR success
8798
/// @param silent - whether or not to silence logging, in case we're
8899
/// executing at compile-time, for example
89100
/// @return true of no errors occured
90-
bool ExecuteAND(const Many& flow, Many& context, Many& output, bool& skipVerbs, const bool silent) {
101+
bool ExecuteAND(
102+
const Many& flow, Many& context, Many& output,
103+
const bool integrate, bool& skipVerbs, const bool silent
104+
) {
91105
Count executed = 0;
92106
if (flow.IsDeep() and flow.IsDense()) {
93107
executed = flow.ForEach([&](const Many& block) {
94108
// Nest if deep
95109
Many local;
96-
if (not Execute(block, context, local, skipVerbs, silent)) {
110+
if (not Execute(block, context, local, integrate, skipVerbs, silent)) {
97111
if (silent)
98112
LANGULUS_THROW(Flow, "Deep AND failure");
99113
else
@@ -108,7 +122,7 @@ namespace Langulus::Flow
108122
[&](const Inner::Missing& missing) {
109123
// Nest if missing points
110124
Many local;
111-
if (not Execute(missing.mContent, context, local, skipVerbs, silent)) {
125+
if (not Execute(missing.mContent, context, local, integrate, skipVerbs, silent)) {
112126
if (silent)
113127
LANGULUS_THROW(Flow, "Missing point failure");
114128
else
@@ -126,7 +140,7 @@ namespace Langulus::Flow
126140
}
127141

128142
Many local;
129-
if (not Execute(trait, context, local, skipVerbs, silent)) {
143+
if (not Execute(trait, context, local, integrate, skipVerbs, silent)) {
130144
if (silent)
131145
LANGULUS_THROW(Flow, "Trait AND failure");
132146
else
@@ -178,24 +192,26 @@ namespace Langulus::Flow
178192
);
179193

180194
VERBOSE("Executing construct (verbs executed): ", local);
181-
//if (constructIsMissing) {
182-
// Just propagate, if missing
195+
if (constructIsMissing
196+
or construct.GetType()->mProducerRetriever
197+
or not construct.GetType()->mDescriptorConstructor) {
198+
// Just propagate if missing or not instantiatable at
199+
// compile-time
183200
output.SmartPush(IndexBack, Abandon(local));
184-
//return;
185-
//}
201+
return;
202+
}
186203

187-
// A construct always means an implicit Verbs::Create
188-
// Try creating it in the current environment, it should
189-
// produce everything possible, including stateless ones
190-
/*Verbs::Create creator {&local};
204+
// We can attempt an implicit Verbs::Create to make
205+
// the data at compile-time
206+
Verbs::Create creator {&local};
191207
if (DispatchDeep<true, true, false>(context, creator))
192208
output.SmartPush(IndexBack, Abandon(creator.GetOutput()));
193209
else {
194210
if (silent)
195211
LANGULUS_THROW(Flow, "Construct creation failure");
196212
else
197213
LANGULUS_OOPS(Flow, "Construct creation failure: ", flow);
198-
}*/
214+
}
199215
},
200216
[&](const A::Verb& constVerb) {
201217
// Execute verbs
@@ -235,7 +251,7 @@ namespace Langulus::Flow
235251
);
236252
}
237253

238-
if (not executed) {
254+
if (not executed and integrate) {
239255
// If this is reached, then we had non-verb content
240256
// Just propagate its contents
241257
output.SmartPush(IndexBack, flow);
@@ -249,19 +265,27 @@ namespace Langulus::Flow
249265
/// @param flow - the flow to execute
250266
/// @param context - the context in which scope will be executed
251267
/// @param output - [out] verb result will be pushed here
268+
/// @param integrate - execution happens in two styles:
269+
/// 1. integration - everything not executed will still be pushed to
270+
/// output, preserving the hierarchy. useful when integrating verbs
271+
/// 2. not integration - only unexecuted verbs will push to output,
272+
/// useful for collecting side-effects when updating
252273
/// @param skipVerbs - [out] whether to skip verbs after OR success
253274
/// @param silent - whether or not to silence logging, in case we're
254275
/// executing at compile-time, for example
255276
/// @return true of no errors occured
256-
bool ExecuteOR(const Many& flow, Many& context, Many& output, bool& skipVerbs, const bool silent) {
277+
bool ExecuteOR(
278+
const Many& flow, Many& context, Many& output,
279+
const bool integrate, bool& skipVerbs, const bool silent
280+
) {
257281
Count executed = 0;
258282
bool localSkipVerbs = false;
259283

260284
if (flow.IsDeep() and flow.IsDense()) {
261285
executed = flow.ForEach([&](const Many& block) {
262286
// Nest if deep
263287
Many local;
264-
if (Execute(block, context, local, localSkipVerbs, silent)) {
288+
if (Execute(block, context, local, integrate, localSkipVerbs, silent)) {
265289
executed = true;
266290
output.SmartPush(IndexBack, Abandon(local));
267291
}
@@ -278,7 +302,7 @@ namespace Langulus::Flow
278302
}
279303

280304
Many local;
281-
if (Execute(trait, context, local, silent)) {
305+
if (Execute(trait, context, local, integrate, silent)) {
282306
executed = true;
283307
output.SmartPush(IndexBack, Trait::From(trait.GetTrait(), Abandon(local)));
284308
}
@@ -317,24 +341,26 @@ namespace Langulus::Flow
317341
}
318342
);
319343

320-
//if (constructIsMissing) {
321-
// Just propagate, if missing
344+
if (constructIsMissing
345+
or construct.GetType()->mProducerRetriever
346+
or not construct.GetType()->mDescriptorConstructor) {
347+
// Just propagate if missing or not instantiatable at
348+
// compile-time
322349
output.SmartPush(IndexBack, Abandon(local));
323-
//return;
324-
//}
350+
return;
351+
}
325352

326-
// A construct always means an implicit Verbs::Create
327-
// Try creating it in the current environment, it should
328-
// produce everything possible, including stateless ones
329-
/*Verbs::Create creator {&local};
353+
// We can attempt an implicit Verbs::Create to make
354+
// the data at compile-time
355+
Verbs::Create creator {&local};
330356
if (DispatchDeep<true, true, false>(context, creator))
331357
output.SmartPush(IndexBack, Abandon(creator.GetOutput()));
332358
else {
333359
if (silent)
334360
LANGULUS_THROW(Flow, "Construct creation failure");
335361
else
336362
LANGULUS_OOPS(Flow, "Construct creation failure: ", flow);
337-
}*/
363+
}
338364
},
339365
[&](const Verb& constVerb) {
340366
// Execute verbs
@@ -362,7 +388,7 @@ namespace Langulus::Flow
362388

363389
skipVerbs |= localSkipVerbs;
364390

365-
if (not executed) {
391+
if (not executed and integrate) {
366392
// If this is reached, then we have non-verb flat content
367393
// Just propagate it
368394
output.SmartPush(IndexBack, flow);
@@ -390,7 +416,7 @@ namespace Langulus::Flow
390416

391417
// Integrate the verb source to environment
392418
Many localSource;
393-
if (not Execute(verb.GetSource(), context, localSource, silent)) {
419+
if (not Execute(verb.GetSource(), context, localSource, true, silent)) {
394420
// It's considered error only if verb is not monocast
395421
if (not silent)
396422
FLOW_ERRORS("Error at source of: ", verb);
@@ -402,7 +428,7 @@ namespace Langulus::Flow
402428

403429
// Integrate the verb argument to the source
404430
Many localArgument;
405-
if (not Execute(verb.GetArgument(), localSource, localArgument, silent)) {
431+
if (not Execute(verb.GetArgument(), localSource, localArgument, true, silent)) {
406432
// It's considered error only if verb is not monocast
407433
if (not silent)
408434
FLOW_ERRORS("Error at argument of: ", verb);

source/Executor.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ namespace Langulus::Flow
1515
///
1616
/// Tools for executing containers as flows
1717
///
18-
//LANGULUS_API(FLOW)
19-
//bool Execute(const Many&, Many&, bool silent = false);
2018
LANGULUS_API(FLOW)
21-
bool Execute(const Many&, Many&, Many& output, bool silent = false);
19+
bool Execute(const Many&, Many&, Many& output, bool integration, bool silent = false);
2220
LANGULUS_API(FLOW)
23-
bool Execute(const Many&, Many&, Many& output, bool& skipVerbs, bool silent = false);
21+
bool Execute(const Many&, Many&, Many& output, bool integration, bool& skipVerbs, bool silent = false);
2422

2523
LANGULUS_API(FLOW)
26-
bool ExecuteAND(const Many&, Many&, Many& output, bool& skipVerbs, bool silent = false);
24+
bool ExecuteAND(const Many&, Many&, Many& output, bool integration, bool& skipVerbs, bool silent = false);
2725
LANGULUS_API(FLOW)
28-
bool ExecuteOR(const Many&, Many&, Many& output, bool& skipVerbs, bool silent = false);
26+
bool ExecuteOR(const Many&, Many&, Many& output, bool integration, bool& skipVerbs, bool silent = false);
2927

3028
LANGULUS_API(FLOW)
3129
bool ExecuteVerb(Many&, Verb&, bool silent = false);

source/Resolvable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace Langulus::Flow
7575
Many Resolvable::Run(const Many& scope) {
7676
Many context {GetBlock()};
7777
Many output;
78-
if (not Execute(scope, context, output)) {
78+
if (not Execute(scope, context, output, false)) {
7979
Logger::Error("Can't execute scope: ", scope);
8080
return {};
8181
}

source/TFactory.hpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,11 @@ namespace Langulus::Flow
4848
public:
4949
LANGULUS(TYPED) T;
5050
using Base = Anyness::THive<T>;
51-
//using Producer = ProducerOf<T>;
5251
static constexpr bool IsUnique = USAGE == FactoryUsage::Unique;
5352

5453
protected:
5554
using typename Base::Cell;
5655

57-
// Each factory is bound to a producer instance
58-
// Every produced T will also be bound to that instance
59-
// If factory moved, all contents will be remapped to the new
60-
// instance
61-
//Producer* mFactoryOwner {};
62-
6356
// A hash map for fast retrieval of elements
6457
TUnorderedMap<Hash, TMany<Cell*>> mHashmap;
6558

@@ -78,8 +71,6 @@ namespace Langulus::Flow
7871
TFactory(const TFactory&) = delete;
7972
TFactory(TFactory&&) = delete;
8073

81-
//TFactory() = default;
82-
//TFactory(Producer*);
8374
TFactory& operator = (TFactory&&) noexcept;
8475
~TFactory();
8576

@@ -91,10 +82,9 @@ namespace Langulus::Flow
9182

9283
IF_SAFE(void Dump() const);
9384

94-
#if LANGULUS(TESTING)
95-
//auto GetOwner() const noexcept { return mFactoryOwner; }
96-
auto& GetHashmap() const { return mHashmap; }
97-
#endif
85+
#if LANGULUS(TESTING)
86+
auto& GetHashmap() const { return mHashmap; }
87+
#endif
9888
};
9989

10090
template<class T>

source/TFactory.inl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
namespace Langulus::Flow
2222
{
2323

24-
/// Construction of a factory
25-
/// @param owner - the factory owner
26-
//TEMPLATE() LANGULUS(INLINED)
27-
//FACTORY()::TFactory(Producer* owner)
28-
// : mFactoryOwner {owner} {}
29-
3024
/// Factory destructor
3125
/// Checks if all elements are referenced exactly once before destruction
3226
/// if safe mode is enabled

0 commit comments

Comments
 (0)