按规划继续工作

结论:新增命名参数直接查找的 WASM 和浏览器验证,继续通过 vendored LinuxCNC find_named_param 路径覆盖 INI/HAL 边界。
This commit is contained in:
2026-06-08 11:31:13 +08:00
parent d2d0ce8bc1
commit b0250b66e6
8 changed files with 139 additions and 13 deletions

View File

@@ -94,6 +94,10 @@ tool slot status synchronization already covered by the native init harness.
It also calls the vendored single-axis rotary indexer path through
`Interp::execute()` to validate the `UNLOCK_ROTARY`/`LOCK_ROTARY` canonical
runtime boundary already covered by the native indexer harness.
It also calls vendored `Interp::init_named_parameters()` and
`Interp::find_named_param()` through the WASM C ABI to validate the native
named-parameter harness path for LinuxCNC built-in, INI-backed, HAL-backed,
and missing named-parameter lookup.
It also writes selected G-code fixtures into the
Emscripten filesystem through the SDK and runs them through LinuxCNC
`Interp::open()`, `Interp::read()`, and `Interp::execute()` to validate the
@@ -146,7 +150,10 @@ error text plus absent canonical motion output. It also validates vendored
`Interp::init()` and `Interp::synch()` through the same SDK/C ABI path,
including initialization canonical events, metric/inch machine units, and tool
slot readback, and checks the vendored rotary-indexer `G0 A...` execution path
for `UNLOCK_ROTARY`/`LOCK_ROTARY` boundary events. It also uses real browser OPFS
for `UNLOCK_ROTARY`/`LOCK_ROTARY` boundary events. It also validates
`Interp::init_named_parameters()` and `Interp::find_named_param()` through the
same browser SDK/C ABI path for built-in, INI-backed, HAL-backed, and missing
named-parameter lookup. It also uses real browser OPFS
storage plus the interpreter SDK to restore and save a LinuxCNC parameter file
through vendored `Interp::restore_parameters()` and `Interp::save_parameters()`,
and directly checks missing-file success plus out-of-order parameter-file
@@ -297,7 +304,9 @@ Node WASM and browser interpreter smokes now validate the exported
metric/inch `emcStatus` machine-unit conversion, and current/selected tool
slot synchronization. They also validate the exported rotary-indexer probe for
vendored LinuxCNC `UNLOCK_ROTARY`/`LOCK_ROTARY` dispatch around a single-axis
`G0 A...` move.
`G0 A...` move, plus the exported named-parameter probe for direct LinuxCNC
`init_named_parameters()` and `find_named_param()` lookup of built-in,
INI-backed, HAL-backed, and missing named parameters.
OPFS validation covers the JavaScript host-boundary adapter, the INI browser
smoke harness, the INI panel UI's machine-session load and G-code run buttons,
the raw canonical-event display fed directly by LinuxCNC interpreter WASM

View File

@@ -23,8 +23,8 @@ semantic rewrites:
| Boundary | Standalone treatment |
| --- | --- |
| RTAPI | Minimal compatibility shim in `runtime/core/shims/rtapi.h`. |
| HAL lookup | Standalone HAL adapter for `_hal[...]` named parameter reads. |
| INI lookup | Standalone INI adapter around vendored LinuxCNC INI parser behavior, including boolean conversion through LinuxCNC `iniFindBool()` and string lookup for INI-declared `[RS274NGC]PARAMETER_FILE` and `[EMCIO]TOOL_TABLE` machine file names. |
| HAL lookup | Standalone HAL adapter for `_hal[...]` named parameter reads; native, Node WASM, and browser interpreter smokes validate lookup through vendored `Interp::find_named_param()`. |
| INI lookup | Standalone INI adapter around vendored LinuxCNC INI parser behavior, including boolean conversion through LinuxCNC `iniFindBool()` and string lookup for INI-declared `[RS274NGC]PARAMETER_FILE` and `[EMCIO]TOOL_TABLE` machine file names; native, Node WASM, and browser interpreter smokes validate `_ini[...]` lookup through vendored `Interp::find_named_param()`. |
| Canonical output | Canonical calls are captured as test events instead of driving hardware. |
| Feed-rate state | `SET_FEED_RATE` updates standalone canonical runtime state so vendored `convert_length_units()` can read it back through `GET_EXTERNAL_FEED_RATE()` during G20/G21 changes. |
| Tool-data reload | LinuxCNC `RELOAD_TOOLDATA` is captured as a canonical test event; browser/native tool-table reload plumbing remains a future host/runtime adapter. |

View File

