Class: SorobanRustBackend::FunctionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/function_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function, is_helper, user_defined_types, function_names) ⇒ FunctionHandler

Returns a new instance of FunctionHandler.



3
4
5
6
7
8
# File 'lib/function_handler.rb', line 3

def initialize(function, is_helper, user_defined_types, function_names)
  @function = function
  @is_helper = is_helper
  @user_defined_types = user_defined_types
  @function_names = function_names
end

Class Method Details

.generate(function, is_helper, user_defined_types, function_names) ⇒ Object



10
11
12
# File 'lib/function_handler.rb', line 10

def self.generate(function, is_helper, user_defined_types, function_names)
  new(function, is_helper, user_defined_types, function_names).generate
end

Instance Method Details

#generateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/function_handler.rb', line 14

def generate
  content = "\n#{@is_helper ? '' : '    '}pub fn #{@function.name}(#{generate_function_args}) "
  content += generate_function_output

  content += " {\n"
  if @function.output
    content += "#{@is_helper ? '    ' : '        '}let mut Thing_to_return: #{Common::TypeTranslator.translate_type(@function.output)};\n"
  end
  content += generate_instructions_for_blocks(@function.instructions)

  content += "#{@is_helper ? '' : '    '}}\n"

  content
end