Class: Atomy::Code::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/atomy/code/sequence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nodes) ⇒ Sequence

Returns a new instance of Sequence.



6
7
8
# File 'lib/atomy/code/sequence.rb', line 6

def initialize(nodes)
  @nodes = nodes
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



4
5
6
# File 'lib/atomy/code/sequence.rb', line 4

def nodes
  @nodes
end

Instance Method Details

#bytecode(gen, mod) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/atomy/code/sequence.rb', line 10

def bytecode(gen, mod)
  if @nodes.empty?
    gen.push_nil
    return
  end

  @nodes.each.with_index do |node, idx|
    gen.pop unless idx == 0
    mod.compile(gen, node)
  end
end