@@ -46,7 +46,7 @@ Current validation is intentionally mechanical:
| Posemath | `src/libnml/posemath/posemath.cc`, `_posemath.c`, `gomath.c`, `sincos.c`, and matching headers | Copy unchanged | `gomath.c` is compiled as C; `rtapi.h` shim is C/C++ compatible for this boundary | Vendor byte sync, per-file source probes, TP probe |
| RS274 interpreter state and parser | `src/emc/rs274ngc/modal_state.*`, `interp_internal.*`, `interp_read.cc`, `interp_check.cc`, `interp_execute.cc`, `interp_find.cc`, `interp_array.cc`, `interp_queue.*`, `rs274ngc*`, `units.h` | Copy unchanged | Python/remap/runtime edges are isolated in standalone wrappers and shims; parser and execution logic remain LinuxCNC source | Vendor byte sync, per-file source probes, interpreter harness fixtures |
| RS274 conversion semantics | `src/emc/rs274ngc/interp_convert.cc`, `interp_arc.cc`, `interp_inverse.cc`, `interp_cycles.cc`, `interp_g7x.cc`, `interp_o_word.cc`, `interp_write.cc` | Copy unchanged | Canonical calls are captured by standalone event sink functions; conversion behavior stays in vendored LinuxCNC files; feed-rate state is read back through the canonical runtime boundary during length-unit conversion; single-axis rotary indexer lock/unlock dispatch remains vendored LinuxCNC `issue_straight_index()` behavior | Vendor byte sync, per-file source probes, canonical fixture suite, no standalone `Interp::convert_g()` guard, `linuxcnc_indexer_harness`, `tests/wasm/node/verify_interp_wasm.sh` and `tests/browser/verify_interp_browser.sh` rotary-indexer assertions |
| Named parameters and tool slot status | `src/emc/rs274ngc/interp_namedparams.cc`, related interpreter headers | Copy unchanged | `_ini[...]` and `_hal[...]` resolve through standalone INI/HAL adapters while lookup order stays LinuxCNC-derived; current/selected tool slot reads for vendored `Interp::synch()` come from the standalone tool adapter | Vendor byte sync, source probe, `linuxcnc_namedparam_harness`, `linuxcnc_interp_init_harness`, `tests/wasm/node/verify_interp_wasm.sh` and `tests/browser/verify_interp_browser.sh` `Interp::synch()` tool-slot assertions |
| Named parameters and tool slot status | `src/emc/rs274ngc/interp_namedparams.cc`, related interpreter headers | Copy unchanged | `_ini[...]` and `_hal[...]` resolve through standalone INI/HAL adapters while lookup order stays LinuxCNC-derived; current/selected tool slot reads for vendored `Interp::synch()` come from the standalone tool adapter | Vendor byte sync, source probe, `linuxcnc_namedparam_harness`, `linuxcnc_interp_init_harness`, `tests/wasm/node/verify_interp_wasm.sh` and `tests/browser/verify_interp_browser.sh` `Interp::synch()` tool-slot assertions plus `Interp::init_named_parameters()`/`find_named_param()` named-parameter lookup assertions |
| Tool table parsing and formatting | `src/emc/tooldata/tooldata_common.cc` | Copy unchanged plus standalone storage callbacks | Native file parsing/formatting stays in vendored LinuxCNC source; the standalone tool adapter supplies `tooldata_get()`/`tooldata_put()` storage and index lookup, the WASM boundary only selects the LinuxCNC non-random or random-toolchanger branch via `tooldata_init()`, and OPFS remains a host-side persistence boundary | Vendor byte sync, `linuxcnc_tooldata_common_source_probe`, `tests/wasm/node/verify_interp_wasm.sh` non-random/random load/save tool-table assertions |
| Dynamic interpreter base | `src/emc/rs274ngc/interp_base.*` | Copy unchanged | `interp_base.cc` source probe uses standalone `EMC2_HOME` compile-time path boundary for LinuxCNC dynamic interpreter lookup | Vendor byte sync, `linuxcnc_interp_base_source_probe` |

View File

