kanayago 0.1.1 → 0.2.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/.rubocop.yml +12 -0
 - data/.ruby-version +1 -0
 - data/README.md +20 -29
 - data/Rakefile +43 -96
 - data/ext/kanayago/extconf.rb +6 -0
 - data/ext/kanayago/id.h +12 -5
 - data/ext/kanayago/id_table.h +15 -0
 - data/ext/kanayago/include/ruby/st.h +199 -0
 - data/ext/kanayago/internal/array.h +3 -0
 - data/ext/kanayago/internal/basic_operators.h +1 -0
 - data/ext/kanayago/internal/bignum.h +1 -0
 - data/ext/kanayago/internal/bits.h +82 -0
 - data/ext/kanayago/internal/encoding.h +4 -1
 - data/ext/kanayago/internal/error.h +33 -0
 - data/ext/kanayago/internal/fixnum.h +1 -0
 - data/ext/kanayago/internal/gc.h +47 -11
 - data/ext/kanayago/internal/hash.h +3 -0
 - data/ext/kanayago/internal/imemo.h +93 -32
 - data/ext/kanayago/internal/io.h +30 -7
 - data/ext/kanayago/internal/namespace.h +81 -0
 - data/ext/kanayago/internal/numeric.h +1 -0
 - data/ext/kanayago/internal/parse.h +17 -3
 - data/ext/kanayago/internal/re.h +7 -2
 - data/ext/kanayago/internal/sanitizers.h +88 -39
 - data/ext/kanayago/internal/set_table.h +70 -0
 - data/ext/kanayago/internal/string.h +33 -16
 - data/ext/kanayago/internal/symbol.h +4 -3
 - data/ext/kanayago/internal/thread.h +42 -9
 - data/ext/kanayago/internal/variable.h +13 -11
 - data/ext/kanayago/internal/vm.h +4 -5
 - data/ext/kanayago/internal.h +0 -3
 - data/ext/kanayago/kanayago.c +554 -235
 - data/ext/kanayago/kanayago.h +5 -0
 - data/ext/kanayago/literal_node.c +343 -0
 - data/ext/kanayago/literal_node.h +30 -0
 - data/ext/kanayago/method.h +18 -2
 - data/ext/kanayago/node.c +7 -1
 - data/ext/kanayago/node.h +14 -3
 - data/ext/kanayago/parse.c +7602 -7156
 - data/ext/kanayago/parse.h +39 -39
 - data/ext/kanayago/parser_st.c +2 -1
 - data/ext/kanayago/pattern_node.c +78 -0
 - data/ext/kanayago/pattern_node.h +13 -0
 - data/ext/kanayago/ruby_atomic.h +43 -0
 - data/ext/kanayago/ruby_parser.c +7 -35
 - data/ext/kanayago/rubyparser.h +83 -80
 - data/ext/kanayago/scope_node.c +34 -0
 - data/ext/kanayago/scope_node.h +8 -0
 - data/ext/kanayago/shape.h +321 -111
 - data/ext/kanayago/st.c +905 -21
 - data/ext/kanayago/statement_node.c +795 -0
 - data/ext/kanayago/statement_node.h +66 -0
 - data/ext/kanayago/string_node.c +192 -0
 - data/ext/kanayago/string_node.h +19 -0
 - data/ext/kanayago/symbol.h +2 -9
 - data/ext/kanayago/thread_pthread.h +10 -3
 - data/ext/kanayago/universal_parser.c +1 -20
 - data/ext/kanayago/variable_node.c +72 -0
 - data/ext/kanayago/variable_node.h +12 -0
 - data/ext/kanayago/vm_core.h +205 -71
 - data/lib/kanayago/literal_node.rb +87 -0
 - data/lib/kanayago/pattern_node.rb +19 -0
 - data/lib/kanayago/statement_node.rb +222 -0
 - data/lib/kanayago/string_node.rb +43 -0
 - data/lib/kanayago/variable_node.rb +23 -0
 - data/lib/kanayago/version.rb +1 -1
 - data/lib/kanayago.rb +22 -0
 - data/patch/3.4/copy_target.rb +78 -0
 - data/patch/3.4/kanayago.patch +162 -0
 - data/patch/head/copy_target.rb +84 -0
 - data/patch/head/kanayago.patch +162 -0
 - data/sample/minitest_generator.rb +266 -0
 - data/sample/test_generator.rb +272 -0
 - data/typeprof.conf.json +9 -0
 - metadata +32 -4
 - data/ext/kanayago/parse.tmp.y +0 -16145
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 6b8dcde5a49288a284edf3323cc0279740a923e0ea85d895571dcfa1be774970
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5c7bf5ef11155f14e6b8f2049bd344228c10089cb430b4d4c453a7b02e94bdb5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ce3d04f88db918e619f94195b2ca33cae122466b502a56df3e399acfadc7e4ed193ff045b0d12e326ff2fbeb4435587ce75507a02c7a1185c4f3a0290f7d3935
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0a3981c9eae87d6fd12ff320a3f3d8759c78830b2936569c604e7c1c82ca614f2ba07c2d1e97b2c765c81ed4eb0b7e63424af75e8342320c8bc0134fb69aa3b5
         
     | 
    
        data/.rubocop.yml
    CHANGED
    
    | 
         @@ -1,13 +1,25 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            inherit_from: .rubocop_todo.yml
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            AllCops:
         
     | 
| 
      
 4 
     | 
    
         
            +
              NewCops: enable
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       3 
6 
     | 
    
         
             
            Metrics/BlockLength:
         
     | 
| 
       4 
7 
     | 
    
         
             
              Exclude:
         
     | 
| 
       5 
8 
     | 
    
         
             
                - Rakefile
         
     | 
| 
       6 
9 
     | 
    
         
             
                - kanayago.gemspec
         
     | 
| 
       7 
10 
     | 
    
         | 
| 
      
 11 
     | 
    
         
            +
            Metrics/AbcSize:
         
     | 
| 
      
 12 
     | 
    
         
            +
              Enabled: false
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            Minitest/MultipleAssertions:
         
     | 
| 
      
 15 
     | 
    
         
            +
              Enabled: false
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       8 
17 
     | 
    
         
             
            RBS:
         
     | 
| 
       9 
18 
     | 
    
         
             
              Enabled: true
         
     | 
| 
       10 
19 
     | 
    
         | 
| 
      
 20 
     | 
    
         
            +
            Style/Documentation:
         
     | 
| 
      
 21 
     | 
    
         
            +
              Enabled: false
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       11 
23 
     | 
    
         
             
            require:
         
     | 
| 
       12 
24 
     | 
    
         
             
              - rubocop-minitest
         
     | 
| 
       13 
25 
     | 
    
         
             
              - rubocop-on-rbs
         
     | 
    
        data/.ruby-version
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ruby-dev
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,16 +1,21 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Kanayago
         
     | 
| 
      
 1 
     | 
    
         
            +
            # Kanayago(金屋子)
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            Trying to Make Ruby's Parser Available as a Gem.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            ##  
     | 
| 
      
 5 
     | 
    
         
            +
            ## Support Ruby version
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
            Kanayago(金屋子) is supported Ruby 3.4 or Ruby head.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 10 
     | 
    
         
            +
            ### From RubyGems
         
     | 
| 
       8 
11 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
            ```console
         
     | 
| 
       10 
     | 
    
         
            -
            RUBY_CONFIGURE_OPTS="cppflags=-DUNIVERSAL_PARSER" rbenv install ruby-dev
         
     | 
| 
       11 
12 
     | 
    
         
             
            ```
         
     | 
