Create `MRB_OPSYM()` macro to refer symbols corresponding operators.

For example, `MRB_OPSYM(add)` refers a symbol for `+`.
parent 97e3c3a5
......@@ -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
......
......@@ -9,14 +9,17 @@
#undef MRB_PRESYM_MAX
#define MRB_PRESYM_CSYM(sym, num) MRB_PRESYM__##sym = (num<<1),
#define MRB_PRESYM_SYM(sym, num)
#define MRB_PRESYM_OPSYM(op, sym, num) MRB_PRESYM_op_##sym = (num<<1),
#define MRB_PRESYM_SYM(sym, num)
enum mruby_presym {
#include <../build/presym.inc>
};
#undef MRB_PRESYM_CSYM
#undef MRB_PRESYM_OPSYM
#undef MRB_PRESYM_SYM
#define MRB_SYM(sym) MRB_PRESYM__##sym
#define MRB_OPSYM(sym) MRB_PRESYM_op_##sym
#endif /* MRUBY_PRESYM_H */
......@@ -14,8 +14,10 @@
#undef MRB_PRESYM_MAX
#undef MRB_PRESYM_CSYM
#undef MRB_PRESYM_OPSYM
#undef MRB_PRESYM_SYM
#define MRB_PRESYM_CSYM(sym, num) #sym,
#define MRB_PRESYM_OPSYM(op, sym, num) #op,
#define MRB_PRESYM_SYM(sym, num) #sym,
static const char *presym_table[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment