summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-27 06:47:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-27 06:47:00 +0000
commit832c74f428db6c5bd6e575e1f6ea7fe0891c84d2 (patch)
treec3f2ae41becea90fd84e395fe5e0e7ff38581ed9 /ruby.c
parent859337b17b5e1f9ee9ebeb0ac9e3ed7d73691ca2 (diff)
ruby.c: frozen-string-literal option
* ruby.c (process_options): add an option to enable/disable frozen-string-literal. [Feature #8976] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/ruby.c b/ruby.c
index 2f9355f..2d4c64b 100644
--- a/ruby.c
+++ b/ruby.c
@@ -64,6 +64,7 @@ enum feature_flag_bits {
feature_gems,
feature_did_you_mean,
feature_rubyopt,
+ feature_frozen_string_literal,
feature_flag_count
};
@@ -120,6 +121,7 @@ cmdline_options_init(struct cmdline_options *opt)
#if DISABLE_RUBYGEMS
opt->features &= ~FEATURE_BIT(gems);
#endif
+ opt->features &= ~FEATURE_BIT(frozen_string_literal);
return opt;
}
@@ -196,6 +198,7 @@ usage(const char *name, int help)
M("gems", "", "rubygems (default: "DEFAULT_RUBYGEMS_ENABLED")"),
M("did_you_mean", "", "did_you_mean (default: "DEFAULT_RUBYGEMS_ENABLED")"),
M("rubyopt", "", "RUBYOPT environment variable (default: enabled)"),
+ M("frozen-string-literal", "", "freeze all string literals (default: disabled)"),
};
int i;
const int num = numberof(usage_msg) - (help ? 1 : 0);
@@ -733,6 +736,7 @@ enable_option(const char *str, int len, void *arg)
SET_WHEN_ENABLE(gems);
SET_WHEN_ENABLE(did_you_mean);
SET_WHEN_ENABLE(rubyopt);
+ SET_WHEN_ENABLE(frozen_string_literal);
if (NAME_MATCH_P("all", str, len)) {
*(unsigned int *)arg = ~0U;
return;
@@ -747,6 +751,7 @@ disable_option(const char *str, int len, void *arg)
UNSET_WHEN_DISABLE(gems);
UNSET_WHEN_DISABLE(did_you_mean);
UNSET_WHEN_DISABLE(rubyopt);
+ UNSET_WHEN_DISABLE(frozen_string_literal);
if (NAME_MATCH_P("all", str, len)) {
*(unsigned int *)arg = 0U;
return;
@@ -1462,6 +1467,11 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
rb_define_module("DidYouMean");
}
ruby_init_prelude();
+ if (opt->features & FEATURE_BIT(frozen_string_literal)) {
+ VALUE option = rb_hash_new();
+ rb_hash_aset(option, ID2SYM(rb_intern_const("frozen_string_literal")), Qtrue);
+ rb_funcallv(rb_cISeq, rb_intern_const("compile_option="), 1, &option);
+ }
#if UTF8_PATH
opt->script_name = str_conv_enc(opt->script_name, rb_utf8_encoding(), lenc);
opt->script = RSTRING_PTR(opt->script_name);