dtr_core 0.5.3 → 0.5.5
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 +4 -4
 - data/lib/dtr_core/contract.rb +35 -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: 7f2532733cf1e168515e9cdec00a88684c5d534756601e4cfe10bef04b2b3827
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a24631443b4901a28b40ee2501e79da8285ba1ea2d8ab05da5b07b9b6e2732c0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 9956bb9b4ea3cded63827a4b4635b9f5225fdd8caaf2f49ba28034fe0097f89ef6b133554ec7b8e40444fe6a8931cec526dd7003506970e21ae0071fe67cd2ad
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: fd7c1316e1ca388fe920ac81dd5275e5b4cc529b0d8aa89af60578c7728a2513facb400be19be863e0a0e0b4ec917ac983759d560e8da2d9cc281727e84ded29
         
     | 
    
        data/lib/dtr_core/contract.rb
    CHANGED
    
    | 
         @@ -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
         
     | 
    
        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.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- 
     | 
| 
      
 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.
         
     |