You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@evgenykochetkov already made port type read-only in #1930 but has to revert it in #1964 because of some cases become impossible if port-typed values can no longer be emitted. In particular, dht11-device and dht2x-device nodes hold the port inside C++ struct to be latter used by unpack-dht11-device, for example. The latter node compiles with an error after #1930 because emitValue can no longer be used with ports.
We should find a way to complete the attempt because it brings many benefits:
Compile-time port and other read-only values validation: clear error messages are possible
The implementation requires much exploration, trials, and errors with C++ metaprogramming, so no particular receipt here. Only a few high-level thoughts:
High backward-compatibility is a must. The only thing which may break is the emitValue of port type.
The custom type definition (Type) has to become generic in C++, parametrized with read-only values
As a consequence, the State has to become generic as well. The bad news is that it template parameters depend not only on its own pins but on the Type definitions of upstream nodes
Perhaps, it would make sense to move from separate functions and structures in a node implementation to class-based definitions that keep all meta-arguments under a single umbrella:
template <uint8_t x>
structCustomType {
char buff[x];
};
template <uint8_t all, size_t readOnly, uint8_t metaArgs>
structNode : publicNodeBase<Node> {
Number a, b, c;
uint8_t buffer[readOnly]; // Hey, no explicit `State` is necessaryusing Type = CustomType<metaArgs>;
// {{ GENERATED_CODE}} <-- no longer requiredvoidevaluate(Context ctx) {
static_assert(isValidPort(all));
getValue<input_IN>(ctx);
emitValue<output_OUT>(ctx, 42);
}
}
@evgenykochetkov already made port type read-only in #1930 but has to revert it in #1964 because of some cases become impossible if port-typed values can no longer be emitted. In particular,
dht11-device
anddht2x-device
nodes hold the port inside C++ struct to be latter used byunpack-dht11-device
, for example. The latter node compiles with an error after #1930 becauseemitValue
can no longer be used with ports.We should find a way to complete the attempt because it brings many benefits:
The implementation requires much exploration, trials, and errors with C++ metaprogramming, so no particular receipt here. Only a few high-level thoughts:
emitValue
of port type.Type
) has to become generic in C++, parametrized with read-only valuesState
has to become generic as well. The bad news is that it template parameters depend not only on its own pins but on theType
definitions of upstream nodesAcceptance criteria
xod-dev/dht
lib keeps workingThe text was updated successfully, but these errors were encountered: