All the core function are buit-in?

Discussion in 'Ruby' started by Free Kickr, Sep 13, 2009.

  1. Free Kickr

    Free Kickr Guest

    Before posting, I went thru the offical doc and some searching forum,
    still hvn't found how to view the ruby core component source code.

    For example, I'd like to know how the Enumerable implemented the
    iterator, from the http://www.ruby-doc.org/core/, I can see following
    files are involved:

    enum.c
    lib/set.rb
    lib/soap/property.rb
    ext/enumerator/enumerator.c

    But how to check out the code above?

    More things confusing me: For improving the performance, ruby builtin
    all the core component in parser?

    Thanks.
    --
    Posted via http://www.ruby-forum.com/.
     
    Free Kickr, Sep 13, 2009
    #1
    1. Advertising

  2. Free Kickr

    Ryan Davis Guest

    On Sep 13, 2009, at 00:10 , Free Kickr wrote:

    > Before posting, I went thru the offical doc and some searching forum,
    > still hvn't found how to view the ruby core component source code.
    >
    > For example, I'd like to know how the Enumerable implemented the
    > iterator, from the http://www.ruby-doc.org/core/, I can see following
    > files are involved:
    >
    > enum.c
    > lib/set.rb
    > lib/soap/property.rb
    > ext/enumerator/enumerator.c
    >
    > But how to check out the code above?


    * How to get Ruby

    The Ruby distribution files can be found in the following FTP site:

    ftp://ftp.ruby-lang.org/pub/ruby/

    The trunk of the Ruby source tree can be checked out with the
    following command:

    $ svn co http://svn.ruby-lang.org/repos/ruby/trunk/ ruby

    There are some other branches under development. Try the following
    command and see the list of branches:

    $ svn ls http://svn.ruby-lang.org/repos/ruby/branches/


    > More things confusing me: For improving the performance, ruby builtin
    > all the core component in parser?


    It should be (a bit) more clear once you have the code and can poke
    around.
     
    Ryan Davis, Sep 13, 2009
    #2
    1. Advertising

  3. Free Kickr

    Free Kickr Guest

    Thanks, I download the files and have a brief read of the 4 files:

    enum.c
    lib/set.rb
    lib/soap/property.rb
    ext/enumerator/enumerator.c

    Which was told related to Enumerable module, but from those, I still did
    not understand the how the iterator implementation such as "collect,
    select, inject...etc".

    In my imagination, I thought, there's Enumerable.rb which include the
    method
    def select...
    def collect...
    ...

    But it seems I was wrong, Could you pls give a little bit explaination?

    Appreicated!
    --
    Posted via http://www.ruby-forum.com/.
     
    Free Kickr, Sep 13, 2009
    #3
  4. Hi --

    On Sun, 13 Sep 2009, Free Kickr wrote:

    > Thanks, I download the files and have a brief read of the 4 files:
    >
    > enum.c
    > lib/set.rb
    > lib/soap/property.rb
    > ext/enumerator/enumerator.c
    >
    > Which was told related to Enumerable module, but from those, I still did
    > not understand the how the iterator implementation such as "collect,
    > select, inject...etc".
    >
    > In my imagination, I thought, there's Enumerable.rb which include the
    > method
    > def select...
    > def collect...
    > ...
    >
    > But it seems I was wrong, Could you pls give a little bit explaination?


    Usually toward the end of the C files there's a section where the C
    functions are bound to Ruby methods, like this:

    rb_define_method(rb_mEnumerable,"sort", enum_sort, 0);
    rb_define_method(rb_mEnumerable,"sort_by", enum_sort_by, 0);
    rb_define_method(rb_mEnumerable,"grep", enum_grep, 1);
    rb_define_method(rb_mEnumerable,"find", enum_find, -1);

    etc. That's your mapping from C to Ruby.


    David

    --
    David A. Black, Director
    Ruby Power and Light, LLC (http://www.rubypal.com)
    Ruby/Rails training, consulting, mentoring, code review
    Book: The Well-Grounded Rubyist (http://www.manning.com/black2)
     
    David A. Black, Sep 13, 2009
    #4
  5. Free Kickr

    Through Pass Guest

    Yeh, I do have noticed that mapping, but I searched all the source code
    directory, did not find the ruby method definition ...

    eg. for the
    rb_define_method(rb_mEnumerable, "collect", enum_collect, 0);
    but no source code file included string "enum_collect", only the static
    lib included ...

    I am not sure I have the source code tree, but I really downloaded all
    the ruby src tree by: $ svn co
    http://svn.ruby-lang.org/repos/ruby/trunk/ ruby

    Any help?

    -----------------
    > Usually toward the end of the C files there's a section where the C
    > functions are bound to Ruby methods, like this:
    >
    > rb_define_method(rb_mEnumerable,"sort", enum_sort, 0);
    > rb_define_method(rb_mEnumerable,"sort_by", enum_sort_by, 0);
    > rb_define_method(rb_mEnumerable,"grep", enum_grep, 1);
    > rb_define_method(rb_mEnumerable,"find", enum_find, -1);
    >
    > etc. That's your mapping from C to Ruby.
    >
    >
    > David

    ----------------
    --
    Posted via http://www.ruby-forum.com/.
     
    Through Pass, Sep 13, 2009
    #5
  6. Hi --

    On Sun, 13 Sep 2009, Through Pass wrote:

    > Yeh, I do have noticed that mapping, but I searched all the source code
    > directory, did not find the ruby method definition ...
    >
    > eg. for the
    > rb_define_method(rb_mEnumerable, "collect", enum_collect, 0);
    > but no source code file included string "enum_collect", only the static
    > lib included ...
    >
    > I am not sure I have the source code tree, but I really downloaded all
    > the ruby src tree by: $ svn co
    > http://svn.ruby-lang.org/repos/ruby/trunk/ ruby
    >
    > Any help?


    $ grep -B1 enum_collect *.c
    enum.c-static VALUE
    enum.c:enum_collect(obj)

    It should be there somewhere.


    David

    --
    David A. Black, Director
    Ruby Power and Light, LLC (http://www.rubypal.com)
    Ruby/Rails training, consulting, mentoring, code review
    Book: The Well-Grounded Rubyist (http://www.manning.com/black2)
     
    David A. Black, Sep 13, 2009
    #6
  7. Free Kickr

    Through Pass Guest

    Begin to understand ... Many Thanks ...
    -----
    >
    > $ grep -B1 enum_collect *.c
    > enum.c-static VALUE
    > enum.c:enum_collect(obj)
    >
    > It should be there somewhere.
    >
    >
    > David


    --
    Posted via http://www.ruby-forum.com/.
     
    Through Pass, Sep 13, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri
    Replies:
    2
    Views:
    326
    Henri
    Nov 29, 2004
  2. Xaver Hinterhuber

    function causing core dump

    Xaver Hinterhuber, May 10, 2004, in forum: Python
    Replies:
    4
    Views:
    325
    Terry Reedy
    May 10, 2004
  3. Robert Brewer

    RE: function causing core dump

    Robert Brewer, May 10, 2004, in forum: Python
    Replies:
    5
    Views:
    342
    Peter Otten
    May 17, 2004
  4. Replies:
    2
    Views:
    947
    Bengt Richter
    Aug 1, 2005
  5. Gyoung-Yoon Noh
    Replies:
    1
    Views:
    104
    James Britt
    Dec 24, 2005
Loading...

Share This Page