|
| 1 | +/* |
| 2 | + Copyright 2018, 2020, 2021 Joel Svensson [email protected] |
| 3 | +
|
| 4 | + This program is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU General Public License as published by |
| 6 | + the Free Software Foundation, either version 3 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | +
|
| 9 | + This program is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +*/ |
| 17 | +#ifndef EVAL_CPS_H_ |
| 18 | +#define EVAL_CPS_H_ |
| 19 | + |
| 20 | +#include "stack.h" |
| 21 | +#include "lispbm_types.h" |
| 22 | + |
| 23 | +#define EVAL_CPS_STATE_INIT 0 |
| 24 | +#define EVAL_CPS_STATE_PAUSED 1 |
| 25 | +#define EVAL_CPS_STATE_RUNNING 2 |
| 26 | +#define EVAL_CPS_STATE_STEP 3 |
| 27 | +#define EVAL_CPS_STATE_KILL 4 |
| 28 | + |
| 29 | + |
| 30 | +typedef struct eval_context_s{ |
| 31 | + VALUE program; |
| 32 | + VALUE curr_exp; |
| 33 | + VALUE curr_env; |
| 34 | + VALUE mailbox; /*massage passing mailbox */ |
| 35 | + VALUE r; |
| 36 | + bool done; |
| 37 | + bool app_cont; |
| 38 | + stack K; |
| 39 | + /* Process control */ |
| 40 | + uint32_t timestamp; |
| 41 | + uint32_t sleep_us; |
| 42 | + CID id; |
| 43 | + /* List structure */ |
| 44 | + struct eval_context_s *prev; |
| 45 | + struct eval_context_s *next; |
| 46 | +} eval_context_t; |
| 47 | + |
| 48 | +typedef void (*ctx_fun)(eval_context_t *, void*, void*); |
| 49 | + |
| 50 | +/* Common interface */ |
| 51 | +extern VALUE eval_cps_get_env(void); |
| 52 | + |
| 53 | +/* Concurrent interface */ |
| 54 | +extern int eval_cps_init(void); |
| 55 | +extern bool eval_cps_remove_done_ctx(CID cid, VALUE *v); |
| 56 | +extern VALUE eval_cps_wait_ctx(CID cid); |
| 57 | +extern CID eval_cps_program(VALUE lisp); |
| 58 | +extern CID eval_cps_program_ext(VALUE lisp, unsigned int stack_size, bool grow_stack); |
| 59 | +extern void eval_cps_run_eval(void); |
| 60 | + |
| 61 | +extern void eval_cps_pause_eval(void); |
| 62 | +extern void eval_cps_step_eval(void); |
| 63 | +extern void eval_cps_continue_eval(void); |
| 64 | +extern void eval_cps_kill_eval(void); |
| 65 | +extern uint32_t eval_cps_current_state(void); |
| 66 | + |
| 67 | +/* statistics interface */ |
| 68 | +extern void eval_cps_running_iterator(ctx_fun f, void*, void*); |
| 69 | +extern void eval_cps_blocked_iterator(ctx_fun f, void*, void*); |
| 70 | +extern void eval_cps_done_iterator(ctx_fun f, void*, void*); |
| 71 | + |
| 72 | +/* |
| 73 | + Callback routines for sleeping and timestamp generation. |
| 74 | + Depending on target platform these will be implemented in different ways. |
| 75 | + Todo: It may become necessary to also add a mutex callback. |
| 76 | +*/ |
| 77 | +extern void eval_cps_set_usleep_callback(void (*fptr)(uint32_t)); |
| 78 | +extern void eval_cps_set_timestamp_us_callback(uint32_t (*fptr)(void)); |
| 79 | +extern void eval_cps_set_ctx_done_callback(void (*fptr)(eval_context_t *)); |
| 80 | + |
| 81 | +/* Non concurrent interface: */ |
| 82 | +extern int eval_cps_init_nc(unsigned int stack_size, bool grow_stack); |
| 83 | +extern void eval_cps_del_nc(void); |
| 84 | +extern VALUE eval_cps_program_nc(VALUE lisp); |
| 85 | +#endif |
0 commit comments