1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* introduce new ISeq binary format serializer/de-serializer

and a pre-compilation/runtime loader sample.
  [Feature #11788]

* iseq.c: add new methods:
  * RubyVM::InstructionSequence#to_binary_format(extra_data = nil)
  * RubyVM::InstructionSequence.from_binary_format(binary)
  * RubyVM::InstructionSequence.from_binary_format_extra_data(binary)

* compile.c: implement body of this new feature.

* load.c (rb_load_internal0), iseq.c (rb_iseq_load_iseq):
  call RubyVM::InstructionSequence.load_iseq(fname) with
  loading script name if this method is defined.

  We can return any ISeq object as a result value.
  Otherwise loading will be continue as usual.

  This interface is not matured and is not extensible.
  So that we don't guarantee the future compatibility of this method.
  Basically, you should'nt use this method.

* iseq.h: move ISEQ_MAJOR/MINOR_VERSION (and some definitions)
  from iseq.c.

* encoding.c (rb_data_is_encoding), internal.h: added.

* vm_core.h: add several supports for lazy load.
  * add USE_LAZY_LOAD macro to specify enable or disable of
    this feature.
  * add several fields to rb_iseq_t.
  * introduce new macro rb_iseq_check().

* insns.def: some check for lazy loading feature.

* vm_insnhelper.c: ditto.

* proc.c: ditto.

* vm.c: ditto.

* test/lib/iseq_loader_checker.rb: enabled iff suitable
  environment variables are provided.

* test/runner.rb: enable lib/iseq_loader_checker.rb.

* sample/iseq_loader.rb: add sample compiler and loader.

    $ ruby sample/iseq_loader.rb [dir]

  will compile all ruby scripts in [dir].
  With default setting, this compile creates *.rb.yarb files
  in same directory of target .rb scripts.

    $ ruby -r sample/iseq_loader.rb [app]

  will run with enable to load compiled binary data.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2015-12-08 13:58:50 +00:00
parent 8f620b9b17
commit 3dbb390180
16 changed files with 1979 additions and 89 deletions

View file

@ -1,5 +1,8 @@
require '-test-/iseq_load/iseq_load'
begin
require '-test-/iseq_load/iseq_load'
rescue LoadError
end
require 'tempfile'
class RubyVM::InstructionSequence
@ -21,9 +24,6 @@ class RubyVM::InstructionSequence
d2 = i2.disasm_if_possible
if d1 != d2
p i1
return
STDERR.puts "expected:"
STDERR.puts d1
STDERR.puts "actual:"
@ -37,19 +37,38 @@ class RubyVM::InstructionSequence
i2
end
CHECK_TO_A = ENV['RUBY_ISEQ_DUMP_DEBUG'] == 'to_a'
CHECK_TO_BINARY = ENV['RUBY_ISEQ_DUMP_DEBUG'] == 'to_binary'
def self.translate i1
# check to_a/load_iseq
i2 = compare_dump_and_load(i1,
proc{|iseq|
ary = iseq.to_a
ary[9] == :top ? ary : nil
},
proc{|ary|
RubyVM::InstructionSequence.iseq_load(ary)
})
i2_ary = compare_dump_and_load(i1,
proc{|iseq|
ary = iseq.to_a
ary[9] == :top ? ary : nil
},
proc{|ary|
RubyVM::InstructionSequence.iseq_load(ary)
}) if CHECK_TO_A && defined?(RubyVM::InstructionSequence.iseq_load)
# check to_binary_format
i2_bin = compare_dump_and_load(i1,
proc{|iseq|
begin
iseq.to_binary_format
rescue RuntimeError => e # not a toplevel
# STDERR.puts [:failed, e, iseq].inspect
nil
end
},
proc{|bin|
iseq = RubyVM::InstructionSequence.from_binary_format(bin)
# STDERR.puts iseq.inspect
iseq
}) if CHECK_TO_BINARY
# return value
i1
end
i2_bin if CHECK_TO_BINARY
end if CHECK_TO_A || CHECK_TO_BINARY
end
#require_relative 'x'; exit(1)