tealrb 0.9.0 → 0.10.0
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/tealrb/contract.rb +11 -1
- data/lib/tealrb/rewriters.rb +18 -0
- data/lib/tealrb/scratch.rb +7 -3
- 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: 96c56f8bbc18ac1b7fa42f8ad6b553f72296c30a89973d1e95a663f6776c559c
         | 
| 4 | 
            +
              data.tar.gz: c7cd2a73fa00da112e0d420224955dc5a9b1a41a0ec23978250f48ac49a2fc59
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b93a01c924cefb65075160e306436b54a560f2ac5a40465a28dac436a589b252f71d2130dfe39f0f4cf127136223392a0fab9f013acc01c5c4161099732b8bfe
         | 
| 7 | 
            +
              data.tar.gz: 1316ccad828bf8a1682f55987dbffaa9dee942f3e11dfe04d54c31432143732b93de31d6c4bed596509a92e3744a667716acc4cae8b326793efd263d6c1e9354
         | 
    
        data/lib/tealrb/contract.rb
    CHANGED
    
    | @@ -90,12 +90,18 @@ module TEALrb | |
| 90 90 | 
             
                  end
         | 
| 91 91 | 
             
                end
         | 
| 92 92 |  | 
| 93 | 
            +
                VOID_OPS = %w[assert err return app_global_put b bnz bz store
         | 
| 94 | 
            +
                              stores app_local_put app_global_del app_local_del callsub retsub
         | 
| 95 | 
            +
                              log itxn_submit itxn_next].freeze
         | 
| 96 | 
            +
             | 
| 93 97 | 
             
                def teal_source
         | 
| 94 98 | 
             
                  teal_lines = []
         | 
| 95 99 |  | 
| 96 | 
            -
                  @teal. | 
| 100 | 
            +
                  @teal.each_with_index do |line, i|
         | 
| 97 101 | 
             
                    ln = line.strip
         | 
| 98 102 |  | 
| 103 | 
            +
                    teal_lines << '' if VOID_OPS.include? @teal[i - 1][/\S+/]
         | 
| 104 | 
            +
             | 
| 99 105 | 
             
                    if (ln[%r{\S+:($| //)}] && !ln[/^if\d+/]) || ln == 'b main' || ln[/^#/]
         | 
| 100 106 | 
             
                      teal_lines << ln
         | 
| 101 107 | 
             
                    elsif ln == 'retsub'
         | 
| @@ -106,6 +112,10 @@ module TEALrb | |
| 106 112 | 
             
                    end
         | 
| 107 113 | 
             
                  end
         | 
| 108 114 |  | 
| 115 | 
            +
                  teal_lines.delete_if.with_index do |t, i|
         | 
| 116 | 
            +
                    t.empty? && teal_lines[i - 1].empty?
         | 
| 117 | 
            +
                  end
         | 
| 118 | 
            +
             | 
| 109 119 | 
             
                  teal_lines.join("\n")
         | 
| 110 120 | 
             
                end
         | 
| 111 121 |  | 
    
        data/lib/tealrb/rewriters.rb
    CHANGED
    
    | @@ -69,6 +69,24 @@ module TEALrb | |
| 69 69 | 
             
                    insert_after(node.loc.name, '.call') unless ['@teal_methods', '@subroutines', '@scratch'].include? node.source
         | 
| 70 70 | 
             
                    super
         | 
| 71 71 | 
             
                  end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  def on_gvasgn(node)
         | 
| 74 | 
            +
                    unless RuboCop::Cop::Style::GlobalVars::BUILT_IN_VARS.include? node.loc.name.source.to_sym
         | 
| 75 | 
            +
                      var_name = node.loc.name.source[1..]
         | 
| 76 | 
            +
                      replace(node.loc.name, "@scratch[:#{var_name}]")
         | 
| 77 | 
            +
                    end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                    super
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                  def on_gvar(node)
         | 
| 83 | 
            +
                    unless RuboCop::Cop::Style::GlobalVars::BUILT_IN_VARS.include? node.loc.name.source.to_sym
         | 
| 84 | 
            +
                      var_name = node.loc.name.source[1..]
         | 
| 85 | 
            +
                      replace(node.loc.name, "@scratch[:#{var_name}]")
         | 
| 86 | 
            +
                    end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                    super
         | 
| 89 | 
            +
                  end
         | 
| 72 90 | 
             
                end
         | 
| 73 91 |  | 
| 74 92 | 
             
                class ComparisonRewriter < Rewriter
         | 
    
        data/lib/tealrb/scratch.rb
    CHANGED
    
    | @@ -5,21 +5,25 @@ module TEALrb | |
| 5 5 | 
             
                def initialize
         | 
| 6 6 | 
             
                  @open_slots = (0..256).to_a
         | 
| 7 7 | 
             
                  @named_slots = {}
         | 
| 8 | 
            +
                  @values = {}
         | 
| 8 9 | 
             
                end
         | 
| 9 10 |  | 
| 10 11 | 
             
                def [](key)
         | 
| 11 12 | 
             
                  TEAL.instance << "load #{@named_slots[key]} // #{key}"
         | 
| 13 | 
            +
                  @values[key]
         | 
| 12 14 | 
             
                end
         | 
| 13 15 |  | 
| 14 | 
            -
                def []=(key,  | 
| 15 | 
            -
                  store(key)
         | 
| 16 | 
            +
                def []=(key, value)
         | 
| 17 | 
            +
                  store(key, value)
         | 
| 16 18 | 
             
                end
         | 
| 17 19 |  | 
| 18 | 
            -
                def store(key)
         | 
| 20 | 
            +
                def store(key, value = TEAL.instance)
         | 
| 21 | 
            +
                  @values[key] = value
         | 
| 19 22 | 
             
                  TEAL.instance << "store #{@named_slots[key] ||= @open_slots.shift} // #{key}"
         | 
| 20 23 | 
             
                end
         | 
| 21 24 |  | 
| 22 25 | 
             
                def delete(key)
         | 
| 26 | 
            +
                  @values.delete(key)
         | 
| 23 27 | 
             
                  @open_slots << @named_slots.delete(key)
         | 
| 24 28 | 
             
                end
         | 
| 25 29 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: tealrb
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.10.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Joe Polny
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022-09- | 
| 11 | 
            +
            date: 2022-09-13 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: method_source
         |