jacob navia said:
Mr Falconer has his own world, as many people here around.
A stack is not necessary, one complement or sign magnitude
representations rule the world, etc etc.
I think we have touched a trap representation
yes, ok.
but, it is maybe interesting from a theoretical perspective, aka:
a C-implementation allocating all the call frames on a heap.
so, we want a call frame?
grab it from a free-list (or, somehow, allocate more if needed).
need to store locals? grab a chunk of memory for this and attach to call
frame.
need space for args? likewise, grab a chunk of memory, evaluate and store in
the args, and attach it to the (newly created) call frame of the function
being called.
....
afaik, this particular approach is used in many scheme implementations, for
the reason that it makes implementing call/cc really fast and easy (we can
jump outword to some enclosing call frame, do stuff, or jump right back into
a call frame we had previously jumped out of).
some people have used call/cc as a way of implementing multithreading from
within scheme itself, ...
however, such an idea, though possible, would result in something very
different than a traditional C compiler.
very likely, we would have to rework the C code into CPS (actually, this is
partly how the JIT backend for my last script VM worked, as it compiled the
single bytecode blocks into some number of CPS-linked chunks).
CPS:
http://en.wikipedia.org/wiki/Continuation_passing_style
maybe external functions, like API calls, could be handled by temporarily
assigning a conventional stack (this stack serving to disappear once the
call completes). an inward call would mostly call a stub which serves to
transfer from a more traditional stack-based call-frame to the heap-and-CPS
variant...
of course, in my case, something like this would require an almost
completely different implementation of my lower compiler...
of course, it would make a whole lot of sense if I ever really intended to
(effectively) support languages like scheme or haskell...
interesting? maybe.
practical? probably not.