Run XYZAC through upstream LinuxCNC TP
This commit is contained in:
@@ -76,6 +76,7 @@ export class WasmProgramRuntime {
|
||||
this.subroutines = [];
|
||||
this.executionSource = "";
|
||||
this.executionLines = [];
|
||||
this.executionLineMetadata = [];
|
||||
this.rapidVelocity = 35;
|
||||
if (!this.available || typeof core?._malloc !== "function") return;
|
||||
this.pointer = core._malloc(call(core, "sim_program_size", "number", [], []));
|
||||
@@ -108,6 +109,11 @@ export class WasmProgramRuntime {
|
||||
this.subroutines = [];
|
||||
this.executionSource = source;
|
||||
this.executionLines = source.split(/\r?\n/);
|
||||
this.executionLineMetadata = this.executionLines.map((_, index) => ({ path: this.path, line: index + 1 }));
|
||||
while (this.executionLines.length && this.executionLines.at(-1) === "") {
|
||||
this.executionLines.pop();
|
||||
this.executionLineMetadata.pop();
|
||||
}
|
||||
return { status: "verified", program: this.snapshot() };
|
||||
} finally { this.core._free(pointer); }
|
||||
}
|
||||
@@ -133,7 +139,7 @@ export class WasmProgramRuntime {
|
||||
if (loaded.status !== "verified") return loaded;
|
||||
temporary.setRapidVelocity(this.rapidVelocity);
|
||||
for (const subroutine of this.subroutines) {
|
||||
const added = temporary.addSubroutine(subroutine.name, subroutine.source);
|
||||
const added = temporary.addSubroutine(subroutine.name, subroutine.source, subroutine.path);
|
||||
if (added.status !== "verified") return added;
|
||||
}
|
||||
const started = temporary.start();
|
||||
@@ -159,7 +165,7 @@ export class WasmProgramRuntime {
|
||||
if (result !== 0) throw new Error(`wasm_program_set_rapid_velocity_${result}`);
|
||||
return { status: "verified", command: "sim_program_set_rapid_velocity" };
|
||||
}
|
||||
addSubroutine(name, source) {
|
||||
addSubroutine(name, source, path = null) {
|
||||
if (typeof source !== "string" || source.length === 0) return { status: "error", code: "program_subroutine_invalid" };
|
||||
const bytes = new TextEncoder().encode(source);
|
||||
const pointer = this.core._malloc(bytes.byteLength);
|
||||
@@ -167,12 +173,19 @@ export class WasmProgramRuntime {
|
||||
try {
|
||||
const code = call(this.core, "sim_program_add_subroutine", "number", ["number", "number", "number"], [this.pointer, pointer, bytes.byteLength]);
|
||||
if (code !== 0) return { status: "error", code: `wasm_program_add_subroutine_${code}`, result: code };
|
||||
this.subroutines.push({ name: String(name ?? "subroutine"), source });
|
||||
if (this.executionSource && !this.executionSource.endsWith("\n")) this.executionSource += "\n";
|
||||
if (this.executionLines.length && this.executionLines.at(-1) !== "") this.executionLines.push("");
|
||||
if (this.executionLines.length && this.executionLines.at(-1) !== "") {
|
||||
this.executionLines.push("");
|
||||
this.executionLineMetadata.push({ path: null, line: 0 });
|
||||
}
|
||||
this.executionSource += source;
|
||||
if (this.executionLines.length && this.executionLines.at(-1) === "") this.executionLines.pop();
|
||||
if (this.executionLines.length && this.executionLines.at(-1) === "") {
|
||||
this.executionLines.pop();
|
||||
this.executionLineMetadata.pop();
|
||||
}
|
||||
this.executionLines.push(...source.split(/\r?\n/));
|
||||
this.executionLineMetadata.push(...source.split(/\r?\n/).map((_, index) => ({ path, line: index + 1 })));
|
||||
this.subroutines.push({ name: String(name ?? "subroutine"), path, source });
|
||||
return { status: "verified", command: "sim_program_add_subroutine", name: String(name ?? "subroutine") };
|
||||
} finally { this.core._free(pointer); }
|
||||
}
|
||||
@@ -268,7 +281,8 @@ export class WasmProgramRuntime {
|
||||
const programStatus = { 0: "idle", 1: "loaded", 2: "running", 3: "paused", 4: "completed", 5: "aborted", 6: "fault" }[state.status] ?? "idle";
|
||||
const motionControl = { 0: "continuous", 1: "exact_path", 2: "exact_stop" }[state.motion_control_mode] ?? "continuous";
|
||||
const executionLineText = state.current_line > 0 ? (this.executionLines[state.current_line - 1] ?? "").trim() : "";
|
||||
return { schema: SCHEMA, source: "linuxcnc-wasm-sim_program", ...state, motion_control: { mode: motionControl, path_tolerance: Number(state.path_tolerance ?? 0), naive_cam_tolerance: Number(state.naive_cam_tolerance ?? 0) }, active_gcodes: activeGcodes(state), loaded: state.status !== 0, line: state.current_line, currentLine: state.current_line, execution_line: state.current_line, execution_line_text: executionLineText, program_status: programStatus, path: this.path, subroutines: this.subroutines.map((subroutine) => subroutine.name), state_hash: `fnv1a64:${BigInt.asUintN(64, BigInt(hash >>> 0)).toString(16).padStart(16, "0")}`, source_hash: this.source ? fnv1a64(this.source) : null };
|
||||
const executionMeta = state.current_line > 0 ? (this.executionLineMetadata[state.current_line - 1] ?? { path: this.path, line: state.current_line }) : { path: this.path, line: 0 };
|
||||
return { schema: SCHEMA, source: "linuxcnc-wasm-sim_program", ...state, motion_control: { mode: motionControl, path_tolerance: Number(state.path_tolerance ?? 0), naive_cam_tolerance: Number(state.naive_cam_tolerance ?? 0) }, active_gcodes: activeGcodes(state), loaded: state.status !== 0, line: state.current_line, currentLine: state.current_line, execution_line: state.current_line, execution_line_text: executionLineText, execution_source_file: executionMeta.path, execution_source_line: executionMeta.line, program_status: programStatus, path: this.path, subroutines: this.subroutines.map((subroutine) => subroutine.name), state_hash: `fnv1a64:${BigInt.asUintN(64, BigInt(hash >>> 0)).toString(16).padStart(16, "0")}`, source_hash: this.source ? fnv1a64(this.source) : null };
|
||||
} finally { this.core._free(buffer); }
|
||||
}
|
||||
|
||||
@@ -278,5 +292,6 @@ export class WasmProgramRuntime {
|
||||
this.pointer = this.motionPointer = this.samplePointer = this.samplePosePointer = 0;
|
||||
this.executionSource = "";
|
||||
this.executionLines = [];
|
||||
this.executionLineMetadata = [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user