Add operators to `presym` from `Rakefile`.
MODIFY
Rakefile
Rakefile
@@ -112,34 +112,6 @@ rbfiles = (Dir.glob("#{MRUBY_ROOT}/mrblib/*.rb")+
Dir.glob("#{MRUBY_ROOT}/mrbgems/*/mrblib/*.rb")+
Dir.glob("#{MRUBY_ROOT}/build/*/mrbgems/**/mrblib/*.rb")).uniq
presym_file="#{MRUBY_ROOT}/build/presym"
-
-desc "preallocated symbols"
-file presym_file => cfiles+rbfiles do
- csymbols = cfiles.map do |f|
- src = File.read(f)
- [src.scan(/intern_lit\([^\n"]*"([^\n "]*)"/),
- src.scan(/mrb_define_method\([^\n"]*"([^\n"]*)"/),
- src.scan(/mrb_define_class\([^\n"]*"([^\n"]*)"/),
- src.scan(/mrb_define_module\([^\n"]*"([^\n"]*)"/),
- src.scan(/MRB_SYM\((\w+)\)/)]
- end
- rbsymbols = rbfiles.map do |f|
- src = File.read(f)
- [src.scan(/\bclass +([A-Z]\w*)/),
- src.scan(/\bmodule +([A-Z]\w*)/),
- src.scan(/\bdef +(\w+)/)]
- end
- symbols = (csymbols+rbsymbols).flatten.uniq.sort
- presyms = File.readlines(presym_file, chomp: true) rescue []
- if presyms != symbols
- File.write(presym_file, symbols.join("\n"))
- end
-end
-
-presym_inc=presym_file+".inc"
-file presym_inc => presym_file do
- presyms = File.readlines(presym_file, chomp: true)
- File.open(presym_inc, "w") do |f|
op_table = {
"!" => "not",
"!=" => "neq",
@@ -172,6 +144,36 @@ file presym_inc => presym_file do
"||" => "oror",
"~" => "neg",
}
+
+file presym_file => cfiles+rbfiles do
+ csymbols = cfiles.map do |f|
+ src = File.read(f)
+ [src.scan(/intern_lit\([^\n"]*"([^\n "]*)"/),
+ src.scan(/mrb_define_method\([^\n"]*"([^\n"]*)"/),
+ src.scan(/mrb_define_class\([^\n"]*"([^\n"]*)"/),
+ src.scan(/mrb_define_module\([^\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!(/^a_/, "@") || x.sub!(/^d_/, "$")
+ }.compact]
+ end
+ rbsymbols = rbfiles.map do |f|
+ src = File.read(f)
+ [src.scan(/\bclass +([A-Z]\w*)/),
+ src.scan(/\bmodule +([A-Z]\w*)/),
+ src.scan(/\bdef +(\w+)/)]
+ end
+ symbols = (csymbols+rbsymbols+op_table.keys).flatten.compact.uniq.sort
+ presyms = File.readlines(presym_file, chomp: true) rescue []
+ if presyms != symbols
+ File.write(presym_file, symbols.join("\n"))
+ end
+end
+
+presym_inc=presym_file+".inc"
+file presym_inc => presym_file do
+ presyms = File.readlines(presym_file, chomp: true)
+ 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(sym, name, num) - symbol with alias name */\n"
f.print "/* MRB_PRESYM_SYM(sym, num) - symbol which is not valid C id */\n\n"
@@ -186,6 +188,9 @@ file presym_inc => presym_file do
elsif /\!\Z/ =~ sym
s = sym.dup; s[-1] = "_b"
f.print "MRB_PRESYM_QSYM(#{sym}, #{s}, #{i+1})\n"
+ elsif /\=\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] = "a_"
f.print "MRB_PRESYM_QSYM(#{sym}, #{s}, #{i+1})\n"
@@ -200,8 +205,9 @@ file presym_inc => presym_file do
end
end
+desc "preallocated symbols"
task :gensym => presym_inc
-depfiles.unshift "gensym"
+#task :all => :gensym
depfiles += MRuby.targets.map { |n, t|
t.libraries

Add operators to `presym` from `Rakefile`.