Class: Stone::AST::ComputedPropertyDefinition

Inherits:
Stone::AST
  • Object
show all
Defined in:
lib/stone/ast/computed_property_definition.rb

Instance Attribute Summary collapse

Attributes inherited from Stone::AST

#children, #name

Instance Method Summary collapse

Constructor Details

#initialize(type_name, property_name, lambda) ⇒ ComputedPropertyDefinition

Returns a new instance of ComputedPropertyDefinition.



10
11
12
13
14
15
# File 'lib/stone/ast/computed_property_definition.rb', line 10

def initialize(type_name, property_name, lambda)
  @name = :computed_property_definition
  @type_name = type_name
  @property_name = property_name
  @lambda = lambda
end

Instance Attribute Details

#lambdaObject (readonly)

Returns the value of attribute lambda.



8
9
10
# File 'lib/stone/ast/computed_property_definition.rb', line 8

def lambda
  @lambda
end

#property_nameObject (readonly)

Returns the value of attribute property_name.



8
9
10
# File 'lib/stone/ast/computed_property_definition.rb', line 8

def property_name
  @property_name
end

#type_nameObject (readonly)

Returns the value of attribute type_name.



8
9
10
# File 'lib/stone/ast/computed_property_definition.rb', line 8

def type_name
  @type_name
end

Instance Method Details

#to_llir(builder, mod, scope = Stone::Scope.top_level) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stone/ast/computed_property_definition.rb', line 17

def to_llir(builder, mod, scope = Stone::Scope.top_level)
  # Generate the lambda function
  func = @lambda.to_llir(builder, mod, scope)

  # Register as a function alias with the name "Type@property"
  # This allows lookup via mod.lookup_function("Type@property")
  function_name = "#{@type_name}@#{@property_name}"
  mod.register_function_alias(function_name, func)

  # Return nil (computed properties are definitions, not expressions)
  nil
end