mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Add more const qualifier for RProc
This commit is contained in:
+1
-1
@@ -234,7 +234,7 @@ typedef struct {
|
||||
uint32_t flags; /* compatible with mt keys in class.c */
|
||||
|
||||
union {
|
||||
struct RProc *proc;
|
||||
const struct RProc *proc;
|
||||
mrb_func_t func;
|
||||
} as;
|
||||
} mrb_method_t;
|
||||
|
||||
@@ -132,13 +132,13 @@ int mrb_rational_mark(mrb_state *mrb, struct RBasic *rat);
|
||||
|
||||
#ifdef MRUBY_PROC_H
|
||||
struct RProc *mrb_closure_new(mrb_state*, const mrb_irep*);
|
||||
void mrb_proc_copy(mrb_state *mrb, struct RProc *a, struct RProc *b);
|
||||
void mrb_proc_copy(mrb_state *mrb, struct RProc *a, const struct RProc *b);
|
||||
mrb_int mrb_proc_arity(const struct RProc *p);
|
||||
struct REnv *mrb_env_new(mrb_state *mrb, struct mrb_context *c, mrb_callinfo *ci, int nstacks, mrb_value *stack, struct RClass *tc);
|
||||
void mrb_proc_merge_lvar(mrb_state *mrb, mrb_irep *irep, struct REnv *env, int num, const mrb_sym *lv, const mrb_value *stack);
|
||||
mrb_value mrb_proc_local_variables(mrb_state *mrb, const struct RProc *proc);
|
||||
const struct RProc *mrb_proc_get_caller(mrb_state *mrb, struct REnv **env);
|
||||
mrb_value mrb_proc_get_self(mrb_state *mrb, struct RProc *p, struct RClass **target_class_p);
|
||||
mrb_value mrb_proc_get_self(mrb_state *mrb, const struct RProc *p, struct RClass **target_class_p);
|
||||
mrb_bool mrb_proc_eql(mrb_state *mrb, mrb_value self, mrb_value other);
|
||||
#endif
|
||||
|
||||
@@ -192,7 +192,7 @@ void mrb_gc_free_iv(mrb_state*, struct RObject*);
|
||||
/* VM */
|
||||
mrb_int mrb_ci_bidx(mrb_callinfo *ci);
|
||||
mrb_int mrb_ci_nregs(mrb_callinfo *ci);
|
||||
mrb_value mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p);
|
||||
mrb_value mrb_exec_irep(mrb_state *mrb, mrb_value self, const struct RProc *p);
|
||||
mrb_value mrb_obj_instance_eval(mrb_state*, mrb_value);
|
||||
mrb_value mrb_object_exec(mrb_state *mrb, mrb_value self, struct RClass *target_class);
|
||||
mrb_value mrb_mod_module_eval(mrb_state*, mrb_value);
|
||||
|
||||
@@ -119,7 +119,7 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
|
||||
#define MRB_METHOD_FUNC(m) ((m).as.func)
|
||||
#define MRB_METHOD_NOARG_SET(m) do{(m).flags|=MRB_METHOD_NOARG_FL;}while(0)
|
||||
#define MRB_METHOD_FROM_FUNC(m,fn) do{(m).flags=MRB_METHOD_FUNC_FL;(m).as.func=(fn);}while(0)
|
||||
#define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).as.proc=(struct RProc*)(pr);}while(0)
|
||||
#define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).as.proc=(pr);}while(0)
|
||||
#define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
|
||||
#define MRB_METHOD_PROC(m) ((m).as.proc)
|
||||
#define MRB_METHOD_UNDEF_P(m) ((m).as.proc==NULL)
|
||||
|
||||
@@ -258,7 +258,7 @@ load_file(mrb_state *mrb, struct mrbc_args *args)
|
||||
}
|
||||
|
||||
static int
|
||||
dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, struct mrbc_args *args)
|
||||
dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, const struct RProc *proc, struct mrbc_args *args)
|
||||
{
|
||||
int n = MRB_DUMP_OK;
|
||||
const mrb_irep *irep = proc->body.irep;
|
||||
|
||||
@@ -63,7 +63,7 @@ args_unshift(mrb_state *mrb, mrb_value obj)
|
||||
mrb_ary_unshift(mrb, *argv, obj);
|
||||
}
|
||||
|
||||
static struct RProc*
|
||||
static const struct RProc*
|
||||
method_missing_prepare(mrb_state *mrb, mrb_sym *mid, mrb_value recv, struct RClass **tc)
|
||||
{
|
||||
const mrb_sym id_method_missing = MRB_SYM(method_missing);
|
||||
@@ -83,10 +83,11 @@ method_missing_prepare(mrb_state *mrb, mrb_sym *mid, mrb_value recv, struct RCla
|
||||
goto method_missing;
|
||||
}
|
||||
|
||||
struct RProc *proc;
|
||||
const struct RProc *proc;
|
||||
if (MRB_METHOD_FUNC_P(m)) {
|
||||
proc = mrb_proc_new_cfunc(mrb, MRB_METHOD_FUNC(m));
|
||||
MRB_PROC_SET_TARGET_CLASS(proc, *tc);
|
||||
struct RProc *p = mrb_proc_new_cfunc(mrb, MRB_METHOD_FUNC(m));
|
||||
MRB_PROC_SET_TARGET_CLASS(p, *tc);
|
||||
proc = p;
|
||||
}
|
||||
else {
|
||||
proc = MRB_METHOD_PROC(m);
|
||||
@@ -104,7 +105,7 @@ method_object_alloc(mrb_state *mrb, struct RClass *mclass)
|
||||
return MRB_OBJ_ALLOC(mrb, MRB_TT_OBJECT, mclass);
|
||||
}
|
||||
|
||||
static struct RProc*
|
||||
static const struct RProc*
|
||||
method_extract_proc(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value obj = mrb_iv_get(mrb, self, MRB_SYM(_proc));
|
||||
@@ -230,7 +231,7 @@ method_eql(mrb_state *mrb, mrb_value self)
|
||||
static mrb_value
|
||||
mcall(mrb_state *mrb, mrb_value self, mrb_value recv)
|
||||
{
|
||||
struct RProc *proc = method_extract_proc(mrb, self);
|
||||
const struct RProc *proc = method_extract_proc(mrb, self);
|
||||
mrb_sym mid = method_extract_mid(mrb, self);
|
||||
struct RClass *tc = method_extract_owner(mrb, self);
|
||||
|
||||
@@ -282,7 +283,7 @@ method_unbind(mrb_state *mrb, mrb_value self)
|
||||
return mrb_obj_value(ume);
|
||||
}
|
||||
|
||||
static struct RProc *
|
||||
static const struct RProc *
|
||||
method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
|
||||
{
|
||||
mrb_method_t m = mrb_method_search_vm(mrb, cp, mid);
|
||||
@@ -320,7 +321,7 @@ method_super_method(mrb_state *mrb, mrb_value self)
|
||||
super = mrb_class_ptr(owner)->super;
|
||||
}
|
||||
|
||||
struct RProc *proc = method_search_vm(mrb, &super, mrb_symbol(name));
|
||||
const struct RProc *proc = method_search_vm(mrb, &super, mrb_symbol(name));
|
||||
if (!proc) return mrb_nil_value();
|
||||
|
||||
if (!super) return mrb_nil_value();
|
||||
@@ -330,7 +331,7 @@ method_super_method(mrb_state *mrb, mrb_value self)
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_owner), mrb_obj_value(super));
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_recv), recv);
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_name), name);
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), mrb_obj_value(proc));
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), mrb_obj_value((void*)proc));
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_klass), mrb_obj_value(super));
|
||||
|
||||
return mrb_obj_value(me);
|
||||
@@ -432,7 +433,7 @@ method_to_s(mrb_state *mrb, mrb_value self)
|
||||
}
|
||||
|
||||
static mrb_bool
|
||||
search_method_owner(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, struct RClass **owner, struct RProc **proc, mrb_bool unbound)
|
||||
search_method_owner(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, struct RClass **owner, const struct RProc **proc, mrb_bool unbound)
|
||||
{
|
||||
*owner = c;
|
||||
*proc = method_search_vm(mrb, owner, name);
|
||||
@@ -462,7 +463,7 @@ static mrb_value
|
||||
method_alloc(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, mrb_bool unbound, mrb_bool singleton)
|
||||
{
|
||||
struct RClass *owner;
|
||||
struct RProc *proc;
|
||||
const struct RProc *proc;
|
||||
|
||||
if (!search_method_owner(mrb, c, obj, name, &owner, &proc, unbound)) {
|
||||
if (singleton) {
|
||||
@@ -482,7 +483,7 @@ method_alloc(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, mrb_
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_owner), mrb_obj_value(owner));
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_recv), unbound ? mrb_nil_value() : obj);
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_name), mrb_symbol_value(name));
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), proc ? mrb_obj_value(proc) : mrb_nil_value());
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), proc ? mrb_obj_value((void*)proc) : mrb_nil_value());
|
||||
mrb_obj_iv_set(mrb, me, MRB_SYM(_klass), mrb_obj_value(c));
|
||||
|
||||
return mrb_obj_value(me);
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@
|
||||
#define METHOD_MID(m) MT_KEY_SYM((m).flags)
|
||||
|
||||
union mt_ptr {
|
||||
struct RProc *proc;
|
||||
const struct RProc *proc;
|
||||
mrb_func_t func;
|
||||
};
|
||||
|
||||
@@ -285,7 +285,7 @@ mrb_gc_mark_mt(mrb_state *mrb, struct RClass *c)
|
||||
union mt_ptr *vals = t->ptr;
|
||||
for (int i=0; i<t->alloc; i++) {
|
||||
if (MT_KEY_P(keys[i]) && (keys[i] & MT_FUNC) == 0) { /* Proc pointer */
|
||||
struct RProc *p = vals[i].proc;
|
||||
const struct RProc *p = vals[i].proc;
|
||||
mrb_gc_mark(mrb, (struct RBasic*)p);
|
||||
}
|
||||
}
|
||||
@@ -755,7 +755,7 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_
|
||||
}
|
||||
if (!h) h = c->mt = mt_new(mrb);
|
||||
if (MRB_METHOD_PROC_P(m)) {
|
||||
struct RProc *p = MRB_METHOD_PROC(m);
|
||||
struct RProc *p = (struct RProc*)MRB_METHOD_PROC(m);
|
||||
|
||||
ptr.proc = p;
|
||||
if (p) {
|
||||
@@ -2217,7 +2217,7 @@ mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b)
|
||||
mrb_method_t m = mrb_method_search(mrb, c, b);
|
||||
|
||||
if (!MRB_METHOD_CFUNC_P(m)) {
|
||||
struct RProc *p = MRB_METHOD_PROC(m);
|
||||
const struct RProc *p = MRB_METHOD_PROC(m);
|
||||
if (!MRB_PROC_CFUNC_P(p) && !MRB_PROC_ALIAS_P(p)) {
|
||||
struct RProc *pnew = MRB_OBJ_ALLOC(mrb, MRB_TT_PROC, mrb->proc_class);
|
||||
|
||||
|
||||
+6
-6
@@ -199,7 +199,7 @@ mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx)
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_proc_get_self(mrb_state *mrb, struct RProc *p, struct RClass **target_class_p)
|
||||
mrb_proc_get_self(mrb_state *mrb, const struct RProc *p, struct RClass **target_class_p)
|
||||
{
|
||||
if (MRB_PROC_CFUNC_P(p)) {
|
||||
*target_class_p = mrb->object_class;
|
||||
@@ -222,7 +222,7 @@ mrb_proc_get_self(mrb_state *mrb, struct RProc *p, struct RClass **target_class_
|
||||
}
|
||||
|
||||
void
|
||||
mrb_proc_copy(mrb_state *mrb, struct RProc *a, struct RProc *b)
|
||||
mrb_proc_copy(mrb_state *mrb, struct RProc *a, const struct RProc *b)
|
||||
{
|
||||
if (a->body.irep) {
|
||||
/* already initialized proc */
|
||||
@@ -288,8 +288,8 @@ mrb_proc_eql(mrb_state *mrb, mrb_value self, mrb_value other)
|
||||
if (mrb_type(self) != MRB_TT_PROC) return FALSE;
|
||||
if (mrb_type(other) != MRB_TT_PROC) return FALSE;
|
||||
|
||||
struct RProc *p1 = mrb_proc_ptr(self);
|
||||
struct RProc *p2 = mrb_proc_ptr(other);
|
||||
const struct RProc *p1 = mrb_proc_ptr(self);
|
||||
const struct RProc *p2 = mrb_proc_ptr(other);
|
||||
if (MRB_PROC_CFUNC_P(p1)) {
|
||||
if (!MRB_PROC_CFUNC_P(p1)) return FALSE;
|
||||
if (p1->body.func != p2->body.func) return FALSE;
|
||||
@@ -308,7 +308,7 @@ proc_eql(mrb_state *mrb, mrb_value self)
|
||||
static mrb_value
|
||||
proc_hash(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
struct RProc *p = mrb_proc_ptr(self);
|
||||
const struct RProc *p = mrb_proc_ptr(self);
|
||||
return mrb_int_value(mrb, (mrb_int)(((intptr_t)p->body.irep)^MRB_TT_PROC));
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ static mrb_value
|
||||
proc_lambda(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value blk;
|
||||
struct RProc *p;
|
||||
const struct RProc *p;
|
||||
|
||||
mrb_get_args(mrb, "&", &blk);
|
||||
if (mrb_nil_p(blk)) {
|
||||
|
||||
@@ -810,7 +810,7 @@ exec_irep(mrb_state *mrb, mrb_value self, const struct RProc *p)
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p)
|
||||
mrb_exec_irep(mrb_state *mrb, mrb_value self, const struct RProc *p)
|
||||
{
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
if (ci->cci == CINFO_NONE) {
|
||||
@@ -968,7 +968,7 @@ eval_under(mrb_state *mrb, mrb_value self, mrb_value blk, struct RClass *c)
|
||||
return mrb_yield_with_class(mrb, blk, 1, &self, self, c);
|
||||
}
|
||||
ci->u.target_class = c;
|
||||
struct RProc *p = mrb_proc_ptr(blk);
|
||||
const struct RProc *p = mrb_proc_ptr(blk);
|
||||
/* just in case irep is NULL; #6065 */
|
||||
if (p->body.irep == NULL) return mrb_nil_value();
|
||||
CI_PROC_SET(ci, p);
|
||||
@@ -1053,7 +1053,7 @@ mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value
|
||||
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
mrb_int n = mrb_ci_nregs(ci);
|
||||
struct RProc *p = mrb_proc_ptr(b);
|
||||
const struct RProc *p = mrb_proc_ptr(b);
|
||||
mrb_sym mid;
|
||||
|
||||
if (MRB_PROC_ENV_P(p)) {
|
||||
@@ -1087,7 +1087,7 @@ mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value
|
||||
MRB_API mrb_value
|
||||
mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv)
|
||||
{
|
||||
struct RProc *p = mrb_proc_ptr(b);
|
||||
const struct RProc *p = mrb_proc_ptr(b);
|
||||
struct RClass *tc;
|
||||
mrb_value self = mrb_proc_get_self(mrb, p, &tc);
|
||||
|
||||
@@ -1097,7 +1097,7 @@ mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv)
|
||||
MRB_API mrb_value
|
||||
mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg)
|
||||
{
|
||||
struct RProc *p = mrb_proc_ptr(b);
|
||||
const struct RProc *p = mrb_proc_ptr(b);
|
||||
struct RClass *tc;
|
||||
mrb_value self = mrb_proc_get_self(mrb, p, &tc);
|
||||
|
||||
@@ -1109,7 +1109,7 @@ mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const
|
||||
{
|
||||
check_block(mrb, b);
|
||||
|
||||
struct RProc *p = mrb_proc_ptr(b);
|
||||
const struct RProc *p = mrb_proc_ptr(b);
|
||||
mrb_callinfo *ci = mrb->c->ci;
|
||||
|
||||
stack_extend_adjust(mrb, 4, &argv);
|
||||
@@ -2951,7 +2951,7 @@ RETRY_TRY_BLOCK:
|
||||
|
||||
CASE(OP_DEF, BB) {
|
||||
struct RClass *target = mrb_class_ptr(regs[a]);
|
||||
struct RProc *p = mrb_proc_ptr(regs[a+1]);
|
||||
const struct RProc *p = mrb_proc_ptr(regs[a+1]);
|
||||
mrb_method_t m;
|
||||
mrb_sym mid = irep->syms[b];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user