| 
      
 13 
     | 
    
         
            +
            gem install kanayago
         
     | 
| 
      
 14 
     | 
    
         
            +
            ```
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            ### Build and Install in local
         
     | 
| 
       12 
17 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
            First, clone this repository.
         
     | 
| 
       14 
19 
     | 
    
         | 
| 
       15 
20 
     | 
    
         
             
            ```console
         
     | 
| 
       16 
21 
     | 
    
         
             
            git clone https://github.com/S-H-GAMELINKS/kanayago.git
         
     | 
| 
         @@ -26,7 +31,7 @@ Finally, build `Kanayago` gem  and install it. 
     | 
|
| 
       26 
31 
     | 
    
         | 
| 
       27 
32 
     | 
    
         
             
            ```console
         
     | 
| 
       28 
33 
     | 
    
         
             
            bundle exec rake build
         
     | 
| 
       29 
     | 
    
         
            -
            gem install pkg/kanayago-0. 
     | 
| 
      
 34 
     | 
    
         
            +
            gem install pkg/kanayago-0.2.0.gem
         
     | 
| 
       30 
35 
     | 
    
         
             
            ```
         
     | 
| 
       31 
36 
     | 
    
         | 
| 
       32 
37 
     | 
    
         
             
            ## Usage
         
     | 
| 
         @@ -35,29 +40,15 @@ gem install pkg/kanayago-0.1.0.gem 
     | 
|
| 
       35 
40 
     | 
    
         
             
            require 'kanayago/kanayago'
         
     | 
| 
       36 
41 
     | 
    
         | 
| 
       37 
42 
     | 
    
         
             
            result = Kanayago.parse('117 + 117')
         
     | 
| 
      
 43 
     | 
    
         
            +
            # => #<Kanayago::ScopeNode:0x00007f522199c5a8>
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            p result.body
         
     | 
| 
      
 46 
     | 
    
         
            +
            # => #<Kanayago::OperatorCallNode:0x00007f5221b06358>
         
     | 
| 
       38 
47 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
            p result
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
            # 
     | 
| 
       42 
     | 
    
         
            -
            # 
     | 
| 
       43 
     | 
    
         
            -
            #    "args" => nil,
         
     | 
| 
       44 
     | 
    
         
            -
            #    "body" => {
         
     | 
| 
       45 
     | 
    
         
            -
            #      "NODE_OPCALL" => {
         
     | 
| 
       46 
     | 
    
         
            -
            #        "recv" => {
         
     | 
| 
       47 
     | 
    
         
            -
            #          "NODE_INTEGER" => 117
         
     | 
| 
       48 
     | 
    
         
            -
            #        },
         
     | 
| 
       49 
     | 
    
         
            -
            #        "mid" => :+,
         
     | 
| 
       50 
     | 
    
         
            -
            #        "args" => {
         
     | 
| 
       51 
     | 
    
         
            -
            #          "NODE_LIST" => [
         
     | 
| 
       52 
     | 
    
         
            -
            #            {
         
     | 
| 
       53 
     | 
    
         
            -
            #              "NODE_INTEGER"=>117
         
     | 
| 
       54 
     | 
    
         
            -
            #            }
         
     | 
| 
       55 
     | 
    
         
            -
            #          ]
         
     | 
| 
       56 
     | 
    
         
            -
            #        }
         
     | 
| 
       57 
     | 
    
         
            -
            #      }
         
     | 
| 
       58 
     | 
    
         
            -
            #    }
         
     | 
| 
       59 
     | 
    
         
            -
            #  }
         
     | 
| 
       60 
     | 
    
         
            -
            #}
         
     | 
| 
      
 48 
     | 
    
         
            +
            p result.body.recv
         
     | 
| 
      
 49 
     | 
    
         
            +
            p result.body.recv.val
         
     | 
| 
      
 50 
     | 
    
         
            +
            # => #<Kanayago::IntegerNode:0x00007f5221b06330>
         
     | 
| 
      
 51 
     | 
    
         
            +
            # => 117
         
     | 
| 
       61 
52 
     | 
    
         
             
            ```
         
     | 
| 
       62 
53 
     | 
    
         | 
| 
       63 
54 
     | 
    
         
             
            ## Development
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -7,95 +7,36 @@ require 'test_queue' 
     | 
|
| 
       7 
7 
     | 
    
         
             
            require 'test_queue/runner/minitest'
         
     | 
| 
       8 
8 
     | 
    
         
             
            require 'fileutils'
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
               
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              constant.h
         
     | 
| 
       16 
     | 
    
         
            -
              id_table.h
         
     | 
| 
       17 
     | 
    
         
            -
              internal/array.h
         
     | 
| 
       18 
     | 
    
         
            -
              internal/basic_operators.h
         
     | 
| 
       19 
     | 
    
         
            -
              internal/bignum.h
         
     | 
| 
       20 
     | 
    
         
            -
              internal/bits.h
         
     | 
| 
       21 
     | 
    
         
            -
              internal/compile.h
         
     | 
| 
       22 
     | 
    
         
            -
              internal/compilers.h
         
     | 
| 
       23 
     | 
    
         
            -
              internal/complex.h
         
     | 
| 
       24 
     | 
    
         
            -
              internal/encoding.h
         
     | 
| 
       25 
     | 
    
         
            -
              internal/error.h
         
     | 
| 
       26 
     | 
    
         
            -
              internal/fixnum.h
         
     | 
| 
       27 
     | 
    
         
            -
              internal/gc.h
         
     | 
| 
       28 
     | 
    
         
            -
              internal/hash.h
         
     | 
| 
       29 
     | 
    
         
            -
              internal/imemo.h
         
     | 
| 
       30 
     | 
    
         
            -
              internal/io.h
         
     | 
| 
       31 
     | 
    
         
            -
              internal/numeric.h
         
     | 
| 
       32 
     | 
    
         
            -
              internal/parse.h
         
     | 
| 
       33 
     | 
    
         
            -
              internal/rational.h
         
     | 
| 
       34 
     | 
    
         
            -
              internal/re.h
         
     | 
| 
       35 
     | 
    
         
            -
              internal/ruby_parser.h
         
     | 
| 
       36 
     | 
    
         
            -
              internal/sanitizers.h
         
     | 
| 
       37 
     | 
    
         
            -
              internal/serial.h
         
     | 
| 
       38 
     | 
    
         
            -
              internal/static_assert.h
         
     | 
| 
       39 
     | 
    
         
            -
              internal/string.h
         
     | 
| 
       40 
     | 
    
         
            -
              internal/symbol.h
         
     | 
| 
       41 
     | 
    
         
            -
              internal/thread.h
         
     | 
| 
       42 
     | 
    
         
            -
              internal/variable.h
         
     | 
| 
       43 
     | 
    
         
            -
              internal/warnings.h
         
     | 
| 
       44 
     | 
    
         
            -
              internal/vm.h
         
     | 
| 
       45 
     | 
    
         
            -
              internal.h
         
     | 
| 
       46 
     | 
    
         
            -
              method.h
         
     | 
| 
       47 
     | 
    
         
            -
              node.c
         
     | 
| 
       48 
     | 
    
         
            -
              node.h
         
     | 
| 
       49 
     | 
    
         
            -
              parse.y
         
     | 
| 
       50 
     | 
    
         
            -
              parser_bits.h
         
     | 
| 
       51 
     | 
    
         
            -
              parser_node.h
         
     | 
| 
       52 
     | 
    
         
            -
              parser_st.c
         
     | 
| 
       53 
     | 
    
         
            -
              parser_st.h
         
     | 
| 
       54 
     | 
    
         
            -
              parser_value.h
         
     | 
| 
       55 
     | 
    
         
            -
              ruby_assert.h
         
     | 
| 
       56 
     | 
    
         
            -
              ruby_atomic.h
         
     | 
| 
       57 
     | 
    
         
            -
              ruby_parser.c
         
     | 
| 
       58 
     | 
    
         
            -
              rubyparser.h
         
     | 
| 
       59 
     | 
    
         
            -
              shape.h
         
     | 
| 
       60 
     | 
    
         
            -
              st.c
         
     | 
| 
       61 
     | 
    
         
            -
              symbol.h
         
     | 
| 
       62 
     | 
    
         
            -
              thread_pthread.h
         
     | 
| 
       63 
     | 
    
         
            -
              universal_parser.c
         
     | 
| 
       64 
     | 
    
         
            -
              vm_core.h
         
     | 
| 
       65 
     | 
    
         
            -
              vm_opts.h
         
     | 
| 
       66 
     | 
    
         
            -
            ].freeze
         
     | 
| 
      
 10 
     | 
    
         
            +
            if RUBY_DESCRIPTION.include?('dev')
         
     | 
| 
      
 11 
     | 
    
         
            +
              require_relative 'patch/head/copy_target'
         
     | 
| 
      
 12 
     | 
    
         
            +
            else
         
     | 
| 
      
 13 
     | 
    
         
            +
              require_relative "patch/#{RUBY_VERSION[0..2]}/copy_target"
         
     | 
| 
      
 14 
     | 
    
         
            +
            end
         
     | 
| 
       67 
15 
     | 
    
         | 
| 
       68 
16 
     | 
    
         
             
            namespace :ruby_parser do
         
     | 
| 
       69 
17 
     | 
    
         
             
              desc 'import ruby parser files'
         
     | 
| 
       70 
18 
     | 
    
         
             
              task :import do
         
     | 
| 
       71 
     | 
    
         
            -
                 
     | 
| 
      
 19 
     | 
    
         
            +
                tar_name = if RUBY_DESCRIPTION.include?('dev')
         
     | 
| 
      
 20 
     | 
    
         
            +
                             'snapshot/snapshot-master.tar.gz'
         
     | 
| 
      
 21 
     | 
    
         
            +
                           else
         
     | 
| 
      
 22 
     | 
    
         
            +
                             "#{RUBY_VERSION[0..2]}/ruby-#{RUBY_VERSION}.tar.gz"
         
     | 
| 
      
 23 
     | 
    
         
            +
                           end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                `mkdir -p tmp/ruby`
         
     | 
| 
      
 26 
     | 
    
         
            +
                `curl -L https://cache.ruby-lang.org/pub/ruby/#{tar_name} -o tmp/ruby.tar.gz`
         
     | 
