Link wasm runtime status constructors

This commit is contained in:
cnc
2026-06-02 08:20:17 +08:00
parent dab7b9e2ef
commit ad7a461b3e
14 changed files with 137 additions and 12 deletions

View File

@@ -78,6 +78,8 @@ int main() {
const char program[] =
"G21 G90 G17\n"
"G0 X1\n"
"F100\n"
"G2 X2 Y0 I0.5 J0\n"
"M30\n";
if (cnc_sim_parse_program(sim, program, sizeof(program) - 1) != 0) {
cnc_sim_destroy(sim);
@@ -85,15 +87,20 @@ int main() {
}
bool saw_linuxcnc_rapid = false;
bool saw_linuxcnc_arc = false;
bool saw_program_end = false;
for (const auto &event : events) {
saw_linuxcnc_rapid = saw_linuxcnc_rapid ||
(event.type == CNC_SIM_EVENT_RAPID &&
event.line == 2 &&
near(event.end.x, 1.0));
saw_linuxcnc_arc = saw_linuxcnc_arc ||
(event.type == CNC_SIM_EVENT_ARC_FEED &&
event.line == 4 &&
near(event.end.x, 2.0));
saw_program_end = saw_program_end || event.type == CNC_SIM_EVENT_PROGRAM_END;
}
cnc_sim_destroy(sim);
return saw_linuxcnc_rapid && saw_program_end ? 0 : 4;
return saw_linuxcnc_rapid && saw_linuxcnc_arc && saw_program_end ? 0 : 4;
}

View File

@@ -1,4 +1,5 @@
#include "nml_intf/emc_nml.hh"
EMC_STAT *emcStatus = nullptr;
// LinuxCNC src/emc/sai/dummyemcstat.cc uses the same source-backed status
// object when the interpreter runs without the task controller.
EMC_STAT *emcStatus = new EMC_STAT;

View File

@@ -0,0 +1,71 @@
#include "libnml/nml/nmlmsg.hh"
#include "libnml/nml/stat_msg.hh"
#include "libnml/rcs/rcs_print.hh"
#include <cstring>
int NMLmsg::automatically_clear = 1;
NMLmsg::NMLmsg(NMLTYPE t, long s) {
_type = t;
size = s;
if (automatically_clear) {
clear();
}
if (size < static_cast<long>(sizeof(NMLmsg))) {
rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size, sizeof(NMLmsg));
size = sizeof(NMLmsg);
}
if (_type <= 0) {
rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n", static_cast<int>(_type));
}
}
NMLmsg::NMLmsg(NMLTYPE t, size_t s) {
_type = t;
size = static_cast<long>(s);
if (automatically_clear) {
clear();
}
if (size < static_cast<long>(sizeof(NMLmsg))) {
rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size, sizeof(NMLmsg));
size = sizeof(NMLmsg);
}
if (_type <= 0) {
rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n", static_cast<int>(_type));
}
}
NMLmsg::NMLmsg(NMLTYPE t, long s, int noclear) {
if (automatically_clear && !noclear) {
clear();
}
_type = t;
size = s;
if (size < static_cast<long>(sizeof(NMLmsg))) {
rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size, sizeof(NMLmsg));
size = sizeof(NMLmsg);
}
if (_type <= 0) {
rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n", static_cast<int>(_type));
}
}
void NMLmsg::clear() {
const long temp_size = size;
const NMLTYPE temp_type = _type;
std::memset(static_cast<void *>(this), 0, static_cast<size_t>(size));
size = temp_size;
_type = temp_type;
if (size < static_cast<long>(sizeof(NMLmsg))) {
rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size, sizeof(NMLmsg));
size = sizeof(NMLmsg);
}
}
RCS_STAT_MSG::RCS_STAT_MSG(NMLTYPE t, size_t sz) : NMLmsg(t, sz) {
command_type = -1;
echo_serial_number = -1;
status = RCS_STATUS::UNINITIALIZED;
_state = -1;
}

View File

@@ -0,0 +1,14 @@
#include <cstdarg>
#include <cstdio>
extern "C" int set_print_rcs_error_info(const char *, int) {
return 0;
}
extern "C" int print_rcs_error_new(const char *format, ...) {
va_list args;
va_start(args, format);
const int rc = std::vfprintf(stderr, format, args);
va_end(args);
return rc;
}