[m-users.] Storage format for data in low-level C grades
M McDonough
foolkingcrown at gmail.com
Wed Apr 16 12:37:46 AEST 2025
Is there any documentation on how Mercury stores types in the
low-level C grades?
I'm mostly considering the situation where I need to store a string
and a small enum type (three to seven variants). I know that using
tuples would essentially use a dynamically allocated array with two
MR_Word elements:
:- type enum ---> a ; b ; c.
:- type key == {enum, string}. % This will be a pointer to
`MR_Word[2]`, essentially.
I'm wondering if the compiler will choose to stash the enum in the tag
bits in the following case:
:- type enum ---> a ; b ; c.
:- type key ---> key(enum, string). % Is this equivalent to {enum, string}?
Since I believe the compiler already will do things like stashing
multiple enum members into a single MR_Word using what amounts to
bit-fields to save space, it wouldn't be a huge jump to also use the
tag bits here. But I'm unsure if the compiler will actually take this
step automatically. Otherwise, I would want to just define it as so to
manually force that:
:- type key ---> a(string) ; b(string) ; c(string).
It would be nice if there was some documentation on this for the
low-level data grades in particular (I doubt the HL grades would ever
do this?)
More information about the users
mailing list