mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 05:12:33 +00:00
Estimated hours taken: 12 (this figure a wild guess, because most of this
stuff was done about 6 months ago and left to rot).
This change basically exposes the C types used for implementing the
`reference' and `nb_reference' types in extras/references, so that if the
user wishes to allocate these types somewhere other than on the heap, they
can. This is needed by HAL in order to implement global variables.
extras/references/c_reference.h:
New file, intended to expose the C types used by the `reference'
and `nb_reference' modules, so that the user can allocate them
somewhere other than on the heap if they need to.
extras/references/nb_reference.m:
Added a new predicate `init/2' for initialising a user-allocated
`nb_reference'.
extras/references/reference.m:
Moved the `ME_Reference' type to c_reference.h, and added a new
predicate `init/2' for initialising a user-allocated `reference'.
extras/references/README:
Added entries for the new `c_reference.h' and `tests/glob_test.m'
files, as well as correcting the name of `tests/ref_test.m'.
extras/references/tests/Mmakefile:
Added `glob_test' to the list of programs to build.
extras/references/tests/glob_test.m:
Test case for statically-allocated reference types, implementing
global variables. Adapted from output from the HAL compiler.
extras/references/tests/glob_test.exp:
Expected output from `glob_test'.
56 lines
1.6 KiB
C
56 lines
1.6 KiB
C
/*
|
|
** Copyright (C) 1999-2000 University of Melbourne.
|
|
** This file may only be copied under the terms of the GNU Library General
|
|
** Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
*/
|
|
|
|
/*
|
|
** This file exposes the C types used by the reference and nb_reference
|
|
** modules, so that one can allocate them somewhere other than the heap if
|
|
** one so desires. Normally this should not be necessary, and the cleaner,
|
|
** safer interfaces provided by reference.m and nb_reference.m should be
|
|
** used instead. However, sometimes it is useful; for example, the HAL
|
|
** compiler would like to be able to allocate them at compile-time-known
|
|
** locations, in order to implement global variables.
|
|
**
|
|
** These types should be treated as abstract in case their implementation
|
|
** changes in the future.
|
|
**
|
|
** Sample usage:
|
|
**
|
|
** The following example declares an ME_Reference `foo' at a
|
|
** compile-time-known location, and provides a zero-arity function for
|
|
** returning the corresponding Mercury object of type `reference/1'. Note
|
|
** that this reference should be initialised with the `reference:init/2'
|
|
** predicate before use: see the documentation of that predicate in
|
|
** reference.m for more caveats.
|
|
**
|
|
** :- pragma c_header_code("
|
|
** #include ""c_reference.h""
|
|
** extern ME_Reference foo;
|
|
** ").
|
|
**
|
|
** :- pragma c_code("
|
|
** ME_Reference foo;
|
|
** ").
|
|
**
|
|
** :- pragma c_code(foo_reference = (X::out), will_not_call_mercury, "
|
|
** X = (Word) &foo;
|
|
** ").
|
|
*/
|
|
|
|
#ifndef C_REFERENCE_H
|
|
#define C_REFERENCE_H
|
|
|
|
#include "mercury_trail.h"
|
|
|
|
typedef struct {
|
|
void *value;
|
|
MR_ChoicepointId id;
|
|
} ME_Reference;
|
|
|
|
typedef Word ME_NbReference;
|
|
|
|
#endif /* not C_REFERENCE_H */
|
|
|