cvsuser     05/04/04 07:02:26

  Modified:    build_tools build_nativecall.pl
               classes  default.pmc deleg_pmc.pmc nci.pmc parrotclass.pmc
                        parrotobject.pmc ref.pmc sharedref.pmc string.pmc
               config/gen core_pmcs.pl
               docs/pdds pdd03_calling_conventions.pod
               imcc     pcc.c
               include/parrot mmd.h
               src      builtin.c call_list.txt global.c global_setup.c
                        mmd.c objects.c
               t/pmc    mmd.t
               .        vtable.tbl
  Log:
  MMD 16 - builtin infix multis
  
  * see note on p6i
  
  * renamed is_equal_str MMD to is_equal_string
  * fixed bad bug during PMC registration:
    the iglobals was created to late so that
    NCI registration ever and ever recreated the
    the NCI function Hash
  * add I, N NCI signatures
  * removed duplicate find_method entries
  
  Revision  Changes    Path
  1.64      +29 -13    parrot/build_tools/build_nativecall.pl
  
  Index: build_nativecall.pl
  ===================================================================
  RCS file: /cvs/public/parrot/build_tools/build_nativecall.pl,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- build_nativecall.pl       4 Apr 2005 08:39:39 -0000       1.63
  +++ build_nativecall.pl       4 Apr 2005 14:02:14 -0000       1.64
  @@ -40,6 +40,8 @@
        ( p => [1,0,0,1,0],        # Returning a pointer that we PMC stuff
          P => [1,0,0,1,0],        # PMC
          S => [1,0,1,0,0],        # STR
  +       I => [1,1,0,0,0],        # INTVAL
  +       N => [1,0,0,0,1],        # FLOATVAL
          i => [1,1,0,0,0],        # Returning an int
          3 => [1,1,0,0,0],        # Returning an int pointer
          l => [1,1,0,0,0],        # Returning a long
  @@ -68,8 +70,10 @@
          v => "void",
   #      b => "void *",
   #      B => "void **",
  -       P => "void *",
  +       P => "PMC *",
          S => "STRING *",
  +       I => "INTVAL",
  +       N => "FLOATVAL",
        );
   
   my %proto_type =
  @@ -87,8 +91,10 @@
          v => "void",
          J => "Interp *",
          P => "PMC *",
  +       O => "PMC *",      # object
          S => "STRING *",
  -       O => "PMC *",
  +       I => "INTVAL",
  +       N => "FLOATVAL",
          b => "void *",
          B => "void **",
          L => "long *",
  @@ -117,13 +123,16 @@
          v => "void *",
   #      b => "void *",
   #      B => "void **",
  -       P => "void *",
  +       P => "PMC *",
          S => "STRING *",
  +       I => "INTVAL",
  +       N => "FLOATVAL",
        );
   
   my %ret_assign =
        ( p => "PMC_data(final_destination) = return_data;\n    REG_PMC(5) = 
final_destination;",
          i => "REG_INT(5) = return_data;",
  +       I => "REG_INT(5) = return_data;",
          3 => "REG_INT(5) = *return_data;",
          l => "REG_INT(5) = return_data;",
          4 => "REG_INT(5) = *return_data;",
  @@ -131,6 +140,7 @@
          2 => "REG_INT(5) = *return_data;",
          f => "REG_NUM(5) = return_data;",
          d => "REG_NUM(5) = return_data;",
  +       N => "REG_NUM(5) = return_data;",
          P => "REG_PMC(5) = return_data;",
          S => "REG_STR(5) = return_data;",
          v => "",
  @@ -155,6 +165,8 @@
          t => "return_data = ",
          P => "return_data = ",
          S => "return_data = ",
  +       I => "return_data = ",
  +       N => "return_data = ",
   #      B => "return_data = ",
          v => "",
        );
  @@ -270,6 +282,9 @@
       /l/ && do {my $reg_num = $reg_ref->{i}++;
                  return "(long)REG_INT($reg_num)";
                 };
  +    /I/ && do {my $reg_num = $reg_ref->{i}++;
  +               return "REG_INT($reg_num)";
  +              };
       /4/ && do {my $reg_num = $reg_ref->{p}++;
                  return "(long*)&PMC_int_val(REG_PMC($reg_num))";
                 };
  @@ -288,6 +303,9 @@
       /d/ && do {my $reg_num = $reg_ref->{n}++;
                  return "(double)REG_NUM($reg_num)";
                 };
  +    /N/ && do {my $reg_num = $reg_ref->{n}++;
  +               return "REG_NUM($reg_num)";
  +              };
       /t/ && do {my $reg_num = $reg_ref->{s}++;
                  my $temp_num = ${$temp_cnt_ref}++;
                  push @{$extra_preamble_ref}, "char *tempvar$temp_num = 
string_to_cstring(interpreter, REG_STR($reg_num));\n";
  @@ -472,25 +490,23 @@
   
       iglobals = interpreter->iglobals;
   
  -    if (iglobals)
  -        HashPointer = VTABLE_get_pmc_keyed_int(interpreter, iglobals,
  +    if (PMC_IS_NULL(iglobals))
  +     PANIC("iglobals isn�t created yet");
  +    HashPointer = VTABLE_get_pmc_keyed_int(interpreter, iglobals,
               IGLOBALS_NCI_FUNCS);
   
       if (!HashPointer) {
           HashPointer = pmc_new(interpreter, enum_class_Hash);
  +     VTABLE_set_pmc_keyed_int(interpreter, iglobals, IGLOBALS_NCI_FUNCS,
  +                HashPointer);
   
   $put_pointer
   
  -        if (iglobals)
  -        {
  -            VTABLE_set_pmc_keyed_int(interpreter, iglobals, 
IGLOBALS_NCI_FUNCS,
  -                HashPointer);
  -        }
       }
   
       b = VTABLE_get_pmc_keyed_str(interpreter, HashPointer, signature);
   
  -    if (b && (b->vtable->type(interpreter, b) == enum_class_UnManagedStruct) 
)
  +    if (b && b->vtable->base_type == enum_class_UnManagedStruct)
           return F2DPTR(PMC_data(b));
   
       /*
  
  
  
  1.113     +5 -2      parrot/classes/default.pmc
  
  Index: default.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/default.pmc,v
  retrieving revision 1.112
  retrieving revision 1.113
  diff -u -r1.112 -r1.113
  --- default.pmc       1 Feb 2005 14:21:54 -0000       1.112
  +++ default.pmc       4 Apr 2005 14:02:16 -0000       1.113
  @@ -392,7 +392,10 @@
   
   
       PMC* find_method(STRING* method_name) {
  -        return Parrot_find_method_with_cache(INTERP, SELF, method_name);
  +        PMC *method = Parrot_find_method_with_cache(INTERP, SELF, 
method_name);
  +        if (method && method->vtable->base_type == enum_class_MultiSub)
  +            return Parrot_MMD_search_default_func(interpreter,
  +                    method_name, REG_STR(1));
       }
   
       void add_method(STRING *method_name, PMC *sub_pmc) {
  
  
  
  1.6       +2 -2      parrot/classes/deleg_pmc.pmc
  
  Index: deleg_pmc.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/deleg_pmc.pmc,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- deleg_pmc.pmc     7 Dec 2004 17:24:50 -0000       1.5
  +++ deleg_pmc.pmc     4 Apr 2005 14:02:16 -0000       1.6
  @@ -77,7 +77,7 @@
   #define VTABLE_cmp_string(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STRCMP)
   #define VTABLE_is_equal(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_EQ)
   #define VTABLE_is_equal_num(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_NUMEQ)
  -#define VTABLE_is_equal_str(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STREQ)
  +#define VTABLE_is_equal_string(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STREQ)
   #define VTABLE_pow(i, l, r, d) mmd_dispatch_v_ppp(i, l, r, d, MMD_POW)
   #define VTABLE_pow_float(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_FLOAT)
   #define VTABLE_pow_int(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_INT)
  
  
  
  1.34      +17 -2     parrot/classes/nci.pmc
  
  Index: nci.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/nci.pmc,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- nci.pmc   20 Mar 2005 10:16:46 -0000      1.33
  +++ nci.pmc   4 Apr 2005 14:02:16 -0000       1.34
  @@ -92,6 +92,7 @@
            * ManagedStruct or Buffer?
            */
           PMC_data(ret) = PMC_data(SELF);
  +        PObj_get_FLAGS(ret) |= (PObj_get_FLAGS(SELF) & 0x3);
           return ret;
       }
   
  @@ -124,14 +125,21 @@
       void* invoke (void * next) {
           Parrot_csub_t func = (Parrot_csub_t)D2FPTR(PMC_data(SELF));
           PMC *obj;
  +        UINTVAL flags;
           /*
            * If the invocant is a class or there is no invocant
            * shift down arguments.
            * But not if it's a plain NCI function created
            * from dlfunc.
  +         *
  +         * NCI flags:
  +         *   private0 ... builtin multi method
  +         *   private1 ... created via dlfunc
  +         *
            */
           obj = REG_PMC(2);
  -        if (!(PObj_get_FLAGS(SELF) & PObj_private1_FLAG) &&
  +        flags = PObj_get_FLAGS(SELF);
  +        if (!(flags & PObj_private1_FLAG) &&
                   (PMC_IS_NULL(obj) || PObj_is_class_TEST(obj) ||
                   obj->vtable->class == obj)) {
               INTVAL i, n;
  @@ -141,6 +149,13 @@
                   REG_PMC(i) = REG_PMC(i+1);
               }
           }
  +        else if ((flags & PObj_private0_FLAG) && obj) {
  +            INTVAL i = REG_INT(3)++;
  +            while (i--)
  +                REG_PMC(6+i)=REG_PMC(5+i);
  +            REG_PMC(5) = REG_PMC(2);
  +            ++REG_INT(3);
  +        }
           func(INTERP, SELF);
           return next;
       }
  
  
  
  1.35      +1 -23     parrot/classes/parrotclass.pmc
  
  Index: parrotclass.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/parrotclass.pmc,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- parrotclass.pmc   10 Mar 2005 16:41:25 -0000      1.34
  +++ parrotclass.pmc   4 Apr 2005 14:02:16 -0000       1.35
  @@ -95,27 +95,9 @@
           return Parrot_object_isa(INTERP, SELF, class);
       }
   
  -/*
  -
  -=item C<PMC *find_method(STRING *name)>
  -
  -Figure out which method PMC we need. By default we just defer to the
  -system method lookup code.
  -
  -=cut
  -
  -*/
  -
  -    PMC* find_method(STRING* name) {
  -        return Parrot_find_method_with_cache(INTERP, SELF, name);
  -    }
   
   /*
   
  -=item C<INTVAL can(STRING *method)>
  -
  -Returns whether the class can perform C<*method>.
  -
   =item C<PMC *get_class()>
   
   Return SELF.
  @@ -129,10 +111,6 @@
   
   */
   
  -    INTVAL can(STRING* method) {
  -        return VTABLE_find_method(INTERP, SELF, method) != NULL;
  -    }
  -
       PMC* get_class() {
           return SELF;
       }
  
  
  
  1.39      +2 -2      parrot/classes/parrotobject.pmc
  
  Index: parrotobject.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/parrotobject.pmc,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- parrotobject.pmc  12 Jan 2005 11:42:06 -0000      1.38
  +++ parrotobject.pmc  4 Apr 2005 14:02:16 -0000       1.39
  @@ -137,7 +137,7 @@
   
       PMC* find_method(STRING* name) {
           PMC *class = VTABLE_get_class(INTERP, SELF);
  -        return Parrot_find_method_with_cache(INTERP, class, name);
  +        return VTABLE_find_method(INTERP, class, name);
       }
   
       PMC* get_attr(INTVAL idx) {
  
  
  
  1.24      +2 -2      parrot/classes/ref.pmc
  
  Index: ref.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/ref.pmc,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- ref.pmc   7 Dec 2004 17:24:50 -0000       1.23
  +++ ref.pmc   4 Apr 2005 14:02:16 -0000       1.24
  @@ -77,7 +77,7 @@
   #define VTABLE_cmp_string(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STRCMP)
   #define VTABLE_is_equal(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_EQ)
   #define VTABLE_is_equal_num(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_NUMEQ)
  -#define VTABLE_is_equal_str(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STREQ)
  +#define VTABLE_is_equal_string(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STREQ)
   #define VTABLE_pow(i, l, r, d) mmd_dispatch_v_ppp(i, l, r, d, MMD_POW)
   #define VTABLE_pow_float(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_FLOAT)
   #define VTABLE_pow_int(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_INT)
  
  
  
  1.21      +2 -2      parrot/classes/sharedref.pmc
  
  Index: sharedref.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/sharedref.pmc,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- sharedref.pmc     7 Dec 2004 17:24:50 -0000       1.20
  +++ sharedref.pmc     4 Apr 2005 14:02:16 -0000       1.21
  @@ -89,7 +89,7 @@
   #define VTABLE_cmp_string(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STRCMP)
   #define VTABLE_is_equal(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_EQ)
   #define VTABLE_is_equal_num(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_NUMEQ)
  -#define VTABLE_is_equal_str(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STREQ)
  +#define VTABLE_is_equal_string(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_STREQ)
   #define VTABLE_pow(i, l, r, d) mmd_dispatch_v_ppp(i, l, r, d, MMD_POW)
   #define VTABLE_pow_float(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_FLOAT)
   #define VTABLE_pow_int(i, l, r, d) mmd_dispatch_v_pnp(i, l, r, d, 
MMD_POW_INT)
  
  
  
  1.8       +3 -3      parrot/classes/string.pmc
  
  Index: string.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/string.pmc,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- string.pmc        21 Feb 2005 10:05:16 -0000      1.7
  +++ string.pmc        4 Apr 2005 14:02:16 -0000       1.8
  @@ -444,7 +444,7 @@
   
   /*
   
  -=item C<INTVAL is_equal_str(PMC* value)>
  +=item C<INTVAL is_equal_string(PMC* value)>
   
   Compares the string with C<value>; returns FALSE if they match.
   
  @@ -452,7 +452,7 @@
   
   */
   
  -    INTVAL is_equal_str (PMC* value) {
  +    INTVAL is_equal_string (PMC* value) {
           STRING *s = PMC_str_val(SELF);
           STRING *v = VTABLE_get_string(INTERP, value);
           return string_equal(INTERP, s, v) == 0;
  
  
  
  1.20      +10 -2     parrot/config/gen/core_pmcs.pl
  
  Index: core_pmcs.pl
  ===================================================================
  RCS file: /cvs/public/parrot/config/gen/core_pmcs.pl,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- core_pmcs.pl      9 Mar 2005 20:31:25 -0000       1.19
  +++ core_pmcs.pl      4 Apr 2005 14:02:17 -0000       1.20
  @@ -100,7 +100,8 @@
         foreach (@pmcs[0..$#pmcs-1]);
       print OUT <<"END";
        if (!pass) {
  -         PMC *classname_hash;
  +         PMC *classname_hash, *iglobals;
  +         int i;
            /* Need an empty stash */
            interp->globals = mem_sys_allocate(sizeof(struct Stash));
            interp->globals->stash_hash =
  @@ -110,6 +111,13 @@
               interp->class_hash = classname_hash =
                   pmc_new(interp, enum_class_Hash);
            Parrot_register_core_pmcs(interp, classname_hash);
  +         /* init the interpreter globals array */
  +         iglobals = pmc_new(interp, enum_class_SArray);
  +         interp->iglobals = iglobals;
  +         VTABLE_set_integer_native(interp, iglobals, (INTVAL)IGLOBALS_SIZE);
  +         /* clear the array */
  +         for (i = 0; i < (INTVAL)IGLOBALS_SIZE; i++)
  +             VTABLE_set_pmc_keyed_int(interp, iglobals, i, NULL);
        }
       }
   }
  
  
  
  1.26      +5 -1      parrot/docs/pdds/pdd03_calling_conventions.pod
  
  Index: pdd03_calling_conventions.pod
  ===================================================================
  RCS file: /cvs/public/parrot/docs/pdds/pdd03_calling_conventions.pod,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- pdd03_calling_conventions.pod     16 Nov 2004 18:15:54 -0000      1.25
  +++ pdd03_calling_conventions.pod     4 Apr 2005 14:02:19 -0000       1.26
  @@ -116,6 +116,10 @@
   
   The fully qualified name of the method or sub being called
   
  +=item S1
  +
  +Call signature used for MMD only.
  +
   =item I0
   
   1 if the sub is being called with fully prototyped parameters,
  
  
  
  1.91      +14 -8     parrot/imcc/pcc.c
  
  Index: pcc.c
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/pcc.c,v
  retrieving revision 1.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- pcc.c     24 Mar 2005 16:13:31 -0000      1.90
  +++ pcc.c     4 Apr 2005 14:02:20 -0000       1.91
  @@ -822,18 +822,24 @@
   pcc_insert_signature(Parrot_Interp interp, IMC_Unit * unit, Instruction *ins,
           struct pcc_sub_t *pcc_sub)
   {
  -    int i, n;
  +    int i, n, m;
       SymReg *regs[IMCC_MAX_REGS];
       char buffer[20];    /* TODO is there a limit? */
   
       n = pcc_sub->nargs;
       buffer[0] = '"';
  +    if (pcc_sub->object) {
  +        buffer[1] = 'O';
  +        m = 2;
  +    }
  +    else
  +        m = 1;
       for (i = 0; i < n && i < 15; ++i) {
  -        buffer[i + 1] = pcc_sub->args[i]->set;
  +        buffer[m++] = pcc_sub->args[i]->set;
       }
  -    buffer[i + 1] = '"';
  -    buffer[i + 2] = '\0';
  -    regs[0] = get_pasm_reg(interp, "S0");
  +    buffer[m++] = '"';
  +    buffer[m] = '\0';
  +    regs[0] = get_pasm_reg(interp, "S1");
       regs[1] = mk_const(interp, str_dup(buffer), 'S');
       ins = insINS(interp, unit, ins, "set", regs, 2);
       return ins;
  @@ -915,9 +921,8 @@
        * a possible MMD call can inspect the passed arguments
        */
       if (get_name) {
  -        /* for now, put a call signature in S0 */
  -        if (!meth_call)
  -            ins = pcc_insert_signature(interp, unit, ins, sub->pcc_sub);
  +        /* for now, put a call signature in S1 */
  +        ins = pcc_insert_signature(interp, unit, ins, sub->pcc_sub);
           insert_ins(unit, ins, get_name);
           ins = get_name;
       }
  @@ -946,6 +951,7 @@
               else
                   ins = insINS(interp, unit, ins, "set", regs, 2);
           }
  +        ins = pcc_insert_signature(interp, unit, ins, sub->pcc_sub);
           if (sub->pcc_sub->nci)
               goto move_sub;
       }
  
  
  
  1.26      +3 -1      parrot/include/parrot/mmd.h
  
  Index: mmd.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/mmd.h,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- mmd.h     3 Apr 2005 10:14:39 -0000       1.25
  +++ mmd.h     4 Apr 2005 14:02:21 -0000       1.26
  @@ -49,6 +49,8 @@
                                    in question */
   } MMD_table;
   
  +
  +PMC *Parrot_MMD_search_default_func(Interp *, STRING *meth, STRING 
*signature);
   /*
    * in src/objects.c :
    */
  
  
  
  1.3       +6 -3      parrot/src/builtin.c
  
  Index: builtin.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/builtin.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- builtin.c 20 Mar 2005 15:27:43 -0000      1.2
  +++ builtin.c 4 Apr 2005 14:02:22 -0000       1.3
  @@ -154,10 +154,13 @@
   {
       int i;
       PMC *m;
  +    STRING *ns;
   
       i = find_builtin_s(interpreter, func);
  -    if (i < 0)
  -        return NULL;
  +    if (i < 0) {
  +        ns = CONST_STRING(interpreter, "__parrot_core");
  +        return Parrot_find_global(interpreter, ns, func);
  +    }
       m = Parrot_find_global(interpreter,
               builtins[i].namespace,
               builtins[i].meth_name);
  
  
  
  1.60      +7 -1      parrot/src/call_list.txt
  
  Index: call_list.txt
  ===================================================================
  RCS file: /cvs/public/parrot/src/call_list.txt,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- call_list.txt     4 Apr 2005 08:39:43 -0000       1.59
  +++ call_list.txt     4 Apr 2005 14:02:22 -0000       1.60
  @@ -59,6 +59,12 @@
   d    JOd      # Parrot builtins
   d    v
   
  +v    JPPP     # infix MMD
  +v    JPIP
  +v    JPSP
  +v    JPNP
  +I    JPP      # MMD compare
  +
   f                # t/pmc/nci.t
   f    ff       # t/pmc/nci.t
   f    is
  
  
  
  1.18      +3 -5      parrot/src/global.c
  
  Index: global.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/global.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- global.c  30 Mar 2005 16:05:33 -0000      1.17
  +++ global.c  4 Apr 2005 14:02:22 -0000       1.18
  @@ -194,8 +194,6 @@
   
   */
   
  -/* XXX */
  -PMC *Parrot_MMD_search_default_func(Interp *, STRING *meth, STRING 
*signature);
   
   PMC *
   Parrot_get_name(Interp* interpreter, STRING *name)
  @@ -218,10 +216,10 @@
       if (g) {
           if (g->vtable->base_type == enum_class_MultiSub) {
               /*
  -             * signature is currently passed in S0
  +             * signature is currently passed in S1
                * see also imcc/pcc.c
                */
  -            g = Parrot_MMD_search_default_func(interpreter, name, 
REG_STR(0));
  +            g = Parrot_MMD_search_default_func(interpreter, name, 
REG_STR(1));
               if (g)
                   return g;
           }
  
  
  
  1.61      +2 -8      parrot/src/global_setup.c
  
  Index: global_setup.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/global_setup.c,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- global_setup.c    2 Apr 2005 16:54:54 -0000       1.60
  +++ global_setup.c    4 Apr 2005 14:02:22 -0000       1.61
  @@ -71,13 +71,7 @@
       /* Create MMD_table for all MMD functions */
       Parrot_mmd_rebuild_table(interpreter, -1, -1);
   
  -    /* init the interpreter globals array */
  -    iglobals = pmc_new(interpreter, enum_class_SArray);
  -    interpreter->iglobals = iglobals;
  -    VTABLE_set_integer_native(interpreter, iglobals, (INTVAL)IGLOBALS_SIZE);
  -    /* clear the array */
  -    for (i = 0; i < (INTVAL)IGLOBALS_SIZE; i++)
  -        VTABLE_set_pmc_keyed_int(interpreter, iglobals, i, NULL);
  +    iglobals = interpreter->iglobals;
       VTABLE_set_pmc_keyed_int(interpreter, iglobals,
               (INTVAL)IGLOBALS_CLASSNAME_HASH, interpreter->class_hash);
       self = pmc_new_noinit(interpreter, enum_class_ParrotInterpreter);
  
  
  
  1.62      +93 -32    parrot/src/mmd.c
  
  Index: mmd.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/mmd.c,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- mmd.c     3 Apr 2005 16:27:43 -0000       1.61
  +++ mmd.c     4 Apr 2005 14:02:22 -0000       1.62
  @@ -667,7 +667,7 @@
   static int  mmd_search_lexical(Interp *, STRING *meth, PMC *arg_tuple, PMC 
*);
   static int  mmd_search_package(Interp *, STRING *meth, PMC *arg_tuple, PMC 
*);
   static int  mmd_search_global(Interp *, STRING *meth, PMC *arg_tuple, PMC *);
  -static int  mmd_search_builtin(Interp *, STRING *meth, PMC *arg_tuple, PMC 
*);
  +static void mmd_search_builtin(Interp *, STRING *meth, PMC *arg_tuple, PMC 
*);
   static int  mmd_maybe_candidate(Interp *, PMC *pmc, PMC *arg_tuple, PMC *cl);
   static void mmd_sort_candidates(Interp *, PMC *arg_tuple, PMC *cl);
   
  @@ -773,6 +773,7 @@
                   VTABLE_set_integer_keyed_int(interpreter, arg_tuple,
                           i, enum_type_STRING);
                   break;
  +            case 'O':
               case 'P':
                   arg = va_arg(args, PMC *);
                   type = VTABLE_type(interpreter, arg);
  @@ -795,6 +796,14 @@
       INTVAL sig_len, i, type, next_p;
       PMC* arg_tuple, *arg;
   
  +    /* TODO
  +     * if there is no signature e.g. because of
  +     *      m = getattribute l, "__add"
  +     * - we have to return the MultiSub
  +     * - create a BoundMulit
  +     * - dispatch in invoke - yeah ugly
  +     */
  +
       arg_tuple = pmc_new(interpreter, enum_class_FixedIntegerArray);
       sig_len = string_length(interpreter, signature);
       if (!sig_len)
  @@ -816,6 +825,12 @@
                   VTABLE_set_integer_keyed_int(interpreter, arg_tuple,
                           i, enum_type_STRING);
                   break;
  +            case 'O':
  +                arg = REG_PMC(2);
  +                type = VTABLE_type(interpreter, arg);
  +                VTABLE_set_integer_keyed_int(interpreter, arg_tuple,
  +                        i, type);
  +                break;
               case 'P':
                   if (next_p == 16)
                       internal_exception(1, "Unimp MMD too many args");
  @@ -989,14 +1004,20 @@
       INTVAL i, n, args, dist, j, m;
       INTVAL type_sig, type_call;
   
  -    multi_sig = PMC_sub(pmc)->multi_signature;
  -    if (!multi_sig) {
  -        /* some method */
  -        return 0;
  +    if (pmc->vtable->base_type == enum_class_NCI) {
  +        /* has to be a builtin multi method */
  +        multi_sig = PMC_pmc_val(pmc);
       }
  -    if (multi_sig->vtable->base_type == enum_class_FixedStringArray) {
  -        multi_sig = PMC_sub(pmc)->multi_signature =
  -            mmd_cvt_to_types(interpreter, multi_sig);
  +    else {
  +        multi_sig = PMC_sub(pmc)->multi_signature;
  +        if (!multi_sig) {
  +            /* some method */
  +            return 0;
  +        }
  +        if (multi_sig->vtable->base_type == enum_class_FixedStringArray) {
  +            multi_sig = PMC_sub(pmc)->multi_signature =
  +                mmd_cvt_to_types(interpreter, multi_sig);
  +        }
       }
       n = VTABLE_elements(interpreter, multi_sig);
       args = VTABLE_elements(interpreter, arg_tuple);
  @@ -1307,19 +1328,25 @@
   
   /*
   
  -=item C<static int mmd_search_builtin(Interp *, STRING *meth, PMC 
*arg_tuple, PMC *cl)>
  +=item C<static void mmd_search_builtin(Interp *, STRING *meth, PMC 
*arg_tuple, PMC *cl)>
   
  -Search the builtin namespace for matching candidates. Return TRUE if
  -the MMD search should stop.
  +Search the builtin namespace for matching candidates. This is the last
  +search in all the namespaces.
   
   =cut
   
   */
   
  -static int
  +static void
   mmd_search_builtin(Interp *interpreter, STRING *meth, PMC *arg_tuple, PMC 
*cl)
   {
  -    return 0;
  +    PMC *pmc;
  +    STRING *ns;
  +
  +    ns = CONST_STRING(interpreter, "__parrot_core");
  +    pmc = Parrot_find_global(interpreter, ns, meth);
  +    if (pmc)
  +        mmd_maybe_candidate(interpreter, pmc, arg_tuple, cl);
   }
   
   static void
  @@ -1359,13 +1386,19 @@
   {
       const char *name, *short_name;
       char signature[6], val_sig;
  -    STRING *s, *ns;
  +    STRING *meth_name, *ns;
       int len;
       char *p;
  -    PMC *method, *multi;
  +    PMC *method, *multi, *class, *multi_sig;
       INTVAL func_nr;
   
   
  +    if (type == enum_class_Null || type == enum_class_delegate ||
  +            type == enum_class_Ref  || type == enum_class_SharedRef ||
  +            type == enum_class_deleg_pmc || type == enum_class_ParrotClass ||
  +            type == enum_class_ParrotObject) {
  +        return;
  +    }
       func_nr = entry->func_nr;
       name = short_name = Parrot_MMD_methode_name(interpreter, func_nr);
       /*
  @@ -1393,38 +1426,66 @@
               }
           }
       }
  -#if 0
  +
       /*
        * create NCI method in left class
        */
  -    s = const_string(interpreter, name);
  -    strcpy(signature, "vIP.P");
  +    strcpy(signature, "vJP.P");
       signature[3] = val_sig;
       if (func_nr >= MMD_EQ && func_nr <= MMD_STRCMP) {
           signature[0] = 'I';
           signature[4] = '\0';
       }
  -    method = pmc_new(interpreter, enum_class_NCI);
  -    VTABLE_set_pointer_keyed_str(interpreter, method,
  -            const_string(interpreter, signature),
  -            F2DPTR(entry->func_ptr));
  -    Parrot_store_global(interpreter,
  -            Parrot_base_vtables[type]->whoami,
  -            const_string(interpreter, name),
  -            method);
  +    meth_name = const_string(interpreter, short_name);
  +    class = Parrot_base_vtables[type]->class;
  +    method = Parrot_find_method_with_cache(interpreter, class, meth_name);
  +    if (!method) {
  +        /* first method */
  +        method = constant_pmc_new(interpreter, enum_class_NCI);
  +        VTABLE_set_pointer_keyed_str(interpreter, method,
  +                const_string(interpreter, signature),
  +                F2DPTR(entry->func_ptr));
  +        VTABLE_add_method(interpreter, class, meth_name, method);
  +    }
  +    else {
  +        /* multiple methods with that same name */
  +        if (method->vtable->base_type == enum_class_NCI) {
  +            /* convert first to a multi */
  +            multi = constant_pmc_new(interpreter, enum_class_MultiSub);
  +            VTABLE_add_method(interpreter, class, meth_name, multi);
  +            VTABLE_push_pmc(interpreter, multi, method);
  +        }
  +        else {
  +            assert(method->vtable->base_type == enum_class_MultiSub);
  +            multi = method;
  +        }
  +        method = constant_pmc_new(interpreter, enum_class_NCI);
  +        VTABLE_set_pointer_keyed_str(interpreter, method,
  +                const_string(interpreter, signature),
  +                F2DPTR(entry->func_ptr));
  +        VTABLE_push_pmc(interpreter, multi, method);
  +    }
  +    /* mark MMD */
  +    PObj_get_FLAGS(method) |= PObj_private0_FLAG;
  +    /*
  +     * attach the multi_signature array to PMC_pmc_val
  +     */
  +    multi_sig = constant_pmc_new(interpreter, enum_class_FixedIntegerArray);
  +    VTABLE_set_integer_native(interpreter, multi_sig, 2);
  +    VTABLE_set_integer_keyed_int(interpreter, multi_sig, 0, type);
  +    VTABLE_set_integer_keyed_int(interpreter, multi_sig, 1, entry->right);
  +    PMC_pmc_val(method) = multi_sig;
   
       /*
  -     * push method on multi_sub
  +     * push method onto core multi_sub
  +     * TODO cache the namespace
        */
       ns = CONST_STRING(interpreter, "__parrot_core");
       multi = Parrot_find_global(interpreter, ns,
               const_string(interpreter, short_name));
       assert(multi);
  -    /*
  -     * FIXME need the multi signature too
  -     */
       VTABLE_push_pmc(interpreter, multi, method);
  -#endif
  +
   }
   
   /*
  
  
  
  1.139     +2 -2      parrot/src/objects.c
  
  Index: objects.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/objects.c,v
  retrieving revision 1.138
  retrieving revision 1.139
  diff -u -r1.138 -r1.139
  --- objects.c 3 Apr 2005 10:14:42 -0000       1.138
  +++ objects.c 4 Apr 2005 14:02:22 -0000       1.139
  @@ -1147,7 +1147,7 @@
       return find_method_direct(interpreter, class, method_name);
   #endif
   
  -    if (!is_const) {
  +    if (!is_const || !mc) {
           /* TODO use hash - for now just go look up */
           goto find_it;
       }
  
  
  
  1.22      +51 -21    parrot/t/pmc/mmd.t
  
  Index: mmd.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/mmd.t,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- mmd.t     3 Apr 2005 16:27:44 -0000       1.21
  +++ mmd.t     4 Apr 2005 14:02:24 -0000       1.22
  @@ -16,7 +16,7 @@
   
   =cut
   
  -use Parrot::Test tests => 19;
  +use Parrot::Test tests => 21;
   
   pir_output_is(<<'CODE', <<'OUTPUT', "PASM divide");
   
  @@ -653,18 +653,16 @@
   Any    43
   OUT
   
  -SKIP: {
  -  skip("not yet", 2);
  -
   pir_output_is(<<'CODE', <<'OUTPUT', "__add as method");
   .sub main @MAIN
  -    new $P0, .Integer
  -    new $P1, .Integer
  -    new $P2, .Integer
  -    set $P1, 3
  -    set $P2, 39
  -    $P0 = $P1."__add"($P2)
  -    print $P0
  +    .local pmc d, l, r
  +    d = new Integer
  +    l = new Integer
  +    r = new Integer
  +    l = 3
  +    r = 39
  +    l."__add"(r, d)
  +    print d
       print "\n"
       end
   .end
  @@ -674,18 +672,50 @@
   
   pir_output_is(<<'CODE', <<'OUTPUT', "__add as method - inherited");
   .sub main @MAIN
  -    new $P0, .PerlInt
  -    new $P1, .PerlInt
  -    new $P2, .PerlInt
  -    set $P1, 3
  -    set $P2, 39
  -    $P0 = $P1."__add"($P2)
  -    print $P0
  +    .local pmc d, l, r
  +    d = new PerlInt
  +    l = new PerlInt
  +    r = new PerlInt
  +    l = 3
  +    r = 39
  +    l."__add"(r, d)
  +    print d
       print "\n"
  -    end
   .end
   CODE
   42
   OUTPUT
   
  -}
  +pir_output_is(<<'CODE', <<'OUTPUT', "__add as method - Int, Float");
  +.sub main @MAIN
  +    .local pmc d, l, r
  +    d = new Integer
  +    l = new Integer
  +    r = new Float
  +    l = 3
  +    r = 39.42
  +    l."__add"(r, d)
  +    print d
  +    print "\n"
  +    end
  +.end
  +CODE
  +42.42
  +OUTPUT
  +
  +pir_output_is(<<'CODE', <<'OUTPUT', "__add as function - Int, Float");
  +.sub main @MAIN
  +    .local pmc d, l, r
  +    d = new Integer
  +    l = new Integer
  +    r = new Float
  +    l = 3
  +    r = 39.42
  +    "__add"(l, r, d)
  +    print d
  +    print "\n"
  +    end
  +.end
  +CODE
  +42.42
  +OUTPUT
  
  
  
  1.76      +2 -2      parrot/vtable.tbl
  
  Index: vtable.tbl
  ===================================================================
  RCS file: /cvs/public/parrot/vtable.tbl,v
  retrieving revision 1.75
  retrieving revision 1.76
  diff -u -r1.75 -r1.76
  --- vtable.tbl        3 Apr 2005 15:46:48 -0000       1.75
  +++ vtable.tbl        4 Apr 2005 14:02:26 -0000       1.76
  @@ -214,7 +214,7 @@
   [CMP]
   INTVAL is_equal(PMC* value)                  MMD_EQ
   INTVAL is_equal_num(PMC* value)              MMD_NUMEQ
  -INTVAL is_equal_str(PMC* value)              MMD_STREQ
  +INTVAL is_equal_string(PMC* value)           MMD_STREQ
   
   INTVAL is_same(PMC* value)
   
  
  
  

Reply via email to