Class: Cry::Codegen::CrystalFunction::Declaration

Inherits:
Object
  • Object
show all
Defined in:
lib/cry/codegen/crystal_function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(decl: 'fun') ⇒ Declaration

Returns a new instance of Declaration.



7
8
9
10
11
# File 'lib/cry/codegen/crystal_function.rb', line 7

def initialize(decl: 'fun')
  @arg_names = []
  @arg_types = []
  @decl = decl
end

Instance Attribute Details

#arg_namesObject

Returns the value of attribute arg_names.



5
6
7
# File 'lib/cry/codegen/crystal_function.rb', line 5

def arg_names
  @arg_names
end

#arg_typesObject

Returns the value of attribute arg_types.



5
6
7
# File 'lib/cry/codegen/crystal_function.rb', line 5

def arg_types
  @arg_types
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/cry/codegen/crystal_function.rb', line 5

def name
  @name
end

#ret_typeObject

Returns the value of attribute ret_type.



5
6
7
# File 'lib/cry/codegen/crystal_function.rb', line 5

def ret_type
  @ret_type
end

Instance Method Details

#sourceObject



13
14
15
16
17
18
19
20
21
# File 'lib/cry/codegen/crystal_function.rb', line 13

def source
  raise 'name is not set' unless @name
  raise 'size of arg_names and arg_types are not same' unless @arg_names.size == @arg_types.size

  args = arg_names.zip(arg_types).map do |n, t|
    "#{n} : #{t}"
  end.join(', ')
  "#{@decl} #{@name}(#{args}) : #{@ret_type}"
end