Related articles |
---|
Multiple Function call in expression epmolina@ub.edu.ar (2003-03-09) |
From: | epmolina@ub.edu.ar |
Newsgroups: | comp.compilers |
Date: | 9 Mar 2003 17:44:52 -0500 |
Organization: | http://groups.google.com/ |
Keywords: | code, question |
Posted-Date: | 09 Mar 2003 17:44:52 EST |
Hi,
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
this.
Thanks in Advance.
Enrique.
[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
PUSH b
ADD # now f()+b
PUSH $0 # allocate return slot for f1
CALL f1
ADD # now f()+b+f1()
- John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.