summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-27 06:44:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-27 06:44:02 +0000
commit859337b17b5e1f9ee9ebeb0ac9e3ed7d73691ca2 (patch)
tree2f87021f6f7a577c1ab65ed51191bd448e39570e /iseq.c
parent71730b42434e3c2dce7e7f6488bd54fae52cae51 (diff)
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.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/iseq.c b/iseq.c
index cbf78ff..0fd95f0 100644
--- a/iseq.c
+++ b/iseq.c
@@ -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");