[m-dev.] Is there any call for a "generic" impure module.
Ralph Becket
rafe at cs.mu.OZ.AU
Mon Jul 19 16:34:10 AEST 2004
It occurrs to me that we could define a single module encapsulating
the unsafe/impure functionality needed to implement strings, arrays,
version structures etc. We could then further separate the need for
foreign code in the library.
What I have in mind is an interface like the following:
:- type mutable_cell.
% Allocate an (uninitialised) heap cell containing
% N words.
%
:- impure func allocate_mutable_cell(int) = mutable_cell.
% Retrieve the Ith word from the mutable cell and
% cast it into whatever type we need it to be.
% Undefined if I is out of range.
%
:- semipure func mutable_cell ^ unsafe_elem(int) = T.
% Update the Ith word of the mutable cell.
% Undefined if I is out of range.
%
:- semipure func (mutable_cell ^ unsafe_elem(int) := T) = mutable_cell.
% For implementing string buffers, etc.
%
% Access/update the Jth byte offset from the Ith word
% of a mutable cell.
% Undefined if 4I + J is out of range.
%
:- semipure func mutable_cell ^ unsafe_elem(int, int) = T.
:- semipure func (mutable_cell ^ unsafe_elem(int, int) := T) = mutable_cell.
I think this could significantly reduce the amount of foreign C code
needed.
This would probably not work for the C# or Java back-ends, unless you're
willing to put type casts all over the place.
Is this a sensible idea?
Would this be useful?
-- Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list