Re: GCC front-end for FORTH?



Anton Ertl <anton@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Andrew Haley <andrew29@xxxxxxxxxxxxxxxxxxxxxxx> writes:
Anton Ertl <anton@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Andrew Haley <andrew29@xxxxxxxxxxxxxxxxxxxxxxx> writes:
To generate code for DUP, for example, you'd do
more or less the same as generating C from Forth and then compiling
that. You'd generate something like:

sp--; *sp = tos;

Come on, you know better. Do you generate such code in GCJ when you
compile a JVM dup?

No, of course not, but Java's stack is local to the function, and Java
stack operations can trivially be converted to a bunch of local
variables. A stack that is unbounded and shared between functions has
to be represented somehow.

Yes, but the common case is that the stack depth is statically known
and stack accesses can be trivially converted to pseudo-variables.
In the few cases where this does not hold, the front end has to
insert some stores/loads to the unbounded stack in memory; it's all
explained in <http://www.complang.tuwien.ac.at/projects/rafts.html>.

I already said

It is possible, of course, to do optimization in the Forth front
end, and this would allow you to generate trees that didn't touch
memory so much. This would help,

which is another way to say exactly the same thing. I was explaining
to John why the naive approach won't give top-quality results.

As long as you don't want to call other languages, there is no need
to use the usual calling conventions.

Well, I already answered that: I'm assuming we're not writing a new
back end.

I don't know gcc well enough to comment on the dependencies between
the back end and the calling convention;

The back end contains the code that handles the particular hardware
and the particular calling conventions. In the case where a processor
(such as the x86) has more than one calling convention, alternative
routines to generate entry and exit sequences are provided. This
logic has to be in the back-end, really, because it's generally
impossible to describe a calling convention without machine
dependencies. Some common parts of the logic are in the core
compiler, but there are such great differences between the various
calling conventions and hardware architectures that's not generally
possible.

but even if they are strong, it should be possible to treat calls
between Forth words as something lighter-weight than a
calling-convention call, no?

I guess this question amounts to "is it possible to stop the back-end
from generating ABI-compliant entry and exit sequences without
altering the back-end?", to which I suspect the answer is no.

There is a trick where you can call a subroutine within the context of
the current function by doing something like

tmp = &&bar;
goto foo;
bar:

...

foo:
...
goto tmp;

and this does indeed get you a super-lightweight call: no prologue,
epilogue, or local variables. However, if you were to do this very
much I think code quality would suffer because of the complex data
flow and the large number of temporaries.

Andrew.
.



Relevant Pages

  • Re: GCC front-end for FORTH?
    ... more or less the same as generating C from Forth and then compiling ... No, of course not, but Java's stack is local to the function, and Java ... to use the usual calling conventions. ... M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html ...
    (comp.lang.forth)
  • Re: On "lisp machines"
    ... > I'm working on my own implementation, but am compiling directly to C ... > longjmp's back to the driver only when the stack is about to be ... in that it instead devotes a full pointer to a function ... threading, so as to avoid the self-modifying code problems you mentioned ...
    (comp.lang.lisp)
  • RE: Calling convention
    ... For calling conventions, cleaning stack means remove parameters info from ... I will explain cdecl, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Calling convention
    ... For calling conventions, cleaning stack means remove parameters info from ... Microsoft Online Community Support ... nature are best handled working with a dedicated Microsoft Support Engineer ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Linuv 2.6.15-rc1
    ... Compiled and installed the latest snapshot. ... ieee80211 stack git-1.1.7. ... > I am compiling the latest git snapshot 4060994c3e337b40e0f6fa8ce2cc178e021baf3d. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)