mruby 3.3.0
mruby is the lightweight implementation of the Ruby language
Loading...
Searching...
No Matches
irep.h
Go to the documentation of this file.
1
7#ifndef MRUBY_IREP_H
8#define MRUBY_IREP_H
9
10#include "common.h"
11#include <mruby/compile.h>
12
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_BIGINT = 7, /* big integer (not yet supported) */
24 IREP_TT_FLOAT = 5, /* float (double/float) */
25};
26
27#define IREP_TT_NFLAG 1 /* number (non string) flag */
28#define IREP_TT_SFLAG 2 /* static string flag */
29
30typedef struct mrb_pool_value {
31 uint32_t tt; /* packed type and length (for string) */
32 union {
33 const char *str;
34 int32_t i32;
35 int64_t i64;
36#ifndef MRB_NO_FLOAT
37 mrb_float f;
38#endif
39 } u;
41
42enum mrb_catch_type {
43 MRB_CATCH_RESCUE = 0,
44 MRB_CATCH_ENSURE = 1,
45};
46
48 uint8_t type; /* enum mrb_catch_type */
49 uint8_t begin[4]; /* The starting address to match the handler. Includes this. */
50 uint8_t end[4]; /* The endpoint address that matches the handler. Not Includes this. */
51 uint8_t target[4]; /* The address to jump to if a match is made. */
52};
53
54/* Program data array struct */
55struct mrb_irep {
56 uint16_t nlocals; /* Number of local variables */
57 uint16_t nregs; /* Number of register variables */
58 uint16_t clen; /* Number of catch handlers */
59 uint8_t flags;
60
61 const mrb_code *iseq;
62 /*
63 * A catch handler table is placed after the iseq entity.
64 * The reason it doesn't add fields to the structure is to keep the mrb_irep structure from bloating.
65 * The catch handler table can be obtained with `mrb_irep_catch_handler_table(irep)`.
66 */
67 const mrb_pool_value *pool;
68 const mrb_sym *syms;
69 const struct mrb_irep * const *reps;
70
71 const mrb_sym *lv;
72 /* debug info */
73 struct mrb_irep_debug_info* debug_info;
74
75 uint32_t ilen;
76 uint16_t plen, slen;
77 uint16_t rlen;
78 uint16_t refcnt;
79};
80
81#define MRB_ISEQ_NO_FREE 1
82#define MRB_IREP_NO_FREE 2
83#define MRB_IREP_STATIC (MRB_ISEQ_NO_FREE | MRB_IREP_NO_FREE)
84
85MRB_API mrb_irep *mrb_add_irep(mrb_state *mrb);
86
97/* @param [const uint8_t*] irep code, expected as a literal */
99
100/*
101 * @param [const void*] irep code
102 * @param [size_t] size of irep buffer.
103 */
104MRB_API mrb_value mrb_load_irep_buf(mrb_state*, const void*, size_t);
105
106/* @param [const uint8_t*] irep code, expected as a literal */
107MRB_API mrb_value mrb_load_irep_cxt(mrb_state*, const uint8_t*, mrb_ccontext*);
108
109/*
110 * @param [const void*] irep code
111 * @param [size_t] size of irep buffer.
112 */
113MRB_API mrb_value mrb_load_irep_buf_cxt(mrb_state*, const void*, size_t, mrb_ccontext*);
114
116 uint8_t insn;
117 uint32_t a;
118 uint16_t b;
119 uint16_t c;
120 const mrb_code *addr;
121};
122
123#define mrb_irep_catch_handler_pack(n, v) uint32_to_bin(n, v)
124#define mrb_irep_catch_handler_unpack(v) bin_to_uint32(v)
125
126void mrb_irep_incref(mrb_state*, struct mrb_irep*);
127void mrb_irep_decref(mrb_state*, struct mrb_irep*);
128void mrb_irep_cutref(mrb_state*, struct mrb_irep*);
129
131
132#endif /* MRUBY_IREP_H */
mruby Symbol.
mruby common platform definition"
#define MRB_END_DECL
End declarations in C mode.
Definition common.h:28
#define MRB_BEGIN_DECL
Start declarations in C mode.
Definition common.h:26
#define MRB_API
Declare a public mruby API function.
Definition common.h:79
mruby parser
irep_pool_type
Compiled mruby scripts.
Definition irep.h:18
mrb_value mrb_load_irep(mrb_state *, const uint8_t *)
load mruby bytecode functions Please note! Currently due to interactions with the GC calling these fu...
Definition load.c:700
uint8_t mrb_code
mruby C API entry point
Definition mruby.h:146
Definition compile.h:21
Definition irep.h:115
Definition irep.h:47
Definition debug.h:42
Definition irep.h:55
Definition irep.h:30
Definition mruby.h:256
Definition boxing_nan.h:40