| 
      
 27 
     | 
    
         
            +
                `tar -zxvf tmp/ruby.tar.gz -C tmp/ruby --strip-components 1`
         
     | 
| 
       72 
28 
     | 
    
         | 
| 
       73 
29 
     | 
    
         
             
                dist = File.expand_path('ext/kanayago', __dir__)
         
     | 
| 
       74 
30 
     | 
    
         
             
                ruby_dir = File.expand_path('tmp/ruby', __dir__)
         
     | 
| 
       75 
31 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
                 
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
                directories.each do |dir|
         
     | 
| 
       80 
     | 
    
         
            -
                  Dir.mkdir File.join(dist, dir)
         
     | 
| 
      
 32 
     | 
    
         
            +
                MAKE_DIRECTORIES.each do |dir|
         
     | 
| 
      
 33 
     | 
    
         
            +
                  Dir.mkdir File.join(dist, dir) unless Dir.exist? dir
         
     | 
| 
       81 
34 
     | 
    
         
             
                end
         
     | 
| 
       82 
35 
     | 
    
         | 
| 
       83 
     | 
    
         
            -
                 
     | 
| 
      
 36 
     | 
    
         
            +
                RUBY_PARSER_COPY_TARGETS.each do |target|
         
     | 
| 
       84 
37 
     | 
    
         
             
                  FileUtils.cp File.join(ruby_dir, target), File.join(dist, target)
         
     | 
| 
       85 
38 
     | 
    
         
             
                end
         
     | 
| 
       86 
39 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
                # "parse.tmp.y"
         
     | 
| 
       88 
     | 
    
         
            -
                id2token_path = File.join(ruby_dir, 'tool/id2token.rb')
         
     | 
| 
       89 
     | 
    
         
            -
                parse_y_path = File.join(dist, 'parse.y')
         
     | 
| 
       90 
     | 
    
         
            -
                parse_tmp_y_path = File.join(dist, 'parse.tmp.y')
         
     | 
| 
       91 
     | 
    
         
            -
                sh "ruby #{id2token_path} #{parse_y_path} > #{parse_tmp_y_path}"
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
                # "id.h"
         
     | 
| 
       94 
     | 
    
         
            -
                generic_erb_path = File.join(ruby_dir, 'tool/generic_erb.rb')
         
     | 
| 
       95 
     | 
    
         
            -
                id_h_tmpl_path = File.join(ruby_dir, 'template/id.h.tmpl')
         
     | 
| 
       96 
     | 
    
         
            -
                id_h_path = File.join(dist, 'id.h')
         
     | 
| 
       97 
     | 
    
         
            -
                sh "ruby #{generic_erb_path} --output=#{id_h_path} #{id_h_tmpl_path}"
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
40 
     | 
    
         
             
                # "probes.h"
         
     | 
| 
       100 
41 
     | 
    
         
             
                probes_h_path = File.join(dist, 'probes.h')
         
     | 
| 
       101 
42 
     | 
    
         
             
                File.open(probes_h_path, 'w+') do |f|
         
     | 
| 
         @@ -107,29 +48,25 @@ namespace :ruby_parser do 
     | 
|
| 
       107 
48 
     | 
    
         
             
                  SRC
         
     | 
| 
       108 
49 
     | 
    
         
             
                end
         
     | 
| 
       109 
50 
     | 
    
         | 
| 
       110 
     | 
    
         
            -
                 
     | 
| 
       111 
     | 
    
         
            -
                node_name_path = File.join(ruby_dir, 'tool/node_name.rb')
         
     | 
| 
       112 
     | 
    
         
            -
                rubyparser_h_path = File.join(dist, 'rubyparser.h')
         
     | 
| 
       113 
     | 
    
         
            -
                node_name_inc_path = File.join(dist, 'node_name.inc')
         
     | 
| 
       114 
     | 
    
         
            -
                sh "ruby -n #{node_name_path} < #{rubyparser_h_path} > #{node_name_inc_path}"
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
                # "lex.c"
         
     | 
| 
       117 
     | 
    
         
            -
                sh 'cd tmp/ruby && ./autogen.sh && ./configure && make'
         
     | 
| 
       118 
     | 
    
         
            -
                FileUtils.mv File.join(ruby_dir, 'lex.c'), File.join(dist, 'lex.c')
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
                `rm -rf tmp/ruby`
         
     | 
| 
      
 51 
     | 
    
         
            +
                `rm -rf tmp/ruby tmp/ruby.tar.gz`
         
     | 
| 
       121 
52 
     | 
    
         
             
              end
         
     | 
| 
       122 
