зеркало из https://github.com/github/ruby.git
* include/ruby/encoding.h (rb_enc_ispunct): added.
* common.mk (COMMONOBJS), inits.c (rb_call_inits): id.c is now included from parse.c. * id.c (Init_id), id.h (ruby_method_ids): added IDs used by VM. * parse.y (global_symbols): added rooms for VM IDs. * parse.y (rb_intern3, rb_id2str): single puctuation symbol is now same as char code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c710140216
Коммит
dc02325fd8
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
Thu Aug 14 17:57:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* include/ruby/encoding.h (rb_enc_ispunct): added.
|
||||
|
||||
* common.mk (COMMONOBJS), inits.c (rb_call_inits): id.c is now
|
||||
included from parse.c.
|
||||
|
||||
* id.c (Init_id), id.h (ruby_method_ids): added IDs used by VM.
|
||||
|
||||
* parse.y (global_symbols): added rooms for VM IDs.
|
||||
|
||||
* parse.y (rb_intern3, rb_id2str): single puctuation symbol is now
|
||||
same as char code.
|
||||
|
||||
Thu Aug 14 17:46:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* parse.y (union tmpyystype): no longer needed, since YYSTYPE is
|
||||
|
|
|
@ -79,7 +79,6 @@ COMMONOBJS = array.$(OBJEXT) \
|
|||
vm_dump.$(OBJEXT) \
|
||||
thread.$(OBJEXT) \
|
||||
cont.$(OBJEXT) \
|
||||
id.$(OBJEXT) \
|
||||
$(BUILTIN_ENCOBJS) \
|
||||
$(MISSING)
|
||||
|
||||
|
|
65
id.c
65
id.c
|
@ -11,49 +11,40 @@
|
|||
|
||||
#include "ruby/ruby.h"
|
||||
|
||||
#define YYSTYPE_IS_DECLARED
|
||||
#define extern
|
||||
#include "id.h"
|
||||
#undef extern
|
||||
|
||||
void
|
||||
static void
|
||||
Init_id(void)
|
||||
{
|
||||
#undef rb_intern
|
||||
#define rb_intern(str) rb_intern2(str, strlen(str))
|
||||
rb_encoding *enc = rb_usascii_encoding();
|
||||
|
||||
/* Symbols */
|
||||
symIFUNC = ID2SYM(rb_intern("<IFUNC>"));
|
||||
symCFUNC = ID2SYM(rb_intern("<CFUNC>"));
|
||||
REGISTER_SYMID(idNULL, "");
|
||||
REGISTER_SYMID(idIFUNC, "<IFUNC>"),
|
||||
REGISTER_SYMID(idCFUNC, "<CFUNC>"),
|
||||
REGISTER_SYMID(idRespond_to, "respond_to?"),
|
||||
REGISTER_SYMID(idThrowState, "#__ThrowState__"),
|
||||
|
||||
/* IDs */
|
||||
idEach = rb_intern("each");
|
||||
idTimes = rb_intern("times");
|
||||
idLength = rb_intern("length");
|
||||
idLambda = rb_intern("lambda");
|
||||
idIntern = rb_intern("intern");
|
||||
idGets = rb_intern("gets");
|
||||
idSucc = rb_intern("succ");
|
||||
idEnd = rb_intern("end");
|
||||
idRangeEachLT = rb_intern("Range#each#LT");
|
||||
idRangeEachLE = rb_intern("Range#each#LE");
|
||||
idArrayEach = rb_intern("Array#each");
|
||||
idMethodMissing = rb_intern("method_missing");
|
||||
REGISTER_SYMID(id_core_set_method_alias, "core#set_method_alias"),
|
||||
REGISTER_SYMID(id_core_set_variable_alias, "core#set_variable_alias"),
|
||||
REGISTER_SYMID(id_core_undef_method, "core#undef_method"),
|
||||
REGISTER_SYMID(id_core_define_method, "core#define_method"),
|
||||
REGISTER_SYMID(id_core_define_singleton_method, "core#define_singleton_method"),
|
||||
REGISTER_SYMID(id_core_set_postexe, "core#set_postexe"),
|
||||
|
||||
idThrowState = rb_intern("#__ThrowState__");
|
||||
|
||||
idBitblt = rb_intern("bitblt");
|
||||
idAnswer = rb_intern("the_answer_to_life_the_universe_and_everything");
|
||||
|
||||
idSend = rb_intern("send");
|
||||
id__send__ = rb_intern("__send__");
|
||||
|
||||
idRespond_to = rb_intern("respond_to?");
|
||||
idInitialize = rb_intern("initialize");
|
||||
|
||||
id_core_set_method_alias = rb_intern("core_set_method_alias");
|
||||
id_core_set_variable_alias = rb_intern("core_set_variable_alias");
|
||||
id_core_undef_method = rb_intern("core_undef_method");
|
||||
id_core_define_method = rb_intern("core_define_method");
|
||||
id_core_define_singleton_method = rb_intern("core_define_singleton_method");
|
||||
id_core_set_postexe = rb_intern("core_set_postexe");
|
||||
REGISTER_SYMID(idEach, "each");
|
||||
REGISTER_SYMID(idLength, "length");
|
||||
REGISTER_SYMID(idLambda, "lambda");
|
||||
REGISTER_SYMID(idIntern, "intern");
|
||||
REGISTER_SYMID(idGets, "gets");
|
||||
REGISTER_SYMID(idSucc, "succ");
|
||||
REGISTER_SYMID(idMethodMissing, "method_missing");
|
||||
#if SUPPORT_JOKE
|
||||
REGISTER_SYMID(idBitblt, "bitblt");
|
||||
REGISTER_SYMID(idAnswer, "the_answer_to_life_the_universe_and_everything");
|
||||
#endif
|
||||
REGISTER_SYMID(idSend, "send");
|
||||
REGISTER_SYMID(id__send__, "__send__");
|
||||
REGISTER_SYMID(idInitialize, "initialize");
|
||||
}
|
||||
|
|
72
id.h
72
id.h
|
@ -12,10 +12,21 @@
|
|||
#ifndef RUBY_ID_H
|
||||
#define RUBY_ID_H
|
||||
|
||||
#define ID_SCOPE_SHIFT 3
|
||||
#define ID_SCOPE_MASK 0x07
|
||||
#define ID_LOCAL 0x00
|
||||
#define ID_INSTANCE 0x01
|
||||
#define ID_GLOBAL 0x03
|
||||
#define ID_ATTRSET 0x04
|
||||
#define ID_CONST 0x05
|
||||
#define ID_CLASS 0x06
|
||||
#define ID_JUNK 0x07
|
||||
#define ID_INTERNAL ID_JUNK
|
||||
|
||||
#include "parse.h"
|
||||
|
||||
extern VALUE symIFUNC;
|
||||
extern VALUE symCFUNC;
|
||||
#define symIFUNC ID2SYM(idIFUNC)
|
||||
#define symCFUNC ID2SYM(idCFUNC)
|
||||
|
||||
enum ruby_method_ids {
|
||||
idPLUS = '+',
|
||||
|
@ -36,34 +47,37 @@ enum ruby_method_ids {
|
|||
idEqTilde = tMATCH,
|
||||
idAREF = tAREF,
|
||||
idASET = tASET,
|
||||
idDummy
|
||||
idLAST_TOKEN = tLAST_TOKEN >> ID_SCOPE_SHIFT,
|
||||
tIntern,
|
||||
tMethodMissing,
|
||||
tLength,
|
||||
tGets,
|
||||
tSucc,
|
||||
tEach,
|
||||
tLambda,
|
||||
tSend,
|
||||
t__send__,
|
||||
tInitialize,
|
||||
#if SUPPORT_JOKE
|
||||
tBitblt,
|
||||
tAnswer,
|
||||
#endif
|
||||
tLAST_ID
|
||||
};
|
||||
|
||||
extern ID idThrowState;
|
||||
extern ID idIntern;
|
||||
extern ID idMethodMissing;
|
||||
extern ID idLength;
|
||||
extern ID idGets;
|
||||
extern ID idSucc;
|
||||
extern ID idEach;
|
||||
extern ID idLambda;
|
||||
extern ID idRangeEachLT;
|
||||
extern ID idRangeEachLE;
|
||||
extern ID idArrayEach;
|
||||
extern ID idTimes;
|
||||
extern ID idEnd;
|
||||
extern ID idBitblt;
|
||||
extern ID idAnswer;
|
||||
extern ID idSend;
|
||||
extern ID id__send__;
|
||||
extern ID idRespond_to;
|
||||
extern ID idInitialize;
|
||||
|
||||
extern ID id_core_set_method_alias;
|
||||
extern ID id_core_set_variable_alias;
|
||||
extern ID id_core_undef_method;
|
||||
extern ID id_core_define_method;
|
||||
extern ID id_core_define_singleton_method;
|
||||
extern ID id_core_set_postexe;
|
||||
#define idIntern ((tIntern<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define idMethodMissing ((tMethodMissing<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define idLength ((tLength<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define idGets ((tGets<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define idSucc ((tSucc<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define idEach ((tEach<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define idLambda ((tLambda<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define idSend ((tSend<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define id__send__ ((t__send__<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define idInitialize ((tInitialize<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#if SUPPORT_JOKE
|
||||
#define idBitblt ((tBitblt<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#define idAnswer ((tAnswer<<ID_SCOPE_SHIFT)|ID_LOCAL)
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_ID_H */
|
||||
|
|
|
@ -143,6 +143,7 @@ int rb_enc_codelen(int code, rb_encoding *enc);
|
|||
#define rb_enc_isalpha(c,enc) ONIGENC_IS_CODE_ALPHA(enc,c)
|
||||
#define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER(enc,c)
|
||||
#define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER(enc,c)
|
||||
#define rb_enc_ispunct(c,enc) ONIGENC_IS_CODE_PUNCT(enc,c)
|
||||
#define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM(enc,c)
|
||||
#define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT(enc,c)
|
||||
#define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE(enc,c)
|
||||
|
|
2
inits.c
2
inits.c
|
@ -36,7 +36,6 @@ void Init_Object(void);
|
|||
void Init_pack(void);
|
||||
void Init_Precision(void);
|
||||
void Init_sym(void);
|
||||
void Init_id(void);
|
||||
void Init_process(void);
|
||||
void Init_RandomSeed(void);
|
||||
void Init_Random(void);
|
||||
|
@ -61,7 +60,6 @@ rb_call_inits()
|
|||
{
|
||||
Init_RandomSeed();
|
||||
Init_sym();
|
||||
Init_id();
|
||||
Init_var_tables();
|
||||
Init_Object();
|
||||
Init_top_self();
|
||||
|
|
95
parse.y
95
parse.y
|
@ -35,16 +35,11 @@
|
|||
#define calloc YYCALLOC
|
||||
#define free YYFREE
|
||||
|
||||
#define ID_SCOPE_SHIFT 3
|
||||
#define ID_SCOPE_MASK 0x07
|
||||
#define ID_LOCAL 0x00
|
||||
#define ID_INSTANCE 0x01
|
||||
#define ID_GLOBAL 0x03
|
||||
#define ID_ATTRSET 0x04
|
||||
#define ID_CONST 0x05
|
||||
#define ID_CLASS 0x06
|
||||
#define ID_JUNK 0x07
|
||||
#define ID_INTERNAL ID_JUNK
|
||||
#ifndef RIPPER
|
||||
static ID register_symid(ID, const char *, long, rb_encoding *);
|
||||
#define REGISTER_SYMID(id, name) register_symid(id, name, strlen(name), enc)
|
||||
#include "id.c"
|
||||
#endif
|
||||
|
||||
#define is_notop_id(id) ((id)>tLAST_TOKEN)
|
||||
#define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL)
|
||||
|
@ -495,6 +490,10 @@ static VALUE ripper_dispatch5(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,V
|
|||
|
||||
static VALUE ripper_intern(const char*);
|
||||
static VALUE ripper_id2sym(ID);
|
||||
#ifdef __GNUC__
|
||||
#define ripper_id2sym(id) ((id) < 256 && rb_ispunct(id) ? \
|
||||
ID2SYM(id) : ripper_id2sym(id))
|
||||
#endif
|
||||
|
||||
#define arg_new() dispatch0(args_new)
|
||||
#define arg_add(l,a) dispatch2(args_add, l, a)
|
||||
|
@ -732,6 +731,18 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
|
|||
%right tPOW
|
||||
%right '!' '~' tUPLUS
|
||||
|
||||
%nonassoc idNULL
|
||||
%nonassoc idRespond_to
|
||||
%nonassoc idIFUNC
|
||||
%nonassoc idCFUNC
|
||||
%nonassoc idThrowState
|
||||
%nonassoc id_core_set_method_alias
|
||||
%nonassoc id_core_set_variable_alias
|
||||
%nonassoc id_core_undef_method
|
||||
%nonassoc id_core_define_method
|
||||
%nonassoc id_core_define_singleton_method
|
||||
%nonassoc id_core_set_postexe
|
||||
|
||||
%token tLAST_TOKEN
|
||||
|
||||
%%
|
||||
|
@ -8796,41 +8807,28 @@ static const struct {
|
|||
} op_tbl[] = {
|
||||
{tDOT2, ".."},
|
||||
{tDOT3, "..."},
|
||||
{'+', "+"},
|
||||
{'-', "-"},
|
||||
{'+', "+(binary)"},
|
||||
{'-', "-(binary)"},
|
||||
{'*', "*"},
|
||||
{'/', "/"},
|
||||
{'%', "%"},
|
||||
{tPOW, "**"},
|
||||
{tUPLUS, "+@"},
|
||||
{tUMINUS, "-@"},
|
||||
{'|', "|"},
|
||||
{'^', "^"},
|
||||
{'&', "&"},
|
||||
{'!', "!"},
|
||||
{tCMP, "<=>"},
|
||||
{'>', ">"},
|
||||
{tGEQ, ">="},
|
||||
{'<', "<"},
|
||||
{tLEQ, "<="},
|
||||
{tEQ, "=="},
|
||||
{tEQQ, "==="},
|
||||
{tNEQ, "!="},
|
||||
{tMATCH, "=~"},
|
||||
{tNMATCH, "!~"},
|
||||
{'~', "~"},
|
||||
{'!', "!"},
|
||||
{tAREF, "[]"},
|
||||
{tASET, "[]="},
|
||||
{tLSHFT, "<<"},
|
||||
{tRSHFT, ">>"},
|
||||
{tCOLON2, "::"},
|
||||
{'`', "`"},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
#define op_tbl_count (sizeof(op_tbl) / sizeof(op_tbl[0]))
|
||||
|
||||
static struct symbols {
|
||||
ID last_id;
|
||||
st_table *sym_id;
|
||||
|
@ -8838,7 +8836,7 @@ static struct symbols {
|
|||
st_table *ivar2_id;
|
||||
st_table *id_ivar2;
|
||||
VALUE op_sym[tLAST_TOKEN];
|
||||
} global_symbols = {tLAST_TOKEN >> ID_SCOPE_SHIFT};
|
||||
} global_symbols = {tLAST_ID};
|
||||
|
||||
static const struct st_hash_type symhash = {
|
||||
rb_str_hash_cmp,
|
||||
|
@ -8877,7 +8875,8 @@ Init_sym(void)
|
|||
global_symbols.id_str = st_init_numtable_with_size(1000);
|
||||
global_symbols.ivar2_id = st_init_table_with_size(&ivar2_hash_type, 1000);
|
||||
global_symbols.id_ivar2 = st_init_numtable_with_size(1000);
|
||||
rb_intern2("", 0);
|
||||
|
||||
Init_id();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -9022,11 +9021,22 @@ rb_enc_symname2_p(const char *name, int len, rb_encoding *enc)
|
|||
return *m ? Qfalse : Qtrue;
|
||||
}
|
||||
|
||||
static ID
|
||||
register_symid(ID id, const char *name, long len, rb_encoding *enc)
|
||||
{
|
||||
VALUE str = rb_enc_str_new(name, len, enc);
|
||||
OBJ_FREEZE(str);
|
||||
st_add_direct(global_symbols.sym_id, (st_data_t)str, id);
|
||||
st_add_direct(global_symbols.id_str, id, (st_data_t)str);
|
||||
return id;
|
||||
}
|
||||
|
||||
ID
|
||||
rb_intern3(const char *name, long len, rb_encoding *enc)
|
||||
{
|
||||
const char *m = name;
|
||||
const char *e = m + len;
|
||||
unsigned char c;
|
||||
VALUE str;
|
||||
ID id;
|
||||
int last;
|
||||
|
@ -9068,12 +9078,16 @@ rb_intern3(const char *name, long len, rb_encoding *enc)
|
|||
m++;
|
||||
break;
|
||||
default:
|
||||
if (m[0] != '_' && rb_enc_isascii((unsigned char)m[0], enc)
|
||||
&& !rb_enc_isalnum(m[0], enc)) {
|
||||
c = m[0];
|
||||
if (c != '_' && rb_enc_isascii(c, enc) && rb_enc_ispunct(c, enc)) {
|
||||
/* operators */
|
||||
int i;
|
||||
|
||||
for (i=0; op_tbl[i].token; i++) {
|
||||
if (len == 1) {
|
||||
id = c;
|
||||
goto id_register;
|
||||
}
|
||||
for (i = 0; i < op_tbl_count; i++) {
|
||||
if (*op_tbl[i].name == *m &&
|
||||
strcmp(op_tbl[i].name, m) == 0) {
|
||||
id = op_tbl[i].token;
|
||||
|
@ -9129,11 +9143,7 @@ rb_intern3(const char *name, long len, rb_encoding *enc)
|
|||
new_id:
|
||||
id |= ++global_symbols.last_id << ID_SCOPE_SHIFT;
|
||||
id_register:
|
||||
str = rb_enc_str_new(name, len, enc);
|
||||
OBJ_FREEZE(str);
|
||||
st_add_direct(global_symbols.sym_id, (st_data_t)str, id);
|
||||
st_add_direct(global_symbols.id_str, id, (st_data_t)str);
|
||||
return id;
|
||||
return register_symid(id, name, len, enc);
|
||||
}
|
||||
|
||||
ID
|
||||
|
@ -9174,7 +9184,19 @@ rb_id2str(ID id)
|
|||
if (id < tLAST_TOKEN) {
|
||||
int i = 0;
|
||||
|
||||
for (i=0; op_tbl[i].token; i++) {
|
||||
if (rb_ispunct(id)) {
|
||||
VALUE str = global_symbols.op_sym[i = (int)id];
|
||||
if (!str) {
|
||||
char name[2];
|
||||
name[0] = (char)id;
|
||||
name[1] = 0;
|
||||
str = rb_usascii_str_new(name, 1);
|
||||
OBJ_FREEZE(str);
|
||||
global_symbols.op_sym[i] = str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
for (i = 0; i < op_tbl_count; i++) {
|
||||
if (op_tbl[i].token == id) {
|
||||
VALUE str = global_symbols.op_sym[i];
|
||||
if (!str) {
|
||||
|
@ -9694,6 +9716,7 @@ keyword_id_to_str(ID id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#undef ripper_id2sym
|
||||
static VALUE
|
||||
ripper_id2sym(ID id)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче