diff options
Diffstat (limited to 'include/mruby/irep.h')
| -rw-r--r-- | include/mruby/irep.h | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/include/mruby/irep.h b/include/mruby/irep.h index 661ef2b48..a9c20681c 100644 --- a/include/mruby/irep.h +++ b/include/mruby/irep.h @@ -16,28 +16,58 @@ MRB_BEGIN_DECL enum irep_pool_type { - IREP_TT_STRING, - IREP_TT_FIXNUM, - IREP_TT_FLOAT, + IREP_TT_STR = 0, /* string (need free) */ + IREP_TT_SSTR = 2, /* string (static) */ + IREP_TT_INT32 = 1, /* 32bit integer */ + IREP_TT_INT64 = 3, /* 64bit integer */ + IREP_TT_FLOAT = 5, /* float (double/float) */ }; -struct mrb_locals { - mrb_sym name; - uint16_t r; +#define IREP_TT_NFLAG 1 /* number (non string) flag */ +#define IREP_TT_SFLAG 2 /* static string flag */ + +typedef struct mrb_pool_value { + uint32_t tt; /* packed type and length (for string) */ + union { + const char *str; + int32_t i32; +#ifdef MRB_64BIT + int64_t i64; +#endif + mrb_float f; + } u; +} mrb_pool_value; + +enum mrb_catch_type { + MRB_CATCH_RESCUE = 0, + MRB_CATCH_ENSURE = 1, +}; + +struct mrb_irep_catch_handler { + uint8_t type; /* enum mrb_catch_type */ + uint8_t begin[2]; /* The starting address to match the hander. Includes this. */ + uint8_t end[2]; /* The endpoint address that matches the hander. Not Includes this. */ + uint8_t target[2]; /* The address to jump to if a match is made. */ }; /* Program data array struct */ typedef struct mrb_irep { uint16_t nlocals; /* Number of local variables */ uint16_t nregs; /* Number of register variables */ + uint16_t clen; /* Number of catch handlers */ uint8_t flags; const mrb_code *iseq; - mrb_value *pool; - mrb_sym *syms; - struct mrb_irep **reps; - - struct mrb_locals *lv; + /* + * A catch handler table is placed after the iseq entity. + * The reason it doesn't add fields to the structure is to keep the mrb_irep structure from bloating. + * The catch handler table can be obtained with `mrb_irep_catch_handler_table(irep)`. + */ + const mrb_pool_value *pool; + const mrb_sym *syms; + const struct mrb_irep * const *reps; + + const mrb_sym *lv; /* debug info */ struct mrb_irep_debug_info* debug_info; @@ -46,6 +76,8 @@ typedef struct mrb_irep { } mrb_irep; #define MRB_ISEQ_NO_FREE 1 +#define MRB_IREP_NO_FREE 2 +#define MRB_IREP_STATIC (MRB_ISEQ_NO_FREE | MRB_IREP_NO_FREE) MRB_API mrb_irep *mrb_add_irep(mrb_state *mrb); @@ -92,6 +124,17 @@ struct mrb_insn_data { struct mrb_insn_data mrb_decode_insn(const mrb_code *pc); +static inline const struct mrb_irep_catch_handler * +mrb_irep_catch_handler_table(const struct mrb_irep *irep) +{ + if (irep->clen > 0) { + return (const struct mrb_irep_catch_handler*)(irep->iseq + irep->ilen); + } + else { + return (const struct mrb_irep_catch_handler*)NULL; + } +} + MRB_END_DECL #endif /* MRUBY_IREP_H */ |