53 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
              desc ' 
     | 
| 
       124 
     | 
    
         
            -
              task : 
     | 
| 
       125 
     | 
    
         
            -
                 
     | 
| 
      
 54 
     | 
    
         
            +
              desc 'patched ro ruby parse that build for Kanayago'
         
     | 
| 
      
 55 
     | 
    
         
            +
              task :patch do
         
     | 
| 
      
 56 
     | 
    
         
            +
                running_ruby_version = if RUBY_DESCRIPTION.include?('dev')
         
     | 
| 
      
 57 
     | 
    
         
            +
                                         'head'
         
     | 
| 
      
 58 
     | 
    
         
            +
                                       else
         
     | 
| 
      
 59 
     | 
    
         
            +
                                         RUBY_VERSION[..2]
         
     | 
| 
      
 60 
     | 
    
         
            +
                                       end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                sh "patch -p1 < patch/#{running_ruby_version}/kanayago.patch"
         
     | 
| 
       126 
63 
     | 
    
         
             
              end
         
     | 
| 
       127 
64 
     | 
    
         | 
| 
       128 
65 
     | 
    
         
             
              desc 'clean to ruby parser file'
         
     | 
| 
       129 
66 
     | 
    
         
             
              task :clean do
         
     | 
| 
       130 
67 
     | 
    
         
             
                dist = File.expand_path('./ext/kanayago')
         
     | 
| 
       131 
68 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
                 
     | 
| 
      
 69 
     | 
    
         
            +
                RUBY_PARSER_COPY_TARGETS.each do |target|
         
     | 
| 
       133 
70 
     | 
    
         
             
                  FileUtils.rm File.join(dist, target), force: true
         
     | 
| 
       134 
71 
     | 
    
         
             
                end
         
     | 
| 
       135 
