diff options
| -rw-r--r-- | include/mruby/symbol.h | 7 | ||||
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 10 |
2 files changed, 14 insertions, 3 deletions
diff --git a/include/mruby/symbol.h b/include/mruby/symbol.h index f11346830..b0feccc51 100644 --- a/include/mruby/symbol.h +++ b/include/mruby/symbol.h @@ -16,6 +16,7 @@ MRB_BEGIN_DECL typedef enum mrb_reserved_symbol { mrb_sym_null = 0, // NULL symbol + mrb_sym_add = 1, // + mrb_sym_sub = 2, // - mrb_sym_mul = 3, // * @@ -25,9 +26,15 @@ typedef enum mrb_reserved_symbol { mrb_sym_le = 7, // <= mrb_sym_gt = 8, // > mrb_sym_ge = 9, // >= + mrb_sym_method_missing = 10, // method_missing } mrb_reserved_symbol; +static inline mrb_bool +mrb_symbol_constsym_send_p(mrb_sym sym) { + return mrb_sym_add <= sym && sym <= mrb_sym_ge; +} + MRB_END_DECL #endif /* MRUBY_SYMBOL_H */ diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 759e7267e..22ac51239 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -18,6 +18,7 @@ #include <mruby/opcode.h> #include <mruby/re.h> #include <mruby/throw.h> +#include <mruby/symbol.h> #ifndef MRB_CODEGEN_LEVEL_MAX #define MRB_CODEGEN_LEVEL_MAX 1024 @@ -982,8 +983,9 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe) gen_move(s, cursp(), recv, 1); skip = genjmp2(s, OP_JMPNIL, cursp(), 0, val); } - // TODO: don't new when unused - idx = new_sym(s, sym); + if (!mrb_symbol_constsym_send_p(sym)) { + idx = new_sym(s, sym); + } tree = tree->cdr->cdr->car; if (tree) { n = gen_values(s, tree->car, VAL, sp?1:0); @@ -2024,7 +2026,9 @@ codegen(codegen_scope *s, node *tree, int val) push(); pop(); pop(); pop(); - idx = new_sym(s, sym); + if (!mrb_symbol_constsym_send_p(sym)) { + idx = new_sym(s, sym); + } if (len == 1 && name[0] == '+') { gen_addsub(s, OP_ADD, cursp()); } |