@@ -212,6 +212,14 @@ void append_error_text(std::ostringstream &output, Interp &interp, const char *p
}
}
void append_named_value(std::ostringstream &output, Interp &interp, const char *name)
{
int status = 0;
double value = 0.0;
const int rc = interp.find_named_param(name, &status, &value);
output << name << ": rc=" << rc << " found=" << status << " value=" << value << "\n";
}
void apply_parameter_assignments(Interp &interp, const char *assignments)
{
std::istringstream input(assignments ? assignments : "");
@@ -485,6 +493,59 @@ char *lcinterp_probe_indexer()
return copy_result(output.str());
}
EMSCRIPTEN_KEEPALIVE
char *lcinterp_probe_named_parameters(const char *ini_path)
{
if (ini_path && ini_path[0] != '\0') {
setenv("INI_FILE_NAME", ini_path, 1);
} else {
unsetenv("INI_FILE_NAME");
}
Interp interp;
seed_hal_values();
interp._setup.feature_set = FEATURE_INI_VARS | FEATURE_HAL_PIN_VARS;
interp._setup.length_units = CANON_UNITS_MM;
interp._setup.distance_mode = DISTANCE_MODE::ABSOLUTE;
interp._setup.motion_mode = G_1;
interp._setup.feed_rate = 123.45;
interp._setup.speed[0] = 678.9;
interp._setup.current_x = 1.25;
interp._setup.current_y = 2.5;
interp._setup.current_z = 3.75;
interp._setup.parameters[interp_param_global::TOOL_NUMBER] = 12.0;
std::ostringstream output;
const int rc = interp.init_named_parameters();
output << "init_named_parameters=" << rc << "\n";
output << "global_named_count=" << interp._setup.sub_context[0].named_params.size() << "\n";
output << "required_parameter_first=" << interp_param_global::G28_X << "\n";
output << "readonly_tool_number_index=" << interp_param_global::TOOL_NUMBER << "\n";
append_named_value(output, interp, "_vmajor");
append_named_value(output, interp, "_vminor");
append_named_value(output, interp, "_metric_machine");
append_named_value(output, interp, "_motion_mode");
append_named_value(output, interp, "_metric");
append_named_value(output, interp, "_feed");
append_named_value(output, interp, "_rpm");
append_named_value(output, interp, "_x");
append_named_value(output, interp, "_current_tool");
append_named_value(output, interp, "_ini[traj]max_linear_velocity");
append_named_value(output, interp, "_hal[standalone.pin-bit]");
append_named_value(output, interp, "_hal[standalone.signal-float]");
append_named_value(output, interp, "_hal[standalone.param-s32]");
append_named_value(output, interp, "_hal[standalone.pin-u32]");
append_named_value(output, interp, "_hal[standalone.signal-s64]");
append_named_value(output, interp, "_hal[standalone.param-u64]");
append_named_value(output, interp, "_hal[standalone.disconnected-float]");
append_named_value(output, interp, "_hal[standalone.missing]");
unsetenv("INI_FILE_NAME");
standalone::reset_hal_adapter();
return copy_result(output.str());
}
EMSCRIPTEN_KEEPALIVE
void lcinterp_free_string(char *value)
{

View File

@@ -103,5 +103,9 @@ export async function createLinuxCncInterpSdk(moduleOptions = {}) {
probeIndexer() {
return callStringResult(mod, "lcinterp_probe_indexer");
},
probeNamedParameters(iniPath) {
return callStringResult(mod, "lcinterp_probe_named_parameters", iniPath);
},
};
}

View File

