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 +4 -4
- data/lib/dtr_to_rust.rb +3 -1
- data/lib/generator.rb +14 -1
- data/lib/instruction/field.rb +22 -0
- data/lib/instruction/initialize_udt.rb +22 -0
- data/lib/instruction_handler.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7572c039db830a1a216b31e01f53a104701d8321d487b47811a7a366ea520e53
|
4
|
+
data.tar.gz: d359cdc39400f9a0bdaf4823cdf77aea9c1aeb6fb7dbee931419e2208d073a51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 :
|
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
|
-
|
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
|
data/lib/instruction_handler.rb
CHANGED
@@ -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.
|
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-
|
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
|