summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-proc-ext/src/proc.c
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-proc-ext/src/proc.c')
-rw-r--r--mrbgems/mruby-proc-ext/src/proc.c57
1 files changed, 36 insertions, 21 deletions
diff --git a/mrbgems/mruby-proc-ext/src/proc.c b/mrbgems/mruby-proc-ext/src/proc.c
index b13606f5f..c9041ec75 100644
--- a/mrbgems/mruby-proc-ext/src/proc.c
+++ b/mrbgems/mruby-proc-ext/src/proc.c
@@ -25,8 +25,8 @@ mrb_proc_source_location(mrb_state *mrb, mrb_value self)
int32_t line;
const char *filename;
- filename = mrb_debug_get_filename(irep, 0);
- line = mrb_debug_get_line(irep, 0);
+ filename = mrb_debug_get_filename(mrb, irep, 0);
+ line = mrb_debug_get_line(mrb, irep, 0);
return (!filename && line == -1)? mrb_nil_value()
: mrb_assoc_new(mrb, mrb_str_new_cstr(mrb, filename), mrb_fixnum_value(line));
@@ -38,7 +38,7 @@ mrb_proc_inspect(mrb_state *mrb, mrb_value self)
{
struct RProc *p = mrb_proc_ptr(self);
mrb_value str = mrb_str_new_lit(mrb, "#<Proc:");
- mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, mrb_cptr(self)));
+ mrb_str_cat_str(mrb, str, mrb_ptr_to_str(mrb, mrb_cptr(self)));
if (!MRB_PROC_CFUNC_P(p)) {
mrb_irep *irep = p->body.irep;
@@ -46,13 +46,13 @@ mrb_proc_inspect(mrb_state *mrb, mrb_value self)
int32_t line;
mrb_str_cat_lit(mrb, str, "@");
- filename = mrb_debug_get_filename(irep, 0);
+ filename = mrb_debug_get_filename(mrb, irep, 0);
mrb_str_cat_cstr(mrb, str, filename ? filename : "-");
mrb_str_cat_lit(mrb, str, ":");
- line = mrb_debug_get_line(irep, 0);
+ line = mrb_debug_get_line(mrb, irep, 0);
if (line != -1) {
- str = mrb_format(mrb, "%S:%S", str, mrb_fixnum_value(line));
+ mrb_str_concat(mrb, str, mrb_fixnum_value(line));
}
else {
mrb_str_cat_lit(mrb, str, "-");
@@ -94,21 +94,23 @@ static mrb_value
mrb_proc_parameters(mrb_state *mrb, mrb_value self)
{
struct parameters_type {
- int size;
+ size_t len;
const char *name;
+ int size;
} *p, parameters_list [] = {
- {0, "req"},
- {0, "opt"},
- {0, "rest"},
- {0, "req"},
- {0, "block"},
- {0, NULL}
+ {sizeof("req") - 1, "req", 0},
+ {sizeof("opt") - 1, "opt", 0},
+ {sizeof("rest") - 1, "rest", 0},
+ {sizeof("req") - 1, "req", 0},
+ {sizeof("block") - 1, "block", 0},
+ {0, NULL, 0}
};
const struct RProc *proc = mrb_proc_ptr(self);
const struct mrb_irep *irep = proc->body.irep;
mrb_aspec aspec;
- mrb_value sname, parameters;
+ mrb_value parameters;
int i, j;
+ int max = -1;
if (MRB_PROC_CFUNC_P(proc)) {
// TODO cfunc aspec is not implemented yet
@@ -120,16 +122,18 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self)
if (!irep->lv) {
return mrb_ary_new(mrb);
}
- if (GET_OPCODE(*irep->iseq) != OP_ENTER) {
+ if (*irep->iseq != OP_ENTER) {
return mrb_ary_new(mrb);
}
if (!MRB_PROC_STRICT_P(proc)) {
+ parameters_list[0].len = sizeof("opt") - 1;
parameters_list[0].name = "opt";
+ parameters_list[3].len = sizeof("opt") - 1;
parameters_list[3].name = "opt";
}
- aspec = GETARG_Ax(*irep->iseq);
+ aspec = PEEK_W(irep->iseq+1);
parameters_list[0].size = MRB_ASPEC_REQ(aspec);
parameters_list[1].size = MRB_ASPEC_OPT(aspec);
parameters_list[2].size = MRB_ASPEC_REST(aspec);
@@ -138,14 +142,25 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self)
parameters = mrb_ary_new_capa(mrb, irep->nlocals-1);
+ max = irep->nlocals-1;
for (i = 0, p = parameters_list; p->name; p++) {
- if (p->size <= 0) continue;
- sname = mrb_symbol_value(mrb_intern_cstr(mrb, p->name));
+ mrb_value sname = mrb_symbol_value(mrb_intern_static(mrb, p->name, p->len));
+
for (j = 0; j < p->size; i++, j++) {
- mrb_value a = mrb_ary_new(mrb);
+ mrb_value a;
+
+ a = mrb_ary_new(mrb);
mrb_ary_push(mrb, a, sname);
- if (irep->lv[i].name) {
- mrb_ary_push(mrb, a, mrb_symbol_value(irep->lv[i].name));
+ if (i < max && irep->lv[i].name) {
+ mrb_sym sym = irep->lv[i].name;
+ const char *name = mrb_sym2name(mrb, sym);
+ switch (name[0]) {
+ case '*': case '&':
+ break;
+ default:
+ mrb_ary_push(mrb, a, mrb_symbol_value(sym));
+ break;
+ }
}
mrb_ary_push(mrb, parameters, a);
}