🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #861

Three address code

#861
From: Evan Ireland
Date: Thu, 04 Apr 1991 21:49
41 lines
2156 bytes
I've had no luck with mail, so this is for csdw at Rhodes University.

>
>In an attempt to optimize a functional language, I would like to
>turn the stack based intermediate code into three address code. 
>
>Has anyone done similar conversions?  Any references would be
>greatly appreciated.

I do not have any references, but I thought that one aspect of my FAM
implementation might be of interest.

A number of interpreters and compilers that I have seen implement a stack
pointer in a register or global variable.  Then to implement various stack
operations, they use auto-increment or auto-decrement operations on the stack
pointer register.  Since I generate portable C, and thus cannot assume I have

    DATA *f (register DATA *fp)
    {
	....
    }

Thus I pass to each function the current pointer to top of stack, from which it
can index downwards to find its arguments.  Within the function, I use indexing
operations on fp, e.g. fp[3] = fp[1], to manipulate values on the stack, so I
am not continually manipulating the stack pointer.  If "f" calls another
function, it will pass the address of the current top of stack, e.g. g (&f[5]).

The advantage to me is that I have a register for a stack pointer even though I
am generating portable C code.

Now the relationship to three-address code.  If you adopt such a scheme, and
your three address instructions allow some indexing, you can sometimes generate

	ADD	fp[3],f[4],fp[3]

I hope this helps.
_______________________________________________________________________________

E.Ireland@massey.ac.nz          Evan Ireland, School of Information Sciences,
  +64 63 69099 x8541          Massey University, Palmerston North, New Zealand.
Technical Details
Message-ID: <521sis-d@massey.ac.nz>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!comp.vuw.ac.nz!cc-server4.massey.ac.nz!E.Ireland

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!comp.vuw.ac.nz!cc-server4.massey.ac.nz!E.Ireland
From: E.Ireland@massey.ac.nz (Evan Ireland)
Newsgroups: comp.lang.functional
Subject: Three address code
Message-ID: <521sis-d@massey.ac.nz>
Date: 4 Apr 91 21:49:21 GMT
Reply-To: E.Ireland@massey.ac.nz
Organization: Information Sciences, Massey University, New Zealand
Lines: 41