nc-gcode-interpreter 0.2.10__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/CHANGELOG.md +260 -0
  2. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/Cargo.lock +37 -1
  3. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/Cargo.toml +7 -1
  4. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/Development.md +1 -1
  5. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/PKG-INFO +2 -2
  6. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/README.md +21 -4
  7. nc_gcode_interpreter-0.3.1/benches/extensions.rs +160 -0
  8. nc_gcode_interpreter-0.3.1/examples/axis_index_assignment.csv +5 -0
  9. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/axis_index_assignment.mpf +1 -1
  10. nc_gcode_interpreter-0.3.1/examples/defaults.def +6 -0
  11. nc_gcode_interpreter-0.3.1/examples/defaults_start.json +1 -0
  12. nc_gcode_interpreter-0.3.1/examples/function_calls.csv +3 -0
  13. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/function_calls.mpf +1 -1
  14. nc_gcode_interpreter-0.3.1/examples/multiple_m_codes.csv +9 -0
  15. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/multiple_m_codes.mpf +1 -1
  16. nc_gcode_interpreter-0.3.1/examples/r_param.csv +3 -0
  17. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/r_param.mpf +1 -1
  18. nc_gcode_interpreter-0.3.1/examples/simple.csv +6 -0
  19. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/simple.mpf +1 -1
  20. nc_gcode_interpreter-0.3.1/examples/trans_ic.csv +14 -0
  21. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/trans_ic.mpf +1 -1
  22. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/ggroups/generate_g_commands.py +14 -0
  23. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/pyproject.toml +1 -1
  24. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/nc_gcode_interpreter/__init__.py +186 -33
  25. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/nc_gcode_interpreter/_internal.pyi +19 -3
  26. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/nc_gcode_interpreter/cli.py +23 -4
  27. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_batch_variables.py +7 -4
  28. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_batches.py +12 -12
  29. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_diagnostics.py +3 -3
  30. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_expected_output.py +14 -14
  31. nc_gcode_interpreter-0.3.1/python/tests/test_feed_check.py +180 -0
  32. nc_gcode_interpreter-0.3.1/python/tests/test_feed_group.py +132 -0
  33. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_flags.py +2 -2
  34. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_flatten.py +8 -3
  35. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_frames.py +41 -41
  36. nc_gcode_interpreter-0.3.1/python/tests/test_g_group_enum.py +139 -0
  37. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_g_vocabulary.py +3 -3
  38. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_real_comparisons.py +1 -1
  39. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_stage1.py +17 -16
  40. nc_gcode_interpreter-0.3.1/python/tests/test_start_inputs.py +292 -0
  41. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_streaming.py +11 -8
  42. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_string_operations.py +3 -3
  43. nc_gcode_interpreter-0.3.1/python/tests/test_subprograms.py +628 -0
  44. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_unsupported.py +2 -2
  45. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/errors.rs +45 -7
  46. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/flatten.rs +13 -1
  47. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/grammar.pest +59 -8
  48. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/interpret_rules.rs +1243 -34
  49. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/interpreter.rs +245 -37
  50. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/lib.rs +538 -46
  51. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/line_driver.rs +82 -16
  52. nc_gcode_interpreter-0.3.1/src/main.rs +318 -0
  53. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/modal_groups.rs +214 -0
  54. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/output.rs +778 -18
  55. nc_gcode_interpreter-0.3.1/src/start.rs +1010 -0
  56. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/state.rs +102 -2
  57. nc_gcode_interpreter-0.3.1/src/subprogram.rs +655 -0
  58. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/vm.rs +2 -1
  59. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/tests/cli.rs +48 -0
  60. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/uv.lock +53 -20
  61. nc_gcode_interpreter-0.2.10/examples/axis_index_assignment.csv +0 -5
  62. nc_gcode_interpreter-0.2.10/examples/function_calls.csv +0 -3
  63. nc_gcode_interpreter-0.2.10/examples/multiple_m_codes.csv +0 -9
  64. nc_gcode_interpreter-0.2.10/examples/r_param.csv +0 -3
  65. nc_gcode_interpreter-0.2.10/examples/simple.csv +0 -6
  66. nc_gcode_interpreter-0.2.10/examples/trans_ic.csv +0 -14
  67. nc_gcode_interpreter-0.2.10/src/main.rs +0 -168
  68. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/.github/workflows/benchmark.yml +0 -0
  69. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/.github/workflows/build-and-release.yml +0 -0
  70. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/.gitignore +0 -0
  71. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/CONTRIBUTING.md +0 -0
  72. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/LICENSE +0 -0
  73. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/TODO.md +0 -0
  74. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/benches/fixtures.rs +0 -0
  75. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/benches/workloads.rs +0 -0
  76. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/build.rs +0 -0
  77. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/build_backend/nc_build_backend.py +0 -0
  78. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/docs/resumable-interpretation-design.md +0 -0
  79. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/docs/sinumerik-execution-model.md +0 -0
  80. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/actual_position.csv +0 -0
  81. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/actual_position.mpf +0 -0
  82. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/arc.csv +0 -0
  83. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/arc.mpf +0 -0
  84. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/arrays.csv +0 -0
  85. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/arrays.mpf +0 -0
  86. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/basic_math.csv +0 -0
  87. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/basic_math.mpf +0 -0
  88. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/case.csv +0 -0
  89. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/case.mpf +0 -0
  90. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/case_insensitive_variables.csv +0 -0
  91. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/case_insensitive_variables.mpf +0 -0
  92. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/custom_vars.csv +0 -0
  93. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/custom_vars.mpf +0 -0
  94. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/def_string.csv +0 -0
  95. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/def_string.mpf +0 -0
  96. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/defaults.csv +0 -0
  97. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/defaults.mpf +0 -0
  98. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/edge_cases.csv +0 -0
  99. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/edge_cases.mpf +0 -0
  100. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/flattening/flatten_demo.mpf +0 -0
  101. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/flattening/flatten_demo_flattened.csv +0 -0
  102. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/flattening/flatten_demo_raw.csv +0 -0
  103. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/for_loop.csv +0 -0
  104. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/for_loop.mpf +0 -0
  105. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/goto.csv +0 -0
  106. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/goto.mpf +0 -0
  107. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/if_statement.csv +0 -0
  108. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/if_statement.mpf +0 -0
  109. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/increment.csv +0 -0
  110. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/increment.mpf +0 -0
  111. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/logic_operators.csv +0 -0
  112. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/logic_operators.mpf +0 -0
  113. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/loop.csv +0 -0
  114. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/loop.mpf +0 -0
  115. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/precedence.csv +0 -0
  116. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/precedence.mpf +0 -0
  117. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/repeat.csv +0 -0
  118. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/repeat.mpf +0 -0
  119. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/rot.csv +0 -0
  120. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/rot.mpf +0 -0
  121. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/spline.csv +0 -0
  122. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/spline.mpf +0 -0
  123. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/tool.csv +0 -0
  124. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/tool.mpf +0 -0
  125. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/trans.csv +0 -0
  126. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/trans.mpf +0 -0
  127. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/trans2.csv +0 -0
  128. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/trans2.mpf +0 -0
  129. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/trans_reset.csv +0 -0
  130. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/trans_reset.mpf +0 -0
  131. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/trig.csv +0 -0
  132. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/trig.mpf +0 -0
  133. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/variables.csv +0 -0
  134. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/examples/variables.mpf +0 -0
  135. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/example/minimal.py +0 -0
  136. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/example/streaming.py +0 -0
  137. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/nc_gcode_interpreter/ggroups.json +0 -0
  138. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/nc_gcode_interpreter/py.typed +0 -0
  139. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/nc_gcode_interpreter/viz.py +0 -0
  140. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/nc_source.py +0 -0
  141. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_arithmetic_functions.py +0 -0
  142. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_compare_benchmarks.py +0 -0
  143. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_field_defects.py +0 -0
  144. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_g_groups.py +0 -0
  145. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_jumps.py +0 -0
  146. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/python/tests/test_structured_errors.py +0 -0
  147. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/rustfmt.toml +0 -0
  148. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/scripts/benchmark.py +0 -0
  149. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/scripts/compare_benchmarks.py +0 -0
  150. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/frame.rs +0 -0
  151. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/line_driver/experiments.rs +0 -0
  152. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/structure_scan.rs +0 -0
  153. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/src/types.rs +0 -0
  154. {nc_gcode_interpreter-0.2.10 → nc_gcode_interpreter-0.3.1}/tests/performance_contract.rs +0 -0
