diff --git a/wasm-port/AGENTS.md b/wasm-port/AGENTS.md index d3efe0f..3ea1c96 100644 --- a/wasm-port/AGENTS.md +++ b/wasm-port/AGENTS.md @@ -19,6 +19,17 @@ Build a standalone CNC simulation system that: - does not drive real hardware; - preserves LinuxCNC software behavior as closely as practical. +## Current Direction + +The migration target is the LinuxCNC source program itself, adapted to run as +the standalone WASM simulation program. The project must not evolve a +project-authored interpreter, planner, or CNC semantics layer now that the +porting harness is running. + +Existing minimal runtime wrappers are migration probes only. They are allowed +to expose, compile, and validate vendored LinuxCNC code, but they must not be +expanded into a separate implementation of G-code behavior. + ## Repository Boundaries 1. `../linuxcnc/` is upstream and must be treated as read-only input for the @@ -33,21 +44,24 @@ Build a standalone CNC simulation system that: ## Engineering Rules 1. Reuse LinuxCNC source before reimplementing any CNC logic. -2. Prefer wrappers, shims, and extraction scripts over invasive source edits. -3. Preserve LinuxCNC semantics for: +2. Do not add new project-authored CNC semantics when LinuxCNC source exists. + Replace temporary wrapper behavior with direct calls into vendored LinuxCNC + source, or with the narrowest shims needed to make those calls compile. +3. Prefer wrappers, shims, and extraction scripts over invasive source edits. +4. Preserve LinuxCNC semantics for: - G-code execution; - modal state; - parameter and variable behavior; - kinematics; - planner behavior; - machine and controller state visible to software. -4. Replace only the native runtime edges: +5. Replace only the native runtime edges: - file IO; - process model; - HAL runtime; - IPC; - GUI. -5. Frontend code must be implemented with web technology, not migrated from +6. Frontend code must be implemented with web technology, not migrated from native GUI code. ## Required Layout diff --git a/wasm-port/SKILL.md b/wasm-port/SKILL.md index aeee40f..f901971 100644 --- a/wasm-port/SKILL.md +++ b/wasm-port/SKILL.md @@ -38,6 +38,8 @@ Use this skill when the work involves any of the following: 4. Native runtime dependencies are replaced at the edges, not copied whole. 5. Machine state and controller-visible behavior are first-class compatibility targets, not optional nice-to-haves. +6. Do not continue building a project-authored CNC program once the porting + harness runs; move behavior back to vendored LinuxCNC source functions. ## Source Reuse Priorities @@ -96,6 +98,16 @@ Preferred order of work: 6. Build the WASM export layer second. 7. Build the JS SDK and HTML frontend last. +Current migration emphasis: + +- Treat `linuxcnc_interp_minimal_runtime.cpp` as a temporary probe surface. +- Retire hand-written `convert_g()` behavior by linking and calling vendored + LinuxCNC interpreter conversion code. +- Add shims only for host/runtime edges that prevent vendored LinuxCNC source + from compiling. +- Do not add new G-code behavior in JavaScript or in standalone C++ wrappers + except as a short-lived adapter around LinuxCNC code. + ## Filesystem And Browser Guidance For browser use: diff --git a/wasm-port/docs/porting-steps-standalone.md b/wasm-port/docs/porting-steps-standalone.md index 4492279..d500f7b 100644 --- a/wasm-port/docs/porting-steps-standalone.md +++ b/wasm-port/docs/porting-steps-standalone.md @@ -371,7 +371,18 @@ Current verified progress: `interp_convert.cc::convert_straight()` and `rs274ngc_return.hh::NCE_CANNOT_DO_G1_WITH_ZERO_FEED_RATE`. - This proves the current extracted interpreter slice can parse and execute a - simple traverse and feed move through a standalone canonical event sink. + small fixture set through a standalone canonical event sink. +- Important direction change: the minimal wrapper behavior is a migration + probe, not the program body. Do not expand it into a separate CNC + implementation. The next work must retire hand-written wrapper semantics and + move execution through vendored LinuxCNC interpreter source such as + `interp_convert.cc`, `interp_read.cc`, `interp_check.cc`, and + `interp_execute.cc`. +- `tools/build_native_probes.sh` now includes + `linuxcnc_interp_convert_source_probe`, which directly compiles vendored + `interp_convert.cc`. The required `emcStatus` shim is limited to the native + status boundary used by `tag_arc()` for machine units; it is not a + project-authored CNC behavior implementation. ## Phase 4: Port INI Parsing Without Editing Upstream @@ -670,9 +681,11 @@ Keep these documents under `wasm-port/docs/`: Continue expanding the standalone interpreter core from the verified minimal traverse path: -1. replace the temporary minimal `convert_g()` implementation with thin - wrappers around more vendored interpreter conversion code, -2. add `_x`/`_y`/`_z` named parameter fixture coverage and align it with - `#5420`/`#5421`/`#5422`, -3. keep all source changes inside `wasm-port/` and leave `../linuxcnc/` +1. replace the temporary minimal `convert_g()` implementation with calls into + vendored LinuxCNC interpreter conversion code. +2. identify and shim the native runtime symbols blocking direct compilation of + `interp_convert.cc`, `interp_execute.cc`, and related interpreter files. +3. keep fixture coverage as regression protection while deleting temporary + hand-written semantics. +4. keep all source changes inside `wasm-port/` and leave `../linuxcnc/` read-only. diff --git a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_probe.cpp b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_probe.cpp new file mode 100644 index 0000000..3b56762 --- /dev/null +++ b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_probe.cpp @@ -0,0 +1,4 @@ +#include "nml_intf/emc.hh" + +static EMC_STAT standalone_emc_status; +EMC_STAT *emcStatus = &standalone_emc_status; diff --git a/wasm-port/runtime/core/shims/nml_intf/emc.hh b/wasm-port/runtime/core/shims/nml_intf/emc.hh index bb770fa..78caaaf 100644 --- a/wasm-port/runtime/core/shims/nml_intf/emc.hh +++ b/wasm-port/runtime/core/shims/nml_intf/emc.hh @@ -1,7 +1,18 @@ #pragma once -// Minimal shim for the standalone INI parser build. +// Minimal shim for standalone interpreter source probes. enum EmcJointType : int { EMC_LINEAR = 1, EMC_ANGULAR = 2, }; + +class EMC_STAT { +public: + struct Motion { + struct Traj { + double linearUnits = 1.0; + } traj; + } motion; +}; + +extern EMC_STAT *emcStatus; diff --git a/wasm-port/tests/native/verify_native_probes.sh b/wasm-port/tests/native/verify_native_probes.sh index 14a0e50..5f6ba40 100755 --- a/wasm-port/tests/native/verify_native_probes.sh +++ b/wasm-port/tests/native/verify_native_probes.sh @@ -35,6 +35,7 @@ check_exitcode linuxcnc_namedparam_harness check_exitcode linuxcnc_interp_minimal_harness check_exitcode linuxcnc_interp_minimal_harness.run check_exitcode linuxcnc_rs274_compile_probe +check_exitcode linuxcnc_interp_convert_source_probe check_fixture_output() { local fixture="$1" diff --git a/wasm-port/tools/build_native_probes.sh b/wasm-port/tools/build_native_probes.sh index 4916915..c8d8ae1 100755 --- a/wasm-port/tools/build_native_probes.sh +++ b/wasm-port/tools/build_native_probes.sh @@ -31,7 +31,11 @@ rm -f \ "$BUILD_DIR/linuxcnc_rs274_compile_probe.o" \ "$BUILD_DIR/linuxcnc_rs274_compile_probe.exitcode" \ "$BUILD_DIR/linuxcnc_rs274_compile_probe.stdout.log" \ - "$BUILD_DIR/linuxcnc_rs274_compile_probe.stderr.log" + "$BUILD_DIR/linuxcnc_rs274_compile_probe.stderr.log" \ + "$BUILD_DIR/linuxcnc_interp_convert_source_probe.o" \ + "$BUILD_DIR/linuxcnc_interp_convert_source_probe.exitcode" \ + "$BUILD_DIR/linuxcnc_interp_convert_source_probe.stdout.log" \ + "$BUILD_DIR/linuxcnc_interp_convert_source_probe.stderr.log" g++ -std=c++20 -O2 \ -D_GNU_SOURCE \ @@ -160,4 +164,26 @@ RS274_RC=$? set -e echo "$RS274_RC" > "$BUILD_DIR/linuxcnc_rs274_compile_probe.exitcode" + +set +e +g++ -std=c++20 -O2 \ + -D_GNU_SOURCE \ + -DM_PI=3.14159265358979323846 \ + -DOBJECT_FWD_DWA2002724_HPP \ + -I"$SHIM_DIR" \ + -I"$INCLUDE_DIR" \ + -I"$VENDOR_DIR/src" \ + -I"$VENDOR_DIR/src/rtapi" \ + -I"$VENDOR_DIR/src/emc" \ + -I"$VENDOR_DIR/src/emc/nml_intf" \ + -I"$VENDOR_DIR/src/emc/motion" \ + -I"$VENDOR_DIR/src/libnml/posemath" \ + -c "$VENDOR_DIR/src/emc/rs274ngc/interp_convert.cc" \ + -o "$BUILD_DIR/linuxcnc_interp_convert_source_probe.o" \ + >"$BUILD_DIR/linuxcnc_interp_convert_source_probe.stdout.log" \ + 2>"$BUILD_DIR/linuxcnc_interp_convert_source_probe.stderr.log" +CONVERT_SOURCE_RC=$? +set -e + +echo "$CONVERT_SOURCE_RC" > "$BUILD_DIR/linuxcnc_interp_convert_source_probe.exitcode" echo "native probes complete"