cvsuser     05/04/03 08:46:48

  Modified:    lib/Parrot Pmc2c.pm
               src      mmd.c
               t/pmc    mmd.t
               .        vtable.tbl
  Log:
  MMD 14 - create multi subs; fix empty MMD_init error
  
  Revision  Changes    Path
  1.68      +11 -4     parrot/lib/Parrot/Pmc2c.pm
  
  Index: Pmc2c.pm
  ===================================================================
  RCS file: /cvs/public/parrot/lib/Parrot/Pmc2c.pm,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- Pmc2c.pm  2 Apr 2005 16:54:53 -0000       1.67
  +++ Pmc2c.pm  3 Apr 2005 15:46:45 -0000       1.68
  @@ -763,7 +763,7 @@
               # dynamic classes need the runtime type
               # which is passed in entry to class_init
               $left = 0;  # set to 'entry' below in initialization loop.
  -            $right = 0;
  +            $right = 'enum_type_PMC';
               $right = 'enum_type_INTVAL'   if ($func =~ /_INT$/);
               $right = 'enum_type_FLOATVAL' if ($func =~ /_FLOAT$/);
               push @mmds, [ $func, $left, $right, $meth_name ];
  @@ -811,7 +811,8 @@
   EOC
   
       my $const = ($self->{flags}{dynpmc}) ? " " : " const ";
  -    $cout .= <<"EOC";
  +    if (scalar @mmds) {
  +        $cout .= <<"EOC";
   
      $const MMD_init _temp_mmd_init[] = {
           $mmd_list
  @@ -820,6 +821,7 @@
        which is passed in entry to class_init.
       */
   EOC
  +    }
   
       $cout .= <<"EOC";
       if (pass == 0) {
  @@ -920,11 +922,16 @@
           assert(my_enum_class_$dynclass != enum_class_default);
   EOC
       }
  -    $cout .= <<"EOC";
  +    if (scalar @mmds) {
  +        $cout .= <<"EOC";
   #define N_MMD_INIT (sizeof(_temp_mmd_init)/sizeof(_temp_mmd_init[0]))
           Parrot_mmd_register_table(interp, entry,
               _temp_mmd_init, N_MMD_INIT);
  +EOC
       }
  +
  +    $cout .= <<"EOC";
  +    } /* pass */
   } /* Parrot_${classname}_class_init */
   EOC
       if ($self->{flags}{dynpmc}) {
  
  
  
  1.60      +113 -3    parrot/src/mmd.c
  
  Index: mmd.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/mmd.c,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- mmd.c     3 Apr 2005 10:14:42 -0000       1.59
  +++ mmd.c     3 Apr 2005 15:46:46 -0000       1.60
  @@ -1322,6 +1322,110 @@
       return 0;
   }
   
  +static void
  +mmd_create_builtin_multi_stub(Interp *interpreter, INTVAL func_nr)
  +{
  +    const char *name;
  +    STRING *s, *ns;
  +    int len;
  +    char *p;
  +    PMC *multi;
  +
  +    name = Parrot_MMD_methode_name(interpreter, func_nr);
  +    /*
  +     * _int, _float, _str are just native variants of the base
  +     * multi
  +     */
  +    len = strlen(name);
  +    p = strstr(name, "_int");
  +    if (p && (p - name) == len - 4)
  +        return;
  +    p = strstr(name, "_str");
  +    if (p && (p - name) == len - 4)
  +        return;
  +    p = strstr(name, "_float");
  +    if (p && (p - name) == len - 6)
  +        return;
  +    ns = CONST_STRING(interpreter, "__parrot_core");
  +    s =  const_string(interpreter, name);
  +    /* create in constant pool */
  +    multi = constant_pmc_new(interpreter, enum_class_MultiSub);
  +    Parrot_store_global(interpreter, ns, s, multi);
  +}
  +
  +static void
  +mmd_create_builtin_multi_meth(Interp *interpreter, const MMD_init *entry)
  +{
  +    const char *name, *short_name;
  +    char signature[6], val_sig;
  +    STRING *s, *ns;
  +    int len;
  +    char *p;
  +    PMC *method, *multi;
  +    INTVAL func_nr;
  +
  +
  +    func_nr = entry->func_nr;
  +    name = short_name = Parrot_MMD_methode_name(interpreter, func_nr);
  +    /*
  +     * _int, _float, _str are just native variants of the base
  +     * multi
  +     */
  +    val_sig = 'P';
  +    len = strlen(name);
  +    p = strstr(name, "_int");
  +    if (p && (p - name) == len - 4) {
  +        short_name = Parrot_MMD_methode_name(interpreter, func_nr - 1);
  +        val_sig = 'I';
  +    }
  +    else {
  +        p = strstr(name, "_str");
  +        if (p && (p - name) == len - 4) {
  +            short_name = Parrot_MMD_methode_name(interpreter, func_nr - 1);
  +            val_sig = 'S';
  +        }
  +        else {
  +            p = strstr(name, "_float");
  +            if (p && (p - name) == len - 6) {
  +                short_name = Parrot_MMD_methode_name(interpreter, func_nr - 
2);
  +                val_sig = 'N';
  +            }
  +        }
  +    }
  +#if 0
  +    /*
  +     * create NCI method in left class
  +     */
  +    s = const_string(interpreter, name);
  +    strcpy(signature, "vIP.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[entry->left]->whoami,
  +        const_string(interpreter, name),
  +        method);
  +
  +    /*
  +     * push method on multi_sub
  +     */
  +    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
  +}
  +
   /*
   
   =item C<void Parrot_mmd_register_table(Interp*, INTVAL type,
  @@ -1342,23 +1446,29 @@
       MMD_table *table;
   
       table = interpreter->binop_mmd_funcs;
  -    if (table->x < type && type < enum_class_core_max) {
  +    if ((INTVAL)table->x < type && type < enum_class_core_max) {
           /*
            * pre-alloacte the function table
            */
           for (i = 0; i < MMD_USER_FIRST; ++i) {
               mmd_register(interpreter, i, enum_class_core_max - 1,
                       enum_class_core_max - 1, NULL);
  +            /*
  +             * create a MultiSub stub
  +             */
  +            mmd_create_builtin_multi_stub(interpreter, i);
           }
       }
       /*
        * register default mmds for this type
        */
       for (i = 0; i < n; ++i) {
  -        if (mmd_table[i].right <= 0)
  +        if (mmd_table[i].right == enum_type_PMC) {
               mmd_register(interpreter,
                       mmd_table[i].func_nr, type,
                       type, mmd_table[i].func_ptr);
  +        }
  +        mmd_create_builtin_multi_meth(interpreter, mmd_table + i);
       }
       /*
        * register specific mmds for this type
  
  
  
  1.20      +17 -13    parrot/t/pmc/mmd.t
  
  Index: mmd.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/mmd.t,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- mmd.t     30 Mar 2005 16:05:34 -0000      1.19
  +++ mmd.t     3 Apr 2005 15:46:47 -0000       1.20
  @@ -267,18 +267,6 @@
   42
   OUTPUT
   
  -output_is(<<'CODE', <<'OUTPUT', "built in INTVAL");
  -    new P0, .Integer
  -    new P1, .Integer
  -    set P1, 3
  -    bxor P0, P1, 2
  -    print P0
  -    print "\n"
  -    end
  -CODE
  -1
  -OUTPUT
  -
   output_is(<<'CODE', <<'OUTPUT', "PASM INTVAL");
   .include "pmctypes.pasm"
   .include "mmd.pasm"
  @@ -665,3 +653,19 @@
   Any    43
   OUT
   
  +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
  +    print "\n"
  +    end
  +.end
  +CODE
  +42
  +OUTPUT
  +
  
  
  
  1.75      +9 -2      parrot/vtable.tbl
  
  Index: vtable.tbl
  ===================================================================
  RCS file: /cvs/public/parrot/vtable.tbl,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- vtable.tbl        15 Dec 2004 14:14:33 -0000      1.74
  +++ vtable.tbl        3 Apr 2005 15:46:48 -0000       1.75
  @@ -1,6 +1,13 @@
   # $Id$
   # [MAIN] #default section name
   
  +# if there are native MMD variants be sure that:
  +#   n   := PMC
  +#   n+1 := _INT or _STR
  +#   n+2 := _FLOAT
  +# MMD_EQ ... MMD_STRCMP must be in one block
  +# see src/mmd.c
  +
   void init()
   # init must be first for JITed vtable meths
   void init_pmc(PMC* initializer)
  @@ -166,8 +173,8 @@
   void cmodulus_float(FLOATVAL value, PMC* dest) MMD_CMOD_FLOAT
   
   void pow(PMC* value, PMC* dest)        MMD_POW
  -void pow_float(FLOATVAL value, PMC* dest) MMD_POW_FLOAT
   void pow_int(INTVAL value, PMC* dest) MMD_POW_INT
  +void pow_float(FLOATVAL value, PMC* dest) MMD_POW_FLOAT
   
   void neg(PMC* dest)
   
  
  
  

Reply via email to