The G-code interpreter from LinuxCNC, vendored so that qgcoder can interpret the same dialect LinuxCNC runs, on every platform qgcoder builds for — including Windows, macOS and WebAssembly, none of which have LinuxCNC packages.
Upstream revision: bae3bfbdfb97e9bea4295afc6079e1c74a3e0958
emc/rs274ngc/ is the interpreter and emc/rs274ngc/saicanon.cc the canon
layer from emc/sai/, the one LinuxCNC's own standalone rs274 tool uses —
it prints canonical commands as text, which is exactly what qgcoder's g2m
parser reads. The rest (emc/nml_intf, emc/ini, emc/tooldata,
libnml, libposemath, rtapi, hal) is the header and helper closure
those need, computed with g++ -MM rather than guessed at.
The upstream sources are unmodified but for one line. Everything else
qgcoder needs to change to build them lives in shim/ and nopython.cc, so
moving to a newer LinuxCNC is a matter of copying files over the top and
reapplying that one line.
emc/rs274ngc/interp_read.cc parses every number in a g-code line with
std::from_chars. libc++ declares the floating-point overload deleted — it has
never implemented it — and Emscripten is pinned to the version Qt's WebAssembly
build targets, so it cannot be moved forward to a library that has it. An
overload cannot be added beside a deleted declaration either, so the shims
could not reach it.
The call now goes to qgc_from_chars() in shim/compat.h, which uses
std::from_chars where the library implements it and strtod where it does
not. That substitution is sound for this caller and would not be in general:
read_real_number() has already used strspn() to establish that the text is
nothing but +- followed by digits and dots, so none of what separates the two
— leading whitespace, hex, inf, nan — can appear. strtod follows
LC_NUMERIC where from_chars does not, and the driver pins that to "C" for
the duration of a run.
The two were compared directly over the range of inputs read_real_number()
can produce, including the empty string, a lone . or -, trailing
characters, and magnitudes that overflow a double: they agree on the parsed
value, where parsing stopped, and the error code.
No Python. LinuxCNC's interpreter can call Python for O-word subroutines, remapped codes and named parameters; qgcoder previews tool paths and has no use for any of it, and Python would have to be built for four platforms to get there.
Python cannot simply be compiled out — there is no build switch for it, and
setup_struct holds a boost::python::object member, so the types have to
exist. Instead:
shim/boost/python/andshim/Python.hdeclare just enough of both APIs for the upstream sources to compile. Every function throws or returns a failure; none is ever called.shim/pythonplugin/python_plugin.hhprovides a plugin that reports itself unusable.PYUSABLEispython_plugin != NULL && python_plugin->usable(), and the global staysNULL, so every Python path in the interpreter is dead code.nopython.ccdefines the handful of entry points that lived ininterp_python.cc, which is not vendored.
shim/fmt/format.h is a stand-in for the {fmt} library, which upstream uses
for error strings in inifile.cc alone. It covers the subset used there,
rather than adding a dependency to every platform.
HAL is stubbed the same way: #<_hal[...]> parameters need a running machine,
and there is not one here.
LinuxCNC is GPL-2; qgcoder is GPL-2-or-later. See LICENSE.