w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

irep.h
Go to the documentation of this file.
1 /**
2 ** @file mruby/irep.h - mrb_irep structure
3 **
4 ** See Copyright Notice in mruby.h
5 */
6 
7 #ifndef MRUBY_IREP_H
8 #define MRUBY_IREP_H
9 
10 #include "common.h"
11 #include <mruby/compile.h>
12 
13 /**
14  * Compiled mruby scripts.
15  */
17 
19  IREP_TT_STR = 0, /* string (need free) */
20  IREP_TT_SSTR = 2, /* string (static) */
21  IREP_TT_INT32 = 1, /* 32bit integer */
22  IREP_TT_INT64 = 3, /* 64bit integer */
23  IREP_TT_FLOAT = 5, /* float (double/float) */
24 };
25 
26 #define IREP_TT_NFLAG 1 /* number (non string) flag */
27 #define IREP_TT_SFLAG 2 /* static string flag */
28 
29 typedef struct mrb_pool_value {
30  uint32_t tt; /* packed type and length (for string) */
31  union {
32  const char *str;
34 #if defined(MRB_64BIT) || defined(MRB_INT64)
36 #endif
37 #ifndef MRB_NO_FLOAT
39 #endif
40  } u;
42 
46 };
47 
49  uint8_t type; /* enum mrb_catch_type */
50  uint8_t begin[4]; /* The starting address to match the hander. Includes this. */
51  uint8_t end[4]; /* The endpoint address that matches the hander. Not Includes this. */
52  uint8_t target[4]; /* The address to jump to if a match is made. */
53 };
54 
55 /* Program data array struct */
56 typedef struct mrb_irep {
57  uint16_t nlocals; /* Number of local variables */
58  uint16_t nregs; /* Number of register variables */
59  uint16_t clen; /* Number of catch handlers */
61 
62  const mrb_code *iseq;
63  /*
64  * A catch handler table is placed after the iseq entity.
65  * The reason it doesn't add fields to the structure is to keep the mrb_irep structure from bloating.
66  * The catch handler table can be obtained with `mrb_irep_catch_handler_table(irep)`.
67  */
69  const mrb_sym *syms;
70  const struct mrb_irep * const *reps;
71 
72  const mrb_sym *lv;
73  /* debug info */
75 
81 
82 #define MRB_ISEQ_NO_FREE 1
83 #define MRB_IREP_NO_FREE 2
84 #define MRB_IREP_STATIC (MRB_ISEQ_NO_FREE | MRB_IREP_NO_FREE)
85 
87 
88 /** load mruby bytecode functions
89 * Please note! Currently due to interactions with the GC calling these functions will
90 * leak one RProc object per function call.
91 * To prevent this save the current memory arena before calling and restore the arena
92 * right after, like so
93 * int ai = mrb_gc_arena_save(mrb);
94 * mrb_value status = mrb_load_irep(mrb, buffer);
95 * mrb_gc_arena_restore(mrb, ai);
96 */
97 
98 /* @param [const uint8_t*] irep code, expected as a literal */
100 
101 /*
102  * @param [const void*] irep code
103  * @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
104  */
105 MRB_API mrb_value mrb_load_irep_buf(mrb_state*, const void*, size_t);
106 
107 /* @param [const uint8_t*] irep code, expected as a literal */
109 
110 /*
111  * @param [const void*] irep code
112  * @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
113  */
115 
116 void mrb_irep_free(mrb_state*, struct mrb_irep*);
117 void mrb_irep_incref(mrb_state*, struct mrb_irep*);
118 void mrb_irep_decref(mrb_state*, struct mrb_irep*);
119 void mrb_irep_cutref(mrb_state*, struct mrb_irep*);
120 void mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep);
121 
127 };
128 
130 
131 static inline const struct mrb_irep_catch_handler *
133 {
134  if (irep->clen > 0) {
135  return (const struct mrb_irep_catch_handler*)(irep->iseq + irep->ilen);
136  }
137  else {
138  return (const struct mrb_irep_catch_handler*)NULL;
139  }
140 }
141 
142 #define mrb_irep_catch_handler_pack(n, v) uint32_to_bin(n, v)
143 #define mrb_irep_catch_handler_unpack(v) bin_to_uint32(v)
144 
146 
147 #endif /* MRUBY_IREP_H */
long pc
Definition: disdvi.c:114
void mrb_irep_decref(mrb_state *, struct mrb_irep *)
Definition: state.c:117
mrb_value mrb_load_irep_cxt(mrb_state *, const uint8_t *, mrbc_context *)
Definition: load.c:640
struct mrb_irep mrb_irep
void mrb_irep_incref(mrb_state *, struct mrb_irep *)
Definition: state.c:110
void mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep)
Definition: codegen.c:3301
struct mrb_insn_data mrb_decode_insn(const mrb_code *pc)
Definition: codegen.c:331
void mrb_irep_free(mrb_state *, struct mrb_irep *)
Definition: state.c:142
struct mrb_pool_value mrb_pool_value
void mrb_irep_cutref(mrb_state *, struct mrb_irep *)
Definition: state.c:127
mrb_irep * mrb_add_irep(mrb_state *mrb)
Definition: state.c:196
mrb_catch_type
Definition: irep.h:43
@ MRB_CATCH_RESCUE
Definition: irep.h:44
@ MRB_CATCH_ENSURE
Definition: irep.h:45
irep_pool_type
Definition: irep.h:18
@ IREP_TT_STR
Definition: irep.h:19
@ IREP_TT_INT32
Definition: irep.h:21
@ IREP_TT_FLOAT
Definition: irep.h:23
@ IREP_TT_INT64
Definition: irep.h:22
@ IREP_TT_SSTR
Definition: irep.h:20
mrb_value mrb_load_irep(mrb_state *, const uint8_t *)
Definition: load.c:654
static const struct mrb_irep_catch_handler * mrb_irep_catch_handler_table(const struct mrb_irep *irep)
Definition: irep.h:132
mrb_value mrb_load_irep_buf_cxt(mrb_state *, const void *, size_t, mrbc_context *)
Definition: load.c:648
mrb_value mrb_load_irep_buf(mrb_state *, const void *, size_t)
Definition: load.c:660
#define NULL
Definition: ftobjs.h:61
#define const
Definition: ftzconf.h:91
unsigned short uint16_t
Definition: stdint.h:79
signed __int64 int64_t
Definition: stdint.h:89
unsigned int uint32_t
Definition: stdint.h:80
signed int int32_t
Definition: stdint.h:77
unsigned char uint8_t
Definition: stdint.h:78
uint8_t mrb_code
Definition: mruby.h:122
#define MRB_END_DECL
Definition: common.h:28
#define MRB_BEGIN_DECL
Definition: common.h:26
#define MRB_API
Definition: common.h:73
uint8_t insn
Definition: irep.h:123
uint16_t a
Definition: irep.h:124
uint16_t c
Definition: irep.h:126
uint16_t b
Definition: irep.h:125
uint8_t end[4]
Definition: irep.h:51
uint8_t target[4]
Definition: irep.h:52
uint8_t begin[4]
Definition: irep.h:50
Definition: irep.h:56
uint16_t plen
Definition: irep.h:77
uint8_t flags
Definition: irep.h:60
uint16_t nregs
Definition: irep.h:58
uint16_t nlocals
Definition: irep.h:57
uint16_t slen
Definition: irep.h:77
const mrb_code * iseq
Definition: irep.h:62
struct mrb_irep_debug_info * debug_info
Definition: irep.h:74
uint16_t refcnt
Definition: irep.h:79
uint32_t ilen
Definition: irep.h:76
const mrb_sym * lv
Definition: irep.h:72
const mrb_sym * syms
Definition: irep.h:69
uint16_t clen
Definition: irep.h:59
uint16_t rlen
Definition: irep.h:78
const mrb_pool_value * pool
Definition: irep.h:68
const struct mrb_irep *const * reps
Definition: irep.h:70
mrb_float f
Definition: irep.h:38
union mrb_pool_value::@1660 u
const char * str
Definition: irep.h:32
int32_t i32
Definition: irep.h:33
uint32_t tt
Definition: irep.h:30
int64_t i64
Definition: irep.h:35
double mrb_float
Definition: value.h:85