@@ -128,6 +128,9 @@
},
});
const namedParamIniPath = "/work/namedparams.ini";
interp.writeTextFile(namedParamIniPath, await fetchText("../fixtures/ini/namedparams.ini"));
verifyExpectedOutput(
"probe_init_and_synch",
interp.probeInitAndSynch(),
@@ -172,6 +175,31 @@
].join("\n"),
);
verifyExpectedOutput(
"probe_named_parameters",
interp.probeNamedParameters(namedParamIniPath),
[
"init_named_parameters=0",
"global_named_count=57",
"_metric_machine: rc=0 found=1 value=1",
"_motion_mode: rc=0 found=1 value=10",
"_metric: rc=0 found=1 value=1",
"_feed: rc=0 found=1 value=123.45",
"_rpm: rc=0 found=1 value=678.9",
"_x: rc=0 found=1 value=1.25",
"_current_tool: rc=0 found=1 value=12",
"_ini[traj]max_linear_velocity: rc=0 found=1 value=35",
"_hal[standalone.pin-bit]: rc=0 found=1 value=1",
"_hal[standalone.signal-float]: rc=0 found=1 value=98.25",
"_hal[standalone.param-s32]: rc=0 found=1 value=-17",
"_hal[standalone.pin-u32]: rc=0 found=1 value=1.23457e+08",
"_hal[standalone.signal-s64]: rc=0 found=1 value=-9e+09",
"_hal[standalone.param-u64]: rc=0 found=1 value=9e+09",
"_hal[standalone.disconnected-float]: rc=0 found=1 value=12.5",
"_hal[standalone.missing]: rc=0 found=0 value=0",
].join("\n"),
);
for (const fixtureName of INTERP_BROWSER_MDI_FIXTURES) {
const programText = await fetchText(`../fixtures/gcode/${fixtureName}.ngc`);
const expectedText = await fetchText(`../fixtures/canon/${fixtureName}.events`);
@@ -199,14 +227,12 @@
);
}
const namedParamIniPath = "/work/namedparams.ini";
const namedParamProgramText = await fetchText(
`../fixtures/gcode/${INTERP_INI_FIXTURE}.ngc`,
);
const namedParamExpectedText = (
await fetchText(`../fixtures/canon/${INTERP_INI_FIXTURE}.events`)
).trimEnd();
interp.writeTextFile(namedParamIniPath, await fetchText("../fixtures/ini/namedparams.ini"));
verifyExpectedOutput(
INTERP_INI_FIXTURE,
interp.runProgramWithIni(namedParamProgramText, namedParamIniPath),

View File

@@ -86,6 +86,12 @@ const interp = await createLinuxCncInterpSdk({
},
});
const namedParamIniPath = "/work/namedparams.ini";
interp.writeTextFile(
namedParamIniPath,
readFileSync(resolve(rootDir, "tests/fixtures/ini/namedparams.ini"), "utf8"),
);
verifyExpectedOutput(
"probe_init_and_synch",
interp.probeInitAndSynch(),
@@ -130,6 +136,31 @@ verifyExpectedOutput(
].join("\n"),
);
verifyExpectedOutput(
"probe_named_parameters",
interp.probeNamedParameters(namedParamIniPath),
[
"init_named_parameters=0",
"global_named_count=57",
"_metric_machine: rc=0 found=1 value=1",
"_motion_mode: rc=0 found=1 value=10",
"_metric: rc=0 found=1 value=1",
"_feed: rc=0 found=1 value=123.45",
"_rpm: rc=0 found=1 value=678.9",
"_x: rc=0 found=1 value=1.25",
"_current_tool: rc=0 found=1 value=12",
"_ini[traj]max_linear_velocity: rc=0 found=1 value=35",
"_hal[standalone.pin-bit]: rc=0 found=1 value=1",
"_hal[standalone.signal-float]: rc=0 found=1 value=98.25",
"_hal[standalone.param-s32]: rc=0 found=1 value=-17",
"_hal[standalone.pin-u32]: rc=0 found=1 value=1.23457e+08",
"_hal[standalone.signal-s64]: rc=0 found=1 value=-9e+09",
"_hal[standalone.param-u64]: rc=0 found=1 value=9e+09",
"_hal[standalone.disconnected-float]: rc=0 found=1 value=12.5",
"_hal[standalone.missing]: rc=0 found=0 value=0",
].join("\n"),
);
for (const fixtureName of INTERP_MDI_FIXTURES) {
const programText = readFileSync(
resolve(rootDir, `tests/fixtures/gcode/${fixtureName}.ngc`),
@@ -143,11 +174,6 @@ for (const fixtureName of INTERP_MDI_FIXTURES) {
verifyExpectedOutput(fixtureName, interp.runProgram(programText), expectedEvents);
}
const namedParamIniPath = "/work/namedparams.ini";
interp.writeTextFile(
namedParamIniPath,
readFileSync(resolve(rootDir, "tests/fixtures/ini/namedparams.ini"), "utf8"),
);
const namedParamProgramText = readFileSync(
resolve(rootDir, `tests/fixtures/gcode/${INTERP_INI_FIXTURE}.ngc`),
"utf8",

View File

@@ -96,5 +96,5 @@ link_wasm_module \
-s STACK_SIZE=2MB \
-s NO_EXIT_RUNTIME=1 \
-s FORCE_FILESYSTEM=1 \
-s EXPORTED_FUNCTIONS='["_malloc","_free","_lcinterp_run_program","_lcinterp_run_program_with_ini","_lcinterp_run_file","_lcinterp_run_file_with_ini","_lcinterp_restore_parameters","_lcinterp_save_parameters","_lcinterp_load_tool_table","_lcinterp_load_tool_table_random","_lcinterp_save_tool_table","_lcinterp_probe_init_and_synch","_lcinterp_probe_indexer","_lcinterp_free_string"]' \
-s EXPORTED_FUNCTIONS='["_malloc","_free","_lcinterp_run_program","_lcinterp_run_program_with_ini","_lcinterp_run_file","_lcinterp_run_file_with_ini","_lcinterp_restore_parameters","_lcinterp_save_parameters","_lcinterp_load_tool_table","_lcinterp_load_tool_table_random","_lcinterp_save_tool_table","_lcinterp_probe_init_and_synch","_lcinterp_probe_indexer","_lcinterp_probe_named_parameters","_lcinterp_free_string"]' \
-s EXPORTED_RUNTIME_METHODS='["FS","UTF8ToString","stringToUTF8","lengthBytesUTF8"]'