增加解释器WASM文件入口
结论:解释器核心WASM新增基于LinuxCNC Interp::open/read/execute的文件运行入口,并覆盖file_open_reset、percent_file_finish和oword_subroutine夹具。
This commit is contained in:
@@ -113,6 +113,19 @@ char *copy_result(const std::string &result)
|
||||
return out;
|
||||
}
|
||||
|
||||
void append_events_and_state(std::ostringstream &output, const Interp &interp)
|
||||
{
|
||||
for (const auto &event : standalone::canon_events()) {
|
||||
output << "canon_event=" << event << "\n";
|
||||
}
|
||||
output << "setup.current_x=" << interp._setup.current_x << "\n";
|
||||
output << "setup.current_y=" << interp._setup.current_y << "\n";
|
||||
output << "setup.current_z=" << interp._setup.current_z << "\n";
|
||||
output << "setup.parameter_5420=" << interp._setup.parameters[5420] << "\n";
|
||||
output << "setup.parameter_5421=" << interp._setup.parameters[5421] << "\n";
|
||||
output << "setup.parameter_5422=" << interp._setup.parameters[5422] << "\n";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
@@ -143,15 +156,71 @@ char *lcinterp_run_program(const char *program_text)
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &event : standalone::canon_events()) {
|
||||
output << "canon_event=" << event << "\n";
|
||||
append_events_and_state(output, interp);
|
||||
return copy_result(output.str());
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
char *lcinterp_run_file(const char *path)
|
||||
{
|
||||
Interp interp;
|
||||
standalone::reset_canon_events();
|
||||
initialize_minimal_interp(interp);
|
||||
|
||||
std::ostringstream output;
|
||||
const int open_rc = interp.open(path);
|
||||
output << "file_open=" << open_rc << "\n";
|
||||
if (open_rc != INTERP_OK) {
|
||||
if (open_rc > INTERP_MIN_ERROR) {
|
||||
char error_buf[LINELEN] = {0};
|
||||
interp.error_text(open_rc, error_buf, sizeof(error_buf));
|
||||
output << "file_error_text=" << error_buf << "\n";
|
||||
}
|
||||
append_events_and_state(output, interp);
|
||||
return copy_result(output.str());
|
||||
}
|
||||
output << "setup.current_x=" << interp._setup.current_x << "\n";
|
||||
output << "setup.current_y=" << interp._setup.current_y << "\n";
|
||||
output << "setup.current_z=" << interp._setup.current_z << "\n";
|
||||
output << "setup.parameter_5420=" << interp._setup.parameters[5420] << "\n";
|
||||
output << "setup.parameter_5421=" << interp._setup.parameters[5421] << "\n";
|
||||
output << "setup.parameter_5422=" << interp._setup.parameters[5422] << "\n";
|
||||
|
||||
int file_read_count = 0;
|
||||
int file_execute_count = 0;
|
||||
while (true) {
|
||||
const int read_rc = interp.read();
|
||||
if (read_rc == INTERP_ENDFILE) {
|
||||
output << "file_read_eof=" << read_rc << "\n";
|
||||
break;
|
||||
}
|
||||
|
||||
++file_read_count;
|
||||
output << "file_read_" << file_read_count << "=" << read_rc << "\n";
|
||||
if ((read_rc != INTERP_OK) && (read_rc != INTERP_EXECUTE_FINISH)) {
|
||||
if (read_rc > INTERP_MIN_ERROR) {
|
||||
char error_buf[LINELEN] = {0};
|
||||
interp.error_text(read_rc, error_buf, sizeof(error_buf));
|
||||
output << "file_error_text=" << error_buf << "\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
const int execute_rc = interp.execute();
|
||||
++file_execute_count;
|
||||
output << "file_execute_" << file_execute_count << "=" << execute_rc << "\n";
|
||||
if (execute_rc > INTERP_MIN_ERROR) {
|
||||
char error_buf[LINELEN] = {0};
|
||||
interp.error_text(execute_rc, error_buf, sizeof(error_buf));
|
||||
output << "file_error_text=" << error_buf << "\n";
|
||||
}
|
||||
if ((execute_rc != INTERP_OK) &&
|
||||
(execute_rc != INTERP_EXECUTE_FINISH) &&
|
||||
(execute_rc != INTERP_EXIT)) {
|
||||
break;
|
||||
}
|
||||
if (execute_rc == INTERP_EXIT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
output << "file_read_count=" << file_read_count << "\n";
|
||||
output << "file_execute_count=" << file_execute_count << "\n";
|
||||
append_events_and_state(output, interp);
|
||||
return copy_result(output.str());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user