Skip to content

Commit e1a85bb

Browse files
committed
Improved compile-time execution - no doesn't need monocast states; Improved fallback execution path
1 parent eda926f commit e1a85bb

File tree

15 files changed

+136
-107
lines changed

15 files changed

+136
-107
lines changed

source/Code.cpp

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,18 +1003,51 @@ namespace Langulus::Flow
10031003
// Try executing operator at compile-time
10041004
// We must disable multicast for this
10051005
VERBOSE_TAB("Attempting compile-time execution... ");
1006-
const auto opStateBackup = op.GetVerbState();
1007-
op.Multicast(false);
1008-
Many output;
1009-
Many scope {op};
1010-
if (Execute(scope, lhs, output, false, true)) {
1011-
// The verb was executed at compile-time, so directly
1012-
// substitute LHS with the result
1013-
VERBOSE("Verb was executed at compile time: ", output);
1014-
lhs = Abandon(output);
1015-
return progress;
1006+
1007+
// Next-execute the argument first
1008+
Many unusedContext;
1009+
Many argument;
1010+
if (Execute(op.GetArgument(), unusedContext, argument, true, true)) {
1011+
// Then the verb itself
1012+
Many opSrcBackup = Move(op.GetSource());
1013+
Many opArgBackup = Move(op.GetArgument());
1014+
op.SetSource(lhs);
1015+
op.SetArgument(argument);
1016+
Execute<1, 1, 0>(lhs, op);
1017+
1018+
if (op.GetSuccesses()) {
1019+
// The verb was executed at compile-time, so directly
1020+
// substitute LHS with the verb's output
1021+
VERBOSE("Verb was executed at compile time: ", op.GetOutput());
1022+
lhs = Move(op.GetOutput());
1023+
return progress;
1024+
}
1025+
else {
1026+
op.SetSource(Abandon(opSrcBackup));
1027+
//op.SetArgument(Abandon(opArgBackup));
1028+
IF_SAFE(op.GetOutput().Reset());
1029+
}
1030+
}
1031+
else {
1032+
// Argument didn't execute, but we could still try to
1033+
// pre-compute the op. Like for example when conjuncting
1034+
// two containers.
1035+
Many opSrcBackup = Move(op.GetSource());
1036+
op.SetSource(lhs);
1037+
Execute<1, 1, 0>(lhs, op);
1038+
1039+
if (op.GetSuccesses()) {
1040+
// The verb was executed at compile-time, so directly
1041+
// substitute LHS with the verb's output
1042+
VERBOSE("Verb was executed at compile time: ", op.GetOutput());
1043+
lhs = Move(op.GetOutput());
1044+
return progress;
1045+
}
1046+
else {
1047+
op.SetSource(Abandon(opSrcBackup));
1048+
IF_SAFE(op.GetOutput().Reset());
1049+
}
10161050
}
1017-
else op.SetVerbState(opStateBackup);
10181051
}
10191052

10201053
// Either compile-time execution is impossible, or we don't

source/Executor.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ namespace Langulus::Flow
168168

169169
// We can attempt an implicit Verbs::Create to make
170170
// the data at compile-time. Allowed only if no producer
171-
// was specified.
172-
if (not construct.GetType()->mProducerRetriever) {
171+
// was specified and if construct is not flow-dependent.
172+
if (not construct.GetType()->mProducerRetriever
173+
/*and not construct.GetCharge().IsFlowDependent()*/) {
173174
Verbs::Create creator {&solved};
174175
if (Verb::GenericExecuteStateless(creator)) {
175176
output.SmartPush(IndexBack, Abandon(creator.GetOutput()));
@@ -187,7 +188,7 @@ namespace Langulus::Flow
187188
// missing, but generally they will be substituted with
188189
// the corresponding results
189190
VERBOSE("Executing neat: ", neat);
190-
Neat local = neat;
191+
/*Neat local = neat;
191192
local.template RemoveData<A::Verb>();
192193
VERBOSE("Executing neat (verbs stripped): ", local);
193194
@@ -213,15 +214,16 @@ namespace Langulus::Flow
213214
if (silent)
214215
LANGULUS_THROW(Flow, "Construct AND failure");
215216
else
216-
LANGULUS_OOPS(Flow, "Construct AND failure: "/*, flow*/);
217+
LANGULUS_OOPS(Flow, "Construct AND failure: ");
217218
}
218219
else if (verb.GetOutput())
219220
local << Abandon(verb.GetOutput());
220221
}
221222
);
222223
223224
VERBOSE("Executing neat (verbs executed): ", local);
224-
output.SmartPush(IndexBack, Abandon(local));
225+
output.SmartPush(IndexBack, Abandon(local));*/
226+
TODO();
225227
},
226228
[&](const A::Verb& constVerb) {
227229
// Execute verbs
@@ -244,6 +246,14 @@ namespace Langulus::Flow
244246
);
245247
verb.SetSource(constVerb.GetSource());
246248

