diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-06-09 14:39:38 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-10-12 16:21:08 +0900 |
| commit | d428fa0c4acfe4f70ab534d420052c193bd83281 (patch) | |
| tree | 903e5ab41d1c358e3b512be90d36837e54580e29 /src/vm.c | |
| parent | daa37be5495393ce3e4654e00e44099f627e6cd4 (diff) | |
| download | mruby-d428fa0c4acfe4f70ab534d420052c193bd83281.tar.gz mruby-d428fa0c4acfe4f70ab534d420052c193bd83281.zip | |
Replace entire `irep->pool`.
Changes:
- `pool format is completely replaced
- supported types: `STR`, `INT32`, `INT64`, `FLOAT`
- `FLOAT` may be replaced by binary representation in the future
- insert `NUL` after string literals in `mrb` files
- `irep->pool` no longer store values in `mrb_value`
- instead it stores in `mrb_pool_value`
- less allocation
- `mrb_irep` can be stored in ROM
Diffstat (limited to 'src/vm.c')
| -rw-r--r-- | src/vm.c | 43 |
1 files changed, 28 insertions, 15 deletions
@@ -966,7 +966,7 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, const mrb_code *pc) /* mrb_assert(MRB_PROC_CFUNC_P(proc)) */ const mrb_code *pc0 = pc; const mrb_irep *irep = proc->body.irep; - const mrb_value *pool = irep->pool; + const mrb_pool_value *pool = irep->pool; const mrb_sym *syms = irep->syms; mrb_code insn; int ai = mrb_gc_arena_save(mrb); @@ -1013,17 +1013,25 @@ RETRY_TRY_BLOCK: } CASE(OP_LOADL, BB) { -#ifdef MRB_WORD_BOXING - mrb_value val = pool[b]; -#ifndef MRB_WITHOUT_FLOAT - if (mrb_float_p(val)) { - val = mrb_float_value(mrb, mrb_float(val)); - } + switch (pool[b].tt) { /* number */ + case IREP_TT_INT32: + regs[a] = mrb_fixnum_value((mrb_int)pool[b].u.i32); + break; +#ifdef MRB_INT64 + case IREP_TT_INT64: + regs[a] = mrb_fixnum_value((mrb_int)pool[b].u.i64); + break; #endif - regs[a] = val; -#else - regs[a] = pool[b]; +#ifndef MRB_WITHOUT_FLOAT + case IREP_TT_FLOAT: + regs[a] = mrb_float_value(mrb, pool[b].u.f); + break; #endif + default: + /* should not happen (tt:string) */ + regs[a] = mrb_nil_value(); + break; + } NEXT; } @@ -2499,9 +2507,13 @@ RETRY_TRY_BLOCK: } CASE(OP_STRING, BB) { - mrb_value str = mrb_str_dup(mrb, pool[b]); - - regs[a] = str; + size_t len = pool[b].tt >> 2; + if (pool[b].tt & IREP_TT_SFLAG) { + regs[a] = mrb_str_new_static(mrb, pool[b].u.str, len); + } + else { + regs[a] = mrb_str_new(mrb, pool[b].u.str, len); + } mrb_gc_arena_restore(mrb, ai); NEXT; } @@ -2703,10 +2715,11 @@ RETRY_TRY_BLOCK: } CASE(OP_ERR, B) { - mrb_value msg = mrb_str_dup(mrb, pool[a]); + size_t len = pool[a].tt >> 2; mrb_value exc; - exc = mrb_exc_new_str(mrb, E_LOCALJUMP_ERROR, msg); + mrb_assert((pool[a].tt&IREP_TT_NFLAG)==0); + exc = mrb_exc_new(mrb, E_LOCALJUMP_ERROR, pool[a].u.str, len); ERR_PC_SET(mrb); mrb_exc_set(mrb, exc); goto L_RAISE; |
