[m-rev.] for review: MR_DEFINE_ENUM_CONST
David Jeffery
dgj at cs.mu.OZ.AU
Wed May 30 15:42:54 AEST 2001
Hi,
For Fergus, Tyson or Mark to review.
This has bootchecked in asm_fast.gc.rt, and the bootcheck in asm_fast.gc is
still running.
Let me know if you think any other specific grades need checking. I can't
think of any.
---------------------------------------------------------------------------
Estimated hours taken: 20
Branches: main
This diff fixes a bug that was causing the test case
tests/debugger/browser_test to fail in .rt grades. The problem was that some
code in the browser/tracer was assuming that the representation of Mercury
bools was '0'/'1'. This is not the case if we reserve the '0' tag for
variables.
runtime/mercury_tags.h:
Define a macro 'MR_DEFINE_ENUM_CONST' for wrapping around the
declarations of enumeration constants in C. The macro causes the
enumeration constant to be assigned the same value as our tag
allocation scheme assigns its Mercury counterpart. (In most grades
this is a no-op... in .rt grades it has to take the reserved tag
into account).
runtime/mercury_stack_layout.h:
runtime/mercury_type_info.h:
trace/mercury_trace_browse.h:
Wrap enum definitions in 'MR_DEFINE_ENUM_CONST'.
XXX:
- I have wrapped all the 'enum' declarations that I could find that
seemed to correspond to Mercury types. I have left all the others
alone. Perhaps there are some that I've missed? I don't think so.
In any case, we need to make sure that any code checked in in the
future wraps enum declarations in the new macro.
- dougl's bug fix that he committed yesterday fixed some of the places
(in the tracer) that assume that 'no' and 'yes' are assigned '0' and
'1' (whereas they are probably assigned '1' and '5' in .rt grades).
He did so by exporting a function from Mercury and using that in C.
Perhaps now we should define a C enum (with the wrapper macro) and use
*that* to test Mercury enums against when in C code instead.
---------------------------------------------------------------------------
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.49
diff -u -t -r1.49 mercury_stack_layout.h
--- runtime/mercury_stack_layout.h 2001/05/07 02:57:03 1.49
+++ runtime/mercury_stack_layout.h 2001/05/22 07:49:49
@@ -31,6 +31,7 @@
#include "mercury_types.h"
#include "mercury_std.h" /* for MR_VARIABLE_SIZED */
+#include "mercury_tags.h"
/* forward declarations */
typedef struct MR_Proc_Layout_Struct MR_Proc_Layout;
@@ -844,11 +845,11 @@
*/
typedef enum {
- MR_TRACE_LEVEL_NONE,
- MR_TRACE_LEVEL_SHALLOW,
- MR_TRACE_LEVEL_DEEP,
- MR_TRACE_LEVEL_DECL,
- MR_TRACE_LEVEL_DECL_REP
+ MR_DEFINE_ENUM_CONST(MR_TRACE_LEVEL_NONE),
+ MR_DEFINE_ENUM_CONST(MR_TRACE_LEVEL_SHALLOW),
+ MR_DEFINE_ENUM_CONST(MR_TRACE_LEVEL_DEEP),
+ MR_DEFINE_ENUM_CONST(MR_TRACE_LEVEL_DECL),
+ MR_DEFINE_ENUM_CONST(MR_TRACE_LEVEL_DECL_REP)
} MR_Trace_Level;
typedef struct MR_Module_File_Layout_Struct {
Index: runtime/mercury_tags.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_tags.h,v
retrieving revision 1.11
diff -u -t -r1.11 mercury_tags.h
--- runtime/mercury_tags.h 2001/03/18 23:10:13 1.11
+++ runtime/mercury_tags.h 2001/05/30 05:28:03
@@ -137,4 +137,23 @@
#endif
+/*
+** Convert an enumeration declaration into one which assigns the same
+** values to the enumeration constants as Mercury's tag allocation scheme
+** assigns. (This is necessary because in .rt grades Mercury enumerations are
+** not assigned the same values as 'normal' C enumerations).
+**
+*/
+#ifdef MR_RESERVE_TAG
+ #define MR_CONVERT_C_ENUM_CONSTANT(x) \
+ MR_mkword(MR_mktag(MR_FIRST_UNRESERVED_RAW_TAG), MR_mkbody(x))
+#else
+ #define MR_CONVERT_C_ENUM_CONSTANT(x) (x)
+#endif
+
+#define MR_DEFINE_ENUM_CONST(x) \
+ MR_PASTE2(x, _val), \
+ x = MR_CONVERT_C_ENUM_CONSTANT(MR_PASTE2(x, _val)), \
+ MR_PASTE2(x, _dummy) = MR_PASTE2(x, _val)
+
#endif /* not MERCURY_TAGS_H */
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.70
diff -u -t -r1.70 mercury_type_info.h
--- runtime/mercury_type_info.h 2001/04/29 18:21:57 1.70
+++ runtime/mercury_type_info.h 2001/05/24 08:13:42
@@ -52,6 +52,7 @@
#include "mercury_std.h" /* for `MR_STRINGIFY' and `MR_PASTEn' */
#include "mercury_types.h" /* for `MR_Word' */
+#include "mercury_tags.h" /* for `MR_DEFINE_ENUM_CONST' */
/*---------------------------------------------------------------------------*/
@@ -500,10 +501,13 @@
** The qualified versions are used by the MLDS->C back-end,
** which generates references to them.
*/
-#define MR_DEFINE_ENUM_CONST(x) \
- x, \
- MR_PASTE2(mercury__private_builtin__,x) = x
+#define MR_DEFINE_BUILTIN_ENUM_CONST(x) \
+ MR_PASTE2(x, _val), \
+ x = MR_CONVERT_C_ENUM_CONSTANT(MR_PASTE2(x, _val)), \
+ MR_PASTE2(mercury__private_builtin__,x) = x, \
+ MR_PASTE2(x, _dummy) = MR_PASTE2(x, _val)
+
/*
** MR_DataRepresentation is the representation for a particular type
** constructor. For the cases of MR_TYPE_CTOR_REP_DU and
@@ -513,42 +517,42 @@
*/
typedef enum {
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_ENUM),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_ENUM_USEREQ),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_DU),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_DU_USEREQ),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_NOTAG),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_NOTAG_USEREQ),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_EQUIV),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_EQUIV_VAR),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_INT),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_CHAR),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_FLOAT),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_STRING),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_PRED),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_UNIV),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_VOID),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_C_POINTER),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_TYPEINFO),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_TYPECLASSINFO),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_ARRAY),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_SUCCIP),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_HP),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_CURFR),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_MAXFR),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_REDOFR),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_REDOIP),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_TRAIL_PTR),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_TICKET),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_NOTAG_GROUND),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_EQUIV_GROUND),
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_TUPLE),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_ENUM),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_ENUM_USEREQ),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_DU),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_DU_USEREQ),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_NOTAG),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_NOTAG_USEREQ),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_EQUIV),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_EQUIV_VAR),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_INT),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_CHAR),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_FLOAT),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_STRING),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_PRED),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_UNIV),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_VOID),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_C_POINTER),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_TYPEINFO),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_TYPECLASSINFO),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_ARRAY),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_SUCCIP),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_HP),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_CURFR),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_MAXFR),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_REDOFR),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_REDOIP),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_TRAIL_PTR),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_TICKET),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_NOTAG_GROUND),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_EQUIV_GROUND),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_TUPLE),
/*
** MR_TYPECTOR_REP_UNKNOWN should remain the last alternative;
** MR_TYPE_CTOR_STATS depends on this.
*/
- MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_UNKNOWN)
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_TYPECTOR_REP_UNKNOWN)
} MR_TypeCtorRep;
/*
@@ -710,10 +714,10 @@
*/
typedef enum {
- MR_DEFINE_ENUM_CONST(MR_SECTAG_NONE),
- MR_DEFINE_ENUM_CONST(MR_SECTAG_LOCAL),
- MR_DEFINE_ENUM_CONST(MR_SECTAG_REMOTE),
- MR_DEFINE_ENUM_CONST(MR_SECTAG_VARIABLE)
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_SECTAG_NONE),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_SECTAG_LOCAL),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_SECTAG_REMOTE),
+ MR_DEFINE_BUILTIN_ENUM_CONST(MR_SECTAG_VARIABLE)
} MR_Sectag_Locn;
typedef struct {
Index: trace/mercury_trace_browse.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/trace/mercury_trace_browse.h,v
retrieving revision 1.12
diff -u -t -r1.12 mercury_trace_browse.h
--- trace/mercury_trace_browse.h 2001/05/29 17:24:03 1.12
+++ trace/mercury_trace_browse.h 2001/05/30 05:15:51
@@ -17,22 +17,23 @@
#include "mercury_conf.h" /* for MR_USE_EXTERNAL_DEBUGGER */
#include "mercury_types.h" /* for MR_Word, MR_String */
#include "mercury_std.h" /* for bool */
+#include "mercury_tags.h" /* for MR_DEFINE_ENUM_CONST */
/*
** The following types must correspond with browse_caller_type and
** portray_format in browser/browser_info.m.
*/
typedef enum {
- MR_BROWSE_CALLER_PRINT,
- MR_BROWSE_CALLER_BROWSE,
- MR_BROWSE_CALLER_PRINT_ALL
+ MR_DEFINE_ENUM_CONST(MR_BROWSE_CALLER_PRINT),
+ MR_DEFINE_ENUM_CONST(MR_BROWSE_CALLER_BROWSE),
+ MR_DEFINE_ENUM_CONST(MR_BROWSE_CALLER_PRINT_ALL)
} MR_Browse_Caller_Type;
typedef enum {
- MR_BROWSE_FORMAT_FLAT,
- MR_BROWSE_FORMAT_RAW_PRETTY,
- MR_BROWSE_FORMAT_VERBOSE,
- MR_BROWSE_FORMAT_PRETTY
+ MR_DEFINE_ENUM_CONST(MR_BROWSE_FORMAT_FLAT),
+ MR_DEFINE_ENUM_CONST(MR_BROWSE_FORMAT_RAW_PRETTY),
+ MR_DEFINE_ENUM_CONST(MR_BROWSE_FORMAT_VERBOSE),
+ MR_DEFINE_ENUM_CONST(MR_BROWSE_FORMAT_PRETTY)
} MR_Browse_Format;
/*
@@ -69,7 +70,11 @@
*/
/* This must kept in sync with query_type in browser/interactive.m. */
-typedef enum { MR_NORMAL_QUERY, MR_CC_QUERY, MR_IO_QUERY } MR_Query_Type;
+typedef enum {
+ MR_DEFINE_ENUM_CONST(MR_NORMAL_QUERY),
+ MR_DEFINE_ENUM_CONST(MR_CC_QUERY),
+ MR_DEFINE_ENUM_CONST(MR_IO_QUERY)
+} MR_Query_Type;
extern void MR_trace_query(MR_Query_Type type, const char *options,
int num_imports, /* const */ char *imports[]);
dgj
--
David Jeffery (dgj at cs.mu.oz.au) | If you want to build a ship, don't drum up
PhD student, | people together to collect wood or assign
Dept. of Comp. Sci. & Soft. Eng.| them tasks and work, but rather teach them
The University of Melbourne | to long for the endless immensity of the sea.
Australia | -- Antoine de Saint Exupery
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list