dtr_to_rust 0.0.5 → 0.0.6

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: 5e847ba23b85fbcb73f654a7204b136c7d22159da92f1c19834242382f0422e9
4
- data.tar.gz: 02c903ad18bc3ee83024db1df4d838e36dcf58f8fef3e3cb50b1b912037f7da0
3
+ metadata.gz: c9d654b804b0e2e70eaa7262d789da82638a1f0085af9cb59f1c15172183b69c
4
+ data.tar.gz: e19a3975c472be307f7f2b2e23798026fb09778985c2e822ee15f7592bd2c44e
5
5
  SHA512:
6
- metadata.gz: 15801ee722bdc1d23650c2c37535e7a836250ec313a97cadc7b2830679dbd093901ab46f2ad4e1fa995710294d8a985c173db0d9667b11129ec2fac1bb3c8c3a
7
- data.tar.gz: 5f113fe380f4e21f260dd7bfdf6600e0354e0b24f8896cda19f22dcd38d9b173d8dc53eb55962a97ae89b21dc39a36f479c817ccf404164c6be111c7d4b88fae
6
+ metadata.gz: 8d08d0faf3192c0b014be5280f5cc5355e9db939a52aec85eccc34823e14c1fbd8aec6bc87c39754c19dbd1822e8a7e5e9e17b184a69bbcc96136af93442624e
7
+ data.tar.gz: 4d2cd11212145f9e374167142f551dbb732673353a6db399144a685dd507c5b6732e2295201c8510a4495df0cbb645f593e4b442ba9735f5a78371caffce57d0
data/lib/dtr_to_rust.rb CHANGED
@@ -4,4 +4,13 @@
4
4
  module DTRToRust
5
5
  autoload :Generator, 'generator'
6
6
  autoload :InstructionHandler, 'instruction_handler'
7
+
8
+ # This module contains all the classes that handle the different types of instructions.
9
+ module Instruction
10
+ autoload :Handler, 'instruction/handler'
11
+ autoload :Evaluate, 'instruction/evaluate'
12
+ autoload :Return, 'instruction/return'
13
+ autoload :LogString, 'instruction/log_string'
14
+ autoload :AddAndAssign, 'instruction/add_and_assign'
15
+ end
7
16
  end
@@ -0,0 +1,12 @@
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 AddAndAssign < Handler
7
+ def handle
8
+ form_rust_string("#{@instruction[:inputs][0]} += #{@instruction[:inputs][1]}", @instruction[:scope])
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DTRToRust
4
+ module Instruction
5
+ # This class is responsible for generating Rust code for the Evaluate instruction.
6
+ class Evaluate < Handler
7
+ def handle
8
+ rust_string = "#{@instruction[:assign]} = #{@instruction[:inputs][0]}(#{@instruction[:inputs][1..].join(', ')})"
9
+
10
+ form_rust_string(rust_string, @instruction[:scope])
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
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 Handler
7
+ def initialize(instruction)
8
+ @instruction = instruction
9
+ end
10
+
11
+ def self.handle(instruction)
12
+ new(instruction).handle
13
+ end
14
+
15
+ def spacing(scope)
16
+ ' ' * scope
17
+ end
18
+
19
+ def form_rust_string(instruction_string, scope)
20
+ "#{spacing(scope)}#{instruction_string}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DTRToRust
4
+ module Instruction
5
+ # This class is responsible for generating Rust code for the LogString instruction.
6
+ class LogString < Handler
7
+ def handle
8
+ form_rust_string("log!(#{@instruction[:inputs].join(',')})", @instruction[:scope])
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DTRToRust
4
+ module Instruction
5
+ # This class is responsible for generating Rust code for the Return instruction.
6
+ class Return < Handler
7
+ def handle
8
+ form_rust_string(@instruction[:inputs][0], @instruction[:scope])
9
+ end
10
+ end
11
+ end
12
+ end
@@ -10,13 +10,13 @@ module DTRToRust
10
10
  def generate_rust
11
11
  case @instruction[:instruction]
12
12
  when 'Return'
13
- handle_return
13
+ Instruction::Return.handle(@instruction)
14
14
  when 'log_string'
15
- handle_log_string
15
+ Instruction::LogString.handle(@instruction)
16
16
  when 'add_and_assign'
17
- handle_add_and_assign
17
+ Instruction::AddAndAssign.handle(@instruction)
18
18
  when 'evaluate'
19
- "foo bar"
19
+ Instruction::Evaluate.handle(@instruction)
20
20
  else
21
21
  raise "Unknown instruction type: #{@instruction[:instruction]}"
22
22
  end
@@ -25,25 +25,5 @@ module DTRToRust
25
25
  private
26
26
 
27
27
  attr_reader :instruction
28
-
29
- def spacing(scope)
30
- " " * scope
31
- end
32
-
33
- def form_rust_string(instruction_string, scope)
34
- "#{spacing(scope)}#{instruction_string}"
35
- end
36
-
37
- def handle_return
38
- form_rust_string(instruction[:inputs][0], instruction[:scope])
39
- end
40
-
41
- def handle_log_string
42
- form_rust_string("log!(#{instruction[:inputs].join(',')})", instruction[:scope])
43
- end
44
-
45
- def handle_add_and_assign
46
- form_rust_string("#{instruction[:inputs][0]} += #{instruction[:inputs][1]}", instruction[:scope])
47
- end
48
28
  end
49
29
  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.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Durst
@@ -19,6 +19,11 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - lib/dtr_to_rust.rb
21
21
  - lib/generator.rb
22
+ - lib/instruction/add_and_assign.rb
23
+ - lib/instruction/evaluate.rb
24
+ - lib/instruction/handler.rb
25
+ - lib/instruction/log_string.rb
26
+ - lib/instruction/return.rb
22
27
  - lib/instruction_handler.rb
23
28
  homepage: https://spaced-out-thoughts-dev-foundation.github.io/digicus/
24
29
  licenses: