diff options
| author | KOBAYASHI Shuji <[email protected]> | 2020-11-11 23:59:45 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2020-11-13 13:41:20 +0900 |
| commit | 89f591485b91780c213f459f840111a99adca9d0 (patch) | |
| tree | d32adaba112c1cda8eeb5d6c7293a7a3e906bc89 /include | |
| parent | 6a5e97b448e82fe55348ab1a7e96b70b2c45f6c1 (diff) | |
| download | mruby-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 'include')
| -rw-r--r-- | include/mruby.h | 5 | ||||
| -rw-r--r-- | include/mruby/presym.h | 35 |
2 files changed, 30 insertions, 10 deletions
diff --git a/include/mruby.h b/include/mruby.h index 6d03ba79c..0fad0d440 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -1080,7 +1080,8 @@ MRB_API mrb_value mrb_funcall_argv(mrb_state *mrb, mrb_value val, mrb_sym name, */ MRB_API mrb_value mrb_funcall_with_block(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv, mrb_value block); /** - * Create a symbol from C string. But usually it's better to use MRB_SYM(sym) and MRB_QSYM(qsym). + * Create a symbol from C string. But usually it's better to use MRB_SYM, + * MRB_OPSYM, MRB_CVSYM, MRB_IVSYM, MRB_SYM_B, MRB_SYM_Q, MRB_SYM_E macros. * * Example: * @@ -1090,7 +1091,7 @@ MRB_API mrb_value mrb_funcall_with_block(mrb_state *mrb, mrb_value val, mrb_sym * // C style: * mrb_sym sym1 = mrb_intern_lit(mrb, "pizza"); // => :pizza * mrb_sym sym2 = MRB_SYM(pizza); // => :pizza - * mrb_sym sym3 = MRB_SYM(pizza_p); // => :pizza? + * mrb_sym sym3 = MRB_SYM_Q(pizza); // => :pizza? * * @param mrb The current mruby state. * @param str The string to be symbolized diff --git a/include/mruby/presym.h b/include/mruby/presym.h index 3cc12e8fb..61e5bc8cb 100644 --- a/include/mruby/presym.h +++ b/include/mruby/presym.h @@ -8,18 +8,37 @@ #define MRUBY_PRESYM_H #undef MRB_PRESYM_MAX -#define MRB_PRESYM_CSYM(sym, num) MRB_PRESYM__##sym = (num<<1), -#define MRB_PRESYM_QSYM(str, sym, num) MRB_PRESYM_q_##sym = (num<<1), -#define MRB_PRESYM_SYM(sym, num) +#define MRB_PRESYM_NAMED(lit, num, type, name) MRB_##type##__##name = (num<<1), +#define MRB_PRESYM_UNNAMED(lit, num) enum mruby_presym { #include <../build/presym.inc> }; -#undef MRB_PRESYM_CSYM -#undef MRB_PRESYM_QSYM -#undef MRB_PRESYM_SYM +#undef MRB_PRESYM_NAMED +#undef MRB_PRESYM_UNNAMED + +/* + * For `MRB_OPSYM`, specify the names corresponding to operators (refer to + * `op_table` in `Rakefile` for the names that can be specified for it). + * Other than that, describe only word characters excluding leading and + * ending punctuations. + * + * Example: + * MRB_OPSYM(and) //=> & + * MRB_CVSYM(foo) //=> @@foo + * MRB_IVSYM(foo) //=> @foo + * MRB_SYM_B(foo) //=> foo! + * MRB_SYM_Q(foo) //=> foo? + * MRB_SYM_E(foo) //=> foo= + * MRB_SYM(foo) //=> foo + */ +#define MRB_OPSYM(name) MRB_OPSYM__##name /* Operator */ +#define MRB_CVSYM(name) MRB_CVSYM__##name /* Class Variable */ +#define MRB_IVSYM(name) MRB_IVSYM__##name /* Instance Variable */ +#define MRB_SYM_B(name) MRB_SYM_B__##name /* Method with Bang */ +#define MRB_SYM_Q(name) MRB_SYM_Q__##name /* Method with Question mark */ +#define MRB_SYM_E(name) MRB_SYM_E__##name /* Method with Equal */ +#define MRB_SYM(name) MRB_SYM__##name /* Word characters */ -#define MRB_SYM(sym) MRB_PRESYM__##sym -#define MRB_QSYM(sym) MRB_PRESYM_q_##sym #endif /* MRUBY_PRESYM_H */ |
