<commit_before>#ifndef RBX_BUILTIN_NATIVEMETHOD_HPP
#define RBX_BUILTIN_NATIVEMETHOD_HPP

/* Project */
#include "builtin/executable.hpp"
#include "builtin/task.hpp"

#include "message.hpp"
#include "vm.hpp"

#include "vmnativemethod.hpp"


namespace rubinius {

  /**
   *  The various special method arities from a
   *  C method. If not one of these, then the
   *  number denotes the exact number of args
   *  instead.
   */
  enum Arity {
    ARGS_IN_RUBY_ARRAY = -3,
    RECEIVER_PLUS_ARGS_IN_RUBY_ARRAY = -2,
    ARG_COUNT_ARGS_IN_C_ARRAY_PLUS_RECEIVER = -1
  };


  /* The various function signatures needed since C++ requires strict typing here. */

  /** Generic function pointer used to store any type of functor. */
  typedef     void (*GenericFunctor)(void);

  /* Actual functor types. */

  typedef HandleTo (*ArgcFunctor)(int, HandleTo*, HandleTo);
  typedef HandleTo (*OneArgFunctor)(HandleTo);
  typedef HandleTo (*TwoArgFunctor)(HandleTo, HandleTo);
  typedef HandleTo (*ThreeArgFunctor)(HandleTo, HandleTo, HandleTo);


  /**
   *  Ruby side of a NativeMethod, i.e. a C-implemented method.
   *
   *  The possible signatures for the C function are:
   *
   *    VALUE func(VALUE argument_array);
   *    VALUE func(VALUE receiver, VALUE argument_array);
   *    VALUE func(VALUE receiver, int argument_count, VALUE*);
   *    VALUE func(VALUE receiver, ...);    // Some limited number of VALUE arguments
   *
   *  VALUE is an opaque type from which a handle to the actual object
   *  can be extracted. User code never operates on the VALUE itself.
   */
  class NativeMethod : public Executable
  {
    public:   /* Ctors */

      template <typename FunctorType>
      static NativeMethod* create(FunctorType functor, int arity)
      {
        NativeMethod* obj = new NativeMethod();
        obj->my_functor = reinterpret_cast<GenericFunctor>(functor);
        obj->my_arity = Fixnum::from(arity);

        return obj;<commit_msg>Functor types for up to receiver + 5 arguments.<commit_after>#ifndef RBX_BUILTIN_NATIVEMETHOD_HPP
#define RBX_BUILTIN_NATIVEMETHOD_HPP

/* Project */
#include "builtin/executable.hpp"
#include "builtin/task.hpp"

#include "message.hpp"
#include "vm.hpp"

#include "vmnativemethod.hpp"


namespace rubinius {

  /**
   *  The various special method arities from a
   *  C method. If not one of these, then the
   *  number denotes the exact number of args
   *  instead.
   */
  enum Arity {
    ARGS_IN_RUBY_ARRAY = -3,
    RECEIVER_PLUS_ARGS_IN_RUBY_ARRAY = -2,
    ARG_COUNT_ARGS_IN_C_ARRAY_PLUS_RECEIVER = -1
  };


  /* The various function signatures needed since C++ requires strict typing here. */

  /** Generic function pointer used to store any type of functor. */
  typedef     void (*GenericFunctor)(void);

  /* Actual functor types. */

  typedef HandleTo (*ArgcFunctor)     (int, HandleTo*, HandleTo);
  typedef HandleTo (*OneArgFunctor)   (HandleTo);
  typedef HandleTo (*TwoArgFunctor)   (HandleTo, HandleTo);
  typedef HandleTo (*ThreeArgFunctor) (HandleTo, HandleTo, HandleTo);
  typedef HandleTo (*FourArgFunctor)  (HandleTo, HandleTo, HandleTo, HandleTo);
  typedef HandleTo (*FiveArgFunctor)  (HandleTo, HandleTo, HandleTo, HandleTo, HandleTo);
  typedef HandleTo (*SixArgFunctor)   (HandleTo, HandleTo, HandleTo, HandleTo, HandleTo, HandleTo);


  /**
   *  Ruby side of a NativeMethod, i.e. a C-implemented method.
   *
   *  The possible signatures for the C function are:
   *
   *    VALUE func(VALUE argument_array);
   *    VALUE func(VALUE receiver, VALUE argument_array);
   *    VALUE func(VALUE receiver, int argument_count, VALUE*);
   *    VALUE func(VALUE receiver, ...);    // Some limited number of VALUE arguments
   *
   *  VALUE is an opaque type from which a handle to the actual object
   *  can be extracted. User code never operates on the VALUE itself.
   */
  class NativeMethod : public Executable
  {
    public:   /* Ctors */

      template <typename FunctorType>
      static NativeMethod* create(FunctorType functor, int arity)
      {
        NativeMethod* obj = new NativeMethod();
        obj->my_functor = reinterpret_cast<GenericFunctor>(functor);
        obj->my_arity = Fixnum::from(arity);

        return obj;
{'fraction_non_alphanumeric': 0.0979649787032655, 'fraction_numerical': 0.001656412683388547, 'mean_word_length': 3.375776397515528, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5909619', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1297, 'n_words': 398}