Commit da8405a0 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1600 from take-cheeze/mrb_intern_lit

Proposal of mrb_intern_lit macro.
parents e981f0b4 df780ae5
......@@ -239,6 +239,8 @@ const char *mrb_sym2name_len(mrb_state*,mrb_sym,size_t*);
mrb_value mrb_sym2str(mrb_state*,mrb_sym);
mrb_value mrb_str_format(mrb_state *, int, const mrb_value *, mrb_value);
#define mrb_intern_lit(mrb, lit) mrb_intern(mrb, (lit), sizeof(lit) - 1)
void *mrb_malloc(mrb_state*, size_t); /* raise RuntimeError if no mem */
void *mrb_calloc(mrb_state*, size_t, size_t); /* ditto */
void *mrb_realloc(mrb_state*, void*, size_t); /* ditto */
......
......@@ -35,7 +35,7 @@ mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
/* RHASH_TBL allocates st_table if not available. */
#define RHASH(obj) ((struct RHash*)(mrb_ptr(obj)))
#define RHASH_TBL(h) (RHASH(h)->ht)
#define RHASH_IFNONE(h) mrb_iv_get(mrb, (h), mrb_intern(mrb, "ifnone", 6))
#define RHASH_IFNONE(h) mrb_iv_get(mrb, (h), mrb_intern_lit(mrb, "ifnone"))
#define RHASH_PROCDEFAULT(h) RHASH_IFNONE(h)
struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);
......
......@@ -384,7 +384,7 @@ main(int argc, char **argv)
}
else {
/* no */
if (!mrb_respond_to(mrb, result, mrb_intern(mrb, "inspect", 7))){
if (!mrb_respond_to(mrb, result, mrb_intern_lit(mrb, "inspect"))){
result = mrb_any_to_s(mrb,result);
}
p(mrb, result, 1);
......
......@@ -208,7 +208,7 @@ main(int argc, char **argv)
v = mrb_load_irep_file_cxt(mrb, args.rfp, c);
}
else {
mrb_sym zero_sym = mrb_intern(mrb, "$0", 2);
mrb_sym zero_sym = mrb_intern_lit(mrb, "$0");
if (args.rfp) {
char *cmdline;
......
......@@ -49,7 +49,7 @@ mrb_struct_iv_get(mrb_state *mrb, mrb_value c, const char *name)
mrb_value
mrb_struct_s_members(mrb_state *mrb, mrb_value klass)
{
mrb_value members = struct_ivar_get(mrb, klass, mrb_intern(mrb, "__members__", 11));
mrb_value members = struct_ivar_get(mrb, klass, mrb_intern_lit(mrb, "__members__"));
if (mrb_nil_p(members)) {
mrb_raise(mrb, E_TYPE_ERROR, "uninitialized struct");
......@@ -258,7 +258,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
}
MRB_SET_INSTANCE_TT(c, MRB_TT_ARRAY);
nstr = mrb_obj_value(c);
mrb_iv_set(mrb, nstr, mrb_intern(mrb, "__members__", 11), members);
mrb_iv_set(mrb, nstr, mrb_intern_lit(mrb, "__members__"), members);
mrb_define_class_method(mrb, c, "new", mrb_instance_new, MRB_ARGS_ANY());
mrb_define_class_method(mrb, c, "[]", mrb_instance_new, MRB_ARGS_ANY());
......@@ -393,7 +393,7 @@ num_members(mrb_state *mrb, struct RClass *klass)
{
mrb_value members;
members = struct_ivar_get(mrb, mrb_obj_value(klass), mrb_intern(mrb, "__members__", 11));
members = struct_ivar_get(mrb, mrb_obj_value(klass), mrb_intern_lit(mrb, "__members__"));
if (!mrb_array_p(members)) {
mrb_raise(mrb, E_TYPE_ERROR, "broken members");
}
......
......@@ -309,7 +309,7 @@ mrb_ary_cmp(mrb_state *mrb, mrb_value ary1)
a1 = RARRAY(ary1); a2 = RARRAY(ary2);
if (a1->len == a2->len && a1->ptr == a2->ptr) return mrb_fixnum_value(0);
else {
mrb_sym cmp = mrb_intern(mrb, "<=>", 3);
mrb_sym cmp = mrb_intern_lit(mrb, "<=>");
len = RARRAY_LEN(ary1);
if (len > RARRAY_LEN(ary2)) {
......@@ -1070,7 +1070,7 @@ mrb_ary_equal(mrb_state *mrb, mrb_value ary1)
if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value();
if (mrb_special_const_p(ary2)) return mrb_false_value();
if (!mrb_array_p(ary2)) {
if (!mrb_respond_to(mrb, ary2, mrb_intern(mrb, "to_ary", 6))) {
if (!mrb_respond_to(mrb, ary2, mrb_intern_lit(mrb, "to_ary"))) {
return mrb_false_value();
}
else {
......
......@@ -65,7 +65,7 @@ mrb_output_backtrace(mrb_state *mrb, struct RObject *exc, output_stream_func fun
int i, line;
func(mrb, stream, 1, "trace:\n");
ciidx = mrb_fixnum(mrb_obj_iv_get(mrb, exc, mrb_intern(mrb, "ciidx", 5)));
ciidx = mrb_fixnum(mrb_obj_iv_get(mrb, exc, mrb_intern_lit(mrb, "ciidx")));
if (ciidx >= mrb->c->ciend - mrb->c->cibase)
ciidx = 10; /* ciidx is broken... */
......@@ -88,7 +88,7 @@ mrb_output_backtrace(mrb_state *mrb, struct RObject *exc, output_stream_func fun
pc = mrb->c->cibase[i+1].pc - 1;
}
else {
pc = (mrb_code*)mrb_cptr(mrb_obj_iv_get(mrb, exc, mrb_intern(mrb, "lastpc", 6)));
pc = (mrb_code*)mrb_cptr(mrb_obj_iv_get(mrb, exc, mrb_intern_lit(mrb, "lastpc")));
}
filename = mrb_debug_get_filename(irep, pc - irep->iseq);
line = mrb_debug_get_line(irep, pc - irep->iseq);
......
......@@ -53,7 +53,7 @@ void
mrb_name_class(mrb_state *mrb, struct RClass *c, mrb_sym name)
{
mrb_obj_iv_set(mrb, (struct RObject*)c,
mrb_intern(mrb, "__classid__", 11), mrb_symbol_value(name));
mrb_intern_lit(mrb, "__classid__"), mrb_symbol_value(name));
}
#define make_metaclass(mrb, c) prepare_singleton_class((mrb), (struct RBasic*)(c))
......@@ -89,7 +89,7 @@ prepare_singleton_class(mrb_state *mrb, struct RBasic *o)
o->c = sc;
mrb_field_write_barrier(mrb, (struct RBasic*)o, (struct RBasic*)sc);
mrb_field_write_barrier(mrb, (struct RBasic*)sc, (struct RBasic*)o);
mrb_obj_iv_set(mrb, (struct RObject*)sc, mrb_intern(mrb, "__attached__", 12), mrb_obj_value(o));
mrb_obj_iv_set(mrb, (struct RObject*)sc, mrb_intern_lit(mrb, "__attached__"), mrb_obj_value(o));
}
struct RClass*
......@@ -116,7 +116,7 @@ setup_class(mrb_state *mrb, mrb_value outer, struct RClass *c, mrb_sym id)
mrb_name_class(mrb, c, id);
mrb_const_set(mrb, outer, id, mrb_obj_value(c));
mrb_obj_iv_set(mrb, (struct RObject*)c,
mrb_intern(mrb, "__outer__", 9), outer);
mrb_intern_lit(mrb, "__outer__"), outer);
}
struct RClass*
......@@ -124,7 +124,7 @@ mrb_class_outer_module(mrb_state *mrb, struct RClass *c)
{
mrb_value outer;
outer = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern(mrb, "__outer__", 9));
outer = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"));
if (mrb_nil_p(outer)) return 0;
return mrb_class_ptr(outer);
}
......@@ -1061,7 +1061,7 @@ mrb_instance_new(mrb_state *mrb, mrb_value cv)
obj = mrb_instance_alloc(mrb, cv);
mrb_get_args(mrb, "*&", &argv, &argc, &blk);
mrb_funcall_with_block(mrb, obj, mrb_intern(mrb, "initialize", 10), argc, argv, blk);
mrb_funcall_with_block(mrb, obj, mrb_intern_lit(mrb, "initialize"), argc, argv, blk);
return obj;
}
......@@ -1072,7 +1072,7 @@ mrb_obj_new(mrb_state *mrb, struct RClass *c, int argc, mrb_value *argv)
mrb_value obj;
obj = mrb_instance_alloc(mrb, mrb_obj_value(c));
mrb_funcall_argv(mrb, obj, mrb_intern(mrb, "initialize", 10), argc, argv);
mrb_funcall_argv(mrb, obj, mrb_intern_lit(mrb, "initialize"), argc, argv);
return obj;
}
......@@ -1163,7 +1163,7 @@ mrb_bob_missing(mrb_state *mrb, mrb_value mod)
mrb_get_args(mrb, "n*", &name, &a, &alen);
if (mrb_respond_to(mrb,mod,mrb_intern(mrb, "inspect",7))){
if (mrb_respond_to(mrb,mod,mrb_intern_lit(mrb, "inspect"))){
inspect = mrb_funcall(mrb, mod, "inspect", 0);
if (RSTRING_LEN(inspect) > 64) {
inspect = mrb_any_to_s(mrb, mod);
......@@ -1215,7 +1215,7 @@ mrb_class_path(mrb_state *mrb, struct RClass *c)
mrb_value path;
const char *name;
size_t len;
mrb_sym classpath = mrb_intern(mrb, "__classpath__", 13);
mrb_sym classpath = mrb_intern_lit(mrb, "__classpath__");
path = mrb_obj_iv_get(mrb, (struct RObject*)c, classpath);
if (mrb_nil_p(path)) {
......@@ -1376,7 +1376,7 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
mrb_value str;
if (mrb_type(klass) == MRB_TT_SCLASS) {
mrb_value v = mrb_iv_get(mrb, klass, mrb_intern(mrb, "__attached__", 12));
mrb_value v = mrb_iv_get(mrb, klass, mrb_intern_lit(mrb, "__attached__"));
str = mrb_str_new(mrb, "#<Class:", 8);
......@@ -1912,10 +1912,10 @@ mrb_init_class(mrb_state *mrb)
mrb_define_const(mrb, obj, "Class", mrb_obj_value(cls));
/* name each classes */
mrb_name_class(mrb, bob, mrb_intern(mrb, "BasicObject", 11));
mrb_name_class(mrb, obj, mrb_intern(mrb, "Object", 6));
mrb_name_class(mrb, mod, mrb_intern(mrb, "Module", 6));
mrb_name_class(mrb, cls, mrb_intern(mrb, "Class", 5));
mrb_name_class(mrb, bob, mrb_intern_lit(mrb, "BasicObject"));
mrb_name_class(mrb, obj, mrb_intern_lit(mrb, "Object"));
mrb_name_class(mrb, mod, mrb_intern_lit(mrb, "Module"));
mrb_name_class(mrb, cls, mrb_intern_lit(mrb, "Class"));
MRB_SET_INSTANCE_TT(cls, MRB_TT_CLASS);
mrb_define_method(mrb, bob, "initialize", mrb_bob_init, MRB_ARGS_NONE());
......
......@@ -565,7 +565,7 @@ for_body(codegen_scope *s, node *tree)
s = prev;
genop(s, MKOP_Abc(OP_LAMBDA, cursp(), s->irep->rlen-1, OP_L_BLOCK));
pop();
idx = new_msym(s, mrb_intern(s->mrb, "each", 4));
idx = new_msym(s, mrb_intern_lit(s->mrb, "each"));
genop(s, MKOP_ABC(OP_SENDB, cursp(), idx, 0));
}
......@@ -976,7 +976,7 @@ static void
gen_send_intern(codegen_scope *s)
{
pop();
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern(s->mrb, "intern", 6)), 0));
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "intern")), 0));
push();
}
static void
......@@ -1176,12 +1176,12 @@ codegen(codegen_scope *s, node *tree, int val)
codegen(s, n4->car, VAL);
}
else {
genop(s, MKOP_ABx(OP_GETCONST, cursp(), new_msym(s, mrb_intern(s->mrb, "StandardError", 13))));
genop(s, MKOP_ABx(OP_GETCONST, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "StandardError"))));
push();
}
genop(s, MKOP_AB(OP_MOVE, cursp(), exc));
pop();
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern(s->mrb, "===", 3)), 1));
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "===")), 1));
tmp = new_label(s);
genop(s, MKOP_AsBx(OP_JMPIF, cursp(), pos2));
pos2 = tmp;
......@@ -1385,7 +1385,7 @@ codegen(codegen_scope *s, node *tree, int val)
if (head) {
genop(s, MKOP_AB(OP_MOVE, cursp(), head));
pop();
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern(s->mrb, "===", 3)), 1));
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "===")), 1));
}
else {
pop();
......@@ -1725,7 +1725,7 @@ codegen(codegen_scope *s, node *tree, int val)
}
pop_n(n+1);
if (sendv) n = CALL_MAXARGS;
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern(s->mrb, "call", 4)), n));
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "call")), n));
if (val) push();
}
break;
......@@ -1995,7 +1995,7 @@ codegen(codegen_scope *s, node *tree, int val)
default:
{
int sym = new_msym(s, mrb_intern(s->mrb, "-", 1));
int sym = new_msym(s, mrb_intern_lit(s->mrb, "-"));
genop(s, MKOP_ABx(OP_LOADI, cursp(), 0));
push();
......@@ -2063,7 +2063,7 @@ codegen(codegen_scope *s, node *tree, int val)
char *p = (char*)tree->car;
size_t len = (intptr_t)tree->cdr;
int ai = mrb_gc_arena_save(s->mrb);
int sym = new_sym(s, mrb_intern(s->mrb, "Kernel", 6));
int sym = new_sym(s, mrb_intern_lit(s->mrb, "Kernel"));
int off = new_lit(s, mrb_str_new(s->mrb, p, len));
genop(s, MKOP_A(OP_OCLASS, cursp()));
......@@ -2071,7 +2071,7 @@ codegen(codegen_scope *s, node *tree, int val)
push();
genop(s, MKOP_ABx(OP_STRING, cursp(), off));
pop();
sym = new_sym(s, mrb_intern(s->mrb, "`", 1));
sym = new_sym(s, mrb_intern_lit(s->mrb, "`"));
genop(s, MKOP_ABC(OP_SEND, cursp(), sym, 1));
mrb_gc_arena_restore(s->mrb, ai);
push();
......@@ -2083,7 +2083,7 @@ codegen(codegen_scope *s, node *tree, int val)
char *p1 = (char*)tree->car;
char *p2 = (char*)tree->cdr;
int ai = mrb_gc_arena_save(s->mrb);
int sym = new_sym(s, mrb_intern(s->mrb, REGEXP_CLASS, REGEXP_CLASS_CSTR_LEN));
int sym = new_sym(s, mrb_intern_lit(s->mrb, REGEXP_CLASS));
int off = new_lit(s, mrb_str_new(s->mrb, p1, strlen(p1)));
int argc = 1;
......@@ -2099,7 +2099,7 @@ codegen(codegen_scope *s, node *tree, int val)
pop();
}
pop();
sym = new_sym(s, mrb_intern(s->mrb, "compile", 7));
sym = new_sym(s, mrb_intern_lit(s->mrb, "compile"));
genop(s, MKOP_ABC(OP_SEND, cursp(), sym, argc));
mrb_gc_arena_restore(s->mrb, ai);
push();
......@@ -2110,7 +2110,7 @@ codegen(codegen_scope *s, node *tree, int val)
if (val) {
node *n = tree->car;
int ai = mrb_gc_arena_save(s->mrb);
int sym = new_sym(s, mrb_intern(s->mrb, REGEXP_CLASS, REGEXP_CLASS_CSTR_LEN));
int sym = new_sym(s, mrb_intern_lit(s->mrb, REGEXP_CLASS));
int argc = 1;
int off;
char *p;
......@@ -2147,7 +2147,7 @@ codegen(codegen_scope *s, node *tree, int val)
pop();
}
pop();
sym = new_sym(s, mrb_intern(s->mrb, "compile", 7));
sym = new_sym(s, mrb_intern_lit(s->mrb, "compile"));
genop(s, MKOP_ABC(OP_SEND, cursp(), sym, argc));
mrb_gc_arena_restore(s->mrb, ai);
push();
......@@ -2212,7 +2212,7 @@ codegen(codegen_scope *s, node *tree, int val)
{
int a = new_msym(s, sym(tree->car));
int b = new_msym(s, sym(tree->cdr));
int c = new_msym(s, mrb_intern(s->mrb,"alias_method", 12));
int c = new_msym(s, mrb_intern_lit(s->mrb,"alias_method"));
genop(s, MKOP_A(OP_TCLASS, cursp()));
push();
......@@ -2231,7 +2231,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_UNDEF:
{
int undef = new_msym(s, mrb_intern(s->mrb, "undef_method", 12));
int undef = new_msym(s, mrb_intern_lit(s->mrb, "undef_method"));
int num = 0;
node *t = tree;
......
......@@ -45,7 +45,7 @@ exc_initialize(mrb_state *mrb, mrb_value exc)
mrb_value mesg;
if (mrb_get_args(mrb, "|o", &mesg) == 1) {
mrb_iv_set(mrb, exc, mrb_intern(mrb, "mesg", 4), mesg);
mrb_iv_set(mrb, exc, mrb_intern_lit(mrb, "mesg"), mesg);
}
return exc;
}
......@@ -74,7 +74,7 @@ exc_exception(mrb_state *mrb, mrb_value self)
if (argc == 0) return self;
if (mrb_obj_equal(mrb, self, a)) return self;
exc = mrb_obj_clone(mrb, self);
mrb_iv_set(mrb, exc, mrb_intern(mrb, "mesg", 4), a);
mrb_iv_set(mrb, exc, mrb_intern_lit(mrb, "mesg"), a);
return exc;
}
......@@ -90,7 +90,7 @@ exc_exception(mrb_state *mrb, mrb_value self)
static mrb_value
exc_to_s(mrb_state *mrb, mrb_value exc)
{
mrb_value mesg = mrb_attr_get(mrb, exc, mrb_intern(mrb, "mesg", 4));
mrb_value mesg = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "mesg"));
if (mrb_nil_p(mesg)) return mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, exc));
return mesg;
......@@ -124,9 +124,9 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
{
mrb_value str, mesg, file, line;
mesg = mrb_attr_get(mrb, exc, mrb_intern(mrb, "mesg", 4));
file = mrb_attr_get(mrb, exc, mrb_intern(mrb, "file", 4));
line = mrb_attr_get(mrb, exc, mrb_intern(mrb, "line", 4));
mesg = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "mesg"));
file = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "file"));
line = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "line"));
if (!mrb_nil_p(file) && !mrb_nil_p(line)) {
str = file;
......@@ -163,7 +163,7 @@ exc_equal(mrb_state *mrb, mrb_value exc)
mrb_value obj;
mrb_value mesg;
mrb_bool equal_p;
mrb_sym id_mesg = mrb_intern(mrb, "mesg", 4);
mrb_sym id_mesg = mrb_intern_lit(mrb, "mesg");
mrb_get_args(mrb, "o", &obj);
if (mrb_obj_equal(mrb, exc, obj)) {
......@@ -171,7 +171,7 @@ exc_equal(mrb_state *mrb, mrb_value exc)
}
else {
if (mrb_obj_class(mrb, exc) != mrb_obj_class(mrb, obj)) {
if (mrb_respond_to(mrb, obj, mrb_intern(mrb, "message", 7))) {
if (mrb_respond_to(mrb, obj, mrb_intern_lit(mrb, "message"))) {
mesg = mrb_funcall(mrb, obj, "message", 0);
}
else
......@@ -193,7 +193,7 @@ exc_debug_info(mrb_state *mrb, struct RObject *exc)
mrb_callinfo *ci = mrb->c->ci;
mrb_code *pc = ci->pc;
mrb_obj_iv_set(mrb, exc, mrb_intern(mrb, "ciidx", 5), mrb_fixnum_value(ci - mrb->c->cibase));
mrb_obj_iv_set(mrb, exc, mrb_intern_lit(mrb, "ciidx"), mrb_fixnum_value(ci - mrb->c->cibase));
while (ci >= mrb->c->cibase) {
mrb_code *err = ci->err;
......@@ -204,8 +204,8 @@ exc_debug_info(mrb_state *mrb, struct RObject *exc)
int32_t const line = mrb_debug_get_line(irep, err - irep->iseq);
char const* file = mrb_debug_get_filename(irep, err - irep->iseq);
if (line != -1 && file) {
mrb_obj_iv_set(mrb, exc, mrb_intern(mrb, "file", 4), mrb_str_new_cstr(mrb, file));
mrb_obj_iv_set(mrb, exc, mrb_intern(mrb, "line", 4), mrb_fixnum_value(line));
mrb_obj_iv_set(mrb, exc, mrb_intern_lit(mrb, "file"), mrb_str_new_cstr(mrb, file));
mrb_obj_iv_set(mrb, exc, mrb_intern_lit(mrb, "line"), mrb_fixnum_value(line));
return;
}
}
......@@ -350,7 +350,7 @@ mrb_bug(mrb_state *mrb, const char *fmt, ...)
int
sysexit_status(mrb_state *mrb, mrb_value err)
{
mrb_value st = mrb_iv_get(mrb, err, mrb_intern(mrb, "status", 6));
mrb_value st = mrb_iv_get(mrb, err, mrb_intern_lit(mrb, "status"));
return mrb_fixnum(st);
}
......@@ -388,7 +388,7 @@ make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr)
n = 1;
exception_call:
{
mrb_sym exc = mrb_intern(mrb, "exception", 9);
mrb_sym exc = mrb_intern_lit(mrb, "exception");
if (mrb_respond_to(mrb, argv[0], exc)) {
mesg = mrb_funcall_argv(mrb, argv[0], exc, n, argv+1);
}
......
......@@ -266,7 +266,7 @@ mrb_hash_init_core(mrb_state *mrb, mrb_value hash)
RHASH(hash)->flags |= MRB_HASH_PROC_DEFAULT;
ifnone = block;
}
mrb_iv_set(mrb, hash, mrb_intern(mrb, "ifnone", 6), ifnone);
mrb_iv_set(mrb, hash, mrb_intern_lit(mrb, "ifnone"), ifnone);
return hash;
}
......@@ -425,7 +425,7 @@ mrb_hash_set_default(mrb_state *mrb, mrb_value hash)
mrb_get_args(mrb, "o", &ifnone);
mrb_hash_modify(mrb, hash);
mrb_iv_set(mrb, hash, mrb_intern(mrb, "ifnone", 6), ifnone);
mrb_iv_set(mrb, hash, mrb_intern_lit(mrb, "ifnone"), ifnone);
RHASH(hash)->flags &= ~(MRB_HASH_PROC_DEFAULT);
return ifnone;
......@@ -476,7 +476,7 @@ mrb_hash_set_default_proc(mrb_state *mrb, mrb_value hash)
mrb_get_args(mrb, "o", &ifnone);
mrb_hash_modify(mrb, hash);
mrb_iv_set(mrb, hash, mrb_intern(mrb, "ifnone", 6), ifnone);
mrb_iv_set(mrb, hash, mrb_intern_lit(mrb, "ifnone"), ifnone);
RHASH(hash)->flags |= MRB_HASH_PROC_DEFAULT;
return ifnone;
......@@ -734,7 +734,7 @@ mrb_hash_replace(mrb_state *mrb, mrb_value hash)
else {
ifnone = RHASH_IFNONE(hash2);
}
mrb_iv_set(mrb, hash, mrb_intern(mrb, "ifnone", 6), ifnone);
mrb_iv_set(mrb, hash, mrb_intern_lit(mrb, "ifnone"), ifnone);
return hash;
}
......@@ -1004,7 +1004,7 @@ hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, int eql)
if (mrb_obj_equal(mrb, hash1, hash2)) return mrb_true_value();
if (!mrb_hash_p(hash2)) {
if (!mrb_respond_to(mrb, hash2, mrb_intern(mrb, "to_hash", 7))) {
if (!mrb_respond_to(mrb, hash2, mrb_intern_lit(mrb, "to_hash"))) {
return mrb_false_value();
}
if (eql)
......
......@@ -29,7 +29,7 @@ typedef enum {
mrb_bool
mrb_obj_basic_to_s_p(mrb_state *mrb, mrb_value obj)
{
struct RProc *me = mrb_method_search(mrb, mrb_class(mrb, obj), mrb_intern(mrb, "to_s", 4));
struct RProc *me = mrb_method_search(mrb, mrb_class(mrb, obj), mrb_intern_lit(mrb, "to_s"));
if (me && MRB_PROC_CFUNC_P(me) && (me->body.func == mrb_any_to_s))
return TRUE;
return FALSE;
......@@ -280,7 +280,7 @@ mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj)
clone->super = klass->super;
if (klass->iv) {
mrb_iv_copy(mrb, mrb_obj_value(clone), mrb_obj_value(klass));
mrb_obj_iv_set(mrb, (struct RObject*)clone, mrb_intern(mrb, "__attached__", 12), obj);
mrb_obj_iv_set(mrb, (struct RObject*)clone, mrb_intern_lit(mrb, "__attached__"), obj);
}
if (klass->mt) {
clone->mt = kh_copy(mt, mrb, klass->mt);
......@@ -944,7 +944,7 @@ mrb_f_raise(mrb_state *mrb, mrb_value self)
/* fall through */
default:
exc = mrb_make_exception(mrb, argc, a);
mrb_obj_iv_set(mrb, mrb_obj_ptr(exc), mrb_intern(mrb, "lastpc", 6), mrb_cptr_value(mrb, mrb->c->ci->pc));
mrb_obj_iv_set(mrb, mrb_obj_ptr(exc), mrb_intern_lit(mrb, "lastpc"), mrb_cptr_value(mrb, mrb->c->ci->pc));
mrb_exc_raise(mrb, exc);
break;
}
......@@ -1049,7 +1049,7 @@ obj_respond_to(mrb_state *mrb, mrb_value self)
}
if (!respond_to_p) {
rtm_id = mrb_intern(mrb, "respond_to_missing?", 19);
rtm_id = mrb_intern_lit(mrb, "respond_to_missing?");
if (basic_obj_respond_to(mrb, self, rtm_id, !mrb_test(priv))) {
return mrb_funcall_argv(mrb, self, rtm_id, argc, argv);
}
......@@ -1151,5 +1151,5 @@ mrb_init_kernel(mrb_state *mrb)
mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, MRB_ARGS_NONE()); /* 15.3.1.3.46 */
mrb_include_module(mrb, mrb->object_class, mrb->kernel_module);
mrb_alias_method(mrb, mrb->module_class, mrb_intern(mrb, "dup", 3), mrb_intern(mrb, "clone", 5));
mrb_alias_method(mrb, mrb->module_class, mrb_intern_lit(mrb, "dup"), mrb_intern_lit(mrb, "clone"));
}
......@@ -204,8 +204,8 @@ mrb_init_proc(mrb_state *mrb)
mrb_define_method(mrb, mrb->proc_class, "arity", mrb_proc_arity, MRB_ARGS_NONE());
m = mrb_proc_new(mrb, call_irep);
mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "call", 4), m);
mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "[]", 2), m);
mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern_lit(mrb, "call"), m);
mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern_lit(mrb, "[]"), m);
mrb_define_class_method(mrb, mrb->kernel_module, "lambda", proc_lambda, MRB_ARGS_NONE()); /* 15.3.1.2.6 */
mrb_define_method(mrb, mrb->kernel_module, "lambda", proc_lambda, MRB_ARGS_NONE()); /* 15.3.1.3.27 */
......
......@@ -8,6 +8,5 @@
#define RE_H
#define REGEXP_CLASS "Regexp"
#define REGEXP_CLASS_CSTR_LEN 6
#endif
......@@ -546,10 +546,10 @@ mrb_str_cmp_m(mrb_state *mrb, mrb_value str1)
mrb_get_args(mrb, "o", &str2);
if (!mrb_string_p(str2)) {
if (!mrb_respond_to(mrb, str2, mrb_intern(mrb, "to_s", 4))) {
if (!mrb_respond_to(mrb, str2, mrb_intern_lit(mrb, "to_s"))) {
return mrb_nil_value();
}
else if (!mrb_respond_to(mrb, str2, mrb_intern(mrb, "<=>", 3))) {
else if (!mrb_respond_to(mrb, str2, mrb_intern_lit(mrb, "<=>"))) {
return mrb_nil_value();
}
else {
......@@ -585,7 +585,7 @@ mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2)
if (mrb_obj_equal(mrb, str1, str2)) return TRUE;
if (!mrb_string_p(str2)) {
if (mrb_nil_p(str2)) return FALSE;
if (!mrb_respond_to(mrb, str2, mrb_intern(mrb, "to_str", 6))) {
if (!mrb_respond_to(mrb, str2, mrb_intern_lit(mrb, "to_str"))) {
return FALSE;
}
str2 = mrb_funcall(mrb, str2, "to_str", 0);
......
......@@ -884,7 +884,7 @@ L_RETRY:
goto L_RETRY;
}
name = mrb_symbol_value(sym);
return mrb_funcall_argv(mrb, mrb_obj_value(base), mrb_intern(mrb, "const_missing", 13), 1, &name);
return mrb_funcall_argv(mrb, mrb_obj_value(base), mrb_intern_lit(mrb, "const_missing"), 1, &name);
}
mrb_value
......@@ -1064,7 +1064,7 @@ mrb_f_global_variables(mrb_state *mrb, mrb_value self)
buf[2] = 0;
for (i = 1; i <= 9; ++i) {
buf[1] = (char)(i + '0');
mrb_ary_push(mrb, ary, mrb_symbol_value(mrb_intern(mrb, buf, 2)));
mrb_ary_push(mrb, ary, mrb_symbol_value(mrb_intern_lit(mrb, buf)));
}
return ary;
}
......@@ -1127,7 +1127,7 @@ mrb_class_sym(mrb_state *mrb, struct RClass *c, struct RClass *outer)
{
mrb_value name;
name = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern(mrb, "__classid__", 11));
name = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__classid__"));
if (mrb_nil_p(name)) {
if (!outer) return 0;
......
......@@ -361,7 +361,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, int argc, mr
p = mrb_method_search_vm(mrb, &c, mid);
if (!p) {
undef = mid;
mid = mrb_intern(mrb, "method_missing", 14);
mid = mrb_intern_lit(mrb, "method_missing");
p = mrb_method_search_vm(mrb, &c, mid);
n++; argc++;
}
......@@ -901,7 +901,7 @@ mrb_context_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int
if (!m) {
mrb_value sym = mrb_symbol_value(mid);
mid = mrb_intern(mrb, "method_missing", 14);
mid = mrb_intern_lit(mrb, "method_missing");
m = mrb_method_search_vm(mrb, &c, mid);
if (n == CALL_MAXARGS) {
mrb_ary_unshift(mrb, regs[a+1], sym);
......@@ -1058,7 +1058,7 @@ mrb_context_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int
c = mrb->c->ci->target_class->super;
m = mrb_method_search_vm(mrb, &c, mid);
if (!m) {
mid = mrb_intern(mrb, "method_missing", 14);
mid = mrb_intern_lit(mrb, "method_missing");
m = mrb_method_search_vm(mrb, &c, mid);
if (n == CALL_MAXARGS) {
mrb_ary_unshift(mrb, regs[a+1], mrb_symbol_value(ci->mid));
......@@ -1271,8 +1271,8 @@ mrb_context_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int
L_RAISE:
ci = mrb->c->ci;
mrb_obj_iv_ifnone(mrb, mrb->exc, mrb_intern(mrb, "lastpc", 6), mrb_cptr_value(mrb, pc));
mrb_obj_iv_ifnone(mrb, mrb->exc, mrb_intern(mrb, "ciidx", 5), mrb_fixnum_value(ci - mrb->c->cibase));
mrb_obj_iv_ifnone(mrb, mrb->exc, mrb_intern_lit(mrb, "lastpc"), mrb_cptr_value(mrb, pc));
mrb_obj_iv_ifnone(mrb, mrb->exc, mrb_intern_lit(mrb, "ciidx"), mrb_fixnum_value(ci - mrb->c->cibase));
eidx = ci->eidx;
if (ci == mrb->c->cibase) {
if (ci->ridx == 0) goto L_STOP;
......@@ -1397,7 +1397,7 @@ mrb_context_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int
if (!m) {
mrb_value sym = mrb_symbol_value(mid);
mid = mrb_intern(mrb, "method_missing", 14);
mid = mrb_intern_lit(mrb, "method_missing");
m = mrb_method_search_vm(mrb, &c, mid);
if (n == CALL_MAXARGS) {
mrb_ary_unshift(mrb, regs[a+1], sym);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment