dtr_to_rust 0.2.2 → 0.2.4

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: d126c4c538c35083034a022b0d7ea4c6848f26e149ad7f1a876912ffce48bb48
4
- data.tar.gz: c8ea863fc9d0023717a710ce124c40d384d0be01042c0de6d022c54ee292b52d
3
+ metadata.gz: d438e4b50824b1f820f329c291d88bf97034fef9bdfd05b88b5b5a610fa23ee5
4
+ data.tar.gz: 581033f850771cfe5165ebb2028973048ddd5d17123690a06b6c4ab99fd30230
5
5
  SHA512:
6
- metadata.gz: 68f43f0078b25a6b96ae02fd87d21f7102af319d4dc32ffcdd1e8551d7bea94723fdd8a6bfeb9c2b11203b498573656606b913a17d4995fa805908534fa4310a
7
- data.tar.gz: ed189b4cc25fe407de644891b11610d90ebc87e16f9a92b51dcc116c626cc8767357a3494311092d1b1d62a568f03e5075eb23a64408f2c014b97a399a66f0f1
6
+ metadata.gz: 07a1b2d9dc755146b4b5cba34c57c7758dbd406b37f8731962aaeb231d92803ec8afe4cc45d6b2da40f3bf30a9741b45ba2b2c5f004736731cf9aff7afeacf57
7
+ data.tar.gz: bb416781d416dd6a5cf6901d8264ea28f58fc10fdd9e128c5deed8730c507cf1652a7cd00c13ad23556f2a0326567c834ff06f84fc20dfbcfa341c3674b92122
data/lib/dtr_to_rust.rb CHANGED
@@ -7,11 +7,12 @@ module DTRToRust
7
7
 
8
8
  # This module contains all the classes that handle the different types of instructions.
9
9
  module Instruction
10
- autoload :Handler, 'instruction/handler'
10
+ autoload :AddAndAssign, 'instruction/add_and_assign'
11
+ autoload :CreateList, 'instruction/create_list'
11
12
  autoload :Evaluate, 'instruction/evaluate'
12
- autoload :Return, 'instruction/return'
13
13
  autoload :LogString, 'instruction/log_string'
14
- autoload :AddAndAssign, 'instruction/add_and_assign'
14
+ autoload :Handler, 'instruction/handler'
15
+ autoload :Return, 'instruction/return'
15
16
  end
16
17
 
17
18
  # This module contains all the classes that handle common logic.
data/lib/generator.rb CHANGED
@@ -70,18 +70,13 @@ module DTRToRust
70
70
  def generate_function_output(function)
71
71
  return '' if function.output.nil?
72
72
 
73
- case function.output
74
- when 'String'
75
- "-> Symbol"
76
- else
77
- "-> #{function.output}"
78
- end
73
+ "-> #{translate_type(function.output)}"
79
74
  end
80
75
 
81
76
  def generate_function_args(function)
82
77
  all_inputs = [] + function.inputs
83
78
 
84
- all_inputs.map { |x| "#{x[:name]}: #{x[:type_name]}" }.join(', ')
79
+ all_inputs.map { |x| "#{x[:name]}: #{translate_type(x[:type_name])}" }.join(', ')
85
80
  end
86
81
 
87
82
  def generate_instructions_each(instructions)
@@ -94,5 +89,14 @@ module DTRToRust
94
89
  handler = InstructionHandler.new(instruction)
95
90
  handler.generate_rust
96
91
  end
92
+
93
+ def translate_type(type)
94
+ case type
95
+ when 'String'
96
+ 'Symbol'
97
+ else
98
+ type
99
+ end
100
+ end
97
101
  end
98
102
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DTRToRust
4
+ module Instruction
5
+ # This class is responsible for generating Rust code for the AddAndAssign instruction.
6
+ class CreateList < Handler
7
+ def handle
8
+ form_rust_string("let #{@instruction[:assign]} = vec![#{@instruction[:inputs].join(', ')}];",
9
+ @instruction[:scope])
10
+ end
11
+ end
12
+ end
13
+ end
@@ -17,6 +17,8 @@ module DTRToRust
17
17
  Instruction::AddAndAssign.handle(@instruction)
18
18
  when 'evaluate'
19
19
  Instruction::Evaluate.handle(@instruction)
20
+ when 'create_list'
21
+ Instruction::CreateList.handle(@instruction)
20
22
  else
21
23
  raise "Unknown instruction type: #{@instruction[:instruction]}"
22
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtr_to_rust
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Durst
@@ -21,6 +21,7 @@ files:
21
21
  - lib/dtr_to_rust.rb
22
22
  - lib/generator.rb
23
23
  - lib/instruction/add_and_assign.rb
24
+ - lib/instruction/create_list.rb
24
25
  - lib/instruction/evaluate.rb
25
26
  - lib/instruction/handler.rb
26
27
  - lib/instruction/log_string.rb