dtr_to_rust 0.2.9 → 0.2.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e162b79fdd4a6f372b08c6b36c28980c2c4cb1d66577a80d23a244f6ade8cd3
4
- data.tar.gz: a570d2d370182232c38e425c4e179996308ca15db6430d8bfc341a69ff470800
3
+ metadata.gz: 7572c039db830a1a216b31e01f53a104701d8321d487b47811a7a366ea520e53
4
+ data.tar.gz: d359cdc39400f9a0bdaf4823cdf77aea9c1aeb6fb7dbee931419e2208d073a51
5
5
  SHA512:
6
- metadata.gz: 1386ba89bdcd93832c74f7cb6cbb1d832a27ea7f53c0fdb0cfe8ccd1dd9b2922d55f193450673e8d3b1320cefd82c8ec8a78edb0e8b13b81b2e40c4c14ac83ae
7
- data.tar.gz: 79436cffb6d41f451c18a43b6fac27946f47d636e1a444a52a2b153216edbf1ae5b6a5d139fd39024e4ee2dc262d476dd2cae246aacdd667554f693ac81f69ac
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
@@ -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.9
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