cowgol icon indicating copy to clipboard operation
cowgol copied to clipboard

Possible space savings in subroutine calls

Open shattered opened this issue 1 year ago • 1 comments

cowfe/parser.y allocates temporary storage for return values of function calls like these:

# expression(E) ::= startsubcall inputargs(INA).
a := a + sub(); 

I think it shouldn't do that for plain subroutine calls, but there's no matching rule for that:

a := sub();

shattered avatar Jun 06 '24 16:06 shattered

Yes, that could be improved. What it's doing is routing the a := sub() case through the function-call codepath rather than the statement-call codepath; a temporary is needed for function calls to hold the return value in the event of a subsequent call to the same function.

This should be fixed in the new parser which I'm working on (in https://github.com/davidgiven/cowgol/blob/newparser/src/cowfe/parser.coh), but it's not ready yet.

davidgiven avatar Jun 07 '24 12:06 davidgiven