diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-05-15 18:04:57 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-10-12 16:20:53 +0900 |
| commit | 246c76e261ee033210527cfcd37c8eb4bfe680c7 (patch) | |
| tree | e762576d908e093025eb22404344dbed5842a8eb | |
| parent | 6128ae61a81d12892eac5397af74e4ce6ab99b06 (diff) | |
| download | mruby-246c76e261ee033210527cfcd37c8eb4bfe680c7.tar.gz mruby-246c76e261ee033210527cfcd37c8eb4bfe680c7.zip | |
Rename `MRB_OPSYM()` to `MRB_QSYM()`.
Where `QSYM` means quoted symbols, which cannot be represented C
symbols, so specify aliases instead.
- operators: name of the operation, e.g. add for `+`
- predicates: add `_p` suffix instead of `?`
- bang methods: add `_b` suffix instead of `!`
- instance variables: add `a_` prefix instead of `@`
- global variables: add `d_` prefix instead of `@`
- class variables: unsupported; don't use them
| -rw-r--r-- | Rakefile | 16 | ||||
| -rw-r--r-- | include/mruby/presym.h | 6 | ||||
| -rw-r--r-- | src/kernel.c | 2 | ||||
| -rw-r--r-- | src/symbol.c | 4 |
4 files changed, 20 insertions, 8 deletions
@@ -173,13 +173,25 @@ file presym_inc => presym_file do "~" => "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_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" 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" + f.print "MRB_PRESYM_QSYM(#{sym}, #{op_table[sym]}, #{i+1})\n" + elsif /\?\Z/ =~ sym + s = sym.dup; s[-1] = "_p" + f.print "MRB_PRESYM_QSYM(#{sym}, #{s}, #{i+1})\n" + elsif /\!\Z/ =~ sym + s = sym.dup; s[-1] = "_b" + 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" + elsif /\A$/ =~ sym + s = sym.dup; s[0] = "d_" + f.print "MRB_PRESYM_QSYM(#{sym}, #{s}, #{i+1})\n" else f.print "MRB_PRESYM_SYM(#{sym}, #{i+1})\n" end diff --git a/include/mruby/presym.h b/include/mruby/presym.h index bd3918c52..33e51fe18 100644 --- a/include/mruby/presym.h +++ b/include/mruby/presym.h @@ -9,7 +9,7 @@ #undef MRB_PRESYM_MAX #define MRB_PRESYM_CSYM(sym, num) MRB_PRESYM__##sym = (num<<1), -#define MRB_PRESYM_OPSYM(op, sym, num) MRB_PRESYM_op_##sym = (num<<1), +#define MRB_PRESYM_QSYM(src, sym, num) MRB_PRESYM_q_##sym = (num<<1), #define MRB_PRESYM_SYM(sym, num) enum mruby_presym { @@ -17,9 +17,9 @@ enum mruby_presym { }; #undef MRB_PRESYM_CSYM -#undef MRB_PRESYM_OPSYM +#undef MRB_PRESYM_QSYM #undef MRB_PRESYM_SYM #define MRB_SYM(sym) MRB_PRESYM__##sym -#define MRB_OPSYM(sym) MRB_PRESYM_op_##sym +#define MRB_QSYM(sym) MRB_PRESYM_q_##sym #endif /* MRUBY_PRESYM_H */ diff --git a/src/kernel.c b/src/kernel.c index d2074c16b..bc42a75d7 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -766,7 +766,7 @@ mrb_obj_ceqq(mrb_state *mrb, mrb_value self) { mrb_value v = mrb_get_arg1(mrb); mrb_int i, len; - mrb_sym eqq = MRB_OPSYM(eqq); + mrb_sym eqq = MRB_QSYM(eqq); mrb_value ary; if (mrb_array_p(self)) { diff --git a/src/symbol.c b/src/symbol.c index 5f30ccb39..6a72a83c6 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -14,10 +14,10 @@ #undef MRB_PRESYM_MAX #undef MRB_PRESYM_CSYM -#undef MRB_PRESYM_OPSYM +#undef MRB_PRESYM_QSYM #undef MRB_PRESYM_SYM #define MRB_PRESYM_CSYM(sym, num) #sym, -#define MRB_PRESYM_OPSYM(op, sym, num) #op, +#define MRB_PRESYM_QSYM(sym, name, num) #sym, #define MRB_PRESYM_SYM(sym, num) #sym, static const char *presym_table[] = { |
