dtr_to_rust 0.2.8 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0727f4ba55f3585b37450487756b1ed479254101eba8454b95b426f718fb9ac3
4
- data.tar.gz: 6bd5798565bd5daff348e35703f20efbed64c3b04a34cbfa0c57371d152da3d4
3
+ metadata.gz: 7572c039db830a1a216b31e01f53a104701d8321d487b47811a7a366ea520e53
4
+ data.tar.gz: d359cdc39400f9a0bdaf4823cdf77aea9c1aeb6fb7dbee931419e2208d073a51
5
5
  SHA512:
6
- metadata.gz: 82465c833948c2569adee3ec5db6cc3c6a7788b26fb98255bc49f8c6eecc6ab081b2dfd3245ce950cd59776c8c1ec41cef47eac8bf0b787234e3008719685d81
7
- data.tar.gz: 7070e278d1758bdbb9e750196c628acbb244c4da968141bb7e9a1952c02c7cb6bcbf31c5aa7b1e0eebbb5b24a3f42b27705e4078263f03f9a4844cb23d169dfb
6
+ metadata.gz: 8c62415d2d4f63cb331cf26bdf73c72e9b230a69c65cf8df5bf0ff83f102f4658641b329e48d3c7f01a2c53501f58be1c5bfd5133ce98b9652674911043a0b60
7
+ data.tar.gz: 43caee328ae2b7216104600b8a656cb0ab5cc71ceeaae6a75de277516bef5b095ab1ca2f57a495c47dd353b7bd87b3a66ace7d11ebdcd7ecff97ead0521aa381
data/lib/dtr_to_rust.rb CHANGED
@@ -10,8 +10,10 @@ module DTRToRust
10
10
  autoload :AddAndAssign, 'instruction/add_and_assign'
11
11
  autoload :CreateList, 'instruction/create_list'
12
12
  autoload :Evaluate, 'instruction/evaluate'
13
- autoload :LogString, 'instruction/log_string'
13
+ autoload :Field, 'instruction/field'
14
14
  autoload :Handler, 'instruction/handler'
15
+ autoload :InitializeUDT, 'instruction/initialize_udt'
16
+ autoload :LogString, 'instruction/log_string'
15
17
  autoload :Return, 'instruction/return'
16
18
  end
17
19
 
data/lib/generator.rb CHANGED
@@ -13,8 +13,9 @@ module DTRToRust
13
13
  @content = ''
14
14
 
15
15
  generate_contract_header
16
- generate_contract_name
16
+ generate_user_defined_types
17
17
  generate_state
18
+ generate_contract_name
18
19
  generate_functions
19
20
 
20
21
  @content
@@ -102,5 +103,17 @@ module DTRToRust
102
103
  type
103
104
  end
104
105
  end
106
+
107
+ def generate_user_defined_types
108
+ return if dtr_contract.user_defined_types.nil?
109
+
110
+ dtr_contract.user_defined_types.each do |udt|
111
+ @content += "#{derives}pub struct #{udt.name} {#{udt.attributes.map { |x| "#{x[:name]}: #{x[:type]}" }.join(', ')}}\n\n"
112
+ end
113
+ end
114
+
115
+ def derives
116
+ "#[contracttype]\n#[derive(Clone, Debug, Eq, PartialEq)]\n"
117
+ end
105
118
  end
106
119
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DTRToRust
4
+ module Instruction
5
+ # This class is responsible for generating Rust code for the Field instruction.
6
+ class Field < Handler
7
+ def handle
8
+ form_rust_string("#{handle_field_assign}#{handle_field_call}", @instruction[:scope])
9
+ end
10
+
11
+ private
12
+
13
+ def handle_field_call
14
+ "#{@instruction[:inputs][0]}.#{@instruction[:inputs][1]};"
15
+ end
16
+
17
+ def handle_field_assign
18
+ "let mut #{@instruction[:assign]} = " if @instruction[:assign]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -13,7 +13,7 @@ module DTRToRust
13
13
  end
14
14
 
15
15
  def spacing(scope)
16
- ' ' * (scope + 1)
16
+ ' ' * (scope + 1)
17
17
  end
18
18
 
19
19
  def form_rust_string(instruction_string, scope)
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DTRToRust
4
+ module Instruction
5
+ # This class is responsible for generating Rust code for the Field instruction.
6
+ class InitializeUDT < Handler
7
+ def handle
8
+ form_rust_string("#{handle_assign}#{handle_udt_part}", @instruction[:scope])
9
+ end
10
+
11
+ private
12
+
13
+ def handle_udt_part
14
+ "#{@instruction[:inputs][0]} { #{@instruction[:inputs][1..].join(' ')} };"
15
+ end
16
+
17
+ def handle_assign
18
+ "let mut #{@instruction[:assign]} = " if @instruction[:assign]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -19,6 +19,10 @@ module DTRToRust
19
19
  Instruction::Evaluate.handle(@instruction)
20
20
  when 'create_list'
21
21
  Instruction::CreateList.handle(@instruction)
22
+ when 'field'
23
+ Instruction::Field.handle(@instruction)
24
+ when 'initialize_udt'
25
+ Instruction::InitializeUDT.handle(@instruction)
22
26
  else
23
27
  raise "Unknown instruction type: #{@instruction[:instruction]}"
24
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtr_to_rust
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Durst
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-07 00:00:00.000000000 Z
11
+ date: 2024-06-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rust to DTR translator (Digicus Textual Representation).
14
14
  email:
@@ -23,7 +23,9 @@ files:
23
23
  - lib/instruction/add_and_assign.rb
24
24
  - lib/instruction/create_list.rb
25
25
  - lib/instruction/evaluate.rb
26
+ - lib/instruction/field.rb
26
27
  - lib/instruction/handler.rb
28
+ - lib/instruction/initialize_udt.rb
27
29
  - lib/instruction/log_string.rb
28
30
  - lib/instruction/return.rb
29
31
  - lib/instruction_handler.rb