node.h and nd_line

  • Thread starter B. K. Oxley (binkley)
  • Start date
B

B. K. Oxley (binkley)

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
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: node.h and nd_line"

|#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

B. K. Oxley (binkley)

Yukihiro said:
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

B. K. Oxley (binkley)

B. K. Oxley (binkley) said:
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
 
N

nobu.nokada

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.
 
B

B. K. Oxley (binkley)

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top