Comments
Loading Dream Comments...
You must be logged in to write a comment - Log In
Consider an expression such as
mylocalvariable;
or
myrecord.myfield;
In the first example it is a "field" of the "stack frame", an implicit struct instantiated when a procedure is called; in the second case it is a selected field of a record (itself a struct or object). We declare the locals thus:
MyProc <:: &{ ( mylocalvariable=123, foo=137, bar=42) ... }
so that when the compiler meets "mylocalvariable" in the input source code, it emits "stackframe!1" as the code, i.e. mylocalvariable is the first "field" of the "stack frame" (this is on the stack in order to efficiently implement recursion). When the compiler meets "myrecord.myfield", it similarly looks up "myfield" in myrecord's symbol table (i.e.myrecord[0]) and emits "myrecord!1" or whatever the subcript was for "myfield". This avoids doing symbol lookups at runtime, and allows us to switch things round in the source code if we want to add new fields (or class members). So basically the "." operator lets us name fields or local variables instead of using hard-coded subscripts. (This is all standard Comp-Sci stuff, supported I guess first by Cobol with its "01 MYRECORD PIC whatever.
02 MYFIELD PIC whatever."
Ooh look, she's got an extra hand :)