enum mrb_vtype varies on compile time configuration, namely MRB_NAN_BOXING

parent 16b34d18
...@@ -11,6 +11,12 @@ ...@@ -11,6 +11,12 @@
extern "C" { extern "C" {
#endif #endif
enum irep_pool_type {
IREP_TT_STRING,
IREP_TT_FIXNUM,
IREP_TT_FLOAT,
};
/* Program data array struct */ /* Program data array struct */
typedef struct mrb_irep { typedef struct mrb_irep {
uint16_t nlocals; /* Number of local variables */ uint16_t nlocals; /* Number of local variables */
...@@ -27,7 +33,7 @@ typedef struct mrb_irep { ...@@ -27,7 +33,7 @@ typedef struct mrb_irep {
} *s; } *s;
mrb_int i; mrb_int i;
} value; } value;
enum mrb_vtype type; enum irep_pool_type type;
} *pool; } *pool;
mrb_sym *syms; mrb_sym *syms;
struct mrb_irep **reps; struct mrb_irep **reps;
......
...@@ -316,7 +316,7 @@ genop_peep(codegen_scope *s, mrb_code i, int val) ...@@ -316,7 +316,7 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
if (c0 == OP_STRING) { if (c0 == OP_STRING) {
int i = GETARG_Bx(i0); 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->irep->pool[i].value.s->len == 0) {
s->pc--; s->pc--;
return; return;
...@@ -405,7 +405,7 @@ new_lit(codegen_scope *s, mrb_value val) ...@@ -405,7 +405,7 @@ new_lit(codegen_scope *s, mrb_value val)
mrb_int len; mrb_int len;
pv = &s->irep->pool[i]; 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 ((len = pv->value.s->len) != RSTRING_LEN(val)) continue;
if (memcmp(pv->value.s->buf, RSTRING_PTR(val), len) == 0) if (memcmp(pv->value.s->buf, RSTRING_PTR(val), len) == 0)
return i; return i;
...@@ -414,14 +414,14 @@ new_lit(codegen_scope *s, mrb_value val) ...@@ -414,14 +414,14 @@ new_lit(codegen_scope *s, mrb_value val)
case MRB_TT_FLOAT: case MRB_TT_FLOAT:
for (i=0; i<s->irep->plen; i++) { for (i=0; i<s->irep->plen; i++) {
pv = &s->irep->pool[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; if (pv->value.f == mrb_float(val)) return i;
} }
break; break;
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
for (i=0; i<s->irep->plen; i++) { for (i=0; i<s->irep->plen; i++) {
pv = &s->irep->pool[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; if (pv->value.i == mrb_fixnum(val)) return i;
} }
break; break;
...@@ -437,18 +437,20 @@ new_lit(codegen_scope *s, mrb_value val) ...@@ -437,18 +437,20 @@ new_lit(codegen_scope *s, mrb_value val)
pv = &s->irep->pool[s->irep->plen]; pv = &s->irep->pool[s->irep->plen];
i = s->irep->plen++; i = s->irep->plen++;
pv->type = mrb_type(val);
switch (pv->type) { switch (mrb_type(val)) {
case MRB_TT_STRING: 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 = (struct irep_pool_string*)codegen_malloc(s, sizeof(struct irep_pool_string) + RSTRING_LEN(val));
pv->value.s->len = RSTRING_LEN(val); pv->value.s->len = RSTRING_LEN(val);
memcpy(pv->value.s->buf, RSTRING_PTR(val), RSTRING_LEN(val)); memcpy(pv->value.s->buf, RSTRING_PTR(val), RSTRING_LEN(val));
break; break;
case MRB_TT_FLOAT: case MRB_TT_FLOAT:
pv->type = IREP_TT_FLOAT;
pv->value.f = mrb_float(val); pv->value.f = mrb_float(val);
break; break;
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
pv->type = IREP_TT_FIXNUM;
pv->value.i = mrb_fixnum(val); pv->value.i = mrb_fixnum(val);
break; break;
default: default:
......
...@@ -80,17 +80,17 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep) ...@@ -80,17 +80,17 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep)
int ai = mrb_gc_arena_save(mrb); int ai = mrb_gc_arena_save(mrb);
switch (irep->pool[pool_no].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); str = mrb_fixnum_to_str(mrb, mrb_fixnum_value(irep->pool[pool_no].value.i), 10);
size += RSTRING_LEN(str); size += RSTRING_LEN(str);
break; break;
case MRB_TT_FLOAT: case IREP_TT_FLOAT:
len = mrb_float_to_str(buf, irep->pool[pool_no].value.f); len = mrb_float_to_str(buf, irep->pool[pool_no].value.f);
size += len; size += len;
break; break;
case MRB_TT_STRING: case IREP_TT_STRING:
size += irep->pool[pool_no].value.s->len; size += irep->pool[pool_no].value.s->len;
break; break;
...@@ -121,18 +121,18 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf) ...@@ -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 */ cur += uint8_to_bin(irep->pool[pool_no].type, cur); /* data type */
switch (irep->pool[pool_no].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); str = mrb_fixnum_to_str(mrb, mrb_fixnum_value(irep->pool[pool_no].value.i), 10);
char_ptr = RSTRING_PTR(str); char_ptr = RSTRING_PTR(str);
len = RSTRING_LEN(str); len = RSTRING_LEN(str);
break; break;
case MRB_TT_FLOAT: case IREP_TT_FLOAT:
len = mrb_float_to_str(char_buf, irep->pool[pool_no].value.f); len = mrb_float_to_str(char_buf, irep->pool[pool_no].value.f);
char_ptr = &char_buf[0]; char_ptr = &char_buf[0];
break; break;
case MRB_TT_STRING: case IREP_TT_STRING:
char_ptr = irep->pool[pool_no].value.s->buf; char_ptr = irep->pool[pool_no].value.s->buf;
len = irep->pool[pool_no].value.s->len; len = irep->pool[pool_no].value.s->len;
break; break;
......
...@@ -94,6 +94,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len) ...@@ -94,6 +94,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
for (i = 0; i < plen; i++) { for (i = 0; i < plen; i++) {
mrb_value s; mrb_value s;
tt = *src++; //pool TT tt = *src++; //pool TT
pool_data_len = bin_to_uint16(src); //pool data length pool_data_len = bin_to_uint16(src); //pool data length
src += sizeof(uint16_t); src += sizeof(uint16_t);
...@@ -101,7 +102,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len) ...@@ -101,7 +102,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
src += pool_data_len; src += pool_data_len;
irep->pool[i].type = tt; irep->pool[i].type = tt;
switch (tt) { //pool data switch (tt) { //pool data
case MRB_TT_FIXNUM: case IREP_TT_FIXNUM:
{ {
mrb_value v = mrb_str_to_inum(mrb, s, 10, FALSE); 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) ...@@ -119,11 +120,11 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
} }
break; break;
case MRB_TT_FLOAT: case IREP_TT_FLOAT:
irep->pool[i].value.f = mrb_str_to_dbl(mrb, s, FALSE); irep->pool[i].value.f = mrb_str_to_dbl(mrb, s, FALSE);
break; 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 = (struct irep_pool_string*)mrb_malloc(mrb, sizeof(struct irep_pool_string) + pool_data_len);
irep->pool[i].value.s->len = 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); memcpy(irep->pool[i].value.s->buf, src-pool_data_len, pool_data_len);
......
...@@ -129,7 +129,7 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep) ...@@ -129,7 +129,7 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
if (!(irep->flags & MRB_ISEQ_NO_FREE)) if (!(irep->flags & MRB_ISEQ_NO_FREE))
mrb_free(mrb, irep->iseq); mrb_free(mrb, irep->iseq);
for (i=0; i<irep->plen; i++) { 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[i].value.s);
} }
mrb_free(mrb, irep->pool); mrb_free(mrb, irep->pool);
......
...@@ -618,7 +618,7 @@ mrb_context_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int ...@@ -618,7 +618,7 @@ mrb_context_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int
CASE(OP_LOADL) { CASE(OP_LOADL) {
/* A Bx R(A) := Pool(Bx) */ /* 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); SET_FLT_VALUE(mrb, regs[GETARG_A(i)], pool[GETARG_Bx(i)].value.f);
else else
SET_INT_VALUE(regs[GETARG_A(i)], pool[GETARG_Bx(i)].value.i); SET_INT_VALUE(regs[GETARG_A(i)], pool[GETARG_Bx(i)].value.i);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment