ensemble_cast 0.1.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 +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ensemble_cast.gemspec +41 -0
- data/ext/ensemble_cast/ensemble_cast.c +54 -0
- data/ext/ensemble_cast/ensemble_cast.h +300 -0
- data/ext/ensemble_cast/extconf.rb +5 -0
- data/lib/ensemble_cast/version.rb +5 -0
- data/lib/ensemble_cast.rb +44 -0
- metadata +62 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: d91879ccd7e7f191bd1acbfaa183d5ee322644ef58ab03074afafb784d0134ec
         | 
| 4 | 
            +
              data.tar.gz: f9e124d7b5119570ec52828bf7f0771cce06fcc91700e55e03ed5ef1c6e4c7cc
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 7c6612091e0dd60177c0aa9b3706d9f990dec1d21dc599b2f53a704aea31c6070d0b3cbc68fd414d759b750c1c346495a3474032bcedf254b44c6a3894b74c0b
         | 
| 7 | 
            +
              data.tar.gz: b50c23129ab9f4a8573d9b2a50135e067e17cca416a8468eb2345e68fd11f39abe07b2de479176f1ded7f75bf58f159a8fa158cfc8670cf506a3efc0916dfc3e
         | 
    
        data/CODE_OF_CONDUCT.md
    ADDED
    
    | @@ -0,0 +1,84 @@ | |
| 1 | 
            +
            # Contributor Covenant Code of Conduct
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ## Our Pledge
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ## Our Standards
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            Examples of behavior that contributes to a positive environment for our community include:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            * Demonstrating empathy and kindness toward other people
         | 
| 14 | 
            +
            * Being respectful of differing opinions, viewpoints, and experiences
         | 
| 15 | 
            +
            * Giving and gracefully accepting constructive feedback
         | 
| 16 | 
            +
            * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
         | 
| 17 | 
            +
            * Focusing on what is best not just for us as individuals, but for the overall community
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            Examples of unacceptable behavior include:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            * The use of sexualized language or imagery, and sexual attention or
         | 
| 22 | 
            +
              advances of any kind
         | 
| 23 | 
            +
            * Trolling, insulting or derogatory comments, and personal or political attacks
         | 
| 24 | 
            +
            * Public or private harassment
         | 
| 25 | 
            +
            * Publishing others' private information, such as a physical or email
         | 
| 26 | 
            +
              address, without their explicit permission
         | 
| 27 | 
            +
            * Other conduct which could reasonably be considered inappropriate in a
         | 
| 28 | 
            +
              professional setting
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            ## Enforcement Responsibilities
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            ## Scope
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            ## Enforcement
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at 44367208+tetetratra@users.noreply.github.com. All complaints will be reviewed and investigated promptly and fairly.
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            All community leaders are obligated to respect the privacy and security of the reporter of any incident.
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            ## Enforcement Guidelines
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            ### 1. Correction
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            ### 2. Warning
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            **Community Impact**: A violation through a single incident or series of actions.
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
         | 
| 61 | 
            +
             | 
| 62 | 
            +
            ### 3. Temporary Ban
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            ### 4. Permanent Ban
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior,  harassment of an individual, or aggression toward or disparagement of classes of individuals.
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            **Consequence**: A permanent ban from any sort of public interaction within the community.
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            ## Attribution
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
         | 
| 77 | 
            +
            available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            [homepage]: https://www.contributor-covenant.org
         | 
| 82 | 
            +
             | 
| 83 | 
            +
            For answers to common questions about this code of conduct, see the FAQ at
         | 
| 84 | 
            +
            https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
         | 
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            The MIT License (MIT)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2023 tetetratra
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            The above copyright notice and this permission notice shall be included in
         | 
| 13 | 
            +
            all copies or substantial portions of the Software.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 21 | 
            +
            THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,57 @@ | |
| 1 | 
            +
            # EnsembleCast
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Evaluate block in first argument.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ```ruby
         | 
| 10 | 
            +
            gem 'ensemble_cast'
         | 
| 11 | 
            +
            ```
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            And then execute:
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                $ bundle install
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            Or install it yourself as:
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                $ gem install ensemble_cast
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ## Usage
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            You can use `Module#ensemble(method_name)` method.
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            When you call `ensemble(method_name)`,
         | 
