summaryrefslogtreecommitdiffhomepage
path: root/Rakefile
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2020-11-11 23:59:45 +0900
committerKOBAYASHI Shuji <[email protected]>2020-11-13 13:41:20 +0900
commit89f591485b91780c213f459f840111a99adca9d0 (patch)
treed32adaba112c1cda8eeb5d6c7293a7a3e906bc89 /Rakefile
parent6a5e97b448e82fe55348ab1a7e96b70b2c45f6c1 (diff)
downloadmruby-89f591485b91780c213f459f840111a99adca9d0.tar.gz
mruby-89f591485b91780c213f459f840111a99adca9d0.zip
Change name and usage of presym macros
To be also able to build mruby without presym in the future. However, `MRB_QSYM` has been removed and changed as follows: ### Example | Type | Symbol | Previous Style | New Style | |---------------------------|--------|------------------|----------------| | Operator | & | MRB_QSYM(and) | MRB_OPSYM(and) | | Class Variable | @@foo | MRB_QSYM(00_foo) | MRB_CVSYM(foo) | | Instance Variable | @foo | MRB_QSYM(0_foo) | MRB_IVSYM(foo) | | Method with Bang | foo! | MRB_QSYM(foo_b) | MRB_SYM_B(foo) | | Method with Question mark | foo? | MRB_QSYM(foo_p) | MRB_SYM_Q(foo) | | Mmethod with Equal | foo= | MRB_QSYM(foo_e) | MRB_SYM_E(foo) | This change makes it possible to define, for example, `MRB_IVSYM(foo)` as `mrb_intern_lit(mrb, "@" "foo")`, which is useful if we support building without presym in the future.
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile60
1 files changed, 29 insertions, 31 deletions
diff --git a/Rakefile b/Rakefile
index 2d88cde99..9869dc62e 100644
--- a/Rakefile
+++ b/Rakefile
@@ -148,8 +148,21 @@ op_table = {
"||" => "oror",
"~" => "neg",
}
+macro_to_symbol = {
+# Macro Symbol
+# [prefix, suffix] => [prefix, suffix]
+ ["CV" , "" ] => ["@@" , "" ],
+ ["IV" , "" ] => ["@" , "" ],
+ ["" , "_B" ] => ["" , "!" ],
+ ["" , "_Q" ] => ["" , "?" ],
+ ["" , "_E" ] => ["" , "=" ],
+ ["" , "" ] => ["" , "" ],
+}
file presym_file => cfiles+rbfiles+psfiles+[__FILE__] do
+ prefix_re = Regexp.union(*macro_to_symbol.keys.uniq.map(&:first))
+ suffix_re = Regexp.union(*macro_to_symbol.keys.uniq.map(&:last))
+ macro_re = /MRB_(#{prefix_re})SYM(#{suffix_re})\((\w+)\)/o
csymbols = cfiles.map do |f|
src = File.read(f)
src.gsub!(/\/\/.+(\n|$)/, "\n")
@@ -161,10 +174,9 @@ file presym_file => cfiles+rbfiles+psfiles+[__FILE__] do
src.scan(/mrb_define_module_function\([^\n"]*"([^\n"]*)"/),
src.scan(/mrb_define_const\([^\n"]*"([^\n"]*)"/),
src.scan(/mrb_define_global_const\([^\n"]*"([^\n"]*)"/),
- src.scan(/MRB_SYM\((\w+)\)/),
- src.scan(/MRB_QSYM\((\w+)\)/).map{|x,|
- x.sub!(/_p$/, "?") || x.sub!(/_b$/, "!") || x.sub!(/_e$/, "=") || x.sub!(/^0_/, "@") || x.sub!(/^00_/, "@@")
- }.compact]
+ src.scan(macro_re).map{|prefix, suffix, name|
+ macro_to_symbol[[prefix, suffix]] * name
+ }]
end
rbsymbols = rbfiles.map do |f|
src = File.read(f)
@@ -197,34 +209,20 @@ end
task presym_inc do
presyms = File.readlines(presym_file)
presyms.each{|x| x.chomp!}
+ symbol_to_macro = macro_to_symbol.invert
+ prefix_re = Regexp.union(*symbol_to_macro.keys.uniq.map(&:first))
+ suffix_re = Regexp.union(*symbol_to_macro.keys.uniq.map(&:last))
+ macro_re = /\A(#{prefix_re})?([\w&&\D]\w*)(#{suffix_re})?\z/o
File.open(presym_inc, "w") do |f|
- f.print "/* MRB_PRESYM_CSYM(sym, num) - symbol which is valid C id name */\n"
- f.print "/* MRB_PRESYM_QSYM(name, sym, num) - symbol with alias name */\n"
- f.print "/* MRB_PRESYM_SYM(name, num) - symbol which is not valid C id */\n"
- presyms.each.with_index do |sym,i|
- if sym.bytes.detect{|x|x>0x80} || /\A\$/ =~ sym
- f.print "MRB_PRESYM_SYM(\"#{sym}\", #{i+1})\n"
- elsif /\A\w+\Z/ =~ sym
- f.print "MRB_PRESYM_CSYM(#{sym}, #{i+1})\n"
- elsif op_table.key?(sym)
- f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{op_table[sym]}, #{i+1})\n"
- elsif /\A[A-Za-z_]\w*\?\Z/ =~ sym
- s = sym.dup; s[-1] = "_p"
- f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
- elsif /\A[A-Za-z_]\w*\!\Z/ =~ sym
- s = sym.dup; s[-1] = "_b"
- f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
- elsif /\A[A-Za-z_]\w*\=\Z/ =~ sym
- s = sym.dup; s[-1] = "_e"
- f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
- elsif /\A@@/ =~ sym
- s = sym.dup; s[0,2] = "00_"
- f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
- elsif /\A@/ =~ sym
- s = sym.dup; s[0] = "0_"
- f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
- else
- f.print "MRB_PRESYM_SYM(\"#{sym}\", #{i+1})\n"
+ f.puts "/* MRB_PRESYM_NAMED(lit, num, type, name) */"
+ f.puts "/* MRB_PRESYM_UNNAMED(lit, num) */"
+ presyms.each.with_index(1) do |sym, num|
+ if macro_re =~ sym && (affixes = symbol_to_macro[[$1, $3]])
+ f.puts %|MRB_PRESYM_NAMED("#{sym}", #{num}, #{affixes * 'SYM'}, #{$2})|
+ elsif name = op_table[sym]
+ f.puts %|MRB_PRESYM_NAMED("#{sym}", #{num}, OPSYM, #{name})|
+ elsif
+ f.puts %|MRB_PRESYM_UNNAMED("#{sym}", #{num})|
end
end
f.print "#define MRB_PRESYM_MAX #{presyms.size}"