comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: What is your opinion on Global Objects?
Date: Fri, 21 Nov 2014 15:53:13 -0600
Date: 2014-11-21T15:53:13-06:00	[thread overview]
Message-ID: <m4oc8a$90c$1@loke.gir.dk> (raw)
In-Reply-To: 65f2470c-0828-4f97-9f0e-f11966896c06@googlegroups.com

"Adam Beneschan" <adambeneschan@gmail.com> wrote in message 
news:65f2470c-0828-4f97-9f0e-f11966896c06@googlegroups.com...
...
>> The symbol table for a compiler is a good candidate for a singleton.
>
>This doesn't seem right to me.

It does to me. :-)

>I haven't followed the whole discussion closely, so I might have missed 
>something...  But
>in the case of a symbol table, an Ada compiler that implements generics by 
>"macro
>instantiation" is an example of why a symbol table should *not* be a 
>singleton.  If the
>compiler rescans the text of the generic, the entire context (i.e. what 
>symbols are visible)
>will change while the generic is being instantiated, and then it will 
>change back at the end.
>And of course the generic can instantiate another generic.

This makes no sense whatsoever. First of all, you can't instantiate a 
generic by rescanning the text, because all of the objects are bound when 
they are initially compiled. Most likely, everything would resolve wrong. 
Trying to make that work would be an absolute nightmare.

Our symboltable is purely a singleton; it reflects exactly the declarations 
available to the program at the current point in the compilation. (Our 
compiler is syntax-driven, so for most purposes it can be considered one 
pass -- we never go backwards in the source or symbols). Every change in the 
code changes the symboltable. (Initially, we deleted declarations as they 
went out of scope, but that always seemed to leave dangling pointers and was 
just a lot more complex than marking things as invisble.) That's why 
implementing ASIS is impractical in our compiler -- we don't ever have a 
view of the compilation as a whole to work from.

Generic instantiations are implemented by copying the symboltable for the 
generic unit and making the changes required by the instantiation. We don't 
do macro expansion, but if we did, we'd do it by duplicating a tree form of 
the unit (in which all of the symbols are already bound). Trying to work 
from the text is madness (especially as our parser is also a singleton)!

Now, I'm well aware that anything done in someone else's compiler is totally 
weird -- the things that other ARG members consider hard (or easy for that 
matter) often make little sense to me. I could imagine structuring a symbol 
table as a set of units (which would not be a singleton). [I can't imagine 
the Rational compiler, which supposely doesn't have a symbol table at all. 
But whatever.]

Anyway, I think the main point is that there really is no rules. Sometimes a 
singleton package is the best design. Sometimes a bunch of global spagetti 
is about all that would ever work (that's probably the best description of 
the symbol table in Janus/Ada)! [We couldn't afford the code that 
encapsulation would have cost back on CP/M and MS-DOS -- indeed, we use 
jumps, not calls for elaboration because we saved the call setup code *200 
units -- which was enough to make a big difference when getting code to fit 
into 64K RAM.]

                                           Randy.





  parent reply	other threads:[~2014-11-21 21:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-18  1:36 What is your opinion on Global Objects? Hubert
2014-11-18  2:52 ` Jeffrey Carter
2014-11-18  3:08   ` Hubert
2014-11-18  3:16     ` Shark8
2014-11-18  5:09     ` Jeffrey Carter
2014-11-18 11:23     ` Brian Drummond
2014-11-19  2:50       ` Hubert
2014-11-19  3:03         ` Jeffrey Carter
2014-11-19  9:13           ` Hubert
2014-11-19 10:22             ` J-P. Rosen
2014-11-19 17:37             ` Jeffrey Carter
2014-11-20 16:34         ` Stephen Leake
2014-11-20 21:11           ` Adam Beneschan
2014-11-21 15:25             ` Stephen Leake
2014-11-21 21:53             ` Randy Brukardt [this message]
2014-11-21  1:25           ` Hubert
2014-11-21  3:00           ` Brad Moore
2014-11-19 10:11   ` Jacob Sparre Andersen
2014-11-20  6:21     ` Hubert
2014-11-18  8:54 ` Dmitry A. Kazakov
2014-11-20 20:33 ` sbelmont700
2014-11-20 21:35   ` J-P. Rosen
2014-11-21  1:02     ` sbelmont700
2014-11-21  1:31       ` Hubert
2014-11-21  9:01     ` Dmitry A. Kazakov
2014-11-22  7:46       ` J-P. Rosen
2014-11-22  9:02         ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox