path: root/iseq.c
diff options
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-21 20:47:53 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-21 20:47:53 +0000
commit7cf523c7db67c22ffc09b38a9c5bea057f578db2 (patch)
tree93119a59a19abdd3a1d931fc27c5828b234418e8 /iseq.c
parent42c3a67748da667cb87afd7928718c537cdd8201 (diff)
* vm_opts.h, iseq.c, iseq.h: add compile option to force frozen
string literals. [Feature #11473] This addition is not specification change, but to try frozen string literal world discussed on [Feature #11473]. You can try frozen string literal world using this magical line: RubyVM::InstructionSequence.compile_option = {frozen_string_literal: true} Note that this is a global compilation option, so that you need to compile another script like that: p 'foo'.frozen? #=> false RubyVM::InstructionSequence.compile_option = {frozen_string_literal: true} p 'foo'.frozen? #=> false, because this line is already compiled. p eval("'foo'.frozen?") #=> true Details: * String literals are deduped by rb_fstring(). * Dynamic string literals ("...#{xyz}...") is now only frozen, not deduped. Maybe you have other ideas. Now, please do not use this option on your productions :) Of course, current specification can be changed. * compile.c: ditto. * test/ruby/test_iseq.rb: add a test. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
1 files changed, 3 insertions, 0 deletions
diff --git a/iseq.c b/iseq.c
index 9b32c0a..fa89f51 100644
--- a/iseq.c
+++ b/iseq.c
@@ -338,7 +338,9 @@ static rb_compile_option_t COMPILE_OPTION_DEFAULT = {
OPT_INSTRUCTIONS_UNIFICATION, /* int instructions_unification; */
OPT_STACK_CACHING, /* int stack_caching; */
OPT_TRACE_INSTRUCTION, /* int trace_instruction */
static const rb_compile_option_t COMPILE_OPTION_FALSE = {0};
static void
@@ -375,6 +377,7 @@ make_compile_option(rb_compile_option_t *option, VALUE opt)
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);