cvsuser     04/12/16 02:37:18

  Modified:    dynclasses pybuiltin.pmc
               imcc     parser_util.c
               include/parrot library.h
               ops      ops.num pmc.ops
               src      library.c
               t/dynclass pybuiltin.t
  Log:
  class autoload
  
  Revision  Changes    Path
  1.23      +15 -2     parrot/dynclasses/pybuiltin.pmc
  
  Index: pybuiltin.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pybuiltin.pmc,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- pybuiltin.pmc     15 Dec 2004 19:48:15 -0000      1.22
  +++ pybuiltin.pmc     16 Dec 2004 10:37:08 -0000      1.23
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pybuiltin.pmc,v 1.22 2004/12/15 19:48:15 rubys Exp $
  +$Id: pybuiltin.pmc,v 1.23 2004/12/16 10:37:08 leo Exp $
   
   =head1 NAME
   
  @@ -43,6 +43,14 @@
   
   #define VTABLE_cmp(i,l,r) mmd_dispatch_i_pp(i,l,r,MMD_CMP)
   
  +PMC* Parrot_lib_python_group_init(Interp* interpreter, PMC *lib_pmc);
  +
  +PMC*
  +Parrot_lib_python_group_init(Interp* interpreter, PMC *lib_pmc)
  +{
  +    Parrot_PyBuiltin___load__(interpreter);
  +    return lib_pmc;
  +}
   pmclass PyBuiltin dynpmc group python_group {
   /*
   
  @@ -103,6 +111,11 @@
   
           /* Already init'ed? */
           pad = scratchpad_get_current(INTERP);
  +        if (!pad) {
  +            pad = scratchpad_new(interpreter, NULL, 0);
  +            stack_push(interpreter, &interpreter->ctx.pad_stack, pad,
  +                    STACK_ENTRY_PMC, STACK_CLEANUP_NULL);
  +        }
           name = const_string(INTERP, "__name__");
           temp = scratchpad_find(INTERP, pad, name);
           if (temp && VTABLE_defined(INTERP, temp)) return;
  @@ -177,7 +190,7 @@
           /* Begin main! */
           item = pmc_new(INTERP, dynclass_PyString);
           VTABLE_set_string_native(INTERP, item,
  -            const_string(INTERP, "__main__"));
  +                const_string(INTERP, "__main__"));
           scratchpad_store_by_name(INTERP, pad, 0, name, item);
       }
   
  
  
  
  1.92      +2 -0      parrot/imcc/parser_util.c
  
  Index: parser_util.c
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/parser_util.c,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- parser_util.c     13 Dec 2004 13:46:14 -0000      1.91
  +++ parser_util.c     16 Dec 2004 10:37:12 -0000      1.92
  @@ -400,6 +400,7 @@
           /* emit a debug seg, if this op is seen */
           PARROT_WARNINGS_on(interpreter, PARROT_WARNINGS_ALL_FLAG);
       }
  +#if 0
       else if (!strcmp(name, "loadlib")) {
           SymReg *r1 = r[1];   /* lib name */
           STRING *lib;
  @@ -414,6 +415,7 @@
               Parrot_load_lib(interpreter, lib, NULL);
           }
       }
  +#endif
       else if (!memcmp(name, "invoke", 6) ||
               !memcmp(name, "callmethod", 10)) {
           if (cur_unit->type & IMC_PCCSUB)
  
  
  
  1.5       +3 -1      parrot/include/parrot/library.h
  
  Index: library.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/library.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- library.h 7 Oct 2004 14:48:14 -0000       1.4
  +++ library.h 16 Dec 2004 10:37:14 -0000      1.5
  @@ -1,7 +1,7 @@
   /* library.h
    *  Copyright: 2004 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: library.h,v 1.4 2004/10/07 14:48:14 leo Exp $
  + *     $Id: library.h,v 1.5 2004/12/16 10:37:14 leo Exp $
    *  Overview:
    *      Contains accessor functions for the _parrotlib bytecode interface
    *  Data Structure and Algorithms:
  @@ -27,6 +27,8 @@
   char* Parrot_locate_runtime_file(Interp *, const char *file_name,
           enum_runtime_ft);
   
  +void Parrot_autoload_class(Interp *, STRING *class);
  +
   #endif /* PARROT_LIBRARY_H_GUARD */
   
   /*
  
  
  
  1.53      +1 -0      parrot/ops/ops.num
  
  Index: ops.num
  ===================================================================
  RCS file: /cvs/public/parrot/ops/ops.num,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- ops.num   8 Dec 2004 13:20:42 -0000       1.52
  +++ ops.num   16 Dec 2004 10:37:14 -0000      1.53
  @@ -1363,3 +1363,4 @@
   popmark_ic                     1333
   pushmark_i                     1334
   pushmark_ic                    1335
  +new_p_sc                       1336
  
  
  
  1.33      +17 -0     parrot/ops/pmc.ops
  
  Index: pmc.ops
  ===================================================================
  RCS file: /cvs/public/parrot/ops/pmc.ops,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- pmc.ops   15 Dec 2004 17:32:45 -0000      1.32
  +++ pmc.ops   16 Dec 2004 10:37:15 -0000      1.33
  @@ -32,6 +32,8 @@
   
   =item B<new>(out PMC, in INT)
   
  +=item B<new>(out PMC, inconst STR)
  +
   =item B<new>(out PMC, in INT, in PMC)
   
   =item B<new>(out PMC, in INT, in KEY)
  @@ -68,6 +70,21 @@
     goto NEXT();
   }
   
  +op new(out PMC, inconst STR) {
  +    STRING *class = $2;
  +    INTVAL type = pmc_type(interpreter, class);
  +    if (!type) {
  +     Parrot_autoload_class(interpreter, class);
  +        type = pmc_type(interpreter, class);
  +    }
  +    if (type <= 0)
  +        real_exception(interpreter, NULL, NO_CLASS,
  +            "Class '%Ss' not found", class);
  +  $1 = pmc_new(interpreter, type);
  +  goto NEXT();
  +}
  +}
  +
   op new(out PMC, in INT, in PMC) {
     if ($2 <= 0 || $2 >= enum_class_max) {
       internal_exception(1, "Illegal PMC enum (%d) in new", (int)$2);
  
  
  
  1.14      +37 -1     parrot/src/library.c
  
  Index: library.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/library.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- library.c 10 Nov 2004 18:30:11 -0000      1.13
  +++ library.c 16 Dec 2004 10:37:16 -0000      1.14
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2004 The Perl Foundation.  All Rights Reserved.
  -$Id: library.c,v 1.13 2004/11/10 18:30:11 nicholas Exp $
  +$Id: library.c,v 1.14 2004/12/16 10:37:16 leo Exp $
   
   =head1 NAME
   
  @@ -19,6 +19,7 @@
   */
   
   #include "parrot/parrot.h"
  +#include "parrot/dynext.h"
   #include <assert.h>
   #include "library.str"
   
  @@ -290,6 +291,41 @@
        *prefix_str = s;
       return prefix;
   }
  +
  +/*
  +
  +=item C<void Parrot_autoload_class(Interp *, STRING *class)>
  +
  +Try to load a library that holds the PMC class.
  +
  +=cut
  +
  +*/
  +void
  +Parrot_autoload_class(Interp *interpreter, STRING *class)
  +{
  +    static const struct {
  +        const char *prefix;
  +        const char *lib;
  +    } mappings[] = {
  +        { "Py", "python_group" },
  +        { "Tcl", "tcl_group" }
  +    };
  +    size_t i;
  +    char *cclass;
  +
  +    cclass = string_to_cstring(interpreter, class);
  +    for (i = 0; i < sizeof(mappings)/sizeof(mappings[0]); ++i) {
  +        if (!memcmp(mappings[i].prefix, cclass, strlen(mappings[i].prefix))) 
{
  +            STRING *slib = const_string(interpreter, mappings[i].lib);
  +            Parrot_load_lib(interpreter, slib, NULL);
  +            break;
  +        }
  +    }
  +    string_cstring_free(cclass);
  +
  +}
  +
   /*
   
   =back
  
  
  
  1.7       +17 -2     parrot/t/dynclass/pybuiltin.t
  
  Index: pybuiltin.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/dynclass/pybuiltin.t,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- pybuiltin.t       15 Dec 2004 12:30:36 -0000      1.6
  +++ pybuiltin.t       16 Dec 2004 10:37:17 -0000      1.7
  @@ -1,6 +1,6 @@
   #! perl -w
   # Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -# $Id: pybuiltin.t,v 1.6 2004/12/15 12:30:36 rubys Exp $
  +# $Id: pybuiltin.t,v 1.7 2004/12/16 10:37:17 leo Exp $
   
   =head1 NAME
   
  @@ -16,9 +16,24 @@
   
   =cut
   
  -use Parrot::Test tests => 4;
  +use Parrot::Test tests => 5;
   use Parrot::Config;
   
  +pir_output_is(<< 'CODE', << 'OUTPUT', "autoload");
  +.sub main @MAIN
  +    new_pad 0
  +
  +    new $P0, "PyInt"
  +
  +    set $P0, 31
  +    print $P0
  +    print "\n"
  +.end
  +CODE
  +31
  +OUTPUT
  +
  +
   output_is(<< 'CODE', << 'OUTPUT', "delegating");
   ##PIR##
   .sub main @MAIN
  
  
  

Reply via email to