On Tue, Apr 23, 2002 at 08:54:56PM -0700, Steve Fink wrote:
> (And that 3 should really be 4; the computed goto should > just be
> another option IMHO.)

Maybe not so humble: here's a patch to disable the default computed
goto core, so you can compare all four cores (assuming the previous
patch is applied.)

One weirdness I encountered:

 #define setopt(flag) Parrot_setflag(interpreter, flag, (*argv)[0]+2);

What the heck does this do? Parrot_setflag uses its 3rd argument only
as a boolean value. Where this is used, argv[0] always contains the
current command-line argument. So this is equivalent to 

  argv[0][0]+2

or in the example of "-p", that would be the character '-' + 2. Now,
to make that do something, you'd need the first character of the
option to be -2, and that's some weird hi-bit character. Huh?

Index: include/parrot/interpreter.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/interpreter.h,v
retrieving revision 1.40
diff -u -r1.40 interpreter.h
--- include/parrot/interpreter.h        3 Apr 2002 04:01:41 -0000       1.40
+++ include/parrot/interpreter.h        24 Apr 2002 03:58:02 -0000
@@ -23,7 +23,8 @@
     PARROT_BOUNDS_FLAG   = 0x04,  /* We're tracking byte code bounds */
     PARROT_PROFILE_FLAG  = 0x08,  /* We're gathering profile information */
     PARROT_PREDEREF_FLAG = 0x10,  /* We're using the prederef runops */
-    PARROT_JIT_FLAG      = 0x20   /* We're using the jit runops */
+    PARROT_JIT_FLAG      = 0x20,  /* We're using the jit runops */
+    PARROT_CGOTO_FLAG    = 0x40   /* We're using the computed goto runops */
 } Interp_flags;
 
 #define Interp_flags_SET(interp, flag)   (/*@i1@*/ (interp)->flags |= (flag))
Index: include/parrot/runops_cores.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/runops_cores.h,v
retrieving revision 1.4
diff -u -r1.4 runops_cores.h
--- include/parrot/runops_cores.h       4 Mar 2002 03:17:21 -0000       1.4
+++ include/parrot/runops_cores.h       24 Apr 2002 03:58:03 -0000
@@ -20,6 +20,8 @@
 
 opcode_t *runops_fast_core(struct Parrot_Interp *, opcode_t *);
 
+opcode_t *runops_cgoto_core(struct Parrot_Interp *, opcode_t *);
+
 opcode_t *runops_slow_core(struct Parrot_Interp *, opcode_t *);
 
 #endif
Index: interpreter.c
===================================================================
RCS file: /home/perlcvs/parrot/interpreter.c,v
retrieving revision 1.84
diff -u -r1.84 interpreter.c
--- interpreter.c       15 Apr 2002 18:05:18 -0000      1.84
+++ interpreter.c       24 Apr 2002 03:58:04 -0000
@@ -420,7 +425,12 @@
         which |= (Interp_flags_TEST(interpreter, PARROT_PROFILE_FLAG)) ? 0x02 : 0x00;
         which |= (Interp_flags_TEST(interpreter, PARROT_TRACE_FLAG))   ? 0x04 : 0x00;
 
-        core = which ? runops_slow_core : runops_fast_core;
+        if (which)
+            core = runops_slow_core;
+        else if (Interp_flags_TEST(interpreter, PARROT_CGOTO_FLAG))
+            core = runops_cgoto_core;
+        else
+            core = runops_fast_core;
 
         if (Interp_flags_TEST(interpreter, PARROT_PROFILE_FLAG)) {
             unsigned int i;
Index: runops_cores.c
===================================================================
RCS file: /home/perlcvs/parrot/runops_cores.c,v
retrieving revision 1.17
diff -u -r1.17 runops_cores.c
--- runops_cores.c      17 Apr 2002 03:50:25 -0000      1.17
+++ runops_cores.c      24 Apr 2002 03:58:04 -0000
@@ -30,12 +30,29 @@
 opcode_t *
 runops_fast_core(struct Parrot_Interp *interpreter, opcode_t *pc)
 {
-#ifdef HAVE_COMPUTED_GOTO
-    pc = cg_core(pc, interpreter);
-#else
     while (pc) {
         DO_OP(pc, interpreter);
     }
+    return pc;
+}
+
+/*=for api interpreter runops_cgoto_core
+ * run parrot operations until the program is complete, using the computed
+ * goto core (if available).
+ *
+ * No bounds checking.
+ * No profiling.
+ * No tracing.
+ */
+
+opcode_t *
+runops_cgoto_core(struct Parrot_Interp *interpreter, opcode_t *pc)
+{
+#ifdef HAVE_COMPUTED_GOTO
+    pc = cg_core(pc, interpreter);
+#else
+    fprintf(stderr, "Computed goto unavailable in this configuration.\n");
+    exit(1);
 #endif
     return pc;
 }
Index: test_main.c
===================================================================
RCS file: /home/perlcvs/parrot/test_main.c,v
retrieving revision 1.50
diff -u -r1.50 test_main.c
--- test_main.c 26 Mar 2002 16:33:01 -0000      1.50
+++ test_main.c 24 Apr 2002 04:01:25 -0000
@@ -14,6 +14,7 @@
 #include <stdlib.h>
 
 #define setopt(flag) Parrot_setflag(interpreter, flag, (*argv)[0]+2);
+#define unsetopt(flag) Parrot_setflag(interpreter, flag, 0)
 
 char *parseflags(Parrot interpreter, int *argc, char **argv[]);
 
@@ -62,6 +63,10 @@
     (*argc)--;
     (*argv)++;
 
+#ifdef HAVE_COMPUTED_GOTO
+    setopt(PARROT_CGOTO_FLAG);
+#endif
+
     while ((*argc) && (*argv)[0][0] == '-') {
         switch ((*argv)[0][1]) {
         case 'b':
@@ -76,6 +81,9 @@
         case 'P':
             setopt(PARROT_PREDEREF_FLAG);
             break;
+        case 'g':
+            unsetopt(PARROT_CGOTO_FLAG);
+            break;
         case 't':
             setopt(PARROT_TRACE_FLAG);
             break;
@@ -119,6 +127,12 @@
 static void
 usage(void)
 {
+#ifdef HAVE_COMPUTED_GOTO
+    char* cgoto_info = "Deactivate computed goto";
+#else
+    char* cgoto_info = "(unavailable) Deactivate computed goto";
+#endif
+
     fprintf(stderr,
 "Usage: parrot [switches] [--] programfile [arguments]\n\
   -b    Activate bounds checks\n\
@@ -127,9 +141,11 @@
   -j    Activate Just-In-Time compiler\n\
   -p    Activate profiling\n\
   -P    Activate predereferencing\n\
+  -g    %s\n\
   -t    Activate tracing\n\
   -v    Display version information\n\
-  -.    Wait for a keypress (gives Windows users time to attach a debugger)\n\n"
+  -.    Wait for a keypress (gives Windows users time to attach a debugger)\n\n",
+            cgoto_info
     );
 
     exit(0);

Reply via email to