Module: ASTTransform::InstructionSequence

Defined in:
lib/ast_transform/instruction_sequence.rb,
lib/ast_transform/instruction_sequence/mixin.rb,
lib/ast_transform/instruction_sequence/bootsnap_mixin.rb

Defined Under Namespace

Modules: BootsnapMixin, Mixin

Class Method Summary collapse

Class Method Details

.source_to_transformed_iseq(source, source_path) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ast_transform/instruction_sequence.rb', line 13

def source_to_transformed_iseq(source, source_path)
  transformer = ASTTransform::Transformer.new(ASTTransform::Transformation.new)
  rewritten_file_pathname = write_pathname(source_path)

  rewritten_source = transformer.transform_file_source(source, source_path, rewritten_file_pathname.to_s)
  write(rewritten_source, rewritten_file_pathname)

  RubyVM::InstructionSequence.compile(rewritten_source, source_path, source_path)
end

.using_bootsnap_compilation?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
# File 'lib/ast_transform/instruction_sequence.rb', line 6

def using_bootsnap_compilation?
  filepath, = RubyVM::InstructionSequence.method(:load_iseq).source_location
  filepath =~ %r{/bootsnap/}
rescue NameError
  false
end

.write(string, pathname) ⇒ Object



29
30
31
32
33
34
# File 'lib/ast_transform/instruction_sequence.rb', line 29

def write(string, pathname)
  FileUtils.mkdir_p(pathname.dirname)
  File.open(pathname, "w") do |file|
    file.write(string)
  end
end

.write_pathname(file_path) ⇒ Object



23
24
25
26
27
# File 'lib/ast_transform/instruction_sequence.rb', line 23

def write_pathname(file_path)
  project_path = File.expand_path("")
  relative_source_file_pathname = Pathname.new(file_path).relative_path_from(Pathname.new(project_path))
  Pathname.new("").join(project_path, "tmp", "ast_transform", relative_source_file_pathname)
end