dtr_to_rust 0.5.0 → 0.8.1

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: b758e2693dba6f08986542c9a49c6d15f285529cbb172d3a29bb171ec95536b1
4
- data.tar.gz: 3d4ef34c8dfd29ff2124fe8c3b0c8ac194872729bbd9443b633a0e5e973aafb6
3
+ metadata.gz: 002e00efbc75ccf74ff3383c9027901e390186aaa8c40d1c415f0c88610972c6
4
+ data.tar.gz: 24a42f407043cd7273d651626f6e7d9f0cac095b0023a37459198dc775b5481e
5
5
  SHA512:
6
- metadata.gz: 40cd10cc460cae31a4a596a28e10d9ede4af898effbc4cd14037394ed6d3930cb47420c88f6716c253c3f33b732ed2474cb99f6af5a1d0048d3c71bfea80f9c5
7
- data.tar.gz: b4dda97391b69c4eefa43916514d8185564ba98b2d86b461b8e45b2f94e2e578cc360de5c84a5768df99494c295a9c708db0500a4db9582d5ccacb80fc5d967c
6
+ metadata.gz: c752d59d3a79a59ee1e0e46858cdf46539e0db4ecc1c4cfef6de53b368a5f493e4be37d0febf0f553d64393fd831226c926e415f5adeee2d217372d1c439ac1c
7
+ data.tar.gz: d52b67210ae2d46ed11f3b21d9873687f08251f15879343742f2fc2d8a066f0869e845970fc0b60f015f9f230ad794ed0595f47aab33f3497f898ca7df5f5dbc
data/lib/generator.rb CHANGED
@@ -107,8 +107,12 @@ module DTRToRust
107
107
 
108
108
  return_string = "\n#{is_helper ? '' : ' '}pub fn #{function.name}(#{generate_function_args(function)}) "
109
109
  return_string += generate_function_output(function)
110
- return_string += " {\n#{generate_instructions_for_blocks(instruction_blocks, function_names,
111
- is_helper)}"
110
+ return_string += " {\n"
111
+ if function.output
112
+ return_string += " let Thing_to_return: #{Common::TypeTranslator.translate_type(function.output)};\n"
113
+ end
114
+ return_string += "#{generate_instructions_for_blocks(instruction_blocks, function_names,
115
+ is_helper)}"
112
116
 
113
117
  if @last_scope.positive?
114
118
  while @last_scope.positive?
@@ -5,7 +5,7 @@ module DTRToRust
5
5
  # This class handles the assign instruction.
6
6
  class Assign < Handler
7
7
  def handle
8
- if @instruction.assign.include?('.')
8
+ if @instruction.assign.include?('.') || @instruction.assign == 'Thing_to_return'
9
9
  form_rust_string("#{@instruction.assign} = #{@instruction.inputs[0]};")
10
10
  else
11
11
  form_rust_string("let mut #{@instruction.assign} = #{@instruction.inputs[0]};")
@@ -14,13 +14,19 @@ module DTRToRust
14
14
  def handle_keyword_method_invocation
15
15
  case @instruction.inputs[0]
16
16
  when 'equal_to'
17
- handle_equal_to
17
+ handle_binary('==')
18
18
  when '!'
19
19
  handle_unary_negation
20
20
  when 'less_than'
21
- handle_less_than
21
+ handle_binary('<')
22
22
  when 'less_than_or_equal_to'
23
- handle_less_than_or_equal_to
23
+ handle_binary('<=')
24
+ when 'greater_than'
25
+ handle_binary('>')
26
+ when 'greater_than_or_equal_to'
27
+ handle_binary('>=')
28
+ when 'not_equal_to'
29
+ handle_binary('!=')
24
30
  else
25
31
  handle_non_keyword_method_invocation
26
32
  end
@@ -35,44 +41,22 @@ module DTRToRust
35
41
  # TODO: make this less hacky evaluated_method_name.end_with?('set')
36
42
  body_rust = "#{invocation_name(evaluated_method_name)}(#{inputs_to_rust_string(inputs,
37
43
  append_ref_to_num?, try_append_ref_to_var?)});"
