dtr_to_rust 0.8.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/code_generator.rb +90 -0
- data/lib/common/type_translator.rb +3 -3
- data/lib/contract_handler.rb +98 -0
- data/lib/contract_state/handler.rb +35 -0
- data/lib/function_handler.rb +47 -0
- data/lib/instruction/add.rb +4 -4
- data/lib/instruction/and.rb +2 -4
- data/lib/instruction/assign.rb +3 -3
- data/lib/instruction/binary_instruction.rb +22 -0
- data/lib/instruction/break.rb +12 -0
- data/lib/instruction/divide.rb +3 -3
- data/lib/instruction/end_of_iteration_check.rb +2 -2
- data/lib/instruction/evaluate.rb +26 -12
- data/lib/instruction/exit_with_message.rb +4 -3
- data/lib/instruction/field.rb +2 -2
- data/lib/instruction/handler.rb +18 -13
- data/lib/instruction/increment.rb +3 -2
- data/lib/instruction/instantiate_object.rb +31 -17
- data/lib/instruction/jump.rb +24 -5
- data/lib/instruction/multiply.rb +3 -3
- data/lib/instruction/or.rb +2 -4
- data/lib/instruction/print.rb +9 -8
- data/lib/instruction/return.rb +2 -2
- data/lib/instruction/subtract.rb +3 -4
- data/lib/instruction/{goto.rb → try_assign.rb} +3 -3
- data/lib/instruction_handler.rb +7 -11
- data/lib/lcpbt_forrest.rb +83 -0
- data/lib/left_child_preferential_binary_tree.rb +66 -0
- data/lib/non_translatables/handler.rb +23 -0
- data/lib/silviculturist.rb +149 -0
- data/lib/soroban_rust_backend.rb +51 -0
- data/lib/user_defined_types_handler.rb +87 -0
- metadata +19 -17
- data/lib/aggregator/scope_block_aggregator.rb +0 -72
- data/lib/common/input_interpreter.rb +0 -74
- data/lib/common/reference_appender.rb +0 -59
- data/lib/dtr_to_rust.rb +0 -54
- data/lib/generator.rb +0 -196
- data/lib/instruction/label.rb +0 -12
- data/lib/optimization/binary_x_to_self_assignment_reduction.rb +0 -93
- data/lib/optimization/chained_invocation_assignment_reduction.rb +0 -123
- data/lib/optimization/field_to_assignment_conversion.rb +0 -37
- data/lib/user_defined_types/handler.rb +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 395b86bb45dc20bc681eaf200679c503120b2f88a22711ddbf504cd34cc581e3
|
4
|
+
data.tar.gz: 31770e47b89d3470604e6ce81119337db2f97654ee5cabec4c0c986b715ecd72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e218d9931087b5c4f5a5569d58dd0f6a36b130f10d58f032cdd603b9ea11caea0c9d7ad8562d5c685b8d319f944cff4df77333995ef9572508598324827ff8bd
|
7
|
+
data.tar.gz: 386e31210d3c385fa0147615f112f43f2a7f3d0cefd8b8859c737dcce2d0211257bc7d4eba57c3cc2aca4e4beacbbe6f7fbbe6f318bf7c0ea79b3fbd8648b823
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module SorobanRustBackend
|
2
|
+
class CodeGenerator
|
3
|
+
def initialize(instructions, base_indentation: 0)
|
4
|
+
@instructions = instructions
|
5
|
+
@base_indentation = base_indentation
|
6
|
+
|
7
|
+
silviculturist = SorobanRustBackend::Silviculturist.new(instructions, base_indentation:)
|
8
|
+
silviculturist.make_forrest
|
9
|
+
|
10
|
+
@forrest = silviculturist.forrest
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate
|
14
|
+
return_string = ''
|
15
|
+
|
16
|
+
@forrest
|
17
|
+
.code_generator_traverse do |y|
|
18
|
+
y = y.compact
|
19
|
+
|
20
|
+
og_instruction = y[0]
|
21
|
+
instruction = handle_metadata(y[0], y[2])
|
22
|
+
indentation = og_instruction.instruction == 'goto' ? y[2][:return_scope] + @base_indentation : y[1]
|
23
|
+
|
24
|
+
return_string << "#{' ' * indentation}#{InstructionHandler.new(instruction, y[2]).generate_rust}\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
return_string
|
28
|
+
end
|
29
|
+
|
30
|
+
def handle_metadata(instruction, metadata)
|
31
|
+
if instruction.instruction == 'goto'
|
32
|
+
DTRCore::Instruction.new(
|
33
|
+
'jump',
|
34
|
+
[metadata[:return_scope]],
|
35
|
+
instruction.assign,
|
36
|
+
instruction.scope,
|
37
|
+
instruction.id
|
38
|
+
)
|
39
|
+
elsif match_statement?(instruction, metadata)
|
40
|
+
DTRCore::Instruction.new(
|
41
|
+
'jump',
|
42
|
+
instruction.inputs + ['ELSE_IF_BRANCH'],
|
43
|
+
instruction.assign,
|
44
|
+
instruction.scope,
|
45
|
+
instruction.id
|
46
|
+
)
|
47
|
+
elsif if_let?(instruction, metadata)
|
48
|
+
let_statement = "let #{metadata[:try_assign][:lhs]} = #{metadata[:try_assign][:rhs]}"
|
49
|
+
DTRCore::Instruction.new(
|
50
|
+
'jump',
|
51
|
+
[let_statement, instruction.inputs[1]],
|
52
|
+
instruction.assign,
|
53
|
+
instruction.scope,
|
54
|
+
instruction.id
|
55
|
+
)
|
56
|
+
elsif while_loop?(instruction, metadata)
|
57
|
+
operator_variable = "#{metadata[:end_of_iteration_check][:lhs]}"
|
58
|
+
iterator_variable = "#{metadata[:end_of_iteration_check][:rhs]}"
|
59
|
+
|
60
|
+
DTRCore::Instruction.new(
|
61
|
+
'jump',
|
62
|
+
[operator_variable, iterator_variable, instruction.inputs[1], 'WHILE_LOOP'],
|
63
|
+
instruction.assign,
|
64
|
+
instruction.scope,
|
65
|
+
instruction.id
|
66
|
+
)
|
67
|
+
else
|
68
|
+
instruction
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def match_statement?(instruction, metadata)
|
73
|
+
metadata[:last_node_was_conditional_jump] && instruction.instruction == 'jump' && metadata[:parent_scope] && metadata[:parent_scope] == instruction.scope
|
74
|
+
end
|
75
|
+
|
76
|
+
def if_let?(instruction, metadata)
|
77
|
+
instruction.instruction == 'jump' &&
|
78
|
+
metadata[:try_assign] &&
|
79
|
+
metadata[:try_assign][:assign] == instruction.inputs[0] &&
|
80
|
+
metadata[:parent_scope] == instruction.scope
|
81
|
+
end
|
82
|
+
|
83
|
+
def while_loop?(instruction, metadata)
|
84
|
+
instruction.instruction == 'jump' &&
|
85
|
+
metadata[:end_of_iteration_check] &&
|
86
|
+
metadata[:end_of_iteration_check][:assign] == instruction.inputs[0] &&
|
87
|
+
metadata[:parent_scope] == instruction.scope
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Common
|
5
5
|
# TypeTranslator translates DTR types to Rust types
|
6
6
|
module TypeTranslator
|
@@ -10,10 +10,10 @@ module DTRToRust
|
|
10
10
|
.gsub('List<', 'Vec<')
|
11
11
|
.gsub('Dictionary<', 'HashMap<')
|
12
12
|
.gsub('BigInteger', 'i128')
|
13
|
-
.gsub('Integer', '
|
13
|
+
.gsub('Integer', 'i128')
|
14
14
|
.gsub('ByteStringSmall', 'BytesN<32>')
|
15
15
|
.gsub('ByteStringLarge', 'BytesN<64>')
|
16
|
-
.gsub('String', 'Symbol')
|
16
|
+
# .gsub('String', 'Symbol')
|
17
17
|
.gsub('Boolean', 'bool')
|
18
18
|
.gsub('Float', 'f64')
|
19
19
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module SorobanRustBackend
|
2
|
+
class ContractHandler
|
3
|
+
def initialize(contract)
|
4
|
+
@dtr_contract = contract
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.generate(contract)
|
8
|
+
new(contract).generate
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate
|
12
|
+
generate_contract
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :dtr_contract
|
18
|
+
|
19
|
+
def generate_contract
|
20
|
+
@content = ''
|
21
|
+
|
22
|
+
@content += NonTranslatables::Handler.generate(dtr_contract.non_translatables) if dtr_contract.non_translatables
|
23
|
+
|
24
|
+
if dtr_contract.user_defined_types
|
25
|
+
dtr_contract.user_defined_types.each do |user_defined_type|
|
26
|
+
@content += SorobanRustBackend::UserDefinedTypesHandler.generate(user_defined_type)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
@content += ContractState::Handler.generate(dtr_contract.state) if dtr_contract.state
|
30
|
+
generate_contract_name
|
31
|
+
generate_interface if dtr_contract.interface
|
32
|
+
generate_helpers if dtr_contract.helpers
|
33
|
+
|
34
|
+
generate_contract_header
|
35
|
+
|
36
|
+
@content
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate_interface
|
40
|
+
@content += "#[contractimpl]\nimpl #{dtr_contract.name} {#{generate_functions_each(dtr_contract.interface,
|
41
|
+
false)}}\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
def generate_helpers
|
45
|
+
@content += "#{generate_functions_each(dtr_contract.helpers, true)}\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_functions_each(functions, is_helper)
|
49
|
+
# function_names = functions&.map(&:name)
|
50
|
+
|
51
|
+
functions&.map do |function|
|
52
|
+
FunctionHandler.generate(function, is_helper)
|
53
|
+
end&.join("\n")
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_contract_header
|
57
|
+
imports_super_set = %w[
|
58
|
+
Address
|
59
|
+
BytesN
|
60
|
+
contract
|
61
|
+
contractimpl
|
62
|
+
contracttype
|
63
|
+
contracterror
|
64
|
+
symbol_short
|
65
|
+
vec
|
66
|
+
Env
|
67
|
+
String
|
68
|
+
Symbol
|
69
|
+
Vec
|
70
|
+
Val
|
71
|
+
log
|
72
|
+
token
|
73
|
+
]
|
74
|
+
|
75
|
+
used_imports = []
|
76
|
+
|
77
|
+
@content.split.each do |word|
|
78
|
+
imports_super_set.each do |import|
|
79
|
+
used_imports << import if word.include?(import)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
used_imports.uniq!
|
84
|
+
|
85
|
+
# TODO: unsure how to check this one
|
86
|
+
used_imports << 'auth::Context'
|
87
|
+
used_imports << 'IntoVal'
|
88
|
+
used_imports << 'unwrap::UnwrapOptimized'
|
89
|
+
|
90
|
+
# TODO: don't hardcode imports
|
91
|
+
@content = "#![no_std]\nuse soroban_sdk::{#{used_imports.join(', ')}};\n\n" + @content
|
92
|
+
end
|
93
|
+
|
94
|
+
def generate_contract_name
|
95
|
+
@content += "#[contract]\npub struct #{dtr_contract.name};\n\n"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module SorobanRustBackend
|
2
|
+
module ContractState
|
3
|
+
class Handler
|
4
|
+
def initialize(state)
|
5
|
+
@state = state
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.generate(state)
|
9
|
+
new(state).generate
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate
|
13
|
+
generate_state
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def generate_state
|
19
|
+
content = ''
|
20
|
+
|
21
|
+
@state.each do |state_value|
|
22
|
+
if state_value.type == 'Symbol'
|
23
|
+
content += "const #{state_value.name}: Symbol = symbol_short!(#{state_value.initial_value});\n"
|
24
|
+
elsif state_value.type == 'String'
|
25
|
+
content += "const #{state_value.name}: String = String::from_str(#{state_value.initial_value});\n"
|
26
|
+
else
|
27
|
+
content += "const #{state_value.name}: #{Common::TypeTranslator.translate_type(state_value.type)} = #{state_value.initial_value};\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
content
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module SorobanRustBackend
|
2
|
+
class FunctionHandler
|
3
|
+
def initialize(function, is_helper)
|
4
|
+
@function = function
|
5
|
+
@is_helper = is_helper
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.generate(function, is_helper)
|
9
|
+
new(function, is_helper).generate
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate
|
13
|
+
content = ''
|
14
|
+
|
15
|
+
content = "\n#{@is_helper ? '' : ' '}pub fn #{@function.name}(#{generate_function_args}) "
|
16
|
+
content += generate_function_output
|
17
|
+
|
18
|
+
content += " {\n"
|
19
|
+
if @function.output
|
20
|
+
content += "#{@is_helper ? ' ' : ' '}let Thing_to_return: #{Common::TypeTranslator.translate_type(@function.output)};\n"
|
21
|
+
end
|
22
|
+
content += generate_instructions_for_blocks(@function.instructions)
|
23
|
+
|
24
|
+
content += "\n#{@is_helper ? '' : ' '}}\n"
|
25
|
+
|
26
|
+
content
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def generate_function_output
|
32
|
+
return '' if @function.output.nil?
|
33
|
+
|
34
|
+
"-> #{Common::TypeTranslator.translate_type(@function.output)}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_function_args
|
38
|
+
all_inputs = [] + @function.inputs
|
39
|
+
|
40
|
+
all_inputs.map { |x| "#{x[:name]}: #{Common::TypeTranslator.translate_type(x[:type_name])}" }.join(', ')
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate_instructions_for_blocks(instructions)
|
44
|
+
CodeGenerator.new(instructions, base_indentation: @is_helper ? 1 : 2).generate
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/instruction/add.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Instruction
|
5
5
|
# This class handles the add instruction.
|
6
|
-
class Add <
|
7
|
-
def
|
8
|
-
|
6
|
+
class Add < BinaryInstruction
|
7
|
+
def initialize(instruction, metadata)
|
8
|
+
super('+', instruction, metadata)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/instruction/and.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Instruction
|
5
5
|
# This class handles the and instruction.
|
6
6
|
class And < Handler
|
@@ -10,9 +10,7 @@ module DTRToRust
|
|
10
10
|
|
11
11
|
assignment_rust = "let #{assignment} = "
|
12
12
|
body_rust = "#{inputs[0]} && #{inputs[1]};"
|
13
|
-
|
14
|
-
|
15
|
-
form_rust_string(rust_string)
|
13
|
+
"#{assignment.nil? ? '' : assignment_rust}#{body_rust}"
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
data/lib/instruction/assign.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Instruction
|
5
5
|
# This class handles the assign instruction.
|
6
6
|
class Assign < Handler
|
7
7
|
def handle
|
8
8
|
if @instruction.assign.include?('.') || @instruction.assign == 'Thing_to_return'
|
9
|
-
|
9
|
+
"#{@instruction.assign} = #{@instruction.inputs[0]};"
|
10
10
|
else
|
11
|
-
|
11
|
+
"let mut #{@instruction.assign} = #{@instruction.inputs[0]};"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SorobanRustBackend
|
4
|
+
module Instruction
|
5
|
+
# This class handles the add instruction.
|
6
|
+
class BinaryInstruction < Handler
|
7
|
+
def initialize(operation, instruction, metadata)
|
8
|
+
@operation = operation
|
9
|
+
|
10
|
+
super(instruction, metadata)
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle
|
14
|
+
if @metadata[:symbol_table].include?(@instruction.assign) || @instruction.assign.include?('.')
|
15
|
+
"#{@instruction.assign} = #{@instruction.inputs[0]} #{@operation} #{@instruction.inputs[1]};"
|
16
|
+
else
|
17
|
+
"let mut #{@instruction.assign} = #{@instruction.inputs[0]} #{@operation} #{@instruction.inputs[1]};"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/instruction/divide.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Instruction
|
5
5
|
# This class handles the add instruction.
|
6
6
|
class Divide < Handler
|
7
|
-
def
|
8
|
-
|
7
|
+
def initialize(instruction, metadata)
|
8
|
+
super('/', instruction, metadata)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/instruction/evaluate.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Instruction
|
5
5
|
# This class is responsible for generating Rust code for the Evaluate instruction.
|
6
6
|
class Evaluate < Handler
|
7
7
|
def handle
|
8
|
-
|
9
|
-
form_rust_string(rust_string)
|
8
|
+
handle_keyword_method_invocation
|
10
9
|
end
|
11
10
|
|
12
11
|
private
|
@@ -27,11 +26,17 @@ module DTRToRust
|
|
27
26
|
handle_binary('>=')
|
28
27
|
when 'not_equal_to'
|
29
28
|
handle_binary('!=')
|
29
|
+
when 'start'
|
30
|
+
handle_start
|
30
31
|
else
|
31
32
|
handle_non_keyword_method_invocation
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
36
|
+
def handle_start
|
37
|
+
"let mut OPTION_#{@instruction.assign} = #{@instruction.inputs[1]}.next();"
|
38
|
+
end
|
39
|
+
|
35
40
|
def handle_non_keyword_method_invocation
|
36
41
|
inputs = @instruction.inputs[1..]
|
37
42
|
evaluated_method_name = @instruction.inputs[0]
|
@@ -44,7 +49,7 @@ module DTRToRust
|
|
44
49
|
"#{if assignment.nil?
|
45
50
|
''
|
46
51
|
else
|
47
|
-
assignment == 'Thing_to_return' ? assignment
|
52
|
+
assignment == 'Thing_to_return' ? "#{assignment} = " : assignment_rust
|
48
53
|
end}#{body_rust}"
|
49
54
|
end
|
50
55
|
|
@@ -81,20 +86,29 @@ module DTRToRust
|
|
81
86
|
!(@instruction.inputs[0].end_with?('unwrap_or') ||
|
82
87
|
@instruction.inputs[0].end_with?('publish') ||
|
83
88
|
@instruction.inputs[0].end_with?('Err') ||
|
84
|
-
@instruction.inputs[0].end_with?('Ok')
|
89
|
+
@instruction.inputs[0].end_with?('Ok') ||
|
90
|
+
@instruction.inputs[0].end_with?('checked_mul') ||
|
91
|
+
@instruction.inputs[0].end_with?('checked_add') ||
|
92
|
+
@instruction.inputs[0].end_with?('update_current_contract_wasm') ||
|
93
|
+
@instruction.inputs[0].end_with?('with_address') ||
|
94
|
+
@instruction.inputs[0].end_with?('deploy')
|
85
95
|
)
|
86
96
|
end
|
87
97
|
|
88
98
|
def invocation_name(evaluated_method_name)
|
89
|
-
if @function_names.include?(evaluated_method_name)
|
90
|
-
|
91
|
-
else
|
92
|
-
|
93
|
-
end
|
99
|
+
# if @function_names.include?(evaluated_method_name)
|
100
|
+
# "Self::#{evaluated_method_name}"
|
101
|
+
# else
|
102
|
+
evaluated_method_name
|
103
|
+
# end
|
94
104
|
end
|
95
105
|
|
96
|
-
def inputs_to_rust_string(inputs,
|
97
|
-
inputs.map
|
106
|
+
def inputs_to_rust_string(inputs, _ref_nums, _ref_vars)
|
107
|
+
# inputs.map do |input|
|
108
|
+
# ref_vars ? Common::ReferenceAppender.call(input, ref_nums:, function_inputs: @function_inputs) : input
|
109
|
+
# end.join(', ')
|
110
|
+
|
111
|
+
inputs.join(', ')
|
98
112
|
end
|
99
113
|
end
|
100
114
|
end
|
@@ -1,17 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Instruction
|
5
5
|
# This class handles the exit_with_message instruction.
|
6
6
|
class ExitWithMessage < Handler
|
7
7
|
def handle
|
8
|
-
|
8
|
+
"panic!(#{inputs_to_rust_string(@instruction.inputs)});"
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def inputs_to_rust_string(inputs)
|
14
|
-
inputs.map { |input| Common::ReferenceAppender.call(input) }.join(', ')
|
14
|
+
# inputs.map { |input| Common::ReferenceAppender.call(input, function_inputs: @function_inputs) }.join(', ')
|
15
|
+
inputs.map { |input| input }.join(', ')
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
data/lib/instruction/field.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Instruction
|
5
5
|
# This class is responsible for generating Rust code for the Field instruction.
|
6
6
|
class Field < Handler
|
7
7
|
def handle
|
8
|
-
|
8
|
+
"#{handle_field_assign}#{handle_field_call}"
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
data/lib/instruction/handler.rb
CHANGED
@@ -1,27 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Instruction
|
5
5
|
# This class is responsible for generating Rust code for the AddAndAssign instruction.
|
6
6
|
class Handler
|
7
|
-
def initialize(instruction,
|
7
|
+
def initialize(instruction, metadata)
|
8
8
|
@instruction = instruction
|
9
|
-
@
|
10
|
-
@function_names = function_names
|
11
|
-
@user_defined_types = user_defined_types
|
12
|
-
@is_helper = is_helper
|
13
|
-
end
|
9
|
+
@metadata = metadata
|
14
10
|
|
15
|
-
|
16
|
-
new(instruction, spacing_scope, function_names, user_defined_types, is_helper).handle
|
11
|
+
format_assign
|
17
12
|
end
|
18
13
|
|
19
|
-
def
|
20
|
-
|
14
|
+
def format_assign
|
15
|
+
return unless @instruction.assign&.include?('|||') && @instruction.assign.split('|||').size == 2
|
16
|
+
|
17
|
+
var_name, type_name = @instruction.assign.split('|||')
|
18
|
+
|
19
|
+
@instruction = DTRCore::Instruction.new(
|
20
|
+
@instruction.instruction,
|
21
|
+
@instruction.inputs,
|
22
|
+
"#{var_name}: #{Common::TypeTranslator.translate_type(type_name)}",
|
23
|
+
@instruction.scope,
|
24
|
+
@instruction.id
|
25
|
+
)
|
21
26
|
end
|
22
27
|
|
23
|
-
def
|
24
|
-
|
28
|
+
def self.handle(instruction, metadata)
|
29
|
+
new(instruction, metadata).handle
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SorobanRustBackend
|
4
4
|
module Instruction
|
5
5
|
class Increment < Handler
|
6
6
|
def handle
|
7
|
-
|
7
|
+
# assumes non-range iterator
|
8
|
+
"OPTION_#{@instruction.inputs[0]} = #{@instruction.inputs[1]}.next();"
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|