249+
if (verb.IsMissing()) {
250+
if (integrate) {
251+
output.SmartPush(IndexBack, verb);
252+
return Loop::Continue;
253+
}
254+
else FLOW_ERRORS("Trying to execute a missing verb: ", verb);
255+
}
256+
247257
// Execute the verb
248258
if (not ExecuteVerb(context, verb, silent)) {
249259
if (silent)
@@ -329,7 +339,8 @@ namespace Langulus::Flow
329339
// We can attempt an implicit Verbs::Create to make
330340
// the data at compile-time. Allowed only if no
331341
// producer was specified.
332-
if (not construct.GetType()->mProducerRetriever) {
342+
if (not construct.GetType()->mProducerRetriever
343+
/*and not construct.GetCharge().IsFlowDependent()*/) {
333344
Verbs::Create creator {&solved};
334345
if (Verb::GenericExecuteStateless(creator)) {
335346
output.SmartPush(IndexBack, Abandon(creator.GetOutput()));
@@ -346,7 +357,7 @@ namespace Langulus::Flow
346357
// verbs from it. Some of them might get reinserted, if
347358
// missing, but generally they will be substituted with
348359
// the corresponding results
349-
Neat local = neat;
360+
/*Neat local = neat;
350361
local.template RemoveData<A::Verb>();
351362
352363
local.ForEach(
@@ -372,7 +383,8 @@ namespace Langulus::Flow
372383
}
373384
);
374385
375-
output.SmartPush(IndexBack, Abandon(local));
386+
output.SmartPush(IndexBack, Abandon(local));*/
387+
TODO();
376388
},
377389
[&](const Verb& constVerb) {
378390
// Execute verbs
@@ -388,6 +400,14 @@ namespace Langulus::Flow
388400
constVerb.GetVerbState()
389401
);
390402

403+
if (verb.IsMissing()) {
404+
if (integrate) {
405+
output.SmartPush(IndexBack, verb);
406+
return Loop::Continue;
407+
}
408+
else FLOW_ERRORS("Trying to execute a missing verb: ", verb);
409+
}
410+
391411
if (not ExecuteVerb(context, verb, silent))
392412
return Loop::Continue;
393413

@@ -419,12 +439,12 @@ namespace Langulus::Flow
419439
/// executing at compile-time, for example
420440
/// @return true of no errors occured
421441
bool IntegrateVerb(Many& context, Verb& verb, const bool silent) {
422-
if (verb.IsMonocast()) {
442+
/*if (verb.IsMonocast()) {
423443
// We're executing on whole argument/source, so be lazy
424444
if (verb.GetSource().IsInvalid())
425445
verb.SetSource(context);
426446
return true;
427-
}
447+
}*/
428448

429449
// Integrate the verb source to environment
430450
Many localSource;

source/Resolvable.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ namespace Langulus
2929
#if not LANGULUS(PARANOID) and LANGULUS(DEBUG)
3030
// Feel like getting doxxed? Directly dump the memory address
3131
result += Anyness::Text {
32-
fmt::format("{:X}",
32+
fmt::format("{:02X}",
3333
reinterpret_cast<intptr_t>(&DenseCast(instance))
3434
)
3535
};
3636
#else
3737
// Obfuscate the pointer, by hashing it
3838
result += Anyness::Text {
39-
fmt::format("{:X}", HashOf(&DenseCast(instance)).mHash)
39+
fmt::format("{:02X}", HashOf(&DenseCast(instance)).mHash)
4040
};
4141
#endif
4242
result += Text::Operator::CloseScope;

source/TVerb.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace Langulus::Flow
7676
Hash GetHash() const;
7777

7878
VERB& ShortCircuit(bool) noexcept;
79-
VERB& Multicast(bool) noexcept;
79+
//VERB& Multicast(bool) noexcept;
8080
VERB& SetVerbState(VerbState) noexcept;
8181
VERB& Invert() noexcept;
8282
VERB& SetMass(Real) noexcept;

source/TVerb.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ namespace Langulus::Flow
127127
return Verb::ShortCircuit<VERB>(state);
128128
}
129129

130-
TEMPLATE() LANGULUS(INLINED)
130+
/*TEMPLATE() LANGULUS(INLINED)
131131
VERB& TME()::Multicast(bool state) noexcept {
132132
return Verb::Multicast<VERB>(state);
133-
}
133+
}*/
134134

135135
TEMPLATE() LANGULUS(INLINED)
136136
VERB& TME()::SetVerbState(VerbState state) noexcept {

source/Verb.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ namespace Langulus::Flow
9191

9292
template<CT::VerbBased THIS = Verb>
9393
THIS& ShortCircuit(bool) noexcept;
94-
template<CT::VerbBased THIS = Verb>
95-
THIS& Multicast(bool) noexcept;
94+
/*template<CT::VerbBased THIS = Verb>
95+
THIS& Multicast(bool) noexcept;*/
9696
template<CT::VerbBased THIS = Verb>
9797
THIS& SetVerbState(VerbState) noexcept;
9898

source/Verb.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ namespace Langulus::Flow
206206
/// Change the verb's castness
207207
/// @param toggle - enable or disable multicast
208208
/// @return a reference to this verb for chaining
209-
template<CT::VerbBased THIS> LANGULUS(INLINED)
209+
/*template<CT::VerbBased THIS> LANGULUS(INLINED)
210210
THIS& Verb::Multicast(bool toggle) noexcept {
211211
if (toggle)
212212
mState -= VerbState::Monocast;
213213
else
214214
mState += VerbState::Monocast;
215215
return *reinterpret_cast<THIS*>(this);
216-
}
216+
}*/
217217

218218
/// Check if verb is matches the provided V1
219219
/// @tparam V1 - the verb to compare against

source/verbs/Compare.inl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
#include "Compare.hpp"
1010
#include "../TVerb.inl"
1111

12-
#if 0
13-
#define VERBOSE_COMPARE(...) Logger::Verbose(__VA_ARGS__)
14-
#else
15-
#define VERBOSE_COMPARE(...) LANGULUS(NOOP)
16-
#endif
17-
1812

1913
namespace Langulus::Verbs
2014
{
@@ -93,6 +87,4 @@ namespace Langulus::Verbs
9387
return verb.IsDone();
9488
}
9589

96-
} // namespace Langulus::Verbs
97-
98-
#undef VERBOSE_COMPARE
90+
} // namespace Langulus::Verbs

source/verbs/Do.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ namespace Langulus::Flow
4949
template<bool DISPATCH, bool DEFAULT, bool FALLBACK>
5050
Count Execute(CT::Data auto&, CT::VerbBased auto&);
5151

52-
template<bool DISPATCH, bool DEFAULT, bool FALLBACK, class...BASES>
52+
/*template<bool DISPATCH, bool DEFAULT, bool FALLBACK, class...BASES>
5353
Count ExecuteInBases(CT::Data auto&, CT::VerbBased auto&, Types<BASES...>);
5454
5555
namespace Inner
5656
{
5757
template<bool DISPATCH, bool DEFAULT, bool FALLBACK, class BASE>
5858
Count ExecuteInBases(CT::Data auto&, CT::VerbBased auto&);
59-
}
59+
}*/
6060

6161
template<bool RESOLVE = true, bool DISPATCH = true, bool DEFAULT = true>
6262
Count DispatchFlat(CT::Deep auto&, CT::VerbBased auto&);

0 commit comments

Comments
 (0)