|Multiple Function call in expression email@example.com (2003-03-09)|
|Date:||9 Mar 2003 17:44:52 -0500|
|Posted-Date:||09 Mar 2003 17:44:52 EST|
I am writting a one-pass compiler, which generate code (using
syntax direct translation) for a virtual machine that doesn't have
registers, just a stack.
My problem is with expressions like: a := f() + b + f1(); (with
multiple function calls). The problem is that I can't find a
systematic way to generate code for this kind
of expressions. The space for the return value of the function is
allocated before the call
and after the function return I have the value on the top of the
stack, but... what happends with the second function f1(), where I
should save the return value of each function call? How calcule this
temporary storage in a one-pass compiler during the parsing of this
kind of expressions.
Please, I really appreciate a clue, or a paper that help me with
Thanks in Advance.
[You shouldn't need to do anything special. Function values sit on the
stack until needed. In this case, you'd generate something like this:
PUSH $0 # allocate return slot for f
CALL f # value now on the top of the stack
ADD # now f()+b
PUSH $0 # allocate return slot for f1
ADD # now f()+b+f1()
Return to the
Search the comp.compilers archives again.