Re: Stack Machine and Parameters

"amal" <amalmanuel@gmail.com>
16 Dec 2004 00:48:37 -0500

          From comp.compilers

Related articles
Stack Machine and Parameters jkallup@web.de (Jens Kallup) (2004-11-29)
Re: Stack Machine and Parameters amalmanuel@gmail.com (amal) (2004-12-16)
| List of all articles for this month |

From: "amal" <amalmanuel@gmail.com>
Newsgroups: comp.compilers
Date: 16 Dec 2004 00:48:37 -0500
Organization: http://groups.google.com
References: 04-11-129
Keywords: code, architecture
Posted-Date: 16 Dec 2004 00:48:37 EST







Jens Kallup wrote:
> Hello Newsgroup,
>
> I trying to program an interpreter in stack machine behavior.
> It works fine at now - IF ELSE ENDIF FOR loops and
> variable definitions like "b0 = 100".
> But now, I reached the point where parameters of functions
> should be interpreted. I don't know how it possible.
> I pushed parameters on stack of functions that are fixed and
> know by me - but how works with unknow procedure
> parameters?
>
> Here a little code snippet of the parsed interpreter code:
>
> enter main
> npush 10
> vpush b0
> add
> nassign b0
> call @test
> ret


hello,
evaluate the arguments. push them to the stack ( assuming call by
value) . on function invocation pop as many arguments as the arity of
the function. do the functions job.


like


CALL MAX ( 1, A+B+C, SQUARE( A - B)) can be translated as
lets assume we evaluate from left to right.


vpush A
vpush B
sub
call @sq
vpush A
vpush B
add
vpush C
add
npush 1
call @max


bye
amal


Post a followup to this message

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