72 
     | 
    
         
             
                delete_files = ['constant.h', 'id.h', 'id.h', 'id.h', 'id_table.h', 'lex.c', 'node_name.inc', 'parse.c', 'parse.h',
         
     | 
| 
         @@ -139,16 +76,14 @@ namespace :ruby_parser do 
     | 
|
| 
       139 
76 
     | 
    
         
             
                  FileUtils.rm File.join(dist, file), force: true
         
     | 
| 
       140 
77 
     | 
    
         
             
                end
         
     | 
| 
       141 
78 
     | 
    
         | 
| 
       142 
     | 
    
         
            -
                 
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
                delete_directories.each do |dir|
         
     | 
| 
      
 79 
     | 
    
         
            +
                DELETE_DIRECTORIES.each do |dir|
         
     | 
| 
       145 
80 
     | 
    
         
             
                  FileUtils.rm_rf File.join(dist, dir)
         
     | 
| 
       146 
81 
     | 
    
         
             
                end
         
     | 
| 
       147 
82 
     | 
    
         
             
              end
         
     | 
| 
       148 
83 
     | 
    
         
             
            end
         
     | 
| 
       149 
84 
     | 
    
         | 
| 
       150 
     | 
    
         
            -
            task build: ['ruby_parser: 
     | 
| 
       151 
     | 
    
         
            -
            task install: ['ruby_parser: 
     | 
| 
      
 85 
     | 
    
         
            +
            task build: ['ruby_parser:import', 'ruby_parser:patch', 'compile']
         
     | 
| 
      
 86 
     | 
    
         
            +
            task install: ['ruby_parser:import', 'ruby_parser:patch', 'compile']
         
     | 
| 
       152 
87 
     | 
    
         | 
| 
       153 
88 
     | 
    
         
             
            GEMSPEC = Gem::Specification.load('kanayago.gemspec')
         
     | 
| 
       154 
89 
     | 
    
         | 
| 
         @@ -169,6 +104,18 @@ Rake::TestTask.new(:test) do |t| 
     | 
|
| 
       169 
104 
     | 
    
         
             
              t.test_files = FileList['test/**/*_test.rb']
         
     | 
| 
       170 
105 
     | 
    
         
             
            end
         
     | 
| 
       171 
106 
     | 
    
         | 
| 
      
 107 
     | 
    
         
            +
            namespace :sample do
         
     | 
| 
      
 108 
     | 
    
         
            +
              desc 'Generate RSpec tests from Ruby code using Kanayago AST'
         
     | 
| 
      
 109 
     | 
    
         
            +
              task :rspec_generate do
         
     | 
| 
      
 110 
     | 
    
         
            +
                sh 'ruby sample/test_generator.rb'
         
     | 
| 
      
 111 
     | 
    
         
            +
              end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
              desc 'Generate Minitest tests from Ruby code using Kanayago AST'
         
     | 
| 
      
 114 
     | 
    
         
            +
              task :minitest_generate do
         
     | 
| 
      
 115 
     | 
    
         
            +
                sh 'ruby sample/minitest_generator.rb'
         
     | 
| 
      
 116 
     | 
    
         
            +
              end
         
     | 
| 
      
 117 
     | 
    
         
            +
            end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
       172 
119 
     | 
    
         
             
            desc 'try to kanayago code'
         
     | 
| 
       173 
120 
     | 
    
         
             
            task :run do
         
     | 
| 
       174 
121 
     | 
    
         
             
              sh 'ruby test.rb'
         
     | 
    
        data/ext/kanayago/extconf.rb
    CHANGED
    
    
    
        data/ext/kanayago/id.h
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            /* DO NOT EDIT THIS FILE DIRECTLY */
         
     | 
| 
      
 1 
     | 
    
         
            +
            /* DO NOT EDIT THIS FILE DIRECTLY: source is at template/id.h.tmpl */
         
     | 
| 
       2 
2 
     | 
    
         
             
            /**********************************************************************
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
              id.h -
         
     | 
| 
         @@ -14,15 +14,14 @@ 
     | 
|
| 
       14 
14 
     | 
    
         
             
            #define RUBY_ID_H
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            enum ruby_id_types {
         
     | 
| 
       17 
     | 
    
         
            -
                RUBY_ID_STATIC_SYM  = 0x01,
         
     | 
| 
       18 
17 
     | 
    
         
             
                RUBY_ID_LOCAL       = 0x00,
         
     | 
| 
      
 18 
     | 
    
         
            +
                RUBY_ID_STATIC_SYM  = 0x01,
         
     | 
| 
       19 
19 
     | 
    
         
             
                RUBY_ID_INSTANCE    = (0x01<<1),
         
     | 
| 
       20 
20 
     | 
    
         
             
                RUBY_ID_GLOBAL      = (0x03<<1),
         
     | 
| 
       21 
21 
     | 
    
         
             
                RUBY_ID_ATTRSET     = (0x04<<1),
         
     | 
| 
       22 
22 
     | 
    
         
             
                RUBY_ID_CONST       = (0x05<<1),
         
     | 
| 
       23 
23 
     | 
    
         
             
                RUBY_ID_CLASS       = (0x06<<1),
         
     | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
       25 
     | 
    
         
            -
                RUBY_ID_INTERNAL    = RUBY_ID_JUNK,
         
     | 
| 
      
 24 
     | 
    
         
            +
                RUBY_ID_INTERNAL    = (0x07<<1),
         
     | 
| 
       26 
25 
     | 
    
         
             
                RUBY_ID_SCOPE_SHIFT = 4,
         
     | 
| 
       27 
26 
     | 
    
         
             
                RUBY_ID_SCOPE_MASK  = (~(~0U<<(RUBY_ID_SCOPE_SHIFT-1))<<1)
         
     | 
| 
       28 
27 
     | 
    
         
             
            };
         
     | 
| 
         @@ -36,7 +35,6 @@ enum ruby_id_types { 
     | 
|
| 
       36 
35 
     | 
    
         
             
            #define ID_ATTRSET     RUBY_ID_ATTRSET
         
     | 
| 
       37 
36 
     | 
    
         
             
            #define ID_CONST       RUBY_ID_CONST
         
     | 
| 
       38 
37 
     | 
    
         
             
            #define ID_CLASS       RUBY_ID_CLASS
         
     | 
| 
       39 
     | 
    
         
            -
            #define ID_JUNK        RUBY_ID_JUNK
         
     | 
| 
       40 
38 
     | 
    
         
             
            #define ID_INTERNAL    RUBY_ID_INTERNAL
         
     | 
| 
       41 
39 
     | 
    
         | 
| 
       42 
40 
     | 
    
         
             
            #define symIFUNC ID2SYM(idIFUNC)
         
     | 
| 
         @@ -110,6 +108,7 @@ enum ruby_method_ids { 
     | 
|
| 
       110 
108 
     | 
    
         
             
                idANDDOT = RUBY_TOKEN(ANDDOT),
         
     | 
| 
       111 
109 
     | 
    
         
             
                tPRESERVED_ID_BEGIN = 150,
         
     | 
| 
       112 
110 
     | 
    
         
             
                idNilP,
         
     | 
| 
      
 111 
     | 
    
         
            +
                idIncludeP,
         
     | 
| 
       113 
112 
     | 
    
         
             
                idNULL,
         
     | 
| 
       114 
113 
     | 
    
         
             
                idEmptyP,
         
     | 
| 
       115 
114 
     | 
    
         
             
                idEqlP,
         
     | 
| 
         @@ -139,6 +138,7 @@ enum ruby_method_ids { 
     | 
|
| 
       139 
138 
     | 
    
         
             
                tInspect,
         
     | 
| 
       140 
139 
     | 
    
         
             
                tIntern,
         
     | 
| 
       141 
140 
     | 
    
         
             
                tObject_id,
         
     | 
| 
      
 141 
     | 
    
         
            +
                t__id__,
         
     | 
| 
       142 
142 
     | 
    
         
             
                tConst_added,
         
     | 
| 
       143 
143 
     | 
    
         
             
                tConst_missing,
         
     | 
| 
       144 
144 
     | 
    
         
             
                tMethodMissing,
         
     | 
| 
         @@ -192,6 +192,8 @@ enum ruby_method_ids { 
     | 
|
| 
       192 
192 
     | 
    
         
             
                tPath,
         
     | 
| 
       193 
193 
     | 
    
         
             
                tPack,
         
     | 
| 
       194 
194 
     | 
    
         
             
                tBuffer,
         
     | 
| 
      
 195 
     | 
    
         
            +
                tAborted,
         
     | 
| 
      
 196 
     | 
    
         
            +
                tExited,
         
     | 
| 
       195 
197 
     | 
    
         
             
                tUScore,
         
     | 
| 
       196 
198 
     | 
    
         
             
                tNUMPARAM_1,
         
     | 
| 
       197 
199 
     | 
    
         
             
                tNUMPARAM_2,
         
     | 
| 
         @@ -221,6 +223,7 @@ enum ruby_method_ids { 
     | 
|
| 
       221 
223 
     | 
    
         | 
| 
       222 
224 
     | 
    
         
             
                /* CONST tokens {{{ */
         
     | 
| 
       223 
225 
     | 
    
         
             
                tTOKEN_CONST_BEGIN = tTOKEN_GLOBAL_END-1,
         
     | 
| 
      
 226 
     | 
    
         
            +
                tRuby,
         
     | 
| 
       224 
227 
     | 
    
         
             
                tTOKEN_CONST_END,
         
     | 
| 
       225 
228 
     | 
    
         
             
                /* CONST tokens }}} */
         
     | 
| 
       226 
229 
     | 
    
         | 
| 
         @@ -245,6 +248,7 @@ enum ruby_method_ids { 
     | 
|
| 
       245 
248 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(Inspect),
         
     | 
| 
       246 
249 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(Intern),
         
     | 
| 
       247 
250 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(Object_id),
         
     | 
| 
      
 251 
     | 
    
         
            +
                DEFINE_LOCALID_FROM_TOKEN(__id__),
         
     | 
| 
       248 
252 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(Const_added),
         
     | 
| 
       249 
253 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(Const_missing),
         
     | 
| 
       250 
254 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(MethodMissing),
         
     | 
| 
         @@ -298,6 +302,8 @@ enum ruby_method_ids { 
     | 
|
| 
       298 
302 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(Path),
         
     | 
| 
       299 
303 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(Pack),
         
     | 
| 
       300 
304 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(Buffer),
         
     | 
| 
      
 305 
     | 
    
         
            +
                DEFINE_LOCALID_FROM_TOKEN(Aborted),
         
     | 
| 
      
 306 
     | 
    
         
            +
                DEFINE_LOCALID_FROM_TOKEN(Exited),
         
     | 
| 
       301 
307 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(UScore),
         
     | 
| 
       302 
308 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_1),
         
     | 
| 
       303 
309 
     | 
    
         
             
                DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_2),
         
     | 
| 
         @@ -327,6 +333,7 @@ enum ruby_method_ids { 
     | 
|
| 
       327 
333 
     | 
    
         | 
| 
       328 
334 
     | 
    
         
             
                /* CONST IDs {{{ */
         
     | 
| 
       329 
335 
     | 
    
         
             
            #define DEFINE_CONSTID_FROM_TOKEN(n) id##n = TOKEN2CONSTID(t##n)
         
     | 
| 
      
 336 
     | 
    
         
            +
                DEFINE_CONSTID_FROM_TOKEN(Ruby),
         
     | 
| 
       330 
337 
     | 
    
         
             
            #undef DEFINE_CONSTID_FROM_TOKEN
         
     | 
| 
       331 
338 
     | 
    
         
             
                /* CONST IDs }}} */
         
     | 
| 
       332 
339 
     | 
    
         | 
    
        data/ext/kanayago/id_table.h
    CHANGED
    
    | 
         @@ -16,7 +16,10 @@ enum rb_id_table_iterator_result { 
     | 
|
| 
       16 
16 
     | 
    
         
             
            };
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            struct rb_id_table *rb_id_table_create(size_t size);
         
     | 
| 
      
 19 
     | 
    
         
            +
            struct rb_id_table *rb_id_table_init(struct rb_id_table *tbl, size_t capa);
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       19 
21 
     | 
    
         
             
            void rb_id_table_free(struct rb_id_table *tbl);
         
     | 
| 
      
 22 
     | 
    
         
            +
            void rb_id_table_free_items(struct rb_id_table *tbl);
         
     | 
| 
       20 
23 
     | 
    
         
             
            void rb_id_table_clear(struct rb_id_table *tbl);
         
     | 
| 
       21 
24 
     | 
    
         | 
| 
       22 
25 
     | 
    
         
             
            size_t rb_id_table_memsize(const struct rb_id_table *tbl);
         
     | 
| 
         @@ -32,6 +35,18 @@ void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *fu 
     | 
|
| 
       32 
35 
     | 
    
         
             
            void rb_id_table_foreach_values(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data);
         
     | 
| 
       33 
36 
     | 
    
         
             
            void rb_id_table_foreach_values_with_replace(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, rb_id_table_update_value_callback_func_t *replace, void *data);
         
     | 
| 
       34 
37 
     | 
    
         | 
| 
      
 38 
     | 
    
         
            +
            VALUE rb_managed_id_table_create(const rb_data_type_t *type, size_t capa);
         
     | 
| 
      
 39 
     | 
    
         
            +
            VALUE rb_managed_id_table_new(size_t capa);
         
     | 
| 
      
 40 
     | 
    
         
            +
            VALUE rb_managed_id_table_dup(VALUE table);
         
     | 
| 
      
 41 
     | 
    
         
            +
            int rb_managed_id_table_insert(VALUE table, ID id, VALUE val);
         
     | 
| 
      
 42 
     | 
    
         
            +
            int rb_managed_id_table_lookup(VALUE table, ID id, VALUE *valp);
         
     | 
| 
      
 43 
     | 
    
         
            +
            size_t rb_managed_id_table_size(VALUE table);
         
     | 
| 
      
 44 
     | 
    
         
            +
            void rb_managed_id_table_foreach(VALUE table, rb_id_table_foreach_func_t *func, void *data);
         
     | 
| 
      
 45 
     | 
    
         
            +
            void rb_managed_id_table_foreach_values(VALUE table, rb_id_table_foreach_values_func_t *func, void *data);
         
     | 
| 
      
 46 
     | 
    
         
            +
            int rb_managed_id_table_delete(VALUE table, ID id);
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            extern const rb_data_type_t rb_managed_id_table_type;
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
       35 
50 
     | 
    
         
             
            RUBY_SYMBOL_EXPORT_BEGIN
         
     | 
| 
       36 
51 
     | 
    
         
             
            size_t rb_id_table_size(const struct rb_id_table *tbl);
         
     | 
| 
       37 
52 
     | 
    
         
             
            RUBY_SYMBOL_EXPORT_END
         
     | 
| 
         @@ -0,0 +1,199 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /* This is a public domain general purpose hash table package
         
     | 
| 
      
 2 
     | 
    
         
            +
               originally written by Peter Moore @ UCB.
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
               The hash table data structures were redesigned and the package was
         
     | 
| 
      
 5 
     | 
    
         
            +
               rewritten by Vladimir Makarov <vmakarov@redhat.com>.  */
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            #ifndef RUBY_ST_H
         
     | 
| 
      
 8 
     | 
    
         
            +
            #define RUBY_ST_H 1
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            #if defined(__cplusplus)
         
     | 
| 
      
 11 
     | 
    
         
            +
            extern "C" {
         
     | 
| 
      
 12 
     | 
    
         
            +
            #if 0
         
     | 
| 
      
 13 
     | 
    
         
            +
            } /* satisfy cc-mode */
         
     | 
| 
      
 14 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 15 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            #include "ruby/defines.h"
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            RUBY_SYMBOL_EXPORT_BEGIN
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            #if SIZEOF_LONG == SIZEOF_VOIDP
         
     | 
| 
      
 22 
     | 
    
         
            +
            typedef unsigned long st_data_t;
         
     | 
| 
      
 23 
     | 
    
         
            +
            #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
         
     | 
| 
      
 24 
     | 
    
         
            +
            typedef unsigned LONG_LONG st_data_t;
         
     | 
| 
      
 25 
     | 
    
         
            +
            #else
         
     | 
| 
      
 26 
     | 
    
         
            +
            # error ---->> st.c requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<----
         
     | 
| 
      
 27 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 28 
     | 
    
         
            +
            #define ST_DATA_T_DEFINED
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            #ifndef CHAR_BIT
         
     | 
| 
      
 31 
     | 
    
         
            +
            # ifdef HAVE_LIMITS_H
         
     | 
| 
      
 32 
     | 
    
         
            +
            #  include <limits.h>
         
     | 
| 
      
 33 
     | 
    
         
            +
            # else
         
     | 
| 
      
 34 
     | 
    
         
            +
            #  define CHAR_BIT 8
         
     | 
| 
      
 35 
     | 
    
         
            +
            # endif
         
     | 
| 
      
 36 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 37 
     | 
    
         
            +
            #ifndef _
         
     | 
| 
      
 38 
     | 
    
         
            +
            # define _(args) args
         
     | 
| 
      
 39 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 40 
     | 
    
         
            +
            #ifndef ANYARGS
         
     | 
| 
      
 41 
     | 
    
         
            +
            # ifdef __cplusplus
         
     | 
| 
      
 42 
     | 
    
         
            +
            #   define ANYARGS ...
         
     | 
| 
      
 43 
     | 
    
         
            +
            # else
         
     | 
| 
      
 44 
     | 
    
         
            +
            #   define ANYARGS
         
     | 
| 
      
 45 
     | 
    
         
            +
            # endif
         
     | 
| 
      
 46 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            typedef struct st_table st_table;
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            typedef st_data_t st_index_t;
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            /* Maximal value of unsigned integer type st_index_t.  */
         
     | 
| 
      
 53 
     | 
    
         
            +
            #define MAX_ST_INDEX_VAL (~(st_index_t) 0)
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            typedef int st_compare_func(st_data_t, st_data_t);
         
     | 
| 
      
 56 
     | 
    
         
            +
            typedef st_index_t st_hash_func(st_data_t);
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index_t) ? 1 : -1];
         
     | 
| 
      
 59 
     | 
    
         
            +
            #define SIZEOF_ST_INDEX_T SIZEOF_VOIDP
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            struct st_hash_type {
         
     | 
| 
      
 62 
     | 
    
         
            +
                int (*compare)(st_data_t, st_data_t); /* st_compare_func* */
         
     | 
| 
      
 63 
     | 
    
         
            +
                st_index_t (*hash)(st_data_t);        /* st_hash_func* */
         
     | 
| 
      
 64 
     | 
    
         
            +
            };
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            #define ST_INDEX_BITS (SIZEOF_ST_INDEX_T * CHAR_BIT)
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            #if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR) && defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P)
         
     | 
| 
      
 69 
     | 
    
         
            +
            # define ST_DATA_COMPATIBLE_P(type) \
         
     | 
| 
      
 70 
     | 
    
         
            +
               __builtin_choose_expr(__builtin_types_compatible_p(type, st_data_t), 1, 0)
         
     | 
| 
      
 71 
     | 
    
         
            +
            #else
         
     | 
| 
      
 72 
     | 
    
         
            +
            # define ST_DATA_COMPATIBLE_P(type) 0
         
     | 
| 
      
 73 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            typedef struct st_table_entry st_table_entry;
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            struct st_table_entry; /* defined in st.c */
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            struct st_table {
         
     | 
| 
      
 80 
     | 
    
         
            +
                /* Cached features of the table -- see st.c for more details.  */
         
     | 
| 
      
 81 
     | 
    
         
            +
                unsigned char entry_power, bin_power, size_ind;
         
     | 
| 
      
 82 
     | 
    
         
            +
                /* How many times the table was rebuilt.  */
         
     | 
| 
      
 83 
     | 
    
         
            +
                unsigned int rebuilds_num;
         
     | 
| 
      
 84 
     | 
    
         
            +
                const struct st_hash_type *type;
         
     | 
| 
      
 85 
     | 
    
         
            +
                /* Number of entries currently in the table.  */
         
     | 
| 
      
 86 
     | 
    
         
            +
                st_index_t num_entries;
         
     | 
| 
      
 87 
     | 
    
         
            +
                /* Array of bins used for access by keys.  */
         
     | 
| 
      
 88 
     | 
    
         
            +
                st_index_t *bins;
         
     | 
| 
      
 89 
     | 
    
         
            +
                /* Start and bound index of entries in array entries.
         
     | 
| 
      
 90 
     | 
    
         
            +
                   entries_starts and entries_bound are in interval
         
     | 
| 
      
 91 
     | 
    
         
            +
                   [0,allocated_entries].  */
         
     | 
| 
      
 92 
     | 
    
         
            +
                st_index_t entries_start, entries_bound;
         
     | 
| 
      
 93 
     | 
    
         
            +
                /* Array of size 2^entry_power.  */
         
     | 
| 
      
 94 
     | 
    
         
            +
                st_table_entry *entries;
         
     | 
| 
      
 95 
     | 
    
         
            +
            };
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
            #define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0)
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
            enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK, ST_REPLACE};
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
            size_t rb_st_table_size(const struct st_table *tbl);
         
     | 
| 
      
 102 
     | 
    
         
            +
            #define st_table_size rb_st_table_size
         
     | 
| 
      
 103 
     | 
    
         
            +
            st_table *rb_st_init_table(const struct st_hash_type *);
         
     | 
| 
      
 104 
     | 
    
         
            +
            #define st_init_table rb_st_init_table
         
     | 
| 
      
 105 
     | 
    
         
            +
            st_table *rb_st_init_table_with_size(const struct st_hash_type *, st_index_t);
         
     | 
| 
      
 106 
     | 
    
         
            +
            #define st_init_table_with_size rb_st_init_table_with_size
         
     | 
| 
      
 107 
     | 
    
         
            +
            st_table *rb_st_init_numtable(void);
         
     | 
| 
      
 108 
     | 
    
         
            +
            #define st_init_numtable rb_st_init_numtable
         
     | 
| 
      
 109 
     | 
    
         
            +
            st_table *rb_st_init_numtable_with_size(st_index_t);
         
     | 
| 
      
 110 
     | 
    
         
            +
            #define st_init_numtable_with_size rb_st_init_numtable_with_size
         
     | 
| 
      
 111 
     | 
    
         
            +
            st_table *rb_st_init_strtable(void);
         
     | 
| 
      
 112 
     | 
    
         
            +
            #define st_init_strtable rb_st_init_strtable
         
     | 
| 
      
 113 
     | 
    
         
            +
            st_table *rb_st_init_strtable_with_size(st_index_t);
         
     | 
| 
      
 114 
     | 
    
         
            +
            #define st_init_strtable_with_size rb_st_init_strtable_with_size
         
     | 
| 
      
 115 
     | 
    
         
            +
            st_table *rb_st_init_strcasetable(void);
         
     | 
| 
      
 116 
     | 
    
         
            +
            #define st_init_strcasetable rb_st_init_strcasetable
         
     | 
| 
      
 117 
     | 
    
         
            +
            st_table *rb_st_init_strcasetable_with_size(st_index_t);
         
     | 
| 
      
 118 
     | 
    
         
            +
            #define st_init_strcasetable_with_size rb_st_init_strcasetable_with_size
         
     | 
| 
      
 119 
     | 
    
         
            +
            int rb_st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
         
     | 
| 
      
 120 
     | 
    
         
            +
            #define st_delete rb_st_delete
         
     | 
| 
      
 121 
     | 
    
         
            +
            int rb_st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
         
     | 
| 
      
 122 
     | 
    
         
            +
            #define st_delete_safe rb_st_delete_safe
         
     | 
| 
      
 123 
     | 
    
         
            +
            int rb_st_shift(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
         
     | 
| 
      
 124 
     | 
    
         
            +
            #define st_shift rb_st_shift
         
     | 
| 
      
 125 
     | 
    
         
            +
            int rb_st_insert(st_table *, st_data_t, st_data_t);
         
     | 
| 
      
 126 
     | 
    
         
            +
            #define st_insert rb_st_insert
         
     | 
| 
      
 127 
     | 
    
         
            +
            int rb_st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t));
         
     | 
