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 +4 -4
- data/lib/dtr_to_rust.rb +9 -0
- data/lib/instruction/add_and_assign.rb +12 -0
- data/lib/instruction/evaluate.rb +14 -0
- data/lib/instruction/handler.rb +24 -0
- data/lib/instruction/log_string.rb +12 -0
- data/lib/instruction/return.rb +12 -0
- data/lib/instruction_handler.rb +4 -24
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9d654b804b0e2e70eaa7262d789da82638a1f0085af9cb59f1c15172183b69c
|
4
|
+
data.tar.gz: e19a3975c472be307f7f2b2e23798026fb09778985c2e822ee15f7592bd2c44e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/instruction_handler.rb
CHANGED
@@ -10,13 +10,13 @@ module DTRToRust
|
|
10
10
|
def generate_rust
|
11
11
|
case @instruction[:instruction]
|
12
12
|
when 'Return'
|
13
|
-
|
13
|
+
Instruction::Return.handle(@instruction)
|
14
14
|
when 'log_string'
|
15
|
-
|
15
|
+
Instruction::LogString.handle(@instruction)
|
16
16
|
when 'add_and_assign'
|
17
|
-
|
17
|
+
Instruction::AddAndAssign.handle(@instruction)
|
18
18
|
when 'evaluate'
|
19
|
-
|
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.
|
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:
|