cvsuser 02/07/23 21:39:37
Modified: include/parrot key.h
Log:
This patch does two things:
- changes the key usage in global_setup.c to using stack-based keys.
- adds new macros for the various key types with the goal of increasing code clarity
This patch implements the following convenience macros in key.h:
MAKE_KEY_UNDEF(k)
MAKE_KEY_INT(k,v)
MAKE_KEY_NUM(k,v)
MAKE_KEY_STRING(k,v)
MAKE_KEY_PMC(k,v)
...in addition to the original:
MAKE_KEY(k,v,c,t)
Overall, they are no worse than the original MAKE_KEY (in terms of macro usage), but
make the code much easier to read.
This also changes the default.pmc, global.c, core.ops, and rx.ops code to use the
above macros.
Revision Changes Path
1.14 +23 -6 parrot/include/parrot/key.h
Index: key.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/key.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- key.h 9 Jun 2002 23:29:29 -0000 1.13
+++ key.h 24 Jul 2002 04:39:37 -0000 1.14
@@ -1,7 +1,7 @@
/* key.h
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: key.h,v 1.13 2002/06/09 23:29:29 josh Exp $
+ * $Id: key.h,v 1.14 2002/07/24 04:39:37 mongo Exp $
* Overview:
* This is the api header for the pmc subsystem
* Data Structure and Algorithms:
@@ -32,14 +32,31 @@
typedef struct _key KEY;
struct _key {
- KEY *next;
- INTVAL pad;
- UINTVAL flags;
KEY_ATOM atom;
+ KEY *next;
};
-KEY *key_new(Interp * interpreter);
-KEY *key_clone(Interp * interpreter, KEY *key);
+KEY *key_new(Interp *);
+KEY *key_clone(Interp *, KEY *);
+
+/* This (now even more) convoluted mess avoids costly runtime creation
+ * of KEY structures
+ *
+ * Usage: MAKE_KEY(KEY k, (INTVAL|FLOATVAL|DPOINTER*|STRING*|PMC*) v,
+ * KEY_TYPE c, (int_val|num_val|struct_val|string_val|pmc_val));
+ * or:
+ * MAKE_KEY_INT(KEY k, INTVAL v);
+ * MAKE_KEY_STRING(KEY k, STRING *v);
+ * MAKE_KEY_UNDEF(KEY k);
+ * etc
+ */
+
+#define MAKE_KEY(k,v,c,t) {k.atom.type = c; k.atom.val.t = v; k.next = NULL;}
+#define MAKE_KEY_UNDEF(k) {k.atom.type = enum_key_undef; k.atom.val.struct_val =
NULL; k.next = NULL;}
+#define MAKE_KEY_INT(k,v) {k.atom.type = enum_key_int; k.atom.val.int_val = v;
k.next = NULL;}
+#define MAKE_KEY_NUM(k,v) {k.atom.type = enum_key_num; k.atom.val.num_val = v;
k.next = NULL;}
+#define MAKE_KEY_STRING(k,v) {k.atom.type = enum_key_string; k.atom.val.struct_val
= v; k.next = NULL;}
+#define MAKE_KEY_PMC(k,v) {k.atom.type = enum_key_pmc; k.atom.val.pmc_val = v;
k.next = NULL;}
#endif