| 
      
 128 
     | 
    
         
            +
            #define st_insert2 rb_st_insert2
         
     | 
| 
      
 129 
     | 
    
         
            +
            int rb_st_lookup(st_table *, st_data_t, st_data_t *);
         
     | 
| 
      
 130 
     | 
    
         
            +
            #define st_lookup rb_st_lookup
         
     | 
| 
      
 131 
     | 
    
         
            +
            int rb_st_get_key(st_table *, st_data_t, st_data_t *);
         
     | 
| 
      
 132 
     | 
    
         
            +
            #define st_get_key rb_st_get_key
         
     | 
| 
      
 133 
     | 
    
         
            +
            typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing);
         
     | 
| 
      
 134 
     | 
    
         
            +
            /* *key may be altered, but must equal to the old key, i.e., the
         
     | 
| 
      
 135 
     | 
    
         
            +
             * results of hash() are same and compare() returns 0, otherwise the
         
     | 
| 
      
 136 
     | 
    
         
            +
             * behavior is undefined */
         
     | 
| 
      
 137 
     | 
    
         
            +
            int rb_st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg);
         
     | 
| 
      
 138 
     | 
    
         
            +
            #define st_update rb_st_update
         
     | 
| 
      
 139 
     | 
    
         
            +
            typedef int st_foreach_callback_func(st_data_t, st_data_t, st_data_t);
         
     | 