@@ -4,6 +4,266 @@ Notable changes to **nc-gcode-interpreter**. The format loosely follows
4
4
  [Keep a Changelog](https://keepachangelog.com/); versions are git tags,
5
5
  released to PyPI.
6
6
 
7
+ ## [v0.3.1] - 2026-11-11
8
+
9
+ ### Changed
10
+
11
+ - The G-group columns reach Python as one-byte codes and become `pl.Enum`
12
+ by a gather from each group's categories. Before, Rust sent an Arrow
13
+ dictionary tagged with an undocumented polars metadata key, and polars
14
+ looked up every row's string on import. On polars 1.40 a 7M-row program
15
+ with eleven G-group columns takes 15% less CPU (3.92 s to 3.32 s); on
16
+ polars 2.1 the time is unchanged. The output is identical, and the
17
+ interpreter no longer depends on that key. Polars 2 does not cast
18
+ integers to an Enum, so the gather works on both.
19
+
20
+ ## [v0.3.0] - 2026-11-11
21
+
22
+ This release changes the API and the output. To upgrade:
23
+
24
+ - Replace `initial_state` with `definitions` (definition files),
25
+ `variables` (values) and `start` (machine state); see the first entry
26
+ under Changed.
27
+ - Program a feed before the first path motion, or pass it in `start` (key
28
+ `"feed"`): a missing feed is now the `feed_not_programmed` error, as on
29
+ the control (alarm 10860).
30
+ - The G-group columns are `pl.Enum`, and polars 1.32 or newer is required.
31
+ `cast(pl.String)` restores the old dtype.
32
+ - New loud errors for constructs that used to be misread: two calls in one
33
+ block, `G4` with axis words, `FGROUP`/`FGREF` on non-axes, reading
34
+ `FGREF`, and others listed below.
35
+
36
+ ### Added
37
+
38
+ - Subprogram execution (#48). `nc_to_dataframe` and `nc_to_batches` take
39
+ `subprograms`, a mapping of subprogram name to source text. A call whose
40
+ name is in the mapping runs that text; any other call stays a
41
+ `non_returning_function_call` cell as before. Supported: a `PROC` header
42
+ with by-value parameters (numbers and strings, with defaults), `VAR`
43
+ parameters and `VAR` array parameters, local `DEF` variables (invisible to
44
+ callees, gone on return), return on `M17` or `RET`, and nested calls up to
45
+ 16 levels. Rows produced inside a call keep the main-program line of the
46
+ call in `line_no` and carry two new columns: `subprogram`, the call path
47
+ (`OUTER/INNER`), and `subprogram_line`, the line inside that subprogram's
48
+ text. The interpreter does not read files; the caller supplies the texts.
49
+ - `m_function_subprograms`, a mapping of M function number to subprogram
50
+ name: the subprogram runs at the end of every block that programs that M
51
+ function, as a control does for a tool-change cycle on `M6`. It does not
52
+ apply inside the replacement subprogram itself.
53
+ - External variables. `external_variables` takes a provider object with
54
+ `names`, `read(name, indices)` and `write(name, indices, value)`. Every
55
+ read or write of a listed name (`$A_IN`, `$A_DBB`, `$AA_IM`, or any other
56
+ variable name) goes to the provider and is not stored by the interpreter,
57
+ so a program can branch and wait on machine state the interpreter does not
58
+ model. Indices arrive as ints, or as the axis name where an axis is the
59
+ index. With `nc_to_batches` the rows produced so far are yielded before the
60
+ provider is asked, and the provider is called on the consuming thread, so
61
+ a simulator can play those rows first. An exception raised by the provider
62
+ ends the run and propagates unchanged.
63
+ - Rust API: `interpreter::nc_to_table_with` and
64
+ `interpreter::nc_to_batch_stream_with` take a `subprogram::Extensions`
65
+ value with the same extensions; the provider is the
66
+ `subprogram::ExternalVariables` trait.
67
+ - `required_subprograms`: a call of a listed name that is not among
68
+ `subprograms` is an error that names the call path, where it would
69
+ otherwise stay an opaque cell.
70
+ - `stop_on_setal`: a `SETAL` call ends the run with an error that carries the
71
+ call as written and the call path.
72
+ - String comparison with `==` and `<>` in conditions and expressions
73
+ (`IF (KIND == "MILL")`). Other operators on strings, and a string compared
74
+ with a number, are errors. A served external variable compared with a
75
+ string is read from the provider as text (`read` returns a `str`).
76
+ - A frame value assigned to a served external variable
77
+ (`$P_UIFR[7] = CTRANS(X, 10) : CROT(Z, 90)`) reaches the provider's `write`
78
+ as `[("CTRANS", ("X", 10.0)), ("CROT", ("Z", 90.0))]`. Assigned to any
79
+ other variable it is an error.
80
+ - Machine axis names (`AX1`) and frame components (`TR`, `FI`, `RT`, `SC`,
81
+ `MI`) are passed to the provider as index names.
82
+ - `transformation` column: the last `TRAORI`, `TRANSMIT`, `TRACYL`, `TRAANG`,
83
+ `TRACON` or `TRAFOOF` call as written, forward-filled like a modal G group.
84
+ The call also stays in `non_returning_function_call`.
85
+ - Definition files parse: the `DEF` attributes for range, preprocessing stop,
86
+ access rights, unit and limits (`DEF CHAN APW 4 REAL LLI 0 ULI 10 NAME`),
87
+ the `CHAR` type, and attribute-only `REDEF` lines are accepted and not
88
+ interpreted.
89
+ - Array assignment as a statement: `NAME[n] = SET(v, ...)` and
90
+ `NAME[n] = REP(v[, count])` write consecutive elements starting at the
91
+ indexed one, last index fastest. Before, only the `DEF` initializer form
92
+ was interpreted and the statement form was an internal error.
93
+ - A subprogram whose `PROC` header has the `SAVE` attribute gives the caller
94
+ back its modal G functions on return: each G group the subprogram changed
95
+ gets the caller's value on the row after the body's rows. A group the
96
+ program never set before the call cannot be restored and gives a warning.
97
+ - Loud errors for constructs the subprogram mechanism does not model: a
98
+ `FOR` counter, a `PROC` parameter or a local `DEF` with the name of an
99
+ external variable, a string assigned to an external variable, a `PROC` parameter with the name of an axis or
100
+ address, `SET`/`REP` statements that write past the declared array, and
101
+ two `subprograms` entries whose names differ only in case.
102
+ - Program repetitions: `L6 P2` and `L6 P=2` call `L6` twice (manual
103
+ 4.2.3.3). A supplied subprogram runs that many times, with its arguments
104
+ passed once; without a supplied body the call keeps its name and the
105
+ count goes to a new `call_repetitions` column. A count outside 1 to 9999
106
+ is an error. Before, `L6 P2` was recorded as a call named `P2` and
107
+ `L6 P=2` set a user variable `P` (part of #105).
108
+ - `PCALL NAME(...)` calls `NAME` (manual 4.2.3.8). A path before the name
109
+ (`PCALL/_N_WKS_DIR/_N_X_WPD/NAME`) is not interpreted and gives a
110
+ warning; the call goes to `NAME`. Before, `PCALL` was dropped silently.
111
+
112
+ - `FGROUP(<axes>)` and `FGREF[<axis>]=<radius>` are modal state (manual
113
+ 3.7.1). A forward-filled, dictionary-encoded `FGROUP` column holds the axes
114
+ the path feed refers to, comma-separated as programmed; `FGROUP()` writes
115
+ `""` for the machine-data default, which the interpreter does not know.
116
+ Each programmed axis gets a forward-filled `FGREF[<axis>]` float column;
117
+ null means the control default. Both columns appear only when the program
118
+ uses them, after the axis columns. Before, `FGROUP` was stored as a
119
+ subprogram call in `non_returning_function_call` and `FGREF[<axis>]` needed
120
+ an `axis_index_map` entry and became the variable `FGREF[<index>]`; it now
121
+ resolves by axis name and is no longer a variable. An argument that is not
122
+ a configured channel axis (including N, F, S, D and T) is an
123
+ `unexpected_axis` error. Reading `FGREF[<axis>]` is an
124
+ `unsupported_statement` error, and so is a user array named `FGREF` (#107).
125
+
126
+ ### Changed
127
+
128
+ - **Breaking:** `initial_state` is removed from `nc_to_dataframe`,
129
+ `nc_to_batches`, `nc_to_rows`, the Rust interpreter functions and the CLIs
130
+ (`-i/--initial_state`, `--initial-state`). It ran a string of NC text before
131
+ the program and discarded its rows, which mixed three jobs. Three inputs
132
+ replace it, applied in this order before the main program:
133
+ - `definitions`: a list of definition files (GUD/MGUD/UGUD `.DEF`), each
134
+ read on its own. A file may hold DEF and REDEF statements, assignments to
135
+ variables and comments; the `%_N_..._DEF` header and `$PATH=` line are
136
+ skipped. M17, M30 or M2 ends that file and reading goes on with the next,
137
+ so several files no longer need their end codes stripped. `CHANDATA(1)`
138
+ is accepted and ignored; another channel number is an error. `TRAFOOF`
139
+ on a block of its own sets the start transformation to off, in the first
140
+ row and the returned state, unless `start["transformation"]` gives
141
+ another, so a restore program (CHANDATA(1), TRAFOOF, SET array
142
+ assignments, M30) reads unchanged. The program stops M0 and M1 are
143
+ ignored. A subprogram call stays an error naming the call. Assigning
144
+ to a name the files have not declared is an error, unless it is an R
145
+ parameter or `allow_undefined_variables` is set. Motion, G codes or
146
+ anything else is an error naming the file (`NcError.definition_file`,
147
+ its index in the list) and the line within it. Migration: pass the DEF
148
+ files as a list instead of concatenating them into `initial_state`.
149
+ - `variables`: a dict of values (`float`, `int`, `bool`, `str`) written
150
+ straight into the variable tables and checked against the declared type
151
+ (2.5 into an INT, or a string into a REAL or an R parameter, is an
152
+ error). Names must be
153
+ defined unless they are R parameters, system variables or
154
+ `allow_undefined_variables` is set. Migration: replace generated
155
+ `NAME=VALUE` lines with `variables={"NAME": value}`; strings now work.
156
+ - `start`: the machine state at program start, in the shape of the
157
+ returned state dict (`axes`, `translation`, `rotation`, `symbol_table`,
158
+ `string_table`, plus the new `g_groups`, `feed`, `tool`,
159
+ `transformation`, `fgroup` and `fgref`), so a returned state can be
160
+ passed back. `fgroup` is the FGROUP column value and `fgref` maps a
161
+ channel axis to its FGREF reference radius. Modal G groups
162
+ are checked against the G group table, and they, `feed`, `tool` (the `T`
163
+ column), `transformation`, `fgroup` and `fgref` fill the first output row, so those columns
164
+ no longer start as null. Axis positions and the frame only seed the internal state.
165
+ A name in both `variables` and `start` is an error. Migration: replace
166
+ axis words and frame instructions in `initial_state` with
167
+ `start={"axes": {...}, "translation": {...}}`, and modal G codes and F
168
+ with `start={"g_groups": {...}, "feed": ...}`.
169
+ The returned state gains `g_groups` (modal G group column to code, as of
170
+ the last row), `feed`, `tool`, `transformation`, `fgroup` and `fgref`. The CLIs take `--definitions FILE` (repeatable),
171
+ `--variables FILE.json` and `--start FILE.json`. The Rust functions take
172
+ `Option<&start::StartInputs>` where they took `Option<&str>`.
173
+
174
+ - **Breaking:** a block that traverses a path (G1, G2, G3, CIP, splines and
175
+ the other path motions) while no feed is programmed is an error
176
+ (`NcError.kind == "feed_not_programmed"`), as alarm 10860 is on the
177
+ control. G0, the G4 dwell, G74/G75 and the thread commands need no F;
178
+ G63 tapping does. A change of feed unit deletes F and FZ (Axes and
179
+ spindles manual 7.2.1, 7.2.2): inverse time (G93), traversing time
180
+ (G931), per minute (G94, G961, G971, G942) and per revolution (G95, G96,
181
+ G97, G952, G973); G962 and G972 keep the unit that was active. A change
182
+ within one unit (G95 to G96) keeps F. When the previous feed type is
183
+ unknown (never programmed, not in `start["g_groups"]`) nothing is
184
+ deleted. A feed seeded from `start` is start state, not an F of the first
185
+ block, so a feed type change there deletes it too. `FZ=` (feed per tooth)
186
+ counts as a feed under a revolutional feed type and `FB=` (non-modal feed,
187
+ 7.4.10) for its own block; both are now output columns (`FZ`
188
+ forward-filled, `FB` not), where they used to become variables. G4 with
189
+ axis words in the same block is an error (G4 stands alone, manual
190
+ 3.14.7). G93 recommends but does not
191
+ require F in every block, so that is not checked. The control's default
192
+ feed SD42110 `$SC_DEFAULT_FEED` (0 unless set) is evaluated at program
193
+ start: pass it as `start["feed"]`. The check is off when F is not a
194
+ configured axis. FGROUP only selects the axes F refers to, so a block
195
+ moving only synchronized or rotary axes needs F the same way, and FGROUP
196
+ and FGREF neither move nor delete F. Tree walker, VM and line fast path
197
+ raise the same error.
198
+ Migration: program F before the first path motion or pass
199
+ `start={"feed": ...}`. The examples `simple`, `trans_ic`, `r_param`,
200
+ `axis_index_assignment`, `multiple_m_codes` and `function_calls` gained
201
+ `F1000` on their first path motion, and their expected CSVs gained the
202
+ `F` column (no other column changed).
203
+
204
+ - **Breaking:** every G-group column (`gg01_motion`, `gg02_wait`, ...) in the
205
+ output of `nc_to_batches`, `nc_to_dataframe` and `sanitize_dataframe` is
206
+ now a `pl.Enum` instead of `String`. Its categories are that group's
207
+ commands in manual order, the same in every batch and every run, so batches
208
+ and runs concatenate without a cast and a value outside the group cannot
209
+ occur. Rust hands the codes over as an Arrow dictionary that polars imports
210
+ as `Enum` directly, with no cast. The new `G_GROUP_DTYPES` maps each G-group column name to its
211
+ `pl.Enum`, for matching schemas and empty frames. `T`, `comment`,
212
+ `non_returning_function_call` and other free-text columns stay `String`,
213
+ and `nc_to_rows` still yields `str`. On a 1M-row program the G-group cells
214
+ take 1 byte each instead of a 16-byte string view, and filtering or
215
+ grouping on them is about 1.4 to 2 times faster, at unchanged
216
+ interpretation time. Consequences
217
+ for code that reads these columns:
218
+ - `.str` methods raise `InvalidOperationError`, and joining against a
219
+ `String` column raises `SchemaError`.
220
+ - `fill_null("")` silently leaves the nulls in place, because `""` is not a
221
+ category.
222
+ - `is_in` with a value outside the group raises; `==` with such a literal
223
+ returns no matches.
224
+ - Sorting follows manual order (`G0`, `G1`, `G2`, ...), not alphabetical
225
+ order.
226
+ - A strict `pl.concat` with frames from an older version, or
227
+ `assert_frame_equal` against `String` frames, fails on the dtype.
228
+ - Migration: `df.with_columns(pl.col(c).cast(pl.String) for c in
229
+ G_GROUP_DTYPES if c in df.columns)` restores the old dtype.
230
+
231
+ - **Breaking:** the minimum polars version is now 1.32 (was 1.9). The Enum
232
+ handoff relies on the Arrow field metadata polars reads from 1.32 on.
233
+
234
+ - A program that calls `TRAORI`, `TRANSMIT`, `TRACYL`, `TRAANG`, `TRACON` or
235
+ `TRAFOOF` gets the new `transformation` column, also when it uses none of
236
+ the new arguments.
237
+ - Two subprogram calls in one block (`FOO BAR`) are an error. Before, the
238
+ second silently replaced the first. Keyword G commands such as `SOFT`
239
+ next to a call are unaffected. A repeat count before the name (`P3 FOO`,
240
+ `P=3 FOO`) is an error as well (part of #105).
241
+ - `PROC`, `EXTERN` and `RET` are reserved words and no longer read as
242
+ subprogram calls. A `PROC` header and an `EXTERN` declaration produce no
243
+ output; `RET` ends the program at the top level like `M17`. Before,
244
+ `PROC FOO SAVE` was recorded as a call named `SAVE` and `RET` as a call
245
+ while interpretation continued (part of #105). A main program whose `PROC`
246
+ header declares parameters is an error.
247
+ - A program without control structures keeps the line fast path when an
248
+ extension is used. Only its lines with a call, an M function mapped to a
249
+ subprogram, or a word that names a served variable go through the
250
+ grammar, which dispatches them. Before, any extension sent the whole
251
+ program through the grammar path, about seven times slower per line.
252
+ - `DEF REAL A[n]` declares the elements `A[0]` to `A[n-1]`. Before, it also
253
+ created `A[n]`, so an out-of-range access went unnoticed.
254
+ - `REDEF` and `PCALL` are reserved words.
255
+ - A supplied subprogram is checked and parsed on its first call, and later
256
+ calls in the same run reuse the parse tree. Before, every call parsed the
257
+ text again, which was about two thirds of the time of a call of a 20-line
258
+ body. Adds the `self_cell` dependency, which holds the tree next to the
259
+ text it borrows from.
260
+ - `nc_to_dataframe` with `external_variables` no longer sends the rows
261
+ produced so far as a separate batch before each provider call, since its
262
+ caller reads no row before the run ends. A program that reads the provider
263
+ on every motion row built one batch per row. `nc_to_batches` and the Rust
264
+ API keep handing the rows over first; Rust callers can opt out with
265
+ `Extensions::defer_rows`.
266
+
7
267
  ## [v0.2.10] - 2026-11-10
8
268
 
9
269
  ### Changed
@@ -506,7 +506,7 @@ checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
506
506
 
507
507
  [[package]]
508
508
  name = "nc-gcode-interpreter"
509
- version = "0.2.10"
509
+ version = "0.3.1"
510
510
  dependencies = [
511
511
  "arrow-array",
512
512
  "arrow-data",
@@ -518,6 +518,8 @@ dependencies = [
518
518
  "pyo3",
519
519
  "rayon",
520
520
  "rustc-hash",
521
+ "self_cell",
522
+ "serde_json",
521
523
  "thiserror",
522
524
  ]
523
525
 
@@ -745,6 +747,21 @@ version = "1.0.23"
745
747
  source = "registry+https://github.com/rust-lang/crates.io-index"
746
748
  checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
747
749
 
750
+ [[package]]
751
+ name = "self_cell"
752
+ version = "1.3.0"
753
+ source = "registry+https://github.com/rust-lang/crates.io-index"
754
+ checksum = "2ab42ca02749e120097e328d91d415325bdf43b1c72c4c8badf37375fe40a813"
755
+
756
+ [[package]]
757
+ name = "serde"
758
+ version = "1.0.228"
759
+ source = "registry+https://github.com/rust-lang/crates.io-index"
760
+ checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
761
+ dependencies = [
762
+ "serde_core",
763
+ ]
764
+
748
765
  [[package]]
749
766
  name = "serde_core"
750
767
  version = "1.0.228"
@@ -765,6 +782,19 @@ dependencies = [
765
782
  "syn",
766
783
  ]
767
784
 
785
+ [[package]]
786
+ name = "serde_json"
787
+ version = "1.0.154"
788
+ source = "registry+https://github.com/rust-lang/crates.io-index"
789
+ checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
790
+ dependencies = [
791
+ "itoa",
792
+ "memchr",
793
+ "serde",
794
+ "serde_core",
795
+ "zmij",
796
+ ]
797
+
768
798
  [[package]]
769
799
  name = "sha2"
770
800
  version = "0.10.9"
@@ -1023,3 +1053,9 @@ dependencies = [
1023
1053
  "quote",
1024
1054
  "syn",
1025
1055
  ]
1056
+
1057
+ [[package]]
1058
+ name = "zmij"
1059
+ version = "1.0.23"
1060
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1061
+ checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "nc-gcode-interpreter"
3
- version = "0.2.10"
3
+ version = "0.3.1"
4
4
  edition = "2021"
5
5
  readme = "README.md"
6
6
 
@@ -20,6 +20,7 @@ thiserror = "2.0.18"
20
20
  clap = { version = "4.6", features = ["derive"] }
21
21
  rayon = "1.10"
22
22
  rustc-hash = "2.1"
23
+ serde_json = "1"
23
24
 
24
25
  # NOTE: keep every dependency version inline (`crate = { version = "..." }`),
25
26
  # NOT as a `[dependencies.crate]` block with a standalone `version = "..."`
@@ -44,6 +45,7 @@ pyo3 = { version = "0.29", optional = true }
44
45
  arrow-array = { version = "59", optional = true, default-features = false, features = ["ffi"] }
45
46
  arrow-schema = { version = "59", optional = true, default-features = false }
46
47
  arrow-data = { version = "59", optional = true, default-features = false }
48
+ self_cell = "1"
47
49
 
48
50
  [features]
49
51
  default = []
@@ -54,3 +56,7 @@ python = ["pyo3", "arrow-array", "arrow-schema", "arrow-data"]
54
56
  name = "workloads"
55
57
  harness = false
56
58
  required-features = ["bench-experiments"]
59
+
60
+ [[bench]]
61
+ name = "extensions"
62
+ harness = false
@@ -78,7 +78,7 @@ evaluated for its extra build time across the wheel matrix.
78
78
  There are a bunch of csv files in the examples directory. To test the tool on all of them (use git to check changes)
79
79
 
80
80
  ```bash
81
- rm **/*.csv && cargo build --release && find examples -name "*.mpf" -type f -print0 | xargs -0 -I {} sh -c './target/release/nc-gcode-interpreter --axis-index-map E:4 --initial_state=examples/defaults.mpf "$1" || echo "Failed to process $1" >&2' sh {}
81
+ rm **/*.csv && cargo build --release && find examples -name "*.mpf" -type f -print0 | xargs -0 -I {} sh -c './target/release/nc-gcode-interpreter --axis-index-map E:4 --definitions examples/defaults.def --start examples/defaults_start.json "$1" || echo "Failed to process $1" >&2' sh {}
82
82
  ```
83
83
 
84
84
  ## python test
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nc-gcode-interpreter
3
- Version: 0.2.10
3
+ Version: 0.3.1
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -9,7 +9,7 @@ Classifier: License :: OSI Approved :: MIT License
9
9
  Classifier: Operating System :: OS Independent
10
10
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
11
11
  Requires-Dist: maturin>=1.7.4
12
- Requires-Dist: polars>=1.9.0
12
+ Requires-Dist: polars>=1.32.0
13
13
  Requires-Dist: jupyter>=1.1.1 ; extra == 'dev'
14
14
  Requires-Dist: pytest>=8.3.3 ; extra == 'test'
15
15
  Requires-Dist: mypy ; extra == 'test'
@@ -20,6 +20,7 @@ The **NC-GCode-Interpreter** offers a streamlined and efficient solution for int
20
20
  - **Array Operations**: Manages arrays and allows operations on them.
21
21
  - **Incremental Changes**: Facilitates incremental changes in axes positions like `X=IC(2)`.
22
22
  - **Spline Programming**: `ASPLINE`, `BSPLINE` and `CSPLINE` blocks with their start/end conditions (`BAUTO`/`BNAT`/`BTAN`, `EAUTO`/`ENAT`/`ETAN`) and the spline block addresses `PW` (point weight), `SD` (spline degree) and `PL` (parameter interval length). Block addresses appear as output columns; unlike axes they receive no `TRANS` offset and are not forward-filled, since e.g. a point weight only applies to the point it is programmed with.
23
+ - **Feed group**: `FGROUP(<axes>)` and `FGREF[<axis>]=<radius>` are modal state, not calls or variables. The `FGROUP` column holds the axes the path feed `F` refers to, comma-separated as programmed (`"RA1,RA2,RA3"`); `FGROUP()` gives `""`, the machine-data default, as does a null before the first `FGROUP`. Each `FGREF[<axis>]` column holds the reference radius of that axis; null means the control default (360 mm / 2π for a rotary axis). Both are forward-filled, appear only when the program uses them, and need no `axis_index_map` entry. The interpreter computes no timing from them.
23
24
 
24
25
  ### Additional Functionality
25
26
 
@@ -28,7 +29,8 @@ The **NC-GCode-Interpreter** offers a streamlined and efficient solution for int
28
29
  - **Curve flattening**: pass `flatten_tolerance` (Python) or `--flatten-tolerance` (CLI) to convert curved motions — `G2`/`G3` arcs (`I`/`J`/`K` centre offsets or `CR=` radius form, `G17`/`G18`/`G19` planes, helical third axis with `TURN=` multi-turn support, full circles) and `ASPLINE`/`BSPLINE`/`CSPLINE` splines (including `PW` weights and `SD` degree) — into runs of plain `G1` rows in the same table format. `CIP`/`CT`/`POLY`/thread/involute blocks pass through unchanged with a warning; spline start/end conditions (`BAUTO`/`BNAT`/... ) are approximated by natural (CSPLINE) / Akima (ASPLINE) boundaries — see the `flatten` module docs for the full list of checked approximations. The single tolerance is the maximum deviation between the emitted polyline and the true curve, in path units: arcs use the exact sagitta bound, splines adaptive subdivision. The interpolation addresses (`I`/`J`/`K`/`CR`/`PW`/`SD`/`PL`) are consumed and do not appear in the output; sampled rows keep the source block's line number, and its other cells (`F`, `M`, comments, ...) ride on the first sample so modal behavior is preserved. Generated samples carry a `flattened = 1` marker column (never forward-filled); programmed positions stay null there, so filtering on null recovers the original toolpath points.
29
30
  - **Toolpath visualization** (optional): with the `viz` extra (`pip install 'nc-gcode-interpreter[viz]'`), `nc_gcode_interpreter.viz.view_toolpath(df)` renders an interpreted toolpath in [threejs-viewer](https://pypi.org/project/threejs-viewer/) as an extruded bead tube with a draw-range animation replaying the program at feed-rate-proportional speed. Combined with `flatten_tolerance`, programmed points render orange and flattener-generated samples blue. The extra also installs the `nc-view` command: `nc-view part.mpf` interprets, flattens (default tolerance 0.1, `--no-flatten` to skip) and opens the animated toolpath in the browser; `--speed` sets the time-lapse factor (default 60 = one machine-minute per second).
30
31
  - **Custom Axes**: Allows users to define additional axes beyond the standard `X`, `Y`, `Z`.
31
- - **Initial State Configuration**: Enables the use of an initial state MPF file to set default values for multiple runs.
32
+ - **Definitions, variables and start state**: `definitions` takes the definition files a control loads (GUD/MGUD/UGUD `.DEF`: DEF and REDEF statements, assignments, comments; M17/M30/M2 ends a file), `variables` takes variable values checked against their declared type, and `start` takes the machine state at program start in the shape of the returned `state` dict (axes, frame, variables, modal G groups, feed, tool, transformation, FGROUP and FGREF radii). The G groups, feed, tool, transformation, FGROUP and FGREF fill the first output row; seeded G groups have the same `pl.Enum` dtype as the rest of the column. They are applied in that order, before the main program. In a definition file `CHANDATA(1)` is ignored, another channel is an error, `TRAFOOF` sets the start transformation to off (a later `start["transformation"]` wins), M0 and M1 are ignored, a subprogram call is an error, and assigning to an undeclared name is an error unless it is an R parameter or `allow_undefined_variables` is set.
33
+ - **Feed check**: a path motion (G1, G2, G3, CIP, splines) with no feed programmed is an error, as alarm 10860 is on the control; a change of feed unit (inverse time, per minute, per revolution) deletes F; `FZ=` counts as a feed under a revolutional feed type and `FB=` for its own block. FGROUP does not change this: a block moving only axes outside the FGROUP, or only rotary axes, needs F too. Pass the control's default feed (SD42110 `$SC_DEFAULT_FEED`) as `start["feed"]`. The check is off when F is not a configured axis. On the CLI: `--definitions FILE` (repeatable), `--variables FILE.json` and `--start FILE.json`.
32
34
  - **CLI Options**: Numerous command-line options to customize the processing, such as axis overriding, loop limits, and more.
33
35
 
34
36
  ## Example Usage
@@ -66,7 +68,9 @@ Arguments:
66
68
  Options:
67
69
  -a, --axes <AXIS> Override default axis identifiers (comma-separated, e.g., "X,Y,Z")
68
70
  -e, --extra-axes <EXTRA_AXIS> Add extra axis identifiers (comma-separated, e.g., "RA1,RA2")
69
- -i, --initial_state <INITIAL_STATE> Optional initial state file to e.g. define global variables or set axis positions
71
+ --definitions <FILE> Definition file (GUD/MGUD .DEF) to read before the program; repeat for several, read in order
72
+ --variables <FILE> JSON object of variable values applied after the definitions, e.g. {"COUNT": 3}
73
+ --start <FILE> JSON object with the machine state at program start (the shape of the returned state)
70
74
  -l, --iteration_limit <LIMIT> Maximum number of iterations for loops [default: 10000]
71
75
  -f, --disable-forward-fill Disable forward-filling of null values in axes columns
72
76
  -h, --help Print help
@@ -113,7 +117,7 @@ shape: (14, 7)
113
117
  ┌───────┬───────┬──────┬────────┬───────────┬─────────────┬─────────────────────────────────┐
114
118
  │ X ┆ Y ┆ Z ┆ F ┆ M ┆ gg01_motion ┆ comment │
115
119
  │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
116
- │ f64 ┆ f64 ┆ f64 ┆ f64 ┆ list[str] ┆ str ┆ str │
120
+ │ f64 ┆ f64 ┆ f64 ┆ f64 ┆ list[str] ┆ enum ┆ str │
117
121
  ╞═══════╪═══════╪══════╪════════╪═══════════╪═════════════╪═════════════════════════════════╡
118
122
  │ null ┆ null ┆ null ┆ null ┆ null ┆ null ┆ ;size of the square │
119
123
  │ null ┆ null ┆ null ┆ null ┆ null ┆ null ┆ ;size of the square │
@@ -131,6 +135,17 @@ shape: (14, 7)
131
135
 
132
136
  The Python bindings also return the state of the program after execution, which can be used for inspection.
133
137
 
138
+ #### Column dtypes
139
+
140
+ Axis and other value columns are `Float64`, `N` is `Int64` and `M` is `List(String)`. Each G-group column (`gg01_motion`, `gg06_plane_select`, ...) is a `pl.Enum` whose categories are that group's commands in manual order; `G_GROUP_DTYPES` maps every G-group column name to its dtype, for building matching schemas or empty frames. Every batch and every run has the same Enum per column, so frames concatenate without a cast. The Python package requires polars 1.32 or newer. `T`, `comment`, `non_returning_function_call` and other free-text columns stay `String`. `nc_to_rows` yields plain `str` values.
141
+
142
+ Things that differ from a `String` column:
143
+
144
+ - `pl.col("gg01_motion") == "G1"` and `is_in(["G0", "G1"])` work; `is_in` with a value outside the group raises.
145
+ - `.str` methods and joins against a `String` column raise; cast first with `.cast(pl.String)`.
146
+ - `fill_null("")` leaves the nulls in place, because `""` is not a category. Cast to `String` first.
147
+ - Sorting follows manual order (`G0`, `G1`, `G2`, ...), not alphabetical order.
148
+
134
149
  #### Streaming
135
150
 
136
151
  For long programs (or when you want results before the whole file is interpreted), `nc_to_rows` yields rows lazily while the interpreter runs on a background thread. Each row carries the 1-based source line it came from — loops and jumps repeat line numbers, which is exactly what a visualizer needs to map trace rows back to the program:
@@ -202,7 +217,9 @@ Arguments:
202
217
  Options:
203
218
  -a, --axes <AXIS> Override default axis identifiers (comma-separated, e.g., "X,Y,Z")
204
219
  -e, --extra-axes <EXTRA_AXIS> Add extra axis identifiers (comma-separated, e.g., "RA1,RA2")
205
- -i, --initial_state <INITIAL_STATE> Optional initial_state file to initialize state
220
+ --definitions <FILE> Definition file (GUD/MGUD .DEF) to read before the program; repeat for several, read in order
221
+ --variables <FILE> JSON object of variable values applied after the definitions, e.g. {"COUNT": 3}
222
+ --start <FILE> JSON object with the machine state at program start (the shape of the returned state)
206
223
  -l, --iteration_limit <LIMIT> Maximum number of iterations for loops [default: 10000]
207
224
  -f, --disable-forward-fill Disable forward-filling of null values in axes columns
208
225
  -h, --help Print help
@@ -0,0 +1,160 @@
1
+ //! Cost of supplied subprograms and an external-variable provider (#48),
2
+ //! without the Python boundary: `cargo bench --bench extensions [samples]`.
3
+ use nc_gcode_interpreter::interpreter::{nc_to_batch_stream_with, nc_to_table_with};
4
+ use nc_gcode_interpreter::start::StartInputs;
5
+ use nc_gcode_interpreter::subprogram::{Extensions, ExternalError, ExternalIndex, ExternalVariables};
6
+ use std::{collections::HashMap, hint::black_box, time::Instant};
7
+
8
+ const BODY_LINES: usize = 20;
9
+ const CALLS: usize = 10_000;
10
+ const READS: usize = 100_000;
11
+
12
+ /// Answers every read with 1 and counts the accesses.
13
+ struct Constant(usize);
14
+
15
+ impl ExternalVariables for Constant {
16
+ fn read(&mut self, _: &str, _: &[ExternalIndex]) -> Result<f64, ExternalError> {
17
+ self.0 += 1;
18
+ Ok(1.0)
19
+ }
20
+ fn write(&mut self, _: &str, _: &[ExternalIndex], _: f64) -> Result<(), ExternalError> {
21
+ Ok(())
22
+ }
23
+ }
24
+
25
+ fn body() -> String {
26
+ let mut text = String::from("PROC BODY(REAL VAL)\n");
27
+ for k in 0..BODY_LINES - 2 {
28
+ text += &format!("G1 X=VAL+{k} Y={k}.5 F1200\n");
29
+ }
30
+ text + "M17\n"
31
+ }
32
+
33
+ fn calls() -> String {
34
+ let mut text = String::from("G1 X0 Y0 F1200\n");
35
+ for i in 0..CALLS {
36
+ text += &format!("BODY({i})\n");
37
+ }
38
+ text + "M30\n"
39
+ }
40
+
41
+ /// The rows of `calls()` with the body inlined: the interpreter-only reference.
42
+ fn inlined() -> String {
43
+ let mut text = String::from("G1 X0 Y0 F1200\n");
44
+ for i in 0..CALLS {
45
+ text += &format!("R10={i}\n");
46
+ for k in 0..BODY_LINES - 2 {
47
+ text += &format!("G1 X=R10+{k} Y={k}.5 F1200\n");
48
+ }
49
+ }
50
+ text + "M30\n"
51
+ }
52
+
53
+ fn read_loop(source: &str) -> String {
54
+ format!("R1=0\nR2=0\nWHILE R1<{READS}\nR2=R2+{source}\nR1=R1+1\nENDWHILE\nG1 F1200 X=R2\nM30\n")
55
+ }
56
+
57
+ fn read_rows(source: &str) -> String {
58
+ (0..READS)
59
+ .map(|i| format!("G1 F1200 X={source}+{}\n", i % 100))
60
+ .collect::<String>()
61
+ + "M30\n"
62
+ }
63
+
64
+ fn provider() -> Option<(Vec<String>, Box<dyn ExternalVariables>)> {
65
+ Some((vec!["$A_IN".to_string()], Box::new(Constant(0))))
66
+ }
67
+
68
+ fn table(program: &str, initial: Option<&StartInputs>, extensions: Extensions) -> usize {
69
+ let (table, _) = nc_to_table_with(
70
+ program, initial, None, None, 10_000_000, false, None, false, None, extensions,
71
+ )
72
+ .expect("program runs");
73
+ table.height()
74
+ }
75
+
76
+ /// As the Python bindings run it: batches over a channel, flushed before each provider call.
77
+ fn stream(program: &str, initial: Option<&StartInputs>, extensions: Extensions) -> usize {
78
+ let (tx, rx) = std::sync::mpsc::sync_channel(3);
79
+ let (events, _events) = std::sync::mpsc::channel();
80
+ std::thread::scope(|scope| {
81
+ let consumer = scope.spawn(move || rx.iter().map(|t: nc_gcode_interpreter::output::Table| t.height()).sum());
82
+ nc_to_batch_stream_with(
83
+ program,
84
+ initial,
85
+ None,
86
+ None,
87
+ 10_000_000,
88
+ false,
89
+ None,
90
+ false,
91
+ None,
92
+ 500_000,
93
+ false,
94
+ Box::new(move |t| tx.send(t).map_err(|_| ())),
95
+ false,
96
+ events,
97
+ extensions,
98
+ )
99
+ .expect("program runs");
100
+ consumer.join().unwrap()
101
+ })
102
+ }
103
+
104
+ fn main() {
105
+ let samples: usize = std::env::args().nth(1).and_then(|s| s.parse().ok()).unwrap_or(5);
106
+ let sub = body();
107
+ let preset_inputs = StartInputs {
108
+ definitions: vec!["DEF REAL AIN1=1\n".to_string()],
109
+ ..StartInputs::default()
110
+ };
111
+ let preset = Some(&preset_inputs);
112
+ let calls = calls();
113
+ let inlined = inlined();
114
+ let loop_preset = read_loop("AIN1");
115
+ let loop_ext = read_loop("$A_IN[1]");
116
+ let rows_preset = read_rows("AIN1");
117
+ let rows_ext = read_rows("$A_IN[1]");
118
+ let subs = || Extensions {
119
+ subprograms: HashMap::from([("BODY".to_string(), sub.clone())]),
120
+ ..Default::default()
121
+ };
122
+ let ext = || Extensions {
123
+ external: provider(),
124
+ ..Default::default()
125
+ };
126
+ let cases: Vec<(&str, Box<dyn Fn() -> usize>)> = vec![
127
+ (
128
+ "inline_10k_x20",
129
+ Box::new(|| table(&inlined, None, Extensions::default())),
130
+ ),
131
+ ("calls_10k_x20", Box::new(|| table(&calls, None, subs()))),
132
+ (
133
+ "readloop_preset_100k",
134
+ Box::new(|| table(&loop_preset, preset, Extensions::default())),
135
+ ),
136
+ ("readloop_provider_100k", Box::new(|| table(&loop_ext, None, ext()))),
137
+ (
138
+ "readrows_preset_100k",
139
+ Box::new(|| stream(&rows_preset, preset, Extensions::default())),
140
+ ),
141
+ ("readrows_provider_100k", Box::new(|| stream(&rows_ext, None, ext()))),
142
+ ];
143
+ println!("case,median_ms,min_ms,max_ms,rows");
144
+ for (name, case) in cases {
145
+ let mut times: Vec<f64> = Vec::with_capacity(samples);
146
+ let mut rows = 0;
147
+ for _ in 0..samples {
148
+ let start = Instant::now();
149
+ rows = black_box(case());
150
+ times.push(start.elapsed().as_secs_f64() * 1000.);
151
+ }
152
+ times.sort_by(f64::total_cmp);
153
+ println!(
154
+ "{name},{:.1},{:.1},{:.1},{rows}",
155
+ times[times.len() / 2],
156
+ times[0],
157
+ times[times.len() - 1]
158
+ );
159
+ }
160
+ }
@@ -0,0 +1,5 @@
1
+ gg01_motion,X,F,comment
2
+ ,,,; Reduce the acceleration of the E axis to 50% of the programmed value
3
+ G1,50.000,1000.000,
4
+ G1,4.000,1000.000,
5
+ G1,123.000,1000.000,
@@ -1,7 +1,7 @@
1
1
  DEF INT MY_VAR=3
2
2
  ACC[E]=50; Reduce the acceleration of the E axis to 50% of the programmed value
3
3
  ACC[MY_VAR]=123
4
- G1 X=ACC[E]
4
+ G1 F1000 X=ACC[E]
5
5
  ACC[4]=4
6
6
  X=ACC[E]
7
7
  X=ACC[3]
@@ -0,0 +1,6 @@
1
+ ; definitions shared by the example programs
2
+ DEF INT bb,aa=12
3
+ DEF REAL START_CC=10, START_CC_SPEED=0.5, EXTRUSION_MULTIPLIER=1, RETRACT_CC=1
4
+ aa = aa+3
5
+ bb = 9
6
+ M30
@@ -0,0 +1 @@
1
+ {"axes": {"X": 1600.0, "Y": 900.0, "Z": 0.0, "E": 0.0}}