| 1 | ! Trap dispatch module — breaks circular dependency between executor and ast_executor. |
| 2 | ! executor.f90 calls eval_trap_string() which delegates to the AST pipeline |
| 3 | ! registered by ast_executor at startup via set_trap_evaluator(). |
| 4 | module trap_dispatch |
| 5 | use shell_types |
| 6 | implicit none |
| 7 | private |
| 8 | public :: eval_trap_string, set_trap_evaluator |
| 9 | |
| 10 | abstract interface |
| 11 | subroutine trap_eval_iface(cmd_string, shell, exit_code) |
| 12 | import :: shell_state_t |
| 13 | character(len=*), intent(in) :: cmd_string |
| 14 | type(shell_state_t), intent(inout) :: shell |
| 15 | integer, intent(out) :: exit_code |
| 16 | end subroutine trap_eval_iface |
| 17 | end interface |
| 18 | |
| 19 | procedure(trap_eval_iface), pointer :: trap_evaluator => null() |
| 20 | |
| 21 | contains |
| 22 | |
| 23 | subroutine set_trap_evaluator(proc) |
| 24 | procedure(trap_eval_iface) :: proc |
| 25 | trap_evaluator => proc |
| 26 | end subroutine set_trap_evaluator |
| 27 | |
| 28 | subroutine eval_trap_string(cmd_string, shell, exit_code) |
| 29 | character(len=*), intent(in) :: cmd_string |
| 30 | type(shell_state_t), intent(inout) :: shell |
| 31 | integer, intent(out) :: exit_code |
| 32 | |
| 33 | exit_code = 0 |
| 34 | if (associated(trap_evaluator)) then |
| 35 | call trap_evaluator(cmd_string, shell, exit_code) |
| 36 | end if |
| 37 | end subroutine eval_trap_string |
| 38 | |
| 39 | end module trap_dispatch |
| 40 |