GARTHWILSON wrote:
About Pascal: I've heard that in the past; but doesn't that make for a lot of time wasted moving lots of large items to and from the stack? Or is it more like Forth's dictionary which is last-on-first-off in the sense of new compilation and FORGET, but which normally uses the page-1 hardware stack as a return stack and a ZP area for a parameter stack, independently of the dictionary?
Pascal isn't that much different from other high level languages, like C.
Specifically, in this case, they're both pass by value. For normal scalars, this isn't really a big deal: characters, integers, etc. Floats would push the entire value (8 bytes, depending on the FP implementation). But if you pass in a record (a struct in C), then the entire thing gets copied to the stack, where it's operated upon by the procedure. On exit, the SP is reset and all of that space is released.
Clearly this encourages passing in pointers to things, rather than the things themselves. Now, in Pascal, you can specify pass by reference:
Code:
program p;
var z:integer;
procedure test(x:integer, var y:integer)
begin
y := y + x;
end;
begin
z = 1;
test(1, z);
{ z = 2 }
end.
In this case, "y" would be modified. VS:
Code:
program p;
var z:integer;
procedure test(x:integer, y:integer)
begin
y := y + x;
end;
begin
z = 1;
test(1, z);
{ z = 1 }
end.
"y" would still be modified, but it's tied to the scope of the procedure and doesn't affect the parameter that's called in to the procedure.
The curious part of UCSD is that if your procedure invoked a segment procedure (which is like an overlay), that wasn't loaded yet, it would actually load from disk and "push" the code on to the stack. You could visualize the working memory of UCSD as the dictionary in FORTH. But it has 2 parts, the stack, and the heap. In UCSD the stack would grow upward in memory, while the heap would grow down, until one ran in to the other and you "run out of memory". The heap was mostly used for dynamic memory allocation using the crude mark and release capability in the early UCSD (vs the malloc/free concept in C). Mark simply bumped the heap pointer, release set it back.
The overlay thing isn't really a problem, you can don't put calls to segment procedures in a tight loop.