dtr_core 0.6.0 → 0.6.2
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/instruction_validator.rb +6 -14
- data/lib/dtr_core/supported_attributes.rb +62 -67
- data/lib/dtr_core/type_validator.rb +10 -0
- 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: 149908b637a12363b2de8ef8432c5348bb303756bf619e09ecd3530ca070973d
|
4
|
+
data.tar.gz: a4d642766c5e1bc759e87520de1f35288b6ef6920409a15238a4cdde60040a78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d81497276755f5d3921c40256864936be3d2b105091bf268a7f483e183668cb959c14d386672d8aad1118c1fc0c6564589893564e6eab203eadf4ac17f9ce62
|
7
|
+
data.tar.gz: 83771252da2ebc9d7cbdd15315aeaae226044de99be1cae842dc237db22cded37e027196f6eb57135fa34a67757dd451cf2de4bd53ff0e3e846d795248d99209
|
@@ -19,21 +19,17 @@ module DTRCore
|
|
19
19
|
return false unless scope_valid?
|
20
20
|
|
21
21
|
case @instruction.instruction
|
22
|
-
when 'assign', 'evaluate', '
|
22
|
+
when 'assign', 'evaluate', 'print'
|
23
23
|
validate_basic_operation!
|
24
24
|
when 'exit_with_message', 'return'
|
25
25
|
validate_terminating_operation!
|
26
26
|
when 'and', 'or'
|
27
27
|
validate_logical_operation!
|
28
|
-
when '
|
29
|
-
|
30
|
-
when '
|
31
|
-
validate_smart_contract_specific_operation!
|
32
|
-
when 'create_dictionary', 'create_list', 'create_range', 'create_tuple',
|
33
|
-
'field', 'initialize_udt'
|
28
|
+
when 'goto', 'jump', 'end_of_iteration_check', 'label'
|
29
|
+
validate_control_flow_operation!
|
30
|
+
when 'field', 'instantiate_object'
|
34
31
|
validate_object_operation!
|
35
|
-
when 'add', 'subtract', 'multiply', 'divide'
|
36
|
-
'add_and_assign', 'subtract_and_assign', 'multiply_and_assign', 'divide_and_assign'
|
32
|
+
when 'add', 'subtract', 'multiply', 'divide'
|
37
33
|
validate_binary_operation!
|
38
34
|
else
|
39
35
|
false
|
@@ -66,11 +62,7 @@ module DTRCore
|
|
66
62
|
@instruction.inputs&.length == 2
|
67
63
|
end
|
68
64
|
|
69
|
-
def
|
70
|
-
true
|
71
|
-
end
|
72
|
-
|
73
|
-
def validate_smart_contract_specific_operation!
|
65
|
+
def validate_control_flow_operation!
|
74
66
|
true
|
75
67
|
end
|
76
68
|
|
@@ -1,86 +1,81 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Layout/LineLength
|
3
4
|
module DTRCore
|
4
5
|
module SupportedAttributes
|
5
6
|
# Supported Instructions for DTR.
|
6
7
|
## Instruction Categories ##
|
7
8
|
INSTRUCTION_CATEGORY_BASIC = 'basic'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
INSTRUCTION_CATEGORY_STRING = 'string'
|
12
|
-
INSTRUCTION_CATEGORY_ENVIRONMENT = 'environment'
|
13
|
-
INSTRUCTION_CATEGORY_METHODS = 'methods'
|
14
|
-
INSTRUCTION_CATEGORY_OBJECTS = 'objects'
|
15
|
-
INSTRUCTION_CATEGORY_CONDITIONAL = 'conditional'
|
9
|
+
INSTRUCTION_CATEGORY_BINARY = 'binary'
|
10
|
+
INSTRUCTION_CATEGORY_CONTROL_FLOW = 'control_flow'
|
11
|
+
INSTRUCTION_CATEGORY_TERMINATING = 'terminating'
|
16
12
|
INSTRUCTION_CATEGORY_LOGICAL = 'logical'
|
13
|
+
INSTRUCTION_CATEGORY_OBJECT = 'object'
|
17
14
|
INSTRUCTION_CATEGORIES = [
|
18
15
|
INSTRUCTION_CATEGORY_BASIC,
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
INSTRUCTION_CATEGORY_METHODS,
|
25
|
-
INSTRUCTION_CATEGORY_OBJECTS,
|
26
|
-
INSTRUCTION_CATEGORY_CONDITIONAL,
|
27
|
-
INSTRUCTION_CATEGORY_LOGICAL
|
16
|
+
INSTRUCTION_CATEGORY_BINARY,
|
17
|
+
INSTRUCTION_CATEGORY_CONTROL_FLOW,
|
18
|
+
INSTRUCTION_CATEGORY_TERMINATING,
|
19
|
+
INSTRUCTION_CATEGORY_LOGICAL,
|
20
|
+
INSTRUCTION_CATEGORY_OBJECT
|
28
21
|
].freeze
|
29
22
|
## Instructions ##
|
30
23
|
INSTRUCTIONS = [
|
31
|
-
|
32
|
-
|
33
|
-
{ name: '
|
34
|
-
|
35
|
-
{ name: '
|
36
|
-
|
37
|
-
|
38
|
-
{ name: '
|
39
|
-
category:
|
40
|
-
{ name: '
|
41
|
-
category:
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
{ name: '
|
46
|
-
category:
|
47
|
-
|
48
|
-
{ name: '
|
49
|
-
category:
|
50
|
-
|
51
|
-
|
52
|
-
{ name: '
|
53
|
-
|
54
|
-
{ name: '
|
55
|
-
category:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
{ name: '
|
60
|
-
|
24
|
+
{ name: 'assign', description: 'given some input value, assign to ASSIGN_NAME',
|
25
|
+
category: INSTRUCTION_CATEGORY_BASIC },
|
26
|
+
{ name: 'evaluate',
|
27
|
+
description: 'given a method name and 0 or more inputs, execute method. At this time, evaluate is a fairly loose catch-all for not explicitly defined operations', category: INSTRUCTION_CATEGORY_BASIC },
|
28
|
+
{ name: 'print', description: 'given some value, print it to standard out',
|
29
|
+
category: INSTRUCTION_CATEGORY_BASIC },
|
30
|
+
|
31
|
+
{ name: 'exit_with_message', description: 'immediately end execution, returning message',
|
32
|
+
category: INSTRUCTION_CATEGORY_TERMINATING },
|
33
|
+
{ name: 'return', description: 'return from function with input value',
|
34
|
+
category: INSTRUCTION_CATEGORY_TERMINATING },
|
35
|
+
|
36
|
+
{ name: 'and', description: 'lassign to ASSIGN_NAME result of “and-ing” two values',
|
37
|
+
category: INSTRUCTION_CATEGORY_LOGICAL },
|
38
|
+
{ name: 'or', description: 'assign to ASSIGN_NAME result of “or-ing” two values',
|
39
|
+
category: INSTRUCTION_CATEGORY_LOGICAL },
|
40
|
+
|
41
|
+
{ name: 'goto',
|
42
|
+
description: 'conditional if two inputs. In this case, first input is the condition to evaluate. If that is true, or there is only one input, move in code to the first input (a label name)', category: INSTRUCTION_CATEGORY_CONTROL_FLOW },
|
43
|
+
{ name: 'jump',
|
44
|
+
description: 'conditional if two inputs. In this case, first input is the condition to evaluate. If that is true, or there is only one input, jump to scope level', category: INSTRUCTION_CATEGORY_CONTROL_FLOW },
|
45
|
+
{ name: 'end_of_iteration_check',
|
46
|
+
description: 'check on input to see if at end of iteration. Return result to ASSIGN_NAME', category: INSTRUCTION_CATEGORY_CONTROL_FLOW },
|
47
|
+
{ name: 'label', description: 'a named location within the instruction set for a given function',
|
48
|
+
category: INSTRUCTION_CATEGORY_CONTROL_FLOW },
|
49
|
+
|
50
|
+
{ name: 'field', description: 'access a field on an object and assign result to ASSIGN_NAME',
|
51
|
+
category: INSTRUCTION_CATEGORY_OBJECT },
|
52
|
+
{ name: 'instantiate_object',
|
53
|
+
description: 'initialize an object by first passing in the type of object and the passing in each initial values for its fields. Supported types here include: Dictionary, List, Range, Tuple, and UDT. For UDTs, the second input is the name of the UDT.', category: INSTRUCTION_CATEGORY_OBJECT },
|
54
|
+
|
55
|
+
{ name: 'add', description: 'assign to ASSIGN_NAME result of adding two value',
|
56
|
+
category: INSTRUCTION_CATEGORY_BINARY },
|
57
|
+
{ name: 'subtract', description: 'assign to ASSIGN_NAME result of subtracting two value',
|
58
|
+
category: INSTRUCTION_CATEGORY_BINARY },
|
59
|
+
{ name: 'multiply', description: 'assign to ASSIGN_NAME result of multiplying two value',
|
60
|
+
category: INSTRUCTION_CATEGORY_BINARY },
|
61
|
+
{ name: 'divide', description: 'assign to ASSIGN_NAME result of dividing two value',
|
62
|
+
category: INSTRUCTION_CATEGORY_BINARY }
|
61
63
|
].freeze
|
62
64
|
|
63
65
|
# Supported Types for DTR.
|
64
|
-
TYPES = [
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
'i64',
|
77
|
-
'BigInteger',
|
78
|
-
'BigInteger',
|
79
|
-
## unsigned
|
80
|
-
'Integer',
|
81
|
-
'Integer',
|
82
|
-
'u128',
|
83
|
-
'BigInteger'
|
66
|
+
TYPES = %w[
|
67
|
+
Dictionary
|
68
|
+
List
|
69
|
+
Range
|
70
|
+
Tuple
|
71
|
+
UDT
|
72
|
+
Address
|
73
|
+
BigInteger
|
74
|
+
Boolean
|
75
|
+
Float
|
76
|
+
Integer
|
77
|
+
String
|
84
78
|
].freeze
|
85
79
|
end
|
86
80
|
end
|
81
|
+
# rubocop:enable Layout/LineLength
|
@@ -18,6 +18,7 @@ module DTRCore
|
|
18
18
|
return validate_integer! if %w[Integer BigInteger Float].include?(@type_name)
|
19
19
|
return validate_string! if ['String'].include?(@type_name)
|
20
20
|
return validate_address! if ['Address'].include?(@type_name)
|
21
|
+
return validate_boolean! if ['Boolean'].include?(@type_name)
|
21
22
|
|
22
23
|
raise 'Missing Invalid Type Name.'
|
23
24
|
end
|
@@ -45,6 +46,15 @@ module DTRCore
|
|
45
46
|
@initial_value.strip
|
46
47
|
end
|
47
48
|
|
49
|
+
def validate_boolean!
|
50
|
+
unless %w[true
|
51
|
+
false].include?(@initial_value)
|
52
|
+
raise "Invalid initial value for Boolean: #{@initial_value}. Wrong type."
|
53
|
+
end
|
54
|
+
|
55
|
+
@initial_value == 'true'
|
56
|
+
end
|
57
|
+
|
48
58
|
def validate_integer!
|
49
59
|
unless @initial_value =~ (/^[\-\.\d]\d*(\.?\d*)*/)
|
50
60
|
raise "Invalid initial value for #{@type_name}: #{@initial_value}. Wrong type."
|
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.6.
|
4
|
+
version: 0.6.2
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Core smart contract intermediate language (Digicus Textual Representation)
|
14
14
|
parser.
|