On Sat, Jun 03, 2006 at 03:25:02AM +0900, Logan Capaldo wrote: > On Jun 2, 2006, at 4:44 AM, Mauricio Fernandez wrote: [...] > >ruby relies on malloc(3) for low-level allocation, instead of doing it all > >with sbrk(2) and friends. > > > Interesting. (-- takes notes --). Almost seems like cheating :). But > in a good way. I'm going to have read gc.c. Speaking of reading ruby > source, is there an order you would recommend? Every time I look at > it I get overwhelmed by a) not knowing where to start and b) K&R C. I > can power-through the K&R C for the most part I think, but figuring > out what to read when is tougher. It depends on what you're interested in (/me slaps self). The easiest starting points would be array.c, hash.c (st.c if you really want to see the underlying st_table implementation, but it's just your regular hash table), string.c... that is, the core data structures. They are very easy to read, but maybe not that interesting ultimately due to this very straightforwardness. As for the more interesting stuff, here are some functions to begin with: * eval.c: * rb_eval: the basic AST walker * rb_call, rb_get_method_body: method dispatching (+method cache) at work * rb_add_method: managing the method tables (m_tbl) * rb_include_module: to see how proxy classes (T_ICLASS) work; bits of Ruby's object model .... * parse.y: the grammar + yylex (*tricky*) This is what I answered to a similar question 3 years ago in [74002]: Ruby Core * dln.c: wraps dlopen or the equiv. function of your platform, not very interesting * gc.c: quite easy to follow, of interest only if you want to know how the GC works internally, but it's just mark & sweep doing "common sense" things so you can safely skip it. * st.c: a hash table implementation used internally by Ruby, quite straightforward * eval.c: much harder to read as you have to know the node types to follow it; several functions are essentially a big switch() statement for a node * parse.y: this can help you see what different node types correspond to by having a look at the grammar. * regex.c: whatever, don't read it :-) some other .c files contain only support code Built-in classes Take the class you like, scroll down to the Init_xxx() function and locate the C function that implements the method you want to study. No particular order required. Hope this helps, -- Mauricio Fernandez - http://eigenclass.org - singular Ruby