-
Notifications
You must be signed in to change notification settings - Fork 701
Description
Split from discussion in #483:
I'd like to see some effort made to map these use cases to the existing model and then evaluate what remains unsolvable or what remains inefficient. The use case of multiple return sites might relate to supporting a catch operation or exception handling, but not sure.
On 11/30/2015 01:45 PM, Frank McCabe wrote:
Both Prolog and Haskell pose challenges to the current design. In some
ways they also have a common requirement: a non-standard evaluation
resulting in a need for more control over the representation of evaluation.In the case of Prolog, it has an evaluation 'stack' (quotes required)
that has two features not found in normal languages: a non-local return
(when a Prolog program ends, its return is not necessarily near on the
stack. However, that stack must still be preserved in order to support
backtracking.The second feature is backtracking. What /that/ means is that there are
two separate ways in which a program can return: successfully or
unsuccessfully.
Does prolog compiled to machine code keep a separate binding stack? How far can you get using a separate stack except for the control transfer? Even translated C is expected to have a separate stack for argument passing beyond the fixed arguments.
In general, a good Prolog implementation needs a lot more explicit
control of its evaluation stack than languages Java/C++ do.Haskell is a different case again. It's implementation has a number of
features that are very foreign to conventional languages. In the first
case, arguments are not evaluated prior to entry to functions. The
effect of this is that /all/ data looks like code. It also means that
the normal array mapping of an evaluation stack is not efficient for
Haskell.
This sounds like a higher level issue. Machine code does not support this anyway, so surely it is translated into more primitive operations. For example arguments might be pointers to data structures, and perhaps these need to include an index to a function and a context?
In the second, there can be multiple return points to a function call:
one where the result is represented as a single value, and one or more
where the return result is 'postponed' with the components of the return
value spread across multiple registers.
Can this be handle by a single return site using multiple values (which are to be supported). The first value might be an index to dispatch to different range of return paths?
...
One additional remark: the kind of structures needed to support Haskell
and Prolog are also very good for supporting so-called asynchronous
programming. So, even JavaScript and C++ could benefit from these
techniques.
But they are compiled to machine code anyway, and machine code does not have specific support for 'asynchronous programming'. What we need to know is if the AST can efficiently support the primitive operations needed.