diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | defs/id.def | 34 | ||||
-rw-r--r-- | template/id.c.tmpl | 5 | ||||
-rw-r--r-- | template/id.h.tmpl | 19 |
4 files changed, 47 insertions, 16 deletions
@@ -1,3 +1,8 @@ +Fri Dec 21 16:38:00 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * defs/id.def: support for other scope IDs, + ID_{INSTANCE,GLOBAL,CONST,CLASS}. + Fri Dec 21 14:45:00 2012 Zachary Scott <zachary@zacharyscott.net> * lib/irb.rb, lib/irb/*: Documentation for IRB diff --git a/defs/id.def b/defs/id.def index 0c47bd7804..a9b189f5aa 100644 --- a/defs/id.def +++ b/defs/id.def @@ -1,5 +1,5 @@ -# -*- ruby -*- -predefined = %[\ +# -*- mode: ruby; coding: us-ascii -*- +firstline, predefined = __LINE__+1, %[\ intern method_missing MethodMissing length @@ -35,16 +35,40 @@ predefined = %[\ predefined_ids = {} preserved_ids = [] -attr_ids = [] -predefined.each_line do |line| +local_ids = [] +instance_ids = [] +global_ids = [] +const_ids = [] +class_ids = [] +names = {} +predefined.lines.each_with_index do |line, num| next if /^#/ =~ line or (name, token = line.split; !name) token ||= name if /#/ =~ token token = "_#{token.gsub(/\W+/, '_')}" else token = token.sub(/\?/, 'P').sub(/\A[a-z]/) {$&.upcase} + token.sub!(/\A\$/, "_G_") + token.sub!(/\A@@/, "_C_") + token.sub!(/\A@/, "_I_") token.gsub!(/\W+/, "") end - (/\A(?!\d)\w+\z/ =~ name ? attr_ids : preserved_ids) << token + case name + when /\A[A-Z]\w*\z/; const_ids + when /\A(?!\d)\w+\z/; local_ids + when /\A\$(?:\d+|(?!\d)\w+)\z/; global_ids + when /\A@@(?!\d)\w+\z/; class_ids + when /\A@(?!\d)\w+\z/; instance_ids + else preserved_ids + end << token predefined_ids[token] = name end +{ + "LOCAL" => local_ids, + "INSTANCE" => instance_ids, + "GLOBAL" => global_ids, + "CONST" => const_ids, + "CLASS" => class_ids, + :preserved => preserved_ids, + :predefined => predefined_ids, +} diff --git a/template/id.c.tmpl b/template/id.c.tmpl index 4f54f8b4a0..4a272a98ba 100644 --- a/template/id.c.tmpl +++ b/template/id.c.tmpl @@ -11,9 +11,8 @@ **********************************************************************/ <% -predefined_ids = nil defs = File.join(File.dirname(erb.filename), "../defs/id.def") -eval(File.read(defs), binding, defs) +ids = eval(File.read(defs), binding, defs) %> static void Init_id(void) @@ -22,7 +21,7 @@ Init_id(void) #define rb_intern(str) rb_intern_const(str) rb_encoding *enc = rb_usascii_encoding(); -% predefined_ids.each_pair do |token, name| +% ids[:predefined].each do |token, name| REGISTER_SYMID(id<%=token%>, "<%=name%>"); % end } diff --git a/template/id.h.tmpl b/template/id.h.tmpl index b918bb8953..8df17b398b 100644 --- a/template/id.h.tmpl +++ b/template/id.h.tmpl @@ -21,10 +21,9 @@ token_op_ids = %w[ tCOLON2 tCOLON3 ] -preserved_ids = nil -attr_ids = nil defs = File.join(File.dirname(erb.filename), "../defs/id.def") -eval(File.read(defs), binding, defs) +ids = eval(File.read(defs), binding, defs) +types = ids.keys.grep(/^[A-Z]/) %> #ifndef RUBY_ID_H #define RUBY_ID_H @@ -75,16 +74,20 @@ enum ruby_method_ids { idAREF = RUBY_TOKEN(AREF), idASET = RUBY_TOKEN(ASET), tPRESERVED_ID_BEGIN = <%=op_id_offset + token_op_ids.size - 1%>, -% preserved_ids.each do |token| +% ids[:preserved].each do |token| id<%=token%>, % end tPRESERVED_ID_END, -% attr_ids.each do |token| +% ids.values_at(*types).flatten.each do |token| t<%=token%>, % end -#define TOKEN2ID(n) id##n = ((t##n<<ID_SCOPE_SHIFT)|ID_LOCAL) -% attr_ids.each do |token| - TOKEN2ID(<%=token%>), +% types.each do |type| +% types = ids[type] or next +% types.empty? and next +#define TOKEN2<%=type%>ID(n) id##n = ((t##n<<ID_SCOPE_SHIFT)|ID_<%=type%>) +% types.each do |token| + TOKEN2<%=type%>ID(<%=token%>), +% end % end tLAST_OP_ID = tPRESERVED_ID_END-1, idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT |