cleanup of runtime/*
Fergus Henderson
fjh at cs.mu.oz.au
Sat Feb 8 18:23:46 AEDT 1997
Hi,
Bert, can you please review the following change?
---------------------------------------------------------------------------
A general cleanup of the code in the runtime directory, aimed at
formulating a more coherent header file inclusion policy. This change
fixes a couple of bugs that prevented the runtime from compiling in
certain configurations due to missing #includes, and also fixes a few
minor unrelated things such as the use of `size_t' instead of `unsigned'.
Our header file inclusion policy is that every header file should
#include any other header files needed by the declarations or by the
macros it defines. Cyclic interface dependencies, where two header
files each #include the other, must be avoided (by splitting up header
files into smaller indepdent units, if necessary).
At some stage in the future we should rename all the header files to
`mercury_*.h', to avoid any possible name clashes with system or user
header files.
runtime/Mmake:
Add a new target `check_headers' to check that each
header file is syntactically valid in isolation.
runtime/imp.h:
runtime/mercury_float.h:
runtime/mercury_string.h:
runtime/mercury_types.h:
runtime/calls.h:
Move the code in "imp.h" into new header files.
"imp.h" now contains nothing but #includes.
runtime/conf.h.in:
runtime/*.h:
runtime/{label,prof,prof_mem}.c:
runtime/*.mod:
Update the #includes to reflect the new header file structure.
Add some missing header guards. Add some comments.
Put the correct years in most of the copyright notices.
runtime/heap.h:
Fix a bug: add #include "context.h", needed for
min_heap_reclamation_point.
runtime/context.h:
Fix a bug: add #include "memory.h", needed for MemoryZone.
Move the general description comment to the top of the file.
Fix the indentation of some comments. Add a couple of new comments.
runtime/context.mod:
Delete a couple of unnecessary declarations.
runtime/wrapper.mod:
Change the type used for memory sizes from `unsigned' to `size_t'.
Change the `-p' (primary cache size) option so that it is always
a size in kilobytes, rather than being schitzophrenic about
whether it is bytes or kilobytes.
runtime/regorder_base.h:
Removed, since it not used (and constitutes a
double-maintenance problem).
---------------------------------------------------------------------------
cvs diff: Diffing .
Index: Mmake
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/Mmake,v
retrieving revision 1.49
diff -u -r1.49 Mmake
--- 1.49 1997/02/07 18:39:53
+++ Mmake 1997/02/08 07:04:31
@@ -21,10 +21,11 @@
#-----------------------------------------------------------------------------#
-HDRS = access.h misc.h conf.h context.h \
+HDRS = access.h misc.h calls.h conf.h context.h \
deep_copy.h dlist.h debug.h dummy.h \
engine.h getopt.h goto.h heap.h imp.h init.h label.h \
overflow.h prof.h memory.h mercury_solver_backtrack.h \
+ mercury_float.h mercury_string.h mercury_types.h \
regorder.h regs.h spinlock.h std.h stacks.h \
table.h tags.h timing.h wrapper.h \
prof.h prof_mem.h type_info.h context.h
@@ -83,6 +84,14 @@
tags: $(MODS) $(ORIG_CS)
ctags $(MODS) $(ORIG_CS)
+
+.PHONY: check_headers
+check_headers:
+ for file in $(HDRS); do \
+ echo "$$file"; \
+ echo "#include \"$$file\"" > tmp.c; \
+ $(MGNUC) $(MGNUCFLAGS) -c tmp.c || exit 1; \
+ done
#-----------------------------------------------------------------------------#
Index: access.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/access.h,v
retrieving revision 1.5
diff -u -r1.5 access.h
--- 1.5 1995/05/29 02:03:35
+++ access.h 1997/02/08 03:39:19
@@ -4,12 +4,14 @@
** Public License - see the file COPYING.LIB in the Mercury distribution.
*/
+/* access.h - some unfinished junk that should probably be delted */
+
#ifndef ACCESS_H
#define ACCESS_H
-#ifndef LIST_H
-#include "dlist.h"
-#endif
+#include <stdio.h> /* for `FILE' */
+#include "mercury_types.h" /* for `Word' */
+#include "dlist.h" /* for `List' */
extern void reset(void);
extern void help(void);
@@ -19,4 +21,5 @@
extern Word set_mem(Word *, Word);
extern Word createn(List *);
extern int getflexline(const char *, FILE *, char **, int *);
+
#endif
Index: call.mod
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/call.mod,v
retrieving revision 1.23
diff -u -r1.23 call.mod
--- 1.23 1996/10/18 10:09:04
+++ call.mod 1997/02/08 05:15:46
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
@@ -24,8 +24,18 @@
** eventual destinations.
*/
-#include "imp.h"
+#include "regs.h"
+
+#include <assert.h>
+
+#include "mercury_types.h"
#include "type_info.h"
+#include "calls.h"
+#include "stacks.h"
+#include "memory.h" /* for fake_reg */
+#include "tags.h" /* for field() */
+#include "misc.h" /* for fatal_error() */
+#include "engine.h" /* for do_fail */
BEGIN_MODULE(call_module)
cvs diff: calls.h is a new entry, no comparison available
Index: conf.h.in
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/conf.h.in,v
retrieving revision 1.9
diff -u -r1.9 conf.h.in
--- 1.9 1996/12/13 00:02:04
+++ conf.h.in 1997/02/08 02:46:38
@@ -1,14 +1,24 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
+
/*
** @configure_input@
*/
+
/*
-** Various configuration parameters, generally automatically by
-** the auto-configuration script. Their meanings are:
+** conf.h.in -
+** Various configuration parameters, determined automatically by
+** the auto-configuration script.
+*/
+
+#ifndef CONF_H
+#define CONF_H
+
+/*
+** The parameters defined here have the following meanings:
**
** WORD_TYPE the base type for the definition of Word.
** LOW_TAG_BITS the number of low-order tag bits we can use.
@@ -20,10 +30,10 @@
** HAVE_MPROTECT the machine has the mprotect() syscall.
** HAVE_STRERROR the machine has the strerror() function.
** RETSIGTYPE the return type of signal handlers.
-** HAVE_SIGINFO signal handlers are given siginfo arguments.
-** we have <sys/siginfo.h>
-** HAVE_UCONTEXT signal handlers are given ucontext arguments
-** we have <ucontext.h>
+** HAVE_SIGINFO signal handlers are given siginfo arguments,
+** and we have <sys/siginfo.h>
+** HAVE_UCONTEXT signal handlers are given ucontext arguments,
+** and we have <ucontext.h>
** HAVE_SYS_UCONTEXT we have <sys/ucontext.h>
** HAVE_SYS_TIME we have <sys/time.h>
** HAVE_SYS_PARAM we have <sys/param.h>
@@ -54,3 +64,5 @@
#undef PC_ACCESS_GREG
#undef HAVE_SIGACTION
#undef SIGACTION_FIELD
+
+#endif /* CONF_H */
Index: context.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/context.h,v
retrieving revision 1.2
diff -u -r1.2 context.h
--- 1.2 1997/02/07 18:39:58
+++ context.h 1997/02/08 03:15:01
@@ -1,19 +1,12 @@
-#ifndef CONTEXT_H
-#define CONTEXT_H
-
-#include "spinlock.h"
-
/*
-** If we have parallelism switched on (PARALLEL is defined),
-** then we define how many processes should be used.
-** Ultimately this should be configurable through the
-** MERCURY_OPTIONS environment variable.
+** Copyright (C) 1997 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.
*/
-#ifdef PARALLEL
-extern int numprocs;
-#endif
/*
+** context.h - defines Mercury multithreading stuff.
+**
** A Context is like a thread. It contains a detstack, a nondetstack,
** the various pointers that refer to them, a succip, and a thread-
** resumption continuation. Contexts are initally stored in a free-list.
@@ -47,6 +40,28 @@
** to wake suspended processes.
*/
+#ifndef CONTEXT_H
+#define CONTEXT_H
+
+#include "regs.h" /* for hp */
+
+#include <sys/types.h> /* for pid_t */
+
+#include "mercury_types.h" /* for Word */
+#include "memory.h" /* for MemoryZone */
+#include "spinlock.h" /* for SpinLock */
+#include "goto.h" /* for GOTO() */
+
+/*
+** If we have parallelism switched on (PARALLEL is defined),
+** then we define how many processes should be used.
+** Ultimately this should be configurable through the
+** MERCURY_OPTIONS environment variable.
+*/
+#ifdef PARALLEL
+extern int numprocs;
+#endif
+
/*
** The number of context structures initially allocated.
** This allocation does not include the stacks that they
@@ -100,119 +115,119 @@
*/
};
- /*
- ** free_context_list is a global linked list of unused context
- ** structures. If the MemoryZone pointers are not NULL,
- ** then they point to allocated MemoryZones, which will
- ** need to be reinitialized, but have space allocated to
- ** them. (see comments in memory.h about reset_zone())
- */
+/*
+** free_context_list is a global linked list of unused context
+** structures. If the MemoryZone pointers are not NULL,
+** then they point to allocated MemoryZones, which will
+** need to be reinitialized, but have space allocated to
+** them. (see comments in memory.h about reset_zone())
+*/
extern Context **free_context_list_ptr;
- /*
- ** the runqueue is a linked list of contexts that are
- ** runnable.
- */
+/*
+** the runqueue is a linked list of contexts that are
+** runnable.
+*/
extern Context **runqueue_ptr;
- /*
- ** this_context is a pointer to the currently executing
- ** context. the fields of this_context are not necessarily
- ** in sync with the real values, since *this_context only
- ** gets updated when save_context() gets called.
- */
+/*
+** this_context is a pointer to the currently executing
+** context. the fields of this_context are not necessarily
+** in sync with the real values, since *this_context only
+** gets updated when save_context() gets called.
+*/
extern Context *this_context;
- /* a pointer to a word used for the spinlock on the runqueue */
+/* a pointer to a word used for the spinlock on the runqueue */
extern SpinLock *runqueue_lock;
- /*
- ** a pointer to a word used for the spinlock on the free
- ** context list
- */
+/*
+** a pointer to a word used for the spinlock on the free
+** context list
+*/
extern SpinLock *free_context_list_lock;
- /*
- ** init_processes() forks new process (if necessary), and
- ** initializes the data-structures for managing the interactions
- ** between them.
- */
+/*
+** init_processes() forks new process (if necessary), and
+** initializes the data-structures for managing the interactions
+** between them.
+*/
void init_processes(void);
- /*
- ** init_process_context() creates a top-level context for
- ** the original process, and allocates a heap and a solutions-
- ** heap for each process.
- */
+/*
+** init_process_context() creates a top-level context for
+** the original process, and allocates a heap and a solutions-
+** heap for each process.
+*/
void init_process_context(void);
- /*
- ** new_context() allocates and initializes a new context
- ** structure.
- */
+/*
+** new_context() allocates and initializes a new context
+** structure.
+*/
Context *new_context(void);
- /*
- ** delete_context(ptr) returns the context structure pointed
- ** to by ptr to the free list, and releases resources as
- ** necessary.
- */
+/*
+** delete_context(ptr) returns the context structure pointed
+** to by ptr to the free list, and releases resources as
+** necessary.
+*/
void delete_context(Context *context);
- /*
- ** flounder() aborts with a runtime error message. It is called if
- ** the runqueue becomes empty and none of the running processes are
- ** working - ie the computation has floundered.
- */
+/*
+** flounder() aborts with a runtime error message. It is called if
+** the runqueue becomes empty and none of the running processes are
+** working - ie the computation has floundered.
+*/
void flounder(void);
- /*
- ** procid[N] is the process id of the Nth process.
- ** procid[my_procnum] == getpid() == my_procid.
- */
+/*
+** procid[N] is the process id of the Nth process.
+** procid[my_procnum] == getpid() == my_procid.
+*/
extern pid_t *procid;
- /*
- ** procwaiting[N] is true if the process procid[N] is
- ** suspended because the runqueue was empty when it
- ** called runnext().
- ** Although we semantically want bools here, we use
- ** words to ensure coherency. Since a bool may be
- ** smaller than a word, storing a bool may be implemented
- ** in a coherency-breaking manner.
- ** (Assuming that Words can be read and written in a
- ** coherent manner is sufficiently important in terms of
- ** simplifying the synchronization mechanisms, that
- ** we really need to do so -- or so says Tom, at least.
- ** I remain unconvinced. -Fergus.)
- */
-typedef Word AtomicBool;
+/*
+** procwaiting[N] is true if the process procid[N] is
+** suspended because the runqueue was empty when it
+** called runnext().
+** Although we semantically want bools here, we use
+** words to ensure coherency. Since a bool may be
+** smaller than a word, storing a bool may be implemented
+** in a coherency-breaking manner.
+** (Assuming that Words can be read and written in a
+** coherent manner is sufficiently important in terms of
+** simplifying the synchronization mechanisms, that
+** we really need to do so -- or so says Tom, at least.
+** I remain unconvinced. -Fergus.)
+*/
+typedef Word AtomicBool;
extern AtomicBool *procwaiting;
- /*
- ** my_procnum is the number of the current process.
- ** my_procnum == 0 is the original parent process.
- */
+/*
+** my_procnum is the number of the current process.
+** my_procnum == 0 is the original parent process.
+*/
extern int my_procnum;
extern pid_t my_procid;
- /*
- ** The minimum value of hp to which the current context
- ** may truncate the heap on backtracking. see the comments
- ** below next to the set_min_heap_reclamation_point macro.
- */
+/*
+** The minimum value of hp to which the current context
+** may truncate the heap on backtracking. see the comments
+** below next to the set_min_heap_reclamation_point macro.
+*/
extern Word *min_heap_reclamation_point;
- /* do a context switch */
+/* do a context switch */
Declare_entry(do_runnext);
#define runnext() GOTO(ENTRY(do_runnext));
- /*
- ** schedule(Context *cptr, Code *resume):
- ** setup a call to do_schedule which
- ** adds the context pointed to by `cptr' to the runqueue then
- ** branches to `resume'.
- */
+/*
+** schedule(Context *cptr, Code *resume):
+** setup a call to do_schedule which
+** adds the context pointed to by `cptr' to the runqueue then
+** branches to `resume'.
+*/
Declare_entry(do_schedule);
extern Context *do_schedule_cptr;
extern Code *do_schedule_resume;
@@ -222,13 +237,13 @@
GOTO(ENTRY(do_schedule)); \
} while(0)
- /*
- ** fork_new_context(Code *child, Code *parent, int numslots):
- ** create a new context to execute the code at `child', and
- ** copy the topmost `numslots' from the current stackframe.
- ** The new context gets put on the runqueue, and the current
- ** context resumes at `parent'.
- */
+/*
+** fork_new_context(Code *child, Code *parent, int numslots):
+** create a new context to execute the code at `child', and
+** copy the topmost `numslots' from the current stackframe.
+** The new context gets put on the runqueue, and the current
+** context resumes at `parent'.
+*/
#define fork_new_context(child, parent, numslots) do { \
Context *fork_new_context_context; \
int fork_new_context_i; \
Index: context.mod
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/context.mod,v
retrieving revision 1.2
diff -u -r1.2 context.mod
--- 1.2 1997/02/07 18:40:02
+++ context.mod 1997/02/08 07:00:26
@@ -1,16 +1,24 @@
+/*
+** Copyright (C) 1995-1997 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.
+*/
+
+/* context.mod - handles multithreading stuff. */
+
#include "imp.h"
-#include <unistd.h>
+#include <assert.h>
+#include <unistd.h> /* for getpid() and fork() */
+#ifdef PARALLEL
#include <signal.h>
+#endif
#include "context.h"
#ifdef PARALLEL
int numprocs = 1;
#endif
-
-Context *new_context(void);
-void delete_context(Context *context);
#ifdef PARALLEL
pid_t *procid;
Index: debug.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/debug.h,v
retrieving revision 1.7
diff -u -r1.7 debug.h
--- 1.7 1997/01/09 07:08:52
+++ debug.h 1997/02/08 03:45:23
@@ -1,9 +1,11 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
+/* debug.h - definitions for debugging messages */
+
#ifndef DEBUG_H
#define DEBUG_H
@@ -14,8 +16,6 @@
#endif
#endif
-
-/* DEFINITIONS FOR DEBUGGING MESSAGES */
#if defined(SPEED) && !defined(DEBUG_GOTOS)
Index: deep_copy.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/deep_copy.c,v
retrieving revision 1.4
diff -u -r1.4 deep_copy.c
--- 1.4 1997/02/06 04:22:57
+++ deep_copy.c 1997/02/08 05:21:29
@@ -5,8 +5,8 @@
*/
/*
- * This module defines the deep copy function.
- */
+** This module defines the deep_copy() function.
+*/
#include "imp.h"
#include "deep_copy.h"
@@ -21,7 +21,6 @@
static Word * make_type_info(Word *term_type_info, Word *arg_pseudo_type_info,
bool *allocated);
-
/*
** Due to the depth of the control here, we'll use 4 space indentation.
*/
@@ -355,6 +354,4 @@
} else {
return arg_pseudo_type_info;
}
-
}
-
Index: deep_copy.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/deep_copy.h,v
retrieving revision 1.2
diff -u -r1.2 deep_copy.h
--- 1.2 1997/01/31 05:35:13
+++ deep_copy.h 1997/02/08 03:46:50
@@ -4,11 +4,12 @@
** Public License - see the file COPYING.LIB in the Mercury distribution.
*/
+/* deepcopy.h - declares the deep_copy() function. */
+
#ifndef DEEP_COPY_H
#define DEEP_COPY_H
-#include "imp.h"
-
+#include "mercury_types.h" /* for `Word' */
/* Deep Copy:
**
Index: dlist.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/dlist.c,v
retrieving revision 1.3
diff -u -r1.3 dlist.c
--- 1.3 1995/10/24 07:13:13
+++ dlist.c 1997/02/08 05:22:26
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995, 1997 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.
*/
@@ -17,7 +17,7 @@
** Make an empty list.
*/
-List *makelist0()
+List *makelist0(void)
{
reg List *list;
Index: dlist.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/dlist.h,v
retrieving revision 1.3
diff -u -r1.3 dlist.h
--- 1.3 1995/10/24 07:13:14
+++ dlist.h 1997/02/08 03:48:31
@@ -1,15 +1,15 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
/*
-** Definitions for the list module.
+** dlist.h - defines a doubly-linked list type.
*/
-#ifndef LIST_H
-#define LIST_H
+#ifndef DLIST_H
+#define DLIST_H
/*
** The lists we use are doubly-linked.
@@ -69,4 +69,4 @@
extern void dlist_delete(List *, List *, void (*)(void *));
extern void oldlist(List *, void (*)(void *));
-#endif /* LIST_H */
+#endif /* DLIST_H */
Index: dummy.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/dummy.c,v
retrieving revision 1.7
diff -u -r1.7 dummy.c
--- 1.7 1995/12/28 03:58:34
+++ dummy.c 1997/02/08 05:22:53
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1993-1995 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.
*/
Index: engine.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/engine.h,v
retrieving revision 1.10
diff -u -r1.10 engine.h
--- 1.10 1997/02/06 23:11:06
+++ engine.h 1997/02/08 05:35:12
@@ -1,11 +1,21 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
+/*
+** engine.h - definitions for the Mercury runtime engine.
+**
+** For documentation, see the comments in engine.mod.
+*/
+
#ifndef ENGINE_H
#define ENGINE_H
+
+#include "std.h" /* for `bool' */
+#include "mercury_types.h" /* for `Code *' */
+#include "goto.h" /* for `Define_entry()' */
#define PROGFLAG 0
#define GOTOFLAG 1
Index: engine.mod
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/engine.mod,v
retrieving revision 1.37
diff -u -r1.37 engine.mod
--- 1.37 1997/02/06 23:11:13
+++ engine.mod 1997/02/08 07:02:49
@@ -5,10 +5,14 @@
*/
#include "imp.h"
-#include "dummy.h"
+#include <stdio.h>
#include <string.h>
#include <setjmp.h>
+
+#include "engine.h"
+
+#include "dummy.h"
#ifdef USE_GCC_NONLOCAL_GOTOS
Index: getopt.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/getopt.h,v
retrieving revision 1.5
diff -u -r1.5 getopt.h
--- 1.5 1995/05/29 02:03:44
+++ getopt.h 1997/02/08 03:55:20
@@ -4,6 +4,15 @@
** Public License - see the file COPYING.LIB in the Mercury distribution.
*/
+/*
+** getopt.h - declares the interface to the system function getopt()
+**
+** We use this file rather than the system's <getopt.h>
+** because different systems have different ideas about
+** where the `const's should go on the declaration of getopt().
+** Also, some systems might have getopt() but not <getopt.h>.
+*/
+
#ifndef GETOPT_H
#define GETOPT_H
Index: goto.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/goto.h,v
retrieving revision 1.25
diff -u -r1.25 goto.h
--- 1.25 1997/02/08 01:14:13
+++ goto.h 1997/02/08 06:56:12
@@ -1,10 +1,16 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
-/* DEFINITIONS FOR THE "PORTABLE ASSEMBLER" NON-LOCAL GOTOS */
+/* goto.h - definitions for the "portable assembler" non-local gotos */
+
+#ifndef GOTO_H
+#define GOTO_H
+
+#include "mercury_types.h" /* for `Code *' */
+#include "debug.h" /* for debuggoto() */
/*
** Taking the address of a label can inhibit gcc's optimization,
@@ -559,7 +565,7 @@
#endif /* !defined(USE_GCC_NONLOCAL_GOTOS) */
-/* DEFINITIONS FOR COMPUTED GOTOS */
+/* definitions for computed gotos */
#define COMPUTED_GOTO(val, labels) \
{ static Code *jump_table[] = { \
@@ -568,3 +574,5 @@
GOTO(jump_table[val]); \
}
#define AND , /* used to separate the labels */
+
+#endif /* GOTO_H */
Index: heap.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/heap.h,v
retrieving revision 1.8
diff -u -r1.8 heap.h
--- 1.8 1997/02/08 01:16:12
+++ heap.h 1997/02/08 04:00:00
@@ -1,15 +1,16 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
+/* heap.h - definitions for manipulating the Mercury heap */
+
#ifndef HEAP_H
#define HEAP_H
-#include "context.h" /* for min_heap_reclamation_point */
-
-/* DEFINITIONS FOR MANIPULATING THE HEAP */
+#include "mercury_types.h" /* for `Word' */
+#include "context.h" /* for min_heap_reclamation_point() */
#ifdef CONSERVATIVE_GC
@@ -110,7 +111,7 @@
#define hp_alloc(count) incr_hp(hp,count)
#define hp_alloc_atomic(count) incr_hp_atomic(count)
-#endif
+#endif /* ! CONSERVATIVE_GC */
#define incr_hp(dest,count) tag_incr_hp((dest),mktag(0),(count))
#define incr_hp_atomic(dest,count) \
Index: imp.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/imp.h,v
retrieving revision 1.105
diff -u -r1.105 imp.h
--- 1.105 1997/02/07 18:40:04
+++ imp.h 1997/02/08 07:02:13
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
@@ -12,6 +12,8 @@
** systems, the system header files include inline functions, and this
** causes problems when using global register variables, as gcc requires
** global register variable declarations to precede any function definitions.
+**
+** This file just #includes most of the other Mercury runtime header files.
*/
#ifndef IMP_H
@@ -22,299 +24,38 @@
#define NDEBUG
#endif
-/* GENERAL DEFINITIONS */
-
-#include "conf.h"
-
-/* Note that we require sizeof(Word) == sizeof(Integer) == sizeof(Code*) */
-/* this is assured by the autoconfiguration script */
-
-typedef unsigned WORD_TYPE Word;
-typedef WORD_TYPE Integer;
-typedef unsigned WORD_TYPE Unsigned;
-typedef void Code; /* code addresses are `void *' */
-
#include "regs.h" /* must come before system headers */
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include <assert.h>
-#include <sys/types.h>
-
-#include "std.h"
-
-/* continuation function type, for --high-level-C option */
-typedef void (*Cont) (void);
-
-/*
-** semidet predicates indicate success or failure by leaving nonzero or zero
-** respectively in register r1
-*/
-#define SUCCESS_INDICATOR r1
-
-#include "prof.h"
-
-/* DEFINITIONS FOR CALLS AND RETURNS */
-
-#define noprof_localcall(label, succ_cont) \
- do { \
- debugcall(LABEL(label), (succ_cont)); \
- succip = (succ_cont); \
- set_prof_current_proc(LABEL(label)); \
- GOTO_LABEL(label); \
- } while (0)
-
-#if defined(__alpha__) && defined(USE_ASM_LABELS)
-#define noprof_call(proc, succ_cont) \
- ({ \
- __label__ fixup_gp; \
- debugcall((proc), (succ_cont)); \
- succip = (&&fixup_gp); \
- set_prof_current_proc(proc); \
- GOTO(proc); \
- fixup_gp: \
- __asm__ __volatile__ ( \
- "ldgp $gp, 0($27)" \
- : : : "memory" \
- ); \
- GOTO(succ_cont); \
- })
- /* same as above, but with GOTO_LABEL rather than GOTO */
-#define noprof_call_localret(proc, succ_cont) \
- ({ \
- __label__ fixup_gp; \
- debugcall((proc), (succ_cont)); \
- succip = (&&fixup_gp); \
- set_prof_current_proc(proc); \
- GOTO(proc); \
- fixup_gp: \
- __asm__ __volatile__ ( \
- "ldgp $gp, 0($27)" \
- : : : "memory" \
- ); \
- GOTO_LABEL(succ_cont); \
- })
-#else
-#define noprof_call(proc, succ_cont) \
- do { \
- debugcall((proc), (succ_cont)); \
- succip = (succ_cont); \
- set_prof_current_proc(proc); \
- GOTO(proc); \
- } while (0)
-#define noprof_call_localret(proc, succ_cont) \
- noprof_call((proc), LABEL(succ_cont))
-#endif
-
-#define localcall(label, succ_cont, current_label) \
- do { \
- debugcall(LABEL(label), (succ_cont)); \
- succip = (succ_cont); \
- PROFILE(LABEL(label), (current_label)); \
- set_prof_current_proc(LABEL(label)); \
- GOTO_LABEL(label); \
- } while (0)
-
-#define call(proc, succ_cont, current_label) \
- do { \
- PROFILE((proc), (current_label)); \
- noprof_call((proc), (succ_cont)); \
- } while (0)
-
-#define call_localret(proc, succ_cont, current_label) \
- do { \
- PROFILE((proc), (current_label)); \
- noprof_call_localret(proc, succ_cont); \
- } while (0)
-
-#define call_det_closure(succ_cont, current_label) \
- do { \
- Declare_entry(do_call_det_closure); \
- call(ENTRY(do_call_det_closure), \
- (succ_cont), (current_label)); \
- } while (0)
-
-#define call_semidet_closure(succ_cont, current_label) \
- do { \
- Declare_entry(do_call_semidet_closure); \
- call(ENTRY(do_call_semidet_closure), \
- (succ_cont), (current_label)); \
- } while (0)
-
-#define call_nondet_closure(succ_cont, current_label) \
- do { \
- Declare_entry(do_call_nondet_closure); \
- call(ENTRY(do_call_nondet_closure), \
- (succ_cont), (current_label)); \
- } while (0)
-
-#define localtailcall(label, current_label) \
- do { \
- debugtailcall(LABEL(label)); \
- PROFILE(LABEL(label), (current_label)); \
- set_prof_current_proc(LABEL(label)); \
- GOTO_LABEL(label); \
- } while (0)
-
-#define tailcall(proc, current_label) \
- do { \
- debugtailcall(proc); \
- PROFILE((proc), (current_label)); \
- set_prof_current_proc(proc); \
- GOTO(proc); \
- } while (0)
-
-#define proceed() \
- do { \
- debugproceed(); \
- GOTO(succip); \
- } while (0)
-
-/* STRING HANDLING */
-
-typedef char Char; /* we may eventually move to using wchar_t */
-
-typedef Char *String;
-typedef const Char *ConstString;
-
-#define string_const(string, len) ((Word)string)
-#define string_equal(s1,s2) (strcmp((char*)(s1),(char*)(s2))==0)
-
-
-/*
-** If the string is aligned, set ptr equal to it, otherwise allocate one
-** on the heap.
-*/
-#define make_aligned_string(ptr, string) \
- ( tag((Word)string) != 0 ? \
- (incr_hp_atomic(LVALUE_CAST(Word, (ptr)), \
- (strlen(string) + sizeof(Word)) / sizeof(Word)), \
- strcpy((ptr), (string))) \
- : \
- ((ptr) = (string)) \
- )
-
-/*
-** Note that hash_string is also defined in library/string.m.
-** The definition here and the definition in string.m
-** must be kept equivalent.
-*/
-
-#define do_hash_string(hash,s) \
- { \
- int len = 0; \
- hash = 0; \
- while(((const char *)(s))[len]) { \
- hash ^= (hash << 5); \
- hash ^= ((const char *)(s))[len]; \
- len++; \
- } \
- hash ^= len; \
- }
-
-extern int hash_string(Word);
-
-#ifdef __GNUC__
-#define hash_string(s) \
- ({ int hash; \
- do_hash_string(hash,s); \
- hash; \
- })
-#endif
-
-/* if we're not using gcc, the actual definition of hash_string is in aux.c */
-/* it uses the macro HASH_STRING_FUNC_BODY below */
-
-#define HASH_STRING_FUNC_BODY \
- int hash; \
- do_hash_string(hash, s); \
- return hash;
-
-/* FLOATING POINT HANDLING */
-
-#ifdef USE_SINGLE_PREC_FLOAT
-
-typedef float Float;
-
-#else
-typedef double Float;
-
-#endif
-
-#ifdef BOXED_FLOAT
-
-#define word_to_float(w) (*(Float *)(w))
-
-#define FLOAT_WORDS ((sizeof(Float) + sizeof(Word) - 1) / sizeof(Word))
-
-#ifdef CONSERVATIVE_GC
-#define float_to_word(f) ( \
- hp_alloc(FLOAT_WORDS), \
- *(Float *)(void *)(hp - FLOAT_WORDS) = (f), \
- /* return */ (Word) (hp - FLOAT_WORDS) \
- )
-#else
-/* we need to ensure that what we allocated on the heap is properly
- aligned */
-#define float_to_word(f) ( \
- ( (Word)hp & (sizeof(Float) - 1) ? hp_alloc(1) : (void)0 ), \
- hp_alloc(FLOAT_WORDS), \
- *(Float *)(void *)(hp - FLOAT_WORDS) = (f), \
- /* return */ (Word) (hp - FLOAT_WORDS) \
- )
-#endif
-
-#ifdef __GNUC__
-#define float_const(f) ({ static const Float d = f; (Word)&d; })
-#else
-#define float_const(f) float_to_word(f) /* inefficient */
-#endif
-
-#else /* not BOXED_FLOAT */
-
-/* unboxed float means we can assume sizeof(Float) == sizeof(Word) */
-
-union FloatWord {
- Float f;
- Word w;
-};
-
-#define float_const(f) float_to_word(f)
-
-#ifdef __GNUC__
-
-#define float_to_word(f) (__extension__ ((union FloatWord)(Float)(f)).w)
-#define word_to_float(w) (__extension__ ((union FloatWord)(Word)(w)).f)
-
-#else
-
-static Word float_to_word(Float f) { union FloatWord tmp = f; return tmp.w; }
-static Float word_to_float(Word w) { union FloatWord tmp = w; return tmp.f; }
+#include "conf.h"
-#endif
+#include "std.h"
-#endif
+#include "mercury_types.h"
+#include "mercury_string.h"
+#include "mercury_float.h"
#include "tags.h"
#include "goto.h"
+#include "calls.h"
#include "engine.h"
+#include "memory.h"
#include "heap.h"
#include "stacks.h"
#include "overflow.h"
-#include "debug.h"
-#include "misc.h"
#include "label.h"
-#include "memory.h"
#include "wrapper.h"
#include "context.h"
#include "type_info.h"
#ifdef CONSTRAINTS
#include "mercury_solver_backtrack.h"
#endif
+
+#include "debug.h"
+#include "prof.h"
+#include "misc.h"
#endif /* IMP_H */
Index: init.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/init.h,v
retrieving revision 1.11
diff -u -r1.11 init.h
--- 1.11 1997/01/31 23:22:06
+++ init.h 1997/02/08 04:03:17
@@ -1,17 +1,19 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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 defines stuff used by the automatically generated *_init.c files.
+** init.h - this file defines stuff used by the automatically generated
+** _init.c files.
*/
#ifndef INIT_H
#define INIT_H
-#include "imp.h"
+#include "goto.h" /* for Declare_entry */
+#include "mercury_types.h" /* for `Code *' */
/*
** mercury_main() is defined in the <module>_init.c file.
@@ -47,10 +49,11 @@
extern void mercury_init_io(void);
/*
-** The following global variables are set by mercury_main().
+** The following global variables are defined in wrapper.mod,
+** and set by mercury_main() on startup.
** The entry points are set based on the options to mkinit.c.
** The address_of_foo pointers are set to the address of
-** the correspoinding foo.
+** the corresponding foo.
*/
extern Code * library_entry_point; /* normally mercury__io__run_0_0 */
extern Code * program_entry_point; /* normally mercury__main_2_0; */
@@ -61,4 +64,4 @@
extern void (*address_of_init_gc)(void);
#endif
-#endif
+#endif /* INIT_H */
Index: label.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/label.c,v
retrieving revision 1.18
diff -u -r1.18 label.c
--- 1.18 1995/09/23 15:46:22
+++ label.c 1997/02/08 06:58:17
@@ -1,15 +1,25 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
-#include "imp.h"
-#include "table.h"
-#include "prof.h"
-#include "init.h"
+/*
+** label.c defines the label table, which is a pair of hash tables
+** that map from procedure names to addresses and vice versa.
+*/
+#include <stdio.h>
#include <string.h>
+
+#include "conf.h"
+
+#include "label.h"
+
+#include "table.h" /* for `Table' */
+#include "prof.h" /* for prof_output_addr_decls() */
+#include "engine.h" /* for `progdebug' */
+#include "wrapper.h" /* for do_init_modules() */
static const void *entry_name(const void *entry);
static const void *entry_addr(const void *entry);
Index: label.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/label.h,v
retrieving revision 1.11
diff -u -r1.11 label.h
--- 1.11 1995/08/26 08:15:42
+++ label.h 1997/02/08 04:04:21
@@ -1,13 +1,19 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
+/*
+** label.h defines the interface to the label table, which is a pair of
+** hash tables mapping from procedure names to addresses and vice versa.
+*/
+
#ifndef LABEL_H
#define LABEL_H
-#include "dlist.h"
+#include "mercury_types.h" /* for `Code *' */
+#include "dlist.h" /* for `List' */
typedef struct s_label
{
Index: memory.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/memory.c,v
retrieving revision 1.59
diff -u -r1.59 memory.c
--- 1.59 1997/02/07 18:40:07
+++ memory.c 1997/02/08 05:23:35
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1994-1997 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.
*/
Index: memory.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/memory.h,v
retrieving revision 1.23
diff -u -r1.23 memory.h
--- 1.23 1997/02/07 18:40:08
+++ memory.h 1997/02/08 04:11:15
@@ -1,15 +1,29 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
+/*
+** 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 MEMORY_H
#define MEMORY_H
-#include "regs.h"
-#include <stdlib.h>
-#include "std.h"
+#include "regs.h" /* for NUM_REAL_REGS */
+
+#include <stdlib.h> /* for size_t */
+
+#include "mercury_types.h" /* for Word */
+#include "std.h" /* for bool */
+
/* these cannot be changed without lots of modifications elsewhere */
#define MAX_REAL_REG 32 /* r1 .. r32 */
cvs diff: mercury_float.h is a new entry, no comparison available
Index: mercury_solver_backtrack.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_solver_backtrack.h,v
retrieving revision 1.5
diff -u -r1.5 mercury_solver_backtrack.h
--- 1.5 1996/06/13 07:59:17
+++ mercury_solver_backtrack.h 1997/02/08 04:16:28
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1996-1997 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.
*/
@@ -18,9 +18,8 @@
#ifndef MERCURY_SOLVER_BACKTRACK_H
#define MERCURY_SOLVER_BACKTRACK_H
- /* Mercury headers */
-#include "imp.h"
-#include "misc.h"
+#include <stdio.h> /* for `FILE' */
+
/* This constant is also defined in the */
/* CLP(R) headers, but we'll define it */
cvs diff: mercury_string.h is a new entry, no comparison available
cvs diff: mercury_types.h is a new entry, no comparison available
Index: misc.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/misc.c,v
retrieving revision 1.6
diff -u -r1.6 misc.c
--- 1.6 1997/02/06 23:11:37
+++ misc.c 1997/02/08 05:24:17
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1996-1997 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.
*/
@@ -7,6 +7,7 @@
#include "imp.h"
#include "dlist.h"
#include "access.h"
+#include "misc.h"
/*--------------------------------------------------------------------*/
Index: misc.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/misc.h,v
retrieving revision 1.1
diff -u -r1.1 misc.h
--- 1.1 1996/05/14 08:13:32
+++ misc.h 1997/02/08 04:24:11
@@ -1,11 +1,15 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
-#ifndef AUX_H
-#define AUX_H
+/* misc.h - debugging messages, fatal_error(), and checked_malloc() */
+
+#ifndef MISC_H
+#define MISC_H
+
+#include "mercury_types.h" /* for `Code *' */
#ifndef SPEED
@@ -62,6 +66,8 @@
#endif
extern void fatal_error(const char *msg) NO_RETURN;
+/* XXX checked_malloc() should be moved to memory.h or heap.h */
+#include <stddef.h> /* for size_t */
void *checked_malloc(size_t n);
-#endif
+#endif /* MISC_H */
Index: overflow.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/overflow.h,v
retrieving revision 1.4
diff -u -r1.4 overflow.h
--- 1.4 1997/01/08 06:09:07
+++ overflow.h 1997/02/08 04:28:00
@@ -1,14 +1,17 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
-/* DEFINITIONS FOR OVERFLOW CHECKS */
+/* overflow.h - definitions for overflow checks */
-#define IF(cond, val) ((cond) ? (val),(void)0 : (void)0)
+#ifndef OVERFLOW_H
+#define OVERFLOW_H
-#ifdef SPEED
+#define IF(cond, val) ((cond) ? ((val), (void)0) : (void)0)
+
+#ifdef SPEED
#define heap_overflow_check() ((void)0)
#define detstack_overflow_check() ((void)0)
@@ -16,7 +19,10 @@
#define nondstack_overflow_check() ((void)0)
#define nondstack_underflow_check() ((void)0)
-#else
+#else /* not SPEED */
+
+#include "regs.h"
+#include "misc.h" /* for fatal_error() */
#define heap_overflow_check() \
( \
@@ -67,4 +73,6 @@
(void)0 \
)
-#endif
+#endif /* not SPEED */
+
+#endif /* OVERFLOW_H */
Index: prof.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/prof.c,v
retrieving revision 1.26
diff -u -r1.26 prof.c
--- 1.26 1996/11/06 13:47:21
+++ prof.c 1997/02/08 05:25:18
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1996 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.
*/
@@ -15,6 +15,8 @@
#include <unistd.h>
#include <errno.h>
#include <string.h>
+
+#include "prof.h"
#include "std.h"
#include "prof_mem.h"
Index: prof.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/prof.h,v
retrieving revision 1.9
diff -u -r1.9 prof.h
--- 1.9 1996/03/24 06:40:57
+++ prof.h 1997/02/08 03:26:07
@@ -4,9 +4,13 @@
** Public License - see the file COPYING.LIB in the Mercury distribution.
*/
+/* prof.h -- definitions for profiling */
+
#ifndef PROF_H
#define PROF_H
+#include "mercury_types.h" /* for `Code *' */
+
/*
** this variable holds the address of the "current" procedure so that
** when a profiling interrupt occurs, the profiler knows where we are,
@@ -42,4 +46,4 @@
extern void prof_output_addr_decls(const char *, const Code *);
extern void prof_output_addr_table(void);
-#endif
+#endif /* PROF_H */
Index: prof_mem.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/prof_mem.c,v
retrieving revision 1.2
diff -u -r1.2 prof_mem.c
--- 1.2 1996/11/07 12:31:28
+++ prof_mem.c 1997/02/08 03:29:49
@@ -1,4 +1,10 @@
/*
+** Copyright (C) 1996-1997 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.
+*/
+
+/*
** prof_mem.c
**
** Author: petdr
@@ -11,12 +17,11 @@
** as mercury will no longer use malloc anymore.
*/
-
#include <stdio.h>
-#include "std.h"
#include "prof_mem.h"
+#include "std.h" /* for newmem() */
/*----------------------------------------------------------------------------*/
@@ -35,7 +40,7 @@
/*
** Private Global Variables
*/
-static size_t mem_left = 0; /* Number of units left */
+static size_t mem_left = 0; /* Number of bytes left */
static void *next = NULL; /* Pointer to next data block */
/* we can give away */
Index: prof_mem.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/prof_mem.h,v
retrieving revision 1.4
diff -u -r1.4 prof_mem.h
--- 1.4 1996/11/07 12:31:29
+++ prof_mem.h 1997/02/08 04:28:31
@@ -1,10 +1,30 @@
/*
-** prof_mem.h
+** Copyright (C) 1996-1997 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.
+*/
+
+/*
+** prof_mem.h - defines memory allocation functions used to hold
+** the tables of profiling counts.
**
** Author: petdr
*/
-#include <stdlib.h>
-#define prof_make(t) ((t *) prof_malloc(sizeof(t)))
+#ifndef PROF_MEM_H
+#define PROF_MEM_H
+
+#include <stddef.h> /* for size_t */
+/*
+** prof_malloc() allocates memory in large chunks using newmem(),
+** and then doles out portions of these chunks one at a time.
+** We use prof_malloc() to reduce the chance of calling newmem()
+** from a profiling interrupt that interrupted another call to newmem().
+** Doing that is bad news, because newmem() is not re-entrant.
+*/
void *prof_malloc(size_t);
+
+#define prof_make(t) ((t *) prof_malloc(sizeof(t)))
+
+#endif
Index: regorder.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/regorder.h,v
retrieving revision 1.14
diff -u -r1.14 regorder.h
--- 1.14 1995/12/28 03:58:38
+++ regorder.h 1997/02/08 04:37:47
@@ -1,10 +1,20 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995, 1997 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.
*/
/*
+** regorder.h - defines the mapping from the Mercury abstract machine
+** registers (r1, r2, ..., hp, sp, etc.) to the underlying intermediate-level
+** abstract machine memory (mr0, mr1, ...).
+**
+** This file should be #included from "regs.h" and nowhere else.
+** The reason this is separate from "regs.h" is so that it could,
+** at least in theory, be generated automatically based on
+** profiling feedback from the register usage counts for a particular
+** application. However, currently we don't do that.
+**
** If you change this file, you should also change the settings of
** NUM_REAL_R_REGS in ../configure.in.
*/
cvs diff: regorder_base.h was removed, no comparison available
Index: regs.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/regs.h,v
retrieving revision 1.25
diff -u -r1.25 regs.h
--- 1.25 1997/01/31 07:55:41
+++ regs.h 1997/02/08 04:39:05
@@ -1,11 +1,14 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
#ifndef REGS_H
#define REGS_H
+
+#include "conf.h"
+#include "mercury_types.h"
/*
** GNU C allows lvalue casts, so if we have gcc, use them.
Index: spinlock.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/spinlock.c,v
retrieving revision 1.2
diff -u -r1.2 spinlock.c
--- 1.2 1997/02/07 18:40:10
+++ spinlock.c 1997/02/08 05:26:12
@@ -1,3 +1,13 @@
+/*
+** Copyright (C) 1997 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.
+*/
+
+/*
+** spinlock.c - defines the code for locking and unlocking spin locks.
+*/
+
#include "imp.h"
#include "spinlock.h"
Index: spinlock.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/spinlock.h,v
retrieving revision 1.2
diff -u -r1.2 spinlock.h
--- 1.2 1997/02/07 18:40:12
+++ spinlock.h 1997/02/08 05:48:12
@@ -1,3 +1,11 @@
+/*
+** Copyright (C) 1995-1997 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.
+*/
+
+/* spinlock.h - defines spin locks (locks obtained by busy-waiting) */
+
#ifndef SPINLOCK_H
#define SPINLOCK_H
@@ -39,12 +47,10 @@
** but code elsewhere should avoid depending on these details.
*/
-#include "imp.h" /* for `Word' */
-#include <stddef.h> /* for `NULL' */
-#include "conf.h" /* for `PARALLEL' */
-#include "context.h" /* for `numprocs' */
-
-typedef Word SpinLock;
+#include "mercury_types.h" /* for `SpinLock' and `Word' */
+#include <stddef.h> /* for `NULL' */
+#include "conf.h" /* for `PARALLEL' */
+#include "context.h" /* for `numprocs' */
void do_spinlock(SpinLock *s);
Index: stacks.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/stacks.h,v
retrieving revision 1.5
diff -u -r1.5 stacks.h
--- 1.5 1997/01/23 00:30:52
+++ stacks.h 1997/02/08 04:43:19
@@ -1,9 +1,20 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
+/* stacks.h - definitions for manipulation the det and nondet stacks */
+
+#ifndef STACKS_H
+#define STACKS_H
+
+#include "regs.h"
+#include "mercury_types.h"
+#include "overflow.h"
+#include "debug.h"
+#include "goto.h"
+
/* DEFINITIONS FOR MANIPULATING THE DET STACK */
#define detstackvar(n) sp[-n]
@@ -160,3 +171,5 @@
curfr = maxfr; \
GOTO(curredoip); \
} while (0)
+
+#endif /* STACKS_H */
Index: std.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/std.h,v
retrieving revision 1.13
diff -u -r1.13 std.h
--- 1.13 1995/10/24 07:22:31
+++ std.h 1997/02/08 04:50:29
@@ -1,18 +1,19 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1993-1995, 1997 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.
*/
+/*
+** std.h - "standard" [sic] definitions for C:
+** bool, TRUE, FALSE, min(), max(), streq(), etc.
+*/
+
#ifndef STD_H
#define STD_H
#include <stdlib.h> /* for size_t */
-/*
-** Standard definitions for C
-*/
-
#ifndef reg
#define reg register
#endif
@@ -51,6 +52,7 @@
#define ungetchar(c) ungetc(c, stdin)
+/* XXX these should go in memory.h or heap.h */
#define make(t) ((t *) newmem(sizeof(t)))
#define make_many(t, n) ((t *) newmem((n) * sizeof(t)))
#define resize_many(t, p, n) ((t *) resizemem((p), (n) * sizeof(t)))
@@ -62,6 +64,7 @@
#define FALSE 0
#endif
+/* XXX these should go in memory.h or heap.h */
extern void *newmem(size_t);
extern void *resizemem(void *, size_t);
extern void oldmem(void *);
Index: table.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/table.c,v
retrieving revision 1.12
diff -u -r1.12 table.c
--- 1.12 1996/12/12 11:53:53
+++ table.c 1997/02/08 05:27:22
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1993-1996 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.
*/
Index: table.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/table.h,v
retrieving revision 1.8
diff -u -r1.8 table.h
--- 1.8 1995/05/29 02:04:05
+++ table.h 1997/02/08 05:16:39
@@ -1,17 +1,18 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1993-1995, 1997 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.
*/
/*
-** Definitions for the table module.
+** table.h - defines the interface to the hash table module.
*/
#ifndef TABLE_H
#define TABLE_H
-#include "dlist.h"
+#include "std.h" /* for bool */
+#include "dlist.h" /* for List */
typedef struct s_table
{
Index: tags.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/tags.h,v
retrieving revision 1.16
diff -u -r1.16 tags.h
--- 1.16 1997/01/16 14:07:57
+++ tags.h 1997/02/08 05:03:41
@@ -1,13 +1,20 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1993-1997 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.
*/
+/*
+** tags.h - defines macros for tagging and untagging words.
+** Also defines macros for accessing the Mercury list type from C.
+*/
+
#ifndef TAGS_H
#define TAGS_H
-#include <limits.h>
+#include <limits.h> /* for `CHAR_BIT' */
+#include "conf.h" /* for `LOW_TAG_BITS' */
+#include "mercury_types.h" /* for `Word' */
/* DEFINITIONS FOR WORD LAYOUT */
@@ -15,15 +22,15 @@
/* TAGBITS specifies the number of bits in each word that we can use for tags */
#ifndef TAGBITS
-#ifdef HIGHTAGS
-#error "HIGHTAGS defined but TAGBITS undefined"
-#else
-#define TAGBITS LOW_TAG_BITS
-#endif
+ #ifdef HIGHTAGS
+ #error "HIGHTAGS defined but TAGBITS undefined"
+ #else
+ #define TAGBITS LOW_TAG_BITS
+ #endif
#endif
#if TAGBITS > 0 && defined(HIGHTAGS) && defined(CONSERVATIVE_GC)
-#error "Conservative GC does not work with high tag bits"
+ #error "Conservative GC does not work with high tag bits"
#endif
#ifdef HIGHTAGS
@@ -35,7 +42,7 @@
#define unmkbody(w) (w)
#define body(w, t) ((w) & (~(Word)0 >> TAGBITS))
-#else
+#else /* ! HIGHTAGS */
#define mktag(t) (t)
#define unmktag(w) (w)
@@ -44,7 +51,7 @@
#define unmkbody(w) ((Word) (w) >> TAGBITS)
#define body(w, t) ((w) - (t))
-#endif
+#endif /* ! HIGHTAGS */
/*
** the result of mkword() is cast to (const Word *), not to (Word)
Index: timing.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/timing.h,v
retrieving revision 1.5
diff -u -r1.5 timing.h
--- 1.5 1995/05/29 02:04:07
+++ timing.h 1997/02/08 04:59:15
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1993-1995 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.
*/
Index: type_info.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/type_info.h,v
retrieving revision 1.13
diff -u -r1.13 type_info.h
--- 1.13 1997/02/04 01:25:10
+++ type_info.h 1997/02/08 06:55:21
@@ -1,13 +1,21 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1995-1997 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.
*/
+/*
+** type_info.h -
+** Definitions for accessing the type_infos and type_layouts
+** generated by the Mercury compiler.
+** Also contains definitions for accessing the Mercury `univ' type.
+*/
#ifndef TYPE_INFO_H
#define TYPE_INFO_H
+#include "mercury_types.h" /* for `Word' */
+
/*
** Decide which type_info representation we will use.
**
@@ -258,7 +266,7 @@
#define TYPELAYOUT_SIMPLE_FUNCTOR_OFFSET 1
#define TYPELAYOUT_SIMPLE_ARITY_OFFSET 0
-#define TYPELAYOUT_SIMPLE_ARGS_OFFSET 1
+#define TYPELAYOUT_SIMPLE_ARGS_OFFSET 1
/*
** Offsets for dealing with `univ' types.
@@ -268,7 +276,7 @@
** The second word contains the data.
*/
-#define UNIV_OFFSET_FOR_TYPEINFO 0
-#define UNIV_OFFSET_FOR_DATA 1
+#define UNIV_OFFSET_FOR_TYPEINFO 0
+#define UNIV_OFFSET_FOR_DATA 1
#endif
Index: wrapper.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/wrapper.h,v
retrieving revision 1.15
diff -u -r1.15 wrapper.h
--- 1.15 1997/01/26 00:38:04
+++ wrapper.h 1997/02/08 05:07:13
@@ -1,12 +1,20 @@
/*
-** Copyright (C) 1995 University of Melbourne.
+** Copyright (C) 1994-1997 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.
*/
+/*
+** wrapper.h - defines the interface to wrapper.mod.
+** See wrapper.mod for documentation.
+*/
+
#ifndef WRAPPER_H
#define WRAPPER_H
+#include <stddef.h> /* for `size_t' */
+#include "std.h" /* for `bool' */
+
extern void do_init_modules(void);
extern const char * progname;
@@ -14,17 +22,20 @@
extern char ** mercury_argv;
extern int mercury_exit_status;
-extern unsigned heap_size;
-extern unsigned detstack_size;
-extern unsigned nondstack_size;
-extern unsigned solutions_heap_size;
-
-extern unsigned heap_zone_size;
-extern unsigned detstack_zone_size;
-extern unsigned nondstack_zone_size;
-extern unsigned solutions_heap_zone_size;
+/* sizes of the data areas, *including* the red zone size */
+extern size_t heap_size;
+extern size_t detstack_size;
+extern size_t nondstack_size;
+extern size_t solutions_heap_size;
+
+/* sizes of the red zones */
+extern size_t heap_zone_size;
+extern size_t detstack_zone_size;
+extern size_t nondstack_zone_size;
+extern size_t solutions_heap_zone_size;
-extern unsigned pcache_size;
+/* size of the primary cache */
+extern size_t pcache_size;
extern int r1val;
extern int r2val;
Index: wrapper.mod
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/wrapper.mod,v
retrieving revision 1.70
diff -u -r1.70 wrapper.mod
--- 1.70 1997/02/07 18:40:14
+++ wrapper.mod 1997/02/08 07:02:55
@@ -17,63 +17,73 @@
*/
#include "imp.h"
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
#include "timing.h"
#include "getopt.h"
#include "init.h"
#include "dummy.h"
-#include <ctype.h>
-#include <string.h>
/* global variables concerned with testing (i.e. not with the engine) */
/* command-line options */
-/* size of data areas, in kilobytes */
-unsigned heap_size = 4096;
-unsigned detstack_size = 2048;
-unsigned nondstack_size = 128;
-unsigned solutions_heap_size = 1024;
+/* size of data areas (including redzones), in kilobytes */
+/* (but we later multiply by 1024 to convert to bytes) */
+size_t heap_size = 4096;
+size_t detstack_size = 2048;
+size_t nondstack_size = 128;
+size_t solutions_heap_size = 1024;
/* size of the redzones at the end of data areas, in kilobytes */
-unsigned heap_zone_size = 16;
-unsigned detstack_zone_size = 16;
-unsigned nondstack_zone_size = 16;
-unsigned solutions_heap_zone_size = 16;
-
-/* primary cache size to optimize for */
-unsigned pcache_size = 8192;
+/* (but we later multiply by 1024 to convert to bytes) */
+size_t heap_zone_size = 16;
+size_t detstack_zone_size = 16;
+size_t nondstack_zone_size = 16;
+size_t solutions_heap_zone_size = 16;
+
+/* primary cache size to optimize for, in kilobytes */
+/* (but we later multiply by 1024 to convert to bytes) */
+size_t pcache_size = 8192;
/* other options */
+
int r1val = -1;
int r2val = -1;
int r3val = -1;
-/* constraints solver */
-#ifdef CONSTRAINTS
-int *mercury_solver_sp;
-int *mercury_solver_sp_old;
-int solver_ticket_stack_size = SOLVER_STACK_SIZE;
-#endif
-
bool check_space = FALSE;
static bool benchmark_all_solns = FALSE;
static bool use_own_timer = FALSE;
static int repeats = 1;
-static int repcounter;
-
/* timing */
int time_at_last_stat;
int time_at_start;
static int time_at_finish;
const char * progname;
-int mercury_argc; /* not counting progname or debug options */
+int mercury_argc; /* not counting progname */
char ** mercury_argv;
int mercury_exit_status = 0;
/*
+** Constraint solver trail.
+**
+** XXX this should not be here; it should be in engine.mod
+** or constraints.c or somewhere like that.
+*/
+#ifdef CONSTRAINTS
+int *mercury_solver_sp;
+int *mercury_solver_sp_old;
+size_t solver_ticket_stack_size = SOLVER_STACK_SIZE;
+#endif
+
+/*
** The Mercury runtime calls io:run/0 in the Mercury library, and the Mercury
** library calls main/2 in the user's program. The Mercury runtime also calls
** init_gc() and init_modules() which are in the automatically generated
@@ -380,7 +390,9 @@
static void
process_options(int argc, char **argv)
{
+ unsigned long size;
int c;
+
while ((c = getopt(argc, argv, "acd:hLlp:r:s:tw:xz:1:2:3:")) != EOF)
{
switch (c)
@@ -464,11 +476,11 @@
exit(0);
}
- case 'p': if (sscanf(optarg, "%d", &pcache_size) != 1)
+ case 'p':
+ if (sscanf(optarg, "%lu", &size) != 1)
usage();
- if (pcache_size < 512)
- pcache_size *= 1024;
+ pcache_size = size * 1024;
break;
@@ -477,29 +489,28 @@
break;
- case 's': {
- int val;
- if (sscanf(optarg+1, "%d", &val) != 1)
+ case 's':
+ if (sscanf(optarg+1, "%lu", &size) != 1)
usage();
if (optarg[0] == 'h')
- heap_size = val;
+ heap_size = size;
else if (optarg[0] == 'd')
- detstack_size = val;
+ detstack_size = size;
else if (optarg[0] == 'n')
- nondstack_size = val;
+ nondstack_size = size;
else if (optarg[0] == 'l')
- entry_table_size = val *
+ entry_table_size = size *
1024 / (2 * sizeof(List *));
#ifdef CONSTRAINTS
else if (optarg[0] == 's')
- solver_ticket_stack_size = val;
+ solver_ticket_stack_size = size;
#endif
else
usage();
break;
- }
+
case 't': use_own_timer = TRUE;
calldebug = FALSE;
@@ -550,22 +561,21 @@
break;
- case 'z': {
- int val;
- if (sscanf(optarg+1, "%d", &val) != 1)
+ case 'z':
+ if (sscanf(optarg+1, "%lu", &size) != 1)
usage();
if (optarg[0] == 'h')
- heap_zone_size = val;
+ heap_zone_size = size;
else if (optarg[0] == 'd')
- detstack_zone_size = val;
+ detstack_zone_size = size;
else if (optarg[0] == 'n')
- nondstack_zone_size = val;
+ nondstack_zone_size = size;
else
usage();
break;
- }
+
case '1': if (sscanf(optarg, "%d", &r1val) != 1)
usage();
@@ -618,7 +628,7 @@
"-zh<n> \t\tallocate n kb for the heap redzone\n"
"-zd<n> \t\tallocate n kb for the det stack redzone\n"
"-zn<n> \t\tallocate n kb for the nondet stack redzone\n"
- "-p<n> \t\tprimary cache size in (k)bytes\n"
+ "-p<n> \t\tprimary cache size in kbytes\n"
"-r<n> \t\trepeat n times\n"
"-m<name> \tcall I/O predicate with given name (default: main/2)\n"
"-w<name> \tcall predicate with given name\n"
@@ -631,6 +641,8 @@
void run_code(void)
{
+ static int repcounter;
+
#if !defined(SPEED) && defined(USE_GCC_NONLOCAL_GOTOS)
/*
** double-check to make sure that we're not corrupting
cvs diff: Diffing machdeps
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list