38
- "#{assignment.nil? ? '' : assignment_rust}#{body_rust}"
39
- end
40
-
41
- def handle_equal_to
42
- inputs = @instruction.inputs[1..]
43
- @instruction.inputs[0]
44
- assignment = @instruction.assign
45
-
46
- assignment_rust = "let #{assignment} = "
47
- lhs = Common::ReferenceAppender.call(inputs[0])
48
- rhs = Common::ReferenceAppender.call(inputs[1])
49
- body_rust = "#{lhs} == #{rhs};"
50
-
51
- "#{assignment.nil? ? '' : assignment_rust}#{body_rust}"
52
- end
53
-
54
- def handle_less_than
55
- inputs = @instruction.inputs[1..]
56
- @instruction.inputs[0]
57
- assignment = @instruction.assign
58
-
59
- assignment_rust = "let #{assignment} = "
60
- lhs = Common::ReferenceAppender.call(inputs[0])
61
- rhs = Common::ReferenceAppender.call(inputs[1])
62
- body_rust = "#{lhs} < #{rhs};"
63
-
64
- "#{assignment.nil? ? '' : assignment_rust}#{body_rust}"
44
+ "#{if assignment.nil?
45
+ ''
46
+ else
47
+ assignment == 'Thing_to_return' ? assignment + ' = ' : assignment_rust
48
+ end}#{body_rust}"
65
49
  end
66
50
 
67
- def handle_less_than_or_equal_to
51
+ def handle_binary(operation)
68
52
  inputs = @instruction.inputs[1..]
69
53
  @instruction.inputs[0]
70
54
  assignment = @instruction.assign
71
55
 
72
56
  assignment_rust = "let #{assignment} = "
73
- lhs = Common::ReferenceAppender.call(inputs[0])
74
- rhs = Common::ReferenceAppender.call(inputs[1])
75
- body_rust = "#{lhs} <= #{rhs};"
57
+ lhs = inputs[0]
58
+ rhs = inputs[1]
59
+ body_rust = "#{lhs} #{operation} #{rhs};"
76
60
 
77
61
  "#{assignment.nil? ? '' : assignment_rust}#{body_rust}"
78
62
  end
@@ -94,7 +78,11 @@ module DTRToRust
94
78
 
95
79
  def try_append_ref_to_var?
96
80
  # SO HACKY - Refs are hard man
97
- !(@instruction.inputs[0].end_with?('unwrap_or') || @instruction.inputs[0].end_with?('publish'))
81
+ !(@instruction.inputs[0].end_with?('unwrap_or') ||
82
+ @instruction.inputs[0].end_with?('publish') ||
83
+ @instruction.inputs[0].end_with?('Err') ||
84
+ @instruction.inputs[0].end_with?('Ok')
85
+ )
98
86
  end
99
87
 
100
88
  def invocation_name(evaluated_method_name)
@@ -37,6 +37,17 @@ module DTRToRust
37
37
  @user_defined_type.attributes.map do |x|
38
38
  if x[:value]
39
39
  " #{x[:name]} = #{x[:value]},"
40
+ elsif x[:type] && x[:type].start_with?('(') && x[:type].end_with?(')')
41
+ inner_types = x[:type].gsub('(', '').gsub(')', '').split(',').map do |x|
42
+ Common::TypeTranslator.translate_type(x)
43
+ end
44
+ if inner_types.size == 0 || x[:type] == '()'
45
+ " #{x[:name]},"
46
+ else
47
+ " #{x[:name]}(#{inner_types.join(', ')}),"
48
+ end
49
+ elsif x[:type] && x[:type].match(/\d+/)
50
+ " #{x[:name]} = #{x[:type]},"
40
51
  elsif x[:type] && x[:type] != '()'
41
52
  " #{x[:name]}(#{Common::TypeTranslator.translate_type(x[:type])}),"
42
53
  else
@@ -47,7 +58,7 @@ module DTRToRust
47
58
 
48
59
  def derives
49
60
  base = if error? && enum?
50
- "#[contracterror]\n#[derive(Clone, Debug, Eq, PartialEq)]\n"
61
+ "#[contracterror]\n#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]\n"
51
62
  else
52
63
  "#[contracttype]\n#[derive(Clone, Debug, Eq, PartialEq)]\n"
53
64
  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.5.0
4
+ version: 0.8.1
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-23 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rust to DTR translator (Digicus Textual Representation).
14
14
  email: