Class: Furnace::AVM2::Transform::PropagateConstants::Replacer

Inherits:
Object
  • Object
show all
Includes:
Visitor
Defined in:
lib/furnace-avm2/transform/propagate_constants.rb

Instance Method Summary collapse

Constructor Details

#initialize(local_var, value) ⇒ Replacer

Returns a new instance of Replacer.



11
12
13
# File 'lib/furnace-avm2/transform/propagate_constants.rb', line 11

def initialize(local_var, value)
  @local_var, @value = local_var, value
end

Instance Method Details

#on_get_local(node) ⇒ Object



36
37
38
39
40
41
# File 'lib/furnace-avm2/transform/propagate_constants.rb', line 36

def on_get_local(node)
  index, = node.children
  if index == @local_var
    node.update(@value.type, @value.children.dup, @value.)
  end
end

#on_set_local(node) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/furnace-avm2/transform/propagate_constants.rb', line 28

def on_set_local(node)
  index, value = node.children
  if index == @local_var
    @graceful_shutdown = @nodes.include?(node)
    throw :stop
  end
end

#replace_in(nodes) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/furnace-avm2/transform/propagate_constants.rb', line 15

def replace_in(nodes)
  @nodes = nodes
  @graceful_shutdown = true

  catch(:stop) {
    @nodes.each do |node|
      visit node
    end
  }

  @graceful_shutdown
end