Class: Bootsnap::CompileCache::ISeq::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/bootsnap/compile_cache/iseq.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace = nil, compile_options = nil) ⇒ Compiler

Returns a new instance of Compiler.



25
26
27
28
# File 'lib/bootsnap/compile_cache/iseq.rb', line 25

def initialize(namespace = nil, compile_options = nil)
  @namespace = namespace
  @compile_options = compile_options
end

Instance Attribute Details

#compile_optionsObject (readonly)

Returns the value of attribute compile_options.



23
24
25
# File 'lib/bootsnap/compile_cache/iseq.rb', line 23

def compile_options
  @compile_options
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



23
24
25
# File 'lib/bootsnap/compile_cache/iseq.rb', line 23

def namespace
  @namespace
end

Instance Method Details

#input_to_output(source, path, _kwargs) ⇒ Object



68
69
70
# File 'lib/bootsnap/compile_cache/iseq.rb', line 68

def input_to_output(source, path, _kwargs)
  RubyVM::InstructionSequence.compile(source, path, path, nil, @compile_options)
end

#input_to_storage(_, path) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/bootsnap/compile_cache/iseq.rb', line 40

def input_to_storage(_, path)
  iseq = RubyVM::InstructionSequence.compile_file(path, @compile_options)

  begin
    iseq.to_binary
  rescue TypeError
    UNCOMPILABLE # ruby bug #18250
  end
end

#storage_to_output(binary, _args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bootsnap/compile_cache/iseq.rb', line 55

def storage_to_output(binary, _args)
  iseq = RubyVM::InstructionSequence.load_from_binary(binary)
  binary.clear
  iseq
rescue RuntimeError => error
  if error.message == "broken binary format"
    $stderr.puts("[Bootsnap::CompileCache] warning: rejecting broken binary")
    nil
  else
    raise
  end
end