dtr_core 0.5.3 → 0.5.5

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: 6a3cdffbc86ae587c123fbdd733fd4d1a8d9324607b0e5b34b62ccb514e39ac4
4
- data.tar.gz: ca444a8b6ac9dd07877d5aff7815c1817ae22e621da932c5ccad7f34d9bbc9c9
3
+ metadata.gz: 7f2532733cf1e168515e9cdec00a88684c5d534756601e4cfe10bef04b2b3827
4
+ data.tar.gz: a24631443b4901a28b40ee2501e79da8285ba1ea2d8ab05da5b07b9b6e2732c0
5
5
  SHA512:
6
- metadata.gz: 291a726b8b9f8d7986f400f6394cb812913c4b2018edec5f8cf84b4cef7322aac6ce73a814811f630373a5f6dbc90111b55d9089ed4fbad57d7e14baeb5e5c70
7
- data.tar.gz: 8e8b1a022bff07ff1f67a50d51f9cb16c3ca34479b1e1f449ab0ca2cf7da6c48b9699e0693c4be251301ff1c003ed8ab16ace9a67862a5c18b3be76d7e4453e2
6
+ metadata.gz: 9956bb9b4ea3cded63827a4b4635b9f5225fdd8caaf2f49ba28034fe0097f89ef6b133554ec7b8e40444fe6a8931cec526dd7003506970e21ae0071fe67cd2ad
7
+ data.tar.gz: fd7c1316e1ca388fe920ac81dd5275e5b4cc529b0d8aa89af60578c7728a2513facb400be19be863e0a0e0b4ec917ac983759d560e8da2d9cc281727e84ded29
@@ -30,5 +30,40 @@ 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
+ return '' if @state.nil?
59
+
60
+ "[InternalFunctions]:\n#{@functions&.map(&:to_s)&.join("\n")}\n:[InternalFunctions]\n"
61
+ end
62
+
63
+ def user_defined_types_to_s
64
+ return '' if @user_defined_types.nil?
65
+
66
+ "[UserDefinedTypes]:\n#{@user_defined_types&.map(&:to_s)&.join("\n")}\n:[UserDefinedTypes]\n"
67
+ end
33
68
  end
34
69
  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.5
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.