Qualidents, near and far labels, an N-level nesting (lessons in Pascaline) #257
samiam95124
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Qualidents, near and far labels, an N-level nesting (lessons in Pascaline)
In original Pascal, nested procedures and functions were the basic program structuring method. This meant that there was no separate program structuring method, that is, you could not break down a program into separately compiled units.
This does not mean there was no structuring method. Wirth's use of nested procedures and functions is on display in pcom, the compiler. Looking at Pascal-P4, the structure of that reflects the structure of the program it was parsing. It is structured as (simplified):
The routines that don't fit that structure, like the scanner, appear above that. Pascal was first used to create it's own compiler, and it would not be a stretch to say it was designed for that purpose. For example, the lookahead system built into Pascal I/O was a useful mechanism for compilers.
Wirth's original structure for the compiler was and is a work of art. I have no intention of changing it. It will stay in pcom.pas.
Modules and separate compilation
Pascaline, and most other Pascal implementations, treat modularity as a two dimensional affair. That is, any number of modules can be linked together, but they cannot be nested. Contrast that with Modula, Wirth's other language, where they could be nested. Each module itself can be nested, but other modules cannot access the inner parts of that nesting.
Near and far labels
Although Pascal-P had, and has, a nested symbol table, addresses within the compiler are passed around as flat, linear numbers. They start at 1 and continue as much as needed. The import of that is that the compiler does not need to keep track of levels. Everything in the address space of the program is numbered linearly, regardless of nesting depth.
The near labels system makes the compiler's job simpler, but it does not work when Pascal-P gets extended to multiple separately compiled modules. The compiler does not know how things are numbered in the other module, or even if it is consistent. The numbering can change if the source is changed. Thus with Pascal-P6, the system changed to that of "near labels" and "far labels". Its actually a small "in-joke" about the way that the Intel 8086 treated addresses.
In the near/far system, the labels appear as:
module.identifier - a far label
module.integer - a near label
With near labels, the compiler still treats labels as numbers, but outputs them in the above format. Far labels are used for anything going to another module, and so bear both the module name and the symbol name. The import of that is that downstream processors like pint or pgen can immediately tell far labels from near labels. If what follows "module." is a number, it's near, otherwise far.
Qualidents
This module.name convention directly matches a qualident in Pascaline terminology[1]. It does not need to be more than two levels, module and symbol, because modules can only access other module's outer nesting level. If just a symbol is used, not a qualident, then it is a local reference, that is, within the current scope.
Qualidents on steriods
What about:
Would that inner z be referred to as x.y.z?
Well, that's not a valid qualident, although I have honestly considered it[2]. The problem is what does it mean if you reach up and down into another procedure? How about a procedure that is not currently active?
But I misled you there. These "super qualidents" do exist... in pint, in the debugger. The reason why is while debugging you need a way to specify the exact symbol you want, regardless of nesting. Thus, the level of nesting can be specified to the debugger[3].
The reason for this is that the near label numbers would be meaningless to a programmer. Thus a way to specify any level of nesting symbolically is useful.
[1] Qualidents were N. Wirth's terminology.
[2] You can always consider things more. And it is easier to consider things than take out bad features. Although I have heard some people call this "procrastination".
[3] pint builds the entire symbol tree and thus can do this easily.
Beta Was this translation helpful? Give feedback.
All reactions