diff options
Diffstat (limited to 'src/codegen.c')
| -rw-r--r-- | src/codegen.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/src/codegen.c b/src/codegen.c index 2072d278a..3162c44dd 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -316,8 +316,8 @@ 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 == IREP_TT_STRING && - s->irep->pool[i].value.s->len == 0) { + if (mrb_type(s->irep->pool[i]) == MRB_TT_STRING && + RSTRING_LEN(s->irep->pool[i]) == 0) { s->pc--; return; } @@ -397,7 +397,7 @@ static inline int new_lit(codegen_scope *s, mrb_value val) { size_t i; - struct irep_pool *pv; + mrb_value *pv; switch (mrb_type(val)) { case MRB_TT_STRING: @@ -405,24 +405,24 @@ new_lit(codegen_scope *s, mrb_value val) mrb_int len; pv = &s->irep->pool[i]; - 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) + if (mrb_type(*pv) != MRB_TT_STRING) continue; + if ((len = RSTRING_LEN(*pv)) != RSTRING_LEN(val)) continue; + if (memcmp(RSTRING_PTR(*pv), RSTRING_PTR(val), len) == 0) return i; } break; case MRB_TT_FLOAT: for (i=0; i<s->irep->plen; i++) { pv = &s->irep->pool[i]; - if (pv->type != IREP_TT_FLOAT) continue; - if (pv->value.f == mrb_float(val)) return i; + if (mrb_type(*pv) != MRB_TT_FLOAT) continue; + if (mrb_float(*pv) == 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 != IREP_TT_FIXNUM) continue; - if (pv->value.i == mrb_fixnum(val)) return i; + if (mrb_type(*pv) != MRB_TT_FIXNUM) continue; + if (mrb_fixnum(*pv) == mrb_fixnum(val)) return i; } break; default: @@ -432,7 +432,7 @@ new_lit(codegen_scope *s, mrb_value val) if (s->irep->plen == s->pcapa) { s->pcapa *= 2; - s->irep->pool = (struct irep_pool*)codegen_realloc(s, s->irep->pool, sizeof(struct irep_pool)*s->pcapa); + s->irep->pool = (mrb_value *)codegen_realloc(s, s->irep->pool, sizeof(mrb_value)*s->pcapa); } pv = &s->irep->pool[s->irep->plen]; @@ -440,19 +440,14 @@ new_lit(codegen_scope *s, mrb_value val) 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)); + *pv = mrb_str_dup_static(s->mrb, 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); + *pv = val; break; + default: /* should not happen */ break; @@ -2414,7 +2409,7 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv) p->iseq = (mrb_code*)mrb_malloc(mrb, sizeof(mrb_code)*p->icapa); p->pcapa = 32; - p->irep->pool = (struct irep_pool*)mrb_malloc(mrb, sizeof(struct irep_pool)*p->pcapa); + p->irep->pool = (struct mrb_value*)mrb_malloc(mrb, sizeof(struct mrb_value)*p->pcapa); p->irep->plen = 0; p->scapa = 256; @@ -2467,7 +2462,7 @@ scope_finish(codegen_scope *s) irep->lines = 0; } } - irep->pool = (struct irep_pool*)codegen_realloc(s, irep->pool, sizeof(struct irep_pool)*irep->plen); + irep->pool = (mrb_value*)codegen_realloc(s, irep->pool, sizeof(mrb_value)*irep->plen); irep->syms = (mrb_sym*)codegen_realloc(s, irep->syms, sizeof(mrb_sym)*irep->slen); irep->reps = (mrb_irep**)codegen_realloc(s, irep->reps, sizeof(mrb_irep*)*irep->rlen); if (s->filename) { @@ -2809,8 +2804,8 @@ codedump(mrb_state *mrb, mrb_irep *irep) break; case OP_STRING: { - struct irep_pool *pv = &irep->pool[GETARG_Bx(c)]; - mrb_value s = mrb_str_dump(mrb, mrb_str_new(mrb, pv->value.s->buf, pv->value.s->len)); + mrb_value v = irep->pool[GETARG_Bx(c)]; + mrb_value s = mrb_str_dump(mrb, mrb_str_new(mrb, RSTRING_PTR(v), RSTRING_LEN(v))); printf("OP_STRING\tR%d\t%s\n", GETARG_A(c), RSTRING_PTR(s)); } break; |
