Passing function parameters by reference

"Emmanuel Boutin" <emmanuel.boutin@noos.fr>
9 Dec 2001 21:59:03 -0500

          From comp.compilers

Related articles
Passing function parameters by reference emmanuel.boutin@noos.fr (Emmanuel Boutin) (2001-12-09)
Re: Passing function parameters by reference rbates@southwind.net (Rodney M. Bates) (2001-12-11)
| List of all articles for this month |
From: "Emmanuel Boutin" <emmanuel.boutin@noos.fr>
Newsgroups: comp.compilers
Date: 9 Dec 2001 21:59:03 -0500
Organization: Service Usenet NoosNet
Keywords: design, question
Posted-Date: 09 Dec 2001 21:59:03 EST

Hi,


I'm currently writing a toolchain (compiler/interpreter/debugger) for
a new scripting language. The whole thing is now working but what I
thought to be a "small feature that anybody can add at the end" is now
becoming a "small feature that needs a major rewrite". The "small
feature" I'm talking about is the possibility to pass function
parameters by reference. By default, I support "copy" parameters
where the parameter's value is pushed entirely on the stack which
currently works fine. But it's not very efficient for "large" objects.
I planned from the beginning to support other parameter passing modes
for l-values : in, out, inout like in ADA


The problem I'm facing is a chicken & egg one :
- in the AST, I have a function_call node that basically contains an
identifier and a list of expressions nodes
- when I translate this node into code nodes, I first traverse the list of
expressions for the parameters which gives me a list of translated
expressions. It also gives me a list of types. I use the list of types +
identifier to find a matching function. I then use the function's exact
signature to determine the way I should pass the parameters to the function.
- but it's too late. I've already translated all the arguments into code.
Even l-values have been translated into values. The distinction I make
between l-values and values is that l-values are only an address on the
stack whereas values are entirely stored on the stack.


I have already several ideas but none of them please me. Would anybody
know a "standard" approach to this problem ?


One note: I don't plan to support temporay objects on the stack for "in"
parameters. in/out/inout parameters MUST be l-values and I only want their
address on the stack whe the function is called.


Thanks,
Emmanuel Boutin
[I'd think you either need an explicit "address of" operator which
preserves an lvalue, which you can then check against the function's
signature, or else make a pass and a half over a function call, one to
figure out the argument types and find the function, the other to
generate the code, using the function's signature to know when you
want a pointer and when you want a value. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.