Leopold Toetsch wrote:

Sam Ruby wrote:

First, a direct quote from <http://www.perl.com/pub/a/2004/04/16/a12.html?page=10>:

Please let's stay at the basics. Please describe your counter proposal for a very elementary


  add Px, Py, Pz

operation.

There's really no need to procede to Perl6 objects, if we can't even find a common interoperating implementation that is suited for Parrot's target languages.

 > And it does rule out syntax changes and using a different opcode for
 > invoking MMD subroutines than non-MMD subroutines.

Yep.

First, a few things to note: the semantics of "add" vary from language to language. In particular, add is not guaranteed to be commutative in Python (think string addition).


As my proposal is primarily focused on where the logic is placed in the system, not how it works, I'll like to use your proposal <http://xrl.us/egvp> as a starting point. Just to make sure that I don't mischaracterize your proposal, can you take a look at the attached and either agree that it represents a reasonable first approximation of what you had in mind, or modify it so that it is?

Once that's done, I'll sketch out all of the changes required to enable Perl and Python to each have their own separate semantics for this operation, and yet be able to have meaningful interop when it comes to adding a PerlInt and a PyInt, or vice versa.

- Sam Ruby
Index: math.ops
===================================================================
RCS file: /cvs/public/parrot/ops/math.ops,v
retrieving revision 1.32
diff -u -r1.32 math.ops
--- math.ops    7 Dec 2004 17:24:53 -0000       1.32
+++ math.ops    22 Dec 2004 16:08:50 -0000
@@ -171,7 +171,32 @@
 }
 
 inline op add (in PMC, in PMC, in PMC) :base_core {
-  mmd_dispatch_v_ppp(interpreter, $2, $3, $1, MMD_ADD);
+  if (1) { /* this is here to allow declarations, even in C89 */
+      struct Parrot_Context ctx;
+      struct parrot_regs_t *bp = interpreter->ctx.bp;
+      STRING *__add = const_string(interpreter, "__add");
+      INTVAL mmd_flag;
+      PMC *addsub;
+
+      /* we probably don't need to save the full context, just a few regs... */
+      save_context(interpreter, &ctx);
+
+      /* let's ignore the complexities of a distance_func for now... */
+      mmd_flag = 0;
+      addsub = VTABLE_find_method(INTERP, $1, __add, 0, &mdd_flag);
+      if (!addsub)
+          mmd_flag = 0;
+          addsub = VTABLE_find_method(INTERP, $2, __add, 1, &mdd_flag);
+
+      /* assume NCI for now */
+      VTABLE_invoke(interpreter, sub, NULL);
+
+      /* note: this was allocated by __add */
+      $3 = BP_REG_PMC(bp,5);
+
+      /* again, probably overkill */
+      restore_context(interpreter, &ctx);
+  }
   goto NEXT();
 }
 

Reply via email to