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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daf7d4ee7b08b952fd8fe687e0dd6edbfa09bd576d35cb1b50d24528a411dc2b
4
- data.tar.gz: d65462fe604c303f6be6317170582ee0e98bc2ccc459cdde0b2dbd8cf5024e23
3
+ metadata.gz: 149908b637a12363b2de8ef8432c5348bb303756bf619e09ecd3530ca070973d
4
+ data.tar.gz: a4d642766c5e1bc759e87520de1f35288b6ef6920409a15238a4cdde60040a78
5
5
  SHA512:
6
- metadata.gz: 014bd2182a685a04e2acf4349055431102fd48a96f4a0a8928603279af66f4059175d8fe7ed8f9c39d93c8e0388e5e41ca0417ab0539b693e67621f59bab0c78
7
- data.tar.gz: a650d2cb77f65292991eabe585d771a0a797b26cab9c30f5b46cb34137365499edb02c80235388240d982c9c1825bdd0fa2d78207b67e77aa49c19b0a1d92144
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', 'log_string'
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 'conditional_goto', 'conditional_jump', 'end_of_iteration_check', 'label', 'unconditional_goto', 'unconditional_jump'
29
- validate_unconditional_jump_operation!
30
- when 'contract_address'
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 validate_unconditional_jump_operation!
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
- INSTRUCTION_CATEGORY_STATE = 'state'
9
- INSTRUCTION_CATEGORY_UNTYPED = 'untyped'
10
- INSTRUCTION_CATEGORY_NUMERIC = 'numeric'
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
- INSTRUCTION_CATEGORY_STATE,
20
- INSTRUCTION_CATEGORY_UNTYPED,
21
- INSTRUCTION_CATEGORY_NUMERIC,
22
- INSTRUCTION_CATEGORY_STRING,
23
- INSTRUCTION_CATEGORY_ENVIRONMENT,
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
- # basic operations
32
- { name: 'return', description: 'return a value from a function.', category: INSTRUCTION_CATEGORY_BASIC },
33
- { name: 'assign', description: 'Assign a value to a variable.', category: INSTRUCTION_CATEGORY_BASIC },
34
- { name: 'panic', description: 'Exit, quickly, and loudly.', category: INSTRUCTION_CATEGORY_BASIC },
35
- { name: 'save_state', description: 'Save a value to the state.', category: INSTRUCTION_CATEGORY_STATE },
36
- # untyped operations
37
- { name: 'add', description: 'Add two things of unknown types together.', category: INSTRUCTION_CATEGORY_UNTYPED },
38
- { name: 'subtract', description: 'Subtract two things of unknown types together.',
39
- category: INSTRUCTION_CATEGORY_UNTYPED },
40
- { name: 'divide', description: 'Divide two things of unknown types together.',
41
- category: INSTRUCTION_CATEGORY_UNTYPED },
42
- { name: 'multiply', description: 'Multiply two things of unknown types together.',
43
- category: INSTRUCTION_CATEGORY_UNTYPED },
44
- # environment operations
45
- { name: 'contract_address', description: 'Get the contract address.',
46
- category: INSTRUCTION_CATEGORY_ENVIRONMENT },
47
- # method operations
48
- { name: 'evaluate', description: 'Evaluate a method. Method name is the first input and arguments follow',
49
- category: INSTRUCTION_CATEGORY_METHODS },
50
- # object operations
51
- { name: 'field', description: 'Reference an object field.', category: INSTRUCTION_CATEGORY_OBJECTS },
52
- { name: 'initialize_udt', description: 'Instantiate UDT object.', category: INSTRUCTION_CATEGORY_OBJECTS },
53
- # conditional operations
54
- { name: 'conditional_unconditional_jump', description: 'unconditional_jump to a label if first input is true.',
55
- category: INSTRUCTION_CATEGORY_CONDITIONAL },
56
- { name: 'unconditional_unconditional_jump', description: 'unconditional_jump to a no matter what.',
57
- category: INSTRUCTION_CATEGORY_CONDITIONAL },
58
- # logical operations
59
- { name: 'and', description: 'Logical AND.', category: INSTRUCTION_CATEGORY_LOGICAL },
60
- { name: 'or', description: 'Logical OR.', category: INSTRUCTION_CATEGORY_LOGICAL }
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
- # basic types
66
- 'address',
67
- 'boolean',
68
- # string types
69
- 'String',
70
- # collection types
71
- 'array',
72
- 'map',
73
- # numeric types
74
- ## signed
75
- 'Integer',
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.0
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-16 00:00:00.000000000 Z
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.