Class: CodeTools::Compiler::Writer

Inherits:
Stage
  • Object
show all
Defined in:
lib/rubinius/code/compiler/stages.rb

Overview

compiled method -> compiled file

Instance Attribute Summary collapse

Attributes inherited from Stage

#next_stage, #printer

Instance Method Summary collapse

Methods inherited from Stage

#create_next_stage, #input, #insert, next_stage, next_stage_class, #processor, #run_next, stage, stage_name

Constructor Details

#initialize(compiler, last) ⇒ Writer

Returns a new instance of Writer.



66
67
68
69
70
71
72
73
# File 'lib/rubinius/code/compiler/stages.rb', line 66

def initialize(compiler, last)
  super
  compiler.writer = self

  @version = 0
  @processor = CompiledFile
  @signature = Rubinius::Signature
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



64
65
66
# File 'lib/rubinius/code/compiler/stages.rb', line 64

def name
  @name
end

#versionObject

Returns the value of attribute version.



64
65
66
# File 'lib/rubinius/code/compiler/stages.rb', line 64

def version
  @version
end

Instance Method Details

#runObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rubinius/code/compiler/stages.rb', line 75

def run
  return @input unless @name

  dir = File.dirname(@name)
  unless File.directory?(dir)
    parts = []

    until dir == "/" or dir == "."
      parts << dir
      dir = File.dirname(dir)
    end

    parts.reverse_each do |d|
      Dir.mkdir d unless File.directory?(d)
    end
  end

  @processor.dump @input, @name, @signature, @version
  @input
end