[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

node.h and nd_line

B. K. Oxley (binkley)

4/27/2005 3:52:00 PM

I'm interested in adding more precise source location information to
NODE structs. I see:

typedef struct RNode {
/* ... */
char *nd_file;
int nd_line;
/* ... */
} NODE;

But the accessor macros for nd_line look like this (spaces added for
email clarity):

#define nd_line(n) ((unsigned int) (((RNODE(n))->flags >> NODE_LSHIFT) &
NODE_LMASK))
#define nd_set_line(n,l) RNODE(n)->flags=((RNODE(n)->flags & ~(-1 << NODE_LSHIFT)) | (((l) &
NODE_LMASK) << NODE_LSHIFT))

What is going on? :)

What I'd like to do is add an int nd_pos member to RNode to record the
precise byte position in nd_file for the node, but I'm somewhat baffled
by the utter lack of ".nd_line" or "->nd_line" in the sources. Looking
at parse.y, frequently assign the nd_line(node) macro to
ruby_sourceline, but I do not grasp how that macro uses nd_line.


Thanks,
--binkley


6 Answers

Yukihiro Matsumoto

4/27/2005 3:57:00 PM

0

Hi,

In message "Re: node.h and nd_line"
on Thu, 28 Apr 2005 00:52:19 +0900, "B. K. Oxley (binkley)" <binkley@alumni.rice.edu> writes:

|#define nd_line(n) ((unsigned int) (((RNODE(n))->flags >> NODE_LSHIFT) &
|NODE_LMASK))
|#define nd_set_line(n,l) |RNODE(n)->flags=((RNODE(n)->flags & ~(-1 << NODE_LSHIFT)) | (((l) &
|NODE_LMASK) << NODE_LSHIFT))
|
|What is going on? :)

Line numbers are packed in the flags bits. It's a trick to save
memory. Since all nodes and objects shares same heap slot, adding an
extra field cost 4 bytes (or 8 bytes on 64bit machines) for every
object.

matz.


B. K. Oxley (binkley)

4/27/2005 4:04:00 PM

0

Yukihiro Matsumoto wrote:
> Line numbers are packed in the flags bits. It's a trick to save
> memory. Since all nodes and objects shares same heap slot, adding an
> extra field cost 4 bytes (or 8 bytes on 64bit machines) for every
> object.

What, then, is the purpose of the nd_line field? I do not find access
of the field in the sources.

$ find . -type f | xargs grep '\.nd_line'
$ find . -type f | xargs grep -- '->nd_line'


Thanks,
--binkley


B. K. Oxley (binkley)

4/27/2005 4:23:00 PM

0

B. K. Oxley (binkley) wrote:
> What, then, is the purpose of the nd_line field? I do not find access
> of the field in the sources.
>
> $ find . -type f | xargs grep '\.nd_line'
> $ find . -type f | xargs grep -- '->nd_line'

I see now. In the 1.8.2 sources, "int node_line" is still int he
definition of struct RNode; but when I grab the stable-snapshot tarball,
it is gone. I suppose it wasn't refactored away for the 1.8.2 build
although it wasn't used.

I suppose what I can do is replace the unused int (which could be
64-bits in an ILP model) with one for byte position and leave the
bit-fiddling alone for the fd_line macros. (Technically, the type
should be what ever the seek call uses on a given platform; one thing at
a time.)


Cheers,
--binkley


nobu.nokada

4/27/2005 4:28:00 PM

0

Hi,

At Thu, 28 Apr 2005 01:22:42 +0900,
B. K. Oxley (binkley) wrote in [ruby-talk:140076]:
> I see now. In the 1.8.2 sources, "int node_line" is still int he
> definition of struct RNode; but when I grab the stable-snapshot tarball,
> it is gone. I suppose it wasn't refactored away for the 1.8.2 build
> although it wasn't used.

What file are you seeing? RNode has never had such field at
all.

--
Nobu Nakada


B. K. Oxley (binkley)

4/27/2005 4:33:00 PM

0

nobu.nokada@softhome.net wrote:
> What file are you seeing? RNode has never had such field at
> all.

Drat. My error. I had a bad copy from previous edits when I looked
into adding byte position information a few weeks ago but was
interrupted by work. I unpacked a clean 1.8.2 tarball and the field is
clear absent. Apologies.


Cheers,
--binkley


What Me Worry?

5/18/2007 6:48:00 PM

0


"Adam Albright" <AA@ABC.net> wrote in message
news:0o6q43d57qkd73nacthmra3nmg79ounfqa@4ax.com...
> On Thu, 17 May 2007 13:30:25 -0500, David Hartung
> <dhart1ng@quixnet.net> wrote:
>
>>What Me Worry? wrote:
>>> "David Hartung" <dhart1ng@quixnet.net> wrote in message
>>> news:nrGdndbyGeB-FNbbnZ2dnUVZ_hadnZ2d@comcast.com...
>>>> What Me Worry? wrote:
>>>>> "David Hartung" <dhart1ng@quixnet.net> wrote in message
>>>>> news:Zv2dnVx-ofuEytbbnZ2dnUVZ_vrinZ2d@comcast.com...
>>>>>> What Me Worry? wrote:
>>>>>>
>>>>>>> Conservative Christians, under the Bush regime, have attempted to
>>>>>>> force
>>>>>>> a bill through Congress that would replace the Constitution with
>>>>>>> "God's
>>>>>>> Law", effectively rendering Constitutional law and common law
>>>>>>> doctrines
>>>>>>> null and void.
>>>>>> source?
>>>>> Are you trying to make us believe that you didn't know exactly what I
>>>>> was
>>>>> referring to? Of course you did.
>>>>> The cynically misleading and ultra-radical Constitution Restoration
>>>>> Act
>>>>> of 2004:
>>>>>
>>>>> http://www.peroutka2004.com/schedule/index.php?action=eventview&ev...
>>>>> http://en.wikipedia.org/wiki/Constitution_Resto...
>>>>> http://www.zmag.org/content/showarticle.cfm?I...
>>>>> http://www.dailykos.com/story/2004/10/23...
>>>>> (hundreds more sources where this came from)
>>>> What you claim, and what the bill said, are not the same thing.
>>>
>>> Do you specialize in lying and being wrong all the time? Must be a
>>> repug.
>>
>>No, I merely know how to read, and I try not to exaggerate. You may want
>>to
>>adopt such a policy.
>
> You need to try a lot harder not to exaggerate.

What would his postings consist of without exaggeration?