30static const char RITE[4] =
"RITE";
35static const char IREP[4] =
"IREP";
36static const char END[4] =
"END\0";
77 if( memcmp(bin,
RITE,
sizeof(
RITE)) != 0 ) {
134 const uint8_t *p = bin + 4;
136#if defined(MRBC_DEBUG)
137 irep.obj_mark_[0] =
'I';
138 irep.obj_mark_[1] =
'R';
142#if defined(MRBC_DEBUG)
151 if( ilen > 0xffff )
goto ERROR_TOO_LARGE;
161 for(
int i = 0; i < plen; i++ ) {
170#if defined(MRBC_INT64)
176 mrbc_raise(vm,
MRBC_CLASS(NotImplementedError),
"Unsupported int64 (set MRBC_INT64 in vm_config)");
190 uint32_t siz =
sizeof(
mrbc_sym) * slen;
191 if( siz > 0xffff )
goto ERROR_TOO_LARGE;
194 siz +=
sizeof(uint16_t) * plen;
195 if( siz > 0xffff )
goto ERROR_TOO_LARGE;
196 siz += (-siz & 0x03);
199#if defined(MRBC_DEBUG)
211 for(
int i = 0; i < slen; i++ ) {
217 memcpy(sym_str, p, siz);
234 p = p_irep->
pool + 2;
235 for(
int i = 0; i < plen; i++ ) {
237 if( (p - irep.
pool) > UINT16_MAX ) {
241 *ofs_pools++ = (uint16_t)(p - irep.
pool);
246#if defined(MRBC_INT64)
278 if( !irep )
return NULL;
279 int total_len = len1;
283 for(
int i = 0; i < irep->
rlen; i++ ) {
284 tbl_ireps[i] =
load_irep(vm, bin + total_len, &len1);
285 if( ! tbl_ireps[i] )
return NULL;
289 if( len ) *len = total_len;
305 const uint8_t *bin = bytecode;
313 if( memcmp(bin,
IREP,
sizeof(
IREP)) == 0 ) {
316 }
else if( memcmp(bin,
END,
sizeof(
END)) == 0 ) {
337 const uint8_t *bin = bytecode;
340 if( vm->
top_irep == NULL )
return -1;
355 for(
int i = 0; i < irep->
rlen; i++ ) {
364#if defined(MRBC_INT64)
366static mrbc_int_t conv_bigint(
const uint8_t *p )
369 int base = *(
const int8_t *)p++;
371 if( base < 0 ) base = -base;
375 for(
int i = 0; i < len; i++ ) {
376 ret = (ret * base) + (*p++ -
'0');
379 for(
int i = 0; i < len; i++ ) {
381 if( n > 9 ) n += (
'9' -
'a' + 1);
382 ret = (ret * base) + n;
386 return (sign < 0) ? -ret : ret;
424#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)
static void mrbc_set_nil(mrbc_value *p)
static void mrbc_set_float(mrbc_value *p, mrbc_float_t d)
struct RObject mrbc_value
Value object. Default version.
static void mrbc_set_integer(mrbc_value *p, mrbc_int_t n)
mrbc_value mrbc_string_new(mrbc_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(mrbc_vm *vm, const uint8_t *bin, int *len)
static const char RITE_VERSION[4]
static const char RITE[4]
static int load_header(mrbc_vm *vm, const uint8_t *bin)
mrbc_value mrbc_irep_pool_value(mrbc_vm *vm, int n)
void mrbc_irep_free(mrbc_irep *irep)
int mrbc_load_mrb(mrbc_vm *vm, const void *bytecode)
static mrbc_irep * load_irep_1(mrbc_vm *vm, const uint8_t *bin, int *len)
static const int SIZE_RITE_BINARY_HEADER
int mrbc_load_irep(mrbc_vm *vm, const void *bytecode)
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)
int16_t mrbc_sym
mruby/c symbol ID
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.
struct VM mrbc_vm
Virtual Machine.
Global configuration of mruby/c VM's.