Class: Stone::AST::FunctionCall

Inherits:
Expression show all
Defined in:
lib/stone/ast/function_call.rb

Instance Attribute Summary collapse

Attributes inherited from Stone::AST

#children, #name

Instance Method Summary collapse

Constructor Details

#initialize(function_name, arguments) ⇒ FunctionCall

Returns a new instance of FunctionCall.



12
13
14
15
16
# File 'lib/stone/ast/function_call.rb', line 12

def initialize(function_name, arguments)
  @function_name = function_name
  @arguments = arguments
  @name = :function_call
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



10
11
12
# File 'lib/stone/ast/function_call.rb', line 10

def arguments
  @arguments
end

#function_nameObject (readonly)

Returns the value of attribute function_name.



10
11
12
# File 'lib/stone/ast/function_call.rb', line 10

def function_name
  @function_name
end

Instance Method Details

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stone/ast/function_call.rb', line 18

def to_llir(builder, mod, scope = Stone::Scope.top_level)
  # NULL comparisons with non-NULL values are always unequal (different types)
  return null_comparison_result if mixed_null_comparison?

  # TODO: Record equality should be delegated to the type system.
  # When the type system is refactored, equality should be polymorphic:
  # - Global `==` checks that both args are the same type
  # - If same type, delegate to type-specific comparison
  # - This special case should be removed
  return generate_record_equality(builder, mod, scope) if record_equality_comparison?(mod)
  # TODO: Record instantiation should not be special-cased here.
  # When the type system is refactored, record constructors should be
  # regular functions, and this check should be removed.
  return instantiate_record(builder, mod, scope) if mod.record_type?(function_name)

  # For chained comparisons, generate inline comparison logic
  return generate_chained_comparison(builder, mod, scope) if chained_comparison?

  # For chained boolean operations, generate inline logic
  return generate_chained_boolean(builder, mod, scope) if chained_boolean?

  # Regular function call
  generate_function_call(builder, mod, scope)
end

#to_sObject



43
44
45
# File 'lib/stone/ast/function_call.rb', line 43

def to_s
  "#{function_name}(#{arguments.join(', ')})"
end

#type(context = nil) ⇒ Object



47
48
49
50
51
52
# File 'lib/stone/ast/function_call.rb', line 47

def type(context = nil)
  return Stone::Type::Bool if comparison_operator? || boolean_operator?
  return record_constructor_type if context&.record_type?(function_name)

  function_return_type
end