| 26 | 
            +
            block passed to `method_name` will be evaluated in the context of the first argument of the block.
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            example:
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            ```ruby
         | 
| 31 | 
            +
            class Array
         | 
| 32 | 
            +
              ensemble def my_select
         | 
| 33 | 
            +
                select { |e| yield(e) }
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            [-2, -1, 0, 1, 2].my_select { even? && !negative? }
         | 
| 38 | 
            +
            # => [0, 2]
         | 
| 39 | 
            +
            ```
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            <!-- ## Development -->
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            <!-- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. -->
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            <!-- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). -->
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            ## Contributing
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ensemble_cast. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ensemble_cast/blob/main/CODE_OF_CONDUCT.md).
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            ## License
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            ## Code of Conduct
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            Everyone interacting in the EnsembleCast project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ensemble_cast/blob/main/CODE_OF_CONDUCT.md).
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            # frozen_string_literal: true
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            require "bundler/setup"
         | 
| 5 | 
            +
            require "ensemble_cast"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            # You can add fixtures and/or initialization code here to make experimenting
         | 
| 8 | 
            +
            # with your gem easier. You can also use a different console, if you like.
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         | 
| 11 | 
            +
            # require "pry"
         | 
| 12 | 
            +
            # Pry.start
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            require "irb"
         | 
| 15 | 
            +
            IRB.start(__FILE__)
         | 
    
        data/bin/setup
    ADDED
    
    
| @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative "lib/ensemble_cast/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |spec|
         | 
| 6 | 
            +
              spec.name = "ensemble_cast"
         | 
| 7 | 
            +
              spec.version = EnsembleCast::VERSION
         | 
| 8 | 
            +
              spec.authors = ["tetetratra"]
         | 
| 9 | 
            +
              spec.email = ["44367208+tetetratra@users.noreply.github.com"]
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              spec.summary = "Evaluate block in first argument"
         | 
| 12 | 
            +
              spec.description = <<~EOS
         | 
| 13 | 
            +
                Evaluate block in first argument.
         | 
| 14 | 
            +
                You can use `Module#ensemble(method_name)` method.
         | 
| 15 | 
            +
                When you call `ensemble(method_name)`, block passed to `method_name` will be evaluated in the context of the first argument of the block.
         | 
| 16 | 
            +
              EOS
         | 
| 17 | 
            +
              spec.homepage = "https://github.com/tetetratra/ensemble"
         | 
| 18 | 
            +
              spec.license = "MIT"
         | 
| 19 | 
            +
              spec.required_ruby_version = ">= 3.1.0"
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.metadata["homepage_uri"] = spec.homepage
         | 
| 22 | 
            +
              spec.metadata["source_code_uri"] = "https://github.com/tetetratra/ensemble"
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              # Specify which files should be added to the gem when it is released.
         | 
| 25 | 
            +
              # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
         | 
| 26 | 
            +
              spec.files = Dir.chdir(File.expand_path(__dir__)) do
         | 
| 27 | 
            +
                `git ls-files -z`.split("\x0").reject do |f|
         | 
