dtr_core 0.5.3 → 0.5.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a3cdffbc86ae587c123fbdd733fd4d1a8d9324607b0e5b34b62ccb514e39ac4
4
- data.tar.gz: ca444a8b6ac9dd07877d5aff7815c1817ae22e621da932c5ccad7f34d9bbc9c9
3
+ metadata.gz: 9a76831cfb42b2de1ef560b649c69cc783b985f58b50a03db39f2f5a8606b5f7
4
+ data.tar.gz: f396576f559028c3c79ac1d476705602373932ea1d2f985ca0d734a3998754d2
5
5
  SHA512:
6
- metadata.gz: 291a726b8b9f8d7986f400f6394cb812913c4b2018edec5f8cf84b4cef7322aac6ce73a814811f630373a5f6dbc90111b55d9089ed4fbad57d7e14baeb5e5c70
7
- data.tar.gz: 8e8b1a022bff07ff1f67a50d51f9cb16c3ca34479b1e1f449ab0ca2cf7da6c48b9699e0693c4be251301ff1c003ed8ab16ace9a67862a5c18b3be76d7e4453e2
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,9 +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.', category: INSTRUCTION_CATEGORY_UNTYPED },
44
- { name: 'divide', description: 'Divide two things of unknown types together.', category: INSTRUCTION_CATEGORY_UNTYPED },
45
- { name: 'multiply', description: 'Multiply two things of unknown types together.', 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 },
46
49
  # numeric operations
47
50
  { name: 'add_numbers', description: 'Add two numbers.', category: INSTRUCTION_CATEGORY_NUMERIC },
48
51
  { name: 'subtract_numbers', description: 'Subtract two numbers.', category: INSTRUCTION_CATEGORY_NUMERIC },
@@ -60,8 +63,10 @@ module DTRCore
60
63
  { name: 'field', description: 'Reference an object field.', category: INSTRUCTION_CATEGORY_OBJECTS },
61
64
  { name: 'initialize_udt', description: 'Instantiate UDT object.', category: INSTRUCTION_CATEGORY_OBJECTS },
62
65
  # conditional operations
63
- { name: 'conditional_jump', description: 'Jump to a label if first input is true.', category: INSTRUCTION_CATEGORY_CONDITIONAL },
64
- { 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 },
65
70
  # logical operations
66
71
  { name: 'and', description: 'Logical AND.', category: INSTRUCTION_CATEGORY_LOGICAL },
67
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.3
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.