dtr_core 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dtr_core/contract.rb +33 -0
- data/lib/dtr_core/function.rb +43 -0
- data/lib/dtr_core/state.rb +6 -0
- data/lib/dtr_core/supported_attributes.rb +10 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a76831cfb42b2de1ef560b649c69cc783b985f58b50a03db39f2f5a8606b5f7
|
4
|
+
data.tar.gz: f396576f559028c3c79ac1d476705602373932ea1d2f985ca0d734a3998754d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1eb9f5f0048c2a56b1728c5b90720ef147699cb5657ab46b9d1178b0749c5398d4d3cbc9e2cd36e7cc8968559af520c0e58857c4444732c8dabfd64b9f8683d
|
7
|
+
data.tar.gz: 51a936d12c44ba7166b505445a5fee7264793ff03cec1a2961b6bf3d4356d9c9667398dbab7e47596e662f86d696fd042d35dc611b6ccad62cd2407c1c7e80e5
|
data/lib/dtr_core/contract.rb
CHANGED
@@ -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
|
data/lib/dtr_core/function.rb
CHANGED
@@ -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
|
|
data/lib/dtr_core/state.rb
CHANGED
@@ -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.',
|
44
|
-
|
45
|
-
{ name: '
|
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.',
|
64
|
-
|
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.
|
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-
|
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.
|