| 
      
 140 
     | 
    
         
            +
            typedef int st_foreach_check_callback_func(st_data_t, st_data_t, st_data_t, int);
         
     | 
| 
      
 141 
     | 
    
         
            +
            int rb_st_foreach_with_replace(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg);
         
     | 
| 
      
 142 
     | 
    
         
            +
            #define st_foreach_with_replace rb_st_foreach_with_replace
         
     | 
| 
      
 143 
     | 
    
         
            +
            int rb_st_foreach(st_table *, st_foreach_callback_func *, st_data_t);
         
     | 
| 
      
 144 
     | 
    
         
            +
            #define st_foreach rb_st_foreach
         
     | 
| 
      
 145 
     | 
    
         
            +
            int rb_st_foreach_check(st_table *, st_foreach_check_callback_func *, st_data_t, st_data_t);
         
     | 
| 
      
 146 
     | 
    
         
            +
            #define st_foreach_check rb_st_foreach_check
         
     | 
| 
      
 147 
     | 
    
         
            +
            st_index_t rb_st_keys(st_table *table, st_data_t *keys, st_index_t size);
         
     | 
| 
      
 148 
     | 
    
         
            +
            #define st_keys rb_st_keys
         
     | 
| 
      
 149 
     | 
    
         
            +
            st_index_t rb_st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never);
         
     | 
| 
      
 150 
     | 
    
         
            +
            #define st_keys_check rb_st_keys_check
         
     | 
| 
      
 151 
     | 
    
         
            +
            st_index_t rb_st_values(st_table *table, st_data_t *values, st_index_t size);
         
     | 
| 
      
 152 
     | 
    
         
            +
            #define st_values rb_st_values
         
     | 
| 
      
 153 
     | 
    
         
            +
            st_index_t rb_st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never);
         
     | 
| 
      
 154 
     | 
    
         
            +
            #define st_values_check rb_st_values_check
         
     | 
| 
      
 155 
     | 
    
         
            +
            void rb_st_add_direct(st_table *, st_data_t, st_data_t);
         
     | 
| 
      
 156 
     | 
    
         
            +
            #define st_add_direct rb_st_add_direct
         
     | 
