29static const char RITE[4] =
"RITE";
34static const char IREP[4] =
"IREP";
35static const char END[4] =
"END\0";
75 if( memcmp(bin,
RITE,
sizeof(
RITE)) != 0 ) {
132 const uint8_t *p = bin + 4;
134#if defined(MRBC_DEBUG)
135 irep.obj_mark_[0] =
'R';
136 irep.obj_mark_[1] =
'P';
140#if defined(MRBC_DEBUG)
149 if( ilen > 0xffff )
goto ERROR_TOO_LARGE;
159 for(
int i = 0; i < plen; i++ ) {
168#if !defined(MRBC_INT64)
169 mrbc_raise(vm,
MRBC_CLASS(NotImplementedError),
"Unsupported int64 (set MRBC_INT64 in vm_config)");
181 uint32_t siz =
sizeof(
mrbc_sym) * slen;
182 if( siz > 0xffff )
goto ERROR_TOO_LARGE;
185 siz +=
sizeof(uint16_t) * plen;
186 if( siz > 0xffff )
goto ERROR_TOO_LARGE;
187 siz += (-siz & 0x03);
190#if defined(MRBC_DEBUG)
206 for(
int i = 0; i < slen; i++ ) {
211 memcpy(sym_str, p, siz);
226 p = p_irep->
pool + 2;
227 for(
int i = 0; i < plen; i++ ) {
229 if( (p - irep.
pool) > UINT16_MAX ) {
233 *ofs_pools++ = (uint16_t)(p - irep.
pool);
267 if( !irep )
return NULL;
268 int total_len = len1;
272 for(
int i = 0; i < irep->
rlen; i++ ) {
273 tbl_ireps[i] =
load_irep(vm, bin + total_len, &len1);
274 if( ! tbl_ireps[i] )
return NULL;
278 if( len ) *len = total_len;
294 const uint8_t *bin = bytecode;
302 if( memcmp(bin,
IREP,
sizeof(
IREP)) == 0 ) {
305 }
else if( memcmp(bin,
END,
sizeof(
END)) == 0 ) {
326 const uint8_t *bin = bytecode;
329 if( vm->
top_irep == NULL )
return -1;
343 for(
int i = 0; i < irep->
rlen; i++ ) {
386#if defined(MRBC_INT64)
void * mrbc_raw_alloc(unsigned int size)
void * mrbc_raw_alloc_no_free(unsigned int size)
void mrbc_raw_free(void *ptr)
mrbc_value mrbc_string_new(struct VM *vm, const void *src, int len)
void mrbc_raise(struct VM *vm, struct RClass *exc_cls, const char *msg)
void mrbc_raisef(struct VM *vm, struct RClass *exc_cls, const char *fstr,...)
#define mrbc_israised(vm)
static const int SIZE_RITE_CATCH_HANDLER
static const int SIZE_RITE_SECTION_HEADER
static mrbc_irep * load_irep(struct VM *vm, const uint8_t *bin, int *len)
static const char RITE_VERSION[4]
static const char RITE[4]
int mrbc_load_mrb(struct VM *vm, const void *bytecode)
int mrbc_load_irep(struct VM *vm, const void *bytecode)
mrbc_value mrbc_irep_pool_value(struct VM *vm, int n)
static int load_header(struct VM *vm, const uint8_t *bin)
static mrbc_irep * load_irep_1(struct VM *vm, const uint8_t *bin, int *len)
void mrbc_irep_free(struct IREP *irep)
static const int SIZE_RITE_BINARY_HEADER
Include at once the necessary header files.
IREP Internal REPresentation.
uint16_t ofs_pools
offset of data->tbl_pools.
const uint8_t * inst
pointer to instruction in RITE binary
const uint8_t * pool
pointer to pool in RITE binary
uint16_t ilen
num of bytes in OpCode
uint16_t ref_count
reference counter
uint16_t ofs_ireps
offset of data->tbl_ireps. (32bit aligned)
uint16_t rlen
num of child IREP blocks
uint16_t clen
num of catch handlers
uint16_t nregs
num of register variables
const mrbc_irep * cur_irep
IREP currently running.
mrbc_value exception
Raised exception or nil.
unsigned int flag_permanence
mrbc_irep * top_irep
IREP tree top.
mrbc_sym mrbc_str_to_symid(const char *str)
static uint32_t bin_to_uint32(const void *s)
static double bin_to_double64(const void *s)
#define mrbc_set_integer(p, n)
#define mrbc_set_float(p, n)
int16_t mrbc_sym
mruby/c symbol ID
struct RObject mrbc_value
static uint16_t bin_to_uint16(const void *s)
#define mrbc_irep_tbl_syms(irep)
get a symbol id table pointer.
#define mrbc_irep_pool_ptr(irep, n)
get a pointer to n'th pool data.
#define mrbc_irep_child_irep(irep, n)
get a n'th child irep
#define mrbc_irep_tbl_pools(irep)
get a pool data offset table pointer.
#define mrbc_irep_tbl_ireps(irep)
get a child irep table pointer.
struct IREP mrbc_irep
IREP Internal REPresentation.
Global configuration of mruby/c VM's.