dtr_to_rust 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- 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: 0b601b1a9ea3ca3f47651dbd2cfd90d563244994bdccb0aa7b44ec2882219067
|
4
|
+
data.tar.gz: a480b70e8c6bfb2421900f5b82db3c2f8c83d1194954a78683b30db78a67a860
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2497d871d595c64552926cde73f20dc574e342ba769de4961baef8c595c31d78f2b9080d3c6793b8ecc28aa981d4ced0c00fa9ff7f1ebbc6335765e4983309d
|
7
|
+
data.tar.gz: 5c2eb5673bff37de5fe02a64456eae6b60a2b89182b75fc4a22489e29c016d0fd9f1e3f1fe8ebb30888efa2f4f89f308da9942276d3e4bc1bccd461cdc167654
|
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.7
|
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:
|