On Mon, Dec 31, 2001 at 06:19:22PM -0500, Dan Sugalski wrote:
> At 11:10 PM 12/31/2001 +0000, Nicholas Clark wrote:
> >But is the correct correction to swap the parameters
> >
> >((op_func_prederef_t)*pc_prederef) (interpreter, pc_prederef);
> >
> >or to change the typedef?
> 
> The functions all take the interpreter argument second. First arg is a 
> pointer to an opcode_t, the second a pointer to the interpreter structure.

I believe that the only clean way to deal with the runops_prederef array
being of lots of C<void *>s is to make the other parts of parrot honest.
It's not actually an array of bytecode, so this patch makes everything
treat it as void *, not opcode_t.

> I've been twiddling with this a bit, but I've no answer and it's time to 
> knock off for dinner, so... if you fix it I'd be much obliged.

I've not been able to test long long things because Configure.pl barfed:

Configure.pl:  Unable to find a suitable packtype for intvalsize.

even when I ran it with perl5.7.1 which was built with IV as long long. :-(

So I may have done something very stupid. But all the compiler warnings go
away. Also, please realise that I've only been looking at this code for a few
hours so I although I think I've figured out roughly what it's doing.
[and I did laugh out loud when I finally realised what cunning tricks it is
doing to replace the deref function with the pointer to the opcode function,
and return the same address so that the run loop calls the real function at
that point]

Nicholas Clark

--- parrot-clean/include/parrot/op.h    Mon Dec 31 23:13:41 2001
+++ parrot-Wall/include/parrot/op.h     Tue Jan  1 01:33:53 2002
@@ -43,7 +43,7 @@
 struct Parrot_Interp;
 
 typedef opcode_t *(*op_func_t)(opcode_t *, struct Parrot_Interp *);
-typedef void **(*op_func_prederef_t)(opcode_t *, struct Parrot_Interp *);
+typedef void **(*op_func_prederef_t)(void **, struct Parrot_Interp *);
 
 
 /*
--- parrot-clean/Parrot/OpTrans.pm      Mon Dec 24 03:46:53 2001
+++ parrot-Wall/Parrot/OpTrans.pm       Tue Jan  1 01:25:16 2002
@@ -12,6 +12,8 @@
 sub new    { return bless { }, shift; }
 sub prefix { return 'Parrot_'; }
 sub suffix { return ''; }
-
+# The type for the array of opcodes. Usually it's an array opcode_t, but the
+# prederef runops core uses an array of void* to do its clever tricks.
+sub opsarraytype { return 'opcode_t' };
 1;
 
--- parrot-clean/Parrot/OpTrans/CPrederef.pm    Mon Dec 24 03:46:53 2001
+++ parrot-Wall/Parrot/OpTrans/CPrederef.pm     Tue Jan  1 01:29:53 2002
@@ -19,7 +19,6 @@
 sub defines
 {
   return <<END;
-#define opcode_t void *
 #define REL_PC ((size_t)(cur_opcode - interpreter->prederef_code))
 #define CUR_OPCODE (((opcode_t *)interpreter->code->byte_code) + REL_PC)
 END
@@ -34,6 +33,8 @@
 {
   return "_prederef";
 }
+
+sub opsarraytype { return 'void *' };
 
 
 #
--- parrot-clean/ops2c.pl       Mon Dec 31 00:15:28 2001
+++ parrot-Wall/ops2c.pl        Tue Jan  1 01:26:02 2002
@@ -33,6 +33,7 @@
 my $prefix  = $trans->prefix;
 my $suffix  = $trans->suffix;
 my $defines = $trans->defines;
+my $opsarraytype = $trans->opsarraytype;
 
 my $file = shift @ARGV;
 
@@ -132,10 +133,10 @@
 
 foreach my $op ($ops->ops) {
     my $func_name  = $op->func_name;
-    my $arg_types  = "opcode_t *, struct Parrot_Interp *";
-    my $prototype  = "opcode_t * $func_name ($arg_types)";
-    my $args       = "opcode_t cur_opcode[], struct Parrot_Interp * interpreter";
-    my $definition = "static opcode_t *\n$func_name ($args)";
+    my $arg_types  = "$opsarraytype *, struct Parrot_Interp *";
+    my $prototype  = "$opsarraytype * $func_name ($arg_types)";
+    my $args       = "$opsarraytype *cur_opcode, struct Parrot_Interp * interpreter";
+    my $definition = "static $opsarraytype *\n$func_name ($args)";
     my $source     = $op->source($trans);
 
 #    print HEADER "$prototype;\n";

Reply via email to