Class: KoiReferenceCompiler::Identifier

Inherits:
SyntaxNode
  • Object
show all
Defined in:
lib/koi-reference-compiler/node_extensions/identifiers/identifier.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
24
25
26
27
28
# File 'lib/koi-reference-compiler/node_extensions/identifiers/identifier.rb', line 4

def compile
  identifier = self.text_value
  parent = self.parent
  if(identifier[0] == "$")
    if(parent.is_a?(Expression) || parent.is_a?(MultitiveExpression) || parent.is_a?(AdditiveExpression) || parent.is_a?(ComparativeExpression) || parent.is_a?(HashAssignment) || parent.is_a?(HashAccess))
      [ GET_GLOBAL, identifier.to_sym ]
      
    elsif(parent.is_a?(Assignment) || parent.is_a?(FunctionDefinition))
      [ SET_GLOBAL, identifier.to_sym ]
      
    else
      raise CompileError, "Unkown parent for Identfier: #{self.parent.class}"        
    end
  else
    if(parent.is_a?(Expression) || parent.is_a?(MultitiveExpression) || parent.is_a?(AdditiveExpression) || parent.is_a?(ComparativeExpression) || parent.is_a?(HashAssignment) || parent.is_a?(HashAccess))
      [ GET_LOCAL, identifier.to_sym ]
      
    elsif(parent.is_a?(Assignment) || parent.is_a?(FunctionDefinition))
      [ SET_LOCAL, identifier.to_sym ]
      
    else
      raise CompileError, "Unkown parent for Identfier: #{self.parent.class}"
    end
  end
end