[m-rev.] for review: MR_DEFINE_ENUM_CONST

David Jeffery dgj at cs.mu.OZ.AU
Sat Jun 2 19:27:32 AEST 2001


On 30-May-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > +#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)
> 
> I think you might as well put the MR_DEFINE_ENUM_CONST() inside the
> #ifdef too, for the same reason that MR_CONVERT_C_ENUM_CONSTANT is
> inside the #ifdef: making it easier to understand what happens in the
> usual case.  In the #else case it can be just
> 
>            #define MR_DEFINE_ENUM_CONST(x)   (x)
> 	
> can't it?

Indeed. I have made this change.

> I think it might be slightly clearer to name MR_DEFINE_ENUM_CONST
> as MR_DEFINE_MERCURY_ENUM_CONST.

OK. I have made this change too.

> Otherwise that change looks fine -- thanks.

A revised diff appears below (the diff is short enough that it is probably
clearer than a relative diff).

I will commit this now.

(Log message stays the same).

Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.51
diff -u -t -r1.51 mercury_stack_layout.h
--- runtime/mercury_stack_layout.h	2001/05/31 06:55:09	1.51
+++ runtime/mercury_stack_layout.h	2001/06/01 07:53:16
@@ -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;
@@ -850,11 +851,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_MERCURY_ENUM_CONST(MR_TRACE_LEVEL_NONE),
+        MR_DEFINE_MERCURY_ENUM_CONST(MR_TRACE_LEVEL_SHALLOW),
+        MR_DEFINE_MERCURY_ENUM_CONST(MR_TRACE_LEVEL_DEEP),
+        MR_DEFINE_MERCURY_ENUM_CONST(MR_TRACE_LEVEL_DECL),
+        MR_DEFINE_MERCURY_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/31 07:45:25
@@ -137,4 +137,40 @@
 
 #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))
+
+                /*
+                ** We generate three enumeration constants:
+                **      - the first one, with '_val' pasted at the end of its
+                **        name, to give us a name for the current *unconverted*
+                **        enumeration value
+                **      - the converted enumeration value
+                **      - a '_dummy' value to reset the unconverted enumeration
+                **        value
+                */
+        #define MR_DEFINE_MERCURY_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)
+
+#else
+
+        #define MR_CONVERT_C_ENUM_CONSTANT(x)   (x)
+
+        #define MR_DEFINE_MERCURY_ENUM_CONST(x) x
+
+#endif
+
+
 #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/31 06:32:39
@@ -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_CONVERT_C_ENUM_CONSTANT' */
 
 /*---------------------------------------------------------------------------*/
 
@@ -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/31 06:34:01
@@ -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_MERCURY_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_MERCURY_ENUM_CONST(MR_BROWSE_CALLER_PRINT),
+        MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_CALLER_BROWSE),
+        MR_DEFINE_MERCURY_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_MERCURY_ENUM_CONST(MR_BROWSE_FORMAT_FLAT),
+        MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_FORMAT_RAW_PRETTY),
+        MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_FORMAT_VERBOSE),
+        MR_DEFINE_MERCURY_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_MERCURY_ENUM_CONST(MR_NORMAL_QUERY), 
+        MR_DEFINE_MERCURY_ENUM_CONST(MR_CC_QUERY), 
+        MR_DEFINE_MERCURY_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