Re: [MLton] Changing MLton.Pointer.word

Matthew Fluet <[email protected]> Tue, 24 Jun 2014 13:59:03 -0400
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <CAMrhFL5ZG=kt1iXAQK1MorRoO1CusMiwKaJLUbXqzQT-g2bfAg@mail.gmail.com>
On Mon, Jun 23, 2014 at 10:24 AM, Christopher Cramer
<[email protected]> wrote:
> On Mon, Jun 23, 2014 at 08:03:23AM +0200, Florian Weimer wrote:
>> I would like to change MLton.Pointer.word to Word32.word on 32-bit
>> architectures, and Word64.word on 64-bit architectures.
>
> If you need a word the size of a pointer, it's actually already available
> in the C_Pointer structure, made available in $(SML_LIB)/basis/c-types.mlb.
> See http://mlton.org/ForeignFunctionInterfaceTypes.

There are also C_Size, C_Ptrdiff, C_Intptr, and C_UIntptr, all of
which should correspond to an integer or word of the appropriate,
target-dependent bit size.  (Technically, the C standard does not
require all of these types to have the same number of bits, though in
practice I suspect that they almost always do.)

>> What's the best way to implement this?  Compiler hacking with primitives?
>> Changing MLB files?  Some form of preprocessing?
>
> The easiest way to do it would be to just include that c-types.mlb
> in basis-library/build/sources.mlb, and put "type word = C_Pointer.word"
> in basis-library/mlton/pointer.sml.
>
> Although now that I think about it, just having the type is kind of
> useless, since you can't do anything with it without the functions. You
> probably want to include the whole C_Pointer structure somehow.

Well, if you propagate the type equality of MLton.Pointer.t and
C_Pointer.word, then you can simply use the C_Pointer.* operations on
MLton.Pointer.t values.  There isn't a need to include the WORD
signature in the MLTON_POINTER signature.

But, I'm not sure that that would work with the current MLton
implementation.  The various MLton.Pointer.* operations are primitives
and expect that MLton.Pointer.t is a distinct abstract type.

A better approach might be to simply expose the MLton.Pointer.toWord
and MLton.Pointer.fromWord operations that are provided as primitives,
but not exported.  These convert to and from C_Size.word values.
Similarly, the MLton.Pointer.{add, sub} operations are internally
implemented by primitives that use C_Ptrdiff.int values, but for
convenience, are exposed and wrapped to use Word.word values.

It might also help if you could describe in a little more detail
how/why you want to use MLton.Pointer.t values as Word<N>.word values.

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft