mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 21:03:53 +00:00
Estimated hours taken: 2 Various bug fixes and cleanups for the code in the runtime directory. runtime/mercury_bootstrap.h: runtime/mercury_regs.h: runtime/mercury_stacks.h: runtime/mercury_type_info.h: Move #defines that are there just for backwards compatibility into mercury_bootstrap.h. runtime/process_getopt: Add MR_ prefixes to the names `_GETOPT_H', `no_arguments', and `required_argument' which are defined by mercury_getopt.h, to make mercury_getopt.h macro-namespace-clean. runtime/mercury_getopt.h: Apply the new version of the process_getopt script. runtime/mercury_imp.h: Make mercury_bootstrap the first header file that is #included, in case some of the macros defined in it are used in declarations in other header files. runtime/mercury_memory.h: Delete duplicate definitions of MAX_REAL_REG, NUM_SPECIAL_REG, and MAX_VIRTUAL_REG -- these are all already defined in mercury_memory_zones.h. runtime/mercury_memory_zones.h: Delete definition of NUM_SPECIAL_REG, since mercury_regorder.h already defines MR_NUM_SPECIAL_REG, which should be used instead of NUM_SPECIAL_REG. The value of NUM_SPECIAL_REG was long obsolete. runtime/mercury_regorder.h: Fix some bugs in the definition of MR_min_sol_hp_rec -- it was using `mr40', which is undefined, instead of `mr(40)'. Also add some comments. runtime/mercury_regs.h: Fix a bug: use MR_NUM_SPECIAL_REGS instead of NUM_SPECIAL_REGS. Note that this bug fix unfortunately breaks backwards compatibility, at least for procedures with more than 32 arguments, since it affects the mapping from r(N) to the fake_reg array. However, there was no alternative, since the old mapping was broken: for example, the old mapping used the same fake_reg slot for both r(41) and MR_global_hp. runtime/mercury_bootstrap.h: Change MR_GRADE_PART_0 from `redofr' to `v1', and document that that part of the grade is a binary compatibility version number. The reason for changing the grade is to ensure that the change in binary backwards compatibility resulting from the changes to runtime/mercury_regs.h will cause link errors rather than just random behaviour for procedures with >32 arguments. runtime/mercury_agc_debug.c: Use MR_NUM_SPECIAL_REGS instead of NUM_SPECIAL_REGS. Also add some XXX comments, since all of the places where NUM_SPECIAL_REGS was used are broken anyway -- they should be using MAX_FAKE_REG instead of MAX_REAL_REG + NUM_SPECIAL_REG. But I think the current definition is put there for efficiency, even though it's known to be broken for procedures with >32 arguments, so I didn't change the code to use MAX_FAKE_REG.
118 lines
3.1 KiB
C
118 lines
3.1 KiB
C
/*
|
|
** Copyright (C) 1994-1998 The 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.
|
|
*/
|
|
|
|
/*
|
|
** mercury_memory.h - general memory-allocation related stuff for the
|
|
** Mercury runtime.
|
|
**
|
|
** This defines the different memory areas used by the Mercury runtime,
|
|
** including the det & nondet stacks, the heap (and solutions heap),
|
|
** and the fake_reg array for holding Mercury virtual registers.
|
|
** It also provides interfaces for constructing new memory zones,
|
|
** and for allocating (possibly shared) memory.
|
|
*/
|
|
|
|
#ifndef MERCURY_MEMORY_H
|
|
#define MERCURY_MEMORY_H
|
|
|
|
#include "mercury_memory_zones.h"
|
|
|
|
#include <stdlib.h> /* for size_t */
|
|
|
|
#include "mercury_types.h" /* for Word */
|
|
#include "mercury_std.h" /* for bool */
|
|
|
|
|
|
#ifdef MR_LOWLEVEL_DEBUG
|
|
extern MemoryZone *dumpstack_zone;
|
|
extern int dumpindex;
|
|
#endif
|
|
|
|
/*
|
|
** round_up(amount, align) returns `amount' rounded up to the nearest
|
|
** alignment boundary. `align' must be a power of 2.
|
|
*/
|
|
|
|
#define round_up(amount, align) ((((amount) - 1) | ((align) - 1)) + 1)
|
|
|
|
/*
|
|
** For these functions, see the comments in mercury_memory.c and
|
|
** mercury_engine.c
|
|
*/
|
|
|
|
extern void init_memory(void);
|
|
extern void init_heap(void);
|
|
extern void debug_memory(void);
|
|
|
|
/*
|
|
** allocate_bytes() allocates the given number of bytes.
|
|
**
|
|
** allocate_object(type) allocates space for an object of the specified type.
|
|
**
|
|
** allocate_array(type, num) allocates space for an array of objects of the
|
|
** specified type.
|
|
**
|
|
** If shared memory is being used, these allocation routines will allocate
|
|
** in shared memory.
|
|
*/
|
|
|
|
extern void *allocate_bytes(size_t numbytes);
|
|
|
|
#define allocate_object(type) \
|
|
((type *)allocate_bytes(sizeof(type)))
|
|
|
|
#define allocate_array(type, num) \
|
|
((type *)allocate_bytes((num) * sizeof(type)))
|
|
|
|
/*
|
|
** deallocate_memory() deallocates the memory allocated by one of the
|
|
** allocate_* functions.
|
|
*/
|
|
|
|
void deallocate_memory(void *);
|
|
|
|
/*
|
|
** checked_malloc() and checked_realloc() are like the standard C
|
|
** malloc() and realloc() functions, except that the return values
|
|
** are checked.
|
|
**
|
|
** NOTE: checked_malloc()ed and checked_realloc()ed structures must
|
|
** never contain pointers into GCed memory, otherwise those pointers
|
|
** will never be traced.
|
|
*/
|
|
|
|
#include <stddef.h> /* for size_t */
|
|
void *checked_malloc(size_t n);
|
|
void *checked_realloc(void *old, size_t n);
|
|
|
|
/*
|
|
** MR_copy_string makes a copy of the given string with checked_malloc.
|
|
*/
|
|
|
|
char *MR_copy_string(const char *s);
|
|
|
|
/*
|
|
** `unit' is the size of the minimum unit of memory we allocate (in bytes).
|
|
** `page_size' is the size of a single page of memory.
|
|
*/
|
|
|
|
extern size_t unit;
|
|
extern size_t page_size;
|
|
|
|
/*
|
|
** Users need to call MR_add_root() for any global variable which
|
|
** contains pointers to the Mercury heap. This information is only
|
|
** used for agc grades.
|
|
*/
|
|
#ifdef NATIVE_GC
|
|
#define MR_add_root(root_ptr, type_info) \
|
|
MR_agc_add_root((root_ptr), (type_info))
|
|
#else
|
|
#define MR_add_root(root_ptr, type_info) /* nothing */
|
|
#endif
|
|
|
|
#endif /* not MERCURY_MEMORY_H */
|