mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge branch 'master' of github.com:mruby/mruby
This commit is contained in:
+6
-3
@@ -51,7 +51,7 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, mrb_code *pc0, each_backtrace_fu
|
||||
pc = mrb->c->cibase[i].err;
|
||||
}
|
||||
else if (i+1 <= ciidx) {
|
||||
pc = mrb->c->cibase[i+1].pc - 1;
|
||||
pc = &mrb->c->cibase[i+1].pc[-1];
|
||||
}
|
||||
else {
|
||||
pc = pc0;
|
||||
@@ -215,11 +215,14 @@ packed_backtrace(mrb_state *mrb)
|
||||
void
|
||||
mrb_keep_backtrace(mrb_state *mrb, mrb_value exc)
|
||||
{
|
||||
mrb_sym sym = mrb_intern_lit(mrb, "backtrace");
|
||||
mrb_value backtrace;
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
int ai;
|
||||
|
||||
if (mrb_iv_defined(mrb, exc, sym)) return;
|
||||
ai = mrb_gc_arena_save(mrb);
|
||||
backtrace = packed_backtrace(mrb);
|
||||
mrb_iv_set(mrb, exc, mrb_intern_lit(mrb, "backtrace"), backtrace);
|
||||
mrb_iv_set(mrb, exc, sym, backtrace);
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
}
|
||||
|
||||
|
||||
+53
-13
@@ -436,8 +436,11 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, struct RPro
|
||||
k = kh_put(mt, mrb, h, mid);
|
||||
kh_value(h, k) = p;
|
||||
if (p) {
|
||||
p->flags |= MRB_PROC_SCOPE;
|
||||
p->c = NULL;
|
||||
mrb_field_write_barrier(mrb, (struct RBasic *)c, (struct RBasic *)p);
|
||||
mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)p);
|
||||
MRB_PROC_SET_TARGET_CLASS(p, c);
|
||||
mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)c);
|
||||
}
|
||||
mc_clear_by_id(mrb, c, mid);
|
||||
}
|
||||
@@ -449,7 +452,7 @@ mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t f
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
|
||||
p = mrb_proc_new_cfunc(mrb, func);
|
||||
p->target_class = c;
|
||||
MRB_PROC_SET_TARGET_CLASS(p, c);
|
||||
mrb_define_method_raw(mrb, c, mid, p);
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
}
|
||||
@@ -532,6 +535,35 @@ to_sym(mrb_state *mrb, mrb_value ss)
|
||||
}
|
||||
}
|
||||
|
||||
MRB_API mrb_int
|
||||
mrb_get_argc(mrb_state *mrb)
|
||||
{
|
||||
mrb_int argc = mrb->c->ci->argc;
|
||||
|
||||
if (argc < 0) {
|
||||
struct RArray *a = mrb_ary_ptr(mrb->c->stack[1]);
|
||||
|
||||
argc = ARY_LEN(a);
|
||||
}
|
||||
return argc;
|
||||
}
|
||||
|
||||
MRB_API mrb_value*
|
||||
mrb_get_argv(mrb_state *mrb)
|
||||
{
|
||||
mrb_int argc = mrb->c->ci->argc;
|
||||
mrb_value *array_argv;
|
||||
if (argc < 0) {
|
||||
struct RArray *a = mrb_ary_ptr(mrb->c->stack[1]);
|
||||
|
||||
array_argv = ARY_PTR(a);
|
||||
}
|
||||
else {
|
||||
array_argv = NULL;
|
||||
}
|
||||
return array_argv;
|
||||
}
|
||||
|
||||
/*
|
||||
retrieve arguments from mrb_state.
|
||||
|
||||
@@ -569,23 +601,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
||||
char c;
|
||||
mrb_int i = 0;
|
||||
va_list ap;
|
||||
mrb_int argc = mrb->c->ci->argc;
|
||||
mrb_int argc = mrb_get_argc(mrb);
|
||||
mrb_int arg_i = 0;
|
||||
mrb_value *array_argv;
|
||||
mrb_value *array_argv = mrb_get_argv(mrb);
|
||||
mrb_bool opt = FALSE;
|
||||
mrb_bool opt_skip = TRUE;
|
||||
mrb_bool given = TRUE;
|
||||
|
||||
va_start(ap, format);
|
||||
if (argc < 0) {
|
||||
struct RArray *a = mrb_ary_ptr(mrb->c->stack[1]);
|
||||
|
||||
argc = ARY_LEN(a);
|
||||
array_argv = ARY_PTR(a);
|
||||
}
|
||||
else {
|
||||
array_argv = NULL;
|
||||
}
|
||||
|
||||
#define ARGV \
|
||||
(array_argv ? array_argv : (mrb->c->stack + 1))
|
||||
@@ -1979,6 +2002,12 @@ mod_define_method(mrb_state *mrb, mrb_value self)
|
||||
return mrb_symbol_value(mid);
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
top_define_method(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
return mod_define_method(mrb, mrb_obj_value(mrb->object_class));
|
||||
}
|
||||
|
||||
static void
|
||||
check_cv_name_str(mrb_state *mrb, mrb_value str)
|
||||
{
|
||||
@@ -2388,6 +2417,12 @@ mrb_value mrb_obj_instance_eval(mrb_state*, mrb_value);
|
||||
/* implementation of Module.nesting */
|
||||
mrb_value mrb_mod_s_nesting(mrb_state*, mrb_value);
|
||||
|
||||
static mrb_value
|
||||
inspect_main(mrb_state *mrb, mrb_value mod)
|
||||
{
|
||||
return mrb_str_new_lit(mrb, "main");
|
||||
}
|
||||
|
||||
void
|
||||
mrb_init_class(mrb_state *mrb)
|
||||
{
|
||||
@@ -2484,4 +2519,9 @@ mrb_init_class(mrb_state *mrb)
|
||||
|
||||
mrb_undef_method(mrb, cls, "append_features");
|
||||
mrb_undef_method(mrb, cls, "extend_object");
|
||||
|
||||
mrb->top_self = (struct RObject*)mrb_obj_alloc(mrb, MRB_TT_OBJECT, mrb->object_class);
|
||||
mrb_define_singleton_method(mrb, mrb->top_self, "inspect", inspect_main, MRB_ARGS_NONE());
|
||||
mrb_define_singleton_method(mrb, mrb->top_self, "to_s", inspect_main, MRB_ARGS_NONE());
|
||||
mrb_define_singleton_method(mrb, mrb->top_self, "define_method", top_define_method, MRB_ARGS_ARG(1,1));
|
||||
}
|
||||
|
||||
+4
-4
@@ -314,22 +314,22 @@ codedump(mrb_state *mrb, mrb_irep *irep)
|
||||
GETARG_C(c));
|
||||
break;
|
||||
case OP_LT:
|
||||
printf("OP_LT\tR%d\t:%s\t%d\n", GETARG_A(c),
|
||||
printf("OP_LT\t\tR%d\t:%s\t%d\n", GETARG_A(c),
|
||||
mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
||||
GETARG_C(c));
|
||||
break;
|
||||
case OP_LE:
|
||||
printf("OP_LE\tR%d\t:%s\t%d\n", GETARG_A(c),
|
||||
printf("OP_LE\t\tR%d\t:%s\t%d\n", GETARG_A(c),
|
||||
mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
||||
GETARG_C(c));
|
||||
break;
|
||||
case OP_GT:
|
||||
printf("OP_GT\tR%d\t:%s\t%d\n", GETARG_A(c),
|
||||
printf("OP_GT\t\tR%d\t:%s\t%d\n", GETARG_A(c),
|
||||
mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
||||
GETARG_C(c));
|
||||
break;
|
||||
case OP_GE:
|
||||
printf("OP_GE\tR%d\t:%s\t%d\n", GETARG_A(c),
|
||||
printf("OP_GE\t\tR%d\t:%s\t%d\n", GETARG_A(c),
|
||||
mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
||||
GETARG_C(c));
|
||||
break;
|
||||
|
||||
@@ -200,6 +200,7 @@ exc_debug_info(mrb_state *mrb, struct RObject *exc)
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
mrb_code *pc = ci->pc;
|
||||
|
||||
if (mrb_obj_iv_defined(mrb, exc, mrb_intern_lit(mrb, "file"))) return;
|
||||
while (ci >= mrb->c->cibase) {
|
||||
mrb_code *err = ci->err;
|
||||
|
||||
|
||||
@@ -649,11 +649,8 @@ gc_mark_children(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
|
||||
{
|
||||
struct RProc *p = (struct RProc*)obj;
|
||||
|
||||
mrb_gc_mark(mrb, (struct RBasic*)p->env);
|
||||
mrb_gc_mark(mrb, (struct RBasic*)p->target_class);
|
||||
if (!MRB_PROC_CFUNC_P(p) && p->body.irep) {
|
||||
mrb_gc_mark(mrb, (struct RBasic*)p->body.irep->target_class);
|
||||
}
|
||||
mrb_gc_mark(mrb, (struct RBasic*)p->upper);
|
||||
mrb_gc_mark(mrb, (struct RBasic*)p->e.env);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -662,11 +659,8 @@ gc_mark_children(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
|
||||
struct REnv *e = (struct REnv*)obj;
|
||||
mrb_int i, len;
|
||||
|
||||
if (MRB_ENV_STACK_SHARED_P(e)) {
|
||||
if (e->cxt.c->fib) {
|
||||
mrb_gc_mark(mrb, (struct RBasic*)e->cxt.c->fib);
|
||||
}
|
||||
break;
|
||||
if (MRB_ENV_STACK_SHARED_P(e) && e->cxt->fib) {
|
||||
mrb_gc_mark(mrb, (struct RBasic*)e->cxt->fib);
|
||||
}
|
||||
len = MRB_ENV_STACK_LEN(e);
|
||||
for (i=0; i<len; i++) {
|
||||
|
||||
+21
-21
@@ -136,6 +136,7 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
mrb_value *bp;
|
||||
struct RProc *p;
|
||||
|
||||
bp = ci->stackent + 1;
|
||||
ci--;
|
||||
@@ -143,24 +144,20 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
|
||||
return mrb_false_value();
|
||||
}
|
||||
/* block_given? called within block; check upper scope */
|
||||
if (ci->proc->env) {
|
||||
struct REnv *e = ci->proc->env;
|
||||
|
||||
while (e->c) {
|
||||
e = (struct REnv*)e->c;
|
||||
}
|
||||
p = ci->proc;
|
||||
while (p) {
|
||||
if (MRB_PROC_SCOPE_P(p)) break;
|
||||
p = p->upper;
|
||||
}
|
||||
/* top-level does not have block slot (always false) */
|
||||
if (p == NULL) return mrb_false_value();
|
||||
if (MRB_PROC_ENV_P(p)) {
|
||||
struct REnv *e = MRB_PROC_ENV(p);
|
||||
/* top-level does not have block slot (always false) */
|
||||
if (e->stack == mrb->c->stbase)
|
||||
return mrb_false_value();
|
||||
if (e->stack && e->cioff < 0) {
|
||||
/* use saved block arg position */
|
||||
bp = &e->stack[-e->cioff];
|
||||
ci = 0; /* no callinfo available */
|
||||
}
|
||||
else {
|
||||
ci = e->cxt.c->cibase + e->cioff;
|
||||
bp = ci[1].stackent + 1;
|
||||
}
|
||||
/* use saved block arg position */
|
||||
bp = &e->stack[MRB_ENV_BIDX(e)];
|
||||
}
|
||||
if (ci && ci->argc > 0) {
|
||||
bp += ci->argc;
|
||||
@@ -659,7 +656,7 @@ method_entry_loop(mrb_state *mrb, struct RClass* klass, khash_t(st)* set)
|
||||
khint_t i;
|
||||
|
||||
khash_t(mt) *h = klass->mt;
|
||||
if (!h) return;
|
||||
if (!h || kh_size(h) == 0) return;
|
||||
for (i=0;i<kh_end(h);i++) {
|
||||
if (kh_exist(h, i) && kh_value(h, i)) {
|
||||
kh_put(st, mrb, set, kh_key(h, i));
|
||||
@@ -694,7 +691,7 @@ mrb_class_instance_method_list(mrb_state *mrb, mrb_bool recur, struct RClass* kl
|
||||
klass = klass->super;
|
||||
}
|
||||
|
||||
ary = mrb_ary_new(mrb);
|
||||
ary = mrb_ary_new_capa(mrb, kh_size(set));
|
||||
for (i=0;i<kh_end(set);i++) {
|
||||
if (kh_exist(set, i)) {
|
||||
mrb_ary_push(mrb, ary, mrb_symbol_value(kh_key(set, i)));
|
||||
@@ -1175,16 +1172,19 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
|
||||
return mrb_ary_new(mrb);
|
||||
}
|
||||
vars = mrb_hash_new(mrb);
|
||||
irep = proc->body.irep;
|
||||
while (irep) {
|
||||
while (proc) {
|
||||
if (MRB_PROC_CFUNC_P(proc)) break;
|
||||
irep = proc->body.irep;
|
||||
if (!irep->lv) break;
|
||||
for (i = 0; i + 1 < irep->nlocals; ++i) {
|
||||
if (irep->lv[i].name) {
|
||||
mrb_hash_set(mrb, vars, mrb_symbol_value(irep->lv[i].name), mrb_true_value());
|
||||
}
|
||||
}
|
||||
if (!proc->env) break;
|
||||
irep = irep->outer;
|
||||
if (!MRB_PROC_ENV_P(proc)) break;
|
||||
proc = proc->upper;
|
||||
// if (MRB_PROC_SCOPE_P(proc)) break;
|
||||
if (!proc->c) break;
|
||||
}
|
||||
|
||||
return mrb_hash_keys(mrb, vars);
|
||||
|
||||
@@ -1371,6 +1371,20 @@ num_cmp(mrb_state *mrb, mrb_value self)
|
||||
}
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
num_finite_p(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_get_args(mrb, "");
|
||||
return mrb_true_value();
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
num_infinite_p(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_get_args(mrb, "");
|
||||
return mrb_false_value();
|
||||
}
|
||||
|
||||
/* 15.2.9.3.1 */
|
||||
/*
|
||||
* call-seq:
|
||||
@@ -1406,6 +1420,8 @@ mrb_init_numeric(mrb_state *mrb)
|
||||
mrb_define_method(mrb, numeric, "/", num_div, MRB_ARGS_REQ(1)); /* 15.2.8.3.4 */
|
||||
mrb_define_method(mrb, numeric, "quo", num_div, MRB_ARGS_REQ(1)); /* 15.2.7.4.5 (x) */
|
||||
mrb_define_method(mrb, numeric, "<=>", num_cmp, MRB_ARGS_REQ(1)); /* 15.2.9.3.6 */
|
||||
mrb_define_method(mrb, numeric, "finite?", num_finite_p, MRB_ARGS_NONE());
|
||||
mrb_define_method(mrb, numeric, "infinite?",num_infinite_p, MRB_ARGS_NONE());
|
||||
|
||||
/* Integer Class */
|
||||
integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */
|
||||
|
||||
+47
-25
@@ -20,15 +20,19 @@ mrb_proc_new(mrb_state *mrb, mrb_irep *irep)
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
|
||||
p = (struct RProc*)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class);
|
||||
p->target_class = 0;
|
||||
if (ci) {
|
||||
if (ci->proc)
|
||||
p->target_class = ci->proc->target_class;
|
||||
if (!p->target_class)
|
||||
p->target_class = ci->target_class;
|
||||
struct RClass *tc = NULL;
|
||||
|
||||
if (ci->proc) {
|
||||
tc = MRB_PROC_TARGET_CLASS(ci->proc);
|
||||
}
|
||||
if (tc == NULL) {
|
||||
tc = ci->target_class;
|
||||
}
|
||||
p->upper = ci->proc;
|
||||
p->e.target_class = tc;
|
||||
}
|
||||
p->body.irep = irep;
|
||||
p->env = 0;
|
||||
mrb_irep_incref(mrb, irep);
|
||||
|
||||
return p;
|
||||
@@ -38,30 +42,45 @@ static struct REnv*
|
||||
env_new(mrb_state *mrb, mrb_int nlocals)
|
||||
{
|
||||
struct REnv *e;
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
int bidx;
|
||||
|
||||
e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass*)mrb->c->ci->proc->env);
|
||||
MRB_SET_ENV_STACK_LEN(e, nlocals);
|
||||
e->cxt.c = mrb->c;
|
||||
e->cioff = mrb->c->ci - mrb->c->cibase;
|
||||
e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, NULL);
|
||||
MRB_ENV_SET_STACK_LEN(e, nlocals);
|
||||
bidx = ci->argc;
|
||||
if (ci->argc < 0) bidx = 2;
|
||||
else bidx += 1;
|
||||
MRB_ENV_SET_BIDX(e, bidx);
|
||||
e->mid = ci->mid;
|
||||
e->stack = mrb->c->stack;
|
||||
e->cxt = mrb->c;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static void
|
||||
closure_setup(mrb_state *mrb, struct RProc *p, int nlocals)
|
||||
closure_setup(mrb_state *mrb, struct RProc *p)
|
||||
{
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
struct RProc *up = p->upper;
|
||||
struct REnv *e;
|
||||
|
||||
if (!mrb->c->ci->env) {
|
||||
e = env_new(mrb, nlocals);
|
||||
mrb->c->ci->env = e;
|
||||
if (ci->env) {
|
||||
e = ci->env;
|
||||
}
|
||||
else {
|
||||
e = mrb->c->ci->env;
|
||||
struct RClass *tc = MRB_PROC_TARGET_CLASS(up);
|
||||
|
||||
e = env_new(mrb, up->body.irep->nlocals);
|
||||
ci->env = e;
|
||||
if (tc) {
|
||||
e->c = tc;
|
||||
mrb_field_write_barrier(mrb, (struct RBasic*)e, (struct RBasic*)tc);
|
||||
}
|
||||
}
|
||||
p->env = e;
|
||||
mrb_field_write_barrier(mrb, (struct RBasic *)p, (struct RBasic *)p->env);
|
||||
p->e.env = e;
|
||||
p->flags |= MRB_PROC_ENVSET;
|
||||
mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)e);
|
||||
}
|
||||
|
||||
struct RProc*
|
||||
@@ -69,7 +88,7 @@ mrb_closure_new(mrb_state *mrb, mrb_irep *irep)
|
||||
{
|
||||
struct RProc *p = mrb_proc_new(mrb, irep);
|
||||
|
||||
closure_setup(mrb, p, mrb->c->ci->proc->body.irep->nlocals);
|
||||
closure_setup(mrb, p);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -81,7 +100,8 @@ mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func)
|
||||
p = (struct RProc*)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class);
|
||||
p->body.func = func;
|
||||
p->flags |= MRB_PROC_CFUNC;
|
||||
p->env = 0;
|
||||
p->upper = 0;
|
||||
p->e.target_class = 0;
|
||||
|
||||
return p;
|
||||
}
|
||||
@@ -93,8 +113,9 @@ mrb_proc_new_cfunc_with_env(mrb_state *mrb, mrb_func_t func, mrb_int argc, const
|
||||
struct REnv *e;
|
||||
int i;
|
||||
|
||||
p->env = e = env_new(mrb, argc);
|
||||
mrb_field_write_barrier(mrb, (struct RBasic *)p, (struct RBasic *)p->env);
|
||||
p->e.env = e = env_new(mrb, argc);
|
||||
p->flags |= MRB_PROC_ENVSET;
|
||||
mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)e);
|
||||
MRB_ENV_UNSHARE_STACK(e);
|
||||
e->stack = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value) * argc);
|
||||
if (argv) {
|
||||
@@ -120,7 +141,7 @@ MRB_API mrb_value
|
||||
mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx)
|
||||
{
|
||||
struct RProc *p = mrb->c->ci->proc;
|
||||
struct REnv *e = p->env;
|
||||
struct REnv *e = MRB_PROC_ENV(p);
|
||||
|
||||
if (!MRB_PROC_CFUNC_P(p)) {
|
||||
mrb_raise(mrb, E_TYPE_ERROR, "Can't get cfunc env from non-cfunc proc.");
|
||||
@@ -148,8 +169,9 @@ mrb_proc_copy(struct RProc *a, struct RProc *b)
|
||||
if (!MRB_PROC_CFUNC_P(a) && a->body.irep) {
|
||||
a->body.irep->refcnt++;
|
||||
}
|
||||
a->target_class = b->target_class;
|
||||
a->env = b->env;
|
||||
a->upper = b->upper;
|
||||
a->e.env = b->e.env;
|
||||
/* a->e.target_class = a->e.target_class; */
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
@@ -169,7 +191,7 @@ mrb_proc_s_new(mrb_state *mrb, mrb_value proc_class)
|
||||
proc = mrb_obj_value(p);
|
||||
mrb_funcall_with_block(mrb, proc, mrb_intern_lit(mrb, "initialize"), 0, NULL, proc);
|
||||
if (!MRB_PROC_STRICT_P(p) &&
|
||||
mrb->c->ci > mrb->c->cibase && p->env == mrb->c->ci[-1].env) {
|
||||
mrb->c->ci > mrb->c->cibase && MRB_PROC_ENV(p) == mrb->c->ci[-1].env) {
|
||||
p->flags |= MRB_PROC_ORPHAN;
|
||||
}
|
||||
return proc;
|
||||
|
||||
+2
-20
@@ -11,6 +11,7 @@
|
||||
#include <mruby/variable.h>
|
||||
#include <mruby/debug.h>
|
||||
#include <mruby/string.h>
|
||||
#include <mruby/class.h>
|
||||
|
||||
void mrb_init_core(mrb_state*);
|
||||
void mrb_init_mrbgems(mrb_state*);
|
||||
@@ -18,12 +19,6 @@ void mrb_init_mrbgems(mrb_state*);
|
||||
void mrb_gc_init(mrb_state*, mrb_gc *gc);
|
||||
void mrb_gc_destroy(mrb_state*, mrb_gc *gc);
|
||||
|
||||
static mrb_value
|
||||
inspect_main(mrb_state *mrb, mrb_value mod)
|
||||
{
|
||||
return mrb_str_new_lit(mrb, "main");
|
||||
}
|
||||
|
||||
MRB_API mrb_state*
|
||||
mrb_open_core(mrb_allocf f, void *ud)
|
||||
{
|
||||
@@ -145,11 +140,6 @@ mrb_irep_cutref(mrb_state *mrb, mrb_irep *irep)
|
||||
irep->reps[i] = NULL;
|
||||
if (tmp) mrb_irep_decref(mrb, tmp);
|
||||
}
|
||||
if (irep->outer) {
|
||||
tmp = irep->outer;
|
||||
irep->outer = NULL;
|
||||
if (tmp) mrb_irep_decref(mrb, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -176,10 +166,6 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
|
||||
if (irep->reps[i])
|
||||
mrb_irep_decref(mrb, irep->reps[i]);
|
||||
}
|
||||
if (irep->outer) {
|
||||
if (irep->outer)
|
||||
mrb_irep_decref(mrb, irep->outer);
|
||||
}
|
||||
mrb_free(mrb, irep->reps);
|
||||
mrb_free(mrb, irep->lv);
|
||||
if (irep->own_filename) {
|
||||
@@ -237,6 +223,7 @@ mrb_str_pool(mrb_state *mrb, mrb_value str)
|
||||
ns->as.heap.ptr[len] = '\0';
|
||||
}
|
||||
}
|
||||
RSTR_SET_POOL_FLAG(ns);
|
||||
MRB_SET_FROZEN_FLAG(ns);
|
||||
return mrb_obj_value(ns);
|
||||
}
|
||||
@@ -294,11 +281,6 @@ mrb_add_irep(mrb_state *mrb)
|
||||
MRB_API mrb_value
|
||||
mrb_top_self(mrb_state *mrb)
|
||||
{
|
||||
if (!mrb->top_self) {
|
||||
mrb->top_self = (struct RObject*)mrb_obj_alloc(mrb, MRB_TT_OBJECT, mrb->object_class);
|
||||
mrb_define_singleton_method(mrb, mrb->top_self, "inspect", inspect_main, MRB_ARGS_NONE());
|
||||
mrb_define_singleton_method(mrb, mrb->top_self, "to_s", inspect_main, MRB_ARGS_NONE());
|
||||
}
|
||||
return mrb_obj_value(mrb->top_self);
|
||||
}
|
||||
|
||||
|
||||
+61
-89
@@ -59,7 +59,7 @@ str_new(mrb_state *mrb, const char *p, size_t len)
|
||||
return str_new_static(mrb, p, len);
|
||||
}
|
||||
s = mrb_obj_alloc_string(mrb);
|
||||
if (len < RSTRING_EMBED_LEN_MAX) {
|
||||
if (len <= RSTRING_EMBED_LEN_MAX) {
|
||||
RSTR_SET_EMBED_FLAG(s);
|
||||
RSTR_SET_EMBED_LEN(s, len);
|
||||
if (p) {
|
||||
@@ -343,48 +343,59 @@ mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n)
|
||||
return mrb_memsearch_qs((const unsigned char *)x0, m, (const unsigned char *)y0, n);
|
||||
}
|
||||
|
||||
static mrb_bool
|
||||
str_make_shared(mrb_state *mrb, struct RString *s)
|
||||
static void
|
||||
str_make_shared(mrb_state *mrb, struct RString *orig, struct RString *s)
|
||||
{
|
||||
if (!RSTR_SHARED_P(s)) {
|
||||
if (MRB_FROZEN_P(s) || RSTR_FSHARED_P(s)) {
|
||||
return FALSE;
|
||||
mrb_shared_string *shared;
|
||||
mrb_int len = RSTR_LEN(orig);
|
||||
|
||||
mrb_assert(!RSTR_EMBED_P(orig));
|
||||
if (RSTR_SHARED_P(orig)) {
|
||||
shared = orig->as.heap.aux.shared;
|
||||
shared->refcnt++;
|
||||
s->as.heap.ptr = orig->as.heap.ptr;
|
||||
s->as.heap.len = len;
|
||||
s->as.heap.aux.shared = shared;
|
||||
RSTR_SET_SHARED_FLAG(s);
|
||||
RSTR_UNSET_EMBED_FLAG(s);
|
||||
}
|
||||
else if (RSTR_FSHARED_P(orig)) {
|
||||
struct RString *fs;
|
||||
|
||||
fs = orig->as.heap.aux.fshared;
|
||||
s->as.heap.ptr = orig->as.heap.ptr;
|
||||
s->as.heap.len = len;
|
||||
s->as.heap.aux.fshared = fs;
|
||||
RSTR_SET_FSHARED_FLAG(s);
|
||||
RSTR_UNSET_EMBED_FLAG(s);
|
||||
}
|
||||
else if (MRB_FROZEN_P(orig) && !RSTR_POOL_P(orig)) {
|
||||
s->as.heap.ptr = orig->as.heap.ptr;
|
||||
s->as.heap.len = len;
|
||||
s->as.heap.aux.fshared = orig;
|
||||
RSTR_SET_FSHARED_FLAG(s);
|
||||
RSTR_UNSET_EMBED_FLAG(s);
|
||||
}
|
||||
else {
|
||||
shared = (mrb_shared_string *)mrb_malloc(mrb, sizeof(mrb_shared_string));
|
||||
shared->refcnt = 2;
|
||||
shared->nofree = !!RSTR_NOFREE_P(orig);
|
||||
if (!shared->nofree && orig->as.heap.aux.capa > orig->as.heap.len) {
|
||||
shared->ptr = (char *)mrb_realloc(mrb, orig->as.heap.ptr, len+1);
|
||||
orig->as.heap.ptr = shared->ptr;
|
||||
}
|
||||
else {
|
||||
mrb_shared_string *shared = (mrb_shared_string *)mrb_malloc(mrb, sizeof(mrb_shared_string));
|
||||
|
||||
shared->refcnt = 1;
|
||||
if (RSTR_EMBED_P(s)) {
|
||||
const mrb_int len = RSTR_EMBED_LEN(s);
|
||||
char *const tmp = (char *)mrb_malloc(mrb, len+1);
|
||||
memcpy(tmp, s->as.ary, len);
|
||||
tmp[len] = '\0';
|
||||
RSTR_UNSET_EMBED_FLAG(s);
|
||||
s->as.heap.ptr = tmp;
|
||||
s->as.heap.len = len;
|
||||
shared->nofree = FALSE;
|
||||
shared->ptr = s->as.heap.ptr;
|
||||
}
|
||||
else if (RSTR_NOFREE_P(s)) {
|
||||
shared->nofree = TRUE;
|
||||
shared->ptr = s->as.heap.ptr;
|
||||
RSTR_UNSET_NOFREE_FLAG(s);
|
||||
}
|
||||
else {
|
||||
shared->nofree = FALSE;
|
||||
if (s->as.heap.aux.capa > s->as.heap.len) {
|
||||
s->as.heap.ptr = shared->ptr = (char *)mrb_realloc(mrb, s->as.heap.ptr, s->as.heap.len+1);
|
||||
}
|
||||
else {
|
||||
shared->ptr = s->as.heap.ptr;
|
||||
}
|
||||
}
|
||||
shared->len = s->as.heap.len;
|
||||
s->as.heap.aux.shared = shared;
|
||||
RSTR_SET_SHARED_FLAG(s);
|
||||
shared->ptr = orig->as.heap.ptr;
|
||||
}
|
||||
orig->as.heap.aux.shared = shared;
|
||||
RSTR_SET_SHARED_FLAG(orig);
|
||||
shared->len = len;
|
||||
s->as.heap.aux.shared = shared;
|
||||
s->as.heap.ptr = shared->ptr;
|
||||
s->as.heap.len = len;
|
||||
RSTR_SET_SHARED_FLAG(s);
|
||||
RSTR_UNSET_EMBED_FLAG(s);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
@@ -393,32 +404,15 @@ byte_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
|
||||
struct RString *orig, *s;
|
||||
|
||||
orig = mrb_str_ptr(str);
|
||||
if (RSTR_EMBED_P(orig) || RSTR_LEN(orig) == 0) {
|
||||
s = str_new(mrb, orig->as.ary+beg, len);
|
||||
}
|
||||
else if (str_make_shared(mrb, orig)) {
|
||||
mrb_shared_string *shared = orig->as.heap.aux.shared;
|
||||
|
||||
s = mrb_obj_alloc_string(mrb);
|
||||
s->as.heap.ptr = orig->as.heap.ptr + beg;
|
||||
s->as.heap.len = len;
|
||||
s->as.heap.aux.shared = shared;
|
||||
RSTR_SET_SHARED_FLAG(s);
|
||||
shared->refcnt++;
|
||||
if (RSTR_EMBED_P(orig) || RSTR_LEN(orig) == 0 || len <= RSTRING_EMBED_LEN_MAX) {
|
||||
s = str_new(mrb, RSTR_PTR(orig)+beg, len);
|
||||
}
|
||||
else {
|
||||
s = mrb_obj_alloc_string(mrb);
|
||||
s->as.heap.ptr = orig->as.heap.ptr + beg;
|
||||
str_make_shared(mrb, orig, s);
|
||||
s->as.heap.ptr += beg;
|
||||
s->as.heap.len = len;
|
||||
if (MRB_FROZEN_P(orig)) {
|
||||
s->as.heap.aux.fshared = orig;
|
||||
}
|
||||
else {
|
||||
s->as.heap.aux.fshared = orig->as.heap.aux.fshared;
|
||||
}
|
||||
RSTR_SET_FSHARED_FLAG(s);
|
||||
}
|
||||
|
||||
return mrb_obj_value(s);
|
||||
}
|
||||
#ifdef MRB_UTF8_STRING
|
||||
@@ -525,38 +519,15 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2)
|
||||
|
||||
RSTR_UNSET_FSHARED_FLAG(s1);
|
||||
RSTR_UNSET_NOFREE_FLAG(s1);
|
||||
RSTR_UNSET_EMBED_FLAG(s1);
|
||||
|
||||
if (MRB_FROZEN_P(s2)) {
|
||||
RSTR_SET_FSHARED_FLAG(s1);
|
||||
s1->as.heap.ptr = RSTR_PTR(s2);
|
||||
s1->as.heap.len = len;
|
||||
s1->as.heap.aux.fshared = s2;
|
||||
}
|
||||
else if (RSTR_FSHARED_P(s2)) {
|
||||
RSTR_SET_FSHARED_FLAG(s1);
|
||||
s1->as.heap.ptr = s2->as.heap.ptr;
|
||||
s1->as.heap.len = len;
|
||||
s1->as.heap.aux.fshared = s2->as.heap.aux.fshared;
|
||||
}
|
||||
else if (RSTR_SHARED_P(s2)) {
|
||||
L_SHARE:
|
||||
RSTR_SET_SHARED_FLAG(s1);
|
||||
s1->as.heap.ptr = s2->as.heap.ptr;
|
||||
s1->as.heap.len = len;
|
||||
s1->as.heap.aux.shared = s2->as.heap.aux.shared;
|
||||
s1->as.heap.aux.shared->refcnt++;
|
||||
if (len <= RSTRING_EMBED_LEN_MAX) {
|
||||
RSTR_UNSET_SHARED_FLAG(s1);
|
||||
RSTR_UNSET_FSHARED_FLAG(s1);
|
||||
RSTR_SET_EMBED_FLAG(s1);
|
||||
memcpy(s1->as.ary, RSTR_PTR(s2), len);
|
||||
RSTR_SET_EMBED_LEN(s1, len);
|
||||
}
|
||||
else {
|
||||
if (len <= RSTRING_EMBED_LEN_MAX) {
|
||||
RSTR_SET_EMBED_FLAG(s1);
|
||||
memcpy(s1->as.ary, RSTR_PTR(s2), len);
|
||||
RSTR_SET_EMBED_LEN(s1, len);
|
||||
}
|
||||
else {
|
||||
str_make_shared(mrb, s2);
|
||||
goto L_SHARE;
|
||||
}
|
||||
str_make_shared(mrb, s2, s1);
|
||||
}
|
||||
|
||||
return mrb_obj_value(s1);
|
||||
@@ -712,6 +683,7 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)
|
||||
char *p = s->as.heap.ptr;
|
||||
mrb_int len = s->as.heap.len;
|
||||
|
||||
RSTR_UNSET_FSHARED_FLAG(s);
|
||||
RSTR_UNSET_NOFREE_FLAG(s);
|
||||
RSTR_UNSET_FSHARED_FLAG(s);
|
||||
if (len < RSTRING_EMBED_LEN_MAX) {
|
||||
|
||||
+20
-24
@@ -632,19 +632,18 @@ mrb_cv_defined(mrb_state *mrb, mrb_value mod, mrb_sym sym)
|
||||
mrb_value
|
||||
mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym)
|
||||
{
|
||||
struct RClass *c = mrb->c->ci->proc->target_class;
|
||||
|
||||
if (!c) c = mrb->c->ci->target_class;
|
||||
struct RClass *c;
|
||||
|
||||
c = MRB_PROC_TARGET_CLASS(mrb->c->ci->proc);
|
||||
return mrb_mod_cv_get(mrb, c, sym);
|
||||
}
|
||||
|
||||
void
|
||||
mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v)
|
||||
{
|
||||
struct RClass *c = mrb->c->ci->proc->target_class;
|
||||
struct RClass *c;
|
||||
|
||||
if (!c) c = mrb->c->ci->target_class;
|
||||
c = MRB_PROC_TARGET_CLASS(mrb->c->ci->proc);
|
||||
mrb_mod_cv_set(mrb, c, sym, v);
|
||||
}
|
||||
|
||||
@@ -663,17 +662,18 @@ mod_const_check(mrb_state *mrb, mrb_value mod)
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym)
|
||||
const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym, mrb_bool top)
|
||||
{
|
||||
struct RClass *c = base;
|
||||
mrb_value v;
|
||||
iv_tbl *t;
|
||||
mrb_bool retry = FALSE;
|
||||
mrb_value name;
|
||||
struct RClass *oclass = mrb->object_class;
|
||||
|
||||
L_RETRY:
|
||||
while (c) {
|
||||
if (c->iv) {
|
||||
if (c->iv && (top || c != oclass || base == oclass)) {
|
||||
t = c->iv;
|
||||
if (iv_get(mrb, t, sym, &v))
|
||||
return v;
|
||||
@@ -693,20 +693,18 @@ MRB_API mrb_value
|
||||
mrb_const_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
|
||||
{
|
||||
mod_const_check(mrb, mod);
|
||||
return const_get(mrb, mrb_class_ptr(mod), sym);
|
||||
return const_get(mrb, mrb_class_ptr(mod), sym, FALSE);
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
|
||||
{
|
||||
struct RClass *c = mrb->c->ci->proc->target_class;
|
||||
struct RClass *c;
|
||||
struct RClass *c2;
|
||||
mrb_value v;
|
||||
mrb_irep *irep;
|
||||
|
||||
if (!c) c = mrb->c->ci->target_class;
|
||||
mrb_assert(c != NULL);
|
||||
struct RProc *proc;
|
||||
|
||||
c = MRB_PROC_TARGET_CLASS(mrb->c->ci->proc);
|
||||
if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
|
||||
return v;
|
||||
}
|
||||
@@ -719,17 +717,15 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
|
||||
}
|
||||
if (c2->tt == MRB_TT_CLASS || c2->tt == MRB_TT_MODULE) c = c2;
|
||||
mrb_assert(!MRB_PROC_CFUNC_P(mrb->c->ci->proc));
|
||||
irep = mrb->c->ci->proc->body.irep;
|
||||
while (irep) {
|
||||
if (irep->target_class) {
|
||||
c2 = irep->target_class;
|
||||
if (c2->iv && iv_get(mrb, c2->iv, sym, &v)) {
|
||||
return v;
|
||||
}
|
||||
proc = mrb->c->ci->proc;
|
||||
while (proc) {
|
||||
c2 = MRB_PROC_TARGET_CLASS(proc);
|
||||
if (c2 && c2->iv && iv_get(mrb, c2->iv, sym, &v)) {
|
||||
return v;
|
||||
}
|
||||
irep = irep->outer;
|
||||
proc = proc->upper;
|
||||
}
|
||||
return const_get(mrb, c, sym);
|
||||
return const_get(mrb, c, sym, TRUE);
|
||||
}
|
||||
|
||||
MRB_API void
|
||||
@@ -745,9 +741,9 @@ mrb_const_set(mrb_state *mrb, mrb_value mod, mrb_sym sym, mrb_value v)
|
||||
void
|
||||
mrb_vm_const_set(mrb_state *mrb, mrb_sym sym, mrb_value v)
|
||||
{
|
||||
struct RClass *c = mrb->c->ci->proc->target_class;
|
||||
struct RClass *c;
|
||||
|
||||
if (!c) c = mrb->c->ci->target_class;
|
||||
c = MRB_PROC_TARGET_CLASS(mrb->c->ci->proc);
|
||||
mrb_obj_iv_set(mrb, (struct RObject*)c, sym, v);
|
||||
}
|
||||
|
||||
|
||||
@@ -211,38 +211,38 @@ stack_extend(mrb_state *mrb, int room)
|
||||
static inline struct REnv*
|
||||
uvenv(mrb_state *mrb, int up)
|
||||
{
|
||||
struct REnv *e = mrb->c->ci->proc->env;
|
||||
struct RProc *proc = mrb->c->ci->proc;
|
||||
struct REnv *e;
|
||||
|
||||
while (up--) {
|
||||
if (!e) return NULL;
|
||||
e = (struct REnv*)e->c;
|
||||
proc = proc->upper;
|
||||
if (!proc) return NULL;
|
||||
}
|
||||
return e;
|
||||
e = MRB_PROC_ENV(proc);
|
||||
if (e) return e; /* proc has enclosed env */
|
||||
else {
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
mrb_callinfo *cb = mrb->c->cibase;
|
||||
|
||||
while (cb <= ci) {
|
||||
if (ci->proc == proc) {
|
||||
return ci->env;
|
||||
}
|
||||
ci--;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline mrb_bool
|
||||
is_strict(mrb_state *mrb, struct REnv *e)
|
||||
static inline struct RProc*
|
||||
top_proc(mrb_state *mrb, struct RProc *proc)
|
||||
{
|
||||
ptrdiff_t cioff = e->cioff;
|
||||
|
||||
if (MRB_ENV_STACK_SHARED_P(e) && e->cxt.c->cibase[cioff].proc &&
|
||||
MRB_PROC_STRICT_P(e->cxt.c->cibase[cioff].proc)) {
|
||||
return TRUE;
|
||||
while (proc->upper) {
|
||||
if (MRB_PROC_SCOPE_P(proc) || MRB_PROC_STRICT_P(proc))
|
||||
return proc;
|
||||
proc = proc->upper;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline struct REnv*
|
||||
top_env(mrb_state *mrb, struct RProc *proc)
|
||||
{
|
||||
struct REnv *e = proc->env;
|
||||
|
||||
if (is_strict(mrb, e)) return e;
|
||||
while (e->c) {
|
||||
e = (struct REnv*)e->c;
|
||||
if (is_strict(mrb, e)) return e;
|
||||
}
|
||||
return e;
|
||||
return proc;
|
||||
}
|
||||
|
||||
#define CI_ACC_SKIP -1
|
||||
@@ -273,25 +273,17 @@ cipush(mrb_state *mrb)
|
||||
return ci;
|
||||
}
|
||||
|
||||
MRB_API void
|
||||
void
|
||||
mrb_env_unshare(mrb_state *mrb, struct REnv *e)
|
||||
{
|
||||
if (e == NULL) return;
|
||||
else {
|
||||
size_t len = (size_t)MRB_ENV_STACK_LEN(e);
|
||||
ptrdiff_t cioff = e->cioff;
|
||||
mrb_value *p;
|
||||
|
||||
if (!MRB_ENV_STACK_SHARED_P(e)) return;
|
||||
if (e->cxt.c != mrb->c) return;
|
||||
if (e->cioff == 0 && e->cxt.c == mrb->root_c) return;
|
||||
if (e->cxt != mrb->c) return;
|
||||
MRB_ENV_UNSHARE_STACK(e);
|
||||
if (!e->c) {
|
||||
/* save block argument position (negated) */
|
||||
e->cioff = -e->cxt.c->cibase[cioff].argc-1;
|
||||
if (e->cioff == 0) e->cioff = -2; /* blkarg position for vararg (1:args, 2:blk) */
|
||||
}
|
||||
e->cxt.mid = e->cxt.c->cibase[cioff].mid;
|
||||
p = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*len);
|
||||
if (len > 0) {
|
||||
stack_copy(p, e->stack, len);
|
||||
@@ -317,20 +309,22 @@ static void
|
||||
ecall(mrb_state *mrb, int i)
|
||||
{
|
||||
struct RProc *p;
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
mrb_value *self = mrb->c->stack;
|
||||
struct mrb_context *c = mrb->c;
|
||||
mrb_callinfo *ci = c->ci;
|
||||
struct RObject *exc;
|
||||
struct REnv *env;
|
||||
ptrdiff_t cioff;
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
|
||||
if (i<0) return;
|
||||
if (ci - mrb->c->cibase > MRB_FUNCALL_DEPTH_MAX) {
|
||||
if (ci - c->cibase > MRB_FUNCALL_DEPTH_MAX) {
|
||||
mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
|
||||
}
|
||||
p = mrb->c->ensure[i];
|
||||
p = c->ensure[i];
|
||||
if (!p) return;
|
||||
mrb->c->ensure[i] = NULL;
|
||||
cioff = ci - mrb->c->cibase;
|
||||
mrb_assert(!MRB_PROC_CFUNC_P(p));
|
||||
c->ensure[i] = NULL;
|
||||
cioff = ci - c->cibase;
|
||||
ci = cipush(mrb);
|
||||
ci->stackent = mrb->c->stack;
|
||||
ci->mid = ci[-1].mid;
|
||||
@@ -338,14 +332,17 @@ ecall(mrb_state *mrb, int i)
|
||||
ci->argc = 0;
|
||||
ci->proc = p;
|
||||
ci->nregs = p->body.irep->nregs;
|
||||
ci->target_class = p->target_class;
|
||||
mrb->c->stack = mrb->c->stack + ci[-1].nregs;
|
||||
ci->target_class = MRB_PROC_TARGET_CLASS(p);
|
||||
env = MRB_PROC_ENV(p);
|
||||
mrb_assert(env);
|
||||
c->stack += p->body.irep->nregs;
|
||||
exc = mrb->exc; mrb->exc = 0;
|
||||
if (exc) {
|
||||
mrb_gc_protect(mrb, mrb_obj_value(exc));
|
||||
}
|
||||
mrb_run(mrb, p, *self);
|
||||
mrb->c->ci = mrb->c->cibase + cioff;
|
||||
mrb_run(mrb, p, env->stack[0]);
|
||||
mrb->c = c;
|
||||
c->ci = c->cibase + cioff;
|
||||
if (!mrb->exc) mrb->exc = exc;
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
}
|
||||
@@ -497,7 +494,7 @@ mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p)
|
||||
|
||||
mrb->c->stack[0] = self;
|
||||
ci->proc = p;
|
||||
ci->target_class = p->target_class;
|
||||
ci->target_class = MRB_PROC_TARGET_CLASS(p);
|
||||
if (MRB_PROC_CFUNC_P(p)) {
|
||||
return p->body.func(mrb, self);
|
||||
}
|
||||
@@ -734,7 +731,7 @@ mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv)
|
||||
{
|
||||
struct RProc *p = mrb_proc_ptr(b);
|
||||
|
||||
return mrb_yield_with_class(mrb, b, argc, argv, p->env->stack[0], p->target_class);
|
||||
return mrb_yield_with_class(mrb, b, argc, argv, MRB_PROC_ENV(p)->stack[0], MRB_PROC_TARGET_CLASS(p));
|
||||
}
|
||||
|
||||
MRB_API mrb_value
|
||||
@@ -742,7 +739,7 @@ mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg)
|
||||
{
|
||||
struct RProc *p = mrb_proc_ptr(b);
|
||||
|
||||
return mrb_yield_with_class(mrb, b, 1, &arg, p->env->stack[0], p->target_class);
|
||||
return mrb_yield_with_class(mrb, b, 1, &arg, MRB_PROC_ENV(p)->stack[0], MRB_PROC_TARGET_CLASS(p));
|
||||
}
|
||||
|
||||
mrb_value
|
||||
@@ -772,23 +769,23 @@ mrb_value
|
||||
mrb_mod_s_nesting(mrb_state *mrb, mrb_value mod)
|
||||
{
|
||||
struct RProc *proc;
|
||||
mrb_irep *irep;
|
||||
mrb_value ary;
|
||||
struct RClass *c;
|
||||
struct RClass *c = NULL;
|
||||
|
||||
mrb_get_args(mrb, "");
|
||||
ary = mrb_ary_new(mrb);
|
||||
proc = mrb->c->ci[-1].proc; /* callee proc */
|
||||
c = proc->target_class;
|
||||
mrb_ary_push(mrb, ary, mrb_obj_value(c));
|
||||
mrb_assert(!MRB_PROC_CFUNC_P(proc));
|
||||
irep = proc->body.irep;
|
||||
while (irep) {
|
||||
if (irep->target_class && irep->target_class != c) {
|
||||
c = irep->target_class;
|
||||
mrb_ary_push(mrb, ary, mrb_obj_value(c));
|
||||
while (proc) {
|
||||
if (MRB_PROC_SCOPE_P(proc)) {
|
||||
struct RClass *c2 = MRB_PROC_TARGET_CLASS(proc);
|
||||
|
||||
if (c2 != c) {
|
||||
c = c2;
|
||||
mrb_ary_push(mrb, ary, mrb_obj_value(c));
|
||||
}
|
||||
}
|
||||
irep = irep->outer;
|
||||
proc = proc->upper;
|
||||
}
|
||||
return ary;
|
||||
}
|
||||
@@ -854,18 +851,6 @@ argnum_error(mrb_state *mrb, mrb_int num)
|
||||
mrb_exc_set(mrb, exc);
|
||||
}
|
||||
|
||||
void
|
||||
irep_uplink(mrb_state *mrb, mrb_irep *outer, mrb_irep *irep)
|
||||
{
|
||||
if (irep->outer != outer) {
|
||||
if (irep->outer) {
|
||||
mrb_irep_decref(mrb, irep->outer);
|
||||
}
|
||||
irep->outer = outer;
|
||||
mrb_irep_incref(mrb, outer);
|
||||
}
|
||||
}
|
||||
|
||||
#define ERR_PC_SET(mrb, pc) mrb->c->ci->err = pc;
|
||||
#define ERR_PC_CLR(mrb) mrb->c->ci->err = 0;
|
||||
#ifdef MRB_ENABLE_DEBUG_HOOK
|
||||
@@ -1323,9 +1308,10 @@ RETRY_TRY_BLOCK:
|
||||
CASE(OP_EPOP) {
|
||||
/* A A.times{ensure_pop().call} */
|
||||
int a = GETARG_A(i);
|
||||
int n, epos = mrb->c->ci->epos;
|
||||
mrb_callinfo *ci;
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
int n, epos = ci->epos;
|
||||
mrb_value self = regs[0];
|
||||
struct RClass *target_class = ci->target_class;
|
||||
|
||||
if (mrb->c->eidx == epos) {
|
||||
NEXT;
|
||||
@@ -1343,7 +1329,7 @@ RETRY_TRY_BLOCK:
|
||||
ci->proc = proc;
|
||||
ci->stackent = mrb->c->stack;
|
||||
ci->nregs = irep->nregs;
|
||||
ci->target_class = proc->target_class;
|
||||
ci->target_class = target_class;
|
||||
ci->pc = pc;
|
||||
ci->acc = ci[-1].nregs;
|
||||
mrb->c->stack += ci->acc;
|
||||
@@ -1445,7 +1431,7 @@ RETRY_TRY_BLOCK:
|
||||
if (GET_OPCODE(i) == OP_SENDB) {
|
||||
if (mrb_type(blk) == MRB_TT_PROC) {
|
||||
struct RProc *p = mrb_proc_ptr(blk);
|
||||
if (p && !MRB_PROC_STRICT_P(p) && p->env == ci[-1].env) {
|
||||
if (p && !MRB_PROC_STRICT_P(p) && MRB_PROC_ENV(p) == ci[-1].env) {
|
||||
p->flags |= MRB_PROC_ORPHAN;
|
||||
}
|
||||
}
|
||||
@@ -1497,20 +1483,16 @@ RETRY_TRY_BLOCK:
|
||||
|
||||
/* replace callinfo */
|
||||
ci = mrb->c->ci;
|
||||
ci->target_class = m->target_class;
|
||||
ci->target_class = MRB_PROC_TARGET_CLASS(m);
|
||||
ci->proc = m;
|
||||
if (m->env) {
|
||||
if (MRB_PROC_ENV_P(m)) {
|
||||
mrb_sym mid;
|
||||
struct REnv *e = MRB_PROC_ENV(m);
|
||||
|
||||
if (MRB_ENV_STACK_SHARED_P(m->env)) {
|
||||
mid = m->env->cxt.c->cibase[m->env->cioff].mid;
|
||||
}
|
||||
else {
|
||||
mid = m->env->cxt.mid;
|
||||
}
|
||||
mid = e->mid;
|
||||
if (mid) ci->mid = mid;
|
||||
if (!m->env->stack) {
|
||||
m->env->stack = mrb->c->stack;
|
||||
if (!e->stack) {
|
||||
e->stack = mrb->c->stack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1551,8 +1533,8 @@ RETRY_TRY_BLOCK:
|
||||
else if (ci->argc+2 < irep->nregs) {
|
||||
stack_clear(regs+ci->argc+2, irep->nregs-ci->argc-2);
|
||||
}
|
||||
if (m->env) {
|
||||
regs[0] = m->env->stack[0];
|
||||
if (MRB_PROC_ENV_P(m)) {
|
||||
regs[0] = MRB_PROC_ENV(m)->stack[0];
|
||||
}
|
||||
pc = irep->iseq;
|
||||
JUMP;
|
||||
@@ -1837,6 +1819,12 @@ RETRY_TRY_BLOCK:
|
||||
/* A B return R(A) (B=normal,in-block return/break) */
|
||||
mrb_callinfo *ci;
|
||||
|
||||
#define ecall_adjust() do {\
|
||||
ptrdiff_t cioff = ci - mrb->c->cibase;\
|
||||
ecall(mrb, --mrb->c->eidx);\
|
||||
ci = mrb->c->cibase + cioff;\
|
||||
} while (0)
|
||||
|
||||
ci = mrb->c->ci;
|
||||
if (ci->mid) {
|
||||
mrb_value blk;
|
||||
@@ -1851,7 +1839,7 @@ RETRY_TRY_BLOCK:
|
||||
struct RProc *p = mrb_proc_ptr(blk);
|
||||
|
||||
if (!MRB_PROC_STRICT_P(p) &&
|
||||
ci > mrb->c->cibase && p->env == ci[-1].env) {
|
||||
ci > mrb->c->cibase && MRB_PROC_ENV(p) == ci[-1].env) {
|
||||
p->flags |= MRB_PROC_ORPHAN;
|
||||
}
|
||||
}
|
||||
@@ -1901,8 +1889,7 @@ RETRY_TRY_BLOCK:
|
||||
if (ci[0].ridx == ci[-1].ridx) {
|
||||
mrb_value *org_stbase = mrb->c->stbase;
|
||||
while (mrb->c->eidx > ci->epos) {
|
||||
ecall(mrb, --mrb->c->eidx);
|
||||
ci = mrb->c->ci;
|
||||
ecall_adjust();
|
||||
if (org_stbase != mrb->c->stbase) {
|
||||
stk = mrb->c->stack;
|
||||
}
|
||||
@@ -1915,7 +1902,7 @@ RETRY_TRY_BLOCK:
|
||||
irep = proc->body.irep;
|
||||
pool = irep->pool;
|
||||
syms = irep->syms;
|
||||
if (ci != ci0) {
|
||||
if (ci < ci0) {
|
||||
mrb->c->stack = ci[1].stackent;
|
||||
}
|
||||
stack_extend(mrb, irep->nregs);
|
||||
@@ -1924,37 +1911,37 @@ RETRY_TRY_BLOCK:
|
||||
else {
|
||||
int acc;
|
||||
mrb_value v;
|
||||
struct RProc *dst;
|
||||
|
||||
ci = mrb->c->ci;
|
||||
v = regs[GETARG_A(i)];
|
||||
mrb_gc_protect(mrb, v);
|
||||
switch (GETARG_B(i)) {
|
||||
case OP_R_RETURN:
|
||||
/* Fall through to OP_R_NORMAL otherwise */
|
||||
if (ci->acc >=0 && proc->env && !MRB_PROC_STRICT_P(proc)) {
|
||||
struct REnv *e = top_env(mrb, proc);
|
||||
mrb_callinfo *ce;
|
||||
if (ci->acc >=0 && MRB_PROC_ENV_P(proc) && !MRB_PROC_STRICT_P(proc)) {
|
||||
mrb_callinfo *cibase = mrb->c->cibase;
|
||||
dst = top_proc(mrb, proc);
|
||||
|
||||
if (!MRB_ENV_STACK_SHARED_P(e) || e->cxt.c != mrb->c) {
|
||||
localjump_error(mrb, LOCALJUMP_ERROR_RETURN);
|
||||
goto L_RAISE;
|
||||
if (MRB_PROC_ENV_P(dst)) {
|
||||
struct REnv *e = MRB_PROC_ENV(dst);
|
||||
|
||||
if (!MRB_ENV_STACK_SHARED_P(e) || e->cxt != mrb->c) {
|
||||
localjump_error(mrb, LOCALJUMP_ERROR_RETURN);
|
||||
goto L_RAISE;
|
||||
}
|
||||
}
|
||||
|
||||
ce = mrb->c->cibase + e->cioff;
|
||||
while (ci > ce) {
|
||||
mrb_env_unshare(mrb, ci->env);
|
||||
while (cibase <= ci && ci->proc != dst) {
|
||||
if (ci->acc < 0) {
|
||||
localjump_error(mrb, LOCALJUMP_ERROR_RETURN);
|
||||
goto L_RAISE;
|
||||
}
|
||||
ci--;
|
||||
}
|
||||
mrb_env_unshare(mrb, ci->env);
|
||||
if (ce == mrb->c->cibase) {
|
||||
if (ci <= cibase) {
|
||||
localjump_error(mrb, LOCALJUMP_ERROR_RETURN);
|
||||
goto L_RAISE;
|
||||
}
|
||||
mrb->c->stack = mrb->c->ci->stackent;
|
||||
mrb->c->ci = ce;
|
||||
break;
|
||||
}
|
||||
case OP_R_NORMAL:
|
||||
@@ -1970,14 +1957,14 @@ RETRY_TRY_BLOCK:
|
||||
goto L_RAISE;
|
||||
}
|
||||
while (mrb->c->eidx > 0) {
|
||||
ecall(mrb, --mrb->c->eidx);
|
||||
ecall_adjust();
|
||||
}
|
||||
/* automatic yield at the end */
|
||||
mrb->c->status = MRB_FIBER_TERMINATED;
|
||||
mrb->c = mrb->c->prev;
|
||||
mrb->c->status = MRB_FIBER_RUNNING;
|
||||
ci = mrb->c->ci;
|
||||
}
|
||||
ci = mrb->c->ci;
|
||||
break;
|
||||
case OP_R_BREAK:
|
||||
if (MRB_PROC_STRICT_P(proc)) goto NORMAL_RETURN;
|
||||
@@ -1990,23 +1977,23 @@ RETRY_TRY_BLOCK:
|
||||
mrb_exc_set(mrb, exc);
|
||||
goto L_RAISE;
|
||||
}
|
||||
if (!proc->env || !MRB_ENV_STACK_SHARED_P(proc->env)) {
|
||||
if (!MRB_PROC_ENV_P(proc) || !MRB_ENV_STACK_SHARED_P(MRB_PROC_ENV(proc))) {
|
||||
goto L_BREAK_ERROR;
|
||||
}
|
||||
if (proc->env->cxt.c != mrb->c) {
|
||||
if (MRB_PROC_ENV(proc)->cxt != mrb->c) {
|
||||
goto L_BREAK_ERROR;
|
||||
}
|
||||
while (mrb->c->eidx > mrb->c->ci->epos) {
|
||||
ecall(mrb, --mrb->c->eidx);
|
||||
ecall_adjust();
|
||||
}
|
||||
/* break from fiber block */
|
||||
if (mrb->c->ci == mrb->c->cibase && mrb->c->ci->pc) {
|
||||
if (ci == mrb->c->cibase && ci->pc) {
|
||||
struct mrb_context *c = mrb->c;
|
||||
|
||||
mrb->c = c->prev;
|
||||
c->prev = NULL;
|
||||
ci = mrb->c->ci;
|
||||
}
|
||||
ci = mrb->c->ci;
|
||||
if (ci->acc < 0) {
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
mrb->c->vmexec = FALSE;
|
||||
@@ -2022,31 +2009,32 @@ RETRY_TRY_BLOCK:
|
||||
ci = mrb->c->ci;
|
||||
}
|
||||
mrb->c->stack = ci->stackent;
|
||||
mrb->c->ci = mrb->c->cibase + proc->env->cioff + 1;
|
||||
while (ci > mrb->c->ci) {
|
||||
mrb_env_unshare(mrb, ci->env);
|
||||
proc = proc->upper;
|
||||
while (mrb->c->cibase < ci && ci[-1].proc != proc) {
|
||||
if (ci[-1].acc == CI_ACC_SKIP) {
|
||||
mrb->c->ci = ci;
|
||||
goto L_BREAK_ERROR;
|
||||
}
|
||||
ci--;
|
||||
}
|
||||
mrb_env_unshare(mrb, ci->env);
|
||||
break;
|
||||
default:
|
||||
/* cannot happen */
|
||||
break;
|
||||
}
|
||||
while (mrb->c->eidx > mrb->c->ci->epos) {
|
||||
ecall(mrb, --mrb->c->eidx);
|
||||
while (mrb->c->eidx > ci->epos) {
|
||||
ecall_adjust();
|
||||
}
|
||||
if (mrb->c->vmexec && !mrb->c->ci->target_class) {
|
||||
if (mrb->c->vmexec && !ci->target_class) {
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
mrb->c->vmexec = FALSE;
|
||||
mrb->jmp = prev_jmp;
|
||||
return v;
|
||||
}
|
||||
ci = mrb->c->ci;
|
||||
while (ci < mrb->c->ci) {
|
||||
mrb_env_unshare(mrb, mrb->c->ci->env);
|
||||
mrb->c->ci--;
|
||||
}
|
||||
acc = ci->acc;
|
||||
mrb->c->stack = ci->stackent;
|
||||
cipop(mrb);
|
||||
@@ -2056,6 +2044,7 @@ RETRY_TRY_BLOCK:
|
||||
return v;
|
||||
}
|
||||
pc = ci->pc;
|
||||
ci = mrb->c->ci;
|
||||
DEBUG(fprintf(stderr, "from :%s\n", mrb_sym2name(mrb, ci->mid)));
|
||||
proc = mrb->c->ci->proc;
|
||||
irep = proc->body.irep;
|
||||
@@ -2156,8 +2145,7 @@ RETRY_TRY_BLOCK:
|
||||
if (lv == 0) stack = regs + 1;
|
||||
else {
|
||||
struct REnv *e = uvenv(mrb, lv-1);
|
||||
if (!e || e->cioff == 0 ||
|
||||
(!MRB_ENV_STACK_SHARED_P(e) && e->cxt.mid == 0) ||
|
||||
if (!e || (!MRB_ENV_STACK_SHARED_P(e) && e->mid == 0) ||
|
||||
MRB_ENV_STACK_LEN(e) <= m1+r+m2+1) {
|
||||
localjump_error(mrb, LOCALJUMP_ERROR_YIELD);
|
||||
goto L_RAISE;
|
||||
@@ -2359,75 +2347,51 @@ RETRY_TRY_BLOCK:
|
||||
CASE(OP_DIV) {
|
||||
/* A B C R(A) := R(A)/R(A+1) (Syms[B]=:/,C=1)*/
|
||||
int a = GETARG_A(i);
|
||||
#ifndef MRB_WITHOUT_FLOAT
|
||||
double x, y, f;
|
||||
#endif
|
||||
|
||||
/* need to check if op is overridden */
|
||||
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {
|
||||
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):
|
||||
#ifdef MRB_WITHOUT_FLOAT
|
||||
{
|
||||
mrb_int x = mrb_fixnum(regs[a]);
|
||||
mrb_int y = mrb_fixnum(regs[a+1]);
|
||||
#ifdef MRB_WITHOUT_FLOAT
|
||||
SET_INT_VALUE(regs[a], y ? x / y : 0);
|
||||
#else
|
||||
double f;
|
||||
if (y == 0) {
|
||||
if (x > 0) f = INFINITY;
|
||||
else if (x < 0) f = -INFINITY;
|
||||
else /* if (x == 0) */ f = NAN;
|
||||
}
|
||||
else {
|
||||
f = (mrb_float)x / (mrb_float)y;
|
||||
}
|
||||
SET_FLOAT_VALUE(mrb, regs[a], f);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#ifndef MRB_WITHOUT_FLOAT
|
||||
#else
|
||||
x = (mrb_float)mrb_fixnum(regs[a]);
|
||||
y = (mrb_float)mrb_fixnum(regs[a+1]);
|
||||
break;
|
||||
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT):
|
||||
{
|
||||
mrb_int x = mrb_fixnum(regs[a]);
|
||||
mrb_float y = mrb_float(regs[a+1]);
|
||||
SET_FLOAT_VALUE(mrb, regs[a], (mrb_float)x / y);
|
||||
}
|
||||
x = (mrb_float)mrb_fixnum(regs[a]);
|
||||
y = mrb_float(regs[a+1]);
|
||||
break;
|
||||
case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM):
|
||||
#ifdef MRB_WORD_BOXING
|
||||
{
|
||||
mrb_float x = mrb_float(regs[a]);
|
||||
mrb_int y = mrb_fixnum(regs[a+1]);
|
||||
double f;
|
||||
if (y == 0) {
|
||||
f = INFINITY;
|
||||
}
|
||||
else {
|
||||
f = x / y;
|
||||
}
|
||||
SET_FLOAT_VALUE(mrb, regs[a], f);
|
||||
}
|
||||
#else
|
||||
OP_MATH_BODY(/,mrb_float,mrb_fixnum);
|
||||
#endif
|
||||
x = mrb_float(regs[a]);
|
||||
y = (mrb_float)mrb_fixnum(regs[a+1]);
|
||||
break;
|
||||
case TYPES2(MRB_TT_FLOAT,MRB_TT_FLOAT):
|
||||
#ifdef MRB_WORD_BOXING
|
||||
{
|
||||
mrb_float x = mrb_float(regs[a]);
|
||||
mrb_float y = mrb_float(regs[a+1]);
|
||||
SET_FLOAT_VALUE(mrb, regs[a], x / y);
|
||||
}
|
||||
#else
|
||||
OP_MATH_BODY(/,mrb_float,mrb_float);
|
||||
#endif
|
||||
x = mrb_float(regs[a]);
|
||||
y = mrb_float(regs[a+1]);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
goto L_SEND;
|
||||
}
|
||||
#ifdef MRB_NAN_BOXING
|
||||
if (isnan(mrb_float(regs[a]))) {
|
||||
mrb_value v = mrb_float_value(mrb, mrb_float(regs[a]));
|
||||
regs[a] = v;
|
||||
|
||||
#ifndef MRB_WITHOUT_FLOAT
|
||||
if (y == 0) {
|
||||
if (x > 0) f = INFINITY;
|
||||
else if (x < 0) f = -INFINITY;
|
||||
else /* if (x == 0) */ f = NAN;
|
||||
}
|
||||
else {
|
||||
f = x / y;
|
||||
}
|
||||
SET_FLOAT_VALUE(mrb, regs[a], f);
|
||||
#endif
|
||||
NEXT;
|
||||
}
|
||||
@@ -2738,7 +2702,6 @@ RETRY_TRY_BLOCK:
|
||||
int c = GETARG_c(i);
|
||||
mrb_irep *nirep = irep->reps[b];
|
||||
|
||||
irep_uplink(mrb, irep, nirep);
|
||||
if (c & OP_L_CAPTURE) {
|
||||
p = mrb_closure_new(mrb, nirep);
|
||||
}
|
||||
@@ -2767,9 +2730,7 @@ RETRY_TRY_BLOCK:
|
||||
base = regs[a];
|
||||
super = regs[a+1];
|
||||
if (mrb_nil_p(base)) {
|
||||
baseclass = mrb->c->ci->proc->target_class;
|
||||
if (!baseclass) baseclass = mrb->c->ci->target_class;
|
||||
|
||||
baseclass = mrb->c->ci->target_class;
|
||||
base = mrb_obj_value(baseclass);
|
||||
}
|
||||
c = mrb_vm_define_class(mrb, base, super, id);
|
||||
@@ -2787,9 +2748,7 @@ RETRY_TRY_BLOCK:
|
||||
|
||||
base = regs[a];
|
||||
if (mrb_nil_p(base)) {
|
||||
baseclass = mrb->c->ci->proc->target_class;
|
||||
if (!baseclass) baseclass = mrb->c->ci->target_class;
|
||||
|
||||
baseclass = mrb->c->ci->target_class;
|
||||
base = mrb_obj_value(baseclass);
|
||||
}
|
||||
c = mrb_vm_define_module(mrb, base, id);
|
||||
@@ -2807,13 +2766,14 @@ RETRY_TRY_BLOCK:
|
||||
struct RProc *p;
|
||||
mrb_irep *nirep = irep->reps[bx];
|
||||
|
||||
irep_uplink(mrb, irep, nirep);
|
||||
nirep->target_class = mrb_class_ptr(recv);
|
||||
/* prepare closure */
|
||||
p = mrb_closure_new(mrb, nirep);
|
||||
p = mrb_proc_new(mrb, nirep);
|
||||
p->c = NULL;
|
||||
mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)proc);
|
||||
MRB_PROC_SET_TARGET_CLASS(p, mrb_class_ptr(recv));
|
||||
p->flags |= MRB_PROC_SCOPE;
|
||||
|
||||
/* prepare stack */
|
||||
/* prepare call stack */
|
||||
ci = cipush(mrb);
|
||||
ci->pc = pc + 1;
|
||||
ci->acc = a;
|
||||
@@ -2825,8 +2785,7 @@ RETRY_TRY_BLOCK:
|
||||
/* prepare stack */
|
||||
mrb->c->stack += a;
|
||||
|
||||
/* setup closure */
|
||||
p->target_class = ci->target_class;
|
||||
/* setup block to call */
|
||||
ci->proc = p;
|
||||
|
||||
irep = p->body.irep;
|
||||
@@ -2957,7 +2916,6 @@ mrb_top_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int sta
|
||||
return mrb_vm_run(mrb, proc, self, stack_keep);
|
||||
}
|
||||
if (mrb->c->ci == mrb->c->cibase) {
|
||||
mrb->c->ci->env = NULL;
|
||||
return mrb_vm_run(mrb, proc, self, stack_keep);
|
||||
}
|
||||
ci = cipush(mrb);
|
||||
|
||||
Reference in New Issue
Block a user