From 7319e188104a9f31a21e9dac253cd98cad948aa2 Mon Sep 17 00:00:00 2001 From: cnc Date: Tue, 2 Jun 2026 15:50:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E6=8C=89=20align-linuxcnc=20?= =?UTF-8?q?=E7=BA=A6=E6=9D=9F=EF=BC=9A=E8=A1=A5=E8=A1=A8=E8=BE=BE=E5=BC=8F?= =?UTF-8?q?=E8=BF=90=E7=AE=97=E6=BA=90=E7=A0=81=E5=9B=9E=E5=BD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/linuxcnc-porting.md | 3 ++- test-linuxcnc-source-link.sh | 27 +++++++++++++++++++ tests/gcode/linuxcnc_expression_operators.ngc | 11 ++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/gcode/linuxcnc_expression_operators.ngc diff --git a/docs/linuxcnc-porting.md b/docs/linuxcnc-porting.md index 0abdeef..9eb69ac 100644 --- a/docs/linuxcnc-porting.md +++ b/docs/linuxcnc-porting.md @@ -34,7 +34,7 @@ This parser only exists to test the ABI and UI before Emscripten and LinuxCNC ar - spindle modes `G96`, `G97` - IJK and R arcs - numbered and named parameter assignment/reference such as `#1 = ...`, `# = ...`, `X#1`, and nested expressions like `X[[# + 2] * 3]` -- expression functions `ABS[]`, `SQRT[]`, `EXP[]`, `LN[]`, degree-based `SIN[]`/`COS[]`/`TAN[]`/`ASIN[]`/`ACOS[]`, LinuxCNC-style `ATAN[]/[]`, and `FIX[]`/`FUP[]`/`ROUND[]` +- expression functions `ABS[]`, `SQRT[]`, `EXP[]`, `LN[]`, degree-based `SIN[]`/`COS[]`/`TAN[]`/`ASIN[]`/`ACOS[]`, LinuxCNC-style `ATAN[]/[]`, `FIX[]`/`FUP[]`/`ROUND[]`, and source-linked `mod`/`**`/logical/relational operator precedence - numeric and named O-word subprograms such as `O100 call` and `O call` - canned cycles `G73`, `G74`, `G81`, `G82`, `G83`, `G84`, `G85`, `G86`, `G87`, `G88`, `G89` with `G80`, `G98`, `G99`, `L` - coordinate offset events for `G10 L2`, `G10 L20`, `G54`-`G59.3`, `G52`, `G92`, `G92.1`, `G92.2`, and `G92.3` @@ -212,5 +212,6 @@ This matrix tracks LinuxCNC feature coverage for the web/WASM simulator. A featu | Cutter compensation | covered for tool-table `G41/G42 D...` and explicit-radius `G41.1/G42.1/G40` through LinuxCNC native/source backends | `tests/gcode/linuxcnc_cutter_comp.ngc` | | Probe moves `G38.2/G38.3/G38.4/G38.5` | covered as distinct probe events with LinuxCNC `probe_type` preserved through smoke, native, and source-linked paths | `tests/gcode/linuxcnc_probe_no_error.ngc` | | O-word subroutines, calls, and control flow | covered for numeric and named `O... sub/call/return/endsub` plus `if`/`elseif`/`else`, `while`, `repeat`, `do`/`while`, `break`, and `continue` through LinuxCNC file mode; smoke parser also covers named `O` sub/call/return/endsub and loop-control forms | `tests/gcode/smoke_oword_subprogram.ngc`, `tests/gcode/linuxcnc_named_oword_subprogram.ngc`, `tests/gcode/linuxcnc_oword_control_flow.ngc` | +| Parameter expressions and operators | covered for parameter references and source-linked `mod`, `**`, logical, and relational operator precedence from LinuxCNC `interp_read.cc`/`interp_execute.cc` | `tests/gcode/linuxcnc_parameter_expression_assignment.ngc`, `tests/gcode/linuxcnc_expression_operators.ngc` | | Broader canned cycles `G73`, `G74`, `G82`-`G89` | partially covered: `G73`, `G74`, `G82`, `G83`, `G84`, `G85`, `G86`, `G87`, `G88`, `G89`; smoke parser maps supported cycles across `G17/G18/G19`, including LinuxCNC's special non-XY `G74/G84` tapping argument order and `G87` plane-specific `I/J/K` mapping; native/source regressions now check non-XY `G74/G84/G86/G87/G88` sequences | `tests/gcode/linuxcnc_canned_cycles_extended.ngc`, `tests/gcode/linuxcnc_canned_cycle_planes.ngc`, smoke API regression | | Full source-level wasm build | covered for the current wasm-safe RS274 source set, with remaining work focused on broadening browser-hostile dependency replacement and feature coverage | `./build-wasm.sh`, `test-linuxcnc-wasm-runtime-link.sh`, `test-web-wasm-node-smoke.sh`, `test-web-wasm-browser-smoke.sh` | diff --git a/test-linuxcnc-source-link.sh b/test-linuxcnc-source-link.sh index 50f5a7d..f6bb31e 100755 --- a/test-linuxcnc-source-link.sh +++ b/test-linuxcnc-source-link.sh @@ -586,6 +586,12 @@ CNC_SIM_RS274_FILE_MODE=1 CNC_SIM_RS274_VAR="$var_file" \ CNC_SIM_RS274_FILE_MODE=1 CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_parameter_expression_assignment.ngc \ >"$output_dir/cnc_sim_linuxcnc_source_parameter_expression_assignment.json" +# Source basis: LinuxCNC src/emc/rs274ngc/interp_read.cc read_operation() +# parses mod, power, logical, and relational operators; interp_execute.cc +# execute_binary1()/execute_binary2() evaluate their precedence and values. +CNC_SIM_RS274_FILE_MODE=1 CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_expression_operators.ngc \ + >"$output_dir/cnc_sim_linuxcnc_source_expression_operators.json" CNC_SIM_RS274_FILE_MODE=1 CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_word_bracket_whitespace.ngc \ >"$output_dir/cnc_sim_linuxcnc_source_word_bracket_whitespace.json" @@ -2021,6 +2027,27 @@ if not any( ): raise SystemExit("missing source-linked whitespace-insensitive word value motion") +expression_operators = json.loads((OUTPUT_DIR / "cnc_sim_linuxcnc_source_expression_operators.json").read_text()) +if not any( + event["type"] == "rapid" and + event["line"] == 6 and + event["end"]["x"] == 3 and + event["end"]["y"] == 16 and + event["end"]["z"] == 1 and + event["end"]["a"] == 1 + for event in expression_operators +): + raise SystemExit("missing source-linked expression mod/power/logical/relational motion") +if not any( + event["type"] == "rapid" and + event["line"] == 10 and + event["end"]["b"] == 19 and + event["end"]["c"] == 2 and + event["end"]["u"] == 1 + for event in expression_operators +): + raise SystemExit("missing source-linked expression precedence and relational branch motion") + word_bracket_whitespace = json.loads((OUTPUT_DIR / "cnc_sim_linuxcnc_source_word_bracket_whitespace.json").read_text()) if not any( event["type"] == "linear-feed" and diff --git a/tests/gcode/linuxcnc_expression_operators.ngc b/tests/gcode/linuxcnc_expression_operators.ngc new file mode 100644 index 0000000..2888e98 --- /dev/null +++ b/tests/gcode/linuxcnc_expression_operators.ngc @@ -0,0 +1,11 @@ +G21 G90 +#1 = [-7 mod 5] +#2 = [2 ** 3 * 2] +#3 = [[1 and 0] or [0 xor 2]] +#4 = [[1 lt 2] and [2 ge 2] and [3 ne 4] and [4 eq 4]] +G0 X#1 Y#2 Z#3 A#4 +#5 = [7 + 3 * 2 ** 2] +#6 = [[5 mod 2] + [-5 mod 2]] +#7 = [[2 gt 3] or [3 le 3]] +G0 B#5 C#6 U#7 +M2