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 +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 +7 -13
- metadata +7 -2
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
@@ -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
|
-
|
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
|
+
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-
|
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:
|