9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] scopes in kencc
@ 2007-04-27  1:12 Joel C. Salomon
  2007-04-27  2:04 ` Russ Cox
  0 siblings, 1 reply; 5+ messages in thread
From: Joel C. Salomon @ 2007-04-27  1:12 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I'm tracing through how the symbol table in kencc is maintained, and
I'm not finding the part where scopes are maintained.

E.g., when the compiler sees the declaration of *t in

	typdef int t;
	t foo;

	struct bar
	{
		int *t;
	};

where is it determined that LNAME is returned when *t is scanned
rather than LTYPE (the way it is returned in the declaration of foo)?

--Joel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] scopes in kencc
  2007-04-27  1:12 [9fans] scopes in kencc Joel C. Salomon
@ 2007-04-27  2:04 ` Russ Cox
  2007-04-27  2:48   ` Joel C. Salomon
  0 siblings, 1 reply; 5+ messages in thread
From: Russ Cox @ 2007-04-27  2:04 UTC (permalink / raw)
  To: 9fans

> where is it determined that LNAME is returned when *t is scanned
> rather than LTYPE (the way it is returned in the declaration of foo)?

grep shows that /sys/src/cmd/cc/lex.c is relevant,
since it contains

	s = lookup();
	if(s->macro) {
		...
	}
	yylval.sym = s;
	if(s->class == CTYPEDEF || s->class == CTYPESTR)
		return LTYPE;
	return s->lexical;

for the relevant bit of lexing.  you could trace back and 
see how s->class gets set.

russ



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] scopes in kencc
  2007-04-27  2:04 ` Russ Cox
@ 2007-04-27  2:48   ` Joel C. Salomon
  2007-04-27  3:02     ` Russ Cox
  0 siblings, 1 reply; 5+ messages in thread
From: Joel C. Salomon @ 2007-04-27  2:48 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 4/26/07, Russ Cox <rsc@swtch.com> wrote:
> > where is it determined that LNAME is returned when *t is scanned
> > rather than LTYPE (the way it is returned in the declaration of foo)?
>
> grep shows that /sys/src/cmd/cc/lex.c is relevant,
> since it contains … the relevant bit of lexing.
> you could trace back and see how s->class gets set.

I've done that; I've traced through the code for two weeks now.  As
best as I can determine, s->class is set in the various dcl functions
in dcl.c.  And I still can't find how any sort of scope overiding is
done.

In my compilers class, the professor suggested using some linked list
of scopes so that lookup would always return the nearest symbol by a
given name (modulo namespace issues).  Since there's a single global
symbol table in kencc, what tells lookup to return the properly scoped
symbol?

Is there anyone active on 9fans that can give me a "bird's eye view"
of kencc's internal structures?  I've read Johnson's "A Tour Through
the Portable C Compiler" in the v7 manual, and I'd guess that kencc
does something similar to pcc as described in the "Symbol Table
Maintenance" section -- I just don't find it in the code.

--Joel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] scopes in kencc
  2007-04-27  2:48   ` Joel C. Salomon
@ 2007-04-27  3:02     ` Russ Cox
  2007-04-27  4:35       ` Joel C. Salomon
  0 siblings, 1 reply; 5+ messages in thread
From: Russ Cox @ 2007-04-27  3:02 UTC (permalink / raw)
  To: 9fans

> In my compilers class, the professor suggested using some linked list
> of scopes so that lookup would always return the nearest symbol by a
> given name (modulo namespace issues).  Since there's a single global
> symbol table in kencc, what tells lookup to return the properly scoped
> symbol?

only the properly scoped symbol is in the hash table
during the lookup.  new declarations replace old ones
but the old ones get added to an undo log.  when a } is
reached, the undo log is applied to put the old ones back.
this is a very common "implicit" representation of the scope.
appel's book, at least, discusses it as an alternative
to the linked-list-of-scopes approach.

look for push1 and revertdcl.

russ



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] scopes in kencc
  2007-04-27  3:02     ` Russ Cox
@ 2007-04-27  4:35       ` Joel C. Salomon
  0 siblings, 0 replies; 5+ messages in thread
From: Joel C. Salomon @ 2007-04-27  4:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 4/26/07, Russ Cox <rsc@swtch.com> wrote:
> look for push1 and revertdcl.

Thanks.
--Joel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-04-27  4:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-27  1:12 [9fans] scopes in kencc Joel C. Salomon
2007-04-27  2:04 ` Russ Cox
2007-04-27  2:48   ` Joel C. Salomon
2007-04-27  3:02     ` Russ Cox
2007-04-27  4:35       ` Joel C. Salomon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).