mbed I/F binding for mruby
Dependents: mruby_mbed_web mirb_mbed
mbed-mruby
How to use
Class
include/mruby/proc.h@1:8ccd1d494a4b, 2015-04-13 (annotated)
- Committer:
- mzta
- Date:
- Mon Apr 13 05:20:15 2015 +0000
- Revision:
- 1:8ccd1d494a4b
- Parent:
- 0:158c61bb030f
- code refactoring.; - add SPI, SPISlave, I2C class to mruby-mbed (Incomplete).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mzta | 0:158c61bb030f | 1 | /* |
mzta | 0:158c61bb030f | 2 | ** mruby/proc.h - Proc class |
mzta | 0:158c61bb030f | 3 | ** |
mzta | 0:158c61bb030f | 4 | ** See Copyright Notice in mruby.h |
mzta | 0:158c61bb030f | 5 | */ |
mzta | 0:158c61bb030f | 6 | |
mzta | 0:158c61bb030f | 7 | #ifndef MRUBY_PROC_H |
mzta | 0:158c61bb030f | 8 | #define MRUBY_PROC_H |
mzta | 0:158c61bb030f | 9 | |
mzta | 0:158c61bb030f | 10 | #include "mruby/irep.h" |
mzta | 0:158c61bb030f | 11 | |
mzta | 0:158c61bb030f | 12 | #if defined(__cplusplus) |
mzta | 0:158c61bb030f | 13 | extern "C" { |
mzta | 0:158c61bb030f | 14 | #endif |
mzta | 0:158c61bb030f | 15 | |
mzta | 0:158c61bb030f | 16 | struct REnv { |
mzta | 0:158c61bb030f | 17 | MRB_OBJECT_HEADER; |
mzta | 0:158c61bb030f | 18 | mrb_value *stack; |
mzta | 0:158c61bb030f | 19 | mrb_sym mid; |
mzta | 0:158c61bb030f | 20 | ptrdiff_t cioff; |
mzta | 0:158c61bb030f | 21 | }; |
mzta | 0:158c61bb030f | 22 | |
mzta | 0:158c61bb030f | 23 | #define MRB_SET_ENV_STACK_LEN(e,len) (e)->flags = (unsigned int)(len) |
mzta | 0:158c61bb030f | 24 | #define MRB_ENV_STACK_LEN(e) ((mrb_int)(e)->flags) |
mzta | 0:158c61bb030f | 25 | #define MRB_ENV_UNSHARE_STACK(e) ((e)->cioff = -1) |
mzta | 0:158c61bb030f | 26 | #define MRB_ENV_STACK_SHARED_P(e) ((e)->cioff >= 0) |
mzta | 0:158c61bb030f | 27 | |
mzta | 0:158c61bb030f | 28 | struct RProc { |
mzta | 0:158c61bb030f | 29 | MRB_OBJECT_HEADER; |
mzta | 0:158c61bb030f | 30 | union { |
mzta | 0:158c61bb030f | 31 | mrb_irep *irep; |
mzta | 0:158c61bb030f | 32 | mrb_func_t func; |
mzta | 0:158c61bb030f | 33 | } body; |
mzta | 0:158c61bb030f | 34 | struct RClass *target_class; |
mzta | 0:158c61bb030f | 35 | struct REnv *env; |
mzta | 0:158c61bb030f | 36 | }; |
mzta | 0:158c61bb030f | 37 | |
mzta | 0:158c61bb030f | 38 | /* aspec access */ |
mzta | 0:158c61bb030f | 39 | #define MRB_ASPEC_REQ(a) (((a) >> 18) & 0x1f) |
mzta | 0:158c61bb030f | 40 | #define MRB_ASPEC_OPT(a) (((a) >> 13) & 0x1f) |
mzta | 0:158c61bb030f | 41 | #define MRB_ASPEC_REST(a) (((a) >> 12) & 0x1) |
mzta | 0:158c61bb030f | 42 | #define MRB_ASPEC_POST(a) (((a) >> 7) & 0x1f) |
mzta | 0:158c61bb030f | 43 | #define MRB_ASPEC_KEY(a) (((a) >> 2) & 0x1f) |
mzta | 0:158c61bb030f | 44 | #define MRB_ASPEC_KDICT(a) ((a) & (1<<1)) |
mzta | 0:158c61bb030f | 45 | #define MRB_ASPEC_BLOCK(a) ((a) & 1) |
mzta | 0:158c61bb030f | 46 | |
mzta | 0:158c61bb030f | 47 | #define MRB_PROC_CFUNC 128 |
mzta | 0:158c61bb030f | 48 | #define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC) != 0) |
mzta | 0:158c61bb030f | 49 | #define MRB_PROC_STRICT 256 |
mzta | 0:158c61bb030f | 50 | #define MRB_PROC_STRICT_P(p) (((p)->flags & MRB_PROC_STRICT) != 0) |
mzta | 0:158c61bb030f | 51 | |
mzta | 0:158c61bb030f | 52 | #define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v))) |
mzta | 0:158c61bb030f | 53 | |
mzta | 0:158c61bb030f | 54 | struct RProc *mrb_proc_new(mrb_state*, mrb_irep*); |
mzta | 0:158c61bb030f | 55 | struct RProc *mrb_closure_new(mrb_state*, mrb_irep*); |
mzta | 0:158c61bb030f | 56 | MRB_API struct RProc *mrb_proc_new_cfunc(mrb_state*, mrb_func_t); |
mzta | 0:158c61bb030f | 57 | MRB_API struct RProc *mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals); |
mzta | 0:158c61bb030f | 58 | void mrb_proc_copy(struct RProc *a, struct RProc *b); |
mzta | 0:158c61bb030f | 59 | |
mzta | 0:158c61bb030f | 60 | /* implementation of #send method */ |
mzta | 0:158c61bb030f | 61 | MRB_API mrb_value mrb_f_send(mrb_state *mrb, mrb_value self); |
mzta | 0:158c61bb030f | 62 | |
mzta | 0:158c61bb030f | 63 | /* following functions are defined in mruby-proc-ext so please include it when using */ |
mzta | 0:158c61bb030f | 64 | MRB_API struct RProc *mrb_proc_new_cfunc_with_env(mrb_state*, mrb_func_t, mrb_int, const mrb_value*); |
mzta | 0:158c61bb030f | 65 | MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state*, mrb_int); |
mzta | 0:158c61bb030f | 66 | /* old name */ |
mzta | 0:158c61bb030f | 67 | #define mrb_cfunc_env_get(mrb, idx) mrb_proc_cfunc_env_get(mrb, idx) |
mzta | 0:158c61bb030f | 68 | |
mzta | 0:158c61bb030f | 69 | #include "mruby/khash.h" |
mzta | 0:158c61bb030f | 70 | KHASH_DECLARE(mt, mrb_sym, struct RProc*, TRUE) |
mzta | 0:158c61bb030f | 71 | |
mzta | 0:158c61bb030f | 72 | #if defined(__cplusplus) |
mzta | 0:158c61bb030f | 73 | } /* extern "C" { */ |
mzta | 0:158c61bb030f | 74 | #endif |
mzta | 0:158c61bb030f | 75 | |
mzta | 0:158c61bb030f | 76 | #endif /* MRUBY_PROC_H */ |
mzta | 0:158c61bb030f | 77 |