Class: KoiReferenceCompiler::HashAccessorList

Inherits:
SyntaxNode
  • Object
show all
Defined in:
lib/koi-reference-compiler/node_extensions/hash_literals/hash_accessor_list.rb

Instance Attribute Summary

Attributes inherited from SyntaxNode

#elements, #offset, #parent, #text_value

Instance Method Summary collapse

Methods inherited from SyntaxNode

#initialize

Constructor Details

This class inherits a constructor from KoiReferenceCompiler::SyntaxNode

Instance Method Details

#compileObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/koi-reference-compiler/node_extensions/hash_literals/hash_accessor_list.rb', line 4

def compile
  bytecode = []
  if(self.parent.is_a?(HashAssignment))
    self.elements.each_index do |x|
      if(x == self.elements.length - 1)
        bytecode.concat( self.elements[x].compile_set )
      else
        bytecode.concat( self.elements[x].compile_get )
      end
    end
    bytecode << POP
  elsif(self.parent.is_a?(HashAccess))
    self.elements.each do |x|
      bytecode.concat( x.compile_get )
    end
  else  
    raise CompileError, "Unkown parent for HashAccessorList: #{self.parent.class}"
  end
  return bytecode
end