Class: CodeTools::Compiler::MethodPrinter
- Inherits:
-
Printer
show all
- Defined in:
- lib/rubinius/code/compiler/printers.rb
Constant Summary
collapse
- SEPARATOR_SIZE =
40
Instance Attribute Summary collapse
Attributes inherited from Stage
#next_stage, #printer
Instance Method Summary
collapse
Methods inherited from Printer
#initialize
Methods inherited from Stage
#create_next_stage, #initialize, #input, #insert, next_stage, next_stage_class, #processor, #run_next, stage, stage_name
Instance Attribute Details
#assembly ⇒ Object
Returns the value of attribute assembly.
29
30
31
|
# File 'lib/rubinius/code/compiler/printers.rb', line 29
def assembly
@assembly
end
|
#bytecode ⇒ Object
Returns the value of attribute bytecode.
29
30
31
|
# File 'lib/rubinius/code/compiler/printers.rb', line 29
def bytecode
@bytecode
end
|
Instance Method Details
#match?(name) ⇒ Boolean
38
39
40
41
|
# File 'lib/rubinius/code/compiler/printers.rb', line 38
def match?(name)
return true unless @method_names
@method_names.include? name
end
|
#method_names=(names) ⇒ Object
33
34
35
36
|
# File 'lib/rubinius/code/compiler/printers.rb', line 33
def method_names=(names)
return if names.empty?
@method_names = names.map { |n| n.to_sym }
end
|
71
72
73
|
# File 'lib/rubinius/code/compiler/printers.rb', line 71
def
puts "-" * SEPARATOR_SIZE
end
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/rubinius/code/compiler/printers.rb', line 43
def (code)
name = code.name.inspect
size = (SEPARATOR_SIZE - name.size - 2) / 2
size = 1 if size <= 0
puts "\n#{"=" * size} #{name} #{"=" * (size + name.size % 2)}"
print "Arguments: "
print "#{code.required_args} required, "
print "#{code.post_args} post, "
print "#{code.total_args} total"
print code.splat ? ", (splat #{code.splat})\n" : "\n"
puts "Arity: #{code.arity}"
print "Locals: #{code.local_count}"
print code.local_count > 0 ? ": #{code.local_names.join ", "}\n" : "\n"
puts "Stack size: #{code.stack_size}"
literals = code.literals.collect do |literal|
case literal
when Rubinius::CompiledCode
"<compiled code>"
else
literal.inspect
end
end
print "Literals: #{literals.size}"
print code.literals.size > 0 ? ": #{literals.join ", "}\n" : "\n"
print_lines code
puts
end
|
#print_lines(code) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/rubinius/code/compiler/printers.rb', line 75
def print_lines(code)
lines = code.lines
size = lines.size - 1
i = 1
if lines[0] == -1
puts "Line: #{lines[1]}"
i += 2
end
print "Lines to IP: "
while i < size
print "#{lines[i]}: #{lines[i - 1]}..#{lines[i + 1] - 1}"
i += 2
print ", " if i < size
end
puts
end
|
#print_method(code) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/rubinius/code/compiler/printers.rb', line 94
def print_method(code)
if match? code.name
code
puts code.decode if @bytecode
end
code.literals.each do |m|
next unless m.kind_of? Rubinius::CompiledCode
print_method m
end
end
|
#run ⇒ Object
107
108
109
110
111
112
|
# File 'lib/rubinius/code/compiler/printers.rb', line 107
def run
print_method @input
@output = @input
run_next
end
|