Permalink
Browse files

enum mrb_vtype varies on compile time configuration, namely MRB_NAN_B…

…OXING
  • Loading branch information...
matz committed Nov 14, 2013
1 parent 16b34d1 commit 71354b91cb48ff3a5c1e3c09492d18a3c30efcb9
Showing with 27 additions and 18 deletions.
  1. +7 −1 include/mruby/irep.h
  2. +8 −6 src/codegen.c
  3. +6 −6 src/dump.c
  4. +4 −3 src/load.c
  5. +1 −1 src/state.c
  6. +1 −1 src/vm.c
View
@@ -11,6 +11,12 @@
extern "C" {
#endif
enum irep_pool_type {
IREP_TT_STRING,
IREP_TT_FIXNUM,
IREP_TT_FLOAT,
};
/* Program data array struct */
typedef struct mrb_irep {
uint16_t nlocals; /* Number of local variables */
@@ -27,7 +33,7 @@ typedef struct mrb_irep {
} *s;
mrb_int i;
} value;
enum mrb_vtype type;
enum irep_pool_type type;
} *pool;
mrb_sym *syms;
struct mrb_irep **reps;
View
@@ -316,7 +316,7 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
if (c0 == OP_STRING) {
int i = GETARG_Bx(i0);
if (s->irep->pool[i].type == MRB_TT_STRING &&
if (s->irep->pool[i].type == IREP_TT_STRING &&
s->irep->pool[i].value.s->len == 0) {
s->pc--;
return;
@@ -405,7 +405,7 @@ new_lit(codegen_scope *s, mrb_value val)
mrb_int len;
pv = &s->irep->pool[i];
if (pv->type != MRB_TT_STRING) continue;
if (pv->type != IREP_TT_STRING) continue;
if ((len = pv->value.s->len) != RSTRING_LEN(val)) continue;
if (memcmp(pv->value.s->buf, RSTRING_PTR(val), len) == 0)
return i;
@@ -414,14 +414,14 @@ new_lit(codegen_scope *s, mrb_value val)
case MRB_TT_FLOAT:
for (i=0; i<s->irep->plen; i++) {
pv = &s->irep->pool[i];
if (pv->type != MRB_TT_FLOAT) continue;
if (pv->type != IREP_TT_FLOAT) continue;
if (pv->value.f == mrb_float(val)) return i;
}
break;
case MRB_TT_FIXNUM:
for (i=0; i<s->irep->plen; i++) {
pv = &s->irep->pool[i];
if (pv->type != MRB_TT_FIXNUM) continue;
if (pv->type != IREP_TT_FIXNUM) continue;
if (pv->value.i == mrb_fixnum(val)) return i;
}
break;
@@ -437,18 +437,20 @@ new_lit(codegen_scope *s, mrb_value val)
pv = &s->irep->pool[s->irep->plen];
i = s->irep->plen++;
pv->type = mrb_type(val);
switch (pv->type) {
switch (mrb_type(val)) {
case MRB_TT_STRING:
pv->type = IREP_TT_STRING;
pv->value.s = (struct irep_pool_string*)codegen_malloc(s, sizeof(struct irep_pool_string) + RSTRING_LEN(val));
pv->value.s->len = RSTRING_LEN(val);
memcpy(pv->value.s->buf, RSTRING_PTR(val), RSTRING_LEN(val));
break;
case MRB_TT_FLOAT:
pv->type = IREP_TT_FLOAT;
pv->value.f = mrb_float(val);
break;
case MRB_TT_FIXNUM:
pv->type = IREP_TT_FIXNUM;
pv->value.i = mrb_fixnum(val);
break;
default:
View
@@ -80,17 +80,17 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep)
int ai = mrb_gc_arena_save(mrb);
switch (irep->pool[pool_no].type) {
case MRB_TT_FIXNUM:
case IREP_TT_FIXNUM:
str = mrb_fixnum_to_str(mrb, mrb_fixnum_value(irep->pool[pool_no].value.i), 10);
size += RSTRING_LEN(str);
break;
case MRB_TT_FLOAT:
case IREP_TT_FLOAT:
len = mrb_float_to_str(buf, irep->pool[pool_no].value.f);
size += len;
break;
case MRB_TT_STRING:
case IREP_TT_STRING:
size += irep->pool[pool_no].value.s->len;
break;
@@ -121,18 +121,18 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf)
cur += uint8_to_bin(irep->pool[pool_no].type, cur); /* data type */
switch (irep->pool[pool_no].type) {
case MRB_TT_FIXNUM:
case IREP_TT_FIXNUM:
str = mrb_fixnum_to_str(mrb, mrb_fixnum_value(irep->pool[pool_no].value.i), 10);
char_ptr = RSTRING_PTR(str);
len = RSTRING_LEN(str);
break;
case MRB_TT_FLOAT:
case IREP_TT_FLOAT:
len = mrb_float_to_str(char_buf, irep->pool[pool_no].value.f);
char_ptr = &char_buf[0];
break;
case MRB_TT_STRING:
case IREP_TT_STRING:
char_ptr = irep->pool[pool_no].value.s->buf;
len = irep->pool[pool_no].value.s->len;
break;
View
@@ -94,14 +94,15 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
for (i = 0; i < plen; i++) {
mrb_value s;
tt = *src++; //pool TT
pool_data_len = bin_to_uint16(src); //pool data length
src += sizeof(uint16_t);
s = mrb_str_new(mrb, (char *)src, pool_data_len);
src += pool_data_len;
irep->pool[i].type = tt;
switch (tt) { //pool data
case MRB_TT_FIXNUM:
case IREP_TT_FIXNUM:
{
mrb_value v = mrb_str_to_inum(mrb, s, 10, FALSE);
@@ -119,11 +120,11 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
}
break;
case MRB_TT_FLOAT:
case IREP_TT_FLOAT:
irep->pool[i].value.f = mrb_str_to_dbl(mrb, s, FALSE);
break;
case MRB_TT_STRING:
case IREP_TT_STRING:
irep->pool[i].value.s = (struct irep_pool_string*)mrb_malloc(mrb, sizeof(struct irep_pool_string) + pool_data_len);
irep->pool[i].value.s->len = pool_data_len;
memcpy(irep->pool[i].value.s->buf, src-pool_data_len, pool_data_len);
View
@@ -129,7 +129,7 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
if (!(irep->flags & MRB_ISEQ_NO_FREE))
mrb_free(mrb, irep->iseq);
for (i=0; i<irep->plen; i++) {
if (irep->pool[i].type == MRB_TT_STRING)
if (irep->pool[i].type == IREP_TT_STRING)
mrb_free(mrb, irep->pool[i].value.s);
}
mrb_free(mrb, irep->pool);
View
@@ -618,7 +618,7 @@ mrb_context_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int
CASE(OP_LOADL) {
/* A Bx R(A) := Pool(Bx) */
if (pool[GETARG_Bx(i)].type == MRB_TT_FLOAT)
if (pool[GETARG_Bx(i)].type == IREP_TT_FLOAT)
SET_FLT_VALUE(mrb, regs[GETARG_A(i)], pool[GETARG_Bx(i)].value.f);
else
SET_INT_VALUE(regs[GETARG_A(i)], pool[GETARG_Bx(i)].value.i);

0 comments on commit 71354b9

Please sign in to comment.