| 28 | 
            +
                  (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
              spec.bindir = "exe"
         | 
| 32 | 
            +
              spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
         | 
| 33 | 
            +
              spec.require_paths = ["lib"]
         | 
| 34 | 
            +
              spec.extensions = ["ext/ensemble_cast/extconf.rb"]
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              # Uncomment to register a new dependency of your gem
         | 
| 37 | 
            +
              # spec.add_dependency "example-gem", "~> 1.0"
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              # For more information and examples about making a new gem, check out our
         | 
| 40 | 
            +
              # guide at: https://bundler.io/guides/creating_gem.html
         | 
| 41 | 
            +
            end
         | 
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            #include "ensemble_cast.h"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            VALUE rb_mEnsembleCast;
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            struct rb_captured_block *vm_bh_to_iseq_block(VALUE block_handler) {
         | 
| 6 | 
            +
              struct rb_captured_block *captured = ((void *)((block_handler) & ~0x03));
         | 
| 7 | 
            +
              return captured;
         | 
| 8 | 
            +
            }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            VALUE
         | 
| 11 | 
            +
            vm_cf_block_handler(rb_control_frame_t *cfp) {
         | 
| 12 | 
            +
              const VALUE *ep = cfp->ep;
         | 
| 13 | 
            +
              return ep[-1];
         | 
| 14 | 
            +
            }
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            VALUE
         | 
| 17 | 
            +
            rb_tracepoint_call(VALUE _self) { // Rubyで記述されたメソッド
         | 
| 18 | 
            +
              struct rb_captured_block *prev2_cfp_bh =
         | 
| 19 | 
            +
                  (struct rb_captured_block *)vm_bh_to_iseq_block(
         | 
| 20 | 
            +
                      vm_cf_block_handler((rb_current_ec()->cfp + 2)));
         | 
| 21 | 
            +
              if (prev2_cfp_bh == NULL) {
         | 
| 22 | 
            +
                return Qnil;
         | 
| 23 | 
            +
              }
         | 
| 24 | 
            +
              if (prev2_cfp_bh->code.iseq == NULL) {
         | 
| 25 | 
            +
                return Qnil;
         | 
| 26 | 
            +
              }
         | 
| 27 | 
            +
              if (prev2_cfp_bh->code.iseq->body->param.size != 0) {
         | 
| 28 | 
            +
                return Qnil;
         | 
| 29 | 
            +
              }
         | 
| 30 | 
            +
              // ブロック引数が積まれるようにする
         | 
| 31 | 
            +
              prev2_cfp_bh->code.iseq->body->param.flags.has_lead = 1;
         | 
| 32 | 
            +
              prev2_cfp_bh->code.iseq->body->param.flags.ambiguous_param0 = 1;
         | 
| 33 | 
            +
              prev2_cfp_bh->code.iseq->body->param.size = 1;
         | 
| 34 | 
            +
              prev2_cfp_bh->code.iseq->body->param.lead_num = 1;
         | 
| 35 | 
            +
              prev2_cfp_bh->code.iseq->body->local_table_size = 1;
         | 
| 36 | 
            +
              return Qnil;
         | 
| 37 | 
            +
            }
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            VALUE
         | 
| 40 | 
            +
            rb_tracepoint_b_call(VALUE _self) {
         | 
| 41 | 
            +
              if ((rb_current_ec()->cfp + 3)->iseq == NULL) {
         | 
| 42 | 
            +
                return Qnil;
         | 
| 43 | 
            +
              }
         | 
| 44 | 
            +
              VALUE block_arg = *((rb_current_ec()->cfp + 2)->ep - 3); // 積んだ引数を取得
         | 
| 45 | 
            +
              (rb_current_ec()->cfp + 2)->self = block_arg; // selfを置き換え
         | 
| 46 | 
            +
              return Qnil;
         | 
| 47 | 
            +
            }
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            void Init_ensemble_cast(void) {
         | 
| 50 | 
            +
              rb_mEnsembleCast = rb_define_module("EnsembleCast");
         | 
| 51 | 
            +
             | 
| 52 | 
            +
              rb_define_global_function("tracepoint_call", rb_tracepoint_call, 0);
         | 
| 53 | 
            +
              rb_define_global_function("tracepoint_b_call", rb_tracepoint_b_call, 0);
         | 
| 54 | 
            +
            }
         | 
| @@ -0,0 +1,300 @@ | |
| 1 | 
            +
            #ifndef ENSEMBLE_CAST_H
         | 
| 2 | 
            +
            #define ENSEMBLE_CAST_H 1
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            #include "ruby.h"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            #endif /* ENSEMBLE_CAST_H */
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            typedef struct rb_iseq_struct {
         | 
| 9 | 
            +
              VALUE flags;   /* 1 */
         | 
| 10 | 
            +
              VALUE wrapper; /* 2 */
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              struct rb_iseq_constant_body *body; /* 3 */
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              union {                                   /* 4, 5 words */
         | 
| 15 | 
            +
                struct iseq_compile_data *compile_data; /* used at compile time */
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                struct {
         | 
| 18 | 
            +
                  VALUE obj;
         | 
| 19 | 
            +
                  int index;
         | 
| 20 | 
            +
                } loader;
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                struct {
         | 
| 23 | 
            +
                  struct rb_hook_list_struct *local_hooks;
         | 
| 24 | 
            +
                  rb_event_flag_t global_trace_events;
         | 
| 25 | 
            +
                } exec;
         | 
| 26 | 
            +
              } aux;
         | 
| 27 | 
            +
            } rb_iseq_t;
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            typedef struct rb_control_frame_struct {
         | 
| 30 | 
            +
              const VALUE *pc;       /* cfp[0] */
         | 
| 31 | 
            +
              VALUE *sp;             /* cfp[1] */
         | 
| 32 | 
            +
              const rb_iseq_t *iseq; /* cfp[2] */
         | 
| 33 | 
            +
              VALUE self;            /* cfp[3] / block[0] */
         | 
| 34 | 
            +
              const VALUE *ep;       /* cfp[4] / block[1] */
         | 
| 35 | 
            +
              const void *block_code;
         | 
| 36 | 
            +
              /* cfp[5] / block[2] */ /* iseq or ifunc or forwarded block handler */
         | 
| 37 | 
            +
              VALUE *__bp__;
         | 
| 38 | 
            +
              /* cfp[6] */ /* outside vm_push_frame, use vm_base_ptr instead. */
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              // Return address for YJIT code
         | 
| 41 | 
            +
              void *jit_return;
         | 
| 42 | 
            +
            } rb_control_frame_t;
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            typedef struct rb_ensure_entry {
         | 
| 45 | 
            +
              VALUE marker;
         | 
| 46 | 
            +
              VALUE (*e_proc)(VALUE);
         | 
| 47 | 
            +
              VALUE data2;
         | 
| 48 | 
            +
            } rb_ensure_entry_t;
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            typedef struct rb_ensure_list {
         | 
| 51 | 
            +
              struct rb_ensure_list *next;
         | 
| 52 | 
            +
              struct rb_ensure_entry entry;
         | 
| 53 | 
            +
            } rb_ensure_list_t;
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            enum method_missing_reason {
         | 
| 56 | 
            +
              MISSING_NOENTRY = 0x00,
         | 
| 57 | 
            +
              MISSING_PRIVATE = 0x01,
         | 
| 58 | 
            +
              MISSING_PROTECTED = 0x02,
         | 
| 59 | 
            +
              MISSING_FCALL = 0x04,
         | 
| 60 | 
            +
              MISSING_VCALL = 0x08,
         | 
| 61 | 
            +
              MISSING_SUPER = 0x10,
         | 
| 62 | 
            +
              MISSING_MISSING = 0x20,
         | 
| 63 | 
            +
              MISSING_NONE = 0x40
         | 
| 64 | 
            +
            };
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            #define BITFIELD(type, name, size) type name : size
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            typedef struct rb_execution_context_struct {
         | 
| 69 | 
            +
              /* execution information */
         | 
| 70 | 
            +
              VALUE *vm_stack;      /* must free, must mark */
         | 
| 71 | 
            +
              size_t vm_stack_size; /* size in word (byte size / sizeof(VALUE)) */
         | 
| 72 | 
            +
              rb_control_frame_t *cfp;
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              struct rb_vm_tag *tag;
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              /* interrupt flags */
         | 
| 77 | 
            +
              // rb_atomic_t interrupt_flag;
         | 
| 78 | 
            +
              // rb_atomic_t interrupt_mask; /* size should match flag */
         | 
| 79 | 
            +
            #if defined(USE_VM_CLOCK) && USE_VM_CLOCK
         | 
| 80 | 
            +
              uint32_t checked_clock;
         | 
| 81 | 
            +
            #endif
         | 
| 82 | 
            +
             | 
| 83 | 
            +
              // rb_fiber_t *fiber_ptr;
         | 
| 84 | 
            +
              struct rb_thread_struct *thread_ptr;
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              /* storage (ec (fiber) local) */
         | 
| 87 | 
            +
              struct rb_id_table *local_storage;
         | 
| 88 | 
            +
              VALUE local_storage_recursive_hash;
         | 
| 89 | 
            +
              VALUE local_storage_recursive_hash_for_trace;
         | 
| 90 | 
            +
             | 
| 91 | 
            +
              /* eval env */
         | 
| 92 | 
            +
              const VALUE *root_lep;
         | 
| 93 | 
            +
              VALUE root_svar;
         | 
| 94 | 
            +
             | 
| 95 | 
            +
              /* ensure & callcc */
         | 
| 96 | 
            +
              rb_ensure_list_t *ensure_list;
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              /* trace information */
         | 
| 99 | 
            +
              struct rb_trace_arg_struct *trace_arg;
         | 
| 100 | 
            +
             | 
| 101 | 
            +
              /* temporary places */
         | 
| 102 | 
            +
              VALUE errinfo;
         | 
| 103 | 
            +
              VALUE passed_block_handler; /* for rb_iterate */
         | 
| 104 | 
            +
             | 
| 105 | 
            +
              uint8_t raised_flag; /* only 3 bits needed */
         | 
| 106 | 
            +
             | 
| 107 | 
            +
              /* n.b. only 7 bits needed, really: */
         | 
| 108 | 
            +
              BITFIELD(enum method_missing_reason, method_missing_reason, 8);
         | 
| 109 | 
            +
             | 
| 110 | 
            +
              VALUE private_const_reference;
         | 
| 111 | 
            +
             | 
| 112 | 
            +
              /* for GC */
         | 
| 113 | 
            +
              // struct {
         | 
| 114 | 
            +
              //   VALUE *stack_start;
         | 
| 115 | 
            +
              //   VALUE *stack_end;
         | 
| 116 | 
            +
              //   size_t stack_maxsize;
         | 
| 117 | 
            +
              //   RUBY_ALIGNAS(SIZEOF_VALUE) jmp_buf regs;
         | 
| 118 | 
            +
              // } machine;
         | 
| 119 | 
            +
            } rb_execution_context_t;
         | 
| 120 | 
            +
             | 
| 121 | 
            +
            struct rb_captured_block {
         | 
| 122 | 
            +
              VALUE self;
         | 
| 123 | 
            +
              const VALUE *ep;
         | 
| 124 | 
            +
              union {
         | 
| 125 | 
            +
                const rb_iseq_t *iseq;
         | 
| 126 | 
            +
                const struct vm_ifunc *ifunc;
         | 
| 127 | 
            +
                VALUE val;
         | 
| 128 | 
            +
              } code;
         | 
| 129 | 
            +
            };
         | 
| 130 | 
            +
             | 
| 131 | 
            +
            typedef struct rb_code_position_struct {
         | 
| 132 | 
            +
              int lineno;
         | 
| 133 | 
            +
              int column;
         | 
| 134 | 
            +
            } rb_code_position_t;
         | 
| 135 | 
            +
             | 
| 136 | 
            +
            typedef struct rb_code_location_struct {
         | 
| 137 | 
            +
              rb_code_position_t beg_pos;
         | 
| 138 | 
            +
              rb_code_position_t end_pos;
         | 
| 139 | 
            +
            } rb_code_location_t;
         | 
| 140 | 
            +
             | 
| 141 | 
            +
            typedef signed long rb_snum_t;
         | 
| 142 | 
            +
             | 
| 143 | 
            +
            typedef struct rb_iseq_location_struct {
         | 
| 144 | 
            +
              VALUE pathobj;      /* String (path) or Array [path, realpath]. Frozen. */
         | 
| 145 | 
            +
              VALUE base_label;   /* String */
         | 
| 146 | 
            +
              VALUE label;        /* String */
         | 
| 147 | 
            +
              VALUE first_lineno; /* TODO: may be unsigned short */
         | 
| 148 | 
            +
              int node_id;
         | 
| 149 | 
            +
              rb_code_location_t code_location;
         | 
| 150 | 
            +
            } rb_iseq_location_t;
         | 
| 151 | 
            +
             | 
| 152 | 
            +
            struct rb_iseq_constant_body {
         | 
| 153 | 
            +
              enum iseq_type {
         | 
| 154 | 
            +
                ISEQ_TYPE_TOP,
         | 
| 155 | 
            +
                ISEQ_TYPE_METHOD,
         | 
| 156 | 
            +
                ISEQ_TYPE_BLOCK,
         | 
| 157 | 
            +
                ISEQ_TYPE_CLASS,
         | 
| 158 | 
            +
                ISEQ_TYPE_RESCUE,
         | 
| 159 | 
            +
                ISEQ_TYPE_ENSURE,
         | 
| 160 | 
            +
                ISEQ_TYPE_EVAL,
         | 
| 161 | 
            +
                ISEQ_TYPE_MAIN,
         | 
| 162 | 
            +
                ISEQ_TYPE_PLAIN
         | 
| 163 | 
            +
              } type; /* instruction sequence type */
         | 
| 164 | 
            +
             | 
| 165 | 
            +
              unsigned int iseq_size;
         | 
| 166 | 
            +
              VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
         | 
| 167 | 
            +
             | 
| 168 | 
            +
              /**
         | 
| 169 | 
            +
               * parameter information
         | 
| 170 | 
            +
               *
         | 
| 171 | 
            +
               *  def m(a1, a2, ..., aM,                    # mandatory
         | 
| 172 | 
            +
               *        b1=(...), b2=(...), ..., bN=(...),  # optional
         | 
| 173 | 
            +
               *        *c,                                 # rest
         | 
| 174 | 
            +
               *        d1, d2, ..., dO,                    # post
         | 
| 175 | 
            +
               *        e1:(...), e2:(...), ..., eK:(...),  # keyword
         | 
| 176 | 
            +
               *        **f,                                # keyword_rest
         | 
| 177 | 
            +
               *        &g)                                 # block
         | 
| 178 | 
            +
               * =>
         | 
| 179 | 
            +
               *
         | 
| 180 | 
            +
               *  lead_num     = M
         | 
| 181 | 
            +
               *  opt_num      = N
         | 
| 182 | 
            +
               *  rest_start   = M+N
         | 
| 183 | 
            +
               *  post_start   = M+N+(*1)
         | 
| 184 | 
            +
               *  post_num     = O
         | 
| 185 | 
            +
               *  keyword_num  = K
         | 
| 186 | 
            +
               *  block_start  = M+N+(*1)+O+K
         | 
| 187 | 
            +
               *  keyword_bits = M+N+(*1)+O+K+(&1)
         | 
| 188 | 
            +
               *  size         = M+N+O+(*1)+K+(&1)+(**1) // parameter size.
         | 
| 189 | 
            +
               */
         | 
| 190 | 
            +
             | 
| 191 | 
            +
              struct {
         | 
| 192 | 
            +
                struct {
         | 
| 193 | 
            +
                  unsigned int has_lead : 1;
         | 
| 194 | 
            +
                  unsigned int has_opt : 1;
         | 
| 195 | 
            +
                  unsigned int has_rest : 1;
         | 
| 196 | 
            +
                  unsigned int has_post : 1;
         | 
| 197 | 
            +
                  unsigned int has_kw : 1;
         | 
| 198 | 
            +
                  unsigned int has_kwrest : 1;
         | 
| 199 | 
            +
                  unsigned int has_block : 1;
         | 
| 200 | 
            +
             | 
| 201 | 
            +
                  unsigned int ambiguous_param0 : 1; /* {|a|} */
         | 
| 202 | 
            +
                  unsigned int accepts_no_kwarg : 1;
         | 
| 203 | 
            +
                  unsigned int ruby2_keywords : 1;
         | 
| 204 | 
            +
                } flags;
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                unsigned int size;
         | 
| 207 | 
            +
             | 
| 208 | 
            +
                int lead_num;
         | 
| 209 | 
            +
                int opt_num;
         | 
| 210 | 
            +
                int rest_start;
         | 
| 211 | 
            +
                int post_start;
         | 
| 212 | 
            +
                int post_num;
         | 
| 213 | 
            +
                int block_start;
         | 
| 214 | 
            +
             | 
| 215 | 
            +
                const VALUE *opt_table; /* (opt_num + 1) entries. */
         | 
| 216 | 
            +
                /* opt_num and opt_table:
         | 
| 217 | 
            +
                 *
         | 
| 218 | 
            +
                 * def foo o1=e1, o2=e2, ..., oN=eN
         | 
| 219 | 
            +
                 * #=>
         | 
| 220 | 
            +
                 *   # prologue code
         | 
| 221 | 
            +
                 *   A1: e1
         | 
| 222 | 
            +
                 *   A2: e2
         | 
| 223 | 
            +
                 *   ...
         | 
| 224 | 
            +
                 *   AN: eN
         | 
| 225 | 
            +
                 *   AL: body
         | 
| 226 | 
            +
                 * opt_num = N
         | 
| 227 | 
            +
                 * opt_table = [A1, A2, ..., AN, AL]
         | 
| 228 | 
            +
                 */
         | 
| 229 | 
            +
             | 
| 230 | 
            +
                const struct rb_iseq_param_keyword {
         | 
| 231 | 
            +
                  int num;
         | 
| 232 | 
            +
                  int required_num;
         | 
| 233 | 
            +
                  int bits_start;
         | 
| 234 | 
            +
                  int rest_start;
         | 
| 235 | 
            +
                  const ID *table;
         | 
| 236 | 
            +
                  VALUE *default_values;
         | 
| 237 | 
            +
                } * keyword;
         | 
| 238 | 
            +
              } param;
         | 
| 239 | 
            +
             | 
| 240 | 
            +
              rb_iseq_location_t location;
         | 
| 241 | 
            +
             | 
| 242 | 
            +
              /* insn info, must be freed */
         | 
| 243 | 
            +
              struct iseq_insn_info {
         | 
| 244 | 
            +
                const struct iseq_insn_info_entry *body;
         | 
| 245 | 
            +
                unsigned int *positions;
         | 
| 246 | 
            +
                unsigned int size;
         | 
| 247 | 
            +
              } insns_info;
         | 
| 248 | 
            +
             | 
| 249 | 
            +
              const ID *local_table; /* must free */
         | 
| 250 | 
            +
             | 
| 251 | 
            +
              /* catch table */
         | 
| 252 | 
            +
              struct iseq_catch_table *catch_table;
         | 
| 253 | 
            +
             | 
| 254 | 
            +
              /* for child iseq */
         | 
| 255 | 
            +
              const struct rb_iseq_struct *parent_iseq;
         | 
| 256 | 
            +
              struct rb_iseq_struct *local_iseq; /* local_iseq->flip_cnt can be modified */
         | 
| 257 | 
            +
             | 
| 258 | 
            +
              union iseq_inline_storage_entry *is_entries;
         | 
| 259 | 
            +
              struct rb_call_data *call_data; // struct rb_call_data calls[ci_size];
         | 
| 260 | 
            +
             | 
| 261 | 
            +
              struct {
         | 
| 262 | 
            +
                rb_snum_t flip_count;
         | 
| 263 | 
            +
                VALUE script_lines;
         | 
| 264 | 
            +
                VALUE coverage;
         | 
| 265 | 
            +
                VALUE pc2branchindex;
         | 
| 266 | 
            +
                VALUE *original_iseq;
         | 
| 267 | 
            +
              } variable;
         | 
| 268 | 
            +
             | 
| 269 | 
            +
              unsigned int local_table_size;
         | 
| 270 | 
            +
              unsigned int is_size;
         | 
| 271 | 
            +
              unsigned int ci_size;
         | 
| 272 | 
            +
              unsigned int stack_max; /* for stack overflow check */
         | 
| 273 | 
            +
             | 
| 274 | 
            +
              char catch_except_p; /* If a frame of this ISeq may catch exception, set TRUE
         | 
| 275 | 
            +
                                    */
         | 
| 276 | 
            +
              // If true, this ISeq is leaf *and* backtraces are not used, for example,
         | 
| 277 | 
            +
              // by rb_profile_frames. We verify only leafness on VM_CHECK_MODE though.
         | 
| 278 | 
            +
              // Note that GC allocations might use backtraces due to
         | 
| 279 | 
            +
              // ObjectSpace#trace_object_allocations.
         | 
| 280 | 
            +
              // For more details, see: https://bugs.ruby-lang.org/issues/16956
         | 
| 281 | 
            +
              bool builtin_inline_p;
         | 
| 282 | 
            +
              struct rb_id_table *outer_variables;
         | 
| 283 | 
            +
             | 
| 284 | 
            +
              const rb_iseq_t *mandatory_only_iseq;
         | 
| 285 | 
            +
             | 
| 286 | 
            +
            #if USE_MJIT
         | 
| 287 | 
            +
              /* The following fields are MJIT related info.  */
         | 
| 288 | 
            +
              VALUE(*jit_func)
         | 
| 289 | 
            +
              (struct rb_execution_context_struct *,
         | 
| 290 | 
            +
               struct rb_control_frame_struct
         | 
| 291 | 
            +
                   *);                   /* function pointer for loaded native code */
         | 
| 292 | 
            +
              long unsigned total_calls; /* number of total calls with `mjit_exec()` */
         | 
| 293 | 
            +
              struct rb_mjit_unit *jit_unit;
         | 
| 294 | 
            +
            #endif
         | 
| 295 | 
            +
             | 
| 296 | 
            +
              // rb_yjit_block_array_array_t
         | 
| 297 | 
            +
              //     yjit_blocks; // empty, or has a size equal to iseq_size
         | 
| 298 | 
            +
            };
         | 
| 299 | 
            +
             | 
| 300 | 
            +
            extern rb_execution_context_t *rb_current_ec(void);
         | 
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative "ensemble_cast/version"
         | 
| 4 | 
            +
            require_relative "ensemble_cast/ensemble_cast"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module EnsembleCast
         | 
| 7 | 
            +
              @methods = []
         | 
| 8 | 
            +
              @enable = false
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              TP_CALL = TracePoint.trace(:call) do |tp|
         | 
| 11 | 
            +
                next unless @methods.any?([tp.self.class, tp.method_id])
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                tracepoint_call
         | 
| 14 | 
            +
                @enable = true
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              TP_B_CALL = TracePoint.trace(:b_call) do |tp|
         | 
| 18 | 
            +
                next unless @enable
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                tracepoint_b_call
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              TP_RETURN = TracePoint.trace(:return) do |tp|
         | 
| 24 | 
            +
                next unless @methods.any?([tp.self.class, tp.method_id])
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                @enable = false
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              class << self
         | 
| 30 | 
            +
                def add(klass, method)
         | 
| 31 | 
            +
                  @methods << [klass, method]
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                def delete(klass, method)
         | 
| 35 | 
            +
                  @methods.detele(klass, method)
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            class Module
         | 
| 41 | 
            +
              def ensemble(method)
         | 
| 42 | 
            +
                Inside.add(self, method.name.to_sym)
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,62 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: ensemble_cast
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - tetetratra
         | 
| 8 | 
            +
            autorequire:
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2023-04-23 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: |
         | 
| 14 | 
            +
              Evaluate block in first argument.
         | 
| 15 | 
            +
              You can use `Module#ensemble(method_name)` method.
         | 
| 16 | 
            +
              When you call `ensemble(method_name)`, block passed to `method_name` will be evaluated in the context of the first argument of the block.
         | 
| 17 | 
            +
            email:
         | 
| 18 | 
            +
            - 44367208+tetetratra@users.noreply.github.com
         | 
| 19 | 
            +
            executables: []
         | 
| 20 | 
            +
            extensions:
         | 
| 21 | 
            +
            - ext/ensemble_cast/extconf.rb
         | 
| 22 | 
            +
            extra_rdoc_files: []
         | 
| 23 | 
            +
            files:
         | 
| 24 | 
            +
            - CODE_OF_CONDUCT.md
         | 
| 25 | 
            +
            - Gemfile
         | 
| 26 | 
            +
            - LICENSE.txt
         | 
| 27 | 
            +
            - README.md
         | 
| 28 | 
            +
            - Rakefile
         | 
| 29 | 
            +
            - bin/console
         | 
| 30 | 
            +
            - bin/setup
         | 
| 31 | 
            +
            - ensemble_cast.gemspec
         | 
| 32 | 
            +
            - ext/ensemble_cast/ensemble_cast.c
         | 
| 33 | 
            +
            - ext/ensemble_cast/ensemble_cast.h
         | 
| 34 | 
            +
            - ext/ensemble_cast/extconf.rb
         | 
| 35 | 
            +
            - lib/ensemble_cast.rb
         | 
| 36 | 
            +
            - lib/ensemble_cast/version.rb
         | 
| 37 | 
            +
            homepage: https://github.com/tetetratra/ensemble
         | 
| 38 | 
            +
            licenses:
         | 
| 39 | 
            +
            - MIT
         | 
| 40 | 
            +
            metadata:
         | 
| 41 | 
            +
              homepage_uri: https://github.com/tetetratra/ensemble
         | 
| 42 | 
            +
              source_code_uri: https://github.com/tetetratra/ensemble
         | 
| 43 | 
            +
            post_install_message:
         | 
| 44 | 
            +
            rdoc_options: []
         | 
| 45 | 
            +
            require_paths:
         | 
| 46 | 
            +
            - lib
         | 
| 47 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 48 | 
            +
              requirements:
         | 
| 49 | 
            +
              - - ">="
         | 
| 50 | 
            +
                - !ruby/object:Gem::Version
         | 
| 51 | 
            +
                  version: 3.1.0
         | 
| 52 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 53 | 
            +
              requirements:
         | 
| 54 | 
            +
              - - ">="
         | 
| 55 | 
            +
                - !ruby/object:Gem::Version
         | 
| 56 | 
            +
                  version: '0'
         | 
| 57 | 
            +
            requirements: []
         | 
| 58 | 
            +
            rubygems_version: 3.3.3
         | 
| 59 | 
            +
            signing_key:
         | 
| 60 | 
            +
            specification_version: 4
         | 
| 61 | 
            +
            summary: Evaluate block in first argument
         | 
| 62 | 
            +
            test_files: []
         |