2 ** @file mruby/irep.h - mrb_irep structure
4 ** See Copyright Notice in mruby.h
11 #include <mruby/compile.h>
14 * Compiled mruby scripts.
29 /* Program data array struct */
30 typedef struct mrb_irep {
31 uint16_t nlocals; /* Number of local variables */
32 uint16_t nregs; /* Number of register variables */
38 struct mrb_irep **reps;
40 struct mrb_locals *lv;
42 struct mrb_irep_debug_info* debug_info;
44 uint16_t ilen, plen, slen, rlen;
48 #define MRB_ISEQ_NO_FREE 1
50 MRB_API mrb_irep *mrb_add_irep(mrb_state *mrb);
52 /** load mruby bytecode functions
53 * Please note! Currently due to interactions with the GC calling these functions will
54 * leak one RProc object per function call.
55 * To prevent this save the current memory arena before calling and restore the arena
56 * right after, like so
57 * int ai = mrb_gc_arena_save(mrb);
58 * mrb_value status = mrb_load_irep(mrb, buffer);
59 * mrb_gc_arena_restore(mrb, ai);
62 /* @param [const uint8_t*] irep code, expected as a literal */
63 MRB_API mrb_value mrb_load_irep(mrb_state*, const uint8_t*);
66 * @param [const void*] irep code
67 * @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
69 MRB_API mrb_value mrb_load_irep_buf(mrb_state*, const void*, size_t);
71 /* @param [const uint8_t*] irep code, expected as a literal */
72 MRB_API mrb_value mrb_load_irep_cxt(mrb_state*, const uint8_t*, mrbc_context*);
75 * @param [const void*] irep code
76 * @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
78 MRB_API mrb_value mrb_load_irep_buf_cxt(mrb_state*, const void*, size_t, mrbc_context*);
80 void mrb_irep_free(mrb_state*, struct mrb_irep*);
81 void mrb_irep_incref(mrb_state*, struct mrb_irep*);
82 void mrb_irep_decref(mrb_state*, struct mrb_irep*);
83 void mrb_irep_cutref(mrb_state*, struct mrb_irep*);
84 void mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep);
86 struct mrb_insn_data {
93 struct mrb_insn_data mrb_decode_insn(const mrb_code *pc);
97 #endif /* MRUBY_IREP_H */