On Thu, 08 Jan 2009 22:56:35 -0500, Norman Ramsey wrote: >> Algol 68 has nested procedures, with the convention that inner >> procedures > > can access the identifiers (like variables and parameters0 of the > > outer ones. These have to be accessed by pointers to outer > > activation records. > > > > Now the stackdata will do fine for normal variables... But parameters > > are another matter. They don't have addresses. So I'm stuck with > > copying them into the stackdata on entry (simplest solution, but > > probably not fast). Or being innovative. > > > > Now I could, at the call, pack all the parameters into a struct and > > pass the address as a parameter. I could stick that address into a > > register, into a static display, include it as part of the data > > structure for a nested procedure, and so on. > > > > Is this really the way it's intended to implement nested procedures > > and parameters, or am I missing something obvious? > > We expect that unlike the languages of the past, the languages of the > future will either not have nested procedures or will have first-class > nested procedures. So if you care about performance, you should do an > escape analysis (pretty easy)
Yes, it can be really easy if you don't need to do a good job. Any variable in a procedure without nested procedures doesn't escape, and that's already most of them! I know it's possible to do much better with sufficient effort. Escape analysis was the subject of my 1974 Ph.D. thesis. > to see which variables have to be captured > on the stack and at what program points. The rest of the time you > should keep those variables in registers and let the register allocator > do its job. > > If you don't care about performance then passing a pointer to a struct > is as easy as any other strategy and simpler than most. The two easiest methods are (1) pack all the parameters into a structure on the stack and pass a pointer to it. (2) pass all the parameters as C-- parameters, and copy them into local stackdata on entry. The advantage of the second method is that the linkage convention doesn't need to change to use the results of static escape analysis, if and when it's implemented. What's more. I suspect C-- will much better at reusing stack space than my compiler will be at reusing the space for the parameter structure. I choose (2). > > If you've missed anything obvious, I've missed it too. Fine. Then I won't be abusing the language. Thanks for the discussion. -- hendrik _______________________________________________ Cminusminus mailing list [email protected] https://cminusminus.org/mailman/listinfo/cminusminus
