Of constants and variables
Stefano Ferrari <ferrarst@tiscali.it> writes:
Oberon constants are named literals, they have simple types, not
compound types. Strings being the obvious (and useful) exception, so
the special rule about "assignment compatibility" is added.
From a compiler implementor's perspective, this makes things very
pleasant. You don't have to worry about constants being non-primitive
data types - note how Oberon has no "array literal" or "record
literal" notation the way C does. Constants always fit into
registers, they can be immediate operands in machine instructions. You
don't need fancy memory management to hand them around the compiler's
internals: they will always fit into a variable of simple type.
String constants have a "primitive" and nameless type. Only a few
operations are defined, such as assignment to an array (which is what
happens when you pass a string constant as a procedure parameter),
determining their size, and so on.
Thus, a compiler only has to be "aware" of string constant types in a
few special cases, not in the full general case where they could occur
in qualified identifiers. They can be added almost as an aftertought
when the compiler is almost finished.
Keep in mind that Oberon and C have different ideas what an array is:
in C, an array is a pointer (thus, a primitive data type). In Oberon,
an array is the entire memory area used to store the data of the array
in.
Cheers,
Florian
--
..O. This thing, that hath a code and not a core,
...O Hath set acquaintance where might be affections,
OOO And nothing now
Disturbeth his reflections. -- Ezra Pound, "An Object"
|