XOD 0.35.0: C++ Optimizations, API Improvements, Wider Compatibility

Victor Nakoryakov
XODlang
Published in
3 min readSep 8, 2020

Hello, folks! Today I announce 0.35.0 release of the XOD visual programming language. This time XOD devs focused on improving quality rather than introducing sugar features.

C++ syntax simplification

Those who tried to make own C++ node know that the code looks weird a bit at the first look. Yes, it’s C++ but with some foreign quirks like {{ GENERATED_CODE }}, strange rules to #include other libraries, etc.

We wanted to remove all that non-standard stuff completely with this update. But the reality of many-many-many edge cases did not allow to do so. We have to keep a few deviations. Nevertheless, we are sure that the new API/syntax is much more intuitive, welcoming, and simple to start with.

You can find the complete list of differences in the new guide article Migrating C++ nodes to v0.35. And just to get an idea how it affects the code, here’s an example.

Before:

{{#global}}
#include <LiquidCrystal_I2C.h>
{{/global}}
struct State {
uint8_t mem[sizeof(LCD)];
LCD* lcd;
};
{{ GENERATED_CODE }}void evaluate(Context ctx) {
State* state = getState(ctx);
if (isSettingUp()) {
state->lcd =
new (state->mem) LCD(getValue<input_ADDR>(ctx));
}
state->lcd->printLine("Hello");
state->lcd->printLine("World");
}

After:

#include <LiquidCrystal_I2C.h>node {
LCD lcd = LCD(const_input_ADDR);
void evaluate(Context ctx) {
lcd.printLine("Hello");
lcd.printLine("World");
}
};

Don’t worry if you rely on some C++ code in the previous API. It still works as is.

Port type is read-only now

Oh, this was a hard part. A massive rework of the program transpiler allowed XOD to have constant types. The value of a constant is set once during the program creation and can never change then. For now, the only constant type is Port, the one used to define pins through which a module is connected to the board. “And what’s the point?” — you might ask — “How this is better than a regular type?”

First, the value of such type is known at compile time. That means that XOD can fail the compilation with a clear error message if you set an incorrect port for a module instead of failing to do anything at runtime.

Second, it opens the doors for program optimization because many upstream nodes no longer raise runtime errors (no need to consume memory for error management). There’s no need to keep duplicate port values across an external library and the program storage. Dead code elimination might be more efficient. Etc, etc.

Third, we haven’t done it yet, but there could be other constant types like “buffer size”. The constant values are accessible at the compile-time and so might be used, for example, to allocate memory for an array statically and safely without touching the new operator.

arduino-cli compatibility updated

As you possibly know, XOD uses the arduino-cli tool to manage hardware packages, perform uploads, and interact with the boards in other ways. The used version is updated to 0.12 (latest at the moment), which brings compatibility with many new Arduino-boards to XOD. For example, XOD is now compatible with Arduino Nano Every and ESP32 out of the box.

As usual, the release includes other small improvements and enhancements. Read the full list on GitHub.

Get the new version of XOD from the downloads page or try it directly in your browser. If you have XOD installed already, click the update message when IDE starts.

--

--