dtr_core 0.5.2 → 0.5.4

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: 87ca88cd269d52251ab32a7923f88e8f5735d68880d0bdc45cfd086daf42de47
4
- data.tar.gz: de67b7404af976d585ed6f12a76498fb3ee78bfdea6c63dc57d0690fedf715ed
3
+ metadata.gz: 9a76831cfb42b2de1ef560b649c69cc783b985f58b50a03db39f2f5a8606b5f7
4
+ data.tar.gz: f396576f559028c3c79ac1d476705602373932ea1d2f985ca0d734a3998754d2
5
5
  SHA512:
6
- metadata.gz: 59f317f81005ca77ca7be6a96cf32a198dffcdae77d902ac2574819cf86e3119598384b9d3de870db3a59050d5a7818161db7f8cf062fef0a2e5f03d9c866a97
7
- data.tar.gz: d5809868886625e7c8b7884fd6f6b0e4a29ee7106e1e54ef56291ee27be307cd4126e29aac2dfc2c74aa0c0a946d92c9e1d3b0826d371c99c15c3acc3771c423
6
+ metadata.gz: b1eb9f5f0048c2a56b1728c5b90720ef147699cb5657ab46b9d1178b0749c5398d4d3cbc9e2cd36e7cc8968559af520c0e58857c4444732c8dabfd64b9f8683d
7
+ data.tar.gz: 51a936d12c44ba7166b505445a5fee7264793ff03cec1a2961b6bf3d4356d9c9667398dbab7e47596e662f86d696fd042d35dc611b6ccad62cd2407c1c7e80e5
@@ -30,5 +30,38 @@ module DTRCore
30
30
  functions == other.functions &&
31
31
  user_defined_types == other.user_defined_types
32
32
  end
33
+
34
+ def to_s
35
+ return_string = ''
36
+
37
+ return_string += name_to_s
38
+ return_string += "#{state_to_s}\n"
39
+ return_string += functions_to_s
40
+ return_string += user_defined_types_to_s
41
+
42
+ return_string
43
+ end
44
+
45
+ private
46
+
47
+ def name_to_s
48
+ "[Contract]: #{@name}\n\n"
49
+ end
50
+
51
+ def state_to_s
52
+ return '' if @state.nil?
53
+
54
+ "[State]:\n#{@state&.map(&:to_s)&.join("\n")}\n"
55
+ end
56
+
57
+ def functions_to_s
58
+ "[InternalFunctions]:\n#{@functions&.map(&:to_s)&.join("\n")}\n:[InternalFunctions]\n"
59
+ end
60
+
61
+ def user_defined_types_to_s
62
+ return "[UserDefinedTypes]::[UserDefinedTypes]\n" if @user_defined_types.nil?
63
+
64
+ "[UserDefinedTypes]:\n#{@user_defined_types&.map(&:to_s)&.join("\n")}\n:[UserDefinedTypes]\n"
65
+ end
33
66
  end
34
67
  end
@@ -42,8 +42,51 @@ module DTRCore
42
42
  instructions == other.instructions
43
43
  end
44
44
 
45
+ def to_s
46
+ return_string = ''
47
+
48
+ return_string += name_to_s
49
+ return_string += inputs_to_s
50
+ return_string += output_to_s
51
+ return_string += instructions_to_s
52
+
53
+ return_string
54
+ end
55
+
45
56
  private
46
57
 
58
+ def name_to_s
59
+ " -() [#{name}]\n"
60
+ end
61
+
62
+ def inputs_to_s
63
+ input_formatted = inputs.map { |x| "#{x[:name]}: #{x[:type_name]}" }.join("\n ")
64
+ " * Inputs:\n {\n #{input_formatted}\n }\n"
65
+ end
66
+
67
+ def output_to_s
68
+ " * Output: #{output}\n"
69
+ end
70
+
71
+ def instructions_to_s
72
+ return_string = ''
73
+
74
+ return_string += " * Instructions:\n"
75
+ return_string += " $\n"
76
+ @instructions.each do |x|
77
+ return_string += " #{single_instruction_to_s(x)}\n"
78
+ end
79
+ return_string += " $\n"
80
+
81
+ return_string
82
+ end
83
+
84
+ def single_instruction_to_s(ins)
85
+ "{ instruction: #{ins[:instruction]}," \
86
+ "input: (#{ins[:inputs]&.join(', ')}), " \
87
+ "assign: #{ins[:assign]}, scope: #{ins[:scope]} }\n"
88
+ end
89
+
47
90
  def format_function_inputs(inputs)
48
91
  return [] if inputs.nil?
49
92
 
@@ -39,5 +39,11 @@ module DTRCore
39
39
  type == other.type &&
40
40
  initial_value == other.initial_value
41
41
  end
42
+
43
+ def to_s
44
+ " * [#{name}]\n " \
45
+ "* Type: #{type}\n " \
46
+ "* Initial Value: #{initial_value}"
47
+ end
42
48
  end
43
49
  end
@@ -40,6 +40,12 @@ module DTRCore
40
40
  { name: 'add_and_assign',
41
41
  description: 'Add two things of unknown types together and then assign to the first one.',
42
42
  category: INSTRUCTION_CATEGORY_UNTYPED },
43
+ { name: 'subtract', description: 'Subtract two things of unknown types together.',
44
+ category: INSTRUCTION_CATEGORY_UNTYPED },
45
+ { name: 'divide', description: 'Divide two things of unknown types together.',
46
+ category: INSTRUCTION_CATEGORY_UNTYPED },
47
+ { name: 'multiply', description: 'Multiply two things of unknown types together.',
48
+ category: INSTRUCTION_CATEGORY_UNTYPED },
43
49
  # numeric operations
44
50
  { name: 'add_numbers', description: 'Add two numbers.', category: INSTRUCTION_CATEGORY_NUMERIC },
45
51
  { name: 'subtract_numbers', description: 'Subtract two numbers.', category: INSTRUCTION_CATEGORY_NUMERIC },
@@ -57,8 +63,10 @@ module DTRCore
57
63
  { name: 'field', description: 'Reference an object field.', category: INSTRUCTION_CATEGORY_OBJECTS },
58
64
  { name: 'initialize_udt', description: 'Instantiate UDT object.', category: INSTRUCTION_CATEGORY_OBJECTS },
59
65
  # conditional operations
60
- { name: 'conditional_jump', description: 'Jump to a label if first input is true.', category: INSTRUCTION_CATEGORY_CONDITIONAL },
61
- { name: 'unconditional_jump', description: 'Jump to a no matter what.', category: INSTRUCTION_CATEGORY_CONDITIONAL },
66
+ { name: 'conditional_jump', description: 'Jump to a label if first input is true.',
67
+ category: INSTRUCTION_CATEGORY_CONDITIONAL },
68
+ { name: 'unconditional_jump', description: 'Jump to a no matter what.',
69
+ category: INSTRUCTION_CATEGORY_CONDITIONAL },
62
70
  # logical operations
63
71
  { name: 'and', description: 'Logical AND.', category: INSTRUCTION_CATEGORY_LOGICAL },
64
72
  { name: 'or', description: 'Logical OR.', category: INSTRUCTION_CATEGORY_LOGICAL }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtr_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.4
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-04 00:00:00.000000000 Z
11
+ date: 2024-06-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Core smart contract intermediate language (Digicus Textual Representation)
14
14
  parser.