| 
      
 157 
     | 
    
         
            +
            void rb_st_free_table(st_table *);
         
     | 
| 
      
 158 
     | 
    
         
            +
            #define st_free_table rb_st_free_table
         
     | 
| 
      
 159 
     | 
    
         
            +
            void rb_st_cleanup_safe(st_table *, st_data_t);
         
     | 
| 
      
 160 
     | 
    
         
            +
            #define st_cleanup_safe rb_st_cleanup_safe
         
     | 
| 
      
 161 
     | 
    
         
            +
            void rb_st_clear(st_table *);
         
     | 
| 
      
 162 
     | 
    
         
            +
            #define st_clear rb_st_clear
         
     | 
| 
      
 163 
     | 
    
         
            +
            st_table *rb_st_copy(st_table *);
         
     | 
| 
      
 164 
     | 
    
         
            +
            #define st_copy rb_st_copy
         
     | 
| 
      
 165 
     | 
    
         
            +
            CONSTFUNC(int rb_st_numcmp(st_data_t, st_data_t));
         
     | 
| 
      
 166 
     | 
    
         
            +
            #define st_numcmp rb_st_numcmp
         
     | 
| 
      
 167 
     | 
    
         
            +
            CONSTFUNC(st_index_t rb_st_numhash(st_data_t));
         
     | 
| 
      
 168 
     | 
    
         
            +
            #define st_numhash rb_st_numhash
         
     | 
| 
      
 169 
     | 
    
         
            +
            PUREFUNC(int rb_st_locale_insensitive_strcasecmp(const char *s1, const char *s2));
         
     | 
| 
      
 170 
     | 
    
         
            +
            #define st_locale_insensitive_strcasecmp rb_st_locale_insensitive_strcasecmp
         
     | 
| 
      
 171 
     | 
    
         
            +
            PUREFUNC(int rb_st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n));
         
     | 
| 
      
 172 
     | 
    
         
            +
            #define st_locale_insensitive_strncasecmp rb_st_locale_insensitive_strncasecmp
         
     | 
| 
      
 173 
     | 
    
         
            +
            #define st_strcasecmp rb_st_locale_insensitive_strcasecmp
         
     | 
| 
      
 174 
     | 
    
         
            +
            #define st_strncasecmp rb_st_locale_insensitive_strncasecmp
         
     | 
| 
      
 175 
     | 
    
         
            +
            PUREFUNC(size_t rb_st_memsize(const st_table *));
         
     | 
| 
      
 176 
     | 
    
         
            +
            #define st_memsize rb_st_memsize
         
     | 
| 
      
 177 
     | 
    
         
            +
            PUREFUNC(st_index_t rb_st_hash(const void *ptr, size_t len, st_index_t h));
         
     | 
| 
      
 178 
     | 
    
         
            +
            #define st_hash rb_st_hash
         
     | 
| 
      
 179 
     | 
    
         
            +
            CONSTFUNC(st_index_t rb_st_hash_uint32(st_index_t h, uint32_t i));
         
     | 
| 
      
 180 
     | 
    
         
            +
            #define st_hash_uint32 rb_st_hash_uint32
         
     | 
| 
      
 181 
     | 
    
         
            +
            CONSTFUNC(st_index_t rb_st_hash_uint(st_index_t h, st_index_t i));
         
     | 
| 
      
 182 
     | 
    
         
            +
            #define st_hash_uint rb_st_hash_uint
         
     | 
| 
      
 183 
     | 
    
         
            +
            CONSTFUNC(st_index_t rb_st_hash_end(st_index_t h));
         
     | 
| 
      
 184 
     | 
    
         
            +
            #define st_hash_end rb_st_hash_end
         
     | 
| 
      
 185 
     | 
    
         
            +
            CONSTFUNC(st_index_t rb_st_hash_start(st_index_t h));
         
     | 
| 
      
 186 
     | 
    
         
            +
            #define st_hash_start(h) ((st_index_t)(h))
         
     | 
| 
      
 187 
     | 
    
         
            +
             
     | 
| 
      
 188 
     | 
    
         
            +
            void rb_hash_bulk_insert_into_st_table(long, const VALUE *, VALUE);
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
            RUBY_SYMBOL_EXPORT_END
         
     | 
| 
      
 191 
     | 
    
         
            +
             
     | 
| 
      
 192 
     | 
    
         
            +
            #if defined(__cplusplus)
         
     | 
| 
      
 193 
     | 
    
         
            +
            #if 0
         
     | 
| 
      
 194 
     | 
    
         
            +
            { /* satisfy cc-mode */
         
     | 
| 
      
 195 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 196 
     | 
    
         
            +
            }  /* extern "C" { */
         
     | 
| 
      
 197 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
            #endif /* RUBY_ST_H */
         
     | 
| 
         @@ -37,6 +37,7 @@ size_t rb_ary_size_as_embedded(VALUE ary); 
     | 
|
| 
       37 
37 
     | 
    
         
             
            void rb_ary_make_embedded(VALUE ary);
         
     | 
| 
       38 
38 
     | 
    
         
             
            bool rb_ary_embeddable_p(VALUE ary);
         
     | 
| 
       39 
39 
     | 
    
         
             
            VALUE rb_ary_diff(VALUE ary1, VALUE ary2);
         
     | 
| 
      
 40 
     | 
    
         
            +
            RUBY_EXTERN VALUE rb_cArray_empty_frozen;
         
     | 
| 
       40 
41 
     | 
    
         | 
| 
       41 
42 
     | 
    
         
             
            static inline VALUE rb_ary_entry_internal(VALUE ary, long offset);
         
     | 
| 
       42 
43 
     | 
    
         
             
            static inline bool ARY_PTR_USING_P(VALUE ary);
         
     | 
| 
         @@ -139,6 +140,8 @@ RARRAY_AREF(VALUE ary, long i) 
     | 
|
| 
       139 
140 
     | 
    
         
             
                VALUE val;
         
     | 
| 
       140 
141 
     | 
    
         
             
                RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
         
     | 
| 
       141 
142 
     | 
    
         | 
| 
      
 143 
     | 
    
         
            +
                RUBY_ASSERT(i < RARRAY_LEN(ary));
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
       142 
145 
     | 
    
         
             
                RBIMPL_WARNING_PUSH();
         
     | 
| 
       143 
146 
     | 
    
         
             
            #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 13
         
     | 
| 
       144 
147 
     | 
    
         
             
                RBIMPL_WARNING_IGNORED(-Warray-bounds);
         
     | 
| 
         @@ -121,6 +121,7 @@ VALUE rb_integer_float_eq(VALUE x, VALUE y); 
     | 
|
| 
       121 
121 
     | 
    
         
             
            VALUE rb_str_convert_to_inum(VALUE str, int base, int badcheck, int raise_exception);
         
     | 
| 
       122 
122 
     | 
    
         
             
            VALUE rb_big_comp(VALUE x);
         
     | 
| 
       123 
123 
     | 
    
         
             
            VALUE rb_big_aref(VALUE x, VALUE y);
         
     | 
| 
      
 124 
     | 
    
         
            +
            VALUE rb_big_aref2(VALUE num, VALUE beg, VALUE len);
         
     | 
| 
       124 
125 
     | 
    
         
             
            VALUE rb_big_abs(VALUE x);
         
     | 
| 
       125 
126 
     | 
    
         
             
            VALUE rb_big_size_m(VALUE big);
         
     | 
| 
       126 
127 
     | 
    
         
             
            VALUE rb_big_bit_length(VALUE big);
         
     |