[前][次][番号順一覧][スレッド一覧]

ruby-changes:73479

From: Nobuyoshi <ko1@a...>
Date: Thu, 8 Sep 2022 19:09:53 +0900 (JST)
Subject: [ruby-changes:73479] a977c66312 (master): Generate token ID indexes in id.def

https://git.ruby-lang.org/ruby.git/commit/?id=a977c66312

From a977c663123f7256f51201ed8390dc84adf63cf6 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 8 Sep 2022 15:25:05 +0900
Subject: Generate token ID indexes in id.def

Separate the logic accross the tables from the template view for
id.h.
---
 defs/id.def        |  4 +++-
 template/id.c.tmpl |  2 +-
 template/id.h.tmpl | 10 +++-------
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/defs/id.def b/defs/id.def
index 097e34e405..94af02b12f 100644
--- a/defs/id.def
+++ b/defs/id.def
@@ -194,13 +194,14 @@ predefined.split(/^/).each_with_index do |line, num| https://github.com/ruby/ruby/blob/trunk/defs/id.def#L194
   end << token
   predefined_ids[token] = name
 end
+index = 127
 token_ops.split(/^/).each do |line|
   next if /^#/ =~ line
   line.sub!(/\s+#.*/, '')
   id, op, token = line.split
   next unless id and op
   token ||= (id unless /\A\W\z/ =~ op)
-  token_op_ids << [id, op, token]
+  token_op_ids << [id, op, token, (index += 1 if token)]
 end
 {
   "LOCAL" => local_ids,
@@ -212,4 +213,5 @@ end https://github.com/ruby/ruby/blob/trunk/defs/id.def#L213
   :preserved => preserved_ids,
   :predefined => predefined_ids,
   :token_op => token_op_ids,
+  :last_token => index,
 }
diff --git a/template/id.c.tmpl b/template/id.c.tmpl
index 4f30875c04..5b9e879730 100644
--- a/template/id.c.tmpl
+++ b/template/id.c.tmpl
@@ -12,7 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/template/id.c.tmpl#L12
 **********************************************************************/
 <%
 defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
-ids = eval(File.read(defs), binding, defs)
+ids = eval(File.read(defs), nil, defs)
 ops = ids[:token_op].uniq {|id, op, token| token && op}
 %>
 % ops.each do |_id, _op, token|
diff --git a/template/id.h.tmpl b/template/id.h.tmpl
index 687cbbbe40..9c588305eb 100644
--- a/template/id.h.tmpl
+++ b/template/id.h.tmpl
@@ -11,10 +11,8 @@ https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L11
 
 **********************************************************************/
 <%
-op_id_offset = 128
-
 defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
-ids = eval(File.read(defs), binding, defs)
+ids = eval(File.read(defs), nil, defs)
 types = ids.keys.grep(/^[A-Z]/)
 %>
 #ifndef RUBY_ID_H
@@ -49,11 +47,9 @@ enum ruby_id_types { https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L47
 #define symIFUNC ID2SYM(idIFUNC)
 #define symCFUNC ID2SYM(idCFUNC)
 
-% index = op_id_offset
-% ids[:token_op].each do |_id, _op, token|
+% ids[:token_op].each do |_id, _op, token, index|
 %   next unless token
 #define RUBY_TOKEN_<%=token%> <%=index%>
-%   index += 1
 % end
 #define RUBY_TOKEN(t) RUBY_TOKEN_##t
 
@@ -66,7 +62,7 @@ enum ruby_method_ids { https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L62
 % ids[:token_op].uniq {|_, op| op}.each do |id, op, token|
     id<%=id%> = <%=token ? "RUBY_TOKEN(#{token})" : "'#{op}'"%>,
 % end
-    tPRESERVED_ID_BEGIN = <%=index-1%>,
+    tPRESERVED_ID_BEGIN = <%=ids[:last_token]%>,
 % ids[:preserved].each do |token|
     id<%=token%>,
 % end
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]