From 3333ddb3738c5a5d5d60fa66b98bf5bf670728e8 Mon Sep 17 00:00:00 2001 From: wangdequan Date: Sat, 23 May 2026 17:42:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=AF=8D=EF=BC=9A=20?= =?UTF-8?q?=E5=AF=B9=E6=A0=87=20LinuxCNC=EF=BC=8C=E5=88=86=E9=98=B6?= =?UTF-8?q?=E6=AE=B5=E5=AE=8C=E5=96=84=20Web=20=E7=89=88=E6=95=B0=E6=8E=A7?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=BB=BF=E7=9C=9F=E7=9A=84=20WASM=20?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=EF=BC=8C=E7=BB=A7=E7=BB=AD=E8=A1=A5=E9=BD=90?= =?UTF-8?q?=20G=20=E4=BB=A3=E7=A0=81=E8=AF=AD=E6=B3=95=E5=B9=B6=E4=B8=A5?= =?UTF-8?q?=E6=A0=BC=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 总结: - 对齐 LinuxCNC 字地址值中带符号一元函数的解析行为,支持类似 X-ABS[-2] 的写法。 - 在 smoke API 回归中新增 signed unary word value 覆盖。 - 已通过 ./test-native.sh 和 ./test-linuxcnc-source-link.sh。 --- core/src/smoke_gcode_parser.cpp | 12 ++++++++++-- core/tests/cnc_sim_api_smoke.cpp | 9 ++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/core/src/smoke_gcode_parser.cpp b/core/src/smoke_gcode_parser.cpp index a5aeb33..5c07a3e 100644 --- a/core/src/smoke_gcode_parser.cpp +++ b/core/src/smoke_gcode_parser.cpp @@ -1493,10 +1493,18 @@ std::string expand_expressions_and_parameters(const std::string &line, out.reserve(line.size()); for (size_t i = 0; i < line.size();) { if (std::isalpha(static_cast(line[i])) && i + 1 < line.size()) { + const size_t value_start = i + 1; + size_t function_start = value_start; + if ((line[function_start] == '+' || line[function_start] == '-') && + function_start + 1 < line.size() && + !std::isdigit(static_cast(line[function_start + 1])) && + line[function_start + 1] != '.') { + ++function_start; + } size_t function_end = 0; - if (unary_function_span(line, i + 1, &function_end)) { + if (unary_function_span(line, function_start, &function_end)) { double value = 0.0; - if (!evaluate_expression(line.substr(i + 1, function_end - i - 1), + if (!evaluate_expression(line.substr(value_start, function_end - value_start), call_stack, parameters, named_parameters, diff --git a/core/tests/cnc_sim_api_smoke.cpp b/core/tests/cnc_sim_api_smoke.cpp index 4aa1922..19047ea 100644 --- a/core/tests/cnc_sim_api_smoke.cpp +++ b/core/tests/cnc_sim_api_smoke.cpp @@ -273,6 +273,7 @@ int main() { bool saw_math_function_assignment = false; bool saw_word_unary_function_motion = false; bool saw_word_atan_function_motion = false; + bool saw_signed_word_unary_function_motion = false; bool saw_trig_function_motion = false; bool saw_inverse_trig_function_motion = false; bool saw_atan_function_motion = false; @@ -3571,7 +3572,8 @@ int main() { "G21 G90\n" "F100\n" "G1 XABS[-2]\n" - "G1 YATAN[1]/[1]\n"; + "G1 YATAN[1]/[1]\n" + "G1 Z-ABS[-2]\n"; events.clear(); ok &= expect(cnc_sim_parse_program(sim, word_unary_function_program, @@ -3586,9 +3588,14 @@ int main() { (event.type == CNC_SIM_EVENT_LINEAR_FEED && event.line == 4 && near(event.end.y, 45.0)); + saw_signed_word_unary_function_motion = saw_signed_word_unary_function_motion || + (event.type == CNC_SIM_EVENT_LINEAR_FEED && + event.line == 5 && + event.end.z == -2.0); } ok &= expect(saw_word_unary_function_motion, "expected LinuxCNC unary function as a word value"); ok &= expect(saw_word_atan_function_motion, "expected LinuxCNC ATAN function as a word value"); + ok &= expect(saw_signed_word_unary_function_motion, "expected signed LinuxCNC unary function as a word value"); const char additional_math_function_program[] = "#1 = [ASIN[0.5] + ACOS[0.5]]\n"