提示词:

对标 LinuxCNC,分阶段完善 Web 版数控系统仿真的 WASM 程序,继续补齐 G 代码语法并严格测试。

总结:
- 对齐 LinuxCNC 字地址值中带符号一元函数的解析行为,支持类似 X-ABS[-2] 的写法。
- 在 smoke API 回归中新增 signed unary word value 覆盖。
- 已通过 ./test-native.sh 和 ./test-linuxcnc-source-link.sh。
This commit is contained in:
wangdequan
2026-05-23 17:42:09 +08:00
parent ed4e674d1e
commit 3333ddb373
2 changed files with 18 additions and 3 deletions

View File

@@ -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<unsigned char>(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<unsigned char>(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,

View File

@@ -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"