#ifndef LINUXCNC_WEB_WASM_SIM_PROGRAM_H #define LINUXCNC_WEB_WASM_SIM_PROGRAM_H #include "sim_interpreter.h" #ifdef __cplusplus extern "C" { #endif #define SIM_PROGRAM_SOURCE_CAPACITY 524288u #define SIM_PROGRAM_LINE_CAPACITY 16384u #define SIM_PROGRAM_MAX_SOURCE_BYTES (64u * 1024u * 1024u) #define SIM_PROGRAM_MAX_LINE_COUNT 1048576u #define SIM_PROGRAM_CANONICAL_CAPACITY 4096u #define SIM_PROGRAM_SUBROUTINE_CAPACITY 16u #define SIM_PROGRAM_SUBROUTINE_NAME_CAPACITY 48u #define SIM_PROGRAM_CALL_DEPTH 8u #define SIM_PROGRAM_CALL_PARAMETER_CAPACITY 30u enum sim_program_result { SIM_PROGRAM_OK = 0, SIM_PROGRAM_ERR_ARGUMENT = -1100, SIM_PROGRAM_ERR_RANGE = -1101, SIM_PROGRAM_ERR_STATE = -1102, SIM_PROGRAM_ERR_CONTROL = -1103, SIM_PROGRAM_ERR_BUFFER = -1104, SIM_PROGRAM_ERR_INTERPRETER = -1105, }; enum sim_program_status { SIM_PROGRAM_IDLE = 0, SIM_PROGRAM_LOADED = 1, SIM_PROGRAM_RUNNING = 2, SIM_PROGRAM_PAUSED = 3, SIM_PROGRAM_COMPLETED = 4, SIM_PROGRAM_ABORTED = 5, SIM_PROGRAM_ERROR = 6, }; enum sim_program_motion_control { SIM_PROGRAM_MOTION_CONTINUOUS = 0, SIM_PROGRAM_MOTION_EXACT_PATH = 1, SIM_PROGRAM_MOTION_EXACT_STOP = 2, }; typedef struct sim_program_subroutine { char name[SIM_PROGRAM_SUBROUTINE_NAME_CAPACITY]; uint32_t body_line; uint32_t end_line; } sim_program_subroutine; typedef struct sim_program_call_frame { uint32_t return_line; double parameters[SIM_PROGRAM_CALL_PARAMETER_CAPACITY]; } sim_program_call_frame; typedef struct sim_program { sim_interpreter interpreter; char *source; uint32_t *line_offsets; uint32_t source_capacity; uint32_t line_capacity; uint32_t source_length; uint32_t line_count; uint32_t main_line_count; uint32_t current_line; uint32_t status; int32_t last_error; uint32_t error_line; sim_posemath_segment motion; uint32_t has_motion; sim_program_subroutine subroutines[SIM_PROGRAM_SUBROUTINE_CAPACITY]; uint32_t subroutine_count; sim_program_call_frame call_stack[SIM_PROGRAM_CALL_DEPTH]; uint32_t call_depth; uint32_t has_control; int32_t control_code; double rapid_velocity; int motion_control_mode; double path_tolerance; double naive_cam_tolerance; uint32_t pause_from; } sim_program; uint32_t sim_program_size(void); uint32_t sim_program_checkpoint_size(void); int32_t sim_program_checkpoint_export(const sim_program *program, uint8_t *output, uint32_t capacity); int32_t sim_program_checkpoint_restore(sim_program *program, const uint8_t *input, uint32_t length); int32_t sim_program_requires_subroutines(const char *source, uint32_t length); int32_t sim_program_init(sim_program *program); int32_t sim_program_reset(sim_program *program); void sim_program_destroy(sim_program *program); int32_t sim_program_load(sim_program *program, const char *source, uint32_t length); int32_t sim_program_add_subroutine(sim_program *program, const char *source, uint32_t length); int32_t sim_program_set_rapid_velocity(sim_program *program, double velocity); int32_t sim_program_set_position(sim_program *program, const sim_posemath_pose *position); int32_t sim_program_start(sim_program *program); int32_t sim_program_pause(sim_program *program); int32_t sim_program_resume(sim_program *program); int32_t sim_program_abort(sim_program *program); int32_t sim_program_step(sim_program *program); int32_t sim_program_execute_block(sim_program *program, const char *block, uint32_t length); int32_t sim_program_seek(sim_program *program, uint32_t line); int32_t sim_program_read_motion(const sim_program *program, sim_posemath_segment *segment); int32_t sim_program_clear_motion(sim_program *program); uint32_t sim_program_canonical(const sim_program *program, char *output, uint32_t capacity); uint64_t sim_program_state_hash(const sim_program *program); #ifdef __cplusplus } #endif #endif