diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-27 06:44:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-27 06:44:02 +0000 |
commit | 0c68198cc49431c683ffb9915e67cd05f625553a (patch) | |
tree | 2f87021f6f7a577c1ab65ed51191bd448e39570e /iseq.c | |
parent | 868a0970b6503c402d1190ecc00c7cd4c9521ece (diff) | |
download | ruby-0c68198cc49431c683ffb9915e67cd05f625553a.tar.gz |
fronzen-string-literal pragma
* compile.c (iseq_compile_each): override compile option by option
given by pragma.
* iseq.c (rb_iseq_make_compile_option): extract a function to
overwrite rb_compile_option_t.
* parse.y (parser_set_compile_option_flag): introduce pragma to
override compile options.
* parse.y (magic_comments): new pragma "fronzen-string-literal".
[Feature #8976]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r-- | iseq.c | 56 |
1 files changed, 34 insertions, 22 deletions
@@ -345,6 +345,39 @@ static rb_compile_option_t COMPILE_OPTION_DEFAULT = { static const rb_compile_option_t COMPILE_OPTION_FALSE = {0}; static void +set_compile_option_from_hash(rb_compile_option_t *option, VALUE opt) +{ +#define SET_COMPILE_OPTION(o, h, mem) \ + { VALUE flag = rb_hash_aref((h), ID2SYM(rb_intern(#mem))); \ + if (flag == Qtrue) { (o)->mem = 1; } \ + else if (flag == Qfalse) { (o)->mem = 0; } \ + } +#define SET_COMPILE_OPTION_NUM(o, h, mem) \ + { VALUE num = rb_hash_aref(opt, ID2SYM(rb_intern(#mem))); \ + if (!NIL_P(num)) (o)->mem = NUM2INT(num); \ + } + SET_COMPILE_OPTION(option, opt, inline_const_cache); + SET_COMPILE_OPTION(option, opt, peephole_optimization); + SET_COMPILE_OPTION(option, opt, tailcall_optimization); + SET_COMPILE_OPTION(option, opt, specialized_instruction); + SET_COMPILE_OPTION(option, opt, operands_unification); + SET_COMPILE_OPTION(option, opt, instructions_unification); + SET_COMPILE_OPTION(option, opt, stack_caching); + SET_COMPILE_OPTION(option, opt, trace_instruction); + SET_COMPILE_OPTION(option, opt, frozen_string_literal); + SET_COMPILE_OPTION_NUM(option, opt, debug_level); +#undef SET_COMPILE_OPTION +#undef SET_COMPILE_OPTION_NUM +} + +void +rb_iseq_make_compile_option(rb_compile_option_t *option, VALUE opt) +{ + Check_Type(opt, T_HASH); + set_compile_option_from_hash(option, opt); +} + +static void make_compile_option(rb_compile_option_t *option, VALUE opt) { if (opt == Qnil) { @@ -360,28 +393,7 @@ make_compile_option(rb_compile_option_t *option, VALUE opt) } else if (CLASS_OF(opt) == rb_cHash) { *option = COMPILE_OPTION_DEFAULT; - -#define SET_COMPILE_OPTION(o, h, mem) \ - { VALUE flag = rb_hash_aref((h), ID2SYM(rb_intern(#mem))); \ - if (flag == Qtrue) { (o)->mem = 1; } \ - else if (flag == Qfalse) { (o)->mem = 0; } \ - } -#define SET_COMPILE_OPTION_NUM(o, h, mem) \ - { VALUE num = rb_hash_aref(opt, ID2SYM(rb_intern(#mem))); \ - if (!NIL_P(num)) (o)->mem = NUM2INT(num); \ - } - SET_COMPILE_OPTION(option, opt, inline_const_cache); - SET_COMPILE_OPTION(option, opt, peephole_optimization); - SET_COMPILE_OPTION(option, opt, tailcall_optimization); - SET_COMPILE_OPTION(option, opt, specialized_instruction); - SET_COMPILE_OPTION(option, opt, operands_unification); - SET_COMPILE_OPTION(option, opt, instructions_unification); - SET_COMPILE_OPTION(option, opt, stack_caching); - SET_COMPILE_OPTION(option, opt, trace_instruction); - SET_COMPILE_OPTION(option, opt, frozen_string_literal); - SET_COMPILE_OPTION_NUM(option, opt, debug_level); -#undef SET_COMPILE_OPTION -#undef SET_COMPILE_OPTION_NUM + set_compile_option_from_hash(option, opt); } else { rb_raise(rb_eTypeError, "Compile option must be Hash/true/false/nil"); |