dtr_to_rust 0.0.4 → 0.0.6

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: 1806c512b3954d5b391267085acf5d29e286993840a6fd3f58191be6f9f5062d
4
- data.tar.gz: 0d19d719058f64916475ca8689b6103876f694d962e15b87ab96246472382d99
3
+ metadata.gz: c9d654b804b0e2e70eaa7262d789da82638a1f0085af9cb59f1c15172183b69c
4
+ data.tar.gz: e19a3975c472be307f7f2b2e23798026fb09778985c2e822ee15f7592bd2c44e
5
5
  SHA512:
6
- metadata.gz: 842cd6102fa86b8f66662ba8b799e8e195336fe4895653576c55a7fb14e21bed941eff1b467f16650db32ba9a2a27100b0b3920333770f4c9f8110c155e85800
7
- data.tar.gz: 7f41c7dcfce3f3077d2ada86d5b9b02a1cc0bf8a113803747d0d3a246d5e5d67354387db9cc272753657e155190cf616ac54ba7639337d4a1318d0881f545f54
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
@@ -9,10 +9,14 @@ module DTRToRust
9
9
 
10
10
  def generate_rust
11
11
  case @instruction[:instruction]
12
- when 'AddSymbols'
13
- handle_add_symbols
14
12
  when 'Return'
15
- handle_return
13
+ Instruction::Return.handle(@instruction)
14
+ when 'log_string'
15
+ Instruction::LogString.handle(@instruction)
16
+ when 'add_and_assign'
17
+ Instruction::AddAndAssign.handle(@instruction)
18
+ when 'evaluate'
19
+ Instruction::Evaluate.handle(@instruction)
16
20
  else
17
21
  raise "Unknown instruction type: #{@instruction[:instruction]}"
18
22
  end
@@ -21,15 +25,5 @@ module DTRToRust
21
25
  private
22
26
 
23
27
  attr_reader :instruction
24
-
25
- def handle_add_symbols
26
- " let #{instruction[:assign]} " \
27
- '= vec![&env, ' \
28
- "symbol_short!(#{instruction[:inputs][0]}), #{instruction[:inputs][1]}];"
29
- end
30
-
31
- def handle_return
32
- " #{instruction[:inputs][0]}"
33
- end
34
28
  end
35
29
  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.0.4
4
+ version: 0.0.6
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-01 00:00:00.000000000 Z
11
+ date: 2024-06-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rust to DTR translator (Digicus Textual Representation).
14
14
  email:
@@ -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: