From 1bcf6d9f3cacf6a5c54ee0c74d0dad0f0e9ed436 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 15 May 2020 16:44:36 +0900 Subject: Create `MRB_OPSYM()` macro to refer symbols corresponding operators. For example, `MRB_OPSYM(add)` refers a symbol for `+`. --- Rakefile | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'Rakefile') diff --git a/Rakefile b/Rakefile index 8c7533b43..2aa96fc1a 100644 --- a/Rakefile +++ b/Rakefile @@ -146,11 +146,46 @@ file presym_inc => presym_file do presyms = File.readlines(presym_file, chomp: true) rm_f presym_inc File.open(presym_inc, "w") do |f| + op_table = { + "!" => "not", + "!=" => "neq", + "!~" => "nmatch", + "%" => "mod", + "&" => "and", + "&&" => "andand", + "*" => "mul", + "**" => "pow", + "+" => "add", + "+@" => "plus", + "-" => "sub", + "-@" => "minus", + "/" => "div", + "<" => "lt", + "<=" => "le", + "<<" => "lshift", + "<=>" => "cmp", + "==" => "eq", + "===" => "eqq", + "=~" => "match", + ">" => "gt", + ">=" => "ge", + ">>" => "rshift", + "[]" => "aref", + "[]=" => "aset", + "^" => "xor", + "`" => "tick", + "|" => "or", + "||" => "oror", + "~" => "neg", + } f.print "/* MRB_PRESYM_CSYM(sym, num) - symbol which is valid C id name */\n" + f.print "/* MRB_PRESYM_OPSYM(op, sym, num) - symbol which is an operator id */\n" f.print "/* MRB_PRESYM_SYM(sym, num) - symbol which is not valid C id */\n\n" presyms.each.with_index do |sym,i| if /\A\w+\Z/ =~ sym f.print "MRB_PRESYM_CSYM(#{sym}, #{i+1})\n" + elsif op_table.key?(sym) + f.print "MRB_PRESYM_OPSYM(#{sym}, #{op_table[sym]}, #{i+1})\n" else f.print "MRB_PRESYM_SYM(#{sym}, #{i+1})\n" end -- cgit v1.2.3